Skip to content

Commit e4e37b4

Browse files
author
Claudio
committed
fixing compatibilty issues with python 2.5
1 parent 0f02be1 commit e4e37b4

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

bitly.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,10 @@ def _fetchUrl(self, url):
171171

172172
# Open and return the URL
173173
try:
174-
url_data = self._urllib.urlopen(url=url, timeout=1).read()
174+
import socket
175+
timeout = 1
176+
socket.setdefaulttimeout(timeout);
177+
url_data = self._urllib.urlopen(url=url).read()
175178
except URLError, err:
176179
# nasty bit of hack, i know but unfortunatly urllib2 has no smart way of telling me
177180
# that it was an timeout error

test/test_shortening_urls.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def verifying_that_a_custom_exception_is_raised_on_timeout(api):
109109
bitly_shortening_url = 'http://api.bit.ly/shorten?login=jcfigueiredo&version=2.0.1&apiKey=R_1cf5dc0fa14c2df34261fb620bd256aa&format=json&longUrl=http%3A%2F%2Fwww.matandorobosgigantes.com'
110110

111111
mox.StubOutWithMock(urllib2, "urlopen")
112-
urllib2.urlopen(url=bitly_shortening_url, timeout=1).AndRaise(URLError('urlopen error timed out'))
112+
urllib2.urlopen(url=bitly_shortening_url).AndRaise(URLError('urlopen error timed out'))
113113

114114
url_to_be_shortened = 'http://www.matandorobosgigantes.com'
115115

@@ -126,7 +126,7 @@ def verifying_that_urlerror_exceptions_are_reraised_but_timeout_exceptions(api):
126126
bitly_shortening_url = 'http://api.bit.ly/shorten?login=jcfigueiredo&version=2.0.1&apiKey=R_1cf5dc0fa14c2df34261fb620bd256aa&format=json&longUrl=http%3A%2F%2Fwww.matandorobosgigantes.com'
127127

128128
mox.StubOutWithMock(urllib2, "urlopen")
129-
urllib2.urlopen(url=bitly_shortening_url, timeout=1).AndRaise(URLError('something different from timeout'))
129+
urllib2.urlopen(url=bitly_shortening_url).AndRaise(URLError('something different from timeout'))
130130

131131
url_to_be_shortened = 'http://www.matandorobosgigantes.com'
132132

@@ -143,7 +143,7 @@ def verifying_that_any_other_exceptions_are_reraised_but_timeout_exceptions(api)
143143
bitly_shortening_url = 'http://api.bit.ly/shorten?login=jcfigueiredo&version=2.0.1&apiKey=R_1cf5dc0fa14c2df34261fb620bd256aa&format=json&longUrl=http%3A%2F%2Fwww.matandorobosgigantes.com'
144144

145145
mox.StubOutWithMock(urllib2, "urlopen")
146-
urllib2.urlopen(url=bitly_shortening_url, timeout=1).AndRaise(ValueError('something different'))
146+
urllib2.urlopen(url=bitly_shortening_url).AndRaise(ValueError('something different'))
147147

148148
url_to_be_shortened = 'http://www.matandorobosgigantes.com'
149149

0 commit comments

Comments
 (0)