database
index
/tmp/makerelease-pwman-python.te7lW1kN/pwman-python-2.4/libpwman/database.py

#
# Simple password manager
# Encrypted database
#
# Copyright (c) 2011-2019 Michael Buesch <m@bues.ch>
# Licensed under the GNU/GPL version 2 or later.
#

 
Modules
       
csv
io
os
pathlib
sys

 
Classes
       
builtins.Exception(builtins.BaseException)
libpwman.cryptsql.CSQLError
builtins.object
PWManEntry
PWManEntryAttr
PWManEntryBulk
PWManEntryTOTP
libpwman.cryptsql.CryptSQL(builtins.object)
PWManDatabase

 
class CSQLError(builtins.Exception)
    CryptSQL exception.
 
 
Method resolution order:
CSQLError
builtins.Exception
builtins.BaseException
builtins.object

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

Methods inherited from builtins.Exception:
__init__(self, /, *args, **kwargs)
Initialize self.  See help(type(self)) for accurate signature.

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).
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

 
class PWManDatabase(libpwman.cryptsql.CryptSQL)
    PWManDatabase(filename, passphrase, key=None, readOnly=True, silent=False)
 
Encrypted pwman database.
 
 
Method resolution order:
PWManDatabase
libpwman.cryptsql.CryptSQL
builtins.object

Methods defined here:
__init__(self, filename, passphrase, key=None, readOnly=True, silent=False)
filename: Path to the database file.
             If it does not exist, a new file is created.
passphrase: The passphrase string for the database file.
key: An optional key to use instead of the passphrase. Don't use it.
readOnly: Open the filename read-only. Commits will raise an exception.
silent: Do not print information messages to the console.
addEntry(self, entry)
Create a new entry in the database.
entry: A PWManEntry() instance.
commit(self)
Write all changes to the encrypted database file.
delEntry(self, entry)
Delete an existing entry from the database.
entry: The PWManEntry() instance to delete from the database.
dropUncommitted(self)
Drop all changes that are not committed, yet.
dumpEntries(self, showTotpKey=False)
Returns a human readable dump string of all entries.
If showTotpKey=True: Also dump the TOTP key and parameters.
dumpEntriesCsv(self, showTotpKey=False)
Returns a CSV format dump string of all entries.
If showTotpKey=True: Also dump the TOTP key and parameters.
dumpEntry(self, entry, showTotpKey=False)
Returns a human readable dump string of an entry.
If showTotpKey=True: Also dump the TOTP key and parameters.
editEntry(self, entry)
Update the contents of an existing entry.
entry: A PWManEntry() containing the new data of the entry/
entryExists(self, category, title)
Returns True, if an entry exists in the database.
category: The name string of the category.
title: The title string of the entry.
findEntries(self, pattern, useRegexp=False, search=True, inCategory=None, matchCategory=False, matchTitle=False, matchUser=False, matchPw=False, matchBulk=False, matchAttrName=False, matchAttrData=False)
Search the database for entries that match a pattern.
useRegexp: If True, then the pattern is a regular expression string.
           If False, then the pattern is a SQL LIKE pattern string.
inCategory: If specified as non-zero length string, then only search
            the category with this name.
matchCategory: Match the pattern to the category name string of an entry.
matchTitle: Match the pattern to the title string of an entry.
matchUser: Match the pattern to the user string of an entry.
matchPw: Match the pattern to the password string of an entry.
matchBulk: Match the pattern to the bulk data string of an entry.
matchAttrName: Match the pattern to all attribute name strings of an entry.
matchAttrData: Match the pattern to all attribute data strings of an entry.
Returns a list of PWManEntry() instances that match the pattern.
flunkDirty(self)
Print a warning, if the database contains uncommitted data.
Then set the flag for uncommitted data to False.
getCategoryNames(self)
Get all category names in the database.
Returns a sorted list of strings.
getEntry(self, category, title)
Get an entry from the database.
category: The name string of the category to get an entry from.
title: The title string of the entry to get.
Returns a PWManEntry() instance.
getEntryAttr(self, entry, attrName)
Get an attribute associated with an entry.
entry: The PWManEntry() to get the attribute for.
attrName: The name string of the attribute to get.
Returns a PWManEntryAttr() instance, or None if there is such attribute.
getEntryAttrs(self, entry)
Get all attributes associated with an entry.
entry: The PWManEntry() to get the attributes for.
Returns a list of PWManEntryAttr() instances,
or an empty list if there are no attributes.
getEntryBulk(self, entry)
Get the bulk data associated with an entry.
entry: The PWManEntry() to get the bulk data for.
Returns a PWManEntryBulk() instance or None, if there is no bulk data.
getEntryTitles(self, category)
Get all titles from one category in the database.
category: The category name string.
Returns a sorted list of strings.
getEntryTotp(self, entry)
Get the TOTP parameters associated with an entry.
entry: The PWManEntry() to get the TOTP parameters for.
Returns a PWManEntryTOTP() instance, or None if there is no TOTP data.
getGlobalAttr(self, name)
Get a global attribute.
A global attribute is not associated with an entry.
Returns None, if the attribute does not exist.
getOnDiskDb(self)
Get a read-only instance of PWManDatabase that contains
the current on-disk data. The on-disk data is the data
at the last commit.
importSqlScript(self, *args, **kwargs)
Imports a plain text dump into the database.
script: The script string to import.
clear: If True, drop all tables from the database before importing.
isDirty(self)
Returns True, if the database contains uncommitted data.
moveEntry(self, entry, newCategory, newTitle)
Move an existing entry to a new category and/or set a new entry title.
entry: The PWManEntry() instance to move.
newCategory: The new category name string.
newTitle: The new title string.
renameCategory(self, category, toCategory)
Change the name of a category.
category: The old name string of the category.
toCategory: The new name string of the category.
setEntryAttr(self, entryAttr)
Set an attribute associated with an entry.
entryAttr: The new PWManEntryAttr() instance to write to the database.
           If entryAttr.data is None, then the attribute is deleted.
