Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitadff2e8

Browse files
committed
Some python 2.4 fixes.
1 parent5d61603 commitadff2e8

File tree

7 files changed

+46
-32
lines changed

7 files changed

+46
-32
lines changed

‎common.py‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,19 @@ def _test(self):
6363
self.tested=True
6464

6565
# first shrink an url
66-
turl=self.shrink('http://test.com')
66+
try:
67+
turl=self.shrink('http://test.com')
68+
exceptShortyError,e:
69+
raiseShortyError('@shrink '+e.reason)
6770

6871
# second expand url and verify
69-
ifself.expand(turl)=='http://test.com':
70-
returnTrue
71-
else:
72-
returnFalse
72+
try:
73+
ifself.expand(turl)=='http://test.com':
74+
returnTrue
75+
else:
76+
returnFalse
77+
exceptShortyError,e:
78+
raiseShortyError('@expand '+e.reason)
7379

7480
defshrink(self,bigurl):
7581
"""Take a big url and make it smaller"""

‎services/chilpit.py‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ def expand(self, tinyurl):
1818

1919
# needs fixing
2020
"""turl = urlparse(tinyurl)
21-
if turl.netloc.lstrip('www.') != 'chilp.it':
21+
if turl[1].lstrip('www.') != 'chilp.it':
2222
raise ShortyError('Not a chilp.it url')
23-
resp = request('http://p.chilp.it/api.php?' + turl.query)
23+
resp = request('http://p.chilp.it/api.php?' + turl[4])
2424
url = resp.read()
2525
if url.startswith('http://'):
2626
return url.strip('\n\r')
@@ -30,9 +30,9 @@ def expand(self, tinyurl):
3030
# get click stats of the tinyurl
3131
defstats(self,tinyurl):
3232
turl=urlparse(tinyurl)
33-
ifturl.netloc.lstrip('www.')!='chilp.it':
33+
ifturl[1].lstrip('www.')!='chilp.it':
3434
raiseShortyError('Not a chilp.it url')
35-
resp=request('http://s.chilp.it/api.php?'+turl.query)
35+
resp=request('http://s.chilp.it/api.php?'+turl[4])
3636
hit_count=resp.read()
3737
try:
3838
returnint(hit_count)

‎services/digg.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ def _test(self):
1515
Service._test(self)
1616

1717
defshrink(self,bigurl):
18+
# FIXME: python 2.4 runs into a 403 error for some reason
1819
ifnotself.appkey:
1920
raiseShortyError('Must set an appkey')
2021
resp=request('http://services.digg.com/url/short/create',
@@ -27,10 +28,10 @@ def shrink(self, bigurl):
2728
defexpand(self,tinyurl):
2829
ifself.appkey:
2930
turl=urlparse(tinyurl)
30-
ifturl.netloc!='digg.com'andturl.netloc!='www.digg.com':
31+
ifturl[1].lstrip('www.')!='digg.com':
3132
raiseShortyError('Not a valid digg url')
3233
resp=request('http://services.digg.com/url/short/%s'%quote(
33-
turl.path.strip('/')),
34+
turl[2].strip('/')),
3435
{'appkey':self.appkey,'type':'json'})
3536
jdata=json.loads(resp.read())['shorturls'][0]
3637
self.itemid=jdata['itemid']

‎services/sandbox.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def shrink(self, bigurl):
3131
defexpand(self,tinyurl):
3232
# lookup big url and return
3333
turl=urlparse(tinyurl)
34-
ifturl.netloc!='sandbox.com':
34+
ifturl[1]!='sandbox.com':
3535
raiseShortyError('Not a sandbox url')
36-
returnself.urls.get(turl.path.strip('/'))
36+
returnself.urls.get(turl[2].strip('/'))
3737

‎services/trim.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ def shrink(self, bigurl, custom=None, searchtags=None, privacycode=None,
3838

3939
defexpand(self,tinyurl):
4040
turl=urlparse(tinyurl)
41-
ifturl.netloc!='tr.im'andturl.netloc!='www.tr.im':
41+
ifturl[1].lstrip('www.')!='tr.im':
4242
raiseShortyError('Not a valid tr.im url')
43-
parameters= {'trimpath':turl.path.strip('/')}
43+
parameters= {'trimpath':turl[2].strip('/')}
4444
ifself.apikey:
4545
parameters['api_key']=self.apikey
4646
resp=request('http://api.tr.im/api/trim_destination.json',parameters)

‎services/urlborg.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def expand(self, tinyurl):
2727
ifnotself.apikey:
2828
returnget_redirect(get_redirect(tinyurl))
2929
turl=urlparse(tinyurl)
30-
url='http://urlborg.com/api/%s/url/info.json%s'% (self.apikey,turl.path)
30+
url='http://urlborg.com/api/%s/url/info.json%s'% (self.apikey,turl[2])
3131
resp=request(url)
3232
jdata=json.loads(resp.read())
3333
ifjdata.has_key('error'):

‎shorty.py‎

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,19 @@ def _test(self):
109109
self.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+
exceptShortyError,e:
115+
raiseShortyError('@shrink '+e.reason)
113116

114117
# second expand url and verify
115-
ifself.expand(turl)=='http://test.com':
116-
returnTrue
117-
else:
118-
returnFalse
118+
try:
119+
ifself.expand(turl)=='http://test.com':
120+
returnTrue
121+
else:
122+
returnFalse
123+
exceptShortyError,e:
124+
raiseShortyError('@expand '+e.reason)
119125

120126
defshrink(self,bigurl):
121127
"""Take a big url and make it smaller"""
@@ -177,7 +183,7 @@ def expand(self, tinyurl):
177183
ifnotself.apikey:
178184
returnget_redirect(get_redirect(tinyurl))
179185
turl=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])
181187
resp=request(url)
182188
jdata=json.loads(resp.read())
183189
ifjdata.has_key('error'):
@@ -387,9 +393,9 @@ def shrink(self, bigurl, custom=None, searchtags=None, privacycode=None,
387393

388394
defexpand(self,tinyurl):
389395
turl=urlparse(tinyurl)
390-
ifturl.netloc!='tr.im'andturl.netloc!='www.tr.im':
396+
ifturl[1].lstrip('www.')!='tr.im':
391397
raiseShortyError('Not a valid tr.im url')
392-
parameters= {'trimpath':turl.path.strip('/')}
398+
parameters= {'trimpath':turl[2].strip('/')}
393399
ifself.apikey:
394400
parameters['api_key']=self.apikey
395401
resp=request('http://api.tr.im/api/trim_destination.json',parameters)
@@ -435,6 +441,7 @@ def _test(self):
435441
Service._test(self)
436442

437443
defshrink(self,bigurl):
444+
# FIXME: python 2.4 runs into a 403 error for some reason
438445
ifnotself.appkey:
439446
raiseShortyError('Must set an appkey')
440447
resp=request('http://services.digg.com/url/short/create',
@@ -447,10 +454,10 @@ def shrink(self, bigurl):
447454
defexpand(self,tinyurl):
448455
ifself.appkey:
449456
turl=urlparse(tinyurl)
450-
ifturl.netloc!='digg.com'andturl.netloc!='www.digg.com':
457+
ifturl[1].lstrip('www.')!='digg.com':
451458
raiseShortyError('Not a valid digg url')
452459
resp=request('http://services.digg.com/url/short/%s'%quote(
453-
turl.path.strip('/')),
460+
turl[2].strip('/')),
454461
{'appkey':self.appkey,'type':'json'})
455462
jdata=json.loads(resp.read())['shorturls'][0]
456463
self.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
492499
defstats(self,tinyurl):
493500
turl=urlparse(tinyurl)
494-
ifturl.netloc.lstrip('www.')!='chilp.it':
501+
ifturl[1].lstrip('www.')!='chilp.it':
495502
raiseShortyError('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])
497504
hit_count=resp.read()
498505
try:
499506
returnint(hit_count)
@@ -530,9 +537,9 @@ def shrink(self, bigurl):
530537
defexpand(self,tinyurl):
531538
# lookup big url and return
532539
turl=urlparse(tinyurl)
533-
ifturl.netloc!='sandbox.com':
540+
ifturl[1]!='sandbox.com':
534541
raiseShortyError('Not a sandbox url')
535-
returnself.urls.get(turl.path.strip('/'))
542+
returnself.urls.get(turl[2].strip('/'))
536543

537544
sandbox=Sandbox()
538545

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp