Package dbf :: Module ver_2
[hide private]
[frames] | no frames]

Module ver_2

source code

Classes [hide private]
  IsoDay
  RelativeDay
  IsoMonth
  RelativeMonth
  bytes
str(object='') -> string
  property
2.6 properties for 2.5-
  LazyAttr
doesn't create object until actually accessed
  MutableDefault
Lives in the class, and on first access calls the supplied factory and maps the result into the instance it was called on
  DbfError
Fatal errors elicit this response.
  DataOverflowError
Data too large for field
  BadDataError
bad data in table
  FieldMissingError
Field does not exist in table
  FieldSpecError
invalid field specification
  NonUnicodeError
Data for table not in unicode
  NotFoundError
record criteria not met
  DbfWarning
Normal operations elicit this response
  Eof
End of file reached
  Bof
Beginning of file reached
  DoNotIndex
Returned by indexing functions to suppress a record from becoming part of the index
  NullType
Null object -- any interaction returns Null
  Char
Strips trailing whitespace, and ignores trailing whitespace for comparisons
  Date
adds null capable datetime.date constructs
  DateTime
adds null capable datetime.datetime constructs
  Time
adds null capable datetime.time constructs
  Period
for matching various time ranges
  Logical
Logical field return type.
  Quantum
Logical field return type that implements boolean algebra
  _Navigation
Navigation base class that provides VPFish movement methods
  Record
Provides routines to extract and save data within the fields of a dbf record.
  RecordTemplate
Provides routines to mimic a dbf record.
  RecordVaporWare
Provides routines to mimic a dbf record, but all values are non-existent.
  _DbfMemo
Provides access to memo fields as dictionaries Must override _init, _get_memo, and _put_memo to store memo contents to disk
  _Db3Memo
dBase III specific
  _VfpMemo
Visual Foxpro 6 specific
  DbfCsv
csv format for exporting tables
  Tables
context manager for multiple tables and/or indices
  IndexLocation
Represents the index where the match criteria is if True, or would be if False
  FieldInfo
tuple with named attributes for representing a field's dbf type, length, decimal portion, and python class
  CodePage
tuple with named attributes for representing a tables codepage
  Iter
Provides iterable behavior for a table
  Table
Base class for dbf style tables
  Db3Table
Provides an interface for working with dBase III tables.
  ClpTable
Provides an interface for working with Clipper tables.
  FpTable
Provides an interface for working with FoxPro 2 tables
  VfpTable
Provides an interface for working with Visual FoxPro 6 tables
  List
list of Dbf records, with set-like behavior
  Index
non-persistent index for a table
  Relation
establishes a relation between two dbf tables (not persistent)
  IndexFile
  BytesType
  IntBytesType
add big_endian and neg_one to __init__
  Int8
1-byte integer
  Int16
2-byte integer
  Int32
4-byte integer
  Bytes
  DataBlock
adds _data as a str to class binds variable name to BytesType descriptor
  LruCache
keep the most recent n items in the dict
  Idx
  _Db4Table
under development
Functions [hide private]
 
is_leapyear(year) source code
 
next(iterator) source code
 
all(iterable) source code
 
any(iterable) source code
 
none(*args, **kwargs)
because we can't do `NoneType()`
source code
 
pack_short_int(value, bigendian=False)
Returns a two-bye integer from the value, or raises DbfError
source code
 
pack_long_int(value, bigendian=False)
Returns a four-bye integer from the value, or raises DbfError
source code
 
pack_str(string)
Returns an 11 byte, upper-cased, null padded string suitable for field names; raises DbfError if the string is bigger than 10 bytes
source code
 
unpack_short_int(bytes, bigendian=False)
Returns the value in the two-byte integer passed in
source code
 
unpack_long_int(bytes, bigendian=False)
Returns the value in the four-byte integer passed in
source code
 
unpack_str(chars)
Returns a normal, lower-cased string from a null-padded byte string
source code
 
scinot(value, decimals)
return scientific notation with not more than decimals-1 decimal places
source code
 
unsupported_type(something, *ignore)
called if a data type is not supported for that style of table
source code
 
retrieve_character(bytes, fielddef, memo, decoder)
Returns the string in bytes as fielddef[CLASS] or fielddef[EMPTY]
source code
 
update_character(string, fielddef, memo, decoder, encoder)
returns the string as bytes (not unicode) as fielddef[CLASS] or fielddef[EMPTY]
source code
 
retrieve_currency(bytes, fielddef, *ignore)
Returns the currency value in bytes
source code
 
update_currency(value, *ignore)
Returns the value to be stored in the record's disk data
source code
 
retrieve_date(bytes, fielddef, *ignore)
Returns the ascii coded date as fielddef[CLASS] or fielddef[EMPTY]
source code
 