setEntryBulk(self, entryBulk)
Set the bulk data associated with an entry.
entryBulk: The new PWManEntryBulk() instance to write to the database.
           If entryBulk.data is None, then the bulk data is deleted.
setEntryTotp(self, entryTotp)
Set the TOTP data associated with an entry.
entryTotp: The new PWManEntryTOTP() instance to write to the database.
           If entryTotp.key is None, then the TOTP data is deleted.
setGlobalAttr(self, name, data, setDirty=True)
Set a global attribute.
A global attribute is not associated with an entry.
If data is None or empty, the attribute is deleted from the database.
setPassphrase(self, passphrase)
Set a new passphrase string for encryption and decryption.

Data and other attributes defined here:
DB_TYPE = 'PWMan database'
DB_VER = ('0', '1')

Methods inherited from libpwman.cryptsql.CryptSQL:
close(self)
Close the currently opened database.
This does not commit. All uncommitted changes are lost.
dropAllTables(self)
Drop all tables from the database.
getFilename(self)
Get the file path of the currently open database.
May return None, if no database file is opened.
getKey(self)
Get the raw key. May be None, if there is none, yet.
Do not use this. getPassphrase probably is what you want.
getPassphrase(self)
Get the current passphrase string for encryption and decryption.
isOpen(self)
Returns True, if a database file is opened.
open(self, filename)
Open a database file and decrypt its contents into memory.
filename: The database file path.
setKey(self, key)
Set the raw key.
Do not use this. setPassphrase probably is what you want.
setRegexpFlags(self, search=True, ignoreCase=True, multiLine=True, dotAll=True)
Change the behavior of the REGEXP operator.
sqlCreateFunction(self, name, nrParams, func)
Create an SQL function.
See sqlite3.Connection.create_function for more details.
sqlExec(self, code, params=[])
Execute one SQL statement.
sqlExecScript(self, code)
Execute multiple SQL statements.
sqlIsEmpty(self)
Returns True, if the database does not contain any tables.
sqlPlainDump(self)
Get a plain text dump of the database.
Returns a string.
sqlVacuum(self)
Run the SQL VACUUM statement.
This also commits all changes to the SQL database,
but not to the database file.

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

 
class PWManEntry(builtins.object)
    PWManEntry(category: str, title: str, user: str = None, pw: str = None, entryId: int = None) -&gt; None
 
Database entry data structure.
 
  Methods defined here:
__eq__(self, other)
__init__(self, category: str, title: str, user: str = None, pw: str = None, entryId: int = None) -> None
__repr__(self)

Data descriptors defined here:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

Data and other attributes defined here:
__annotations__ = {'category': <class 'str'>, 'entryId': <class 'int'>, 'pw': <class 'str'>, 'title': <class 'str'>, 'user': <class 'str'>}
__dataclass_fields__ = {'category': Field(name='category',type=<class 'str'>,default...rue,metadata=mappingproxy({}),_field_type=_FIELD), 'entryId': Field(name='entryId',type=<class 'int'>,default=...rue,metadata=mappingproxy({}),_field_type=_FIELD), 'pw': Field(name='pw',type=<class 'str'>,default=None,...rue,metadata=mappingproxy({}),_field_type=_FIELD), 'title': Field(name='title',type=<class 'str'>,default=<d...rue,metadata=mappingproxy({}),_field_type=_FIELD), 'user': Field(name='user',type=<class 'str'>,default=Non...rue,metadata=mappingproxy({}),_field_type=_FIELD)}
__dataclass_params__ = _DataclassParams(init=True,repr=True,eq=True,order=False,unsafe_hash=False,frozen=False)
__hash__ = None
entryId = None
pw = None
user = None

 
class PWManEntryAttr(builtins.object)
    PWManEntryAttr(name: str, data: str = None, entry: database.PWManEntry = None, attrId: int = None) -&gt; None
 
