ui
index
/tmp/makerelease-pwman-python.grjbw8ep/pwman-python-2.10/libpwman/ui.py

# Simple password manager
# Copyright (c) 2011-2023 Michael Büsch <m@bues.ch>
# Licensed under the GNU/GPL version 2 or later.

 
Modules
       
functools
os
pathlib
re
readline
signal
sys
time
traceback

 
Classes
       
builtins.Exception(builtins.BaseException)
PWManTimeout
cmd.Cmd(builtins.object)
__classcell__

 
PWMan = class __classcell__(cmd.Cmd)
    PWMan(filename, passphrase, timeout=None)
 

 
 
Method resolution order:
__classcell__
cmd.Cmd
builtins.object

Methods defined here:
__init__(self, filename, passphrase, timeout=None)
Instantiate a line-oriented interpreter framework.
 
The optional argument 'completekey' is the readline name of a
completion key; it defaults to the Tab key. If completekey is
not None and the readline module is available, command completion
is done automatically. The optional arguments stdin and stdout
specify alternate input and output file objects; if not specified,
sys.stdin and sys.stdout are used.
complete_add = __complete_category_title(self, text, line, begidx, endidx)
complete_c = complete_commit(self, text, line, begidx, endidx)
complete_cat = __complete_category_title_item(self, text, line, begidx, endidx)
complete_close(self, text, line, begidx, endidx)
complete_commit(self, text, line, begidx, endidx)
complete_copy = __complete_move_copy(self, text, line, begidx, endidx)
complete_cp = __complete_move_copy(self, text, line, begidx, endidx)
complete_database(self, text, line, begidx, endidx)
complete_db = complete_database(self, text, line, begidx, endidx)
complete_dbdump(self, text, line, begidx, endidx)
complete_dbimport(self, text, line, begidx, endidx)
complete_del = __complete_category_title(self, text, line, begidx, endidx)
complete_diff(self, text, line, begidx, endidx)
complete_ea = complete_edit_attr(self, text, line, begidx, endidx)
complete_eb = complete_edit_bulk(self, text, line, begidx, endidx)
complete_edit_attr(self, text, line, begidx, endidx)
complete_edit_bulk(self, text, line, begidx, endidx)
complete_edit_pw(self, text, line, begidx, endidx)
complete_edit_totp(self, text, line, begidx, endidx)
complete_edit_user(self, text, line, begidx, endidx)
complete_ep = complete_edit_pw(self, text, line, begidx, endidx)
complete_et = complete_edit_totp(self, text, line, begidx, endidx)
complete_eu = complete_edit_user(self, text, line, begidx, endidx)
complete_f = complete_find(self, text, line, begidx, endidx)
complete_find(self, text, line, begidx, endidx)
complete_list = __complete_category_title_item(self, text, line, begidx, endidx)
complete_ls = __complete_category_title_item(self, text, line, begidx, endidx)
complete_move = __complete_move_copy(self, text, line, begidx, endidx)
complete_mv = __complete_move_copy(self, text, line, begidx, endidx)
complete_n = __complete_category_title(self, text, line, begidx, endidx)
complete_new = __complete_category_title(self, text, line, begidx, endidx)
complete_remove = __complete_category_title(self, text, line, begidx, endidx)
complete_rename = __complete_move_copy(self, text, line, begidx, endidx)
complete_rm = __complete_category_title(self, text, line, begidx, endidx)
complete_t = __complete_category_title(self, text, line, begidx, endidx)
complete_totp = __complete_category_title(self, text, line, begidx, endidx)
complete_w = complete_commit(self, text, line, begidx, endidx)
default(self, line)
Called on an input line when the command prefix is not recognized.
 
If this method is not overridden, it prints an error message and
returns.
do_EOF = do_quit(self, params)
do_add = do_new(self, params)
do_c = do_commit(self, params)
do_cat = do_list(self, params)
do_close(self, params)
--- Close a database ---
Command: close [!] [NAME]
 
If NAME is not given, then this closes the currently selected database.
If NAME is given, then this closes the named database.
 
If ! is specified, then the uncommitted changes will be dropped.
 
If the currently used database is closed, the selected database
will be switched to 'main'.
 
The 'main' database can only be closed last,
which in turn closes the application.
 
Aliases: None
do_cls(self, params)
--- Clear console screen ---
Command: cls
 
Clear the console screen.
Note that this does not clear a possibly existing
'screen' session buffer or other advanced console buffers.
 
Aliases: None
do_commit(self, params)
--- Write changes to the database file(s) ---
Command: commit
 
