home *** CD-ROM | disk | FTP | other *** search
/ Chip 2011 November / CHIP_2011_11.iso / Programy / Narzedzia / Calibre / calibre-0.8.18.msi / file_262 / nturl2path.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2011-09-09  |  1.3 KB  |  48 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.7)
  3.  
  4.  
  5. def url2pathname(url):
  6.     import string
  7.     import urllib
  8.     url = url.replace(':', '|')
  9.     if '|' not in url:
  10.         if url[:4] == '////':
  11.             url = url[2:]
  12.         components = url.split('/')
  13.         return urllib.unquote('\\'.join(components))
  14.     comp = None.split('|')
  15.     if len(comp) != 2 or comp[0][-1] not in string.ascii_letters:
  16.         error = 'Bad URL: ' + url
  17.         raise IOError, error
  18.     drive = comp[0][-1].upper()
  19.     components = comp[1].split('/')
  20.     path = drive + ':'
  21.     for comp in components:
  22.         if comp:
  23.             path = path + '\\' + urllib.unquote(comp)
  24.             continue
  25.     return path
  26.  
  27.  
  28. def pathname2url(p):
  29.     import urllib
  30.     if ':' not in p:
  31.         if p[:2] == '\\\\':
  32.             p = '\\\\' + p
  33.         components = p.split('\\')
  34.         return urllib.quote('/'.join(components))
  35.     comp = None.split(':')
  36.     if len(comp) != 2 or len(comp[0]) > 1:
  37.         error = 'Bad path: ' + p
  38.         raise IOError, error
  39.     drive = urllib.quote(comp[0].upper())
  40.     components = comp[1].split('\\')
  41.     path = '///' + drive + ':'
  42.     for comp in components:
  43.         if comp:
  44.             path = path + '/' + urllib.quote(comp)
  45.             continue
  46.     return path
  47.  
  48.