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


Python netrc.netrc方法代码示例

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


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

示例1: test_security

# 需要导入模块: import netrc [as 别名]
# 或者: from netrc import netrc [as 别名]
def test_security(self):
        # This test is incomplete since we are normally not run as root and
        # therefore can't test the file ownership being wrong.
        d = test_support.TESTFN
        os.mkdir(d)
        self.addCleanup(test_support.rmtree, d)
        fn = os.path.join(d, '.netrc')
        with open(fn, 'wt') as f:
            f.write("""\
                machine foo.domain.com login bar password pass
                default login foo password pass
                """)
        with test_support.EnvironmentVarGuard() as environ:
            environ.set('HOME', d)
            os.chmod(fn, 0600)
            nrc = netrc.netrc()
            self.assertEqual(nrc.hosts['foo.domain.com'],
                             ('bar', None, 'pass'))
            os.chmod(fn, 0o622)
            self.assertRaises(netrc.NetrcParseError, netrc.netrc) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:22,代码来源:test_netrc.py

示例2: usage

# 需要导入模块: import netrc [as 别名]
# 或者: from netrc import netrc [as 别名]
def usage():
    print('\nHelp: {0}'.format(os.path.basename(sys.argv[0])))
    print(' -U X, --user=X\t\tUsername for NASA Earthdata Login')
    print(' -N X, --netrc=X\tPath to .netrc file for authentication')
    print(' -D X, --directory=X\tWorking data directory')
    print(' -Y X, --year=X\t\tYears to sync separated by commas')
    print(' -S X, --subdirectory=X\tSubdirectories to sync separated by commas')
    print(' --release=X\t\tICESat-2 data release to sync')
    print(' --version=X\t\tICESat-2 data version to sync')
    print(' --granule=X\t\tICESat-2 granule regions to sync')
    print(' --track=X\t\tICESat-2 reference ground tracks to sync')
    print(' --auxiliary\t\tSync ICESat-2 auxiliary files for each HDF5 file')
    print(' -F, --flatten\t\tDo not create subdirectories')
    print(' -P X, --np=X\t\tNumber of processes to use in file downloads')
    print(' -M X, --mode=X\t\tPermission mode of directories and files synced')
    print(' -L, --list\t\tOnly print files that are to be transferred')
    print(' -C, --clobber\t\tOverwrite existing data in transfer')
    print(' -l, --log\t\tOutput log file')
    today = time.strftime('%Y-%m-%d',time.localtime())
    LOGFILE = 'NSIDC_IceSat-2_sync_{0}.log'.format(today)
    print('    Log file format: {0}\n'.format(LOGFILE))

#-- Main program that calls nsidc_icesat2_sync() 
开发者ID:tsutterley,项目名称:read-ICESat-2,代码行数:25,代码来源:nsidc_icesat2_sync.py

示例3: usage

# 需要导入模块: import netrc [as 别名]
# 或者: from netrc import netrc [as 别名]
def usage():
    print('\nHelp: {0}'.format(os.path.basename(sys.argv[0])))
    print(' -U X, --user=X\t\tUsername for NASA Earthdata Login')
    print(' -N X, --netrc=X\tPath to .netrc file for authentication')
    print(' -D X, --directory=X\tWorking data directory')
    print(' -Y X, --year=X\t\tYears to sync separated by commas')
    print(' -S X, --subdirectory=X\tSubdirectories to sync separated by commas')
    print(' --release=X\t\tICESat-2 data release to sync')
    print(' --version=X\t\tICESat-2 data version to sync')
    print(' --granule=X\t\tICESat-2 granule regions to sync')
    print(' --track=X\t\tICESat-2 reference ground tracks to sync')
    print(' --auxiliary\t\tSync ICESat-2 auxiliary files for each HDF5 file')
    print(' -F, --flatten\t\tDo not create subdirectories')
    print(' -P X, --np=X\t\tNumber of processes to use in file downloads')
    print(' -M X, --mode=X\t\tPermission mode of directories and files synced')
    print(' -L, --list\t\tOnly print files that are to be transferred')
    print(' -C, --clobber\t\tOverwrite existing data in transfer')
    print(' -l, --log\t\tOutput log file')
    today = time.strftime('%Y-%m-%d',time.localtime())
    LOGFILE = 'NSIDC_IceSat-2_sync_{0}.log'.format(today)
    print('    Log file format: {0}\n'.format(LOGFILE))

