From 9483d840ddf8a921afd54e6c320f4feec8e59213 Mon Sep 17 00:00:00 2001 From: Joaquim Adraz Date: Thu, 23 May 2024 11:21:08 +0100 Subject: [PATCH 1/6] Add extra data option to add_source --- src/pycrunch/importing.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pycrunch/importing.py b/src/pycrunch/importing.py index 06bf6f5..55447fa 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={}): """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: From 31d0e6d7a653ffec880df1f9222ee304467ac6dc Mon Sep 17 00:00:00 2001 From: Joaquim Adraz Date: Thu, 23 May 2024 11:47:54 +0100 Subject: [PATCH 2/6] Add unsafe session for dev --- src/pycrunch/__init__.py | 2 ++ src/pycrunch/elements.py | 30 ++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) 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..82eaff7 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": f"Bearer {self.token}"}) From be0bcc5c8c26bed2ce4238620d840817b7b0b79e Mon Sep 17 00:00:00 2001 From: Joaquim Adraz Date: Thu, 23 May 2024 11:48:21 +0100 Subject: [PATCH 3/6] Add tmp folder to ignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index e686a07..86d6572 100644 --- a/.gitignore +++ b/.gitignore @@ -47,3 +47,5 @@ nosetests.xml .cache/ .pytest_cache/ + +tmp From 5a965160be7f4aacaecb1234f1ce963ba6ca6235 Mon Sep 17 00:00:00 2001 From: Joaquim Adraz Date: Thu, 23 May 2024 11:48:29 +0100 Subject: [PATCH 4/6] Bump version --- src/pycrunch/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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' From a2171540cbf436644a439e2392645798c165af68 Mon Sep 17 00:00:00 2001 From: Maksym Shalenyi Date: Thu, 23 May 2024 10:48:27 -0700 Subject: [PATCH 5/6] change default value for data to None --- src/pycrunch/importing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pycrunch/importing.py b/src/pycrunch/importing.py index 55447fa..9f6c0e0 100644 --- a/src/pycrunch/importing.py +++ b/src/pycrunch/importing.py @@ -53,7 +53,7 @@ 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, data={}): + 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); From f650691ee7e4ba603fe7e1dda602359df4618120 Mon Sep 17 00:00:00 2001 From: Maksym Shalenyi Date: Thu, 23 May 2024 10:52:26 -0700 Subject: [PATCH 6/6] replace f-string with format method --- src/pycrunch/elements.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pycrunch/elements.py b/src/pycrunch/elements.py index 82eaff7..d35267d 100644 --- a/src/pycrunch/elements.py +++ b/src/pycrunch/elements.py @@ -389,4 +389,4 @@ def __init__( if self.token: # Use Bearer token for authentication - self.headers.update({"Authorization": f"Bearer {self.token}"}) + self.headers.update({"Authorization": "Bearer {}".format(self.token)})