Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _fetch(self):
if not self._row_desc:
raise ProgrammingError("no result set")
self._lock.acquire()
try:
if not self._cached_rows:
if self._command_complete:
return None
self._fill_cache()
if self._command_complete and not self._cached_rows:
# fill cache tells us the command is complete, but yet we
# have no rows after filling our cache. This is a special
# case when a query returns no rows.
return None
row = self._cached_rows.pop(0)
self._ongoing_row_count += 1
return tuple(row)
finally:
self._lock.release()
try:
self._c._lock.acquire()
return self._cached_rows.popleft()
except IndexError:
if self.portal_suspended:
self._c.send_EXECUTE(self)
self._c._write(SYNC_MSG)
self._c._flush()
self._c.handle_messages(self)
if not self.portal_suspended:
self._c.close_portal(self)
try:
return self._cached_rows.popleft()
except IndexError:
if self.ps is None:
raise ProgrammingError("A query hasn't been issued.")
elif len(self.ps['row_desc']) == 0:
raise ProgrammingError("no result set")
else:
raise StopIteration()
finally:
self._c._lock.release()
location,text,geolocation) VALUES (" + str(tid) +\
",'" + uname + "', to_timestamp('" + str(created_at) + "','YYYY-MM-DD HH24:MI:SS'),'" +\
str(location) + "',\'" + str(text) +\
"\'," + geoloc + ")"
print query
print uname, "\t", text[:50], geo['coordinates']
#query = """INSERT INTO geolondon(tid, uname,
#created_at, location, text, geolocation)
# VALUES(%s,%s,to_timestamp(%s, \'YYYY-MM-DD
# HH24:MI:SS\'),%s,%s,ST_GeographyFromText(SRID=4326;POINT(%s,%s)))"""
#params = (tid,uname,str(created_at),location,text,str(geolong),str(geolat))
#print "[sql] params ", query
try:
cursor.execute( query )
except ProgrammingError, e:
print query
print e
continue
else:
sql_query = """INSERT INTO geolondon(tid, uname, created_at, location, text) VALUES
(%s,%s,to_timestamp(%s, \'YYYY-MM-DD HH24:MI:SS\'),%s,%s)"""
params = (tid, uname, str(created_at), location, text)
#print "[params]", params
print uname, "\t", text[:50]
try:
cursor.execute(sql_query, params)
except ProgrammingError, e:
print params
print e
continue
return self._cached_rows.popleft()
except IndexError:
if self.portal_suspended:
self._c.send_EXECUTE(self)
self._c._write(SYNC_MSG)
self._c._flush()
self._c.handle_messages(self)
if not self.portal_suspended:
self._c.close_portal(self)
try:
return self._cached_rows.popleft()
except IndexError:
if self.ps is None:
raise ProgrammingError("A query hasn't been issued.")
elif len(self.ps['row_desc']) == 0:
raise ProgrammingError("no result set")
else:
raise StopIteration()
finally:
self._c._lock.release()
# A cursor's copy_to or copy_from argument was not provided a table or query
# to operate on.
class CopyQueryOrTableRequiredError(ProgrammingError):
pass
# Raised if a COPY query is executed without using copy_to or copy_from
# functions to provide a data stream.
class CopyQueryWithoutStreamError(ProgrammingError):
pass
# When query parameters don't match up with query args.
class QueryParameterIndexError(ProgrammingError):
pass
# Some sort of parse error occured during query parameterization.
class QueryParameterParseError(ProgrammingError):
pass
pass
# Raised if a COPY query is executed without using copy_to or copy_from
# functions to provide a data stream.
class CopyQueryWithoutStreamError(ProgrammingError):
pass
# When query parameters don't match up with query args.
class QueryParameterIndexError(ProgrammingError):
pass
# Some sort of parse error occured during query parameterization.
class QueryParameterParseError(ProgrammingError):
pass
# An exception that is thrown when an internal error occurs trying to
# decode binary array data from the server.
class ArrayDataParseError(InternalError):
pass
##
# Thrown when attempting to transmit an array of unsupported data types.
class ArrayContentNotSupportedError(NotSupportedError):
pass
##
# Thrown when attempting to send an array that doesn't contain all the same
# type of objects (eg. some floats, some ints).
class ArrayContentNotHomogenousError(ProgrammingError):
pass
##
# Attempted to pass an empty array in, but it's not possible to determine the
# data type for an empty array.
class ArrayContentEmptyError(ProgrammingError):
pass
##
# Attempted to use a multidimensional array with inconsistent array sizes.
class ArrayDimensionsNotConsistentError(ProgrammingError):
pass
##
# Attempted to use a multidimensional array with inconsistent array sizes.
class ArrayDimensionsNotConsistentError(ProgrammingError):
pass
# A cursor's copy_to or copy_from argument was not provided a table or query
# to operate on.
class CopyQueryOrTableRequiredError(ProgrammingError):
pass
# Raised if a COPY query is executed without using copy_to or copy_from
# functions to provide a data stream.
class CopyQueryWithoutStreamError(ProgrammingError):
pass
# When query parameters don't match up with query args.
class QueryParameterIndexError(ProgrammingError):
pass
# Some sort of parse error occured during query parameterization.
class QueryParameterParseError(ProgrammingError):
pass
ssl=False):
self._client_encoding = "ascii"
self._integer_datetimes = False
self._server_version = None
self._sock_buf = ""
self._sock_lock = threading.Lock()
if unix_sock is None and host is not None:
self._sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
elif unix_sock is not None:
if not hasattr(socket, "AF_UNIX"):
raise errors.InterfaceError(
"attempt to connect to unix socket on "
"unsupported platform")
self._sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
else:
raise errors.ProgrammingError(
"one of host or unix_sock must be provided")
if unix_sock is None and host is not None:
self._sock.connect((host, port))
elif unix_sock is not None:
self._sock.connect(unix_sock)
if ssl:
self._sock_lock.acquire()
try:
self._flush_messages(SSLRequest().serialize())
resp = self._sock.recv(1)
if resp == 'S' and sslmodule is not None:
self._sock = sslmodule.wrap_socket(self._sock)
elif sslmodule is None:
raise errors.InterfaceError(
"SSL required but ssl module not available in "
"this python installation")
def handle_ERROR_RESPONSE(self, data, ps):
msg_dict = data_into_dict(data)
if msg_dict[RESPONSE_CODE] == "28000":
raise InterfaceError("md5 password authentication failed")
else:
raise ProgrammingError(
msg_dict[RESPONSE_SEVERITY], msg_dict[RESPONSE_CODE],
msg_dict[RESPONSE_MSG])