/[thuban]/branches/WIP-pyshapelib-bramz/Thuban/Model/table.py
ViewVC logotype

Diff of /branches/WIP-pyshapelib-bramz/Thuban/Model/table.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 818 by bh, Mon May 5 17:18:31 2003 UTC revision 839 by bh, Tue May 6 15:54:18 2003 UTC
# Line 12  Classes for handling tables of data. Line 12  Classes for handling tables of data.
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.
# Line 30  class OldTableInterfaceMixin: Line 33  class OldTableInterfaceMixin:
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):
# Line 44  class OldTableInterfaceMixin: Line 56  class OldTableInterfaceMixin:
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:
# Line 57  class OldTableInterfaceMixin: Line 71  class OldTableInterfaceMixin:
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    
# Line 152  class DBFTable(OldTableInterfaceMixin): Line 169  class DBFTable(OldTableInterfaceMixin):
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)
# Line 280  class MemoryTable(OldTableInterfaceMixin Line 302  class MemoryTable(OldTableInterfaceMixin
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)

Legend:
Removed from v.818  
changed lines
  Added in v.839

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26