Pyjo.Transaction - Transaction base class¶
import Pyjo.Transaction
class MyTransaction(Pyjo.Transaction.object):
def client_read(self, chunk):
...
def client_write(self):
...
def server_read(self, chunk):
...
def server_write(self):
...
Pyjo.Transaction
is an abstract base class for transactions.
Events¶
Pyjo.Transaction
inherits all events from Pyjo.EventEmitter
and can
emit the following new ones.
connection¶
@tx.on
def connection(tx, connection):
...
Emitted when a connection has been assigned to transaction.
Classes¶
-
class
Pyjo.Transaction.
Pyjo_Transaction
(**kwargs)¶ Pyjo.Transaction
inherits all attributes and methods fromPyjo.EventEmitter
and implements the following new ones.-
client_close
(close=False)¶ tx.client_close() tx.client_close(True)
Transaction closed client-side, no actual connection close is assumed by default, used to implement user agents.
-
client_read
(*args, **kwargs)¶ tx.client_read(chunk)
Read data client-side, used to implement user agents. Meant to be overloaded in a subclass.
-
client_write
(*args, **kwargs)¶ chunk = tx.client_write
Write data client-side, used to implement user agents. Meant to be overloaded in a subclass.
-
connection
¶ cid = tx.connection tx.connection = cid
Connection identifier.
-
error
¶ err = tx.error
Get request or response error and return
None
if there is no error, commonly used together withsuccess
.# Longer version err = tx.req.error or tx.res.error # Check for different kinds of errors err = tx.error if err: if err['code']: raise Exception("{code} response: {message}".format(**err)) else: raise Exception("Connection error: {message}".format(**err))
-
is_finished
¶ bool = tx.is_finished
Check if transaction is finished.
-
is_websocket
¶ false = tx.is_websocket
False.
-
is_writing
¶ boolean = tx.is_writing
Check if transaction is writing.
-
kept_alive
= None¶ kept_alive = tx.kept_alive tx.kept_alive = True
Connection has been kept alive.
-
local_address
= None¶ address = tx.local_address tx.local_address = '127.0.0.1'
Local interface address.
-
local_port
= None¶ port = tx.local_port tx.local_port = 8080
Local interface port.
-
original_remote_address
= None¶ address = tx.original_remote_address tx.original_remote_address = '127.0.0.1'
Remote interface address.
-
remote_address
¶ address = tx.remote_address tx.remote_address = '127.0.0.1'
Same as
original_remote_address
or the last value of theX-Forwarded-For
header ifreq
has been performed through a reverse proxy.
-
remote_port
= None¶ port = tx.remote_port tx.remote_port = 8081
Remote interface port.
-
req
= None¶ req = tx.req tx.req = Pyjo.Message.Request.new()
HTTP request, defaults to a
Pyjo.Message.Request
object.
-
res
= None¶ res = tx.res tx.res = Pyjo.Message.Response.new()
HTTP response, defaults to a
Pyjo.Message.Response
object.
-
resume
()¶ tx = tx.resume
Resume transaction.
-
server_close
()¶ tx.server_close
Transaction closed server-side, used to implement web servers.
-
server_read
(*args, **kwargs)¶ tx.server_read(chunk)
Read data server-side, used to implement web servers. Meant to be overloaded in a subclass.
-
server_write
(*args, **kwargs)¶ chunk = tx.server_write()
Write data server-side, used to implement web servers. Meant to be overloaded in a subclass.
-
success
¶ res = tx.success
Returns the
Pyjo.Message.Response
object fromres
if transaction was successful orNone
otherwise. Connection and parser errors have only a message inerror
, 400 and 500 responses also a code.# Sensible exception handling res = tx.success if res: print(res.body) else: err = tx.error if err['code']: raise Exception("{code} response: {message}".format(**err)) else: raise Exception("Connection error: {message}".format(**err))
-
-
Pyjo.Transaction.
object
¶ alias of
Pyjo_Transaction