summaryrefslogtreecommitdiff
path: root/yaksh/file_utils.py
diff options
context:
space:
mode:
authorPrabhu Ramachandran2017-11-14 19:03:36 +0530
committerGitHub2017-11-14 19:03:36 +0530
commit1996f5d6409a5f936700a906f7da1afacb664ce6 (patch)
tree4a747aac76728a342dc9440b06eff3fb20c87a8f /yaksh/file_utils.py
parenta7afd20e83bff405baf643647afb16a4569481aa (diff)
parent29e358a6fcd438fa7ddf3d3bccb2af1839158ba6 (diff)
downloadonline_test-1996f5d6409a5f936700a906f7da1afacb664ce6.tar.gz
online_test-1996f5d6409a5f936700a906f7da1afacb664ce6.tar.bz2
online_test-1996f5d6409a5f936700a906f7da1afacb664ce6.zip
Merge pull request #378 from prathamesh920/upload_users_csv
Upload users csv
Diffstat (limited to 'yaksh/file_utils.py')
-rw-r--r--yaksh/file_utils.py18
1 files changed, 17 insertions, 1 deletions
diff --git a/yaksh/file_utils.py b/yaksh/file_utils.py
index f41c531..b178eeb 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,19 @@ def extract_files(zip_file, path=None):
zip_file.close()
return zfiles, extract_path
+
+def is_csv(document):
+ ''' Check if document is csv with ',' as the delimiter'''
+ 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, delimiters=',')
+ document.seek(0)
+ except (csv.Error, UnicodeDecodeError):
+ return False, None
+ return True, dialect
+