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


Python requests_file.FileAdapter方法代码示例

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


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

示例1: from_url

# 需要导入模块: import requests_file [as 别名]
# 或者: from requests_file import FileAdapter [as 别名]
def from_url(cls, url, keys=None, encoding='utf-8'):
		"""
		Initialize a new :py:class:`.Catalog` object from a resource at the
		specified URL. The resulting data is validated against a schema file
		with :py:func:`~king_phisher.utilities.validate_json_schema` before
		being passed to :py:meth:`~.__init__`.

		:param str url: The URL to the catalog data to load.
		:param keys: The keys to use for verifying remote data.
		:type keys: :py:class:`~king_phisher.security_keys.SecurityKeys`
		:param str encoding: The encoding of the catalog data.
		:return: The new catalog instance.
		:rtype: :py:class:`.Catalog`
		"""
		keys = keys or security_keys.SecurityKeys()
		req_sess = requests.Session()
		req_sess.mount('file://', requests_file.FileAdapter())
		cls.logger.debug('fetching catalog from: ' + url)
		resp = req_sess.get(url)
		data = resp.content.decode(encoding)
		data = serializers.JSON.loads(data)
		utilities.validate_json_schema(data, 'king-phisher.catalog')
		keys.verify_dict(data, signature_encoding='base64')
		return cls(data, keys=keys) 
开发者ID:rsmusllp,项目名称:king-phisher,代码行数:26,代码来源:catalog.py

示例2: find_first_response

# 需要导入模块: import requests_file [as 别名]
# 或者: from requests_file import FileAdapter [as 别名]
def find_first_response(urls):
    """ Decode the first successfully fetched URL, from UTF-8 encoding to
    Python unicode.
    """
    text = ''

    for url in urls:
        try:
            session = requests.Session()
            session.mount('file://', FileAdapter())
            text = session.get(url).text
        except requests.exceptions.RequestException as ree:
            LOG.error('Exception reading Public Suffix List url ' + url + ' - ' + str(ree) + '.')
        else:
            return _decode_utf8(text)

    LOG.error(
        'No Public Suffix List found. Consider using a mirror or constructing '
        'your TLDExtract with `suffix_list_urls=None`.'
    )
    return unicode('') 
开发者ID:abaykan,项目名称:CrawlBox,代码行数:23,代码来源:remote.py

示例3: processSwaggerURL

# 需要导入模块: import requests_file [as 别名]
# 或者: from requests_file import FileAdapter [as 别名]
def processSwaggerURL(self, url):
        parsed_url = urlparse.urlparse(url)
        if not parsed_url.scheme:  # Assume file relative to documentation
            env = self.state.document.settings.env
            relfn, absfn = env.relfn2path(url)
            env.note_dependency(relfn)

            with open(absfn) as fd:
                content = fd.read()

            return json.loads(content)
        else:
            s = requests.Session()
            s.mount('file://', FileAdapter())
            r = s.get(url)
            return r.json() 
开发者ID:unaguil,项目名称:sphinx-swaggerdoc,代码行数:18,代码来源:swaggerv2_doc.py

示例4: check_to_open

# 需要导入模块: import requests_file [as 别名]
# 或者: from requests_file import FileAdapter [as 别名]
def check_to_open(filename):
    """check if `filename` is a fetchable uri and returns True in the case is true False otherwise"""
    url_name = urllify(filename)
    with r.Session() as r_session:
        r_session.mount('file://', requests_file.FileAdapter())

        f = r_session.get(url_name, stream=True)
        is_ok = True

        try:
            f.raise_for_status()
        except Exception as e:
            is_ok = False
        finally:
            f.close()
            return is_ok 
开发者ID:opentargets,项目名称:data_pipeline,代码行数:18,代码来源:IO.py

示例5: _func_fetch

# 需要导入模块: import requests_file [as 别名]
# 或者: from requests_file import FileAdapter [as 别名]
def _func_fetch(self, url, allow_file=False):
		session = requests.Session()
		if allow_file:
			session.mount('file://', requests_file.FileAdapter())
		try:
			response = session.get(url)
		except requests.exceptions.RequestException:
			self.logger.error('template failed to load url: ' + url)
			return None
		return response.text 
开发者ID:rsmusllp,项目名称:king-phisher,代码行数:12,代码来源:templates.py

示例6: perform_download_packages_from_repository

# 需要导入模块: import requests_file [as 别名]
# 或者: from requests_file import FileAdapter [as 别名]
def perform_download_packages_from_repository(dispatcher, intent):
    """
    See :class:`DownloadPackagesFromRepository`.
    """
    rpm_version = make_rpm_version(intent.flocker_version)

    package_type = intent.distribution.package_type()
    s = requests.Session()
    # Tests use a local package repository
    s.mount('file://', FileAdapter())

    downloaded_packages = set()
    for package in intent.packages:
        package_name = package_filename(
            package_type=package_type,
            package=package,
            architecture=PACKAGE_ARCHITECTURE[package],
            rpm_version=rpm_version,
        )
        url = intent.source_repo + '/' + package_name
        local_path = intent.target_path.child(package_name).path
        download = s.get(url)
        download.raise_for_status()
        content = download.content
        with open(local_path, "wb") as local_file:
            local_file.write(content)
        downloaded_packages.add(package_name)

    return downloaded_packages 
开发者ID:ClusterHQ,项目名称:flocker,代码行数:31,代码来源:yum.py

示例7: async_get

# 需要导入模块: import requests_file [as 别名]
# 或者: from requests_file import FileAdapter [as 别名]
def async_get(event_loop):
    """ AsyncSession cannot be created global since it will create
        a different loop from pytest-asyncio. """
    async_session = AsyncXMLSession()
    async_session.mount('file:///', FileAdapter())
    path = os.path.sep.join((os.path.dirname(os.path.abspath(__file__)), 'nasa.rss'))
    url = 'file:///{}'.format(path)

    return partial(async_session.get, url) 
开发者ID:erinxocon,项目名称:requests-xml,代码行数:11,代码来源:test_request_xml.py

示例8: Playlistparser

# 需要导入模块: import requests_file [as 别名]
# 或者: from requests_file import FileAdapter [as 别名]
def Playlistparser(self):
        try:
           s = requests.Session()
           s.mount('file://', FileAdapter())
           with s.get(config.url, headers=self.headers, proxies=config.proxies, stream=False, timeout=30) as r:
              if r.status_code != 304:
                 if r.encoding is None: r.encoding = 'utf-8'
                 self.headers['If-Modified-Since'] = gevent.time.strftime('%a, %d %b %Y %H:%M:%S %Z', gevent.time.gmtime(self.playlisttime))
                 self.playlist = PlaylistGenerator(m3uchanneltemplate=config.m3uchanneltemplate)
                 self.picons = picons.logomap
                 self.channels = {}
                 m = requests.auth.hashlib.md5()
                 logging.info('[%s]: playlist %s downloaded' % (self.__class__.__name__, config.url))
                 pattern = requests.utils.re.compile(r',(?P<name>.+)[\r\n].+[\r\n].+[\r\n](?P<url>[^\r\n]+)?')
                 urlpattern = requests.utils.re.compile(r'^(acestream|infohash)://[0-9a-f]{40}$|^(http|https)://.*.(acelive|acestream|acemedia|torrent)$')
                 for match in pattern.finditer(r.text, requests.auth.re.MULTILINE):
                    itemdict = match.groupdict()
                    name = itemdict.get('name', '').replace(' (allfon)','')
                    url = itemdict['url']
                    itemdict['logo'] = self.picons[name] = itemdict.get('logo', picons.logomap.get(name))

                    if requests.utils.re.search(urlpattern, url):
                       self.channels[name] = url
                       itemdict['url'] = quote(ensure_str(name),'')

                    self.playlist.addItem(itemdict)
                    m.update(ensure_binary(name))

                 self.etag = '"' + m.hexdigest() + '"'
                 logging.debug('[%s]: plugin playlist generated' % self.__class__.__name__)

              self.playlisttime = gevent.time.time()

        except requests.exceptions.RequestException:
           logging.error("[%s]: can't download %s playlist!" % (self.__class__.__name__, config.url))
           return False
        except: logging.error(traceback.format_exc()); return False

        return True 
开发者ID:pepsik-kiev,项目名称:HTTPAceProxy,代码行数:41,代码来源:allfon_plugin.py

示例9: Playlistparser

# 需要导入模块: import requests_file [as 别名]
# 或者: from requests_file import FileAdapter [as 别名]
def Playlistparser(self):
        try:
           s = requests.Session()
           s.mount('file://', FileAdapter())
           with s.get(config.url, headers=self.headers, proxies=config.proxies, stream=False, timeout=30) as r:
              if r.status_code != 304:
                 if r.encoding is None: r.encoding = 'utf-8'
                 self.headers['If-Modified-Since'] = gevent.time.strftime('%a, %d %b %Y %H:%M:%S %Z', gevent.time.gmtime(self.playlisttime))
                 self.playlist = PlaylistGenerator(m3uchanneltemplate=config.m3uchanneltemplate)
                 self.picons = picons.logomap
                 self.channels = {}
                 m = requests.auth.hashlib.md5()
                 logging.info('[%s]: playlist %s downloaded' % (self.__class__.__name__, config.url))
                 pattern = requests.utils.re.compile(r',(?P<name>.+) \((?P<group>.+)\)[\r\n]+(?P<url>[^\r\n]+)?')
                 urlpattern = requests.utils.re.compile(r'^(acestream|infohash)://[0-9a-f]{40}$|^(http|https)://.*.(acelive|acestream|acemedia|torrent)$')
                 for match in pattern.finditer(r.text, requests.auth.re.MULTILINE):
                    itemdict = match.groupdict()
                    name = itemdict.get('name', '')
                    itemdict['logo'] = self.picons[name] = itemdict.get('logo', picons.logomap.get(name))
                    url = itemdict['url']

                    if requests.utils.re.search(urlpattern, url):
                       self.channels[name] = url
                       itemdict['url'] = quote(ensure_str(name), '')

                    self.playlist.addItem(itemdict)
                    m.update(ensure_binary(name))

                 self.etag = '"' + m.hexdigest() + '"'
                 logging.debug('[%s]: plugin playlist generated' % self.__class__.__name__)

              self.playlisttime = gevent.time.time()

        except requests.exceptions.RequestException:
           logging.error("[%s]: can't download %s playlist!" % (self.__class__.__name__, config.url))
           return False
        except: logging.error(traceback.format_exc()); return False

        return True 
开发者ID:pepsik-kiev,项目名称:HTTPAceProxy,代码行数:41,代码来源:torrenttv_plugin.py

示例10: request

# 需要导入模块: import requests_file [as 别名]
# 或者: from requests_file import FileAdapter [as 别名]
def request(self) -> "requests.model.Response":
        import requests
        from requests.auth import HTTPBasicAuth, HTTPDigestAuth
        import requests.exceptions

        auth_map = {
            "basic": HTTPBasicAuth,
            "digest": HTTPDigestAuth,
        }

        session = requests.Session()
        try:
            from requests_file import FileAdapter

            session.mount("file://", FileAdapter())
        except ImportError:
            pass

        try:
            reply = session.get(self._url, timeout=self._timeout)

            # replace reply with an authenticated version if credentials are
            # available and the server has requested authentication
            if self._username and self._password and reply.status_code == 401:
                auth_scheme = reply.headers["WWW-Authenticate"].split(" ")[0].lower()
                if auth_scheme not in auth_map:
                    raise SevereCheckError(
                        "Unsupported authentication scheme {}".format(auth_scheme)
                    )
                auth = auth_map[auth_scheme](self._username, self._password)
                reply = session.get(self._url, timeout=self._timeout, auth=auth)

            reply.raise_for_status()
            return reply
        except requests.exceptions.RequestException as error:
            raise TemporaryCheckError(error) from error 
开发者ID:languitar,项目名称:autosuspend,代码行数:38,代码来源:util.py

示例11: async_get

# 需要导入模块: import requests_file [as 别名]
# 或者: from requests_file import FileAdapter [as 别名]
def async_get(event_loop):
    """ AsyncSession cannot be created global since it will create
        a different loop from pytest-asyncio. """
    async_session = AsyncHTMLSession()
    async_session.mount('file://', FileAdapter())
    path = os.path.sep.join((os.path.dirname(os.path.abspath(__file__)), 'python.html'))
    url = 'file://{}'.format(path)

    return partial(async_session.get, url) 
开发者ID:psf,项目名称:requests-html,代码行数:11,代码来源:test_requests_html.py

示例12: __init__

# 需要导入模块: import requests_file [as 别名]
# 或者: from requests_file import FileAdapter [as 别名]
def __init__(self, data, keys=None):
		"""
		:param dict data: The formatted repository data.
		:param keys: The keys to use for verifying remote data.
		:type keys: :py:class:`~king_phisher.security_keys.SecurityKeys`
		"""
		self.security_keys = keys or security_keys.SecurityKeys()
		"""The :py:class:`~king_phisher.security_keys.SecurityKeys` used for verifying remote data."""

		self._req_sess = requests.Session()
		self._req_sess.mount('file://', requests_file.FileAdapter())
		self.description = data.get('description')
		self.homepage = data.get('homepage')
		"""The URL of the homepage for this repository if it was specified."""
		self.id = data['id']
		"""The unique identifier of this repository."""
		self.title = data['title']
		"""The title string of this repository."""
		self.url_base = data['url-base']
		"""The base URL string of files included in this repository."""
		self.collections = utilities.FreezableDict()
		"""The dictionary of the different collection types included in this repository."""
		if 'collections-include' in data:
			# include-files is reversed so the dictionary can get .update()'ed and the first seen will be the value kept
			for include in reversed(data['collections-include']):
				include_data = self._fetch_json(include)
				utilities.validate_json_schema(include_data, 'king-phisher.catalog.collections')
				include_data = include_data['collections']
				for collection_type in include.get('types', COLLECTION_TYPES):
					collection = include_data.get(collection_type)
					if collection is None:
						continue
					self._add_collection_data(collection_type, collection)
		if 'collections' in data:
			for collection_type in COLLECTION_TYPES:
				collection = data['collections'].get(collection_type)
				if collection is None:
					continue
				self._add_collection_data(collection_type, collection)
		item_count = sum(len(collection) for collection in self.collections.values())
		self.logger.debug("initialized catalog repository with {0} collection types and {1} total items".format(len(self.collections), item_count))
		for collection_type, collection in self.collections.items():
			collection.freeze()
			self.collections[collection_type] = Collection(self, collection_type, collection)
		self.collections.freeze() 
开发者ID:rsmusllp,项目名称:king-phisher,代码行数:47,代码来源:catalog.py

示例13: Playlistparser

# 需要导入模块: import requests_file [as 别名]
# 或者: from requests_file import FileAdapter [as 别名]
def Playlistparser(self):
        try:
           s = requests.Session()
           s.mount('file://', FileAdapter())
           with s.get(config.url, headers=self.headers, proxies=config.proxies, stream=False, timeout=30) as playlist:
              if playlist.status_code != 304:
                 if playlist.encoding is None: playlist.encoding = 'utf-8'
                 playlist = playlist.json()
                 self.headers['If-Modified-Since'] = gevent.time.strftime('%a, %d %b %Y %H:%M:%S %Z', gevent.time.gmtime(self.playlisttime))
                 self.playlist = PlaylistGenerator(m3uchanneltemplate=config.m3uchanneltemplate)
                 self.picons = picons.logomap
                 self.channels = {}
                 m = requests.auth.hashlib.md5()
                 logging.info('[%s]: playlist %s downloaded' % (self.__class__.__name__, config.url))
                 try:
                    urlpattern = requests.utils.re.compile(r'^(acestream|infohash)://[0-9a-f]{40}$|^(http|https)://.*.(acelive|acestream|acemedia|torrent)$')
                    for channel in playlist['channels']:
                       name = channel['name']
                       url = 'acestream://{url}'.format(**channel)
                       channel['group'] = channel.pop('cat')
                       channel['logo'] = self.picons[name] = channel.get('logo', picons.logomap.get(name))

                       if requests.utils.re.search(urlpattern, url):
                          self.channels[name] = url
                          channel['url'] = quote(ensure_str(name),'')

                       self.playlist.addItem(channel)
                       m.update(ensure_binary(name))

                 except Exception as e:
                    logging.error("[%s]: can't parse JSON! %s" % (self.__class__.__name__, repr(e)))
                    return False

                 self.etag = '"' + m.hexdigest() + '"'
                 logging.debug('[%s]: plugin playlist generated' % self.__class__.__name__)

              self.playlisttime = gevent.time.time()

        except requests.exceptions.RequestException:
           logging.error("[%s]: can't download %s playlist!" % (self.__class__.__name__, config.url))
           return False
        except: logging.error(traceback.format_exc()); return False 
开发者ID:pepsik-kiev,项目名称:HTTPAceProxy,代码行数:44,代码来源:torrenttelik_plugin.py

示例14: Playlistparser

# 需要导入模块: import requests_file [as 别名]
# 或者: from requests_file import FileAdapter [as 别名]
def Playlistparser(self):
        try:
           s = requests.Session()
           s.mount('file://', FileAdapter())
           with s.get(config.url, headers=self.headers, proxies=config.proxies, stream=False, timeout=30) as playlist:
              if playlist.status_code != 304:
                 if playlist.encoding is None: playlist.encoding = 'utf-8'
                 playlist = playlist.json()
                 self.headers['If-Modified-Since'] = gevent.time.strftime('%a, %d %b %Y %H:%M:%S %Z', gevent.time.gmtime(self.playlisttime))
                 self.playlist = PlaylistGenerator(m3uchanneltemplate=config.m3uchanneltemplate)
                 self.picons = picons.logomap
                 self.channels = {}
                 m = requests.auth.hashlib.md5()
                 logging.info('[%s]: playlist %s downloaded' % (self.__class__.__name__, config.url))
                 try:
                    urlpattern = requests.utils.re.compile(r'^(acestream|infohash)://[0-9a-f]{40}$|^(http|https)://.*.(acelive|acestream|acemedia|torrent)$')
                    for channel in playlist['channels']:
                       name = channel['name']
                       url = 'infohash://{url}'.format(**channel)
                       channel['group'] = channel.pop('cat')
                       channel['logo'] = self.picons[name] = channel.get('logo', picons.logomap.get(name))
                       channel['tvgid'] = channel.pop('program')

                       if requests.utils.re.search(urlpattern, url):
                          self.channels[name] = url
                          channel['url'] = quote(ensure_str(name),'')

                       self.playlist.addItem(channel)
                       m.update(ensure_binary(name))

                 except Exception as e:
                    logging.error("[%s]: can't parse JSON! %s" % (self.__class__.__name__, repr(e)))
                    return False

                 self.etag = '"' + m.hexdigest() + '"'
                 logging.debug('[%s]: plugin playlist generated' % self.__class__.__name__)

              self.playlisttime = gevent.time.time()

        except requests.exceptions.RequestException:
           logging.error("[%s]: can't download %s playlist!" % (self.__class__.__name__, config.url))
           return False
        except: logging.error(traceback.format_exc()); return False 
开发者ID:pepsik-kiev,项目名称:HTTPAceProxy,代码行数:45,代码来源:frytv_plugin.py


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