From 91bc9e373d11ff5fe457b023d0b6c32adb64e045 Mon Sep 17 00:00:00 2001 From: Jean-Francois Roche Date: Wed, 11 May 2016 13:33:59 +0200 Subject: [PATCH 1/6] Add timeout Give the possibility to add a urllib timeout for a OEmbedEndpoint --- oembed/__init__.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/oembed/__init__.py b/oembed/__init__.py index 4096e9d..fe4f87f 100644 --- a/oembed/__init__.py +++ b/oembed/__init__.py @@ -64,7 +64,7 @@ import urllib2 # Python 2 import re - +NO_TIMEOUT=object() # json module is in the standard library as of python 2.6; fall back to # simplejson if present for older versions. try: @@ -214,7 +214,7 @@ class OEmbedEndpoint(object): This class handles a number of URL schemes and manage resource retrieval. ''' - def __init__(self, url, urlSchemes=None): + def __init__(self, url, urlSchemes=None, timeout=NO_TIMEOUT): ''' Create a new OEmbedEndpoint object. @@ -226,6 +226,7 @@ def __init__(self, url, urlSchemes=None): self._urlSchemes = {} self._initRequestHeaders() self._urllib = urllib2 + self._timeout = timeout if urlSchemes is not None: for urlScheme in urlSchemes: @@ -348,7 +349,11 @@ def fetch(self, url): ''' opener = self._urllib.build_opener() opener.addheaders = self._requestHeaders.items() - response = opener.open(url) + if self._timeout != NO_TIMEOUT: + response = opener.open(url, timeout=self._timeout) + else: + response = opener.open(url) + headers = response.info() raw = response.read() raw = raw.decode('utf8') From 997f9987cd123bd6d8eaa6970628c3d4f41dc9c8 Mon Sep 17 00:00:00 2001 From: Laurent Lasudry Date: Fri, 4 Dec 2020 11:58:52 +0100 Subject: [PATCH 2/6] Add missing changes --- HISTORY.rst | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/HISTORY.rst b/HISTORY.rst index 79d3658..ffe2dd6 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -4,6 +4,13 @@ History 0.2.4 (2016-01-01) ------------------ +* Add timeout + Give the possibility to add a urllib timeout for a OEmbedEndpoint + [jfroche] + +* support non-standard text/javascript response + [sk1p, abarmat] + * Fix packaging por pypi 0.2.3 (2015-04-02) From 4814f3a5fc99afd45aaf05dbc5ee949df70162f0 Mon Sep 17 00:00:00 2001 From: Laurent Lasudry Date: Fri, 4 Dec 2020 11:59:24 +0100 Subject: [PATCH 3/6] Quickfix: Always try to parse JSON (as default) from response Youtube stopped sending correct Content-Type header: text/html instead of JSON --- HISTORY.rst | 4 ++++ oembed/__init__.py | 5 ++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/HISTORY.rst b/HISTORY.rst index ffe2dd6..45a5a1f 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -4,6 +4,10 @@ History 0.2.4 (2016-01-01) ------------------ +* Quickfix: Always try to parse JSON (as default) from response + Youtube stopped sending correct Content-Type header: text/html instead of JSON + [laulaz] + * Add timeout Give the possibility to add a urllib timeout for a OEmbedEndpoint [jfroche] diff --git a/oembed/__init__.py b/oembed/__init__.py index fe4f87f..e504290 100644 --- a/oembed/__init__.py +++ b/oembed/__init__.py @@ -369,7 +369,10 @@ def fetch(self, url): headers['Content-Type'].find('text/json') != -1: response = OEmbedResponse.newFromJSON(raw) else: - raise OEmbedError('Invalid mime-type in response - %s' % headers['Content-Type']) + try: + response = OEmbedResponse.newFromJSON(raw) + except: + raise OEmbedError('Invalid mime-type in response - %s' % headers['Content-Type']) return response From d503309d74229e6bf1909c25946f548c844677ce Mon Sep 17 00:00:00 2001 From: Benoit Suttor Date: Fri, 4 Dec 2020 12:02:58 +0100 Subject: [PATCH 4/6] Preparing release 0.2.4.imio1 --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 22472cf..8cd3fd3 100644 --- a/setup.py +++ b/setup.py @@ -16,7 +16,7 @@ def publish(): publish() sys.exit() -version = '0.2.4' +version = '0.2.4.imio1' setup( name='python-oembed', From f3a37cd7257d07b7dc780780789c5827313d0010 Mon Sep 17 00:00:00 2001 From: Benoit Suttor Date: Fri, 4 Dec 2020 12:05:07 +0100 Subject: [PATCH 5/6] Back to development: 0.2.4.imio2 --- HISTORY.rst | 6 ++++++ setup.py | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/HISTORY.rst b/HISTORY.rst index 45a5a1f..b5deeb6 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -1,6 +1,12 @@ History ======= +0.2.4.imio2 (unreleased) +------------------------ + +- Nothing changed yet. + + 0.2.4 (2016-01-01) ------------------ diff --git a/setup.py b/setup.py index 8cd3fd3..4535a7f 100644 --- a/setup.py +++ b/setup.py @@ -16,7 +16,7 @@ def publish(): publish() sys.exit() -version = '0.2.4.imio1' +version = '0.2.4.imio2.dev0' setup( name='python-oembed', From 553766acd405d89585f2975fcb8bec0ea75f54f2 Mon Sep 17 00:00:00 2001 From: Benoit Suttor Date: Fri, 4 Dec 2020 12:09:35 +0100 Subject: [PATCH 6/6] Update changelog date --- HISTORY.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/HISTORY.rst b/HISTORY.rst index b5deeb6..94734a5 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -7,7 +7,7 @@ History - Nothing changed yet. -0.2.4 (2016-01-01) +0.2.4 (2020-12-04) ------------------ * Quickfix: Always try to parse JSON (as default) from response