def _cursor(self):
        if self.connection is None:
            ## The following is the same as in django.db.backends.sqlite3.base ##
            settings_dict = self.settings_dict
            if not settings_dict['NAME']:
                raise ImproperlyConfigured("Please fill out the database NAME in the settings module before using the database.")
            kwargs = {
                'database': settings_dict['NAME'],
                'detect_types': Database.PARSE_DECLTYPES | Database.PARSE_COLNAMES,
            }
            kwargs.update(settings_dict['OPTIONS'])
            self.connection = Database.connect(**kwargs)
            # Register extract, date_trunc, and regexp functions.
            self.connection.create_function("django_extract", 2, _sqlite_extract)
            self.connection.create_function("django_date_trunc", 2, _sqlite_date_trunc)
            self.connection.create_function("regexp", 2, _sqlite_regexp)
            connection_created.send(sender=self.__class__, connection=self)

            ## From here on, customized for GeoDjango ##

            # Enabling extension loading on the SQLite connection.
            try:
                self.connection.enable_load_extension(True)
            except __HOLE__:
                raise ImproperlyConfigured('The pysqlite library does not support C extension loading. '
                                           'Both SQLite and pysqlite must be configured to allow '
                                           'the loading of extensions to use SpatiaLite.'
                                           )

            # Loading the SpatiaLite library extension on the connection, and returning
            # the created cursor.
            cur = self.connection.cursor(factory=SQLiteCursorWrapper)
            try:
                cur.execute("SELECT load_extension(%s)", (self.spatialite_lib,))
            except Exception, msg:
                raise ImproperlyConfigured('Unable to load the SpatiaLite library extension '
                                           '"%s" because: %s' % (self.spatialite_lib, msg))
            return cur
        else:
            return self.connection.cursor(factory=SQLiteCursorWrapper)
dataset/ETHPy150Open AppScale/appscale/AppServer/lib/django-1.2/django/contrib/gis/db/backends/spatialite/base.py/DatabaseWrapper._cursor