当前位置: 首页>>代码示例>>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;未经允许,请勿转载。