update_date(moment, *ignore)
Returns the Date or datetime.date object ascii-encoded (yyyymmdd)
source code
 
retrieve_double(bytes, fielddef, *ignore)
Returns the double in bytes as fielddef[CLASS] ('default' == float)
source code
 
update_double(value, *ignore)
returns the value to be stored in the record's disk data
source code
 
retrieve_integer(bytes, fielddef, *ignore)
Returns the binary number stored in bytes in little-endian format as fielddef[CLASS]
source code
 
update_integer(value, *ignore)
Returns value in little-endian binary format
source code
 
retrieve_logical(bytes, fielddef, *ignore)
Returns True if bytes is 't', 'T', 'y', or 'Y' None if '?' False otherwise
source code
 
update_logical(data, *ignore)
Returns 'T' if logical is True, 'F' if False, '?' otherwise
source code
 
retrieve_memo(bytes, fielddef, memo, decoder)
Returns the block of data from a memo file
source code
 
update_memo(string, fielddef, memo, decoder, encoder)
Writes string as a memo, returns the block number it was saved into
source code
 
retrieve_numeric(bytes, fielddef, *ignore)
Returns the number stored in bytes as integer if field spec for decimals is 0, float otherwise
source code
 
update_numeric(value, fielddef, *ignore)
returns value as ascii representation, rounding decimal portion as necessary
source code
 
retrieve_vfp_datetime(bytes, fielddef, *ignore)
returns the date/time stored in bytes; dates <= 01/01/1981 00:00:00 may not be accurate; BC dates are nulled.
source code
 
update_vfp_datetime(moment, *ignore)
Sets the date/time stored in moment...
source code
 
retrieve_vfp_memo(bytes, fielddef, memo, decoder)
Returns the block of data from a memo file
source code
 
update_vfp_memo(string, fielddef, memo, decoder, encoder)
Writes string as a memo, returns the block number it was saved into
source code
 
add_character(format, flags) source code
 
add_date(format, flags) source code
 
add_logical(format, flags) source code
 
add_memo(format, flags) source code
 
add_numeric(format, flags) source code
 
add_clp_character(format, flags) source code
 
add_vfp_character(format, flags) source code
 
add_vfp_currency(format, flags) source code
 
add_vfp_datetime(format, flags) source code
 
add_vfp_double(format, flags) source code
 
add_vfp_integer(format, flags) source code
 
add_vfp_memo(format, flags) source code
 
add_vfp_numeric(format, flags) source code
 
field_spec_error_text(format, flags)
generic routine for error text for the add...() functions
source code
 
ezip(*iters)
extends all iters to longest one, using last value from each as necessary
source code
 
pql_select(records, chosen_fields, condition, field_names) source code
 
pql_update(records, command, condition, field_names) source code
 
pql_delete(records, dead_fields, condition, field_names) source code
 
pql_recall(records, all_fields, condition, field_names) source code
 
pql_add(records, new_fields, condition, field_names) source code
 
pql_drop(records, dead_fields, condition, field_names) source code
 
pql_pack(records, command, condition, field_names) source code
 
pql_resize(records, fieldname_newsize, condition, field_names) source code
 
pql_criteria(records, criteria)
creates a function matching the pql criteria
source code
 
pql_cmd(command, field_names)
creates a function matching to apply command to each record in records
source code
 
pql(records, command)
recognized pql commands are SELECT, UPDATE | REPLACE, DELETE, RECALL, ADD, DROP
source code
 
_nop(value)
returns parameter unchanged
source code
 
_normalize_tuples(tuples, length, filler)
ensures each tuple is the same length, using filler[-missing] for the gaps
source code
 
_codepage_lookup(cp) source code
 
create_template(table_or_record, defaults=None) source code
 
delete(record)
marks record as deleted
source code
 
export(table_or_records, filename=None, field_names=None, format='csv', header=True, dialect='dbf', encoding=None)
writes the records using CSV or tab-delimited format, using the filename given if specified, otherwise the table name if table_or_records is a collection of records (not an actual table) they should all be of the same format
source code
 
field_names(thing)
fields in table/record, keys in dict
source code
 
is_deleted(record)
marked for deletion?
source code
 
recno(record)
physical record number
source code
 
reset(record, keep_fields=None)
sets record's fields back to original, except for fields in keep_fields
source code
 
source_table(thingie)
table associated with table | record | index
source code
 
undelete(record)
marks record as active
source code
 
write(record, **kwargs)
write record data to disk (updates indices)
source code
 
Process(records, start=0, stop=None, filter=None)
commits each record to disk before returning the next one; undoes all changes to that record if exception raised if records is a table, it will be opened and closed if necessary filter function should return True to skip record, False to keep
source code
 
Templates(records, start=0, stop=None, filter=None)
returns a template of each record instead of the record itself if records is a table, it will be opened and closed if necessary
source code
 
index(sequence)
returns integers 0 - len(sequence)
source code
 
guess_table_type(filename) source code
 
table_type(filename)
returns text representation of a table's dbf version
source code
 
add_fields(table_name, field_specs)
adds fields to an existing table
source code
 
delete_fields(table_name, field_names)
deletes fields from an existing table
source code
 
first_record(table_name)
prints the first record of a table
source code
 
from_csv(csvfile, to_disk=False, filename=None, field_names=None, extra_fields=None, dbf_type='db3', memo_size=64, min_field_size=1, encoding=None, errors=None)
creates a Character table from a csv file to_disk will create a table with the same name filename will be used if provided field_names default to f0, f1, f2, etc, unless specified (list) extra_fields can be used to add additional fields -- should be normal field specifiers (list)
source code
 
get_fields(table_name)
returns the list of field names of a table
source code
 
info(table_name)
prints table info
source code
 
rename_field(table_name, oldfield, newfield)
renames a field in a table
source code
 
structure(table_name, field=None)
returns the definition of a field (or all fields)
source code
 
hex_dump(records)
just what it says ;)
source code
 
gather(record, data, drop=False)
saves data into a record's fields; writes to disk if not in flux keys with no matching field will raise a FieldMissingError exception unless drop_missing == True; if an Exception occurs the record is restored before reraising
source code
 
scan(table, direction='forward', filter=<function <lambda> at 0x7f9a4899b230>)
moves record pointer forward 1; returns False if Eof/Bof reached table must be derived from _Navigation or have skip() method
source code
 
scatter(record, as_type=<function create_template at 0x7f9a4899a500>, _mappings=<class '_abcoll.Mapping'>)
returns as_type() of [fieldnames and] values.
source code
Variables [hide private]
  py_ver = (2, 7)
  LOGICAL_BAD_IS_NONE = True
