Skip to content

Commit

Permalink
python-based proxy deserialization
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasheinrich committed Oct 18, 2017
1 parent cb99b61 commit b646e66
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
26 changes: 19 additions & 7 deletions packtivity/backendutils.py
Expand Up @@ -9,8 +9,27 @@


def load_proxy(jsondata, deserialization_opts = None, best_effort_backend = True, raise_on_unknown = False):
log.debug('load_proxy opts %s', deserialization_opts)
deserialization_opts = deserialization_opts or {}
proxy, backend = None, None

if 'proxy' in deserialization_opts:
proxystring = deserialization_opts.pop('proxy')
if proxystring.startswith('py:'):
_, module, proxyclass = proxystring.split(':')
module = importlib.import_module(module)
proxyclass = getattr(module,proxyclass)
proxyopts = {}
return proxyclass.fromJSON(jsondata,**proxyopts)

if 'PACKTIVITY_ASYNCBACKEND' in os.environ:
module, _, proxyclass = os.environ['PACKTIVITY_ASYNCBACKEND'].split(':')
module = importlib.import_module(module)
proxyclass = getattr(module,proxyclass)
proxy = proxyclass.fromJSON(jsondata)
if best_effort_backend:
_, backend = backend_from_string('fromenv')

if jsondata['proxyname'] == 'CeleryProxy':
from .asyncbackends import CeleryProxy
proxy = CeleryProxy.fromJSON(jsondata)
Expand All @@ -28,13 +47,6 @@ def load_proxy(jsondata, deserialization_opts = None, best_effort_backend = True
if best_effort_backend:
_, backend = backend_from_string('foregroundasync')

if 'PACKTIVITY_ASYNCBACKEND' in os.environ:
module, _, proxyclass = os.environ['PACKTIVITY_ASYNCBACKEND'].split(':')
module = importlib.import_module(module)
proxyclass = getattr(module,proxyclass)
proxy = proxyclass.fromJSON(jsondata)
if best_effort_backend:
_, backend = backend_from_string('fromenv')
if not proxy and raise_on_unknown:
raise RuntimeError('unknown proxy type: %s', jsondata['proxyname'])
if best_effort_backend:
Expand Down
4 changes: 4 additions & 0 deletions packtivity/statecontexts/__init__.py
@@ -1,7 +1,10 @@
import os
import importlib
import logging
from .posixfs_context import LocalFSState,LocalFSProvider

log = logging.getLogger(__name__)

def load_state(jsondata):
if jsondata['state_type'] == 'localfs':
return LocalFSState.fromJSON(jsondata)
Expand All @@ -11,6 +14,7 @@ def load_state(jsondata):
raise TypeError('unknown state type {}'.format(jsondata['state_type']))

def load_provider(jsondata,deserialization_opts = None):
log.debug('load_provider opts %s', deserialization_opts)
deserialization_opts = deserialization_opts or {}
if jsondata == None:
return None
Expand Down

0 comments on commit b646e66

Please sign in to comment.