@contextlib.contextmanager<EOL><INDENT>def _get_cursor(self, n_retries=<NUM_LIT:1>):<DEDENT>
n_tries_rem = n_retries + <NUM_LIT:1><EOL>while n_tries_rem > <NUM_LIT:0>:<EOL><INDENT>try:<EOL><INDENT>conn = self._pool.getconn() if self.pooling else self._conn<EOL>conn.autocommit = True<EOL>cur = conn.cursor(cursor_factory=psycopg2.extras.DictCursor)<EOL>cur.execute("<STR_LIT>".format(self=self))<EOL>yield cur<EOL>cur.close()<EOL>if self.pooling:<EOL><INDENT>self._pool.putconn(conn)<EOL><DEDENT>break<EOL><DEDENT>except psycopg2.OperationalError:<EOL><INDENT>_logger.warning(<EOL>"<STR_LIT>".format(url=self.url))<EOL>if self.pooling:<EOL><INDENT>self._pool.closeall()<EOL><DEDENT>self._connect()<EOL>_logger.warning("<STR_LIT>".format(url=self.url))<EOL><DEDENT>n_tries_rem -= <NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>raise HGVSError("<STR_LIT>".format(<EOL>url=self.url, n=n_retries))<EOL><DEDENT>
Returns a context manager for obtained from a single or pooled
        connection, and sets the PostgreSQL search_path to the schema
        specified in the connection URL.

        Although *connections* are threadsafe, *cursors* are bound to
        connections and are *not* threadsafe. Do not share cursors
        across threads.

        Use this funciton like this::

            with hdp._get_cursor() as cur:
                # your code

        Do not call this function outside a contextmanager.