Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _authenticate_reader():
reader = MessageReader(args=('user', 'kwargs'))
def auth_request(connection, msg, context):
return connection._authentication_request(
msg, context.user, **context.kwargs)
reader.add_message(AuthenticationRequest, auth_request)
return reader
def _bind_nodata_response_reader():
reader = MessageReader(args=('copy_stream', 'output'))
reader.add_message(
CopyOutResponse, lambda conn, msg, context:
conn._copy_out_response(msg, context.copy_stream))
reader.add_message(
CopyInResponse, lambda conn, msg, context:
conn._copy_in_response(msg, context.copy_stream))
def cmd_complete(conn, msg, context):
context.output.setdefault('msg', msg)
return CONTINUE_READ_LOOP
reader.add_message(CommandComplete, cmd_complete)
reader.add_message(ReadyForQuery, SUCCESS_READ_LOOP)
reader.delay_raising_exception = True
return reader
def _copy_out_response_reader():
reader = MessageReader(args=('fileobj',))
reader.add_message(
CopyData, lambda conn, msg, context:
conn._copy_data(msg, context.fileobj))
reader.add_message(CopyDone, SUCCESS_READ_LOOP)
return reader
def _sync_reader():
reader = MessageReader(args=())
reader.ignore_unhandled_messages = True
reader.add_message(ReadyForQuery, SUCCESS_READ_LOOP)
return reader
def _bind_reader():
reader = MessageReader(args=('portal', 'copy_stream'))
# BindComplete is good -- just ignore
reader.add_message(BindComplete, CONTINUE_READ_LOOP)
# NoData in this case means we're not executing a query. As a
# result, we won't be fetching rows, so we'll never execute the
# portal we just created... unless we execute it right away, which
# we'll do.
reader.add_message(
NoData, lambda conn, msg, context: conn._bind_nodata(
msg, context.portal, context.copy_stream))
# Return the new row desc, since it will have the format types we
# asked the server for
reader.add_message(
RowDescription, lambda conn, msg, context: (msg, None))
def _fetch_commandcomplete_reader():
reader = MessageReader(args=())
reader.add_message(
ReadyForQuery,
lambda conn, msg, context: conn._fetch_commandcomplete_rfq(msg))
reader.add_message(CloseComplete, CONTINUE_READ_LOOP)
return reader
def _auth_request_reader():
reader = MessageReader(args=())
reader.add_message(
ReadyForQuery,
lambda conn, msg, context: conn._ready_for_query(msg))
reader.add_message(
BackendKeyData,
lambda conn, msg, context:
conn._receive_backend_key_data(msg))
return reader
def _parse_reader():
reader = MessageReader(args=('param_fc',))
# ParseComplete is good.
reader.add_message(ParseComplete, CONTINUE_READ_LOOP)
# Well, we don't really care -- we're going to send whatever we
# want and let the database deal with it. But thanks anyways!
reader.add_message(ParameterDescription, CONTINUE_READ_LOOP)
# We're not waiting for a row description. Return something
# destinctive to let bind know that there is no output.
reader.add_message(
NoData, lambda conn, msg, context: (None, context.param_fc))
# Common row description response
reader.add_message(
RowDescription, lambda conn, msg, context: (msg, context.param_fc))
return reader