本文整理匯總了Python中getpass.GetPassWarning方法的典型用法代碼示例。如果您正苦於以下問題:Python getpass.GetPassWarning方法的具體用法?Python getpass.GetPassWarning怎麽用?Python getpass.GetPassWarning使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類getpass
的用法示例。
在下文中一共展示了getpass.GetPassWarning方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: run_extract
# 需要導入模塊: import getpass [as 別名]
# 或者: from getpass import GetPassWarning [as 別名]
def run_extract(self, args: argparse.Namespace) -> int:
target = args.arcfile
verbose = args.verbose
if not py7zr.is_7zfile(target):
print('not a 7z file')
return(1)
if not args.password:
password = None # type: Optional[str]
else:
try:
password = getpass.getpass()
except getpass.GetPassWarning:
sys.stderr.write('Warning: your password may be shown.\n')
return(1)
a = py7zr.SevenZipFile(target, 'r', password=password)
cb = None # Optional[ExtractCallback]
if verbose:
archive_info = a.archiveinfo()
cb = CliExtractCallback(total_bytes=archive_info.uncompressed, ofd=sys.stderr)
if args.odir:
a.extractall(path=args.odir, callback=cb)
else:
a.extractall(callback=cb)
return(0)
示例2: fix_get_pass
# 需要導入模塊: import getpass [as 別名]
# 或者: from getpass import GetPassWarning [as 別名]
def fix_get_pass():
try:
import getpass
except ImportError:
return #If we can't import it, we can't fix it
import warnings
fallback = getattr(getpass, 'fallback_getpass', None) # >= 2.6
if not fallback:
fallback = getpass.default_getpass # <= 2.5
getpass.getpass = fallback
if hasattr(getpass, 'GetPassWarning'):
warnings.simplefilter("ignore", category=getpass.GetPassWarning)
示例3: test_falls_back_to_stdin
# 需要導入模塊: import getpass [as 別名]
# 或者: from getpass import GetPassWarning [as 別名]
def test_falls_back_to_stdin(self):
with mock.patch('os.open') as os_open, \
mock.patch('sys.stdin', spec=StringIO) as stdin:
os_open.side_effect = IOError
stdin.fileno.side_effect = AttributeError
with support.captured_stderr() as stderr:
with self.assertWarns(getpass.GetPassWarning):
getpass.unix_getpass()
stdin.readline.assert_called_once_with()
self.assertIn('Warning', stderr.getvalue())
self.assertIn('Password:', stderr.getvalue())
示例4: fix_getpass
# 需要導入模塊: import getpass [as 別名]
# 或者: from getpass import GetPassWarning [as 別名]
def fix_getpass():
try:
import getpass
except ImportError:
return #If we can't import it, we can't fix it
import warnings
fallback = getattr(getpass, 'fallback_getpass', None) # >= 2.6
if not fallback:
fallback = getpass.default_getpass # <= 2.5 @UndefinedVariable
getpass.getpass = fallback
if hasattr(getpass, 'GetPassWarning'):
warnings.simplefilter("ignore", category=getpass.GetPassWarning)