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")
python类getpass()的实例源码
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()
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
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()
)
def _prompt_for_password(self):
"""
Prompt for a password on the tty. Suppress Exceptions.
"""
try:
return getpass.getpass()
except (Exception, KeyboardInterrupt):
pass
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")
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
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()
)
def _prompt_for_password(self):
"""
Prompt for a password on the tty. Suppress Exceptions.
"""
try:
return getpass.getpass()
except (Exception, KeyboardInterrupt):
pass
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)
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))
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)
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
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)))
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")
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")
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()
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)