diff --git a/.gitignore b/.gitignore index e686a07..86d6572 100644 --- a/.gitignore +++ b/.gitignore @@ -47,3 +47,5 @@ nosetests.xml .cache/ .pytest_cache/ + +tmp diff --git a/src/pycrunch/__init__.py b/src/pycrunch/__init__.py index caa897a..a19f24e 100644 --- a/src/pycrunch/__init__.py +++ b/src/pycrunch/__init__.py @@ -195,6 +195,8 @@ Session = elements.ElementSession +UnsafeSession = elements.UnsafeElementSession + __all__ = [ 'cubes', 'elements', diff --git a/src/pycrunch/elements.py b/src/pycrunch/elements.py index c4a3053..d35267d 100644 --- a/src/pycrunch/elements.py +++ b/src/pycrunch/elements.py @@ -360,3 +360,33 @@ def password(self): "`session.password` is being deprecated.", PendingDeprecationWarning ) return self.__password + + +class UnsafeElementSession(ElementSession): + """ + A subclass of ElementSession that disables SSL/TLS verification. + This is mean to be used for development purposes only. + """ + + def __init__( + self, + email=None, + password=None, + token=None, + site_url=None, + progress_tracking=None, + ): + super(UnsafeElementSession, self).__init__( + email, + password, + token, + site_url, + progress_tracking, + ) + + # Skip SSL/TLS verification + self.verify = False + + if self.token: + # Use Bearer token for authentication + self.headers.update({"Authorization": "Bearer {}".format(self.token)}) diff --git a/src/pycrunch/importing.py b/src/pycrunch/importing.py index 06bf6f5..9f6c0e0 100644 --- a/src/pycrunch/importing.py +++ b/src/pycrunch/importing.py @@ -5,7 +5,7 @@ import six -from pycrunch import shoji, csvlib +from pycrunch import csvlib, shoji class Importer(object): @@ -53,13 +53,13 @@ def wait_for_batch_status(self, batch, status): raise ValueError("The batch did not reach the '%s' state in the " "given time. Please check again later." % status) - def add_source(self, ds, filename, fp, mimetype): + def add_source(self, ds, filename, fp, mimetype, data=None): """Create a new Source on the given dataset and return its URL.""" sources_url = ds.user_url.catalogs['sources'] # Don't call Catalog.post here (which would force application/json); # we want requests.Session to set multipart/form-data with a boundary. new_source_url = ds.session.post( - sources_url, files={"uploaded_file": (filename, fp, mimetype)} + sources_url, files={"uploaded_file": (filename, fp, mimetype)}, data=data ).headers["Location"] if self.strict is not None: diff --git a/src/pycrunch/version.py b/src/pycrunch/version.py index 22e3a83..91201fc 100644 --- a/src/pycrunch/version.py +++ b/src/pycrunch/version.py @@ -1 +1 @@ -__version__ = '0.5.7' +__version__ = '0.5.8'