Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion HISTORY.rst
Original file line number Diff line number Diff line change
@@ -1,9 +1,26 @@
History
=======

0.2.4 (2016-01-01)
0.2.4.imio2 (unreleased)
------------------------

- Nothing changed yet.


0.2.4 (2020-12-04)
------------------

* 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]

* support non-standard text/javascript response
[sk1p, abarmat]

* Fix packaging por pypi

0.2.3 (2015-04-02)
Expand Down
16 changes: 12 additions & 4 deletions oembed/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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.

Expand All @@ -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:
Expand Down Expand Up @@ -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')
Expand All @@ -364,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

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def publish():
publish()
sys.exit()

version = '0.2.4'
version = '0.2.4.imio2.dev0'

setup(
name='python-oembed',
Expand Down