#-- Main program that calls nsidc_icesat2_zarr() 
开发者ID:tsutterley,项目名称:read-ICESat-2,代码行数:25,代码来源:nsidc_icesat2_zarr.py

示例4: _get_netrc_login_info

# 需要导入模块: import netrc [as 别名]
# 或者: from netrc import netrc [as 别名]
def _get_netrc_login_info(self, netrc_machine=None):
        username = None
        password = None
        netrc_machine = netrc_machine or self._NETRC_MACHINE

        if self._downloader.params.get('usenetrc', False):
            try:
                info = netrc.netrc().authenticators(netrc_machine)
                if info is not None:
                    username = info[0]
                    password = info[2]
                else:
                    raise netrc.NetrcParseError(
                        'No authenticators for %s' % netrc_machine)
            except (IOError, netrc.NetrcParseError) as err:
                self._downloader.report_warning(
                    'parsing .netrc: %s' % error_to_compat_str(err))

        return username, password 
开发者ID:tvalacarta,项目名称:tvalacarta,代码行数:21,代码来源:common.py

示例5: _get_login_info

# 需要导入模块: import netrc [as 别名]
# 或者: from netrc import netrc [as 别名]
def _get_login_info(self, username_option='username', password_option='password', netrc_machine=None):
        """
        Get the login info as (username, password)
        First look for the manually specified credentials using username_option
        and password_option as keys in params dictionary. If no such credentials
        available look in the netrc file using the netrc_machine or _NETRC_MACHINE
        value.
        If there's no info available, return (None, None)
        """
        if self._downloader is None:
            return (None, None)

        downloader_params = self._downloader.params

        # Attempt to use provided username and password or .netrc data
        if downloader_params.get(username_option) is not None:
            username = downloader_params[username_option]
            password = downloader_params[password_option]
        else:
            username, password = self._get_netrc_login_info(netrc_machine)

        return username, password 
开发者ID:tvalacarta,项目名称:tvalacarta,代码行数:24,代码来源:common.py

示例6: check_login

# 需要导入模块: import netrc [as 别名]
# 或者: from netrc import netrc [as 别名]
def check_login(self):
        """
        Check if user logged in. If True - return login and token, else returns None
        """
        netrc_path = os.path.join(os.path.expanduser('~'), '.netrc')
        if not os.path.exists(netrc_path):
            open(netrc_path, 'w').close()
        info = netrc.netrc()
        login, account, password = info.authenticators(STASH_HOST) or (None, None, None)
        if password and login:
            if self.username is None or self.token is None:
                self.username = login
                # todo: why token is equal to password?
                self.token = password
            return login, password
        return None 
开发者ID:nyddle,项目名称:pystash,代码行数:18,代码来源:web.py

示例7: login

# 需要导入模块: import netrc [as 别名]
# 或者: from netrc import netrc [as 别名]
def login(self, login, password):
        if self.check_login() is not None:
            raise AlreadyLoggedIn
        m = hashlib.new('md5')
        m.update(password)
        r = self.get_token(login, password)
        #TODO check if r is an error (remove  / from stash host for example) 
        if 'token' in r:
            # todo: maybe we don't need this two lines?
            self.username = login
            self.token = r['token']
            with open(os.path.join(os.environ['HOME'], ".netrc"), "a") as f:
                f.write("machine " + STASH_HOST + " login " + login + " password " + str(r['token']) + "\n")
                f.close()
        else:
            # todo: do something
            pass
        if 'error' in r:
            raise Exception(r['error'])
        return True 
开发者ID:nyddle,项目名称:pystash,代码行数:22,代码来源:web.py

示例8: make_nrc

# 需要导入模块: import netrc [as 别名]
# 或者: from netrc import netrc [as 别名]
def make_nrc(self, test_data, cleanup=True):
        test_data = textwrap.dedent(test_data)
        mode = 'w'
        if sys.platform != 'cygwin':
            mode += 't'
        with open(temp_filename, mode) as fp:
            fp.write(test_data)
        if cleanup:
            self.addCleanup(os.unlink, temp_filename)
        return netrc.netrc(temp_filename) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:12,代码来源:test_netrc.py

示例9: usage

# 需要导入模块: import netrc [as 别名]
# 或者: from netrc import netrc [as 别名]
def usage():
    print('\nHelp: {0}'.format(os.path.basename(sys.argv[0])))
    print(' -U X, --user=X\t\tUsername for NASA Earthdata Login')
    print(' -N X, --netrc=X\t\tPath to .netrc file for authentication')
    print(' -D X, --directory=X\tOutput data directory')
    print(' -P X, --product=X\tICESat-2 product to download')
    print(' --auxiliary\t\tSync ICESat-2 auxiliary files for each HDF5 file')
    print(' -M X, --mode=X\t\tPermission mode of files downloaded\n')

