From 4e7b8d79c66358f27727156f5465140edd858a5e Mon Sep 17 00:00:00 2001 From: Assis Silva Date: Mon, 6 Jan 2014 23:57:35 -0300 Subject: [PATCH 1/4] Added parser to datetime and decimal to json --- firebase/__init__.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/firebase/__init__.py b/firebase/__init__.py index 81e94a6..b098ccd 100644 --- a/firebase/__init__.py +++ b/firebase/__init__.py @@ -2,8 +2,19 @@ import urlparse #for urlparse and urljoin import os #for os.path.dirname import json #for dumps - - +import datetime #for parse datetime object to string +import decimal #for parse decimal to string + +class JSONEncoder(json.JSONEncoder): + def default(self, obj): + if isinstance(obj, datetime.datetime): + return obj.isoformat() + elif isinstance(obj, datetime.timedelta): + return total_seconds(obj) + elif isinstance(obj, decimal.Decimal): + return float(obj) + else: + return json.JSONEncoder.default(self, obj) class Firebase(): ROOT_URL = '' #no trailing slash @@ -75,7 +86,7 @@ def __request(self, method, **kwargs): #Firebase API does not accept form-encoded PUT/POST data. It needs to #be JSON encoded. if 'data' in kwargs: - kwargs['data'] = json.dumps(kwargs['data']) + kwargs['data'] = json.dumps(kwargs['data'], cls=JSONEncoder) params = {} if self.auth_token: From 6f072633f3aae9ac9cbc2a153075e33b08cee508 Mon Sep 17 00:00:00 2001 From: Assis Silva Date: Tue, 7 Jan 2014 01:07:00 -0300 Subject: [PATCH 2/4] Force cast 'path' to string --- firebase/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firebase/__init__.py b/firebase/__init__.py index b098ccd..ccfcbbd 100644 --- a/firebase/__init__.py +++ b/firebase/__init__.py @@ -27,7 +27,7 @@ def __init__(self, root_url, auth_token=None): def child(self, path): root_url = '%s/' % self.ROOT_URL - url = urlparse.urljoin(root_url, path.lstrip('/')) + url = urlparse.urljoin(root_url, str(path).lstrip('/')) return Firebase(url) def parent(self): From 28a8f45d7b18e487d6ddf85c136f814efd389843 Mon Sep 17 00:00:00 2001 From: Assis Silva Date: Wed, 8 Jan 2014 23:24:52 -0300 Subject: [PATCH 3/4] Keep auth token in child() and parent() methods --- firebase/__init__.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/firebase/__init__.py b/firebase/__init__.py index ccfcbbd..249ef35 100644 --- a/firebase/__init__.py +++ b/firebase/__init__.py @@ -18,6 +18,7 @@ def default(self, obj): class Firebase(): ROOT_URL = '' #no trailing slash + auth_token = None def __init__(self, root_url, auth_token=None): self.ROOT_URL = root_url.rstrip('/') @@ -28,7 +29,7 @@ def __init__(self, root_url, auth_token=None): def child(self, path): root_url = '%s/' % self.ROOT_URL url = urlparse.urljoin(root_url, str(path).lstrip('/')) - return Firebase(url) + return Firebase(url, auth_token=self.auth_token) def parent(self): url = os.path.dirname(self.ROOT_URL) @@ -36,7 +37,7 @@ def parent(self): up = urlparse.urlparse(url) if up.path == '': return None #maybe throw exception here? - return Firebase(url) + return Firebase(url, auth_token=self.auth_token) def name(self): return os.path.basename(self.ROOT_URL) From e11f91e353446362483c3a1873f626eedc0849c2 Mon Sep 17 00:00:00 2001 From: Guilherme Medeiros Date: Tue, 24 Apr 2018 16:33:56 -0300 Subject: [PATCH 4/4] Allows using the most recent REQUESTS library --- requirements.txt | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index 679d575..bc3a7ce 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1 @@ -requests >=1.2.0,<1.2.99 +requests >=1.2.0 diff --git a/setup.py b/setup.py index b4195e0..3f113ab 100644 --- a/setup.py +++ b/setup.py @@ -8,7 +8,7 @@ author = 'Michael Huynh', author_email = 'mike@mikexstudios.com', url = 'http://github.com/mikexstudios/python-firebase', - install_requires = ['requests >=1.2.0,<1.2.99'], + install_requires = ['requests >=1.2.0'], classifiers = [ 'Programming Language :: Python', 'License :: OSI Approved :: BSD License',