Skip to content

Instantly share code, notes, and snippets.

@sashabaranov
Last active August 29, 2015 14:09
Show Gist options
  • Save sashabaranov/d40f2cfa2e961943608b to your computer and use it in GitHub Desktop.
Save sashabaranov/d40f2cfa2e961943608b to your computer and use it in GitHub Desktop.
Python url wrapper
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