home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyo (Python 2.4)
-
- import urllib
- from os import path
- from urlparse import urlparse, urlunparse
-
- class _PropertyGen(object):
- """This is a simple descriptor that uses 'data' array to retrieve its data"""
-
- def __init__(self, index):
- self.index = index
-
-
- def __get__(self, obj, type = None):
- return obj.data[self.index]
-
-
- def __set__(self, obj, value):
- obj.data[self.index] = value
-
-
-
- class UrlParse(object):
- '''UrlParse objects represent a wrapper above urlparse.urlparse with some
- improvements:
- - access the parsed fields as the object field, instead of indexes of
- a tuple
-
- - filename path are converted to the appropriate URL path, with "file"
- scheme. A filename path is one with no associated "scheme" and it is
- unquoted.
- - allows field alterations(after calling the `make_writable` method)
-
- - \'path\' field is unquoted, whereas the \'quoted_path\' is the real one.
- '''
- data = None
-
- def __init__(self, data, basepath = None):
- if data is not None:
- self.parse(data, basepath)
-
-
-
- def parse(self, data, basepath = None):
- data = data.encode('utf-8')
- self.data = urlparse(data)
- if self.scheme == '':
- self.make_writable()
- if basepath is None:
- unqpath = path.abspath(self.quoted_path)
- else:
- unqpath = path.join(basepath, self.quoted_path)
- self.quoted_path = urllib.quote(unqpath)
- self.scheme = 'file'
-
-
- scheme = _PropertyGen(0)
- netloc = _PropertyGen(1)
- quoted_path = _PropertyGen(2)
- params = _PropertyGen(3)
- query = _PropertyGen(4)
- fragment = _PropertyGen(5)
- is_local = property((lambda self: self.scheme == 'file'))
- is_writable = property((lambda self: isinstance(self.data, list)))
-
- def get_path(self):
- return urllib.unquote(self.quoted_path)
-
-
- def set_path(self, value):
- self.quoted_path = urllib.quote(value)
-
- path = property(get_path, set_path)
-
- unparse = lambda self: urlunparse(self.data)
-
- def make_writable(self):
- self.data = list(self.data)
-
-
-
- def get_path(uri_or_path, basepath = None):
- '''Returns a path from a path or from a URI'''
- return UrlParse(uri_or_path, basepath).path
-
-
- def normalize(uri_or_path, basepath = None):
- '''Converts a path or a URI to a URI'''
- return UrlParse(uri_or_path, basepath).unparse()
-
-
- def is_local(uri_or_path, basepath = None):
- '''Checks if a path(paths are always local) or a URI is local(when it
- contains the file scheme)'''
- return UrlParse(uri_or_path, basepath).is_local
-
-
- def basename(uri_or_path, basepath = None):
- return path.basename(UrlParse(uri_or_path, basepath).path)
-
-