Beispiel #1
0
def create_api_dict(bases, url, **kwargs):
    """Create an API dict

    :param bases: configuration bases
    :type bases: :class:`~pyextdirect.configuration.Base` or list of :class:`~pyextdirect.configuration.Base`
    :param string url: URL where the router can be reached
    :param \*\*kwargs: extra keyword arguments to populate the API dict. Most common keyword arguments are *id*, *maxRetries*, *namespace*, *priority* and *timeout*

    .. note::
        Keyword arguments *type*, *url*, *actions* and *enableUrlEncode* will be overridden

    """
    api = kwargs or {}
    api.update({
        'type': 'remoting',
        'url': url,
        'actions': defaultdict(list),
        'enableUrlEncode': 'data'
    })
    if not isinstance(bases, list):
        bases = [bases]
    configuration = merge_configurations([b.configuration for b in bases])
    for action, methods in configuration.iteritems():
        for method, element in methods.iteritems():
            if isinstance(element, tuple):
                func = getattr(element[0], element[1])
                attrs = len(inspect.getargspec(func)[0]) - 1
            else:
                func = element
                attrs = len(inspect.getargspec(func)[0])
            spec = {'name': method, 'len': attrs}
            if func.exposed_kind == SUBMIT:
                spec['formHandler'] = True
            api['actions'][action].append(spec)
    return api
Beispiel #2
0
def create_api_dict(bases, url, **kwargs):
    """Create an API dict

    :param bases: configuration bases
    :type bases: :class:`~pyextdirect.configuration.Base` or list of :class:`~pyextdirect.configuration.Base`
    :param string url: URL where the router can be reached
    :param \*\*kwargs: extra keyword arguments to populate the API dict. Most common keyword arguments are *id*, *maxRetries*, *namespace*, *priority* and *timeout*

    .. note::
        Keyword arguments *type*, *url*, *actions* and *enableUrlEncode* will be overridden

    """
    api = kwargs or {}
    api.update({'type': 'remoting', 'url': url, 'actions': defaultdict(list), 'enableUrlEncode': 'data'})
    if not isinstance(bases, list):
        bases = [bases]
    configuration = merge_configurations([b.configuration for b in bases])
    for action, methods in configuration.iteritems():
        for method, element in methods.iteritems():
            if isinstance(element, tuple):
                func = getattr(element[0], element[1])
                attrs = len(inspect.getargspec(func)[0]) - 1
            else:
                func = element
                attrs = len(inspect.getargspec(func)[0])
            spec = {'name': method, 'len': attrs}
            if func.exposed_kind == SUBMIT:
                spec['formHandler'] = True
            api['actions'][action].append(spec)
    return api
Beispiel #3
0
 def __init__(self, bases):
     if not isinstance(bases, list):
         bases = [bases]
     self.configuration = merge_configurations([b.configuration for b in bases])
     self.instances = create_instances(self.configuration)
     self.debug = False