urlybird

Common url operations not covered by the standard library urllib
git clone git://git.defalsify.org/python-urlybird.git
Log | Files | Refs | LICENSE

merge.py (1024B)


      1 def urlhostmerge(hoststring, host, port):
      2     if host == None and port == None:
      3         return hoststring
      4     r_host = None
      5     r_port = None
      6 
      7     if hoststring != None:
      8         if isinstance(hoststring, bytes) or isinstance(hoststring, bytearray):
      9             hoststring = hoststring.decode('utf-8')
     10         try:
     11             (r_host, r_port) = hoststring.split(':')
     12         except ValueError:
     13             r_host = hoststring
     14     if host != None:
     15         r_host = host
     16     if port != None:
     17         r_port = str(port)
     18     if r_port == None:
     19         return r_host
     20     return r_host + ':' + r_port
     21 
     22 
     23 def urlmerge(default_url, *args):
     24     r = ['', '', '', '', '']
     25     if default_url != None:
     26         for i, v in enumerate(default_url):
     27             if v == None:
     28                 continue
     29             r[i] = default_url[i]
     30     for url in args:
     31         for i, v in enumerate(url):
     32             if v == None:
     33                 v = ''
     34             if len(v) != 0:
     35                 r[i] = url[i]
     36     return (r[0], r[1], r[2], r[3], r[4],)