當前位置: 首頁>>代碼示例>>Python>>正文


Python urllib.url2pathname方法代碼示例

本文整理匯總了Python中urllib.url2pathname方法的典型用法代碼示例。如果您正苦於以下問題:Python urllib.url2pathname方法的具體用法?Python urllib.url2pathname怎麽用?Python urllib.url2pathname使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在urllib的用法示例。


在下文中一共展示了urllib.url2pathname方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: open_local_file

# 需要導入模塊: import urllib [as 別名]
# 或者: from urllib import url2pathname [as 別名]
def open_local_file(self, req):
        host = req.get_host()
        file = req.get_selector()
        localfile = url2pathname(file)
        stats = os.stat(localfile)
        size = stats[stat.ST_SIZE]
        modified = rfc822.formatdate(stats[stat.ST_MTIME])
        mtype = mimetypes.guess_type(file)[0]
        stats = os.stat(localfile)
        headers = mimetools.Message(StringIO(
            'Content-Type: %s\nContent-Length: %d\nLast-modified: %s\n' %
            (mtype or 'text/plain', size, modified)))
        if host:
            host, port = splitport(host)
        if not host or \
           (not port and socket.gethostbyname(host) in self.get_names()):
            return addinfourl(open(localfile, 'rb'),
                              headers, 'file:'+file)
        raise URLError('file not on local host') 
開發者ID:war-and-code,項目名稱:jawfish,代碼行數:21,代碼來源:urllib2.py

示例2: __init__

# 需要導入模塊: import urllib [as 別名]
# 或者: from urllib import url2pathname [as 別名]
def __init__(self, base, config, layered = False, **kwargs):
        addrspace.BaseAddressSpace.__init__(self, base, config, **kwargs)
        self.as_assert(base == None or layered, 'Must be first Address Space')
        self.as_assert(config.LOCATION.startswith("file://"), 'Location is not of file scheme')

        path = urllib.url2pathname(config.LOCATION[7:])
        self.as_assert(os.path.exists(path), 'Filename must be specified and exist')
        self.name = os.path.abspath(path)
        self.fname = self.name
        self.mode = 'rb'
        if config.WRITE:
            self.mode += '+'
        self.fhandle = open(self.fname, self.mode)
        self.fhandle.seek(0, 2)
        self.fsize = self.fhandle.tell()
        self._long_struct = struct.Struct("=I")

    # Abstract Classes cannot register options, and since this checks config.WRITE in __init__, we define the option here 
開發者ID:virtualrealitysystems,項目名稱:aumfor,代碼行數:20,代碼來源:standard.py

示例3: open_file

# 需要導入模塊: import urllib [as 別名]
# 或者: from urllib import url2pathname [as 別名]
def open_file(self, url):
        path = urllib.url2pathname(urllib.unquote(url))
        if os.path.isdir(path):
            if path[-1] != os.sep:
                url = url + '/'
            indexpath = os.path.join(path, "index.html")
            if os.path.exists(indexpath):
                return self.open_file(url + "index.html")
            try:
                names = os.listdir(path)
            except os.error, msg:
                exc_type, exc_value, exc_tb = sys.exc_info()
                raise IOError, msg, exc_tb
            names.sort()
            s = MyStringIO("file:"+url, {'content-type': 'text/html'})
            s.write('<BASE HREF="file:%s">\n' %
                    urllib.quote(os.path.join(path, "")))
            for name in names:
                q = urllib.quote(name)
                s.write('<A HREF="%s">%s</A>\n' % (q, q))
            s.seek(0)
            return s 
開發者ID:aliyun,項目名稱:oss-ftp,代碼行數:24,代碼來源:webchecker.py

示例4: main

# 需要導入模塊: import urllib [as 別名]
# 或者: from urllib import url2pathname [as 別名]
def main(*args):
    ctx = uno.getComponentContext()
    smgr = ctx.ServiceManager
    try:
        ui_locale = gettext.translation('base',
                                        localedir=urllib.url2pathname(
                                            get_main_directory("com.addon.pagenumbering") +
                                            'python/locales'),
                                        languages=[getLanguage()]
                                        )
    except Exception, e:
        ui_locale = gettext.translation('base',
                                        localedir=urllib.url2pathname(
                                            get_main_directory("com.addon.pagenumbering") +
                                            'python/locales'),
                                        languages=["en"]
                                        ) 