Options:
  -a   Commit all open databases.
 
Aliases: c w
do_copy(self, params)
--- Copy an entry or a category ---
 
Copy an existing entry:
Command: copy CATEGORY TITLE TO_CATEGORY [NEW_TITLE]
(NEW_TITLE defaults to TITLE)
 
Copy all entries from a category into another category:
Command: copy FROM_CATEGORY TO_CATEGORY
 
Copy an entry from one database to another:
Command: copy -s main -d other CATEGORY TITLE TO_CATEGORY [NEW_TITLE]
(NEW_TITLE defaults to TITLE)
 
Copy all entries from a category from one database into another database:
Command: copy -s main -d other FROM_CATEGORY [TO_CATEGORY]
(TO_CATEGORY defaults to FROM_CATEGORY)
 
Options:
  -s SOURCE_DATABASE_NAME
  -d DESTINATION_DATABASE_NAME
  Databases default to the currently selected database.
  The named databases must be open. See 'database' command.
 
Aliases: cp
do_cp = do_copy(self, params)
do_database(self, params)
--- Open a database or switch to an already opened database ---
Command: database [-f FILEPATH] [NAME]
 
If neither FILEPATH nor NAME are given, then
a list of all currently opened databases will be printed.
The currently selected database will be marked with [@].
All databases with uncommitted changes will be marked with [*].
 
If only NAME is given, then the selected database will
be switched to the named one. NAME must already be open.
 
A new database can be opened with -f FILEPATH.
NAME is optional in this case.
The selected database will be switched to the newly opened one.
 
Aliases: db
do_db = do_database(self, params)
do_dbdump(self, params)
--- Dump the pwman SQL database ---
Command: dbdump [OPTS] [FILEPATH]
 
If FILEPATH is given, the database is dumped
unencrypted to the file.
If FILEPATH is omitted, the database is dumped
unencrypted to stdout.
 
OPTS may be one of:
  -s   Dump format SQL. (default)
  -h   Dump format human readable text.
  -c   Dump format CSV.
 
WARNING: The database dump is not encrypted.
 
Aliases: None
do_dbimport(self, params)
--- Import an SQL database dump ---
Command: dbimport FILEPATH
 
Import the FILEPATH into the current database.
The database is cleared before importing the file!
 
Aliases: None
do_del = do_remove(self, params)
do_diff(self, params)
--- Diff the current database to another database ---
Command: diff [OPTS] [DATABASE_FILE]
 
If no DATABASE_FILE is provided: Diffs the latest changes in the
currently open database to the committed changes in the current database.
This can be used to review changes before commit.
 
If DATABASE_FILE is provided: Diffs the latest changes in the
currently opened database to the contents of DATABASE_FILE.
 
OPTS may be one of:
-u  Generate a unified diff (default if no OPT is given).
-c  Generate a context diff
-n  Generate an ndiff
 
Aliases: None
do_drop(self, params)
--- Drop all uncommitted changes ---
Command: drop
 
Aliases: None
do_ea = do_edit_attr(self, params)
do_eb = do_edit_bulk(self, params)
do_edit_attr(self, params)
--- Edit an entry attribute ---
Command: edit_attr category title NAME [DATA]
 
Edit or delete an entry attribute.
 
Aliases: ea
do_edit_bulk(self, params)
--- Edit the 'bulk' field of an existing entry ---
Command: edit_bulk category title NEWDATA...
 
Change the 'bulk' field of an existing database entry.
NEWDATA is the new data to write into the 'bulk' field.
The NEWDATA must _not_ be escaped (however, category and
title must be escaped).
 
Aliases: eb
do_edit_pw(self, params)
--- Edit the 'password' field of an existing entry ---
Command: edit_pw category title NEWDATA...
 
Change the 'password' field of an existing database entry.
NEWDATA is the new data to write into the 'password' field.
The NEWDATA must _not_ be escaped (however, category and
title must be escaped).
 
Aliases: ep
do_edit_totp(self, params)
--- Edit TOTP key and parameters ---
Command: edit_totp category title [KEY] [DIGITS] [HASH]
 
Set Time-Based One-Time Password Algorithm key and parameters.
If KEY is not provided, the TOTP parameters for this entry are deleted.
DIGITS default to 6, if not provided.
HASH defaults to SHA1, if not provided.
 
Aliases: et
do_edit_user(self, params)
--- Edit the 'user' field of an existing entry ---
Command: edit_user category title NEWDATA...
 
