本文整理汇总了Python中pwman.util.config.get_value函数的典型用法代码示例。如果您正苦于以下问题:Python get_value函数的具体用法?Python get_value怎么用?Python get_value使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_value函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self):
"""Initialise the Cryptographic Engine
params is a dictionary. Valid keys are:
algorithm: Which cipher to use
callback: Callback class.
keycrypted: This should be set by the database layer.
timeout: Time after which key will be forgotten.
Default is -1 (disabled).
"""
algo = config.get_value("Encryption", "algorithm")
if len(algo) > 0:
self._algo = algo
else:
raise CryptoException("Parameters missing, no algorithm given")
callback = config.get_value("Encryption", "callback")
if isinstance(callback, Callback):
self._callback = callback
else:
self._callback = None
keycrypted = config.get_value("Encryption", "keycrypted")
if len(keycrypted) > 0:
self._keycrypted = keycrypted
else:
self._keycrypted = None
timeout = config.get_value("Encryption", "timeout")
if timeout.isdigit():
self._timeout = timeout
else:
self._timeout = -1
self._cipher = None
示例2: get
def get(cls, dbver=0.5):
"""
CryptoEngine.get() -> CryptoEngine
Return an instance of CryptoEngine.
If no instance is found, a CryptoException is raised.
"""
if CryptoEngine._instance:
return CryptoEngine._instance
if CryptoEngine._instance_new:
return CryptoEngine._instance_new
keycrypted = config.get_value("Encryption", "keycrypted")
algo = config.get_value("Encryption", "algorithm")
if not algo:
raise CryptoException("Parameters missing, no algorithm given")
try:
timeout = int(config.get_value("Encryption", "timeout"))
except ValueError:
timeout = -1
kwargs = {'keycrypted': keycrypted, 'algorithm': algo,
'timeout': timeout}
if dbver < 0.5:
CryptoEngine._instance = CryptoEngineOld(**kwargs)
return CryptoEngine._instance
if dbver >= 0.5:
CryptoEngine._instance_new = CryptoEngine(**kwargs)
return CryptoEngine._instance_new
示例3: __init__
def __init__(self, args, config):
self.dbname = config.get_value('Database', 'filename')
self.dbtype = config.get_value("Database", "type")
if not args.output:
self.newdb_name = self.dbname
else:
self.newdb_name = '.new-%s'.join(os.path.splitext(self.dbname))
示例4: get_pass_conf
def get_pass_conf():
numerics = config.get_value("Generator", "numerics").lower() == 'true'
# TODO: allow custom leetifying through the config
leetify = config.get_value("Generator", "leetify").lower() == 'true'
special_chars = config.get_value("Generator", "special_chars"
).lower() == 'true'
return numerics, leetify, special_chars
示例5: clean
def clean(self):
if os.path.exists(config.get_value('Database', 'filename')):
os.remove(config.get_value('Database', 'filename'))
if os.path.exists(os.path.join(os.path.dirname(__file__),
'testing_config')):
os.remove(os.path.join(os.path.dirname(__file__),
'testing_config'))
示例6: get_password
def get_password(self, default=""):
password = getpassword("Password (Blank to generate): ", _defaultwidth, False)
if len(password) == 0:
length = getinput("Password length (default 7): ", "7")
length = int(length)
numerics = config.get_value("Generator", "numerics") == 'true';
leetify = config.get_value("Generator", "leetify") == 'true';
(password, dumpme) = generator.generate_password(length, length, True, leetify, numerics)
print "New password: %s" % (password)
return password
else:
return password
示例7: get_conf_options
def get_conf_options(args, OSX):
config = get_conf_file(args)
xselpath = config.get_value("Global", "xsel")
if not xselpath:
set_xsel(config, OSX)
set_win_colors(config)
set_db(args)
set_umask(config)
set_algorithm(args, config)
dbtype = config.get_value("Database", "type")
if not dbtype:
raise Exception("Could not read the Database type from the config!")
return xselpath, dbtype
示例8: print_node
def print_node(self, node):
width = str(tools._defaultwidth)
print "Node %d." % (node.get_id())
print ("%" + width + "s %s") % (tools.typeset("Username:", Fore.RED), node.get_username())
print ("%" + width + "s %s") % (tools.typeset("Password:", Fore.RED), node.get_password())
print ("%" + width + "s %s") % (tools.typeset("Url:", Fore.RED), node.get_url())
print ("%" + width + "s %s") % (tools.typeset("Notes:", Fore.RED), node.get_notes())
print tools.typeset("Tags: ", Fore.RED),
for t in node.get_tags():
print " %s " % t
print
def heardEnter():
i, o, e = uselect.select([sys.stdin], [], [], 0.0001)
for s in i:
if s == sys.stdin:
sys.stdin.readline()
return True
return False
def waituntil_enter(somepredicate, timeout, period=0.25):
mustend = time.time() + timeout
while time.time() < mustend:
cond = somepredicate()
if cond:
break
time.sleep(period)
self.do_cls("")
flushtimeout = int(config.get_value("Global", "cls_timeout"))
if flushtimeout > 0:
print "Type Enter to flush screen (autoflash in " + "%d sec.)" % flushtimeout
waituntil_enter(heardEnter, flushtimeout)
示例9: print_node
def print_node(self, node):
width = tools._defaultwidth
print("Node {}.".format(node._id))
print("{} {}".format(tools.typeset("Username:", Fore.RED).ljust(width),
node.username))
print ("{} {}".format(tools.typeset("Password:", Fore.RED).ljust(width),
node.password))
print("{} {}".format(tools.typeset("Url:", Fore.RED).ljust(width), node.url))
print("{} {}".format(tools.typeset("Notes:", Fore.RED).ljust(width), node.notes))
print("{}".format(tools.typeset("Tags: ", Fore.RED)), end=" ")
for t in node.tags:
print(t)
def heardEnterWin():
c = msvcrt.kbhit()
if c == 1:
ret = msvcrt.getch()
if ret is not None:
return True
return False
def waituntil_enter(somepredicate, timeout, period=0.25):
mustend = time.time() + timeout
while time.time() < mustend:
cond = somepredicate()
if cond:
break
time.sleep(period)
self.do_cls('')
flushtimeout = int(config.get_value("Global", "cls_timeout"))
if flushtimeout > 0:
print("Press any key to flush screen (autoflash "
"in %d sec.)" % flushtimeout)
waituntil_enter(heardEnterWin, flushtimeout)
示例10: __init__
def __init__(self, db, hasxsel, callback):
"""
initialize CLI interface, set up the DB
connecion, see if we have xsel ...
"""
cmd.Cmd.__init__(self)
self.intro = "%s %s (c) visit: %s" % (pwman.appname, pwman.version, pwman.website)
self._historyfile = config.get_value("Readline", "history")
self.hasxsel = hasxsel
try:
enc = CryptoEngine.get()
enc._callback = callback()
self._db = db
# this cascades down all the way to setting the database key
self._db.open()
except Exception as e: # pragma: no cover
self.error(e)
sys.exit(1)
try:
readline.read_history_file(self._historyfile)
except IOError as e: # pragma: no cover
pass
self.prompt = "pwman> "
示例11: setUp
def setUp(self):
"test that the right db instance was created"
dbver = __DB_FORMAT__
self.dbtype = config.get_value("Database", "type")
self.db = factory.create(self.dbtype, dbver)
self.tester = SetupTester(dbver)
self.tester.create()
示例12: do_set
def do_set(self, args):
argstrs = args.split()
try:
if len(argstrs) == 0:
conf = config.get_conf()
for s in conf.keys():
for n in conf[s].keys():
print ("%s.%s = %s" % (s, n, conf[s][n]))
elif len(argstrs) == 1:
r = re.compile("(.+)\.(.+)")
m = r.match(argstrs[0])
if m is None or len(m.groups()) != 2:
print ("Invalid option format")
self.help_set()
return
print ("%s.%s = %s" % (m.group(1), m.group(2),
config.get_value(m.group(1),
m.group(2))))
elif len(argstrs) == 2:
r = re.compile("(.+)\.(.+)")
m = r.match(argstrs[0])
if m is None or len(m.groups()) != 2:
print ("Invalid option format")
self.help_set()
return
config.set_value(m.group(1), m.group(2), argstrs[1])
else:
self.help_set()
except Exception as e:
self.error(e)
示例13: create
def create(self):
dbtype = config.get_value("Database", "type")
if self.filename:
db = factory.create(dbtype, self.dbver, self.filename)
else:
db = factory.create(dbtype, self.dbver)
self.cli = PwmanCliNew(db, self.xselpath, DummyCallback)
示例14: do_new
def do_new(self, args):
"""
can override default config settings the following way:
Pwman3 0.2.1 (c) visit: http://github.com/pwman3/pwman3
pwman> n {'leetify':False, 'numerics':True, 'special_chars':True}
Password (Blank to generate):
"""
errmsg = """could not parse config override, please input some"""\
+ """ kind of dictionary, e.g.: n {'leetify':False, """\
+ """'numerics':True, 'special_chars':True}"""
try:
username = self.get_username()
if args:
try:
args = ast.literal_eval(args)
except Exception:
raise Exception(errmsg)
if not isinstance(args, dict):
raise Exception(errmsg)
password = self.get_password(1, **args)
else:
numerics = config.get_value(
"Generator", "numerics").lower() == 'true'
# TODO: allow custom leetifying through the config
leetify = config.get_value(
"Generator", "leetify").lower() == 'true'
special_chars = config.get_value(
"Generator", "special_chars").lower() == 'true'
password = self.get_password(0,
numerics=numerics,
symbols=leetify,
special_signs=special_chars)
url = self.get_url()
notes = self.get_notes()
node = NewNode()
node.username = username
node.password = password
node.url = url
node.notes = notes
tags = self.get_tags()
node.tags = tags
self._db.addnodes([node])
print("Password ID: %d" % (node._id))
# when done with node erase it
zerome(password)
except Exception as e:
self.error(e)
示例15: get_db_version
def get_db_version(config, dbtype, args):
if os.path.exists(config.get_value("Database", "filename")):
dbver = factory.check_db_version(dbtype)
if dbver < 0.4 and not args.dbconvert:
print(_db_warn)
else:
dbver = __DB_FORMAT__
return dbver