Last active
August 29, 2015 14:09
-
-
Save sashabaranov/d40f2cfa2e961943608b to your computer and use it in GitHub Desktop.
Python url wrapper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
class u(str): | |
""" | |
Class to deal with urls concat. | |
""" | |
def __init__(self, url): | |
self.url = str(url) | |
def __add__(self, other): | |
if isinstance(other, u): | |
return u(os.path.join(self.url, other.url)) | |
else: | |
return u(os.path.join(self.url, other)) | |
def __div__(self, other): | |
return self.__add__(other) | |
def __unicode__(self): | |
return self.url | |
def __repr__(self): | |
return self.url |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment