当前位置: 首页>>代码示例>>Python>>正文


Python Request.get_full_url方法代码示例

本文整理汇总了Python中urllib.request.Request.get_full_url方法的典型用法代码示例。如果您正苦于以下问题:Python Request.get_full_url方法的具体用法?Python Request.get_full_url怎么用?Python Request.get_full_url使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在urllib.request.Request的用法示例。


在下文中一共展示了Request.get_full_url方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: fetch_dsc

# 需要导入模块: from urllib.request import Request [as 别名]
# 或者: from urllib.request.Request import get_full_url [as 别名]
 def fetch_dsc(self):
     parms = {}
     self.data = None
     conf = {'mirror': ('[^#]?MIRRORSITE="?(.*[^"])"?\n', 'MIRRORSITE'),
             'components': ('[^#]?COMPONENTS="?(.*[^"])"?\n', 'COMPONENTS')}
     try:
         with open(self.originconf, 'r') as fd:
             data = fd.read()
     except IOError:
         error(_('Unable to open %s') % self.originconf)
         return
     for elem in conf:
         try:
             parms[elem] = findall(conf[elem][0], data)[0]
         except IndexError:
             error(_('Please set %(parm)s in %s(conf)s') %
                   {'parm': conf[elem][0], 'conf': self.originconf})
             return
     for component in parms['components'].split():
         request = Request('%s/pool/%s/%s/%s/%s' %
                           (parms['mirror'], component,
                            findall('^lib\S|^\S', self.package)[0],
                            self.package, self.dscname))
         debug(_('Requesting URL %s') % request.get_full_url())
         try:
             debug(_('Downloading missing %s') % self.dscname)
             self.data = urlopen(request).read()
             break
         except (HTTPError, URLError):
             error(_('Unable to fetch %s') %
                   '_'.join((self.package, self.version)))
开发者ID:mapreri,项目名称:debomatic,代码行数:33,代码来源:commands.py

示例2: load

# 需要导入模块: from urllib.request import Request [as 别名]
# 或者: from urllib.request.Request import get_full_url [as 别名]
 def load(self, location, data=None, headers={}):
     if not location:
         raise LoginError()
     self.last_url = re.sub(r"https?:\/\/[^/]+", r"", location)
     heads = {"Accept-Encoding": "gzip, deflate",
              "User-Agent": self.core_cfg.get("User-Agent", "OTRS_US/0.0")}
     if "Cookies" in self.runt_cfg:
         heads["Cookie"] = self.runt_cfg["Cookies"]
     heads.update(headers)
     r = Request(location, data, headers=heads)
     try:
         pg = urlopen(r, timeout=60)
     except HTTPError as err:
         self.echo("HTTP Error:", err.getcode())
         return
     except Exception as err:
         self.echo(repr(err))
         return
     pd = pg.read()
     if pg.getheader("Content-Encoding") == "gzip":
         pd = decompress(pd)
     self.dump_data(pg, pd)
     if not self.check_login(pd.decode(errors="ignore")):
         raise LoginError(r.get_full_url())
     return self.parse(pd)
开发者ID:Lysovenko,项目名称:OTRS_US,代码行数:27,代码来源:pgload.py

示例3: fetch

# 需要导入模块: from urllib.request import Request [as 别名]
# 或者: from urllib.request.Request import get_full_url [as 别名]
def fetch(method, uri, params_prefix=None, **params):
    """Fetch the given uri and return the contents of the response."""
    params = urlencode(_prepare_params(params, params_prefix))
    binary_params = params.encode('ASCII')

    # build the HTTP request
    url = "https://%s/%s.xml" % (CHALLONGE_API_URL, uri)
    req = Request(url, binary_params)
    req.get_method = lambda: method

    # use basic authentication
    user, api_key = get_credentials()
    auth_handler = HTTPBasicAuthHandler()
    auth_handler.add_password(
        realm="Application",
        uri=req.get_full_url(),
        user=user,
        passwd=api_key
    )
    opener = build_opener(auth_handler)

    try:
        response = opener.open(req)
    except HTTPError as e:
        if e.code != 422:
            raise
        # wrap up application-level errors
        doc = ElementTree.parse(e).getroot()
        if doc.tag != "errors":
            raise
        errors = [e.text for e in doc]
        raise ChallongeException(*errors)

    return response
开发者ID:77Wertfuzzy77,项目名称:pychallonge,代码行数:36,代码来源:api.py

示例4: fetch_missing_files

# 需要导入模块: from urllib.request import Request [as 别名]
# 或者: from urllib.request.Request import get_full_url [as 别名]
 def fetch_missing_files(self):
     filename = self.dscfile if self.dscfile else self.package
     packagename = os.path.basename(filename).split('_')[0]
     for filename in self.files:
         if not self.dscfile:
             if filename.endswith('.dsc'):
                 self.dscfile = filename
                 break
     if not self.dscfile:
         self.remove_files()
         error(_('Bad .changes file: %s') % self.package)
         raise RuntimeError
     with open(self.dscfile, 'r') as fd:
         data = fd.read()
     for entry in findall('\s\w{32}\s\d+\s(\S+)', data):
         if not os.path.exists(os.path.join(self.packagedir, entry)):
             for component in self.distopts['ocomponents'].split():
                 request = Request('%s/pool/%s/%s/%s/%s' %
                                   (self.distopts['origin'], component,
                                    findall('^lib\S|^\S', packagename)[0],
                                    packagename, entry))
                 debug(_('Requesting URL %s') % request.get_full_url())
                 try:
                     debug(_('Downloading missing %s') % entry)
                     data = urlopen(request).read()
                     break
                 except (HTTPError, URLError):
                     data = None
             if data:
                 with open(os.path.join(self.packagedir, entry), 'wb') as e:
                     e.write(data)
         if not (os.path.join(self.packagedir, entry)) in self.files:
             entry = os.path.join(self.packagedir, entry)
             self.files.add(entry)
             debug(_('File %s added') % entry)
开发者ID:mapreri,项目名称:debomatic,代码行数:37,代码来源:build.py

示例5: RequestTests

# 需要导入模块: from urllib.request import Request [as 别名]
# 或者: from urllib.request.Request import get_full_url [as 别名]
class RequestTests(unittest.TestCase):

    def setUp(self):
        self.get = Request("http://www.python.org/~jeremy/")
        self.post = Request("http://www.python.org/~jeremy/",
                            "data",
                            headers={"X-Test": "test"})

    def test_method(self):
        self.assertEqual("POST", self.post.get_method())
        self.assertEqual("GET", self.get.get_method())

    def test_add_data(self):
        self.assertFalse(self.get.has_data())
        self.assertEqual("GET", self.get.get_method())
        self.get.add_data("spam")
        self.assertTrue(self.get.has_data())
        self.assertEqual("POST", self.get.get_method())

    def test_get_full_url(self):
        self.assertEqual("http://www.python.org/~jeremy/",
                         self.get.get_full_url())

    def test_selector(self):
        self.assertEqual("/~jeremy/", self.get.get_selector())
        req = Request("http://www.python.org/")
        self.assertEqual("/", req.get_selector())

    def test_get_type(self):
        self.assertEqual("http", self.get.get_type())

    def test_get_host(self):
        self.assertEqual("www.python.org", self.get.get_host())

    def test_get_host_unquote(self):
        req = Request("http://www.%70ython.org/")
        self.assertEqual("www.python.org", req.get_host())

    def test_proxy(self):
        self.assertFalse(self.get.has_proxy())
        self.get.set_proxy("www.perl.org", "http")
        self.assertTrue(self.get.has_proxy())
        self.assertEqual("www.python.org", self.get.get_origin_req_host())
        self.assertEqual("www.perl.org", self.get.get_host())

    def test_wrapped_url(self):
        req = Request("<URL:http://www.python.org>")
        self.assertEqual("www.python.org", req.get_host())

    def test_urlwith_fragment(self):
        req = Request("http://www.python.org/?qs=query#fragment=true")
        self.assertEqual("/?qs=query", req.get_selector())
        req = Request("http://www.python.org/#fun=true")
        self.assertEqual("/", req.get_selector())