Change the 'user' field of an existing database entry.
NEWDATA is the new data to write into the 'user' field.
The NEWDATA must _not_ be escaped (however, category and
title must be escaped).
 
Aliases: eu
do_ep = do_edit_pw(self, params)
do_et = do_edit_totp(self, params)
do_eu = do_edit_user(self, params)
do_exit = do_quit(self, params)
do_f = do_find(self, params)
do_find(self, params)
--- Search the database ---
Command: find [OPTS] [IN_CATEGORY] PATTERN
 
Searches the database for patterns. If 'IN_CATEGORY' is given, only search
in the specified category.
PATTERN may either use SQL LIKE wildcards (without -r)
or Python Regular Expression special characters (with -r).
 
OPTS may be one or multiple of:
  -c   Match 'category'       (only if no IN_CATEGORY parameter)
  -t   Match 'title'          (*)
  -u   Match 'user'           (*)
  -p   Match 'password'       (*)
  -b   Match 'bulk'           (*)
  -a   Match 'attribute data' (*)
  -A   Match 'attribute name'
  -r   Use Python Regular Expression matching
 
(*) = These OPTS are enabled by default, if and only if
      none of them are specified by the user.
 
Aliases: f
do_h = do_help(self, params)
do_help(self, params)
--- Shows help text about a command ---
Command: help [COMMAND]
 
If COMMAND is not given: Show a command summary.
If COMMAND is given: Show detailed help about that command.
 
Aliases: h
do_list(self, params)
--- Print a listing ---
Command: list [category] [title] [item]
 
If a category is given as parameter, list the 
contents of the category. If category and entry
are given, list the contents of the entry.
If item is given, then only list one specific content item.
Item may be one of: user, password, bulk, totpkey or any attribute name.
 
Aliases: ls cat
do_ls = do_list(self, params)
do_masterp(self, params)
--- Change the master passphrase ---
Command: masterp
 
Aliases: None
do_move(self, params)
--- Move/rename an existing entry or a category ---
 
Move/rename an existing entry:
Command: move CATEGORY TITLE TO_CATEGORY [NEW_TITLE]
(NEW_TITLE defaults to TITLE)
 
Move all entries from one category into another category.
Command: move FROM_CATEGORY TO_CATEGORY
 
Move an entry from one database to another:
Command: move -s main -d other CATEGORY TITLE TO_CATEGORY [NEW_TITLE]
(NEW_TITLE defaults to TITLE)
 
Move all entries from a category from one database into another database:
Command: move -s main -d other FROM_CATEGORY [TO_CATEGORY]
(TO_CATEGORY defaults to FROM_CATEGORY)
 
Options:
  -s SOURCE_DATABASE_NAME
  -d DESTINATION_DATABASE_NAME
  Databases default to the currently selected database.
  The named databases must be open. See 'database' command.
 
Aliases: mv rename
do_mv = do_move(self, params)
do_n = do_new(self, params)
do_new(self, params)
--- Create a new entry ---
Command: new [category] [title] [user] [password]
 
Create a new database entry. If no parameters are given,
they are asked for interactively.
 
Aliases: n add
do_q = do_quit(self, params)
do_quit(self, params)
--- Exit pwman ---
Command: quit [!]
 
Use the exclamation mark to force quit and discard changes.
 
Aliases: q exit ^D
do_remove(self, params)
--- Remove an existing entry ---
Command: remove category [title]
 
Remove an existing database entry.
 
Aliases: rm del
do_rename = do_move(self, params)
do_rm = do_remove(self, params)
do_t = do_totp(self, params)
do_totp(self, params)
--- Generate a TOTP token ---
Command: totp [CATEGORY TITLE] OR [TITLE]
 
Generates a token using the Time-Based One-Time Password Algorithm.
 
Aliases: t
do_w = do_commit(self, params)
emptyline(self)
Called when an empty line is entered in response to the prompt.
 
If this method is not overridden, it repeats the last nonempty
command entered.
flunkDirty(self)
interactive(self)
postcmd(self, stop, line)
Hook method executed just after a command dispatch is finished.
precmd(self, line)
Hook method executed just before the command line is
interpreted, but after the input prompt is generated and issued.
runOneCommand(self, command)

