Given a request with a cursor, return a `Cursor` instance.

        Differs from the standard CursorPagination to handle a tuple in the
        position field.
420270
def decode_cursor(self, request):
        
        # Determine if we have a cursor, and if so then decode it.
        encoded = request.query_params.get(self.cursor_query_param)
        if encoded is None:
            return None

        try:
            querystring = b64decode(encoded.encode('ascii')).decode('ascii')
            tokens = urlparse.parse_qs(querystring, keep_blank_values=True)

            offset = tokens.get('o', ['0'])[0]
            offset = _positive_int(offset, cutoff=self.offset_cutoff)

            reverse = tokens.get('r', ['0'])[0]
            reverse = bool(int(reverse))

            # The difference. Don't get just the 0th entry: get all entries.
            position = tokens.get('p', None)
        except (TypeError, ValueError):
            raise NotFound(self.invalid_cursor_message)

        return Cursor(offset=offset, reverse=reverse, position=position)
1050447
def _produce_return(self, cursor):
        
        results = cursor.fetchmany(2)
        if len(results) != 1:
            return None

        # Return the one row, or the one column.
        row = results[0]
        if self._row_formatter is not None:
            row = self._row_formatter(row, cursor)
        elif len(row) == 1:
            row = row[0]

        return row
339747
def next(self):
    
    out = self.peek()[self._headers.index(self._field)]
    self._cursor += 1
    if out is not None:
      self._lastValue = out
    return out
1143193
def Query(self, query):
    
    cursor = self._database.cursor()
    cursor.execute(query)
    return cursor
617510
def cursor(self):
        
        cursor = self.mdr.cursor()
        with self.transaction():
            try:
                yield cursor
                if cursor.rowcount != -1:
                    self.last_row_count = cursor.rowcount
                self.last_row_id = getattr(cursor, 'lastrowid', None)
            except:
                self.last_row_count = None
                self.last_row_id = None
                _safe_close(cursor)
                raise
1038723
def restore(self, cursor):
    "  "

    if not isinstance(cursor, Cursor):
      raise TypeError('expected Cursor object', type(cursor))
    self.index, self.lineno, self.colno = cursor
114609
def cursor(self):
        
        self._assert_valid()
        c = Cursor(self.impl.cursor())
        self.cursors.add(c)
        return c
1094404
def get_cursor_position(self):
        """"""
        # TODO would this be cleaner as a parameter?
        in_stream = self.in_stream

        query_cursor_position = u"\x1b[6n"
        self.write(query_cursor_position)

        def retrying_read():
            while True:
                try:
                    c = in_stream.read(1)
                    if c == '':
                        raise ValueError("Stream should be blocking - should't"
                                         " return ''. Returned %r so far",
                                         (resp,))
                    return c
                except IOError:
                    raise ValueError(
                        'cursor get pos response read interrupted'
                    )
                    # find out if this ever really happens - if so, continue

        resp = ''
        while True:
            c = retrying_read()
            resp += c
            m = re.search('(?P<extra>.*)'
                          '(?P<CSI>\x1b\[|\x9b)'
                          '(?P<row>\\d+);(?P<column>\\d+)R', resp, re.DOTALL)
            if m:
                row = int(m.groupdict()['row'])
                col = int(m.groupdict()['column'])
                extra = m.groupdict()['extra']
                if extra:
                    if self.extra_bytes_callback:
                        self.extra_bytes_callback(
                            extra.encode(in_stream.encoding)
                        )
                    else:
                        raise ValueError(("Bytes preceding cursor position "
                                          "query response thrown out:\n%r\n"
                                          "Pass an extra_bytes_callback to "
                                          "CursorAwareWindow to prevent this")
                                         % (extra,))
                return (row - 1, col - 1)
675041
def create_cursor(self, name=None):
        """"""
        cursor = self.connection.cursor()
        cursor.tzinfo_factory = self.tzinfo_factory
        return cursor
