Ejemplo n.º 1
0
class Mapped(with_metaclass(ABCMeta)):
    @classmethod
    def of(cls, *args, **kwargs):
        return Mapped._of(cls, *args, **kwargs)

    @staticmethod
    def _of(cls, *args, **kwargs):
        final_args = cls.defaults()
        final_args.update(*args)
        final_args.update(
            {cls.mappings().get(k, k): v
             for k, v in kwargs.items()})
        try:
            return cls.factory(**final_args)
        except Exception as e:
            pass

    factory = None

    @staticmethod
    def mappings():
        return None

    @staticmethod
    def defaults():
        return None
Ejemplo n.º 2
0
class Forwarder(with_metaclass(ABCMeta)):
    def forward_args(
            self,
            arg_vars,  # type: Optional[Dict[str,Any]]
            *options  # type: OptionBlockDeriv
    ):
        # type: (...) -> OptionBlockDeriv[str,Any]
        arg_vars = copy.copy(arg_vars) if arg_vars else {}
        temp_options = copy.copy(
            options[0]) if (options and options[0]) else OptionBlock()
        kwargs = arg_vars.pop('kwargs', {})
        temp_options.update(kwargs)
        temp_options.update(arg_vars)

        end_options = {}
        for k, v in temp_options.items():
            map_item = self.arg_mapping().get(k, None)
            if not (map_item is None):
                for out_k, out_f in map_item.items():
                    converted = out_f(v)
                    if converted is not None:
                        end_options[out_k] = converted
            else:
                end_options[k] = v
        return end_options

    @abstractmethod
    def arg_mapping(self):
        pass
Ejemplo n.º 3
0
class AsyncBucket(with_metaclass(CoreAsyncBucketFactory, Bucket)):
    def __init__(self, *args, **kwargs):
        super(AsyncBucket, self).__init__(*args, **kwargs)

    def query(self, *args, **kwargs):
        """
        Reimplemented from base class.

        This method does not add additional functionality of the
        base class' :meth:`~couchbase_v2.bucket.Bucket.query` method (all the
        functionality is encapsulated in the view class anyway). However it
        does require one additional keyword argument

        :param class itercls: A class used for instantiating the view
          object. This should be a subclass of
          :class:`~couchbase_v2.asynchronous.view.AsyncViewBase`.
        """
        if not issubclass(kwargs.get('itercls', None), AsyncViewBase):
            raise ArgumentError.pyexc("itercls must be defined "
                                      "and must be derived from AsyncViewBase")

        return super(AsyncBucket, self).query(*args, **kwargs)

    def endure(self, key, *args, **kwargs):
        res = super(AsyncBucket, self).endure_multi([key], *args, **kwargs)
        res._set_single()
        return res
Ejemplo n.º 4
0
class SDK2AsyncMutationResult(with_metaclass(AsyncWrapper,
                                             SDK2MutationResult)):
    def __init__(
            self,
            sdk2_result  # type: SDK2Result
    ):
        # type (...)->None
        super(SDK2AsyncMutationResult, self).__init__(sdk2_result)
Ejemplo n.º 5
0
class SDK2AsyncResult(with_metaclass(AsyncWrapper, SDK2GetResult)):
    def __init__(
            self,
            sdk2_result,  # type: SDK2Result
            expiry=None,  # type: Seconds
            **kwargs):
        kwargs['expiry'] = expiry
        super(SDK2AsyncResult, self).__init__(sdk2_result, **kwargs)
Ejemplo n.º 6
0
class RoleAndDescription(with_metaclass(ABCMeta, Mapped)):
    """ Associates a role with its name and description.
    This is additional information only present in the "list available roles" response."""

    factory = RawRoleAndDescription

    @staticmethod
    def defaults():
        return {
            'ce': True,
            'bucket_name': None,
            'scope_name': None,
            'collection_name': None
        }

    @staticmethod
    def mappings():
        return {'desc': 'description', 'name': 'display_name'}

    @property
    @abstractmethod
    def role(self):
        # type: (...) -> Role
        return None

    @property
    @abstractmethod
    def ce(self):
        # type: (...) -> Role
        return None

    @property
    @abstractmethod
    def display_name(self):
        # type: (...) -> str
        return None

    @property
    @abstractmethod
    def description(self):
        # type: (...) -> str
        pass

    @classmethod
    def of(cls, *args, **kwargs):
        return Mapped._of(cls, *args, **kwargs)
Ejemplo n.º 7
0
class Role(with_metaclass(ABCMeta, Mapped)):
    """A role identifies a specific permission. CAVEAT,  # type: The properties of a role are likely to change with the introduction of collection-level permissions. Until then
    here's what the accessor methods look like:
    """
    factory = RawRole

    @staticmethod
    def defaults():
        return {'bucket': None}

    @staticmethod
    def mappings():
        return {'role': 'name'}

    @property
    @abstractmethod
    def name(self):
        pass

    @property
    @abstractmethod
    def bucket(self):
        pass

    def __iter__(self):
        return iter([self.name, self.bucket])

    def __str__(self):
        return Admin.role_to_str(self)

    @classmethod
    def decode(cls, param):
        if isinstance(param, str):
            param = Admin.str_to_role(param)
        if isinstance(param, dict):
            args = list(map(param.get, ('role', 'bucket')))
        else:
            args = param
        return cls.factory(*args)
Ejemplo n.º 8
0
class V3CoreBucket(with_metaclass(AsyncBucketFactory, CoreAsyncBucket)):
    def __init__(self, *args, **kwargs):
        super(V3CoreBucket, self).__init__(*args, **kwargs)
Ejemplo n.º 9
0
class Bucket(with_metaclass(AsyncBucketFactory, V2AsyncBucket)):
    def __init__(self, *args, **kwargs):
        super(Bucket, self).__init__(*args, **kwargs)
Ejemplo n.º 10
0
class AsyncClient(with_metaclass(AsyncClientFactory, CoreClient)):
    def __init__(self, *args, **kwargs):
        super(AsyncClient, self).__init__(*args, **kwargs)
Ejemplo n.º 11
0
class AsyncCBCollection(with_metaclass(AsyncBucketFactory, BaseAsyncCBCollection)):
    def __init__(self,
                 *args,
                 **kwargs
                 ):
        super(AsyncCBCollection, self).__init__(*args, **kwargs)