hash(x)
  input_decoding = 'ascii'
  default_type = 'db3'
  temp_dir = ''
  pql_user_functions = {}
  _Template_Records = {}
  days_per_month = [31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, ...
  days_per_leap_month = [31, 31, 29, 31, 30, 31, 30, 31, 31, 30,...
  SYSTEM = 1
  NULLABLE = 2
  BINARY = 4
  TYPE = 0
  START = 1
  LENGTH = 2
  END = 3
  DECIMALS = 4
  FLAGS = 5
  CLASS = 6
  EMPTY = 7
  NULL = 8
  FIELD_FLAGS = {1: 'system', 2: 'null', 4: 'binary', 'binary': ...
  IN_MEMORY = 0
  ON_DISK = 1
  CLOSED = 'closed'
  READ_ONLY = 'read-only'
  READ_WRITE = 'read-write'
  Null = <null>
  Vapor = Vapor()
  basestring = (<type 'str'>, <type 'unicode'>, <class 'dbf.ver_...
  baseinteger = (<type 'int'>, <type 'long'>)
  NullDate = Date()
  NullDateTime = DateTime()
  NullTime = Time()
  Truth = Logical('T')
  Falsth = Logical('F')
  Unknown = Logical('?')
  On = Quantum('Y')
  Off = Quantum('N')
  Other = Quantum('?')
  _DeadObject = _DeadObject()
  VFPTIME = 1721425
  table_types = {'clp': <class 'dbf.ver_2.ClpTable'>, 'db3': <cl...
  version_map = {'\x02': 'FoxBASE', '\x03': 'dBase III Plus', '\...
  code_pages = {'\x00': ('ascii', 'plain ol\' ascii'), '\x01': (...
  default_codepage = 'ascii'
  pql_functions = {'select': pql_select, 'update': pql_update, '...
  LAST_APRIL = <RelativeMonth.NEXT_JUNE: ()>
  LAST_AUGUST = <RelativeMonth.NEXT_JUNE: ()>
  LAST_DECEMBER = <RelativeMonth.NEXT_JUNE: ()>
  LAST_FEBRUARY = <RelativeMonth.NEXT_JUNE: ()>
  LAST_FRIDAY = <RelativeDay.LAST_SUNDAY: ()>
  LAST_JANUARY = <RelativeMonth.NEXT_JUNE: ()>
  LAST_JULY = <RelativeMonth.NEXT_JUNE: ()>
  LAST_JUNE = <RelativeMonth.NEXT_JUNE: ()>
  LAST_MARCH = <RelativeMonth.NEXT_JUNE: ()>
  LAST_MAY = <RelativeMonth.NEXT_JUNE: ()>
  LAST_MONDAY = <RelativeDay.LAST_SUNDAY: ()>
  LAST_NOVEMBER = <RelativeMonth.NEXT_JUNE: ()>
  LAST_OCTOBER = <RelativeMonth.NEXT_JUNE: ()>
  LAST_SATURDAY = <RelativeDay.LAST_SUNDAY: ()>
  LAST_SEPTEMBER = <RelativeMonth.NEXT_JUNE: ()>
  LAST_SUNDAY = <RelativeDay.LAST_SUNDAY: ()>
  LAST_THURSDAY = <RelativeDay.LAST_SUNDAY: ()>
  LAST_TUESDAY = <RelativeDay.LAST_SUNDAY: ()>
  LAST_WEDNESDAY = <RelativeDay.LAST_SUNDAY: ()>
  NEXT_APRIL = <RelativeMonth.NEXT_JUNE: ()>
  NEXT_AUGUST = <RelativeMonth.NEXT_JUNE: ()>
  NEXT_DECEMBER = <RelativeMonth.NEXT_JUNE: ()>
  NEXT_FEBRUARY = <RelativeMonth.NEXT_JUNE: ()>
  NEXT_FRIDAY = <RelativeDay.LAST_SUNDAY: ()>
  NEXT_JANUARY = <RelativeMonth.NEXT_JUNE: ()>
  NEXT_JULY = <RelativeMonth.NEXT_JUNE: ()>
  NEXT_JUNE = <RelativeMonth.NEXT_JUNE: ()>
  NEXT_MARCH = <RelativeMonth.NEXT_JUNE: ()>
  NEXT_MAY = <RelativeMonth.NEXT_JUNE: ()>
  NEXT_MONDAY = <RelativeDay.LAST_SUNDAY: ()>
  NEXT_NOVEMBER = <RelativeMonth.NEXT_JUNE: ()>
  NEXT_OCTOBER = <RelativeMonth.NEXT_JUNE: ()>
  NEXT_SATURDAY = <RelativeDay.LAST_SUNDAY: ()>
  NEXT_SEPTEMBER = <RelativeMonth.NEXT_JUNE: ()>
  NEXT_SUNDAY = <RelativeDay.LAST_SUNDAY: ()>
  NEXT_THURSDAY = <RelativeDay.LAST_SUNDAY: ()>
  NEXT_TUESDAY = <RelativeDay.LAST_SUNDAY: ()>
  NEXT_WEDNESDAY = <RelativeDay.LAST_SUNDAY: ()>
  SEEK_CUR = 1
  SEEK_END = 2
  SEEK_SET = 0
  __package__ = 'dbf'
  dbf = <dbf.fake_module object at 0x7f9a48799cd0>
Function Details [hide private]

update_vfp_datetime(moment, *ignore)

source code 

Sets the date/time stored in moment
moment must have fields:
    year, month, day, hour, minute, second, microsecond


Variables Details [hide private]

days_per_month

Value:
[31, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31]

days_per_leap_month

Value:
[31, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31]

FIELD_FLAGS

Value:
{1: 'system',
 2: 'null',
 4: 'binary',
 'binary': 4,
 'nocptrans': 4,
 'null': 2}

basestring

Value:
(<type 'str'>, <type 'unicode'>, <class 'dbf.ver_2.Char'>)

table_types

Value:
{'clp': <class 'dbf.ver_2.ClpTable'>,
 'db3': <class 'dbf.ver_2.Db3Table'>,
 'fp': <class 'dbf.ver_2.FpTable'>,
 'vfp': <class 'dbf.ver_2.VfpTable'>}

version_map

Value:
{'\x02': 'FoxBASE',
 '\x03': 'dBase III Plus',
 '\x04': 'dBase IV',
 '\x05': 'dBase V',
 '0': 'Visual FoxPro',
 '1': 'Visual FoxPro (auto increment field)',
 '2': 'Visual FoxPro (VarChar, VarBinary, or BLOB enabled)',
 'C': 'dBase IV SQL table files',
...

code_pages

Value:
{'\x00': ('ascii', 'plain ol\' ascii'),
 '\x01': ('cp437', 'U.S. MS-DOS'),
 '\x02': ('cp850', 'International MS-DOS'),
 '\x03': ('cp1252', 'Windows ANSI'),
 '\x04': ('mac_roman', 'Standard Macintosh'),
 '\x08': ('cp865', 'Danish OEM'),
 '\t': ('cp437', 'Dutch OEM'),
 '''
...

pql_functions

Value:
{'select': pql_select, 'update': pql_update, 'replace': pql_update, 'i\
nsert': None, 'delete': pql_delete, 'recall': pql_recall, 'add': pql_a\
dd, 'drop': pql_drop, 'count': None, 'pack': pql_pack, 'resize': pql_r\
esize,}