python类getpass()的实例源码

travis_pypi_setup.py 文件源码 项目:rust_pypi_example 作者: mckaymatt 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def main(args):
    public_key = fetch_public_key(args.repo)
    password = args.password or getpass('PyPI password: ')
    update_travis_deploy_password(encrypt(public_key, password.encode()))
    print("Wrote encrypted password to .travis.yml -- you're ready to deploy")
User.py 文件源码 项目:HTP 作者: nklose 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def login(self):
        db = Database()
        valid_creds = False
        attempts = 1
        while not valid_creds:
            username = raw_input('\n\tUsername: ')
            password = getpass('\tPassword: ')

            sql = 'SELECT password FROM users WHERE username = %s'
            password_hash = db.get_query(sql, [username])

            if attempts > 4:
                gc.error('\nDisconnecting after 5 failed login attempts.')
                exit()
            elif len(password_hash) == 0 or not gc.check_hash(password, password_hash[0][0]):
                time.sleep(2)
                gc.error('\nInvalid credentials. Please try again.')
                attempts += 1
            else:
                gc.success('\nCredentials validated. Logging in...')
                self.name = username
                self.lookup()
                valid_creds = True

        # close database
        db.close()
download.py 文件源码 项目:python- 作者: secondtonone1 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def handle_401(self, resp, **kwargs):
        # We only care about 401 responses, anything else we want to just
        #   pass through the actual response
        if resp.status_code != 401:
            return resp

        # We are not able to prompt the user so simply return the response
        if not self.prompting:
            return resp

        parsed = urllib_parse.urlparse(resp.url)

        # Prompt the user for a new username and password
        username = six.moves.input("User for %s: " % parsed.netloc)
        password = getpass.getpass("Password: ")

        # Store the new username and password to use for future requests
        if username or password:
            self.passwords[parsed.netloc] = (username, password)

        # Consume content and release the original connection to allow our new
        #   request to reuse the same one.
        resp.content
        resp.raw.release_conn()

        # Add our new username and password to the request
        req = HTTPBasicAuth(username or "", password or "")(resp.request)

        # Send our new request
        new_resp = resp.connection.send(req, **kwargs)
        new_resp.history.append(resp)

        return new_resp
upload.py 文件源码 项目:python- 作者: secondtonone1 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def finalize_options(self):
        orig.upload.finalize_options(self)
        self.username = (
            self.username or
            getpass.getuser()
        )
        # Attempt to obtain password. Short circuit evaluation at the first
        # sign of success.
        self.password = (
            self.password or
            self._load_password_from_keyring() or
            self._prompt_for_password()
        )
upload.py 文件源码 项目:python- 作者: secondtonone1 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def _prompt_for_password(self):
        """
        Prompt for a password on the tty. Suppress Exceptions.
        """
        try:
            return getpass.getpass()
        except (Exception, KeyboardInterrupt):
            pass
travis_pypi_setup.py 文件源码 项目:calendary 作者: DavidHickman 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def main(args):
    public_key = fetch_public_key(args.repo)
    password = args.password or getpass('PyPI password: ')
    update_travis_deploy_password(encrypt(public_key, password.encode()))
    print("Wrote encrypted password to .travis.yml -- you're ready to deploy")
download.py 文件源码 项目:my-first-blog 作者: AnkurBegining 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def handle_401(self, resp, **kwargs):
        # We only care about 401 responses, anything else we want to just
        #   pass through the actual response
        if resp.status_code != 401:
            return resp

        # We are not able to prompt the user so simply return the response
        if not self.prompting:
            return resp

        parsed = urllib_parse.urlparse(resp.url)

        # Prompt the user for a new username and password
        username = six.moves.input("User for %s: " % parsed.netloc)
        password = getpass.getpass("Password: ")

        # Store the new username and password to use for future requests
        if username or password:
            self.passwords[parsed.netloc] = (username, password)

        # Consume content and release the original connection to allow our new
        #   request to reuse the same one.
        resp.content
        resp.raw.release_conn()

        # Add our new username and password to the request
        req = HTTPBasicAuth(username or "", password or "")(resp.request)

        # Send our new request
        new_resp = resp.connection.send(req, **kwargs)
        new_resp.history.append(resp)

        return new_resp
upload.py 文件源码 项目:my-first-blog 作者: AnkurBegining 项目源码 文件源码 阅读 125 收藏 0 点赞 0 评论 0
def finalize_options(self):
        orig.upload.finalize_options(self)
        self.username = (
            self.username or
            getpass.getuser()
        )
        # Attempt to obtain password. Short circuit evaluation at the first
        # sign of success.
        self.password = (
            self.password or
            self._load_password_from_keyring() or
            self._prompt_for_password()
        )
upload.py 文件源码 项目:my-first-blog 作者: AnkurBegining 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def _prompt_for_password(self):
        """
        Prompt for a password on the tty. Suppress Exceptions.
        """
        try:
            return getpass.getpass()
        except (Exception, KeyboardInterrupt):
            pass