开发者ID:pogigroo,项目名称:py3k-__format__,代码行数:56,代码来源:test_urllib2.py

示例6: _download_files

# 需要导入模块: from urllib.request import Request [as 别名]
# 或者: from urllib.request.Request import get_full_url [as 别名]
 def _download_files(mirror, component, package, file, filepath):
     request = Request('%s/pool/%s/%s/%s/%s' % (mirror, component,
                       findall('^lib\S|^\S', package)[0],
                       package, file))
     try:
         debug(_('Requesting URL %s') % request.get_full_url())
         data = urlopen(request).read()
         with open(filepath, 'wb') as fd:
             fd.write(data)
     except (HTTPError, URLError):
         pass
开发者ID:debomatic,项目名称:debomatic,代码行数:13,代码来源:build.py

示例7: notify_home

# 需要导入模块: from urllib.request import Request [as 别名]
# 或者: from urllib.request.Request import get_full_url [as 别名]
def notify_home(url, package_name, intended_package_name):
    host_os = platform.platform()
    try:
        admin_rights = bool(os.getuid() == 0)
    except AttributeError:
        try:
            admin_rights = bool(ctypes.windll.shell32.IsUserAnAdmin() !=    0)
        except:
            admin_rights = False

    if sys.version_info[0] == 3:
        from urllib.request import Request, urlopen
        from urllib.parse import urlencode
    else:
        from urllib2 import Request, urlopen
        from urllib import urlencode

    if os.name != 'nt':
        try:
            pip_version = os.popen('pip --version').read()
        except:
            pip_version = ''
    else:
        pip_version = platform.python_version()

    try:
        data = {
            'p1': package_name,
            'p2': intended_package_name,
            'p3': 'pip',
            'p4': host_os,
            'p5': admin_rights,
            'p6': pip_version,
        }
        data = urlencode(data)
        request = Request(url + data)
        if debug:
            print(request.get_full_url())

        response = urlopen(request).read()

        if debug:
            print(response.decode('utf-8'))
    except Exception as e:
        print(str(e))

    print('')
    print("Warning! Maybe you made a typo in your installation command?!")
    print("Did you really want to install '{}'?!! {} should already be installed in the python stdlib.".format(intended_package_name, intended_package_name))
开发者ID:douglas-iron,项目名称:SegmentDemo,代码行数:51,代码来源:main.py

示例8: _open_tag_file

# 需要导入模块: from urllib.request import Request [as 别名]
# 或者: from urllib.request.Request import get_full_url [as 别名]
        def _open_tag_file(mirror, suffix):
            """Download an apt tag file if needed, then open it."""
            if not mirror.endswith('/'):
                mirror += '/'
            url = (mirror + "dists/" + dist + "/" + component + "/" + ftppath +
                   suffix)
            req = Request(url)
            filename = None

            if get_request_type(req) != "file":
                filename = "%s_%s_%s_%s" % (quote(mirror, safe=""),
                                            quote(dist, safe=""),
                                            component, tagfile_type)
            else:
                # Make a more or less dummy filename for local URLs.
                filename = os.path.split(get_request_selector(req))[0].replace(
                    os.sep, "_")

            fullname = os.path.join(dirname, filename)
            if get_request_type(req) == "file":
                # Always refresh.  TODO: we should use If-Modified-Since for
                # remote HTTP tag files.
                try:
                    os.unlink(fullname)
                except OSError:
                    pass
            if not os.path.exists(fullname):
                _progress("Downloading %s file ...", req.get_full_url())

                compressed = os.path.join(dirname, filename + suffix)
                try:
                    with closing(urlopen(req)) as url_f, \
                         open(compressed, "wb") as compressed_f:
                        compressed_f.write(url_f.read())

                    # apt_pkg is weird and won't accept GzipFile
                    if suffix:
                        _progress("Decompressing %s file ...",
                                  req.get_full_url())

                        if suffix == ".gz":
                            import gzip
                            decompressor = gzip.GzipFile
                        elif suffix == ".bz2":
                            import bz2
                            decompressor = bz2.BZ2File
                        elif suffix == ".xz":
                            if sys.version >= "3.3":
                                import lzma
                                decompressor = lzma.LZMAFile
                            else:
                                @contextmanager
                                def decompressor(name):
                                    proc = subprocess.Popen(
                                        ["xzcat", name],
                                        stdout=subprocess.PIPE)
                                    yield proc.stdout
                                    proc.stdout.close()
                                    proc.wait()
                        else:
                            raise RuntimeError("Unknown suffix '%s'" % suffix)

                        with decompressor(compressed) as compressed_f, \
                             open(fullname, "wb") as f:
                            f.write(compressed_f.read())
                            f.flush()
                finally:
                    if suffix:
                        try:
                            os.unlink(compressed)
                        except OSError:
                            pass

            if sys.version_info[0] < 3:
                return codecs.open(fullname, 'r', 'UTF-8', 'replace')
            else:
                return io.open(fullname, mode='r', encoding='UTF-8',
                               errors='replace')
