hio.core.http

hio.core.http Package

Submodules

Package Contents

Classes

Client

Client class nonblocking HTTP client connection manager and HTTP client

ClientDoer

HTTP Client Doer

BareServer

BareServer class nonblocking Bare (non-WSGI) HTTP server

Server

Server WSGI HTTP Server Class

ServerDoer

HTTP WSGI Server Doer

Functions

openClient(cls=None, **kwa)

Wrapper to create and open HTTP Client instances

openServer(cls=None, **kwa)

Wrapper to create and open HTTP Server instances

Attributes

WsgiServer

exception hio.core.http.HTTPError(status, reason='', title='', detail='', fault=None, headers=None)[source]

Bases: Exception

HTTP error for use with Valet or Other WSGI servers to raise exceptions caught by the WSGI server.

status is int HTTP status code, e.g. 400
reason is  str HTTP status text, "Unknown Error"
title  is str title of error
headers is dict of extra headers to add to the response
error

An internal application error code

Type

int

__slots__ = ['status', 'reason', 'title', 'detail', 'headers', 'fault']
__repr__(self)

Return repr(self).

render(self, jsonify=False)

Render and return the attributes as a bytes If jsonify then render as serialized json

class hio.core.http.Client(connector=None, requester=None, respondent=None, name='', uid=0, bufsize=8096, wl=None, hostname='127.0.0.1', port=None, scheme='', method='GET', path='/', headers=None, qargs=None, fragment='', body=b'', data=None, fargs=None, requests=None, msg=None, dictable=None, events=None, redirectable=True, redirects=None, responses=None, **kwa)[source]

Client class nonblocking HTTP client connection manager and HTTP client request and response processor

wind(self, tymth)

Inject new tymist.tymth as new ._tymth. Changes tymist.tyme base. Updates winds .tymer .tymth

reopen(self)

Return result of .connector.reopen()

close(self)

Call .connecter.close (shutclose)

static attrify(response)

Convert response dict into named tuple Response so can access fields as attributes

respond(self)

Pops and returns next response from .responses if any Otherwise returns None

request(self, method=None, path=None, qargs=None, fragment=None, headers=None, body=None, data=None, fargs=None, reply=None, **kwa)

Create and append request dict onto .requests with updated values from parameters. Use existing .requester values if not provided except for body. Body/Data/fargs must be newly provided. This is a differential request that reuses latest values if not changed. Requires that patron already be setup with scheme host port

request = dict([(‘method’, method),

(‘path’, path), (‘qargs’, dict([(“auth”, self.token.value)])), (‘headers’, dict([(‘Accept’, ‘application/json’),

(‘Connection’, ‘Keep-Alive’), (‘Keep-Alive’, ‘timeout=60, max=100’), ])),

(‘body’, body), (‘reply’, dict([(‘rid’, rid), (‘rdeck’, replies)])), ])

self.patron.value.requests.append(request)

transmit(self, method=None, path=None, qargs=None, fragment=None, headers=None, body=None, data=None, fargs=None, **kwa)

Rebuild and transmit request Assumes that .waited is not True. Do not use bare unless know that there is no current request/reponse in process otherwise it clobbers .requester attributes

If the parameters are all None then use existing .requester and .respondent attributes otherwise reinit .requester and .respondent if method is not None

Should only use with all None first time after that change one of the parameters.

redirect(self)

Perform redirect

serviceRequests(self)

Service requests deque

serviceResponse(self)

Service Rx on connection and parse

service(self)

Service request response

serviceWhileGen(self, tymeout=0.5)

Generator Method. ServiceAll while pending requests or not a response or not tymeout

Usage: response = yield from .serviceWhileGen(tymeout=0.5)

Runs one iteration of .service() on next and yields empty bytes while not done.

Assumes associated tymist is advanced and realtime sleep delay is incurred elsewhere.

Returns response as namedtuple or None if tymeout.

hio.core.http.openClient(cls=None, **kwa)[source]

Wrapper to create and open HTTP Client instances When used in with statement block, calls .close() on exit of with block

Parameters

instance (cls is Class instance of subclass) –

Usage:
with openClient() as client0:

client0.accept()

with openClient(cls=Client) as client0:

client0.accept()

class hio.core.http.ClientDoer(client, **kwa)[source]

Bases: hio.base.doing.Doer

HTTP Client Doer

See Doer for inherited attributes, properties, and methods.

.client is HTTP Client instance
wind(self, tymth)

Inject new tymist.tymth as new ._tymth. Changes tymist.tyme base. Updates winds .tymer .tymth

enter(self)
recur(self, tyme)
exit(self)
class hio.core.http.BareServer(servant=None, stewards=None, name='', bufsize=8096, wl=None, ha=None, host='', port=None, eha=None, scheme='', dictable=False, timeout=None, **kwa)[source]

BareServer class nonblocking Bare (non-WSGI) HTTP server Define CustomResponder subclass to respond to requests as per Steward

Timeout = 5.0
reopen(self)

Return result of .servant.reopen()

idle(self)

Returns True if no connections have requests in process Useful for debugging

close(self)

Close all ixes for all stewards

closeConnection(self, ca)

Close and remove connection and associated steward given by ca

serviceConnects(self)

Service new incoming connections Create requestants Timeout stale connections

serviceStewards(self)

Service pending requestants and responders

service(self)

Service request response

class hio.core.http.Server(name='hio.wsgi.server', app=None, reqs=None, reps=None, servant=None, bufsize=8096, wl=None, ha=None, host='', port=None, eha=None, scheme='', tymeout=None, **kwa)[source]

Server WSGI HTTP Server Class

Tymeout = 5.0
wind(self, tymth)

Inject new tymist.tymth as new ._tymth. Changes tymist.tyme base. Updates winds .tymer .tymth

reopen(self)

Return result of .servant.reopen()

close(self)

Close all reqs, reps, and ixes

idle(self)

Returns True if no connections have requests in process Useful for debugging

buildEnviron(self, requestant)

Returns wisgi environment dictionary for supplied requestant

closeConnection(self, ca)

Close and remove connection given by ca

serviceConnects(self)

Service new incoming connections Create requestants Timeout stale connections

serviceReqs(self)

Service pending requestants

serviceReps(self)

Service pending responders

service(self)

Service request response

hio.core.http.WsgiServer[source]
hio.core.http.openServer(cls=None, **kwa)[source]

Wrapper to create and open HTTP Server instances When used in with statement block, calls .close() on exit of with block

Parameters

instance (cls is Class instance of subclass) –

Usage:
with openServer() as server0:

server0.

with openServer(cls=BareServer) as server0:

server0.

class hio.core.http.ServerDoer(server, **kwa)[source]

Bases: hio.base.doing.Doer

HTTP WSGI Server Doer

See Doer for inherited attributes, properties, and methods.

.server is HTTP WSGI Server instance

Properties:

wind(self, tymth)

Inject new tymist.tymth as new ._tymth. Changes tymist.tyme base. Updates winds .tymer .tymth

enter(self)
recur(self, tyme)
exit(self)