Entry attribute data structure.
 
  Methods defined here:
__eq__(self, other)
__init__(self, name: str, data: str = None, entry: database.PWManEntry = None, attrId: int = None) -> None
__repr__(self)

Data descriptors defined here:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

Data and other attributes defined here:
__annotations__ = {'attrId': <class 'int'>, 'data': <class 'str'>, 'entry': <class 'database.PWManEntry'>, 'name': <class 'str'>}
__dataclass_fields__ = {'attrId': Field(name='attrId',type=<class 'int'>,default=N...rue,metadata=mappingproxy({}),_field_type=_FIELD), 'data': Field(name='data',type=<class 'str'>,default=Non...rue,metadata=mappingproxy({}),_field_type=_FIELD), 'entry': Field(name='entry',type=<class 'database.PWManEn...rue,metadata=mappingproxy({}),_field_type=_FIELD), 'name': Field(name='name',type=<class 'str'>,default=<da...rue,metadata=mappingproxy({}),_field_type=_FIELD)}
__dataclass_params__ = _DataclassParams(init=True,repr=True,eq=True,order=False,unsafe_hash=False,frozen=False)
__hash__ = None
attrId = None
data = None
entry = None

 
class PWManEntryBulk(builtins.object)
    PWManEntryBulk(data: str = None, entry: database.PWManEntry = None, bulkId: int = None) -&gt; None
 
Entry bulk-data data structure.
 
  Methods defined here:
__eq__(self, other)
__init__(self, data: str = None, entry: database.PWManEntry = None, bulkId: int = None) -> None
__repr__(self)

Data descriptors defined here:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

Data and other attributes defined here:
__annotations__ = {'bulkId': <class 'int'>, 'data': <class 'str'>, 'entry': <class 'database.PWManEntry'>}
__dataclass_fields__ = {'bulkId': Field(name='bulkId',type=<class 'int'>,default=N...rue,metadata=mappingproxy({}),_field_type=_FIELD), 'data': Field(name='data',type=<class 'str'>,default=Non...rue,metadata=mappingproxy({}),_field_type=_FIELD), 'entry': Field(name='entry',type=<class 'database.PWManEn...rue,metadata=mappingproxy({}),_field_type=_FIELD)}
__dataclass_params__ = _DataclassParams(init=True,repr=True,eq=True,order=False,unsafe_hash=False,frozen=False)
__hash__ = None
bulkId = None
data = None
entry = None

 
class PWManEntryTOTP(builtins.object)
    PWManEntryTOTP(key: str, digits: int = 6, hmacHash: str = 'SHA1', entry: database.PWManEntry = None, totpId: int = None) -&gt; None
 
Entry TOTP-data data structure.
 
  Methods defined here:
__eq__(self, other)
__init__(self, key: str, digits: int = 6, hmacHash: str = 'SHA1', entry: database.PWManEntry = None, totpId: int = None) -> None
__repr__(self)

Data descriptors defined here:
__dict__
dictionary for instance variables (if defined)
__weakref__
list of weak references to the object (if defined)

Data and other attributes defined here:
__annotations__ = {'digits': <class 'int'>, 'entry': <class 'database.PWManEntry'>, 'hmacHash': <class 'str'>, 'key': <class 'str'>, 'totpId': <class 'int'>}
__dataclass_fields__ = {'digits': Field(name='digits',type=<class 'int'>,default=6...rue,metadata=mappingproxy({}),_field_type=_FIELD), 'entry': Field(name='entry',type=<class 'database.PWManEn...rue,metadata=mappingproxy({}),_field_type=_FIELD), 'hmacHash': Field(name='hmacHash',type=<class 'str'>,default...rue,metadata=mappingproxy({}),_field_type=_FIELD), 'key': Field(name='key',type=<class 'str'>,default=<dat...rue,metadata=mappingproxy({}),_field_type=_FIELD), 'totpId': Field(name='totpId',type=<class 'int'>,default=N...rue,metadata=mappingproxy({}),_field_type=_FIELD)}
__dataclass_params__ = _DataclassParams(init=True,repr=True,eq=True,order=False,unsafe_hash=False,frozen=False)
__hash__ = None
digits = 6
entry = None
hmacHash = 'SHA1'
totpId = None

 
Functions
       
getDefaultDatabase()
Get the default database path.
Returns a pathlib.Path() instance.

 
Data
        __all__ = ['CSQLError', 'PWManDatabase', 'PWManEntry', 'PWManEntryAttr', 'PWManEntryBulk', 'PWManEntryTOTP', 'getDefaultDatabase']