Changeset 385

Show
Ignore:
Timestamp:
02/11/07 06:56:44 (2 years ago)
Author:
athomas
Message:

pyndexter: More doctests for URI.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • pyndexter/trunk/pyndexter/util.py

    r384 r385  
    3939 
    4040    PS. `urlparse` is not useful. 
     41 
     42    The URI constructor can be passed a string: 
    4143 
    4244    >>> u = URI('http://user:password@www.example.com/some/path?parm=1&parm=2&other=3#fragment') 
     
    5860    'fragment' 
    5961 
     62    ...or the individual URI components as keyword arguments: 
     63 
     64    >>> URI(scheme='http', username='user', password='password', host='www.example.com', path='/some/path', query={'parm': [1, 2], 'other': [3]}, fragment='fragment') 
     65    http://user:password@www.example.com/some/path?other=3&parm=1&parm=2#fragment 
     66 
     67    ...or finally, another URI object: 
     68 
     69    >>> v = URI(u) 
     70    >>> v == u 
     71    True 
     72    >>> v.query is u.query 
     73    False 
     74    >>> v 
     75    http://user:password@www.example.com/some/path?other=3&parm=1&parm=2#fragment 
     76 
    6077    URI also normalises the path component: 
    6178 
     
    109126    path = property(_get_path, _set_path) 
    110127 
    111     def __ne__(self, other): 
     128    def __cmp__(self, other): 
     129        """Compare two URI objects. 
     130 
     131        >>> u = URI('http://user:password@www.example.com/some/path?parm=1&parm=2&other=3#fragment') 
     132        >>> v = URI(u) 
     133        >>> u == v 
     134        True 
     135        >>> v.host = 'www.google.com' 
     136        >>> u == v 
     137        False 
     138        """ 
    112139        return cmp(repr(self), repr(other)) 
    113140 
     
    125152        uri += quote(self.path) 
    126153        if self.query: 
    127             uri += '?' + '&'.join(['&'.join(['%s=%s' % (k, quote(v)) for v in l]) 
     154            uri += '?' + '&'.join(['&'.join(['%s=%s' % (k, quote(str(v))) for v in l]) 
    128155                                   for k, l in sorted(self.query.items())]) 
    129156        if self.fragment: