How to use the werkzeug.utils.cached_property function in Werkzeug

To help you get started, we’ve selected a few Werkzeug examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pallets / werkzeug / werkzeug / contrib / testtools.py View on Github external
fromstring = etree.HTML
        if self.mimetype == 'text/html':
            return fromstring(self.data)
        return etree.XML(self.data)
    lxml = cached_property(lxml)

    def json(self):
        """Get the result of simplejson.loads if possible."""
        if 'json' not in self.mimetype:
            raise AttributeError('Not a JSON response')
        try:
            from simplejson import loads
        except ImportError:
            from json import loads
        return loads(self.data)
    json = cached_property(json)


class TestResponse(Response, ContentAccessors):

    """Pass this to `werkzeug.test.Client` for easier unittesting."""
github tranquilit / WAPT / lib / site-packages / werkzeug / wrappers.py View on Github external
    @cached_property
    def access_route(self):
        """If a forwarded header exists this is a list of all ip addresses
        from the client ip to the last proxy server.
        """
        if 'HTTP_X_FORWARDED_FOR' in self.environ:
            addr = self.environ['HTTP_X_FORWARDED_FOR'].split(',')
            return self.list_storage_class([x.strip() for x in addr])
        elif 'REMOTE_ADDR' in self.environ:
            return self.list_storage_class([self.environ['REMOTE_ADDR']])
        return self.list_storage_class()
github projecteru / redis-trib.py / redistrib / clusternode.py View on Github external
    @cached_property
    def role_in_cluster(self):
        return 'master' if self.master else 'slave'
github biosustain / potion / flask_potion / fields.py View on Github external
    @cached_property
    def _property_attributes(self):
        if not self.properties:
            return ()
        return [field.attribute or key for key, field in self.properties.items()]
github biosustain / potion / flask_potion / schema.py View on Github external
    @cached_property
    def request(self):
        schema = self.schema()
        if isinstance(schema, tuple):
            return schema[1]
        return schema
github ulope / pyformat.info / vendor / lektor / lektor / environment.py View on Github external
    @cached_property
    def base_path(self):
        """The base path of the URL."""
        url = self.values['PROJECT'].get('url')
        if url:
            return url_parse(url).path.rstrip('/') + '/'
        return '/'
github mushkevych / scheduler / synergy / mx / tree_details.py View on Github external
    @cached_property
    def tree_details(self):
        tree_name = self.request_arguments.get('tree_name')
        if tree_name:
            return self._get_tree_details(tree_name).document
        else:
            return dict()
github jam-py / jam-py / jam / third_party / werkzeug / wrappers.py View on Github external
    @cached_property
    def data(self):
        """
        Contains the incoming request data as string in case it came with
        a mimetype Werkzeug does not handle.
        """

        if self.disable_data_descriptor:
            raise AttributeError('data descriptor is disabled')
        # XXX: this should eventually be deprecated.

        # We trigger form data parsing first which means that the descriptor
        # will not cache the data that would otherwise be .form or .files
        # data.  This restores the behavior that was there in Werkzeug
        # before 0.9.  New code should use :meth:`get_data` explicitly as
        # this will make behavior explicit.
        return self.get_data(parse_form_data=True)
github wwqgtxx / wwqLyParse / wwqLyParse / lib / flask_lib / werkzeug / wrappers.py View on Github external
    @cached_property
    def if_unmodified_since(self):
        """The parsed `If-Unmodified-Since` header as datetime object."""
        return parse_date(self.environ.get('HTTP_IF_UNMODIFIED_SINCE'))
github Flask-FlatPages / Flask-FlatPages / flask_flatpages / page.py View on Github external
    @cached_property
    def meta(self):
        """
        Store a dict of metadata parsed as YAML
        from the header of the file.
        """
        meta = yaml.safe_load(self._meta)
        # YAML documents can be any type but we want a dict
        # eg. yaml.safe_load('') -> None
        #     yaml.safe_load('- 1\n- a') -> [1, 'a']
        if not meta:
            return {}
        if not isinstance(meta, dict):
            raise ValueError("Expected a dict in metadata for '{0}', got {1}".
                             format(self.path, type(meta).__name__))
        return meta