hio.core.http.clienting
hio.core.http.clienting module
nonblocking http client
Module Contents
- class hio.core.http.clienting.Requester(hostname='127.0.0.1', port=None, scheme='http', method='GET', path='/', qargs=None, fragment='', headers=None, body=b'', data=None, fargs=None, portOptional=False)
Bases:
objectNonblocking HTTP Client Requester class
- reinit(hostname=None, port=None, scheme=None, method=None, path=None, qargs=None, fragment=None, headers=None, body=None, data=None, fargs=None, portOptional=None)
Reinitialize anything that is not None This enables creating another request on a connection to the same host port
- rebuild(method=None, path=None, qargs=None, fragment=None, headers=None, body=None, data=None, fargs=None, portOptional=None)
Reinit then build and return request message This allows sending another request to same destination
- build()
Build and return request message from attributes
- class hio.core.http.clienting.Respondent(redirects=None, redirectable=True, events=None, retry=None, leid=None, **kwa)
Bases:
hio.core.http.httping.ParsentNonblocking HTTP Client Respondent class
- reinit(redirectable=None, **kwa)
Reinitialize Instance See super class redirectable means allow redirection
- close()
Call super to assign True to .closed Also close event source
- checkPersisted()
Checks headers to determine if connection should be kept open until server closes it Sets the .persisted flag
- parseHead()
Generator to parse headers in heading of .msg Yields None if more to parse Yields True if done parsing
- parseBody()
Parse body
- hio.core.http.clienting.openClient(cls=None, **kwa)
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.clienting.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, portOptional=False, **kwa)
Client class nonblocking HTTP client connection manager and HTTP client request and response processor
- wind(tymth)
Inject new tymist.tymth as new ._tymth. Changes tymist.tyme base. Updates winds .tymer .tymth
- reopen()
Return result of .connector.reopen()
- close()
Call .connecter.close (shutclose)
- static attrify(response)
Convert response dict into named tuple Response so can access fields as attributes
- respond()
Pops and returns next response from .responses if any Otherwise returns None
- request(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
Example:
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(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()
Perform redirect
- serviceRequests()
Service requests deque
- serviceResponse()
Service Rx on connection and parse
- service()
Service request response
- serviceWhileGen(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.clienting.backendRequest(tymth, *, method='GET', scheme='', host='localhost', port=None, path='/', qargs=None, data=None, buffered=False, tymeout=2.0)
Perform Async ReST request to Backend Server
Parameters:
Usage: (Inside a generator function)
response = yield from backendRequest()
response is the response if valid else None before response is completed the yield from yields up an empty string ‘’ once completed then response has a value
path can be full url with host port etc path takes precedence over others
- class hio.core.http.clienting.ClientDoer(client, **kwa)
Bases:
hio.base.doing.DoerHTTP Client Doer
See Doer for inherited attributes, properties, and methods.
- .client is HTTP Client instance
- wind(tymth)
Inject new tymist.tymth as new ._tymth. Changes tymist.tyme base. Updates winds .tymer .tymth
- enter(*, temp=None)
Do ‘enter’ context actions. Set up resources. Comparable to context manager enter.
temp is bool or None. True means use temporary file resources if any. None means ignore parameter value and use self.temp.
Inject temp or self.temp into file resources here if any.
- recur(tyme)
Service the client once per cycle.
- exit()
Close client resources.