/[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 984 by bh, Thu May 22 16:37:48 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 196  class DBFTable(OldTableInterfaceMixin): Line 218  class DBFTable(OldTableInterfaceMixin):
218          values.sort()          values.sort()
219          return values          return values
220    
221        def Dependencies(self):
222            """Return an empty sequence. The DBFTable doesn't depend on anything"""
223            return ()
224    
225      # DBF specific interface parts.      # DBF specific interface parts.
226    
# Line 226  class DBFTable(OldTableInterfaceMixin): Line 251  class DBFTable(OldTableInterfaceMixin):
251    
252    
253    
 # Temporary backwards compatibility  
 Table = DBFTable  
   
   
   
254  class MemoryColumn:  class MemoryColumn:
255    
256      def __init__(self, name, type, index):      def __init__(self, name, type, index):
# Line 280  class MemoryTable(OldTableInterfaceMixin Line 300  class MemoryTable(OldTableInterfaceMixin
300          """          """
301          return self.columns          return self.columns
302    
303        def HasColumn(self, col):
304            """Return whether the table has a column with the given name or index
305            """
306            return self.column_map.has_key(col)
307    
308      def NumRows(self):      def NumRows(self):
309          """Return the number of rows in the table"""          """Return the number of rows in the table"""
310          return len(self.data)          return len(self.data)
# Line 322  class MemoryTable(OldTableInterfaceMixin Line 347  class MemoryTable(OldTableInterfaceMixin
347          values.sort()          values.sort()
348          return values          return values
349    
350        def Dependencies(self):
351            """Return an empty sequence. The MemoryTable doesn't depend on anything
352            """
353            return ()
354    
355      def write_record(self, record, values):      def write_record(self, record, values):
356          # TODO: Check for correct lenght and perhaps also          # TODO: Check for correct lenght and perhaps also

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26