Package cdbx :: Module _cdb :: Class CDB
[frames] | no frames]

Class CDB

object --+
         |
        CDB

CDB(file)

Create a CDB instance from a file.

'file' can be either a (binary) python stream (providing fileno()) or a filename or an integer (representing a filedescriptor).

Instance Methods
bool
__contains__(self, key)
Check if the key appears in the CDB.
 
__getattribute__(...)
x.__getattribute__('name') <==> x.name
bytes
__getitem__(self, key)
Find the first value of the passed key and return the value as bytestring
iterable
__iter__(self)
Create an iterator over unique keys - in insertion order
int
__len__(self)
Count the number of unique keys
 
close(self)
Close the CDB.
int
fileno(self)
Find the underlying file descriptor
any
get(self, key, default=None, all=False)
Return value(s) for a key
bool
has_key(self, key)
Check if the key appears in the CDB.
iterable
items(self, all=False)
Create key/value pair iterator
iterable
keys(self, all=False)
Create key iterator
CDBMaker
make(cls, file)
Create a CDB maker instance, which returns a CDB instance when done.

Inherited from object: __delattr__, __format__, __init__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Static Methods
CDB
__new__(cls, file)
Create a CDB instance.
Class Variables
  __hash__ = None
hash(x)
Properties

Inherited from object: __class__

Method Details

__contains__(self, key)
(In operator)

 

Check if the key appears in the CDB.

Note that in case of a unicode key, it will be transformed to a byte string using the ascii encoding.

Parameters:
  • key (basestring) - Key to look up
Returns: bool
Does the key exists?

__getattribute__(...)

 
x.__getattribute__('name') <==> x.name
Overrides: object.__getattribute__

__getitem__(self, key)
(Indexing operator)

 

Find the first value of the passed key and return the value as bytestring

Note that in case of a unicode key, it will be transformed to a byte string using the ascii encoding.

Parameters:
  • key (basestring) - Key to look up
Returns: bytes
The first value of the key
Raises:
  • KeyError - Key not found

__iter__(self)

 
Create an iterator over unique keys - in insertion order
Returns: iterable
The key iterator

__len__(self)
(Length operator)

 
Count the number of unique keys
Returns: int
The number of unique keys

__new__(cls, file)
Static Method

 
Create a CDB instance.
Parameters:
  • file (file or str or fd) - Either a (binary) python stream (providing fileno()) or a filename or an integer (representing a filedescriptor).
Returns: CDB
New CDB instance
Overrides: object.__new__

close(self)

 
Close the CDB.

fileno(self)

 
Find the underlying file descriptor
Returns: int
The underlying file descriptor

get(self, key, default=None, all=False)

 

Return value(s) for a key

If key is not found, default is returned. If key was found, then depending on the all flag the value return is either a byte string (all == False) or a list of byte strings (all == True).

Note that in case of a unicode key, it will be transformed to a byte string using the ascii encoding.

Parameters:
  • key (bytes) - Key to lookup
  • default (any) - Default value to pass back if the key was not found
  • all (bool) - Return all values instead of only the first? Default: False
Returns: any
The value(s) or the default

has_key(self, key)

 

Check if the key appears in the CDB.

Note that in case of a unicode key, it will be transformed to a byte string using the ascii encoding.

Returns: bool
Does the key exists?

items(self, all=False)

 
Create key/value pair iterator
Parameters:
  • all (bool) - Return all (i.e. non-unique-key) items? Default: False
Returns: iterable
Iterator over items

keys(self, all=False)

 
Create key iterator
Parameters:
  • all (bool) - Return all (i.e. non-unique) keys? Default: False
Returns: iterable
Iterator over keys

make(cls, file)

 
Create a CDB maker instance, which returns a CDB instance when done.
Parameters:
  • file (file or str or fd) - Either a (binary) python stream (providing fileno()) or a filename or an integer (representing a filedescriptor).
Returns: CDBMaker
New maker instance

Class Variable Details

__hash__

hash(x)

Value:
None