def generate(url):
parts = ['''\
"""
webencodings.labels
~~~~~~~~~~~~~~~~~~~
Map encoding labels to their name.
:copyright: Copyright 2012 by Simon Sapin
:license: BSD, see LICENSE for details.
"""
# XXX Do not edit!
# This file is automatically generated by mklabels.py
LABELS = {
''']
labels = [
(repr(assert_lower(label)).lstrip('u'),
repr(encoding['name']).lstrip('u'))
for category in json.loads(urlopen(url).read().decode('ascii'))
for encoding in category['encodings']
for label in encoding['labels']]
max_len = max(len(label) for label, name in labels)
parts.extend(
' %s:%s %s,\n' % (label, ' ' * (max_len - len(label)), name)
for label, name in labels)
parts.append('}')
return ''.join(parts)
python类urlopen()的实例源码
def get_global_usage (api_url, query_string_dict, title_list) :
usage_dict_ = dict()
usage_dict_["image"] = dict()
usage_dict_["article"] = dict()
raw_api_query_string = unicode(u'|'.join(title_list)).encode('utf-8')
#print raw_api_query_string
API_QUERY_STRING["titles"] = raw_api_query_string
f = urlopen(API_BASE_URL, urlencode(API_QUERY_STRING))
response = f.read()
response_dict = json.loads(response)
for key, value in response_dict["query"]["pages"].iteritems():
if len(value[u'globalusage']) > 0:
#print value
found_dict = dict()
for item in value[u'globalusage']:
if (item[u'ns'] == u'0') or (item[u'ns'] == u'104'):
if item[u'wiki'] in usage_dict_["article"]:
usage_dict_["article"][item[u'wiki']] += 1
else:
usage_dict_["article"][item[u'wiki']] = 1
found_dict[item[u'wiki']] = True
for key, value in found_dict.iteritems():
if key in usage_dict_["image"]:
usage_dict_["image"][key] += 1
else:
usage_dict_["image"][key] = 1
#print usage_dict_
return usage_dict_
def GetHTTPFileContents( url ):
fileContents = None
try:
filehandle = urllib.urlopen( url )
return filehandle.read()
except:
logging.warning("connection cannot be made to" + url)
return
def prepare_input_source(source, base = ""):
"""This function takes an InputSource and an optional base URL and
returns a fully resolved InputSource object ready for reading."""
if type(source) in _StringTypes:
source = xmlreader.InputSource(source)
elif hasattr(source, "read"):
f = source
source = xmlreader.InputSource()
source.setByteStream(f)
if hasattr(f, "name"):
source.setSystemId(f.name)
if source.getByteStream() is None:
sysid = source.getSystemId()
basehead = os.path.dirname(os.path.normpath(base))
sysidfilename = os.path.join(basehead, sysid)
if os.path.isfile(sysidfilename):
source.setSystemId(sysidfilename)
f = open(sysidfilename, "rb")
else:
source.setSystemId(urlparse.urljoin(base, sysid))
f = urllib.urlopen(source.getSystemId())
source.setByteStream(f)
return source
def fetch_public_key(repo):
"""Download RSA public key Travis will use for this repo.
Travis API docs: http://docs.travis-ci.com/api/#repository-keys
"""
keyurl = 'https://api.travis-ci.org/repos/{0}/key'.format(repo)
data = json.loads(urlopen(keyurl).read().decode())
if 'key' not in data:
errmsg = "Could not find public key for repo: {}.\n".format(repo)
errmsg += "Have you already added your GitHub repo to Travis?"
raise ValueError(errmsg)
return data['key']
def download(file_url,local_filename):
web_file = urllib.urlopen(file_url)
local_file = open(local_filename, 'w')
local_file.write(web_file.read())
web_file.close()
local_file.close()
def download(file_url,local_filename):
web_file = urllib.urlopen(file_url)
local_file = open(local_filename, 'w')
local_file.write(web_file.read())
web_file.close()
local_file.close()
def check():
response = urlopen('https://raw.githubusercontent.com/D4Vinci/Dr0p1t-Framework/master/core/version.txt')
version = response.read().decode('utf-8').strip()
f = open( os.path.join("core","version.txt"), 'r')
file_data = f.read().strip()
if version != file_data:
colored_print('\n[*] New Version available ! Visit: https://github.com/D4Vinci/Dr0p1t-Framework\n',"y")
else:
colored_print('[*] Your version is up-to-date ;)',"b")
def fetch_public_key(repo):
"""Download RSA public key Travis will use for this repo.
Travis API docs: http://docs.travis-ci.com/api/#repository-keys
"""
keyurl = 'https://api.travis-ci.org/repos/{0}/key'.format(repo)
data = json.loads(urlopen(keyurl).read().decode())
if 'key' not in data:
errmsg = "Could not find public key for repo: {}.\n".format(repo)
errmsg += "Have you already added your GitHub repo to Travis?"
raise ValueError(errmsg)
return data['key']
def command_nick(current_buffer, args):
pass
# urllib.urlopen("https://%s/account/settings" % (domain))
# browser.select_form(nr=0)
# browser.form['username'] = args
# reply = browser.submit()
def fetch_public_key(repo):
"""Download RSA public key Travis will use for this repo.
Travis API docs: http://docs.travis-ci.com/api/#repository-keys
"""
keyurl = 'https://api.travis-ci.org/repos/{0}/key'.format(repo)
data = json.loads(urlopen(keyurl).read().decode())
if 'key' not in data:
errmsg = "Could not find public key for repo: {}.\n".format(repo)
errmsg += "Have you already added your GitHub repo to Travis?"
raise ValueError(errmsg)
return data['key']
def get_html(url):
"""Get the html """
page = urllib.urlopen(url)
html = page.read()
return html
def get_html(url):
"""Get the html """
page = urllib.urlopen(url)
html = page.read()
return html
def get_html(url):
"""Get the html """
page = urllib.urlopen(url)
html = page.read()
return html
def get_html(url):
"""Get the html """
page = urllib.urlopen(url)
html = page.read()
return html
def get_html(url):
"""Get the html """
page = urllib.urlopen(url)
html = page.read()
return html
def get_html(url):
"""Get the html """
page = urllib.urlopen(url)
html = page.read()
return html
def get_html(url):
"""Get the html """
page = urllib.urlopen(url)
html = page.read()
return html
def get_html(url):
"""Get the html """
page = urllib.urlopen(url)
html = page.read()
return html
def get_html(url):
"""Get the html """
page = urllib.urlopen(url)
html = page.read()
return html