summaryrefslogtreecommitdiff
path: root/yaksh/file_utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'yaksh/file_utils.py')
-rw-r--r--yaksh/file_utils.py29
1 files changed, 28 insertions, 1 deletions
diff --git a/yaksh/file_utils.py b/yaksh/file_utils.py
index f41c531..361b29c 100644
--- a/yaksh/file_utils.py
+++ b/yaksh/file_utils.py
@@ -2,7 +2,7 @@ import shutil
import os
import zipfile
import tempfile
-
+import csv
def copy_files(file_paths):
""" Copy Files to current directory, takes
@@ -50,3 +50,30 @@ def extract_files(zip_file, path=None):
zip_file.close()
return zfiles, extract_path
+
+def is_csv(document):
+ try:
+ try:
+ content = document.read(1024).decode('utf-8')
+ except AttributeError:
+ document.seek(0)
+ content = document.read(1024)
+ sniffer = csv.Sniffer()
+ dialect = sniffer.sniff(content)
+ document.seek(0)
+ except (csv.Error, UnicodeDecodeError):
+ return False
+ return True
+
+
+def headers_present(dict_reader, headers):
+ fields = dict_reader.fieldnames
+ clist = set()
+ for field in fields:
+ if field.strip() in headers.keys():
+ headers[field.strip()] = field
+ clist.add(field.strip())
+ if clist != headers.keys():
+ return False
+ return True
+