vsphere_inventory.py 文件源码 项目:vsphere_ansible_inventory 作者: mikesimos 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def main():

    # - Get command line args and config args.
    args = get_args()
    (filters, cache_path, cache_ttl, vcenter_host, vsphere_user, vsphere_pass, vsphere_port, cert_check) \
        = parse_config()

    # - Override settings with arg parameters if defined
    if not args.password:
        if not vsphere_pass:
            import getpass
            vsphere_pass = getpass.getpass()
        setattr(args, 'password', vsphere_pass)
    if not args.username:
        setattr(args, 'username', vsphere_user)
    if not args.hostname:
        setattr(args, 'hostname', vcenter_host)
    if not args.port:
        setattr(args, 'port', vsphere_port)
    if not args.no_cert_check:
        setattr(args, 'cert_check', cert_check)
    else:
        setattr(args, 'cert_check', False)

    # - Perform requested operations (list, host/guest, reload cache)
    if args.host or args.guest:
        print ('{}')
        exit(0)
    elif args.list or args.reload_cache:
        v = VSphere(args.hostname, args.username, args.password, vsphere_port=443, cert_check=args.cert_check)
        data = v.cached_inventory(filters, cache_path=cache_path, cache_ttl=cache_ttl, refresh=args.reload_cache)
        print ("{}".format(dumps(data)))
        exit(0)
db_convert.py 文件源码 项目:PyPlanet 作者: PyPlanet 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def handle(self, *args, **options):
        if options['source_db_password'] is None:
            options['source_db_password'] = getpass('Database Password: ')

        instance = Controller.prepare(options['pool']).instance
        converter = get_converter(
            options['source_format'], instance=instance, db_name=options['source_db_name'],
            db_type=options['source_db_type'], db_user=options['source_db_username'],
            db_port=options['source_db_port'], db_password=options['source_db_password'],
            db_host=options['source_db_host'], prefix=options['source_db_prefix']
        )

        instance.loop.run_until_complete(self.convert(instance, converter))
interactive_telegram_client.py 文件源码 项目:BitBot 作者: crack00r 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def __init__(self, session_user_id, user_phone, api_id, api_hash,
                 proxy=None):
        print_title('Initialization')

        print('Initializing interactive example...')
        super().__init__(session_user_id, api_id, api_hash, proxy)

        # Store all the found media in memory here,
        # so it can be downloaded if the user wants
        self.found_media = set()

        print('Connecting to Telegram servers...')
        if not self.connect():
            print('Initial connection failed. Retrying...')
            if not self.connect():
                print('Could not connect to Telegram servers.')
                return

        # Then, ensure we're authorized and have access
        if not self.is_user_authorized():
            print('First run. Sending code request...')
            self.send_code_request(user_phone)

            self_user = None
            while self_user is None:
                code = input('Enter the code you just received: ')
                try:
                    self_user = self.sign_in(user_phone, code)

                # Two-step verification may be enabled
                except SessionPasswordNeededError:
                    pw = getpass('Two step verification is enabled. '
                                 'Please enter your password: ')

                    self_user = self.sign_in(password=pw)
download facebook photos.py 文件源码 项目:Facebook-Photos-Download-Bot 作者: NalinG 项目源码 文件源码 阅读 36 收藏 0 点赞 0 评论 0
def __call__(self, parser, namespace, values, option_string):
        if values is None:
            values = getpass.getpass()

        setattr(namespace, self.dest, values)
urllib.py 文件源码 项目:kinect-2-libras 作者: inessadl 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def prompt_user_passwd(self, host, realm):
        """Override this in a GUI environment!"""
        import getpass
        try:
            user = raw_input("Enter username for %s at %s: " % (realm,
                                                                host))
            passwd = getpass.getpass("Enter password for %s in %s at %s: " %
                (user, realm, host))
            return user, passwd
        except KeyboardInterrupt:
            print
            return None, None


# Utility functions
user_operations.py 文件源码 项目:cbapi-python 作者: carbonblack 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def get_api_key(cb, parser, args):
    if not args.password:
        password = getpass.getpass("Password for {0}: ".format(args.username))
    else:
        password = args.password

    print("API token for user {0}: {1}".format(args.username, get_api_token(cb.credentials.url,
                                                                            args.username, password,
                                                                            verify=cb.credentials.ssl_verify)))
travis_pypi_setup.py 文件源码 项目:tokenize-uk 作者: lang-uk 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def main(args):
    public_key = fetch_public_key(args.repo)
    password = args.password or getpass('PyPI password: ')
    update_travis_deploy_password(encrypt(public_key, password.encode()))
    print("Wrote encrypted password to .travis.yml -- you're ready to deploy")
travis_pypi_setup.py 文件源码 项目:libcloud.api 作者: tonybaloney 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def main(args):
    public_key = fetch_public_key(args.repo)
    password = args.password or getpass('PyPI password: ')
    update_travis_deploy_password(encrypt(public_key, password.encode()))
    print("Wrote encrypted password to .travis.yml -- you're ready to deploy")
fabfile.py 文件源码 项目:meetup-facebook-bot 作者: Stark-Mountain 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def deploy(branch='master'):
    update_dependencies = confirm('Update dependencies?')
    print('OK, deploying branch %s' % branch)
    env.sudo_password = getpass('Initial value for env.sudo_password: ')
    fetch_sources_from_repo(branch, PROJECT_FOLDER)
    if update_dependencies:
        reinstall_venv()
        install_modules()
    start_systemctl_service(UWSGI_SERVICE_NAME)
    start_systemctl_service('nginx')
    status()
fabfile.py 文件源码 项目:meetup-facebook-bot 作者: Stark-Mountain 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def status():
    if env.sudo_password is None:
        env.sudo_password = getpass('Initial value for env.sudo_password: ')
    sudo('systemctl status %s' % UWSGI_SERVICE_NAME)


问题


面经


文章

微信
公众号

扫码关注公众号