33 |
dbflib.FTDouble: FIELDTYPE_DOUBLE} |
dbflib.FTDouble: FIELDTYPE_DOUBLE} |
34 |
|
|
35 |
|
|
|
class OldTableInterfaceMixin: |
|
|
|
|
|
"""Mixin to implement the old table interface using the new one""" |
|
|
|
|
|
def __deprecation_warning(self): |
|
|
"""Issue a DeprecationWarning for code hat uses the old interface""" |
|
|
callername = inspect.currentframe().f_back.f_code.co_name |
|
|
warnings.warn("The %s method of the old table interface" |
|
|
" is deprecated" % callername, |
|
|
DeprecationWarning, stacklevel = 3) |
|
|
|
|
|
def record_count(self): |
|
|
self.__deprecation_warning() |
|
|
return self.NumRows() |
|
|
|
|
|
def field_count(self): |
|
|
self.__deprecation_warning() |
|
|
return self.NumColumns() |
|
|
|
|
|
def field_info(self, field): |
|
|
"""Return a tuple (type, name, width, prec) for the field no. field |
|
|
|
|
|
type is the data type of the field, name the name, width the |
|
|
field width in characters and prec the decimal precision. width |
|
|
and prec will be zero if the information returned by the Column |
|
|
method doesn't provide values for them. |
|
|
""" |
|
|
self.__deprecation_warning() |
|
|
col = self.Column(field) |
|
|
return (col.type, col.name, |
|
|
getattr(col, "width", 0), getattr(col, "prec", 0)) |
|
|
|
|
|
def field_info_by_name(self, col): |
|
|
self.__deprecation_warning() |
|
|
try: |
|
|
return self.field_info(col) |
|
|
except KeyError: |
|
|
# FIXME: It may be that field_info raises other exceptions |
|
|
# when the name is not a valid column name. |
|
|
return None |
|
|
|
|
|
def field_range(self, fieldName): |
|
|
self.__deprecation_warning() |
|
|
min, max = self.ValueRange(fieldName) |
|
|
return ((min, None), (max, None)) |
|
|
|
|
|
def GetUniqueValues(self, field): |
|
|
self.__deprecation_warning() |
|
|
return self.UniqueValues(field) |
|
|
|
|
|
def read_record(self, r): |
|
|
self.__deprecation_warning() |
|
|
return self.ReadRowAsDict(r) |
|
|
|
|
|
|
|
|
|
|
36 |
class DBFColumn: |
class DBFColumn: |
37 |
|
|
38 |
"""Description of a column in a DBFTable |
"""Description of a column in a DBFTable |
55 |
self.index = index |
self.index = index |
56 |
|
|
57 |
|
|
58 |
class DBFTable(TitledObject, OldTableInterfaceMixin): |
class DBFTable(TitledObject): |
59 |
|
|
60 |
""" |
""" |
61 |
Table interface for the data in a DBF file |
Table interface for the data in a DBF file |
163 |
The row_is_ordinal is ignored for DBF tables because the row id |
The row_is_ordinal is ignored for DBF tables because the row id |
164 |
is always the row number. |
is always the row number. |
165 |
""" |
""" |
166 |
return self.dbf.read_record(row)[self.column_map[col].name] |
return self.dbf.read_attribute(row, self.column_map[col].index) |
167 |
|
|
168 |
def ValueRange(self, col): |
def ValueRange(self, col): |
169 |
"""Return the minimum and maximum values of the values in the column |
"""Return the minimum and maximum values of the values in the column |
245 |
self.type = type |
self.type = type |
246 |
self.index = index |
self.index = index |
247 |
|
|
248 |
class MemoryTable(TitledObject, OldTableInterfaceMixin): |
class MemoryTable(TitledObject): |
249 |
|
|
250 |
"""Very simple table implementation that operates on a list of tuples""" |
"""Very simple table implementation that operates on a list of tuples""" |
251 |
|
|