本文整理汇总了Python中urllib.URLopener.close方法的典型用法代码示例。如果您正苦于以下问题:Python URLopener.close方法的具体用法?Python URLopener.close怎么用?Python URLopener.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类urllib.URLopener
的用法示例。
在下文中一共展示了URLopener.close方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: utGrabFromUrl
# 需要导入模块: from urllib import URLopener [as 别名]
# 或者: from urllib.URLopener import close [as 别名]
def utGrabFromUrl(p_url):
""" Takes a file from a remote server """
from urllib import URLopener
try:
l_opener = URLopener()
l_file = l_opener.open(p_url)
ctype = l_file.headers['Content-Type']
l_opener.close()
return (l_file.read(), ctype)
except:
return (None, 'text/x-unknown-content-type')
示例2: __init__
# 需要导入模块: from urllib import URLopener [as 别名]
# 或者: from urllib.URLopener import close [as 别名]
def __init__(self):
global dbaselocal
global datapath
fname = datapath + 'TRMM_classmap.dat'
print 'Loading class map ',fname
if dbaselocal:
landclassmap.data = np.loadtxt(fname, dtype='int')[:,1]
else:
f = URLopener().open(fname)
tmp = []
for line in f:
columns = line.split()
tmp.append(int(columns[1]))
f.close()
landclassmap.data = np.array(tmp)
landclassmap.data = np.reshape(landclassmap.data, (-1, 360))
print 'Class map loaded'
示例3: install_firmware
# 需要导入模块: from urllib import URLopener [as 别名]
# 或者: from urllib.URLopener import close [as 别名]
def install_firmware(self, new_version):
logging.info('Update firmware request')
logging.info('Current firmware version: {}'.format(
self.firmware_version))
logging.info('Firmware version to install: {}'.format(new_version))
fw_fname_prefix = 'sensa-%s' % new_version
fw_check_url = '%sstatic/firmware/%s.chk' % (
self.api_url, fw_fname_prefix)
fw_filename = fw_fname_prefix + '.zip'
fw_url = '%sstatic/firmware/%s' % (self.api_url, fw_filename)
# Firmware install shell script
deploy_script = 'deploy.sh'
# Download firmware
fw_file = URLopener()
try:
fw_file.retrieve(fw_url, fw_filename)
except IOError:
logging.error('Error during firmware download')
return 1
fw_file.close()
# Check downloaded firmware integrity
try:
fw_checksum_req = requests.get(fw_check_url)
except requests.exceptions.RequestException:
logging.error('Error during firmware download')
return 1
expected_check = fw_checksum_req.text.split()
fw_checksum = md5(open(fw_filename, 'rb').read()).hexdigest()
if(fw_checksum != expected_check[0] and
fw_filename != expected_check[1]):
logging.error('Error checking firmware integrity')
return
logging.info('Files checked. Updating')
# Unzip
try:
fw_file = ZipFile(fw_filename, 'r')
except IOError:
logging.error('Error reading local firmware file')
return
fw_file.extractall()
fw_file.close()
# Run firmware script
call(['sh', deploy_script])
# Remove firmware file
call(['rm', fw_filename])
# Remove firmware script
call(['rm', deploy_script])
config = SafeConfigParser()
config.read(self.config_file)
# Update firmware version on config file
config.set('device', 'firmware_version', new_version)
try:
conf_file = open(self.config, 'wb')
try:
parser.write(conf_file)
finally:
conf_file.close()
except IOError:
logging.error('Error updating version on config file')
'''
示例4: URLopener
# 需要导入模块: from urllib import URLopener [as 别名]
# 或者: from urllib.URLopener import close [as 别名]
f = URLopener().open(fname)
# print 'Loading data from ',fname
for line in f:
columns = line.split()
ic = int(columns[0])
ikey = tuple([int(c) for c in columns[1:3+idim]])
rr = float(columns[-17])
fracs = [float(x) for x in columns[-16:]]
dictentry = {'NCOUNT': ic, 'RR' : rr, 'FR' : fracs}
dbase_dict[cls][dbd].update({ikey : dictentry})
f.close()
print 'Done loading databases.'
print
class landclassmap:
def __init__(self):
global dbaselocal
global datapath
fname = datapath + 'TRMM_classmap.dat'
print 'Loading class map ',fname
if dbaselocal:
landclassmap.data = np.loadtxt(fname, dtype='int')[:,1]
示例5: get_facilities
# 需要导入模块: from urllib import URLopener [as 别名]
# 或者: from urllib.URLopener import close [as 别名]
def get_facilities(file):
o = URLopener().open(file)
t = o.readlines()
o.close()
return [i.split(' ')[0].lower() for i in t]