12 |
|
|
13 |
__version__ = "$Revision$" |
__version__ = "$Revision$" |
14 |
|
|
15 |
|
import inspect |
16 |
|
import warnings |
17 |
|
|
18 |
import dbflib |
import dbflib |
19 |
|
|
20 |
# the field types supported by a Table instance. |
# the field types supported by a Table instance. |
33 |
|
|
34 |
"""Mixin to implement the old table interface using the new one""" |
"""Mixin to implement the old table interface using the new one""" |
35 |
|
|
36 |
|
def __deprecation_warning(self): |
37 |
|
"""Issue a DeprecationWarning for code hat uses the old interface""" |
38 |
|
callername = inspect.currentframe().f_back.f_code.co_name |
39 |
|
warnings.warn("The %s method of the old table interface" |
40 |
|
" is deprecated" % callername, |
41 |
|
DeprecationWarning, stacklevel = 3) |
42 |
|
|
43 |
def record_count(self): |
def record_count(self): |
44 |
|
self.__deprecation_warning() |
45 |
return self.NumRows() |
return self.NumRows() |
46 |
|
|
47 |
def field_count(self): |
def field_count(self): |
48 |
|
self.__deprecation_warning() |
49 |
return self.NumColumns() |
return self.NumColumns() |
50 |
|
|
51 |
def field_info(self, field): |
def field_info(self, field): |
56 |
and prec will be zero if the information returned by the Column |
and prec will be zero if the information returned by the Column |
57 |
method doesn't provide values for them. |
method doesn't provide values for them. |
58 |
""" |
""" |
59 |
|
self.__deprecation_warning() |
60 |
col = self.Column(field) |
col = self.Column(field) |
61 |
return (col.type, col.name, |
return (col.type, col.name, |
62 |
getattr(col, "width", 0), getattr(col, "prec", 0)) |
getattr(col, "width", 0), getattr(col, "prec", 0)) |
63 |
|
|
64 |
def field_info_by_name(self, col): |
def field_info_by_name(self, col): |
65 |
|
self.__deprecation_warning() |
66 |
try: |
try: |
67 |
return self.field_info(col) |
return self.field_info(col) |
68 |
except KeyError: |
except KeyError: |
71 |
return None |
return None |
72 |
|
|
73 |
def field_range(self, fieldName): |
def field_range(self, fieldName): |
74 |
|
self.__deprecation_warning() |
75 |
min, max = self.ValueRange(fieldName) |
min, max = self.ValueRange(fieldName) |
76 |
return ((min, None), (max, None)) |
return ((min, None), (max, None)) |
77 |
|
|
78 |
def GetUniqueValues(self, field): |
def GetUniqueValues(self, field): |
79 |
|
self.__deprecation_warning() |
80 |
return self.UniqueValues(field) |
return self.UniqueValues(field) |
81 |
|
|
82 |
def read_record(self, r): |
def read_record(self, r): |
83 |
|
self.__deprecation_warning() |
84 |
return self.ReadRowAsDict(r) |
return self.ReadRowAsDict(r) |
85 |
|
|
86 |
|
|
169 |
""" |
""" |
170 |
return self.column_map[col] |
return self.column_map[col] |
171 |
|
|
172 |
|
def HasColumn(self, col): |
173 |
|
"""Return whether the table has a column with the given name or index |
174 |
|
""" |
175 |
|
return self.column_map.has_key(col) |
176 |
|
|
177 |
def ReadRowAsDict(self, row): |
def ReadRowAsDict(self, row): |
178 |
"""Return the entire row as a dictionary with column names as keys""" |
"""Return the entire row as a dictionary with column names as keys""" |
179 |
return self.dbf.read_record(row) |
return self.dbf.read_record(row) |
302 |
""" |
""" |
303 |
return self.columns |
return self.columns |
304 |
|
|
305 |
|
def HasColumn(self, col): |
306 |
|
"""Return whether the table has a column with the given name or index |
307 |
|
""" |
308 |
|
return self.column_map.has_key(col) |
309 |
|
|
310 |
def NumRows(self): |
def NumRows(self): |
311 |
"""Return the number of rows in the table""" |
"""Return the number of rows in the table""" |
312 |
return len(self.data) |
return len(self.data) |