runeh / urlunshort

No description has been added.

Clone this repository (size: 24.0 KB): HTTPS / SSH
$ hg clone http://bitbucket.org/runeh/urlunshort/

Changed (Δ10 bytes):

raw changeset »

urlunshort/__init__.py (6 lines added, 8 lines removed)

Up to file-list urlunshort/__init__.py:

1
"""Tools for exanding shortened URLs (from tinyurl/bit.ly/etc.) and 
2
detection if a URL has been shortened.
3
"""
1
"""Tools for detecting and expanding shortened URLs."""
4
2
5
__version__ = "0.2"
3
__version__ = "0.2.0"
6
4
__author__ = "Rune Halvorsen <runefh@gmail.com>"
7
5
__homepage__ = "http://bitbucket.org/runeh/urlunshort"
8
6
@@ -10,7 +8,7 @@ import urlparse
10
8
from resolvers import generic_resolver
11
9
12
10
# If some tiny url services require a special resolver, this mapping will
13
# map between hostname -> resolver
11
# map between hostname -> resolver (currently we have no custom resolvers)
14
12
_resolver_map = {
15
13
16
14
}
@@ -54,9 +52,9 @@ def resolve(url, timeout=None):
54
52
    return resolver(parts.netloc, parts.path, timeout)
55
53
56
54
def is_shortened(url):
57
    """Check if the url appears to be shortened, based on the services 
55
    """Check if the url appears to be shortened, based on the services
58
56
    whitelist. **Note:** This will be a best-effort thing, as the list
59
    if services has to be kept up to date. Also note that valid URLs on 
57
    if services has to be kept up to date. Also note that valid URLs on
60
58
    shortening services (like bit.ly/apidocs) will be assumed to be a
61
59
    shortened url.
62
60
@@ -69,4 +67,4 @@ def is_shortened(url):
69
67
        # yes, I dknow about the default_scheme argument to ursplit,
70
68
        # and no, it doesn't actully work.
71
69
72
    return parts.hostname in services and parts.path
70
    return bool(parts.hostname in services and parts.path)