開發者ID:arvchristos,項目名稱:lo-page-numbering,代碼行數:19,代碼來源:main.py

示例5: __init__

# 需要導入模塊: import urllib [as 別名]
# 或者: from urllib import url2pathname [as 別名]
def __init__(self, base, config, layered = False, **kwargs):
        addrspace.BaseAddressSpace.__init__(self, base, config, **kwargs)
        self.as_assert(base == None or layered, 'Must be first Address Space')
        self.as_assert(config.LOCATION.startswith("file://"), 'Location is not of file scheme')

        path = urllib.url2pathname(config.LOCATION[7:])
        self.as_assert(os.path.exists(path), 'Filename must be specified and exist')
        self.name = os.path.abspath(path)
        self.fname = self.name
        self.mode = 'rb'
        if config.WRITE:
            self.mode += '+'
        self.fhandle = open(self.fname, self.mode)
        self.fhandle.seek(0, 2)
        self.fsize = self.fhandle.tell()

    # Abstract Classes cannot register options, and since this checks config.WRITE in __init__, we define the option here 
開發者ID:504ensicsLabs,項目名稱:DAMM,代碼行數:19,代碼來源:standard.py

示例6: open_local_file

# 需要導入模塊: import urllib [as 別名]
# 或者: from urllib import url2pathname [as 別名]
def open_local_file(self, req):
        import email.Utils
        import mimetypes
        host = req.get_host()
        file = req.get_selector()
        localfile = url2pathname(file)
        stats = os.stat(localfile)
        size = stats.st_size
        modified = email.Utils.formatdate(stats.st_mtime, usegmt=True)
        mtype = mimetypes.guess_type(file)[0]
        headers = mimetools.Message(StringIO(
            'Content-type: %s\nContent-length: %d\nLast-modified: %s\n' %
            (mtype or 'text/plain', size, modified)))
        if host:
            host, port = splitport(host)
        if not host or \
           (not port and socket.gethostbyname(host) in self.get_names()):
            return addinfourl(open(localfile, 'rb'),
                              headers, 'file:'+file)
        raise URLError('file not on local host') 
開發者ID:ofermend,項目名稱:medicare-demo,代碼行數:22,代碼來源:urllib2.py

示例7: get_filename

# 需要導入模塊: import urllib [as 別名]
# 或者: from urllib import url2pathname [as 別名]
def get_filename(self, basename):
        filename = None
        # first try finding the file in the root
        if self.storage.exists(basename):
            try:
                filename = self.storage.path(basename)
            except NotImplementedError:
                # remote storages don't implement path, access the file locally
                filename = compressor_file_storage.path(basename)
        # secondly try to find it with staticfiles (in debug mode)
        elif self.finders:
            filename = self.finders.find(urllib.url2pathname(basename))
        if filename:
            return filename
        # or just raise an exception as the last resort
        raise UncompressableFileError(
            "'%s' could not be found in the COMPRESS_ROOT '%s'%s" %
            (basename, settings.COMPRESS_ROOT,
             self.finders and " or with staticfiles." or ".")) 
開發者ID:canvasnetworks,項目名稱:canvas,代碼行數:21,代碼來源:base.py

示例8: open_local_file

# 需要導入模塊: import urllib [as 別名]
# 或者: from urllib import url2pathname [as 別名]
def open_local_file(self, req):
        import email.utils
        import mimetypes
        host = req.get_host()
        filename = req.get_selector()
        localfile = url2pathname(filename)
        try:
            stats = os.stat(localfile)
            size = stats.st_size
            modified = email.utils.formatdate(stats.st_mtime, usegmt=True)
            mtype = mimetypes.guess_type(filename)[0]
            headers = mimetools.Message(StringIO(
                'Content-type: %s\nContent-length: %d\nLast-modified: %s\n' %
                (mtype or 'text/plain', size, modified)))
            if host:
                host, port = splitport(host)
            if not host or \
                (not port and _safe_gethostbyname(host) in self.get_names()):
                if host:
                    origurl = 'file://' + host + filename
                else:
                    origurl = 'file://' + filename
                return addinfourl(open(localfile, 'rb'), headers, origurl)
        except OSError, msg:
            # urllib2 users shouldn't expect OSErrors coming from urlopen()
            raise URLError(msg) 
開發者ID:glmcdona,項目名稱:meddle,代碼行數:28,代碼來源:urllib2.py

示例9: test_basic