475213
def handle_imcursor(self, pkt):
        
        self.logger.debug("handle imcursor")

        if pkt.tid & IIS_READ:
            if pkt.tid & IMC_SAMPLE:
                self.logger.debug("SAMPLE")
                # return the cursor position
                wcsflag = int(pkt.z)
                #wcsflag = 0
                res = self.server.controller.get_keystroke()

                self.return_cursor(pkt.dataout, res.x, res.y,
                                   res.frame, wcsflag, '0', '')
            else:
                self.logger.debug("OTHER")
                res = self.server.controller.get_keystroke()
                self.logger.debug("FRAME=%d X,Y=%f,%f" % (
                    res.frame, res.x, res.y))
                ## sx = self.x
                self.x = res.x
                self.y = res.y
                self.frame = res.frame
                ## sy = self.y
                ## frame = self.frame
                #wcsflag = 1
                wcsflag = 0

                #self.return_cursor(pkt.dataout, sx, sy, frame, 1, key, '')
                self.return_cursor(pkt.dataout, res.x, res.y,
                                   res.frame, wcsflag, res.key, '')
        else:
            self.logger.debug("READ")
            # read the cursor position in logical coordinates
            sx = int(pkt.x)
            sy = int(pkt.y)
            wx = float(pkt.x)
            wy = float(pkt.y)
            wcs = int(pkt.z)

            if wcs:
                # decode the WCS info for the current frame
                try:
                    fb = self.server.controller.get_frame(self.frame)
                except KeyError:
                    # the selected frame does not exist, create it
                    fb = self.server.controller.init_frame(self.frame)
                fb.ct = self.wcs_update(fb.wcs)

                if fb.ct.valid:
                    if abs(fb.ct.a) > 0.001:
                        sx = int((wx - fb.ct.tx) / fb.ct.a)
                    if abs(fb.ct.d) > 0.001:
                        sy = int((wy - fb.ct.ty) / fb.ct.d)

            self.server.controller.set_cursor(sx, sy)
73047
def _cursor(self, *args, **kwargs):
        """"""
        # The args and kwargs are not part of the standard,
        # but some database modules seem to use these.
        transaction = self._transaction
        if not transaction:
            self._ping_check(2)
        try:
            if self._maxusage:
                if self._usage >= self._maxusage:
                    # the connection was used too often
                    raise self._failure
            cursor = self._con.cursor(*args, **kwargs)  # try to get a cursor
        except self._failures as error:  # error in getting cursor
            try:  # try to reopen the connection
                con = self._create()
            except Exception:
                pass
            else:
                try:  # and try one more time to get a cursor
                    cursor = con.cursor(*args, **kwargs)
                except Exception:
                    pass
                else:
                    self._close()
                    self._store(con)
                    if transaction:
                        raise error  # re-raise the original error again
                    return cursor
                try:
                    con.close()
                except Exception:
                    pass
            if transaction:
                self._transaction = False
            raise error  # re-raise the original error again
        return cursor
23788
def _dictionary_to_cursor(self, obj):
        
        if obj.get("id"):
            obj["_id"] = ObjectId(obj.get("id"))
            del obj["id"]

        if isinstance(obj.get("_id"), str):
            obj["_id"] = ObjectId(obj.get("_id"))

        return obj
973908
def _get_result_wrapper(self, query):
        
        cursor = RowsCursor(self._rows, self._cursor.description)
        return query._get_cursor_wrapper(cursor)
1344037
def _cursor_position(self, data):
        
        column, line = self._get_line_and_col(data)
        self._move_cursor_to_line(line)
        self._move_cursor_to_column(column)
        self._last_cursor_pos = self._cursor.position()
803797
def _get_cursor(self):
        '''
        
        '''
        _options = self._get_options()
        conn = sqlcipher.connect(_options.get('database'),
                                 timeout=float(_options.get('timeout')))
        conn.execute('pragma key="{0}"'.format(_options.get('pass')))
        cursor = conn.cursor()
        try:
            yield cursor
        except sqlcipher.Error as err:
            log.exception('Error in ext_pillar SQLCipher: %s', err.args)
        finally:
            conn.close()
1007138
def cursor(self, as_dict=False):
        """"""
        self.ensure_connect()
        ctype = self.real_ctype(as_dict)
        return self._connect.cursor(ctype)
1060524
def _obj_cursor_to_dictionary(self, cursor):
        
        if not cursor:
            return cursor

        cursor = json.loads(json.dumps(cursor, cls=BSONEncoder))

        if cursor.get("_id"):
            cursor["id"] = cursor.get("_id")
            del cursor["_id"]

        return cursor