prompy.networkio package¶
prompy.networkio.call_factory module¶
call_factory
Meta web api wrapper.
Usage:
from prompy.networkio.call_factory import CallRoute, Caller
from prompy.threadio.promise_queue import PromiseQueuePool
class Api(Caller):
def call_home(self, **kwargs):
return CallRoute('/')
def call_data(self, **kwargs):
return CallRoute('/data', method='POST')
pool = PromiseQueuePool(start=True)
api = Api(base_url='http://localhost:5000', promise_container=pool)
api.call_data(data={'num': 6}).then(print).catch(print)
-
class
prompy.networkio.call_factory.
CallRoute
(route, method='GET', content_type='application/json')[source]¶ Bases:
object
Route object used by
Caller
-
__init__
(route, method='GET', content_type='application/json')[source]¶ Route data object with format methods.
Parameters:
-
-
class
prompy.networkio.call_factory.
Caller
(base_url='', promise_container=None, prom_type=prompy.promise.Promise, prom_args=None)[source]¶ Bases:
object
Wraps all method starting with call_ with a call.
route methods must:
- return a CallRoute object.
- kwargs must be there if you want Caller.call and route params kwargs.
-
__init__
(base_url='', promise_container=None, prom_type=prompy.promise.Promise, prom_args=None)[source]¶ Parameters: - base_url (
str
) – - promise_container (
Optional
[BasePromiseContainer
]) – - prom_type –
- prom_args (
Optional
[dict
]) –
- base_url (
-
after_call
(route, route_params, params, result, error)[source]¶ global after call callback
Parameters: Returns:
prompy.networkio.urlcall module¶
-
prompy.networkio.urlcall.
get
(url, params=None, prom_type=prompy.promise.Promise, **kwargs)[source]¶ Return type: Promise
[]
-
prompy.networkio.urlcall.
json_call
(url, payload=None, encoding='UTF-8', prom_type=prompy.promise.Promise, headers=None, **kwargs)[source]¶ Auto encode payload and decode response in json.
Return type: Promise
[]
-
prompy.networkio.urlcall.
post
(url, data=None, prom_type=prompy.promise.Promise, **kwargs)[source]¶ Return type: Promise
[]
-
prompy.networkio.urlcall.
put
(url, data, prom_type=prompy.promise.Promise, **kwargs)[source]¶ Return type: Promise
[]
-
prompy.networkio.urlcall.
url_call
(url, data=None, headers=None, origin_req_host=None, unverifiable=False, method=None, content_mapper=<function default_content_mapper>, prom_type=prompy.promise.Promise, **kwargs)[source]¶ Base http call using urllib.
Parameters: Return type: Promise
[]Returns: A promise to resolve with a response.