Skip to content

Commit 0f2f6c0

Browse files
committed
Allow expand() to expand any tiny url by defaulting to get_redirect()
if the service implementation is missing or does not implement expand().
1 parent 64dfc2f commit 0f2f6c0

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

README

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
Access many URL shortening services from one library.
1010

11-
Supported URL shortening services:
11+
Supported URL shortening services for shrinking long urls:
1212
sandbox (stored locally in memory for testing)
1313
tinyurl.com
1414
tr.im
@@ -18,6 +18,11 @@ Supported URL shortening services:
1818
cli.gs
1919
twurl.nl (tweetburner)
2020

21+
Shorty can expand any url service by getting the redirect
22+
location by requesting the tiny url.
23+
24+
See example.py for a demo of using this library.
25+
2126
Language: Python
2227
Website: http://gitorious.org/shorty
2328
Repository: git://gitorious.org/shorty/python.git
@@ -30,4 +35,3 @@ Install:
3035
If using a version of python before 2.6 you will also need
3136
to have simplejson installed.
3237

33-
See example.py for a demo of using this library.

shorty.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -346,8 +346,8 @@ def shrink(service_domain, bigurl, *args, **kargs):
346346
return s.shrink(bigurl, *args, **kargs)
347347

348348
"""
349-
Auto detect service and expand the tiny url.
350-
Returns the expanded url or None if service not supported.
349+
Expand tiny url into its full url.
350+
Returns long url if successful or None if failure.
351351
"""
352352
def expand(tinyurl):
353353

@@ -358,7 +358,6 @@ def expand(tinyurl):
358358
domain = domain[4:]
359359
s = services.get(domain)
360360
if not s:
361-
# service not supported
362-
return None
361+
return get_redirect(tinyurl)
363362
return s.expand(tinyurl)
364363

0 commit comments

Comments
 (0)