#-- Main program that calls nsidc_icesat2_associated() 
开发者ID:tsutterley,项目名称:read-ICESat-2,代码行数:12,代码来源:nsidc_icesat2_associated.py

示例10: make_nrc

# 需要导入模块: import netrc [as 别名]
# 或者: from netrc import netrc [as 别名]
def make_nrc(self, test_data):
        test_data = textwrap.dedent(test_data)
        mode = 'w'
        if sys.platform != 'cygwin':
            mode += 't'
        with open(temp_filename, mode) as fp:
            fp.write(test_data)
        return netrc.netrc(temp_filename) 
开发者ID:dxwu,项目名称:BinderFilter,代码行数:10,代码来源:test_netrc.py

示例11: make_nrc

# 需要导入模块: import netrc [as 别名]
# 或者: from netrc import netrc [as 别名]
def make_nrc(self, test_data):
        test_data = textwrap.dedent(test_data)
        mode = 'w'
        if sys.platform != 'cygwin':
            mode += 't'
        with open(temp_filename, mode) as fp:
            fp.write(test_data)
        self.addCleanup(os.unlink, temp_filename)
        return netrc.netrc(temp_filename) 
开发者ID:aliyun,项目名称:oss-ftp,代码行数:11,代码来源:test_netrc.py

示例12: __init__

# 需要导入模块: import netrc [as 别名]
# 或者: from netrc import netrc [as 别名]
def __init__(self):
        self.netrc_file = os.path.join(os.path.expanduser('~'), '.netrc')
        if not os.path.exists(self.netrc_file):
            open(self.netrc_file, 'a').close()
            # Setting mode for the file:
            os.chmod(self.netrc_file, stat.S_IWUSR | stat.S_IRUSR)
        self.is_secured()
        self.netrc_obj = netrc.netrc(self.netrc_file) 
开发者ID:VUIIS,项目名称:dax,代码行数:10,代码来源:dax_settings.py

示例13: get_hosts

# 需要导入模块: import netrc [as 别名]
# 或者: from netrc import netrc [as 别名]
def get_hosts(self):
        """ Rerutn list of hosts from netrc file."""
        return list(self.netrc_obj.hosts.keys()) 
开发者ID:VUIIS,项目名称:dax,代码行数:5,代码来源:dax_settings.py

示例14: cli

# 需要导入模块: import netrc [as 别名]
# 或者: from netrc import netrc [as 别名]
def cli():
    """ command line interface to store different NETRC credentials
    call via 'oggm_netrc_credentials'
    """

    print('This will store login credentials in a local .netrc file.\n'
          'Enter the number or the service you want to add credentials for, '
          'this might override existing credentials in the .netrc file!\n\n'
          '[0] urs.earthdata.nasa.gov, ASTER DEM\n'
          '[1] geoservice.dlr.de, TanDEM-X\n'
          '[2] spacedata.copernicus.eu, Copernicus DEM Glo-90\n\n')
    nr = input("Number: ")

    if nr == '0':
        key = 'urs.earthdata.nasa.gov'
        testurl = ('https://e4ftl01.cr.usgs.gov//ASTER_B/ASTT/ASTGTM.003/' +
                   '2000.03.01/ASTGTMV003_S09W158.zip')

    elif nr == '1':
        key = 'geoservice.dlr.de'
        testurl = ("https://download.geoservice.dlr.de" +
                   "/TDM90/files/N57/E000/TDM1_DEM__30_N57E006.zip")

    elif nr == '2':
        key = 'spacedata.copernicus.eu'
        testurl = 'ftps://cdsdata.copernicus.eu:990'

    else:
        print('Not a valid number, aborting.')
        sys.exit(-1)

    read_credentials(key, testurl) 
开发者ID:OGGM,项目名称:oggm,代码行数:34,代码来源:netrc_credentials.py

示例15: raise_login_required

# 需要导入模块: import netrc [as 别名]
# 或者: from netrc import netrc [as 别名]
def raise_login_required(msg='This video is only available for registered users'):
        raise ExtractorError(
            '%s. Use --username and --password or --netrc to provide account credentials.' % msg,
            expected=True) 
开发者ID:tvalacarta,项目名称:tvalacarta,代码行数:6,代码来源:common.py


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