Putting all the code from the current master branch of TWBlue

This commit is contained in:
2014-10-27 16:29:04 -06:00
parent 58c82e5486
commit 1af4a8b291
284 changed files with 58760 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
from httplib import HTTPConnection
from urlparse import urlparse
class URLShortener (object):
def __init__ (self, *args, **kwargs):
#Stub out arguments, silly object. :(
return super(URLShortener, self).__init__()
def shorten (self, url):
if self.created_url(url):
return url
else:
return self._shorten(url)
def _shorten (self, url):
raise NotImplementedError
def created_url (self, url):
"""Returns a boolean indicating whether or not this shortener created a provided url"""
raise NotImplementedError
def unshorten(self, url):
working = urlparse(url)
if not working.netloc:
raise TypeError, "Unable to parse URL."
con = HTTPConnection(working.netloc)
con.connect()
con.request('GET', working.path)
resp = con.getresponse()
con.close()
return resp.getheader('location')