# 需要導入模塊: import urllib [as 別名]
# 或者: from urllib import url2pathname [as 別名]
def test_basic(self):
        # Make sure simple tests pass
        expected_path = os.path.join("parts", "of", "a", "path")
        expected_url = "parts/of/a/path"
        result = urllib.pathname2url(expected_path)
        self.assertEqual(expected_url, result,
                         "pathname2url() failed; %s != %s" %
                         (result, expected_url))
        result = urllib.url2pathname(expected_url)
        self.assertEqual(expected_path, result,
                         "url2pathame() failed; %s != %s" %
                         (result, expected_path)) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:14,代碼來源:test_urllib.py

示例10: test_quoting

# 需要導入模塊: import urllib [as 別名]
# 或者: from urllib import url2pathname [as 別名]
def test_quoting(self):
        # Test automatic quoting and unquoting works for pathnam2url() and
        # url2pathname() respectively
        given = os.path.join("needs", "quot=ing", "here")
        expect = "needs/%s/here" % urllib.quote("quot=ing")
        result = urllib.pathname2url(given)
        self.assertEqual(expect, result,
                         "pathname2url() failed; %s != %s" %
                         (expect, result))
        expect = given
        result = urllib.url2pathname(result)
        self.assertEqual(expect, result,
                         "url2pathname() failed; %s != %s" %
                         (expect, result))
        given = os.path.join("make sure", "using_quote")
        expect = "%s/using_quote" % urllib.quote("make sure")
        result = urllib.pathname2url(given)
        self.assertEqual(expect, result,
                         "pathname2url() failed; %s != %s" %
                         (expect, result))
        given = "make+sure/using_unquote"
        expect = os.path.join("make+sure", "using_unquote")
        result = urllib.url2pathname(given)
        self.assertEqual(expect, result,
                         "url2pathname() failed; %s != %s" %
                         (expect, result)) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:28,代碼來源:test_urllib.py

示例11: test_ntpath

# 需要導入模塊: import urllib [as 別名]
# 或者: from urllib import url2pathname [as 別名]
def test_ntpath(self):
        given = ('/C:/', '///C:/', '/C|//')
        expect = 'C:\\'
        for url in given:
            result = urllib.url2pathname(url)
            self.assertEqual(expect, result,
                             'nturl2path.url2pathname() failed; %s != %s' %
                             (expect, result))
        given = '///C|/path'
        expect = 'C:\\path'
        result = urllib.url2pathname(given)
        self.assertEqual(expect, result,
                         'nturl2path.url2pathname() failed; %s != %s' %
                         (expect, result)) 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:16,代碼來源:test_urllib.py

示例12: downloadPackageOnly

# 需要導入模塊: import urllib [as 別名]
# 或者: from urllib import url2pathname [as 別名]
def downloadPackageOnly(self, output=None):
        """Download a single package, if needed.

        An MD5 signature is used to determine whether download is needed,
        and to test that we actually downloaded what we expected.
        If output is given it is a file-like object that will receive a log
        of what happens.

        If anything unforeseen happened the method returns an error message
        string.
        """

        scheme, loc, path, query, frag = urlparse.urlsplit(self._dict['Download-URL'])
        path = urllib.url2pathname(path)
        filename = os.path.split(path)[1]
        self.archiveFilename = os.path.join(self._db.preferences.downloadDir, filename)
        if not self._archiveOK():
            if scheme == 'manual':
                return "Please download package manually and save as %s" % self.archiveFilename
            downloader = PimpUrllibDownloader(None, self._db.preferences.downloadDir,
                watcher=self._db.preferences.watcher)
            if not downloader.download(self._dict['Download-URL'],
                    self.archiveFilename, output):
                return "download command failed"
        if not os.path.exists(self.archiveFilename) and not NO_EXECUTE:
            return "archive not found after download"
        if not self._archiveOK():
            return "archive does not have correct MD5 checksum" 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:30,代碼來源:pimp.py

示例13: url2pathname

# 需要導入模塊: import urllib [as 別名]
# 或者: from urllib import url2pathname [as 別名]
def url2pathname(url):
    if PYVER >= 3:
        return urllib.request.url2pathname(url)
    else:
        return urllib.url2pathname(url) 
開發者ID:fossfreedom,項目名稱:alternative-toolbar,代碼行數:7,代碼來源:alttoolbar_rb3compat.py


注:本文中的urllib.url2pathname方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。