开发者ID:aurex-linux-16-04,项目名称:germinate,代码行数:80,代码来源:archive.py

示例9: _open_tag_file

# 需要导入模块: from urllib.request import Request [as 别名]
# 或者: from urllib.request.Request import get_full_url [as 别名]
        def _open_tag_file(mirror, suffix):
            """Download an apt tag file if needed, then open it."""
            if not mirror.endswith('/'):
                mirror += '/'
            url = (mirror + "dists/" + dist + "/" + component + "/" + ftppath +
                   suffix)
            req = Request(url)
            filename = None

            if get_request_type(req) != "file":
                filename = "%s_%s_%s_%s" % (quote(mirror, safe=""),
                                            quote(dist, safe=""),
                                            component, tagfile_type)
            else:
                # Make a more or less dummy filename for local URLs.
                filename = os.path.split(get_request_selector(req))[0].replace(
                    os.sep, "_")

            fullname = os.path.join(dirname, filename)
            if get_request_type(req) == "file":
                # Always refresh.  TODO: we should use If-Modified-Since for
                # remote HTTP tag files.
                try:
                    os.unlink(fullname)
                except OSError:
                    pass
            if not os.path.exists(fullname):
                _progress("Downloading %s file ...", req.get_full_url())

                compressed = os.path.join(dirname, filename + suffix)
                try:
                    url_f = urlopen(req)
                    try:
                        with open(compressed, "wb") as compressed_f:
                            compressed_f.write(url_f.read())
                    finally:
                        url_f.close()

                    # apt_pkg is weird and won't accept GzipFile
                    if suffix:
                        _progress("Decompressing %s file ...",
                                  req.get_full_url())

                        if suffix == ".gz":
                            import gzip
                            compressed_f = gzip.GzipFile(compressed)
                        elif suffix == ".bz2":
                            import bz2
                            compressed_f = bz2.BZ2File(compressed)
                        else:
                            raise RuntimeError("Unknown suffix '%s'" % suffix)

                        # This can be simplified once we can require Python
                        # 2.7, where gzip.GzipFile and bz2.BZ2File are
                        # context managers.
                        try:
                            with open(fullname, "wb") as f:
                                f.write(compressed_f.read())
                                f.flush()
                        finally:
                            compressed_f.close()
                finally:
                    if suffix:
                        try:
                            os.unlink(compressed)
                        except OSError:
                            pass

            if sys.version_info[0] < 3:
                return codecs.open(fullname, 'r', 'UTF-8', 'replace')
            else:
                return io.open(fullname, mode='r', encoding='UTF-8',
                               errors='replace')
开发者ID:aurex-linux,项目名称:germinate,代码行数:75,代码来源:archive.py


注:本文中的urllib.request.Request.get_full_url方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。