@@ -109,13 +109,19 @@ def _test(self):
109109self .tested = True
110110
111111# first shrink an url
112- turl = self .shrink ('http://test.com' )
112+ try :
113+ turl = self .shrink ('http://test.com' )
114+ except ShortyError ,e :
115+ raise ShortyError ('@shrink ' + e .reason )
113116
114117# second expand url and verify
115- if self .expand (turl )== 'http://test.com' :
116- return True
117- else :
118- return False
118+ try :
119+ if self .expand (turl )== 'http://test.com' :
120+ return True
121+ else :
122+ return False
123+ except ShortyError ,e :
124+ raise ShortyError ('@expand ' + e .reason )
119125
120126def shrink (self ,bigurl ):
121127"""Take a big url and make it smaller"""
@@ -177,7 +183,7 @@ def expand(self, tinyurl):
177183if not self .apikey :
178184return get_redirect (get_redirect (tinyurl ))
179185turl = urlparse (tinyurl )
180- url = 'http://urlborg.com/api/%s/url/info.json%s' % (self .apikey ,turl . path )
186+ url = 'http://urlborg.com/api/%s/url/info.json%s' % (self .apikey ,turl [ 2 ] )
181187resp = request (url )
182188jdata = json .loads (resp .read ())
183189if jdata .has_key ('error' ):
@@ -387,9 +393,9 @@ def shrink(self, bigurl, custom=None, searchtags=None, privacycode=None,
387393
388394def expand (self ,tinyurl ):
389395turl = urlparse (tinyurl )
390- if turl . netloc != 'tr.im' and turl . netloc != 'www. tr.im' :
396+ if turl [ 1 ]. lstrip ( 'www.' ) != 'tr.im' :
391397raise ShortyError ('Not a valid tr.im url' )
392- parameters = {'trimpath' :turl . path .strip ('/' )}
398+ parameters = {'trimpath' :turl [ 2 ] .strip ('/' )}
393399if self .apikey :
394400parameters ['api_key' ]= self .apikey
395401resp = request ('http://api.tr.im/api/trim_destination.json' ,parameters )
@@ -435,6 +441,7 @@ def _test(self):
435441Service ._test (self )
436442
437443def shrink (self ,bigurl ):
444+ # FIXME: python 2.4 runs into a 403 error for some reason
438445if not self .appkey :
439446raise ShortyError ('Must set an appkey' )
440447resp = request ('http://services.digg.com/url/short/create' ,
@@ -447,10 +454,10 @@ def shrink(self, bigurl):
447454def expand (self ,tinyurl ):
448455if self .appkey :
449456turl = urlparse (tinyurl )
450- if turl . netloc != 'digg.com' and turl . netloc != 'www. digg.com' :
457+ if turl [ 1 ]. lstrip ( 'www.' ) != 'digg.com' :
451458raise ShortyError ('Not a valid digg url' )
452459resp = request ('http://services.digg.com/url/short/%s' % quote (
453- turl . path .strip ('/' )),
460+ turl [ 2 ] .strip ('/' )),
454461 {'appkey' :self .appkey ,'type' :'json' })
455462jdata = json .loads (resp .read ())['shorturls' ][0 ]
456463self .itemid = jdata ['itemid' ]
@@ -479,9 +486,9 @@ def expand(self, tinyurl):
479486
480487# needs fixing
481488"""turl = urlparse(tinyurl)
482- if turl.netloc .lstrip('www.') != 'chilp.it':
489+ if turl[1] .lstrip('www.') != 'chilp.it':
483490 raise ShortyError('Not a chilp.it url')
484- resp = request('http://p.chilp.it/api.php?' + turl.query )
491+ resp = request('http://p.chilp.it/api.php?' + turl[4] )
485492 url = resp.read()
486493 if url.startswith('http://'):
487494 return url.strip('\n \r ')
@@ -491,9 +498,9 @@ def expand(self, tinyurl):
491498# get click stats of the tinyurl
492499def stats (self ,tinyurl ):
493500turl = urlparse (tinyurl )
494- if turl . netloc .lstrip ('www.' )!= 'chilp.it' :
501+ if turl [ 1 ] .lstrip ('www.' )!= 'chilp.it' :
495502raise ShortyError ('Not a chilp.it url' )
496- resp = request ('http://s.chilp.it/api.php?' + turl . query )
503+ resp = request ('http://s.chilp.it/api.php?' + turl [ 4 ] )
497504hit_count = resp .read ()
498505try :
499506return int (hit_count )
@@ -530,9 +537,9 @@ def shrink(self, bigurl):
530537def expand (self ,tinyurl ):
531538# lookup big url and return
532539turl = urlparse (tinyurl )
533- if turl . netloc != 'sandbox.com' :
540+ if turl [ 1 ] != 'sandbox.com' :
534541raise ShortyError ('Not a sandbox url' )
535- return self .urls .get (turl . path .strip ('/' ))
542+ return self .urls .get (turl [ 2 ] .strip ('/' ))
536543
537544sandbox = Sandbox ()
538545