cleaning up code, removing unreferenced method and comments
changed miniuri.py
This commit is contained in:
parent
671ecd408a
commit
3f1f60a132
1 changed files with 12 additions and 29 deletions
41
miniuri.py
41
miniuri.py
|
|
@ -12,27 +12,18 @@ class Uri( object ):
|
|||
scheme authority | path | extension
|
||||
| |
|
||||
port filename
|
||||
|
||||
How to use:
|
||||
.. code-block:: python
|
||||
|
||||
>>> from miniuri import Uri
|
||||
>>> u = Uri("https://fox:pass@www.foxhop.net:81/path/filename.jpg?p=2#5")
|
||||
>>> print u.hostname
|
||||
www.foxhop.net
|
||||
>>> u.username = 'max'
|
||||
>>> print u.uri
|
||||
https://max:pass@www.foxhop.net:81/path/filename.jpg?p=2#5
|
||||
"""
|
||||
def __init__( self, uri = None ):
|
||||
if uri: self.uri = uri # invoke uri.setter
|
||||
|
||||
def __str__(self): return self.uri
|
||||
|
||||
@property
|
||||
def uri( self ):
|
||||
"""build and return uri from attributes"""
|
||||
scheme = path = filename = query = fragment = ''
|
||||
if self.path: path = '/'.join( self.path.split('/')[:-1] )
|
||||
if self.scheme: scheme = self.scheme + '://'
|
||||
if self.path: path = '/'.join(self.path.split('/')[:-1])
|
||||
if self.filename: filename = '/' + self.filename
|
||||
if self.query: query = '?' + self.query
|
||||
if self.fragment: fragment = '#' + self.fragment
|
||||
|
|
@ -79,18 +70,18 @@ class Uri( object ):
|
|||
"""set all the attribute that makeup a authority"""
|
||||
self.username = self.password = self.port = None
|
||||
self.hostname = a
|
||||
if '@' in a:
|
||||
if '@' in self.hostname:
|
||||
self.userinfo, self.hostname = a.split( '@' ) # userinfo setter
|
||||
if ':' in self.hostname:
|
||||
self.hostname, self.port = self.hostname.split( ':' )
|
||||
|
||||
@property
|
||||
def userinfo( self ):
|
||||
"""return username:password"""
|
||||
if self.username and self.password:
|
||||
return self.username + ':' + self.password
|
||||
if self.username: return self.username
|
||||
else: return None
|
||||
"""return username:password, username, or None"""
|
||||
if self.username:
|
||||
if self.password:
|
||||
return self.username + ':' + self.password
|
||||
return self.username
|
||||
|
||||
@userinfo.setter
|
||||
def userinfo( self, info ):
|
||||
|
|
@ -100,16 +91,8 @@ class Uri( object ):
|
|||
self.username, self.password = info.split( ':' )
|
||||
|
||||
@property
|
||||
def extension( self ):
|
||||
"""return extension"""
|
||||
if '.' in self.filename: return self.filename.split('.')[-1]
|
||||
else: return None
|
||||
def extension(self):
|
||||
"""return filename extension"""
|
||||
return self.filename.split('.')[-1] if '.' in self.filename else None
|
||||
|
||||
@property
|
||||
def parts( self ):
|
||||
"""remove scheme then return a list of uri parts splitting on / """
|
||||
p = self.uri
|
||||
if self.scheme: p = p[ len(self.scheme) + 3: ]
|
||||
return p.split( '/' )
|
||||
|
||||
def __str__( self ): return self.uri
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue