本文整理汇总了Python中urllib.response方法的典型用法代码示例。如果您正苦于以下问题:Python urllib.response方法的具体用法?Python urllib.response怎么用?Python urllib.response使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类urllib
的用法示例。
在下文中一共展示了urllib.response方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: checkPlugins
# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import response [as 别名]
def checkPlugins(self):
try:
with self._send("GET", "pluginManager/api/python?depth=1") as response:
plugins = ast.literal_eval(response.read().decode("utf8"))["plugins"]
required = set(requiredPlugins.keys())
for p in plugins:
if p["shortName"] not in required: continue
if not p["active"] or not p["enabled"]:
raise BuildError("Plugin not enabled: " + requiredPlugins[p["shortName"]])
required.remove(p["shortName"])
if required:
raise BuildError("Missing plugin(s): " + ", ".join(
requiredPlugins[p] for p in required))
except BuildError:
raise
except urllib.error.HTTPError as e:
print("Warning: could not verify plugins: HTTP error: {} {}"
.format(e.code, e.reason),
file=sys.stderr)
except:
raise BuildError("Malformed Jenkins response while checking plugins!")
示例2: fetchConfig
# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import response [as 别名]
def fetchConfig(self, name):
try:
with self._send("GET", "job/" + name + "/config.xml") as response:
return response.read()
except urllib.error.HTTPError as e:
if e.code == 404:
return None
raise BuildError("Warning: could not download '{}' job config: HTTP error: {} {}"
.format(name, e.code, e.reason))
示例3: test_urllib_imports_moves
# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import response [as 别名]
def test_urllib_imports_moves(self):
import future.moves.urllib
import future.moves.urllib.parse
import future.moves.urllib.request
import future.moves.urllib.robotparser
import future.moves.urllib.error
import future.moves.urllib.response
self.assertTrue(True)
示例4: test_urllib_imports_install_aliases
# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import response [as 别名]
def test_urllib_imports_install_aliases(self):
with standard_library.suspend_hooks():
standard_library.install_aliases()
import urllib
import urllib.parse
import urllib.request
import urllib.robotparser
import urllib.error
import urllib.response
self.assertTrue(True)
示例5: test_urllib_imports_cm
# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import response [as 别名]
def test_urllib_imports_cm(self):
with standard_library.hooks():
import urllib
import urllib.parse
import urllib.request
import urllib.robotparser
import urllib.error
import urllib.response
self.assertTrue(True)
示例6: test_urllib_imports_install_hooks
# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import response [as 别名]
def test_urllib_imports_install_hooks(self):
standard_library.remove_hooks()
standard_library.install_hooks()
import urllib
import urllib.parse
import urllib.request
import urllib.robotparser
import urllib.error
import urllib.response
self.assertTrue(True)
示例7: test_install_aliases
# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import response [as 别名]
def test_install_aliases(self):
"""
Does the install_aliases() interface monkey-patch urllib etc. successfully?
"""
from future.standard_library import remove_hooks, install_aliases
remove_hooks()
install_aliases()
from collections import Counter, OrderedDict # backported to Py2.6
from collections import UserDict, UserList, UserString
# Requires Python dbm support:
# import dbm
# import dbm.dumb
# import dbm.gnu
# import dbm.ndbm
from itertools import filterfalse, zip_longest
from subprocess import check_output # backported to Py2.6
from subprocess import getoutput, getstatusoutput
from sys import intern
# test_support may not be available (e.g. on Anaconda Py2.6):
# import test.support
import urllib.error
import urllib.parse
import urllib.request
import urllib.response
import urllib.robotparser
self.assertTrue('urlopen' in dir(urllib.request))
示例8: test_urllib
# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import response [as 别名]
def test_urllib(self):
"""
Tests that urllib isn't changed from under our feet. (This might not
even be a problem?)
"""
from future import standard_library
import urllib
orig_file = urllib.__file__
with standard_library.hooks():
import urllib.response
self.assertEqual(orig_file, urllib.__file__)
示例9: _json
# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import response [as 别名]
def _json(url):
with closing(urllib2.urlopen(url)) as response:
if response.code >= 300 and response.code <= 307:
# Pause currently playing Quasar file to avoid doubling requests
if xbmc.Player().isPlaying() and ADDON_ID in xbmc.Player().getPlayingFile():
xbmc.Player().pause()
_infoLabels = InfoLabels(getInfoLabels())
item = xbmcgui.ListItem(
path=response.geturl(),
label=_infoLabels["label"],
label2=_infoLabels["label2"])
item.setArt({
"thumb": _infoLabels["artthumb"],
"poster": _infoLabels["artposter"],
"tvshowposter": _infoLabels["arttvshowposter"],
"banner": _infoLabels["artbanner"],
"fanart": _infoLabels["artfanart"],
"clearart": _infoLabels["artclearart"],
"clearlogo": _infoLabels["artclearlogo"],
"landscape": _infoLabels["artlandscape"],
"icon": _infoLabels["articon"]
})
item.setInfo(type='Video', infoLabels=_infoLabels)
xbmcplugin.setResolvedUrl(HANDLE, True, item)
return
payload = response.read()
try:
if payload:
return json.loads(payload)
except:
raise Exception(payload)
示例10: __init__
# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import response [as 别名]
def __init__(self, config, sslVerify):
self.__config = config
url = self.__config["url"]
self.__headers = { "Content-Type": "application/xml" }
self.__root = "{}://{}{}{}".format(url['scheme'], url['server'],
":{}".format(url['port']) if url.get('port') else "", url['path'])
handlers = []
# Handle cookies
cookies = http.cookiejar.CookieJar()
handlers.append(urllib.request.HTTPCookieProcessor(cookies))
# Optionally disable SSL certificate checks
if not sslVerify:
handlers.append(urllib.request.HTTPSHandler(
context=ssl.SSLContext(ssl.PROTOCOL_SSLv23)))
# handle authorization
username = url.get("username")
if username is not None:
username = urllib.parse.unquote(username)
passwd = url.get("password")
if passwd is None:
passwd = getpass.getpass()
else:
passwd = urllib.parse.unquote(passwd)
userPass = username + ":" + passwd
self.__headers['Authorization'] = 'Basic ' + base64.b64encode(
userPass.encode("utf-8")).decode("ascii")
# remember basic settings
self.__opener = urllib.request.build_opener(*handlers)
# get CSRF token
try:
with self._send("GET", "crumbIssuer/api/xml") as response:
resp = xml.etree.ElementTree.fromstring(response.read())
crumb = resp.find("crumb").text
field = resp.find("crumbRequestField").text
self.__headers[field] = crumb
except urllib.error.HTTPError:
pass
示例11: getInfoLabels
# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import response [as 别名]
def getInfoLabels():
id_list = [int(s) for s in sys.argv[0].split("/") if s.isdigit()]
tmdb_id = id_list[0] if id_list else None
if not tmdb_id:
parsed_url = urlparse.urlparse(sys.argv[0] + sys.argv[2])
query = urlparse.parse_qs(parsed_url.query)
log.debug("Parsed URL: %s, Query: %s", repr(parsed_url), repr(query))
if 'tmdb' in query and 'type' in query and query['type'][0] == 'movie':
tmdb_id = query['tmdb'][0]
url = "%s/movie/%s/infolabels" % (QUASARD_HOST, tmdb_id)
elif 'show' in query:
tmdb_id = query['show'][0]
if 'season' in query and 'episode' in query:
url = "%s/show/%s/season/%s/episode/%s/infolabels" % (QUASARD_HOST, tmdb_id, query['season'][0], query['episode'][0])
else:
url = "%s/show/%s/infolabels" % (QUASARD_HOST, tmdb_id)
else:
url = "%s/infolabels" % (QUASARD_HOST)
elif 'movie' in sys.argv[0]:
url = "%s/movie/%s/infolabels" % (QUASARD_HOST, tmdb_id)
elif ('episode' in sys.argv[0] or 'show' in sys.argv[0]) and len(id_list) > 2:
url = "%s/show/%s/season/%s/episode/%s/infolabels" % (QUASARD_HOST, tmdb_id, id_list[1], id_list[2])
elif 'show' in sys.argv[0] and len(id_list) == 2:
url = "%s/show/%s/season/%s/episode/%s/infolabels" % (QUASARD_HOST, tmdb_id, id_list[1], 1)
else:
url = "%s/infolabels" % (QUASARD_HOST)
log.debug("Resolving TMDB item by calling %s for %s" % (url, repr(sys.argv)))
try:
with closing(urllib2.urlopen(url)) as response:
resolved = json.loads(response.read(), parse_int=str)
if not resolved:
return {}
if 'info' in resolved and resolved['info']:
resolved.update(resolved['info'])
if 'art' in resolved and resolved['art']:
resolved['artbanner'] = ''
for k, v in list(resolved['art'].items()):
resolved['art' + k] = v
if 'info' in resolved:
del resolved['info']
if 'art' in resolved:
del resolved['art']
if 'stream_info' in resolved:
del resolved['stream_info']
if 'dbtype' not in resolved:
resolved['dbtype'] = 'video'
if 'mediatype' not in resolved or resolved['mediatype'] == '':
resolved['Mediatype'] = resolved['dbtype']
return resolved
except:
log.debug("Could not resolve TMDB item: %s" % tmdb_id)
return {}