Django

Code

Changeset 9284

Show
Ignore:
Timestamp:
10/26/08 17:24:21 (3 months ago)
Author:
jbronn
Message:

Fixed #9448 -- Layer objects now carry a reference to their parent DataSource. Thanks, Matthew D. Hancher for the bug report.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/contrib/gis/gdal/datasource.py

    r8219 r9284  
    112112        else: 
    113113            raise TypeError('Invalid index type: %s' % type(index)) 
    114         return Layer(l
     114        return Layer(l, self
    115115         
    116116    def __len__(self): 
  • django/trunk/django/contrib/gis/gdal/layer.py

    r8219 r9284  
    2626 
    2727    #### Python 'magic' routines #### 
    28     def __init__(self, layer_ptr): 
    29         "Needs a C pointer (Python/ctypes integer) in order to initialize." 
     28    def __init__(self, layer_ptr, ds): 
     29        """ 
     30        Initializes on an OGR C pointer to the Layer and the `DataSource` object 
     31        that owns this layer.  The `DataSource` object is required so that a  
     32        reference to it is kept with this Layer.  This prevents garbage  
     33        collection of the `DataSource` while this Layer is still active. 
     34        """ 
    3035        self._ptr = None # Initially NULL 
    3136        if not layer_ptr: 
    3237            raise OGRException('Cannot create Layer, invalid pointer given') 
    3338        self._ptr = layer_ptr 
     39        self._ds = ds 
    3440        self._ldefn = get_layer_defn(self._ptr) 
    3541        # Does the Layer support random reading? 
  • django/trunk/django/contrib/gis/tests/test_gdal_ds.py

    r8219 r9284  
    131131            self.assertEqual(control_vals, test_vals) 
    132132 
     133    def test03c_layer_references(self): 
     134        "Test to make sure Layer access is still available without the DataSource." 
     135        source = ds_list[0] 
     136 
     137        # See ticket #9448. 
     138        def get_layer(): 
     139            # This DataSource object is not accessible outside this 
     140            # scope.  However, a reference should still be kept alive 
     141            # on the `Layer` returned. 
     142            ds = DataSource(source.ds) 
     143            return ds[0] 
     144 
     145        # Making sure we can call OGR routines on the Layer returned. 
     146        lyr = get_layer() 
     147        self.assertEqual(source.nfeat, len(lyr)) 
     148        self.assertEqual(source.gtype, lyr.geom_type.num)         
     149 
    133150    def test04_features(self): 
    134151        "Testing Data Source Features."