Data and other attributes defined here:
CommandError = <class 'ui.PWMan.CommandError'>
Quit = <class 'ui.PWMan.Quit'>
cmdHelpDatabase = (('database', ('db',), 'Open or select another database'), ('commit', ('c', 'w'), 'Commit/write selected db to disk'), ('drop', (), 'Drop uncommitted changes in selected db'), ('close', (), 'Close a database'), ('dbdump', (), 'Dump the selected database'), ('dbimport', (), 'Import a database dump file'), ('masterp', (), 'Change the master passphrase'))
cmdHelpEdit = (('new', ('n', 'add'), 'Create new entry'), ('edit_user', ('eu',), "Edit the 'user' field of an entry"), ('edit_pw', ('ep',), "Edit the 'password' field of an entry"), ('edit_bulk', ('eb',), "Edit the 'bulk' field of an entry"), ('edit_totp', ('et',), 'Edit the TOTP key and parameters'), ('edit_attr', ('ea',), 'Edit an entry attribute'), ('move', ('mv', 'rename'), 'Move/rename an existing entry'), ('copy', ('cp',), 'Copy an existing entry or category'), ('remove', ('rm', 'del'), 'Remove an existing entry'))
cmdHelpMisc = (('help', ('h',), 'Show help about commands'), ('quit', ('q', 'exit', '^D'), 'Quit pwman'), ('cls', (), 'Clear screen'))
cmdHelpShow = (('list', ('ls', 'cat'), 'List/print entry contents'), ('find', ('f',), 'Search the database for patterns'), ('totp', ('t',), 'Generate TOTP token'), ('diff', (), 'Show the database differences'))

Methods inherited from cmd.Cmd:
cmdloop(self, intro=None)
Repeatedly issue a prompt, accept input, parse an initial prefix
off the received input, and dispatch to action methods, passing them
the remainder of the line as argument.
columnize(self, list, displaywidth=80)
Display a list of strings as a compact set of columns.
 
Each column is only as wide as necessary.
Columns are separated by two spaces (one was not legible enough).
complete(self, text, state)
Return the next possible completion for 'text'.
 
If a command has not been entered, then complete against command list.
Otherwise try to call complete_<command> to get list of completions.
complete_help(self, *args)
completedefault(self, *ignored)
Method called to complete an input line when no command-specific
complete_*() method is available.
 
By default, it returns an empty list.
completenames(self, text, *ignored)
get_names(self)
onecmd(self, line)
Interpret the argument as though it had been typed in response
to the prompt.
 
This may be overridden, but should not normally need to be;
see the precmd() and postcmd() methods for useful execution hooks.
The return value is a flag indicating whether interpretation of
commands by the interpreter should stop.
parseline(self, line)
Parse the line into a command name and a string containing
the arguments.  Returns a tuple containing (command, args, line).
'command' and 'args' may be None if the line couldn't be parsed.
postloop(self)
Hook method executed once when the cmdloop() method is about to
return.
preloop(self)
Hook method executed once when the cmdloop() method is called.
print_topics(self, header, cmds, cmdlen, maxcol)

Data descriptors inherited from cmd.Cmd:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

Data and other attributes inherited from cmd.Cmd:
doc_header = 'Documented commands (type help <topic>):'
doc_leader = ''
identchars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_'
intro = None
lastcmd = ''
misc_header = 'Miscellaneous help topics:'
nohelp = '*** No help on %s'
prompt = '(Cmd) '
ruler = '='
undoc_header = 'Undocumented commands:'
use_rawinput = 1

 
class PWManTimeout(builtins.Exception)
    PWManTimeout(seconds)
 

 
 
Method resolution order:
PWManTimeout
builtins.Exception
builtins.BaseException
builtins.object

Methods defined here:
__init__(self, seconds)
Initialize self.  See help(type(self)) for accurate signature.
poke(self)

Data descriptors defined here:
__weakref__
list of weak references to the object (if defined)

Static methods inherited from builtins.Exception:
__new__(*args, **kwargs) from builtins.type
Create and return a new object.  See help(type) for accurate signature.

Methods inherited from builtins.BaseException:
__delattr__(self, name, /)
Implement delattr(self, name).
__getattribute__(self, name, /)
Return getattr(self, name).
__reduce__(...)
Helper for pickle.
__repr__(self, /)
Return repr(self).
__setattr__(self, name, value, /)
Implement setattr(self, name, value).
__setstate__(...)
__str__(self, /)
Return str(self).
add_note(...)
Exception.add_note(note) --
add a note to the exception
with_traceback(...)
Exception.with_traceback(tb) --
set self.__traceback__ to tb and return self.

Data descriptors inherited from builtins.BaseException:
__cause__
exception cause
__context__
exception context
__dict__
__suppress_context__
__traceback__
args

 
Data
        __all__ = ['PWMan', 'PWManTimeout']