Пример #1
0
        def __init__(self,
                     foreign_keys,
                     reference_fields,
                     on_delete='CASCADE',
                     on_update='CASCADE'):

            on = [
                'NO ACTION', 'RESTRICT', 'SET NULL', 'SET DEFAULT', 'CASCADE'
            ]
            on_delete = on_delete.upper()
            on_update = on_update.upper()

            if on_delete not in on:
                raise ValueError("Invalid on delete option" +
                                 " table '%s'" % self._table)

            if on_update not in on:
                raise ValueError("Invalid on delete option" +
                                 " table '%s'" % self._table)

            self._foreign_keys = to_tuple(foreign_keys)
            self._reference_fields = to_tuple(reference_fields)
            self._on_delete = on_delete.upper()
            self._on_update = on_update.upper()
            super().__init__()
            self.internal = True
Пример #2
0
    def __init__(self, model=list, hide=None):
        if model != list and model != dict:
            raise ValueError("Invalid model type '%s'" % model)

        self._current = model()
        self._new = model()
        self._updated = False
        self._created = True
        self._hide = to_tuple(hide)

        if isinstance(self._current, dict):
            # NOTE(cfrademan): Set default values for model object.
            for field in self.fields:
                default = self.fields[field].default
                if default is not None:
                    default = parse_defaults(default)
                    default = self.fields[field]._parse(default)
                    if (field not in self._transaction
                            or self._transaction[field] is None):
                        self._current[field] = default
                elif field in (
                        'domain_id',
                        'tenant_id',
                ):
                    self._new[field] = getattr(g.current_request, field)
                elif not isinstance(self.fields[field], Model.filter_fields):
                    self._current[field] = None
Пример #3
0
    def __init__(self, hosts='127.0.0.1', port=5672,
                 virtualhost='/', username=None, password=None,
                 channel_callback=None, block_callback=None,
                 unblock_callback=None, heartbeat=15):

        amq_params = {'port': port,
                      'virtual_host': virtualhost,
                      'heartbeat': heartbeat,
                      'blocked_connection_timeout': 1}

        self._ch_callback = channel_callback
        self._unblock_callback = unblock_callback
        self._block_callback = block_callback
        self._sync_lock = RLock()
        self._event_count = 0
        self._event_lock = RLock()
        self._ioloop_lock = Lock()
        self._connect_lock = Lock()
        self._blocked = False

        if username:
            amq_params = {**amq_params,
                          'credentials': pika.PlainCredentials(username,
                                                               password)}
        self._conn_params = []
        for host in to_tuple(hosts):
            self._conn_params.append(pika.ConnectionParameters(host=host,
                                                               **amq_params))

        self.connect()
Пример #4
0
    def __init__(self, hide=None):
        self._current = {}
        self._new = {}
        self._updated = False
        self._created = True
        # Used by SQL Commit
        self._deleted = False
        self._hide = to_tuple(hide)

        # NOTE(cfrademan): Set default values for model object.
        for field in self.fields:
            default = self.fields[field].default
            if default is not None:
                default = parse_defaults(default)
                default = self.fields[field]._parse(default)
                if (field not in self._transaction
                        or self._transaction[field] is None):
                    self._current[field] = default
            elif not isinstance(self.fields[field], self.filter_fields):
                self._current[field] = None
Пример #5
0
    def get_list(self, field, required=False):
        """Get list of values for the requested field name in form.

        Returns an empty list if the file doesn’t exist. It’s guaranteed to
        return a list unless the field is required as per keyword args.

        Args:
            field (str): Form field name.

        Keyword Args:
            required (bool): Set to 'True' to raise
                'HTTPMissingParam' instead of returning
                gracefully when field is not found
                (default 'False').

        Returns:
            tuple: List of values.

        Raises:
            HTTPMissinParam: The parameter was not found in the request, but
                it was required.

            HTTPUnsupportedMediaType: Expected payload.
        """
        form = self.form

        if required is True and field not in form:
            raise errors.HTTPMissingFormField(field)

        try:
            return to_tuple(form.getlist(field))
        except TypeError:
            pass

        if required is True:
            raise errors.HTTPMissingFormField(field)

        return ()
Пример #6
0
    def add(self, methods, route, resource, tag=None, cache=0):
        """Add route to view.

        The route() method is used to associate a URI template with
        a resource. Luxon then maps incoming requests to resources
        based on these templates.

        URI Template example: "/music/rock"

        If the route’s template contains field expressions, any responder that
        desires to receive requests for that route must accept arguments named
        after the respective field names defined in the template.

        A field expression consists of a bracketed field name.
        For example, given the following template: "/music/{genre}"

        The view would look like:
            def genre(self, req, resp, genre):

        Args:
            methods (list): List of Methods. Use constants in
                For example in HTTP...
                luxon.constants. can be used ie HTTP_GET
                * HTTP_GET
                * HTTP_POST
                * HTTP_PUT
                * HTTP_PATCH
                * HTTP_DELETE
            route (str): Route resource. (URI Template)
            resource (object): Actual view function or method.

        Keyword Args:
            tag (str): Used to identify rule_set to apply. default: 'None'
        """
        methods = to_tuple(methods)
        if route[0:6].lower() == "regex:":
            route = route[6:]
            for method in methods:
                method = method.upper()
                try:
                    route = re.compile(route)
                    self._regex_routes[method].append((
                        resource,
                        method,
                        {},
                        route,
                        tag,
                        cache,
                    ))
                    self._routes['%s:%s' %
                                 (method, route)] = (resource, method, {},
                                                     route, tag, cache)
                except KeyError:
                    self._regex_routes[method] = []
                    route = re.compile(route)
                    self._routes['%s:%s' %
                                 (method, route)] = (resource, method, {},
                                                     route, tag, cache)
                    self._regex_routes[method].append(
                        self._routes['%s:%s' % (method, route)])
                except Exception as e:
                    raise exceptions.Error("Bad RE expression for route '%s'" %
                                           route + ". (%s)" % e)
        else:
            route = route.strip('/')
            for method in methods:
                method = method.upper()
                try:
                    if not isinstance(route, retype) and '{' in route:
                        self._routers[method].add_route(
                            route, method, resource, tag, cache)

                    self._routes['%s:%s' %
                                 (method, route)] = (resource, method, {},
                                                     route, tag, cache)
                except KeyError:
                    if not isinstance(route, retype) and '{' in route:
                        self._routers[method] = CompiledRouter()
                        self._routers[method].add_route(
                            route, method, resource, tag, cache)

                    self._routes['%s:%s' %
                                 (method, route)] = (resource, method, {},
                                                     route, tag, cache)
        self._methods.add(method)
        log.info('Added Route: %s' % route + ' Methods: %s' % str(methods) +
                 ' Resource: %s' % object_name(resource) + ' Tag: %s' % tag +
                 ' Cache: %s' % cache)