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


Python URLopener.close方法代码示例

本文整理汇总了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')
开发者ID:eea,项目名称:Products.Reportek,代码行数:13,代码来源:RepUtils.py

示例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'      
开发者ID:gpetty,项目名称:TRMM,代码行数:24,代码来源:UW_TMIrain.py

示例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')

        '''
开发者ID:alealmuna,项目名称:sensa-client,代码行数:68,代码来源:sensa.py

示例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]
开发者ID:gpetty,项目名称:TRMM,代码行数:33,代码来源:UW_TMIrain.py

示例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]
开发者ID:augustfly,项目名称:astrodatacite,代码行数:7,代码来源:ads_DatasetID.py


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