<s> import re <EOL> URI_REGEX = r'<STR_LIT>' <EOL> URI_RE = re . compile ( URI_REGEX ) <EOL> AUTH_REGEX = r'<STR_LIT>' <EOL> AUTH_RE = re . compile ( AUTH_REGEX ) <EOL> class Uri ( object ) : <EOL> '''<STR_LIT>''' <EOL> def __init__ ( self , uri ) : <EOL> self . uri = uri <EOL> self . matches = URI_RE . match ( uri ) <EOL> def getScheme ( self ) : <EOL> return self . matches . group ( <NUM_LIT:2> ) <EOL> def getAuthority ( self ) : <EOL> return Authority ( self . matches . group ( <NUM_LIT:4> ) ) <EOL> def getPath ( self ) : <EOL> path = self . matches . group ( <NUM_LIT:5> ) <EOL> if not path : <EOL> return None <EOL> return self . matches . group ( <NUM_LIT:5> ) <EOL> def getQuery ( self ) : <EOL> return Query ( self . matches . group ( <NUM_LIT:7> ) ) <EOL> def getFragment ( self ) : <EOL> return self . matches . group ( <NUM_LIT:9> ) <EOL> class Authority ( object ) : <EOL> '''<STR_LIT>''' <EOL> def __init__ ( self , auth ) : <EOL> self . auth = auth <EOL> auths = auth . split ( '<STR_LIT:@>' ) <EOL> if len ( auths ) == <NUM_LIT:2> : <EOL> userpass = auths . pop ( <NUM_LIT:0> ) <EOL> userpass = userpass . split ( '<STR_LIT::>' ) <EOL> self . user = userpass . pop ( <NUM_LIT:0> ) <EOL> try : <EOL> self . passwd = userpass . pop ( <NUM_LIT:0> ) <EOL> except : <EOL> self . passwd = None <EOL> else : <EOL> self . user = self . passwd = None <EOL> hostport = auths [ <NUM_LIT:0> ] . split ( '<STR_LIT::>' ) <EOL> self . host = hostport . pop ( <NUM_LIT:0> ) <EOL> try : <EOL> self . port = hostport . pop ( <NUM_LIT:0> ) <EOL> except : <EOL> self . port = None <EOL> def getUser ( self ) : <EOL> return self . user <EOL> def getPassword ( self ) : <EOL> return self . passwd <EOL> def getHost ( self ) : <EOL> return self . host <EOL> def getPort ( self ) : <EOL> if self . port : <EOL> return int ( self . port ) <EOL> class Query ( dict ) : <EOL> '''<STR_LIT>''' <EOL> def __init__ ( self , query ) : <EOL> self . query = query <EOL> if query : <EOL> query_dict = dict ( [ x . split ( '<STR_LIT:=>' ) for x in query . split ( '<STR_LIT:&>' ) ] ) <EOL> self . update ( query_dict ) <EOL> for key , val in query_dict . items ( ) : <EOL> self . __setattr__ ( key , val ) <EOL> def _test ( ) : <EOL> import doctest , utils <EOL> return doctest . testmod ( utils ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> _test ( ) </s>
