repo
stringlengths
7
55
path
stringlengths
4
223
func_name
stringlengths
1
134
original_string
stringlengths
75
104k
language
stringclasses
1 value
code
stringlengths
75
104k
code_tokens
listlengths
19
28.4k
docstring
stringlengths
1
46.9k
docstring_tokens
listlengths
1
1.97k
sha
stringlengths
40
40
url
stringlengths
87
315
partition
stringclasses
1 value
pallets/werkzeug
src/werkzeug/http.py
parse_if_range_header
def parse_if_range_header(value): """Parses an if-range header which can be an etag or a date. Returns a :class:`~werkzeug.datastructures.IfRange` object. .. versionadded:: 0.7 """ if not value: return IfRange() date = parse_date(value) if date is not None: return IfRange(d...
python
def parse_if_range_header(value): """Parses an if-range header which can be an etag or a date. Returns a :class:`~werkzeug.datastructures.IfRange` object. .. versionadded:: 0.7 """ if not value: return IfRange() date = parse_date(value) if date is not None: return IfRange(d...
[ "def", "parse_if_range_header", "(", "value", ")", ":", "if", "not", "value", ":", "return", "IfRange", "(", ")", "date", "=", "parse_date", "(", "value", ")", "if", "date", "is", "not", "None", ":", "return", "IfRange", "(", "date", "=", "date", ")", ...
Parses an if-range header which can be an etag or a date. Returns a :class:`~werkzeug.datastructures.IfRange` object. .. versionadded:: 0.7
[ "Parses", "an", "if", "-", "range", "header", "which", "can", "be", "an", "etag", "or", "a", "date", ".", "Returns", "a", ":", "class", ":", "~werkzeug", ".", "datastructures", ".", "IfRange", "object", "." ]
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/http.py#L597-L609
train
pallets/werkzeug
src/werkzeug/http.py
parse_date
def parse_date(value): """Parse one of the following date formats into a datetime object: .. sourcecode:: text Sun, 06 Nov 1994 08:49:37 GMT ; RFC 822, updated by RFC 1123 Sunday, 06-Nov-94 08:49:37 GMT ; RFC 850, obsoleted by RFC 1036 Sun Nov 6 08:49:37 1994 ; ANSI C's asctime...
python
def parse_date(value): """Parse one of the following date formats into a datetime object: .. sourcecode:: text Sun, 06 Nov 1994 08:49:37 GMT ; RFC 822, updated by RFC 1123 Sunday, 06-Nov-94 08:49:37 GMT ; RFC 850, obsoleted by RFC 1036 Sun Nov 6 08:49:37 1994 ; ANSI C's asctime...
[ "def", "parse_date", "(", "value", ")", ":", "if", "value", ":", "t", "=", "parsedate_tz", "(", "value", ".", "strip", "(", ")", ")", "if", "t", "is", "not", "None", ":", "try", ":", "year", "=", "t", "[", "0", "]", "# unfortunately that function doe...
Parse one of the following date formats into a datetime object: .. sourcecode:: text Sun, 06 Nov 1994 08:49:37 GMT ; RFC 822, updated by RFC 1123 Sunday, 06-Nov-94 08:49:37 GMT ; RFC 850, obsoleted by RFC 1036 Sun Nov 6 08:49:37 1994 ; ANSI C's asctime() format If parsing fail...
[ "Parse", "one", "of", "the", "following", "date", "formats", "into", "a", "datetime", "object", ":" ]
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/http.py#L780-L809
train
pallets/werkzeug
src/werkzeug/http.py
_dump_date
def _dump_date(d, delim): """Used for `http_date` and `cookie_date`.""" if d is None: d = gmtime() elif isinstance(d, datetime): d = d.utctimetuple() elif isinstance(d, (integer_types, float)): d = gmtime(d) return "%s, %02d%s%s%s%s %02d:%02d:%02d GMT" % ( ("Mon", "Tu...
python
def _dump_date(d, delim): """Used for `http_date` and `cookie_date`.""" if d is None: d = gmtime() elif isinstance(d, datetime): d = d.utctimetuple() elif isinstance(d, (integer_types, float)): d = gmtime(d) return "%s, %02d%s%s%s%s %02d:%02d:%02d GMT" % ( ("Mon", "Tu...
[ "def", "_dump_date", "(", "d", ",", "delim", ")", ":", "if", "d", "is", "None", ":", "d", "=", "gmtime", "(", ")", "elif", "isinstance", "(", "d", ",", "datetime", ")", ":", "d", "=", "d", ".", "utctimetuple", "(", ")", "elif", "isinstance", "(",...
Used for `http_date` and `cookie_date`.
[ "Used", "for", "http_date", "and", "cookie_date", "." ]
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/http.py#L812-L843
train
pallets/werkzeug
src/werkzeug/http.py
parse_age
def parse_age(value=None): """Parses a base-10 integer count of seconds into a timedelta. If parsing fails, the return value is `None`. :param value: a string consisting of an integer represented in base-10 :return: a :class:`datetime.timedelta` object or `None`. """ if not value: retu...
python
def parse_age(value=None): """Parses a base-10 integer count of seconds into a timedelta. If parsing fails, the return value is `None`. :param value: a string consisting of an integer represented in base-10 :return: a :class:`datetime.timedelta` object or `None`. """ if not value: retu...
[ "def", "parse_age", "(", "value", "=", "None", ")", ":", "if", "not", "value", ":", "return", "None", "try", ":", "seconds", "=", "int", "(", "value", ")", "except", "ValueError", ":", "return", "None", "if", "seconds", "<", "0", ":", "return", "None...
Parses a base-10 integer count of seconds into a timedelta. If parsing fails, the return value is `None`. :param value: a string consisting of an integer represented in base-10 :return: a :class:`datetime.timedelta` object or `None`.
[ "Parses", "a", "base", "-", "10", "integer", "count", "of", "seconds", "into", "a", "timedelta", "." ]
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/http.py#L875-L894
train
pallets/werkzeug
src/werkzeug/http.py
dump_age
def dump_age(age=None): """Formats the duration as a base-10 integer. :param age: should be an integer number of seconds, a :class:`datetime.timedelta` object, or, if the age is unknown, `None` (default). """ if age is None: return if isinstance(age, timedelt...
python
def dump_age(age=None): """Formats the duration as a base-10 integer. :param age: should be an integer number of seconds, a :class:`datetime.timedelta` object, or, if the age is unknown, `None` (default). """ if age is None: return if isinstance(age, timedelt...
[ "def", "dump_age", "(", "age", "=", "None", ")", ":", "if", "age", "is", "None", ":", "return", "if", "isinstance", "(", "age", ",", "timedelta", ")", ":", "# do the equivalent of Python 2.7's timedelta.total_seconds(),", "# but disregarding fractional seconds", "age"...
Formats the duration as a base-10 integer. :param age: should be an integer number of seconds, a :class:`datetime.timedelta` object, or, if the age is unknown, `None` (default).
[ "Formats", "the", "duration", "as", "a", "base", "-", "10", "integer", "." ]
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/http.py#L897-L915
train
pallets/werkzeug
src/werkzeug/http.py
is_resource_modified
def is_resource_modified( environ, etag=None, data=None, last_modified=None, ignore_if_range=True ): """Convenience method for conditional requests. :param environ: the WSGI environment of the request to be checked. :param etag: the etag for the response for comparison. :param data: or alternativel...
python
def is_resource_modified( environ, etag=None, data=None, last_modified=None, ignore_if_range=True ): """Convenience method for conditional requests. :param environ: the WSGI environment of the request to be checked. :param etag: the etag for the response for comparison. :param data: or alternativel...
[ "def", "is_resource_modified", "(", "environ", ",", "etag", "=", "None", ",", "data", "=", "None", ",", "last_modified", "=", "None", ",", "ignore_if_range", "=", "True", ")", ":", "if", "etag", "is", "None", "and", "data", "is", "not", "None", ":", "e...
Convenience method for conditional requests. :param environ: the WSGI environment of the request to be checked. :param etag: the etag for the response for comparison. :param data: or alternatively the data of the response to automatically generate an etag using :func:`generate_etag`. :...
[ "Convenience", "method", "for", "conditional", "requests", "." ]
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/http.py#L918-L982
train
pallets/werkzeug
src/werkzeug/http.py
remove_entity_headers
def remove_entity_headers(headers, allowed=("expires", "content-location")): """Remove all entity headers from a list or :class:`Headers` object. This operation works in-place. `Expires` and `Content-Location` headers are by default not removed. The reason for this is :rfc:`2616` section 10.3.5 which...
python
def remove_entity_headers(headers, allowed=("expires", "content-location")): """Remove all entity headers from a list or :class:`Headers` object. This operation works in-place. `Expires` and `Content-Location` headers are by default not removed. The reason for this is :rfc:`2616` section 10.3.5 which...
[ "def", "remove_entity_headers", "(", "headers", ",", "allowed", "=", "(", "\"expires\"", ",", "\"content-location\"", ")", ")", ":", "allowed", "=", "set", "(", "x", ".", "lower", "(", ")", "for", "x", "in", "allowed", ")", "headers", "[", ":", "]", "=...
Remove all entity headers from a list or :class:`Headers` object. This operation works in-place. `Expires` and `Content-Location` headers are by default not removed. The reason for this is :rfc:`2616` section 10.3.5 which specifies some entity headers that should be sent. .. versionchanged:: 0.5 ...
[ "Remove", "all", "entity", "headers", "from", "a", "list", "or", ":", "class", ":", "Headers", "object", ".", "This", "operation", "works", "in", "-", "place", ".", "Expires", "and", "Content", "-", "Location", "headers", "are", "by", "default", "not", "...
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/http.py#L985-L1003
train
pallets/werkzeug
src/werkzeug/http.py
remove_hop_by_hop_headers
def remove_hop_by_hop_headers(headers): """Remove all HTTP/1.1 "Hop-by-Hop" headers from a list or :class:`Headers` object. This operation works in-place. .. versionadded:: 0.5 :param headers: a list or :class:`Headers` object. """ headers[:] = [ (key, value) for key, value in headers...
python
def remove_hop_by_hop_headers(headers): """Remove all HTTP/1.1 "Hop-by-Hop" headers from a list or :class:`Headers` object. This operation works in-place. .. versionadded:: 0.5 :param headers: a list or :class:`Headers` object. """ headers[:] = [ (key, value) for key, value in headers...
[ "def", "remove_hop_by_hop_headers", "(", "headers", ")", ":", "headers", "[", ":", "]", "=", "[", "(", "key", ",", "value", ")", "for", "key", ",", "value", "in", "headers", "if", "not", "is_hop_by_hop_header", "(", "key", ")", "]" ]
Remove all HTTP/1.1 "Hop-by-Hop" headers from a list or :class:`Headers` object. This operation works in-place. .. versionadded:: 0.5 :param headers: a list or :class:`Headers` object.
[ "Remove", "all", "HTTP", "/", "1", ".", "1", "Hop", "-", "by", "-", "Hop", "headers", "from", "a", "list", "or", ":", "class", ":", "Headers", "object", ".", "This", "operation", "works", "in", "-", "place", "." ]
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/http.py#L1006-L1016
train
pallets/werkzeug
src/werkzeug/http.py
parse_cookie
def parse_cookie(header, charset="utf-8", errors="replace", cls=None): """Parse a cookie. Either from a string or WSGI environ. Per default encoding errors are ignored. If you want a different behavior you can set `errors` to ``'replace'`` or ``'strict'``. In strict mode a :exc:`HTTPUnicodeError` is...
python
def parse_cookie(header, charset="utf-8", errors="replace", cls=None): """Parse a cookie. Either from a string or WSGI environ. Per default encoding errors are ignored. If you want a different behavior you can set `errors` to ``'replace'`` or ``'strict'``. In strict mode a :exc:`HTTPUnicodeError` is...
[ "def", "parse_cookie", "(", "header", ",", "charset", "=", "\"utf-8\"", ",", "errors", "=", "\"replace\"", ",", "cls", "=", "None", ")", ":", "if", "isinstance", "(", "header", ",", "dict", ")", ":", "header", "=", "header", ".", "get", "(", "\"HTTP_CO...
Parse a cookie. Either from a string or WSGI environ. Per default encoding errors are ignored. If you want a different behavior you can set `errors` to ``'replace'`` or ``'strict'``. In strict mode a :exc:`HTTPUnicodeError` is raised. .. versionchanged:: 0.5 This function now returns a :clas...
[ "Parse", "a", "cookie", ".", "Either", "from", "a", "string", "or", "WSGI", "environ", "." ]
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/http.py#L1041-L1083
train
pallets/werkzeug
src/werkzeug/http.py
dump_cookie
def dump_cookie( key, value="", max_age=None, expires=None, path="/", domain=None, secure=False, httponly=False, charset="utf-8", sync_expires=True, max_size=4093, samesite=None, ): """Creates a new Set-Cookie header without the ``Set-Cookie`` prefix The parameter...
python
def dump_cookie( key, value="", max_age=None, expires=None, path="/", domain=None, secure=False, httponly=False, charset="utf-8", sync_expires=True, max_size=4093, samesite=None, ): """Creates a new Set-Cookie header without the ``Set-Cookie`` prefix The parameter...
[ "def", "dump_cookie", "(", "key", ",", "value", "=", "\"\"", ",", "max_age", "=", "None", ",", "expires", "=", "None", ",", "path", "=", "\"/\"", ",", "domain", "=", "None", ",", "secure", "=", "False", ",", "httponly", "=", "False", ",", "charset", ...
Creates a new Set-Cookie header without the ``Set-Cookie`` prefix The parameters are the same as in the cookie Morsel object in the Python standard library but it accepts unicode data, too. On Python 3 the return value of this function will be a unicode string, on Python 2 it will be a native string. ...
[ "Creates", "a", "new", "Set", "-", "Cookie", "header", "without", "the", "Set", "-", "Cookie", "prefix", "The", "parameters", "are", "the", "same", "as", "in", "the", "cookie", "Morsel", "object", "in", "the", "Python", "standard", "library", "but", "it", ...
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/http.py#L1086-L1219
train
pallets/werkzeug
src/werkzeug/http.py
is_byte_range_valid
def is_byte_range_valid(start, stop, length): """Checks if a given byte content range is valid for the given length. .. versionadded:: 0.7 """ if (start is None) != (stop is None): return False elif start is None: return length is None or length >= 0 elif length is None: ...
python
def is_byte_range_valid(start, stop, length): """Checks if a given byte content range is valid for the given length. .. versionadded:: 0.7 """ if (start is None) != (stop is None): return False elif start is None: return length is None or length >= 0 elif length is None: ...
[ "def", "is_byte_range_valid", "(", "start", ",", "stop", ",", "length", ")", ":", "if", "(", "start", "is", "None", ")", "!=", "(", "stop", "is", "None", ")", ":", "return", "False", "elif", "start", "is", "None", ":", "return", "length", "is", "None...
Checks if a given byte content range is valid for the given length. .. versionadded:: 0.7
[ "Checks", "if", "a", "given", "byte", "content", "range", "is", "valid", "for", "the", "given", "length", "." ]
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/http.py#L1222-L1235
train
pallets/werkzeug
examples/plnt/utils.py
expose
def expose(url_rule, endpoint=None, **kwargs): """Expose this function to the web layer.""" def decorate(f): e = endpoint or f.__name__ endpoints[e] = f url_map.add(Rule(url_rule, endpoint=e, **kwargs)) return f return decorate
python
def expose(url_rule, endpoint=None, **kwargs): """Expose this function to the web layer.""" def decorate(f): e = endpoint or f.__name__ endpoints[e] = f url_map.add(Rule(url_rule, endpoint=e, **kwargs)) return f return decorate
[ "def", "expose", "(", "url_rule", ",", "endpoint", "=", "None", ",", "*", "*", "kwargs", ")", ":", "def", "decorate", "(", "f", ")", ":", "e", "=", "endpoint", "or", "f", ".", "__name__", "endpoints", "[", "e", "]", "=", "f", "url_map", ".", "add...
Expose this function to the web layer.
[ "Expose", "this", "function", "to", "the", "web", "layer", "." ]
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/examples/plnt/utils.py#L64-L73
train
pallets/werkzeug
examples/plnt/utils.py
render_template
def render_template(template_name, **context): """Render a template into a response.""" tmpl = jinja_env.get_template(template_name) context["url_for"] = url_for return Response(tmpl.render(context), mimetype="text/html")
python
def render_template(template_name, **context): """Render a template into a response.""" tmpl = jinja_env.get_template(template_name) context["url_for"] = url_for return Response(tmpl.render(context), mimetype="text/html")
[ "def", "render_template", "(", "template_name", ",", "*", "*", "context", ")", ":", "tmpl", "=", "jinja_env", ".", "get_template", "(", "template_name", ")", "context", "[", "\"url_for\"", "]", "=", "url_for", "return", "Response", "(", "tmpl", ".", "render"...
Render a template into a response.
[ "Render", "a", "template", "into", "a", "response", "." ]
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/examples/plnt/utils.py#L76-L80
train
pallets/werkzeug
examples/plnt/utils.py
nl2p
def nl2p(s): """Add paragraphs to a text.""" return u"\n".join(u"<p>%s</p>" % p for p in _par_re.split(s))
python
def nl2p(s): """Add paragraphs to a text.""" return u"\n".join(u"<p>%s</p>" % p for p in _par_re.split(s))
[ "def", "nl2p", "(", "s", ")", ":", "return", "u\"\\n\"", ".", "join", "(", "u\"<p>%s</p>\"", "%", "p", "for", "p", "in", "_par_re", ".", "split", "(", "s", ")", ")" ]
Add paragraphs to a text.
[ "Add", "paragraphs", "to", "a", "text", "." ]
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/examples/plnt/utils.py#L83-L85
train
pallets/werkzeug
examples/plnt/utils.py
strip_tags
def strip_tags(s): """Resolve HTML entities and remove tags from a string.""" def handle_match(m): name = m.group(1) if name in html_entities: return unichr(html_entities[name]) if name[:2] in ("#x", "#X"): try: return unichr(int(name[2:], 16)) ...
python
def strip_tags(s): """Resolve HTML entities and remove tags from a string.""" def handle_match(m): name = m.group(1) if name in html_entities: return unichr(html_entities[name]) if name[:2] in ("#x", "#X"): try: return unichr(int(name[2:], 16)) ...
[ "def", "strip_tags", "(", "s", ")", ":", "def", "handle_match", "(", "m", ")", ":", "name", "=", "m", ".", "group", "(", "1", ")", "if", "name", "in", "html_entities", ":", "return", "unichr", "(", "html_entities", "[", "name", "]", ")", "if", "nam...
Resolve HTML entities and remove tags from a string.
[ "Resolve", "HTML", "entities", "and", "remove", "tags", "from", "a", "string", "." ]
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/examples/plnt/utils.py#L93-L112
train
pallets/werkzeug
src/werkzeug/wrappers/json.py
JSONMixin.is_json
def is_json(self): """Check if the mimetype indicates JSON data, either :mimetype:`application/json` or :mimetype:`application/*+json`. """ mt = self.mimetype return ( mt == "application/json" or mt.startswith("application/") and mt.endswith("+...
python
def is_json(self): """Check if the mimetype indicates JSON data, either :mimetype:`application/json` or :mimetype:`application/*+json`. """ mt = self.mimetype return ( mt == "application/json" or mt.startswith("application/") and mt.endswith("+...
[ "def", "is_json", "(", "self", ")", ":", "mt", "=", "self", ".", "mimetype", "return", "(", "mt", "==", "\"application/json\"", "or", "mt", ".", "startswith", "(", "\"application/\"", ")", "and", "mt", ".", "endswith", "(", "\"+json\"", ")", ")" ]
Check if the mimetype indicates JSON data, either :mimetype:`application/json` or :mimetype:`application/*+json`.
[ "Check", "if", "the", "mimetype", "indicates", "JSON", "data", "either", ":", "mimetype", ":", "application", "/", "json", "or", ":", "mimetype", ":", "application", "/", "*", "+", "json", "." ]
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/wrappers/json.py#L72-L81
train
pallets/werkzeug
src/werkzeug/wrappers/json.py
JSONMixin.get_json
def get_json(self, force=False, silent=False, cache=True): """Parse :attr:`data` as JSON. If the mimetype does not indicate JSON (:mimetype:`application/json`, see :meth:`is_json`), this returns ``None``. If parsing fails, :meth:`on_json_loading_failed` is called and it...
python
def get_json(self, force=False, silent=False, cache=True): """Parse :attr:`data` as JSON. If the mimetype does not indicate JSON (:mimetype:`application/json`, see :meth:`is_json`), this returns ``None``. If parsing fails, :meth:`on_json_loading_failed` is called and it...
[ "def", "get_json", "(", "self", ",", "force", "=", "False", ",", "silent", "=", "False", ",", "cache", "=", "True", ")", ":", "if", "cache", "and", "self", ".", "_cached_json", "[", "silent", "]", "is", "not", "Ellipsis", ":", "return", "self", ".", ...
Parse :attr:`data` as JSON. If the mimetype does not indicate JSON (:mimetype:`application/json`, see :meth:`is_json`), this returns ``None``. If parsing fails, :meth:`on_json_loading_failed` is called and its return value is used as the return value. :param force: Ign...
[ "Parse", ":", "attr", ":", "data", "as", "JSON", "." ]
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/wrappers/json.py#L94-L137
train
pallets/werkzeug
src/werkzeug/middleware/proxy_fix.py
ProxyFix._get_trusted_comma
def _get_trusted_comma(self, trusted, value): """Get the real value from a comma-separated header based on the configured number of trusted proxies. :param trusted: Number of values to trust in the header. :param value: Header value to parse. :return: The real value, or ``None``...
python
def _get_trusted_comma(self, trusted, value): """Get the real value from a comma-separated header based on the configured number of trusted proxies. :param trusted: Number of values to trust in the header. :param value: Header value to parse. :return: The real value, or ``None``...
[ "def", "_get_trusted_comma", "(", "self", ",", "trusted", ",", "value", ")", ":", "if", "not", "(", "trusted", "and", "value", ")", ":", "return", "values", "=", "[", "x", ".", "strip", "(", ")", "for", "x", "in", "value", ".", "split", "(", "\",\"...
Get the real value from a comma-separated header based on the configured number of trusted proxies. :param trusted: Number of values to trust in the header. :param value: Header value to parse. :return: The real value, or ``None`` if there are fewer values than the number of...
[ "Get", "the", "real", "value", "from", "a", "comma", "-", "separated", "header", "based", "on", "the", "configured", "number", "of", "trusted", "proxies", "." ]
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/middleware/proxy_fix.py#L93-L108
train
pallets/werkzeug
examples/plnt/sync.py
sync
def sync(): """ Performs a synchronization. Articles that are already syncronized aren't touched anymore. """ for blog in Blog.query.all(): # parse the feed. feedparser.parse will never given an exception # but the bozo bit might be defined. feed = feedparser.parse(blog.feed_...
python
def sync(): """ Performs a synchronization. Articles that are already syncronized aren't touched anymore. """ for blog in Blog.query.all(): # parse the feed. feedparser.parse will never given an exception # but the bozo bit might be defined. feed = feedparser.parse(blog.feed_...
[ "def", "sync", "(", ")", ":", "for", "blog", "in", "Blog", ".", "query", ".", "all", "(", ")", ":", "# parse the feed. feedparser.parse will never given an exception", "# but the bozo bit might be defined.", "feed", "=", "feedparser", ".", "parse", "(", "blog", ".",...
Performs a synchronization. Articles that are already syncronized aren't touched anymore.
[ "Performs", "a", "synchronization", ".", "Articles", "that", "are", "already", "syncronized", "aren", "t", "touched", "anymore", "." ]
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/examples/plnt/sync.py#L26-L109
train
pallets/werkzeug
src/werkzeug/urls.py
_make_fast_url_quote
def _make_fast_url_quote(charset="utf-8", errors="strict", safe="/:", unsafe=""): """Precompile the translation table for a URL encoding function. Unlike :func:`url_quote`, the generated function only takes the string to quote. :param charset: The charset to encode the result with. :param errors: ...
python
def _make_fast_url_quote(charset="utf-8", errors="strict", safe="/:", unsafe=""): """Precompile the translation table for a URL encoding function. Unlike :func:`url_quote`, the generated function only takes the string to quote. :param charset: The charset to encode the result with. :param errors: ...
[ "def", "_make_fast_url_quote", "(", "charset", "=", "\"utf-8\"", ",", "errors", "=", "\"strict\"", ",", "safe", "=", "\"/:\"", ",", "unsafe", "=", "\"\"", ")", ":", "if", "isinstance", "(", "safe", ",", "text_type", ")", ":", "safe", "=", "safe", ".", ...
Precompile the translation table for a URL encoding function. Unlike :func:`url_quote`, the generated function only takes the string to quote. :param charset: The charset to encode the result with. :param errors: How to handle encoding errors. :param safe: An optional sequence of safe characters t...
[ "Precompile", "the", "translation", "table", "for", "a", "URL", "encoding", "function", "." ]
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/urls.py#L487-L517
train
pallets/werkzeug
src/werkzeug/urls.py
url_unquote_plus
def url_unquote_plus(s, charset="utf-8", errors="replace"): """URL decode a single string with the given `charset` and decode "+" to whitespace. Per default encoding errors are ignored. If you want a different behavior you can set `errors` to ``'replace'`` or ``'strict'``. In strict mode a :exc:`...
python
def url_unquote_plus(s, charset="utf-8", errors="replace"): """URL decode a single string with the given `charset` and decode "+" to whitespace. Per default encoding errors are ignored. If you want a different behavior you can set `errors` to ``'replace'`` or ``'strict'``. In strict mode a :exc:`...
[ "def", "url_unquote_plus", "(", "s", ",", "charset", "=", "\"utf-8\"", ",", "errors", "=", "\"replace\"", ")", ":", "if", "isinstance", "(", "s", ",", "text_type", ")", ":", "s", "=", "s", ".", "replace", "(", "u\"+\"", ",", "u\" \"", ")", "else", ":...
URL decode a single string with the given `charset` and decode "+" to whitespace. Per default encoding errors are ignored. If you want a different behavior you can set `errors` to ``'replace'`` or ``'strict'``. In strict mode a :exc:`HTTPUnicodeError` is raised. :param s: The string to unquote. ...
[ "URL", "decode", "a", "single", "string", "with", "the", "given", "charset", "and", "decode", "+", "to", "whitespace", "." ]
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/urls.py#L614-L631
train
pallets/werkzeug
src/werkzeug/urls.py
_codec_error_url_quote
def _codec_error_url_quote(e): """Used in :func:`uri_to_iri` after unquoting to re-quote any invalid bytes. """ out = _fast_url_quote(e.object[e.start : e.end]) if PY2: out = out.decode("utf-8") return out, e.end
python
def _codec_error_url_quote(e): """Used in :func:`uri_to_iri` after unquoting to re-quote any invalid bytes. """ out = _fast_url_quote(e.object[e.start : e.end]) if PY2: out = out.decode("utf-8") return out, e.end
[ "def", "_codec_error_url_quote", "(", "e", ")", ":", "out", "=", "_fast_url_quote", "(", "e", ".", "object", "[", "e", ".", "start", ":", "e", ".", "end", "]", ")", "if", "PY2", ":", "out", "=", "out", ".", "decode", "(", "\"utf-8\"", ")", "return"...
Used in :func:`uri_to_iri` after unquoting to re-quote any invalid bytes.
[ "Used", "in", ":", "func", ":", "uri_to_iri", "after", "unquoting", "to", "re", "-", "quote", "any", "invalid", "bytes", "." ]
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/urls.py#L668-L677
train
pallets/werkzeug
src/werkzeug/urls.py
url_join
def url_join(base, url, allow_fragments=True): """Join a base URL and a possibly relative URL to form an absolute interpretation of the latter. :param base: the base URL for the join operation. :param url: the URL to join. :param allow_fragments: indicates whether fragments should be allowed. "...
python
def url_join(base, url, allow_fragments=True): """Join a base URL and a possibly relative URL to form an absolute interpretation of the latter. :param base: the base URL for the join operation. :param url: the URL to join. :param allow_fragments: indicates whether fragments should be allowed. "...
[ "def", "url_join", "(", "base", ",", "url", ",", "allow_fragments", "=", "True", ")", ":", "if", "isinstance", "(", "base", ",", "tuple", ")", ":", "base", "=", "url_unparse", "(", "base", ")", "if", "isinstance", "(", "url", ",", "tuple", ")", ":", ...
Join a base URL and a possibly relative URL to form an absolute interpretation of the latter. :param base: the base URL for the join operation. :param url: the URL to join. :param allow_fragments: indicates whether fragments should be allowed.
[ "Join", "a", "base", "URL", "and", "a", "possibly", "relative", "URL", "to", "form", "an", "absolute", "interpretation", "of", "the", "latter", "." ]
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/urls.py#L975-L1039
train
pallets/werkzeug
src/werkzeug/urls.py
BaseURL.ascii_host
def ascii_host(self): """Works exactly like :attr:`host` but will return a result that is restricted to ASCII. If it finds a netloc that is not ASCII it will attempt to idna decode it. This is useful for socket operations when the URL might include internationalized characters. ...
python
def ascii_host(self): """Works exactly like :attr:`host` but will return a result that is restricted to ASCII. If it finds a netloc that is not ASCII it will attempt to idna decode it. This is useful for socket operations when the URL might include internationalized characters. ...
[ "def", "ascii_host", "(", "self", ")", ":", "rv", "=", "self", ".", "host", "if", "rv", "is", "not", "None", "and", "isinstance", "(", "rv", ",", "text_type", ")", ":", "try", ":", "rv", "=", "_encode_idna", "(", "rv", ")", "except", "UnicodeError", ...
Works exactly like :attr:`host` but will return a result that is restricted to ASCII. If it finds a netloc that is not ASCII it will attempt to idna decode it. This is useful for socket operations when the URL might include internationalized characters.
[ "Works", "exactly", "like", ":", "attr", ":", "host", "but", "will", "return", "a", "result", "that", "is", "restricted", "to", "ASCII", ".", "If", "it", "finds", "a", "netloc", "that", "is", "not", "ASCII", "it", "will", "attempt", "to", "idna", "deco...
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/urls.py#L81-L93
train
pallets/werkzeug
src/werkzeug/urls.py
BaseURL.port
def port(self): """The port in the URL as an integer if it was present, `None` otherwise. This does not fill in default ports. """ try: rv = int(to_native(self._split_host()[1])) if 0 <= rv <= 65535: return rv except (ValueError, TypeError...
python
def port(self): """The port in the URL as an integer if it was present, `None` otherwise. This does not fill in default ports. """ try: rv = int(to_native(self._split_host()[1])) if 0 <= rv <= 65535: return rv except (ValueError, TypeError...
[ "def", "port", "(", "self", ")", ":", "try", ":", "rv", "=", "int", "(", "to_native", "(", "self", ".", "_split_host", "(", ")", "[", "1", "]", ")", ")", "if", "0", "<=", "rv", "<=", "65535", ":", "return", "rv", "except", "(", "ValueError", ",...
The port in the URL as an integer if it was present, `None` otherwise. This does not fill in default ports.
[ "The", "port", "in", "the", "URL", "as", "an", "integer", "if", "it", "was", "present", "None", "otherwise", ".", "This", "does", "not", "fill", "in", "default", "ports", "." ]
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/urls.py#L96-L105
train
pallets/werkzeug
src/werkzeug/urls.py
BaseURL.get_file_location
def get_file_location(self, pathformat=None): """Returns a tuple with the location of the file in the form ``(server, location)``. If the netloc is empty in the URL or points to localhost, it's represented as ``None``. The `pathformat` by default is autodetection but needs to be set ...
python
def get_file_location(self, pathformat=None): """Returns a tuple with the location of the file in the form ``(server, location)``. If the netloc is empty in the URL or points to localhost, it's represented as ``None``. The `pathformat` by default is autodetection but needs to be set ...
[ "def", "get_file_location", "(", "self", ",", "pathformat", "=", "None", ")", ":", "if", "self", ".", "scheme", "!=", "\"file\"", ":", "return", "None", ",", "None", "path", "=", "url_unquote", "(", "self", ".", "path", ")", "host", "=", "self", ".", ...
Returns a tuple with the location of the file in the form ``(server, location)``. If the netloc is empty in the URL or points to localhost, it's represented as ``None``. The `pathformat` by default is autodetection but needs to be set when working with URLs of a specific system. The s...
[ "Returns", "a", "tuple", "with", "the", "location", "of", "the", "file", "in", "the", "form", "(", "server", "location", ")", ".", "If", "the", "netloc", "is", "empty", "in", "the", "URL", "or", "points", "to", "localhost", "it", "s", "represented", "a...
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/urls.py#L210-L268
train
pallets/werkzeug
examples/simplewiki/utils.py
generate_template
def generate_template(template_name, **context): """Load and generate a template.""" context.update(href=href, format_datetime=format_datetime) return template_loader.load(template_name).generate(**context)
python
def generate_template(template_name, **context): """Load and generate a template.""" context.update(href=href, format_datetime=format_datetime) return template_loader.load(template_name).generate(**context)
[ "def", "generate_template", "(", "template_name", ",", "*", "*", "context", ")", ":", "context", ".", "update", "(", "href", "=", "href", ",", "format_datetime", "=", "format_datetime", ")", "return", "template_loader", ".", "load", "(", "template_name", ")", ...
Load and generate a template.
[ "Load", "and", "generate", "a", "template", "." ]
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/examples/simplewiki/utils.py#L54-L57
train
pallets/werkzeug
examples/simplewiki/utils.py
href
def href(*args, **kw): """ Simple function for URL generation. Position arguments are used for the URL path and keyword arguments are used for the url parameters. """ result = [(request.script_root if request else "") + "/"] for idx, arg in enumerate(args): result.append(("/" if idx els...
python
def href(*args, **kw): """ Simple function for URL generation. Position arguments are used for the URL path and keyword arguments are used for the url parameters. """ result = [(request.script_root if request else "") + "/"] for idx, arg in enumerate(args): result.append(("/" if idx els...
[ "def", "href", "(", "*", "args", ",", "*", "*", "kw", ")", ":", "result", "=", "[", "(", "request", ".", "script_root", "if", "request", "else", "\"\"", ")", "+", "\"/\"", "]", "for", "idx", ",", "arg", "in", "enumerate", "(", "args", ")", ":", ...
Simple function for URL generation. Position arguments are used for the URL path and keyword arguments are used for the url parameters.
[ "Simple", "function", "for", "URL", "generation", ".", "Position", "arguments", "are", "used", "for", "the", "URL", "path", "and", "keyword", "arguments", "are", "used", "for", "the", "url", "parameters", "." ]
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/examples/simplewiki/utils.py#L65-L75
train
pallets/werkzeug
src/werkzeug/routing.py
parse_rule
def parse_rule(rule): """Parse a rule and return it as generator. Each iteration yields tuples in the form ``(converter, arguments, variable)``. If the converter is `None` it's a static url part, otherwise it's a dynamic one. :internal: """ pos = 0 end = len(rule) do_match = _rule_re.ma...
python
def parse_rule(rule): """Parse a rule and return it as generator. Each iteration yields tuples in the form ``(converter, arguments, variable)``. If the converter is `None` it's a static url part, otherwise it's a dynamic one. :internal: """ pos = 0 end = len(rule) do_match = _rule_re.ma...
[ "def", "parse_rule", "(", "rule", ")", ":", "pos", "=", "0", "end", "=", "len", "(", "rule", ")", "do_match", "=", "_rule_re", ".", "match", "used_names", "=", "set", "(", ")", "while", "pos", "<", "end", ":", "m", "=", "do_match", "(", "rule", "...
Parse a rule and return it as generator. Each iteration yields tuples in the form ``(converter, arguments, variable)``. If the converter is `None` it's a static url part, otherwise it's a dynamic one. :internal:
[ "Parse", "a", "rule", "and", "return", "it", "as", "generator", ".", "Each", "iteration", "yields", "tuples", "in", "the", "form", "(", "converter", "arguments", "variable", ")", ".", "If", "the", "converter", "is", "None", "it", "s", "a", "static", "url...
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/routing.py#L202-L231
train
pallets/werkzeug
src/werkzeug/routing.py
Map.is_endpoint_expecting
def is_endpoint_expecting(self, endpoint, *arguments): """Iterate over all rules and check if the endpoint expects the arguments provided. This is for example useful if you have some URLs that expect a language code and others that do not and you want to wrap the builder a bit so that t...
python
def is_endpoint_expecting(self, endpoint, *arguments): """Iterate over all rules and check if the endpoint expects the arguments provided. This is for example useful if you have some URLs that expect a language code and others that do not and you want to wrap the builder a bit so that t...
[ "def", "is_endpoint_expecting", "(", "self", ",", "endpoint", ",", "*", "arguments", ")", ":", "self", ".", "update", "(", ")", "arguments", "=", "set", "(", "arguments", ")", "for", "rule", "in", "self", ".", "_rules_by_endpoint", "[", "endpoint", "]", ...
Iterate over all rules and check if the endpoint expects the arguments provided. This is for example useful if you have some URLs that expect a language code and others that do not and you want to wrap the builder a bit so that the current language code is automatically added if not pro...
[ "Iterate", "over", "all", "rules", "and", "check", "if", "the", "endpoint", "expects", "the", "arguments", "provided", ".", "This", "is", "for", "example", "useful", "if", "you", "have", "some", "URLs", "that", "expect", "a", "language", "code", "and", "ot...
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/routing.py#L1523-L1541
train
pallets/werkzeug
src/werkzeug/routing.py
Map.iter_rules
def iter_rules(self, endpoint=None): """Iterate over all rules or the rules of an endpoint. :param endpoint: if provided only the rules for that endpoint are returned. :return: an iterator """ self.update() if endpoint is not None: re...
python
def iter_rules(self, endpoint=None): """Iterate over all rules or the rules of an endpoint. :param endpoint: if provided only the rules for that endpoint are returned. :return: an iterator """ self.update() if endpoint is not None: re...
[ "def", "iter_rules", "(", "self", ",", "endpoint", "=", "None", ")", ":", "self", ".", "update", "(", ")", "if", "endpoint", "is", "not", "None", ":", "return", "iter", "(", "self", ".", "_rules_by_endpoint", "[", "endpoint", "]", ")", "return", "iter"...
Iterate over all rules or the rules of an endpoint. :param endpoint: if provided only the rules for that endpoint are returned. :return: an iterator
[ "Iterate", "over", "all", "rules", "or", "the", "rules", "of", "an", "endpoint", "." ]
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/routing.py#L1543-L1553
train
pallets/werkzeug
src/werkzeug/routing.py
Map.add
def add(self, rulefactory): """Add a new rule or factory to the map and bind it. Requires that the rule is not bound to another map. :param rulefactory: a :class:`Rule` or :class:`RuleFactory` """ for rule in rulefactory.get_rules(self): rule.bind(self) ...
python
def add(self, rulefactory): """Add a new rule or factory to the map and bind it. Requires that the rule is not bound to another map. :param rulefactory: a :class:`Rule` or :class:`RuleFactory` """ for rule in rulefactory.get_rules(self): rule.bind(self) ...
[ "def", "add", "(", "self", ",", "rulefactory", ")", ":", "for", "rule", "in", "rulefactory", ".", "get_rules", "(", "self", ")", ":", "rule", ".", "bind", "(", "self", ")", "self", ".", "_rules", ".", "append", "(", "rule", ")", "self", ".", "_rule...
Add a new rule or factory to the map and bind it. Requires that the rule is not bound to another map. :param rulefactory: a :class:`Rule` or :class:`RuleFactory`
[ "Add", "a", "new", "rule", "or", "factory", "to", "the", "map", "and", "bind", "it", ".", "Requires", "that", "the", "rule", "is", "not", "bound", "to", "another", "map", "." ]
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/routing.py#L1555-L1565
train
pallets/werkzeug
src/werkzeug/routing.py
Map.bind
def bind( self, server_name, script_name=None, subdomain=None, url_scheme="http", default_method="GET", path_info=None, query_args=None, ): """Return a new :class:`MapAdapter` with the details specified to the call. Note that `script_n...
python
def bind( self, server_name, script_name=None, subdomain=None, url_scheme="http", default_method="GET", path_info=None, query_args=None, ): """Return a new :class:`MapAdapter` with the details specified to the call. Note that `script_n...
[ "def", "bind", "(", "self", ",", "server_name", ",", "script_name", "=", "None", ",", "subdomain", "=", "None", ",", "url_scheme", "=", "\"http\"", ",", "default_method", "=", "\"GET\"", ",", "path_info", "=", "None", ",", "query_args", "=", "None", ",", ...
Return a new :class:`MapAdapter` with the details specified to the call. Note that `script_name` will default to ``'/'`` if not further specified or `None`. The `server_name` at least is a requirement because the HTTP RFC requires absolute URLs for redirects and so all redirect excepti...
[ "Return", "a", "new", ":", "class", ":", "MapAdapter", "with", "the", "details", "specified", "to", "the", "call", ".", "Note", "that", "script_name", "will", "default", "to", "/", "if", "not", "further", "specified", "or", "None", ".", "The", "server_name...
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/routing.py#L1567-L1625
train
pallets/werkzeug
src/werkzeug/routing.py
Map.bind_to_environ
def bind_to_environ(self, environ, server_name=None, subdomain=None): """Like :meth:`bind` but you can pass it an WSGI environment and it will fetch the information from that dictionary. Note that because of limitations in the protocol there is no way to get the current subdomain and re...
python
def bind_to_environ(self, environ, server_name=None, subdomain=None): """Like :meth:`bind` but you can pass it an WSGI environment and it will fetch the information from that dictionary. Note that because of limitations in the protocol there is no way to get the current subdomain and re...
[ "def", "bind_to_environ", "(", "self", ",", "environ", ",", "server_name", "=", "None", ",", "subdomain", "=", "None", ")", ":", "environ", "=", "_get_environ", "(", "environ", ")", "wsgi_server_name", "=", "get_host", "(", "environ", ")", ".", "lower", "(...
Like :meth:`bind` but you can pass it an WSGI environment and it will fetch the information from that dictionary. Note that because of limitations in the protocol there is no way to get the current subdomain and real `server_name` from the environment. If you don't provide it, Werkzeug...
[ "Like", ":", "meth", ":", "bind", "but", "you", "can", "pass", "it", "an", "WSGI", "environment", "and", "it", "will", "fetch", "the", "information", "from", "that", "dictionary", ".", "Note", "that", "because", "of", "limitations", "in", "the", "protocol"...
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/routing.py#L1627-L1701
train
pallets/werkzeug
src/werkzeug/routing.py
Map.update
def update(self): """Called before matching and building to keep the compiled rules in the correct order after things changed. """ if not self._remap: return with self._remap_lock: if not self._remap: return self._rules.sort(k...
python
def update(self): """Called before matching and building to keep the compiled rules in the correct order after things changed. """ if not self._remap: return with self._remap_lock: if not self._remap: return self._rules.sort(k...
[ "def", "update", "(", "self", ")", ":", "if", "not", "self", ".", "_remap", ":", "return", "with", "self", ".", "_remap_lock", ":", "if", "not", "self", ".", "_remap", ":", "return", "self", ".", "_rules", ".", "sort", "(", "key", "=", "lambda", "x...
Called before matching and building to keep the compiled rules in the correct order after things changed.
[ "Called", "before", "matching", "and", "building", "to", "keep", "the", "compiled", "rules", "in", "the", "correct", "order", "after", "things", "changed", "." ]
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/routing.py#L1703-L1717
train
pallets/werkzeug
src/werkzeug/routing.py
MapAdapter.dispatch
def dispatch( self, view_func, path_info=None, method=None, catch_http_exceptions=False ): """Does the complete dispatching process. `view_func` is called with the endpoint and a dict with the values for the view. It should look up the view function, call it, and return a response ...
python
def dispatch( self, view_func, path_info=None, method=None, catch_http_exceptions=False ): """Does the complete dispatching process. `view_func` is called with the endpoint and a dict with the values for the view. It should look up the view function, call it, and return a response ...
[ "def", "dispatch", "(", "self", ",", "view_func", ",", "path_info", "=", "None", ",", "method", "=", "None", ",", "catch_http_exceptions", "=", "False", ")", ":", "try", ":", "try", ":", "endpoint", ",", "args", "=", "self", ".", "match", "(", "path_in...
Does the complete dispatching process. `view_func` is called with the endpoint and a dict with the values for the view. It should look up the view function, call it, and return a response object or WSGI application. http exceptions are not caught by default so that applications can di...
[ "Does", "the", "complete", "dispatching", "process", ".", "view_func", "is", "called", "with", "the", "endpoint", "and", "a", "dict", "with", "the", "values", "for", "the", "view", ".", "It", "should", "look", "up", "the", "view", "function", "call", "it",...
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/routing.py#L1753-L1807
train
pallets/werkzeug
src/werkzeug/routing.py
MapAdapter.allowed_methods
def allowed_methods(self, path_info=None): """Returns the valid methods that match for a given path. .. versionadded:: 0.7 """ try: self.match(path_info, method="--") except MethodNotAllowed as e: return e.valid_methods except HTTPException: ...
python
def allowed_methods(self, path_info=None): """Returns the valid methods that match for a given path. .. versionadded:: 0.7 """ try: self.match(path_info, method="--") except MethodNotAllowed as e: return e.valid_methods except HTTPException: ...
[ "def", "allowed_methods", "(", "self", ",", "path_info", "=", "None", ")", ":", "try", ":", "self", ".", "match", "(", "path_info", ",", "method", "=", "\"--\"", ")", "except", "MethodNotAllowed", "as", "e", ":", "return", "e", ".", "valid_methods", "exc...
Returns the valid methods that match for a given path. .. versionadded:: 0.7
[ "Returns", "the", "valid", "methods", "that", "match", "for", "a", "given", "path", "." ]
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/routing.py#L1979-L1990
train
pallets/werkzeug
src/werkzeug/routing.py
MapAdapter.get_host
def get_host(self, domain_part): """Figures out the full host name for the given domain part. The domain part is a subdomain in case host matching is disabled or a full host name. """ if self.map.host_matching: if domain_part is None: return self.serv...
python
def get_host(self, domain_part): """Figures out the full host name for the given domain part. The domain part is a subdomain in case host matching is disabled or a full host name. """ if self.map.host_matching: if domain_part is None: return self.serv...
[ "def", "get_host", "(", "self", ",", "domain_part", ")", ":", "if", "self", ".", "map", ".", "host_matching", ":", "if", "domain_part", "is", "None", ":", "return", "self", ".", "server_name", "return", "to_unicode", "(", "domain_part", ",", "\"ascii\"", "...
Figures out the full host name for the given domain part. The domain part is a subdomain in case host matching is disabled or a full host name.
[ "Figures", "out", "the", "full", "host", "name", "for", "the", "given", "domain", "part", ".", "The", "domain", "part", "is", "a", "subdomain", "in", "case", "host", "matching", "is", "disabled", "or", "a", "full", "host", "name", "." ]
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/routing.py#L1992-L2006
train
pallets/werkzeug
src/werkzeug/routing.py
MapAdapter.get_default_redirect
def get_default_redirect(self, rule, method, values, query_args): """A helper that returns the URL to redirect to if it finds one. This is used for default redirecting only. :internal: """ assert self.map.redirect_defaults for r in self.map._rules_by_endpoint[rule.endpoi...
python
def get_default_redirect(self, rule, method, values, query_args): """A helper that returns the URL to redirect to if it finds one. This is used for default redirecting only. :internal: """ assert self.map.redirect_defaults for r in self.map._rules_by_endpoint[rule.endpoi...
[ "def", "get_default_redirect", "(", "self", ",", "rule", ",", "method", ",", "values", ",", "query_args", ")", ":", "assert", "self", ".", "map", ".", "redirect_defaults", "for", "r", "in", "self", ".", "map", ".", "_rules_by_endpoint", "[", "rule", ".", ...
A helper that returns the URL to redirect to if it finds one. This is used for default redirecting only. :internal:
[ "A", "helper", "that", "returns", "the", "URL", "to", "redirect", "to", "if", "it", "finds", "one", ".", "This", "is", "used", "for", "default", "redirecting", "only", "." ]
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/routing.py#L2008-L2024
train
pallets/werkzeug
src/werkzeug/routing.py
MapAdapter.make_redirect_url
def make_redirect_url(self, path_info, query_args=None, domain_part=None): """Creates a redirect URL. :internal: """ suffix = "" if query_args: suffix = "?" + self.encode_query_args(query_args) return str( "%s://%s/%s%s" % ( ...
python
def make_redirect_url(self, path_info, query_args=None, domain_part=None): """Creates a redirect URL. :internal: """ suffix = "" if query_args: suffix = "?" + self.encode_query_args(query_args) return str( "%s://%s/%s%s" % ( ...
[ "def", "make_redirect_url", "(", "self", ",", "path_info", ",", "query_args", "=", "None", ",", "domain_part", "=", "None", ")", ":", "suffix", "=", "\"\"", "if", "query_args", ":", "suffix", "=", "\"?\"", "+", "self", ".", "encode_query_args", "(", "query...
Creates a redirect URL. :internal:
[ "Creates", "a", "redirect", "URL", "." ]
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/routing.py#L2031-L2049
train
pallets/werkzeug
src/werkzeug/routing.py
MapAdapter._partial_build
def _partial_build(self, endpoint, values, method, append_unknown): """Helper for :meth:`build`. Returns subdomain and path for the rule that accepts this endpoint, values and method. :internal: """ # in case the method is none, try with the default method first if meth...
python
def _partial_build(self, endpoint, values, method, append_unknown): """Helper for :meth:`build`. Returns subdomain and path for the rule that accepts this endpoint, values and method. :internal: """ # in case the method is none, try with the default method first if meth...
[ "def", "_partial_build", "(", "self", ",", "endpoint", ",", "values", ",", "method", ",", "append_unknown", ")", ":", "# in case the method is none, try with the default method first", "if", "method", "is", "None", ":", "rv", "=", "self", ".", "_partial_build", "(",...
Helper for :meth:`build`. Returns subdomain and path for the rule that accepts this endpoint, values and method. :internal:
[ "Helper", "for", ":", "meth", ":", "build", ".", "Returns", "subdomain", "and", "path", "for", "the", "rule", "that", "accepts", "this", "endpoint", "values", "and", "method", "." ]
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/routing.py#L2061-L2081
train
pallets/werkzeug
src/werkzeug/routing.py
MapAdapter.build
def build( self, endpoint, values=None, method=None, force_external=False, append_unknown=True, ): """Building URLs works pretty much the other way round. Instead of `match` you call `build` and pass it the endpoint and a dict of arguments for...
python
def build( self, endpoint, values=None, method=None, force_external=False, append_unknown=True, ): """Building URLs works pretty much the other way round. Instead of `match` you call `build` and pass it the endpoint and a dict of arguments for...
[ "def", "build", "(", "self", ",", "endpoint", ",", "values", "=", "None", ",", "method", "=", "None", ",", "force_external", "=", "False", ",", "append_unknown", "=", "True", ",", ")", ":", "self", ".", "map", ".", "update", "(", ")", "if", "values",...
Building URLs works pretty much the other way round. Instead of `match` you call `build` and pass it the endpoint and a dict of arguments for the placeholders. The `build` function also accepts an argument called `force_external` which, if you set it to `True` will force external URLs....
[ "Building", "URLs", "works", "pretty", "much", "the", "other", "way", "round", ".", "Instead", "of", "match", "you", "call", "build", "and", "pass", "it", "the", "endpoint", "and", "a", "dict", "of", "arguments", "for", "the", "placeholders", "." ]
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/routing.py#L2083-L2200
train
pallets/werkzeug
examples/coolmagic/utils.py
export
def export(string, template=None, **extra): """ Decorator for registering view functions and adding templates to it. """ def wrapped(f): endpoint = (f.__module__ + "." + f.__name__)[16:] if template is not None: old_f = f def f(**kwargs): rv ...
python
def export(string, template=None, **extra): """ Decorator for registering view functions and adding templates to it. """ def wrapped(f): endpoint = (f.__module__ + "." + f.__name__)[16:] if template is not None: old_f = f def f(**kwargs): rv ...
[ "def", "export", "(", "string", ",", "template", "=", "None", ",", "*", "*", "extra", ")", ":", "def", "wrapped", "(", "f", ")", ":", "endpoint", "=", "(", "f", ".", "__module__", "+", "\".\"", "+", "f", ".", "__name__", ")", "[", "16", ":", "]...
Decorator for registering view functions and adding templates to it.
[ "Decorator", "for", "registering", "view", "functions", "and", "adding", "templates", "to", "it", "." ]
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/examples/coolmagic/utils.py#L33-L55
train
pallets/werkzeug
src/werkzeug/local.py
LocalStack.push
def push(self, obj): """Pushes a new item to the stack""" rv = getattr(self._local, "stack", None) if rv is None: self._local.stack = rv = [] rv.append(obj) return rv
python
def push(self, obj): """Pushes a new item to the stack""" rv = getattr(self._local, "stack", None) if rv is None: self._local.stack = rv = [] rv.append(obj) return rv
[ "def", "push", "(", "self", ",", "obj", ")", ":", "rv", "=", "getattr", "(", "self", ".", "_local", ",", "\"stack\"", ",", "None", ")", "if", "rv", "is", "None", ":", "self", ".", "_local", ".", "stack", "=", "rv", "=", "[", "]", "rv", ".", "...
Pushes a new item to the stack
[ "Pushes", "a", "new", "item", "to", "the", "stack" ]
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/local.py#L142-L148
train
pallets/werkzeug
src/werkzeug/local.py
LocalStack.pop
def pop(self): """Removes the topmost item from the stack, will return the old value or `None` if the stack was already empty. """ stack = getattr(self._local, "stack", None) if stack is None: return None elif len(stack) == 1: release_local(self._l...
python
def pop(self): """Removes the topmost item from the stack, will return the old value or `None` if the stack was already empty. """ stack = getattr(self._local, "stack", None) if stack is None: return None elif len(stack) == 1: release_local(self._l...
[ "def", "pop", "(", "self", ")", ":", "stack", "=", "getattr", "(", "self", ".", "_local", ",", "\"stack\"", ",", "None", ")", "if", "stack", "is", "None", ":", "return", "None", "elif", "len", "(", "stack", ")", "==", "1", ":", "release_local", "("...
Removes the topmost item from the stack, will return the old value or `None` if the stack was already empty.
[ "Removes", "the", "topmost", "item", "from", "the", "stack", "will", "return", "the", "old", "value", "or", "None", "if", "the", "stack", "was", "already", "empty", "." ]
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/local.py#L150-L161
train
pallets/werkzeug
src/werkzeug/local.py
LocalManager.make_middleware
def make_middleware(self, app): """Wrap a WSGI application so that cleaning up happens after request end. """ def application(environ, start_response): return ClosingIterator(app(environ, start_response), self.cleanup) return application
python
def make_middleware(self, app): """Wrap a WSGI application so that cleaning up happens after request end. """ def application(environ, start_response): return ClosingIterator(app(environ, start_response), self.cleanup) return application
[ "def", "make_middleware", "(", "self", ",", "app", ")", ":", "def", "application", "(", "environ", ",", "start_response", ")", ":", "return", "ClosingIterator", "(", "app", "(", "environ", ",", "start_response", ")", ",", "self", ".", "cleanup", ")", "retu...
Wrap a WSGI application so that cleaning up happens after request end.
[ "Wrap", "a", "WSGI", "application", "so", "that", "cleaning", "up", "happens", "after", "request", "end", "." ]
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/local.py#L225-L233
train
pallets/werkzeug
src/werkzeug/wrappers/etag.py
ETagResponseMixin._wrap_response
def _wrap_response(self, start, length): """Wrap existing Response in case of Range Request context.""" if self.status_code == 206: self.response = _RangeWrapper(self.response, start, length)
python
def _wrap_response(self, start, length): """Wrap existing Response in case of Range Request context.""" if self.status_code == 206: self.response = _RangeWrapper(self.response, start, length)
[ "def", "_wrap_response", "(", "self", ",", "start", ",", "length", ")", ":", "if", "self", ".", "status_code", "==", "206", ":", "self", ".", "response", "=", "_RangeWrapper", "(", "self", ".", "response", ",", "start", ",", "length", ")" ]
Wrap existing Response in case of Range Request context.
[ "Wrap", "existing", "Response", "in", "case", "of", "Range", "Request", "context", "." ]
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/wrappers/etag.py#L112-L115
train
pallets/werkzeug
src/werkzeug/wrappers/etag.py
ETagResponseMixin._is_range_request_processable
def _is_range_request_processable(self, environ): """Return ``True`` if `Range` header is present and if underlying resource is considered unchanged when compared with `If-Range` header. """ return ( "HTTP_IF_RANGE" not in environ or not is_resource_modified( ...
python
def _is_range_request_processable(self, environ): """Return ``True`` if `Range` header is present and if underlying resource is considered unchanged when compared with `If-Range` header. """ return ( "HTTP_IF_RANGE" not in environ or not is_resource_modified( ...
[ "def", "_is_range_request_processable", "(", "self", ",", "environ", ")", ":", "return", "(", "\"HTTP_IF_RANGE\"", "not", "in", "environ", "or", "not", "is_resource_modified", "(", "environ", ",", "self", ".", "headers", ".", "get", "(", "\"etag\"", ")", ",", ...
Return ``True`` if `Range` header is present and if underlying resource is considered unchanged when compared with `If-Range` header.
[ "Return", "True", "if", "Range", "header", "is", "present", "and", "if", "underlying", "resource", "is", "considered", "unchanged", "when", "compared", "with", "If", "-", "Range", "header", "." ]
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/wrappers/etag.py#L117-L130
train
pallets/werkzeug
src/werkzeug/wrappers/etag.py
ETagResponseMixin._process_range_request
def _process_range_request(self, environ, complete_length=None, accept_ranges=None): """Handle Range Request related headers (RFC7233). If `Accept-Ranges` header is valid, and Range Request is processable, we set the headers as described by the RFC, and wrap the underlying response in a ...
python
def _process_range_request(self, environ, complete_length=None, accept_ranges=None): """Handle Range Request related headers (RFC7233). If `Accept-Ranges` header is valid, and Range Request is processable, we set the headers as described by the RFC, and wrap the underlying response in a ...
[ "def", "_process_range_request", "(", "self", ",", "environ", ",", "complete_length", "=", "None", ",", "accept_ranges", "=", "None", ")", ":", "from", ".", ".", "exceptions", "import", "RequestedRangeNotSatisfiable", "if", "accept_ranges", "is", "None", ":", "r...
Handle Range Request related headers (RFC7233). If `Accept-Ranges` header is valid, and Range Request is processable, we set the headers as described by the RFC, and wrap the underlying response in a RangeWrapper. Returns ``True`` if Range Request can be fulfilled, ``False`` otherwise....
[ "Handle", "Range", "Request", "related", "headers", "(", "RFC7233", ")", ".", "If", "Accept", "-", "Ranges", "header", "is", "valid", "and", "Range", "Request", "is", "processable", "we", "set", "the", "headers", "as", "described", "by", "the", "RFC", "and...
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/wrappers/etag.py#L132-L166
train
pallets/werkzeug
src/werkzeug/wrappers/etag.py
ETagResponseMixin.make_conditional
def make_conditional( self, request_or_environ, accept_ranges=False, complete_length=None ): """Make the response conditional to the request. This method works best if an etag was defined for the response already. The `add_etag` method can be used to do that. If called without eta...
python
def make_conditional( self, request_or_environ, accept_ranges=False, complete_length=None ): """Make the response conditional to the request. This method works best if an etag was defined for the response already. The `add_etag` method can be used to do that. If called without eta...
[ "def", "make_conditional", "(", "self", ",", "request_or_environ", ",", "accept_ranges", "=", "False", ",", "complete_length", "=", "None", ")", ":", "environ", "=", "_get_environ", "(", "request_or_environ", ")", "if", "environ", "[", "\"REQUEST_METHOD\"", "]", ...
Make the response conditional to the request. This method works best if an etag was defined for the response already. The `add_etag` method can be used to do that. If called without etag just the date header is set. This does nothing if the request method in the request or environ is...
[ "Make", "the", "response", "conditional", "to", "the", "request", ".", "This", "method", "works", "best", "if", "an", "etag", "was", "defined", "for", "the", "response", "already", ".", "The", "add_etag", "method", "can", "be", "used", "to", "do", "that", ...
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/wrappers/etag.py#L168-L234
train
pallets/werkzeug
src/werkzeug/wrappers/etag.py
ETagResponseMixin.add_etag
def add_etag(self, overwrite=False, weak=False): """Add an etag for the current response if there is none yet.""" if overwrite or "etag" not in self.headers: self.set_etag(generate_etag(self.get_data()), weak)
python
def add_etag(self, overwrite=False, weak=False): """Add an etag for the current response if there is none yet.""" if overwrite or "etag" not in self.headers: self.set_etag(generate_etag(self.get_data()), weak)
[ "def", "add_etag", "(", "self", ",", "overwrite", "=", "False", ",", "weak", "=", "False", ")", ":", "if", "overwrite", "or", "\"etag\"", "not", "in", "self", ".", "headers", ":", "self", ".", "set_etag", "(", "generate_etag", "(", "self", ".", "get_da...
Add an etag for the current response if there is none yet.
[ "Add", "an", "etag", "for", "the", "current", "response", "if", "there", "is", "none", "yet", "." ]
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/wrappers/etag.py#L236-L239
train
pallets/werkzeug
src/werkzeug/wrappers/etag.py
ETagResponseMixin.set_etag
def set_etag(self, etag, weak=False): """Set the etag, and override the old one if there was one.""" self.headers["ETag"] = quote_etag(etag, weak)
python
def set_etag(self, etag, weak=False): """Set the etag, and override the old one if there was one.""" self.headers["ETag"] = quote_etag(etag, weak)
[ "def", "set_etag", "(", "self", ",", "etag", ",", "weak", "=", "False", ")", ":", "self", ".", "headers", "[", "\"ETag\"", "]", "=", "quote_etag", "(", "etag", ",", "weak", ")" ]
Set the etag, and override the old one if there was one.
[ "Set", "the", "etag", "and", "override", "the", "old", "one", "if", "there", "was", "one", "." ]
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/wrappers/etag.py#L241-L243
train
pallets/werkzeug
src/werkzeug/wrappers/etag.py
ETagResponseMixin.freeze
def freeze(self, no_etag=False): """Call this method if you want to make your response object ready for pickeling. This buffers the generator if there is one. This also sets the etag unless `no_etag` is set to `True`. """ if not no_etag: self.add_etag() supe...
python
def freeze(self, no_etag=False): """Call this method if you want to make your response object ready for pickeling. This buffers the generator if there is one. This also sets the etag unless `no_etag` is set to `True`. """ if not no_etag: self.add_etag() supe...
[ "def", "freeze", "(", "self", ",", "no_etag", "=", "False", ")", ":", "if", "not", "no_etag", ":", "self", ".", "add_etag", "(", ")", "super", "(", "ETagResponseMixin", ",", "self", ")", ".", "freeze", "(", ")" ]
Call this method if you want to make your response object ready for pickeling. This buffers the generator if there is one. This also sets the etag unless `no_etag` is set to `True`.
[ "Call", "this", "method", "if", "you", "want", "to", "make", "your", "response", "object", "ready", "for", "pickeling", ".", "This", "buffers", "the", "generator", "if", "there", "is", "one", ".", "This", "also", "sets", "the", "etag", "unless", "no_etag",...
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/wrappers/etag.py#L251-L258
train
pallets/werkzeug
src/werkzeug/wsgi.py
get_host
def get_host(environ, trusted_hosts=None): """Return the host for the given WSGI environment. This first checks the ``Host`` header. If it's not present, then ``SERVER_NAME`` and ``SERVER_PORT`` are used. The host will only contain the port if it is different than the standard port for the protocol. ...
python
def get_host(environ, trusted_hosts=None): """Return the host for the given WSGI environment. This first checks the ``Host`` header. If it's not present, then ``SERVER_NAME`` and ``SERVER_PORT`` are used. The host will only contain the port if it is different than the standard port for the protocol. ...
[ "def", "get_host", "(", "environ", ",", "trusted_hosts", "=", "None", ")", ":", "if", "\"HTTP_HOST\"", "in", "environ", ":", "rv", "=", "environ", "[", "\"HTTP_HOST\"", "]", "if", "environ", "[", "\"wsgi.url_scheme\"", "]", "==", "\"http\"", "and", "rv", "...
Return the host for the given WSGI environment. This first checks the ``Host`` header. If it's not present, then ``SERVER_NAME`` and ``SERVER_PORT`` are used. The host will only contain the port if it is different than the standard port for the protocol. Optionally, verify that the host is trusted usin...
[ "Return", "the", "host", "for", "the", "given", "WSGI", "environment", ".", "This", "first", "checks", "the", "Host", "header", ".", "If", "it", "s", "not", "present", "then", "SERVER_NAME", "and", "SERVER_PORT", "are", "used", ".", "The", "host", "will", ...
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/wsgi.py#L145-L179
train
pallets/werkzeug
src/werkzeug/wsgi.py
get_query_string
def get_query_string(environ): """Returns the `QUERY_STRING` from the WSGI environment. This also takes care about the WSGI decoding dance on Python 3 environments as a native string. The string returned will be restricted to ASCII characters. .. versionadded:: 0.9 :param environ: the WSGI e...
python
def get_query_string(environ): """Returns the `QUERY_STRING` from the WSGI environment. This also takes care about the WSGI decoding dance on Python 3 environments as a native string. The string returned will be restricted to ASCII characters. .. versionadded:: 0.9 :param environ: the WSGI e...
[ "def", "get_query_string", "(", "environ", ")", ":", "qs", "=", "wsgi_get_bytes", "(", "environ", ".", "get", "(", "\"QUERY_STRING\"", ",", "\"\"", ")", ")", "# QUERY_STRING really should be ascii safe but some browsers", "# will send us some unicode stuff (I am looking at yo...
Returns the `QUERY_STRING` from the WSGI environment. This also takes care about the WSGI decoding dance on Python 3 environments as a native string. The string returned will be restricted to ASCII characters. .. versionadded:: 0.9 :param environ: the WSGI environment object to get the query str...
[ "Returns", "the", "QUERY_STRING", "from", "the", "WSGI", "environment", ".", "This", "also", "takes", "care", "about", "the", "WSGI", "decoding", "dance", "on", "Python", "3", "environments", "as", "a", "native", "string", ".", "The", "string", "returned", "...
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/wsgi.py#L238-L252
train
pallets/werkzeug
src/werkzeug/wsgi.py
extract_path_info
def extract_path_info( environ_or_baseurl, path_or_url, charset="utf-8", errors="werkzeug.url_quote", collapse_http_schemes=True, ): """Extracts the path info from the given URL (or WSGI environment) and path. The path info returned is a unicode string, not a bytestring suitable for a W...
python
def extract_path_info( environ_or_baseurl, path_or_url, charset="utf-8", errors="werkzeug.url_quote", collapse_http_schemes=True, ): """Extracts the path info from the given URL (or WSGI environment) and path. The path info returned is a unicode string, not a bytestring suitable for a W...
[ "def", "extract_path_info", "(", "environ_or_baseurl", ",", "path_or_url", ",", "charset", "=", "\"utf-8\"", ",", "errors", "=", "\"werkzeug.url_quote\"", ",", "collapse_http_schemes", "=", "True", ",", ")", ":", "def", "_normalize_netloc", "(", "scheme", ",", "ne...
Extracts the path info from the given URL (or WSGI environment) and path. The path info returned is a unicode string, not a bytestring suitable for a WSGI environment. The URLs might also be IRIs. If the path info could not be determined, `None` is returned. Some examples: >>> extract_path_info...
[ "Extracts", "the", "path", "info", "from", "the", "given", "URL", "(", "or", "WSGI", "environment", ")", "and", "path", ".", "The", "path", "info", "returned", "is", "a", "unicode", "string", "not", "a", "bytestring", "suitable", "for", "a", "WSGI", "env...
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/wsgi.py#L369-L462
train
pallets/werkzeug
src/werkzeug/wsgi.py
make_line_iter
def make_line_iter(stream, limit=None, buffer_size=10 * 1024, cap_at_buffer=False): """Safely iterates line-based over an input stream. If the input stream is not a :class:`LimitedStream` the `limit` parameter is mandatory. This uses the stream's :meth:`~file.read` method internally as opposite to the...
python
def make_line_iter(stream, limit=None, buffer_size=10 * 1024, cap_at_buffer=False): """Safely iterates line-based over an input stream. If the input stream is not a :class:`LimitedStream` the `limit` parameter is mandatory. This uses the stream's :meth:`~file.read` method internally as opposite to the...
[ "def", "make_line_iter", "(", "stream", ",", "limit", "=", "None", ",", "buffer_size", "=", "10", "*", "1024", ",", "cap_at_buffer", "=", "False", ")", ":", "_iter", "=", "_make_chunk_iter", "(", "stream", ",", "limit", ",", "buffer_size", ")", "first_item...
Safely iterates line-based over an input stream. If the input stream is not a :class:`LimitedStream` the `limit` parameter is mandatory. This uses the stream's :meth:`~file.read` method internally as opposite to the :meth:`~file.readline` method that is unsafe and can only be used in violation of the ...
[ "Safely", "iterates", "line", "-", "based", "over", "an", "input", "stream", ".", "If", "the", "input", "stream", "is", "not", "a", ":", "class", ":", "LimitedStream", "the", "limit", "parameter", "is", "mandatory", "." ]
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/wsgi.py#L687-L769
train
pallets/werkzeug
src/werkzeug/wsgi.py
make_chunk_iter
def make_chunk_iter( stream, separator, limit=None, buffer_size=10 * 1024, cap_at_buffer=False ): """Works like :func:`make_line_iter` but accepts a separator which divides chunks. If you want newline based processing you should use :func:`make_line_iter` instead as it supports arbitrary newline ma...
python
def make_chunk_iter( stream, separator, limit=None, buffer_size=10 * 1024, cap_at_buffer=False ): """Works like :func:`make_line_iter` but accepts a separator which divides chunks. If you want newline based processing you should use :func:`make_line_iter` instead as it supports arbitrary newline ma...
[ "def", "make_chunk_iter", "(", "stream", ",", "separator", ",", "limit", "=", "None", ",", "buffer_size", "=", "10", "*", "1024", ",", "cap_at_buffer", "=", "False", ")", ":", "_iter", "=", "_make_chunk_iter", "(", "stream", ",", "limit", ",", "buffer_size...
Works like :func:`make_line_iter` but accepts a separator which divides chunks. If you want newline based processing you should use :func:`make_line_iter` instead as it supports arbitrary newline markers. .. versionadded:: 0.8 .. versionadded:: 0.9 added support for iterators as input stre...
[ "Works", "like", ":", "func", ":", "make_line_iter", "but", "accepts", "a", "separator", "which", "divides", "chunks", ".", "If", "you", "want", "newline", "based", "processing", "you", "should", "use", ":", "func", ":", "make_line_iter", "instead", "as", "i...
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/wsgi.py#L772-L842
train
pallets/werkzeug
src/werkzeug/filesystem.py
_is_ascii_encoding
def _is_ascii_encoding(encoding): """Given an encoding this figures out if the encoding is actually ASCII (which is something we don't actually want in most cases). This is necessary because ASCII comes under many names such as ANSI_X3.4-1968. """ if encoding is None: return False try: ...
python
def _is_ascii_encoding(encoding): """Given an encoding this figures out if the encoding is actually ASCII (which is something we don't actually want in most cases). This is necessary because ASCII comes under many names such as ANSI_X3.4-1968. """ if encoding is None: return False try: ...
[ "def", "_is_ascii_encoding", "(", "encoding", ")", ":", "if", "encoding", "is", "None", ":", "return", "False", "try", ":", "return", "codecs", ".", "lookup", "(", "encoding", ")", ".", "name", "==", "\"ascii\"", "except", "LookupError", ":", "return", "Fa...
Given an encoding this figures out if the encoding is actually ASCII (which is something we don't actually want in most cases). This is necessary because ASCII comes under many names such as ANSI_X3.4-1968.
[ "Given", "an", "encoding", "this", "figures", "out", "if", "the", "encoding", "is", "actually", "ASCII", "(", "which", "is", "something", "we", "don", "t", "actually", "want", "in", "most", "cases", ")", ".", "This", "is", "necessary", "because", "ASCII", ...
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/filesystem.py#L21-L31
train
pallets/werkzeug
src/werkzeug/filesystem.py
get_filesystem_encoding
def get_filesystem_encoding(): """Returns the filesystem encoding that should be used. Note that this is different from the Python understanding of the filesystem encoding which might be deeply flawed. Do not use this value against Python's unicode APIs because it might be different. See :ref:`filesyste...
python
def get_filesystem_encoding(): """Returns the filesystem encoding that should be used. Note that this is different from the Python understanding of the filesystem encoding which might be deeply flawed. Do not use this value against Python's unicode APIs because it might be different. See :ref:`filesyste...
[ "def", "get_filesystem_encoding", "(", ")", ":", "global", "_warned_about_filesystem_encoding", "rv", "=", "sys", ".", "getfilesystemencoding", "(", ")", "if", "has_likely_buggy_unicode_filesystem", "and", "not", "rv", "or", "_is_ascii_encoding", "(", "rv", ")", ":", ...
Returns the filesystem encoding that should be used. Note that this is different from the Python understanding of the filesystem encoding which might be deeply flawed. Do not use this value against Python's unicode APIs because it might be different. See :ref:`filesystem-encoding` for the exact behavior...
[ "Returns", "the", "filesystem", "encoding", "that", "should", "be", "used", ".", "Note", "that", "this", "is", "different", "from", "the", "Python", "understanding", "of", "the", "filesystem", "encoding", "which", "might", "be", "deeply", "flawed", ".", "Do", ...
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/filesystem.py#L42-L64
train
pallets/werkzeug
src/werkzeug/_reloader.py
_iter_module_files
def _iter_module_files(): """This iterates over all relevant Python files. It goes through all loaded files from modules, all files in folders of already loaded modules as well as all files reachable through a package. """ # The list call is necessary on Python 3 in case the module # dictionary...
python
def _iter_module_files(): """This iterates over all relevant Python files. It goes through all loaded files from modules, all files in folders of already loaded modules as well as all files reachable through a package. """ # The list call is necessary on Python 3 in case the module # dictionary...
[ "def", "_iter_module_files", "(", ")", ":", "# The list call is necessary on Python 3 in case the module", "# dictionary modifies during iteration.", "for", "module", "in", "list", "(", "sys", ".", "modules", ".", "values", "(", ")", ")", ":", "if", "module", "is", "N...
This iterates over all relevant Python files. It goes through all loaded files from modules, all files in folders of already loaded modules as well as all files reachable through a package.
[ "This", "iterates", "over", "all", "relevant", "Python", "files", ".", "It", "goes", "through", "all", "loaded", "files", "from", "modules", "all", "files", "in", "folders", "of", "already", "loaded", "modules", "as", "well", "as", "all", "files", "reachable...
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/_reloader.py#L14-L40
train
pallets/werkzeug
src/werkzeug/_reloader.py
_find_observable_paths
def _find_observable_paths(extra_files=None): """Finds all paths that should be observed.""" rv = set( os.path.dirname(os.path.abspath(x)) if os.path.isfile(x) else os.path.abspath(x) for x in sys.path ) for filename in extra_files or (): rv.add(os.path.dirname(os.path.abspath(f...
python
def _find_observable_paths(extra_files=None): """Finds all paths that should be observed.""" rv = set( os.path.dirname(os.path.abspath(x)) if os.path.isfile(x) else os.path.abspath(x) for x in sys.path ) for filename in extra_files or (): rv.add(os.path.dirname(os.path.abspath(f...
[ "def", "_find_observable_paths", "(", "extra_files", "=", "None", ")", ":", "rv", "=", "set", "(", "os", ".", "path", ".", "dirname", "(", "os", ".", "path", ".", "abspath", "(", "x", ")", ")", "if", "os", ".", "path", ".", "isfile", "(", "x", ")...
Finds all paths that should be observed.
[ "Finds", "all", "paths", "that", "should", "be", "observed", "." ]
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/_reloader.py#L43-L60
train
pallets/werkzeug
src/werkzeug/_reloader.py
_get_args_for_reloading
def _get_args_for_reloading(): """Returns the executable. This contains a workaround for windows if the executable is incorrectly reported to not have the .exe extension which can cause bugs on reloading. This also contains a workaround for linux where the file is executable (possibly with a progra...
python
def _get_args_for_reloading(): """Returns the executable. This contains a workaround for windows if the executable is incorrectly reported to not have the .exe extension which can cause bugs on reloading. This also contains a workaround for linux where the file is executable (possibly with a progra...
[ "def", "_get_args_for_reloading", "(", ")", ":", "rv", "=", "[", "sys", ".", "executable", "]", "py_script", "=", "os", ".", "path", ".", "abspath", "(", "sys", ".", "argv", "[", "0", "]", ")", "args", "=", "sys", ".", "argv", "[", "1", ":", "]",...
Returns the executable. This contains a workaround for windows if the executable is incorrectly reported to not have the .exe extension which can cause bugs on reloading. This also contains a workaround for linux where the file is executable (possibly with a program other than python)
[ "Returns", "the", "executable", ".", "This", "contains", "a", "workaround", "for", "windows", "if", "the", "executable", "is", "incorrectly", "reported", "to", "not", "have", "the", ".", "exe", "extension", "which", "can", "cause", "bugs", "on", "reloading", ...
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/_reloader.py#L63-L113
train
pallets/werkzeug
src/werkzeug/_reloader.py
_find_common_roots
def _find_common_roots(paths): """Out of some paths it finds the common roots that need monitoring.""" paths = [x.split(os.path.sep) for x in paths] root = {} for chunks in sorted(paths, key=len, reverse=True): node = root for chunk in chunks: node = node.setdefault(chunk, {}...
python
def _find_common_roots(paths): """Out of some paths it finds the common roots that need monitoring.""" paths = [x.split(os.path.sep) for x in paths] root = {} for chunks in sorted(paths, key=len, reverse=True): node = root for chunk in chunks: node = node.setdefault(chunk, {}...
[ "def", "_find_common_roots", "(", "paths", ")", ":", "paths", "=", "[", "x", ".", "split", "(", "os", ".", "path", ".", "sep", ")", "for", "x", "in", "paths", "]", "root", "=", "{", "}", "for", "chunks", "in", "sorted", "(", "paths", ",", "key", ...
Out of some paths it finds the common roots that need monitoring.
[ "Out", "of", "some", "paths", "it", "finds", "the", "common", "roots", "that", "need", "monitoring", "." ]
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/_reloader.py#L116-L135
train
pallets/werkzeug
src/werkzeug/_reloader.py
ensure_echo_on
def ensure_echo_on(): """Ensure that echo mode is enabled. Some tools such as PDB disable it which causes usability issues after reload.""" # tcgetattr will fail if stdin isn't a tty if not sys.stdin.isatty(): return try: import termios except ImportError: return attr...
python
def ensure_echo_on(): """Ensure that echo mode is enabled. Some tools such as PDB disable it which causes usability issues after reload.""" # tcgetattr will fail if stdin isn't a tty if not sys.stdin.isatty(): return try: import termios except ImportError: return attr...
[ "def", "ensure_echo_on", "(", ")", ":", "# tcgetattr will fail if stdin isn't a tty", "if", "not", "sys", ".", "stdin", ".", "isatty", "(", ")", ":", "return", "try", ":", "import", "termios", "except", "ImportError", ":", "return", "attributes", "=", "termios",...
Ensure that echo mode is enabled. Some tools such as PDB disable it which causes usability issues after reload.
[ "Ensure", "that", "echo", "mode", "is", "enabled", ".", "Some", "tools", "such", "as", "PDB", "disable", "it", "which", "causes", "usability", "issues", "after", "reload", "." ]
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/_reloader.py#L302-L315
train
pallets/werkzeug
src/werkzeug/_reloader.py
run_with_reloader
def run_with_reloader(main_func, extra_files=None, interval=1, reloader_type="auto"): """Run the given function in an independent python interpreter.""" import signal reloader = reloader_loops[reloader_type](extra_files, interval) signal.signal(signal.SIGTERM, lambda *args: sys.exit(0)) try: ...
python
def run_with_reloader(main_func, extra_files=None, interval=1, reloader_type="auto"): """Run the given function in an independent python interpreter.""" import signal reloader = reloader_loops[reloader_type](extra_files, interval) signal.signal(signal.SIGTERM, lambda *args: sys.exit(0)) try: ...
[ "def", "run_with_reloader", "(", "main_func", ",", "extra_files", "=", "None", ",", "interval", "=", "1", ",", "reloader_type", "=", "\"auto\"", ")", ":", "import", "signal", "reloader", "=", "reloader_loops", "[", "reloader_type", "]", "(", "extra_files", ","...
Run the given function in an independent python interpreter.
[ "Run", "the", "given", "function", "in", "an", "independent", "python", "interpreter", "." ]
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/_reloader.py#L318-L334
train
pallets/werkzeug
src/werkzeug/_reloader.py
ReloaderLoop.restart_with_reloader
def restart_with_reloader(self): """Spawn a new Python interpreter with the same arguments as this one, but running the reloader thread. """ while 1: _log("info", " * Restarting with %s" % self.name) args = _get_args_for_reloading() # a weird bug on w...
python
def restart_with_reloader(self): """Spawn a new Python interpreter with the same arguments as this one, but running the reloader thread. """ while 1: _log("info", " * Restarting with %s" % self.name) args = _get_args_for_reloading() # a weird bug on w...
[ "def", "restart_with_reloader", "(", "self", ")", ":", "while", "1", ":", "_log", "(", "\"info\"", ",", "\" * Restarting with %s\"", "%", "self", ".", "name", ")", "args", "=", "_get_args_for_reloading", "(", ")", "# a weird bug on windows. sometimes unicode strings e...
Spawn a new Python interpreter with the same arguments as this one, but running the reloader thread.
[ "Spawn", "a", "new", "Python", "interpreter", "with", "the", "same", "arguments", "as", "this", "one", "but", "running", "the", "reloader", "thread", "." ]
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/_reloader.py#L153-L178
train
pallets/werkzeug
examples/simplewiki/application.py
SimpleWiki.dispatch_request
def dispatch_request(self, environ, start_response): """Dispatch an incoming request.""" # set up all the stuff we want to have for this request. That is # creating a request object, propagating the application to the # current context and instanciating the database session. sel...
python
def dispatch_request(self, environ, start_response): """Dispatch an incoming request.""" # set up all the stuff we want to have for this request. That is # creating a request object, propagating the application to the # current context and instanciating the database session. sel...
[ "def", "dispatch_request", "(", "self", ",", "environ", ",", "start_response", ")", ":", "# set up all the stuff we want to have for this request. That is", "# creating a request object, propagating the application to the", "# current context and instanciating the database session.", "sel...
Dispatch an incoming request.
[ "Dispatch", "an", "incoming", "request", "." ]
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/examples/simplewiki/application.py#L64-L100
train
pallets/werkzeug
src/werkzeug/utils.py
get_content_type
def get_content_type(mimetype, charset): """Returns the full content type string with charset for a mimetype. If the mimetype represents text, the charset parameter will be appended, otherwise the mimetype is returned unchanged. :param mimetype: The mimetype to be used as content type. :param char...
python
def get_content_type(mimetype, charset): """Returns the full content type string with charset for a mimetype. If the mimetype represents text, the charset parameter will be appended, otherwise the mimetype is returned unchanged. :param mimetype: The mimetype to be used as content type. :param char...
[ "def", "get_content_type", "(", "mimetype", ",", "charset", ")", ":", "if", "(", "mimetype", ".", "startswith", "(", "\"text/\"", ")", "or", "mimetype", "in", "_charset_mimetypes", "or", "mimetype", ".", "endswith", "(", "\"+xml\"", ")", ")", ":", "mimetype"...
Returns the full content type string with charset for a mimetype. If the mimetype represents text, the charset parameter will be appended, otherwise the mimetype is returned unchanged. :param mimetype: The mimetype to be used as content type. :param charset: The charset to be appended for text mimetyp...
[ "Returns", "the", "full", "content", "type", "string", "with", "charset", "for", "a", "mimetype", "." ]
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/utils.py#L291-L313
train
pallets/werkzeug
src/werkzeug/utils.py
detect_utf_encoding
def detect_utf_encoding(data): """Detect which UTF encoding was used to encode the given bytes. The latest JSON standard (:rfc:`8259`) suggests that only UTF-8 is accepted. Older documents allowed 8, 16, or 32. 16 and 32 can be big or little endian. Some editors or libraries may prepend a BOM. :in...
python
def detect_utf_encoding(data): """Detect which UTF encoding was used to encode the given bytes. The latest JSON standard (:rfc:`8259`) suggests that only UTF-8 is accepted. Older documents allowed 8, 16, or 32. 16 and 32 can be big or little endian. Some editors or libraries may prepend a BOM. :in...
[ "def", "detect_utf_encoding", "(", "data", ")", ":", "head", "=", "data", "[", ":", "4", "]", "if", "head", "[", ":", "3", "]", "==", "codecs", ".", "BOM_UTF8", ":", "return", "\"utf-8-sig\"", "if", "b\"\\x00\"", "not", "in", "head", ":", "return", "...
Detect which UTF encoding was used to encode the given bytes. The latest JSON standard (:rfc:`8259`) suggests that only UTF-8 is accepted. Older documents allowed 8, 16, or 32. 16 and 32 can be big or little endian. Some editors or libraries may prepend a BOM. :internal: :param data: Bytes in unk...
[ "Detect", "which", "UTF", "encoding", "was", "used", "to", "encode", "the", "given", "bytes", "." ]
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/utils.py#L316-L360
train
pallets/werkzeug
src/werkzeug/utils.py
format_string
def format_string(string, context): """String-template format a string: >>> format_string('$foo and ${foo}s', dict(foo=42)) '42 and 42s' This does not do any attribute lookup etc. For more advanced string formattings have a look at the `werkzeug.template` module. :param string: the format st...
python
def format_string(string, context): """String-template format a string: >>> format_string('$foo and ${foo}s', dict(foo=42)) '42 and 42s' This does not do any attribute lookup etc. For more advanced string formattings have a look at the `werkzeug.template` module. :param string: the format st...
[ "def", "format_string", "(", "string", ",", "context", ")", ":", "def", "lookup_arg", "(", "match", ")", ":", "x", "=", "context", "[", "match", ".", "group", "(", "1", ")", "or", "match", ".", "group", "(", "2", ")", "]", "if", "not", "isinstance"...
String-template format a string: >>> format_string('$foo and ${foo}s', dict(foo=42)) '42 and 42s' This does not do any attribute lookup etc. For more advanced string formattings have a look at the `werkzeug.template` module. :param string: the format string. :param context: a dict with the v...
[ "String", "-", "template", "format", "a", "string", ":" ]
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/utils.py#L363-L382
train
pallets/werkzeug
src/werkzeug/utils.py
secure_filename
def secure_filename(filename): r"""Pass it a filename and it will return a secure version of it. This filename can then safely be stored on a regular file system and passed to :func:`os.path.join`. The filename returned is an ASCII only string for maximum portability. On windows systems the funct...
python
def secure_filename(filename): r"""Pass it a filename and it will return a secure version of it. This filename can then safely be stored on a regular file system and passed to :func:`os.path.join`. The filename returned is an ASCII only string for maximum portability. On windows systems the funct...
[ "def", "secure_filename", "(", "filename", ")", ":", "if", "isinstance", "(", "filename", ",", "text_type", ")", ":", "from", "unicodedata", "import", "normalize", "filename", "=", "normalize", "(", "\"NFKD\"", ",", "filename", ")", ".", "encode", "(", "\"as...
r"""Pass it a filename and it will return a secure version of it. This filename can then safely be stored on a regular file system and passed to :func:`os.path.join`. The filename returned is an ASCII only string for maximum portability. On windows systems the function also makes sure that the file i...
[ "r", "Pass", "it", "a", "filename", "and", "it", "will", "return", "a", "secure", "version", "of", "it", ".", "This", "filename", "can", "then", "safely", "be", "stored", "on", "a", "regular", "file", "system", "and", "passed", "to", ":", "func", ":", ...
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/utils.py#L385-L432
train
pallets/werkzeug
src/werkzeug/utils.py
escape
def escape(s): """Replace special characters "&", "<", ">" and (") to HTML-safe sequences. There is a special handling for `None` which escapes to an empty string. .. versionchanged:: 0.9 `quote` is now implicitly on. :param s: the string to escape. :param quote: ignored. """ if s ...
python
def escape(s): """Replace special characters "&", "<", ">" and (") to HTML-safe sequences. There is a special handling for `None` which escapes to an empty string. .. versionchanged:: 0.9 `quote` is now implicitly on. :param s: the string to escape. :param quote: ignored. """ if s ...
[ "def", "escape", "(", "s", ")", ":", "if", "s", "is", "None", ":", "return", "\"\"", "elif", "hasattr", "(", "s", ",", "\"__html__\"", ")", ":", "return", "text_type", "(", "s", ".", "__html__", "(", ")", ")", "if", "not", "isinstance", "(", "s", ...
Replace special characters "&", "<", ">" and (") to HTML-safe sequences. There is a special handling for `None` which escapes to an empty string. .. versionchanged:: 0.9 `quote` is now implicitly on. :param s: the string to escape. :param quote: ignored.
[ "Replace", "special", "characters", "&", "<", ">", "and", "(", ")", "to", "HTML", "-", "safe", "sequences", "." ]
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/utils.py#L435-L459
train
pallets/werkzeug
src/werkzeug/utils.py
find_modules
def find_modules(import_path, include_packages=False, recursive=False): """Finds all the modules below a package. This can be useful to automatically import all views / controllers so that their metaclasses / function decorators have a chance to register themselves on the application. Packages are...
python
def find_modules(import_path, include_packages=False, recursive=False): """Finds all the modules below a package. This can be useful to automatically import all views / controllers so that their metaclasses / function decorators have a chance to register themselves on the application. Packages are...
[ "def", "find_modules", "(", "import_path", ",", "include_packages", "=", "False", ",", "recursive", "=", "False", ")", ":", "module", "=", "import_string", "(", "import_path", ")", "path", "=", "getattr", "(", "module", ",", "\"__path__\"", ",", "None", ")",...
Finds all the modules below a package. This can be useful to automatically import all views / controllers so that their metaclasses / function decorators have a chance to register themselves on the application. Packages are not returned unless `include_packages` is `True`. This can also recursive...
[ "Finds", "all", "the", "modules", "below", "a", "package", ".", "This", "can", "be", "useful", "to", "automatically", "import", "all", "views", "/", "controllers", "so", "that", "their", "metaclasses", "/", "function", "decorators", "have", "a", "chance", "t...
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/utils.py#L584-L613
train
pallets/werkzeug
src/werkzeug/utils.py
validate_arguments
def validate_arguments(func, args, kwargs, drop_extra=True): """Checks if the function accepts the arguments and keyword arguments. Returns a new ``(args, kwargs)`` tuple that can safely be passed to the function without causing a `TypeError` because the function signature is incompatible. If `drop_ext...
python
def validate_arguments(func, args, kwargs, drop_extra=True): """Checks if the function accepts the arguments and keyword arguments. Returns a new ``(args, kwargs)`` tuple that can safely be passed to the function without causing a `TypeError` because the function signature is incompatible. If `drop_ext...
[ "def", "validate_arguments", "(", "func", ",", "args", ",", "kwargs", ",", "drop_extra", "=", "True", ")", ":", "parser", "=", "_parse_signature", "(", "func", ")", "args", ",", "kwargs", ",", "missing", ",", "extra", ",", "extra_positional", "=", "parser"...
Checks if the function accepts the arguments and keyword arguments. Returns a new ``(args, kwargs)`` tuple that can safely be passed to the function without causing a `TypeError` because the function signature is incompatible. If `drop_extra` is set to `True` (which is the default) any extra positional...
[ "Checks", "if", "the", "function", "accepts", "the", "arguments", "and", "keyword", "arguments", ".", "Returns", "a", "new", "(", "args", "kwargs", ")", "tuple", "that", "can", "safely", "be", "passed", "to", "the", "function", "without", "causing", "a", "...
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/utils.py#L616-L666
train
pallets/werkzeug
src/werkzeug/utils.py
bind_arguments
def bind_arguments(func, args, kwargs): """Bind the arguments provided into a dict. When passed a function, a tuple of arguments and a dict of keyword arguments `bind_arguments` returns a dict of names as the function would see it. This can be useful to implement a cache decorator that uses the functi...
python
def bind_arguments(func, args, kwargs): """Bind the arguments provided into a dict. When passed a function, a tuple of arguments and a dict of keyword arguments `bind_arguments` returns a dict of names as the function would see it. This can be useful to implement a cache decorator that uses the functi...
[ "def", "bind_arguments", "(", "func", ",", "args", ",", "kwargs", ")", ":", "(", "args", ",", "kwargs", ",", "missing", ",", "extra", ",", "extra_positional", ",", "arg_spec", ",", "vararg_var", ",", "kwarg_var", ",", ")", "=", "_parse_signature", "(", "...
Bind the arguments provided into a dict. When passed a function, a tuple of arguments and a dict of keyword arguments `bind_arguments` returns a dict of names as the function would see it. This can be useful to implement a cache decorator that uses the function arguments to build the cache key based o...
[ "Bind", "the", "arguments", "provided", "into", "a", "dict", ".", "When", "passed", "a", "function", "a", "tuple", "of", "arguments", "and", "a", "dict", "of", "keyword", "arguments", "bind_arguments", "returns", "a", "dict", "of", "names", "as", "the", "f...
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/utils.py#L669-L707
train
pallets/werkzeug
examples/plnt/views.py
index
def index(request, page): """Show the index page or any an offset of it.""" days = [] days_found = set() query = Entry.query.order_by(Entry.pub_date.desc()) pagination = Pagination(query, PER_PAGE, page, "index") for entry in pagination.entries: day = date(*entry.pub_date.timetuple()[:3]...
python
def index(request, page): """Show the index page or any an offset of it.""" days = [] days_found = set() query = Entry.query.order_by(Entry.pub_date.desc()) pagination = Pagination(query, PER_PAGE, page, "index") for entry in pagination.entries: day = date(*entry.pub_date.timetuple()[:3]...
[ "def", "index", "(", "request", ",", "page", ")", ":", "days", "=", "[", "]", "days_found", "=", "set", "(", ")", "query", "=", "Entry", ".", "query", ".", "order_by", "(", "Entry", ".", "pub_date", ".", "desc", "(", ")", ")", "pagination", "=", ...
Show the index page or any an offset of it.
[ "Show", "the", "index", "page", "or", "any", "an", "offset", "of", "it", "." ]
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/examples/plnt/views.py#L25-L37
train
pallets/werkzeug
src/werkzeug/debug/repr.py
dump
def dump(obj=missing): """Print the object details to stdout._write (for the interactive console of the web debugger. """ gen = DebugReprGenerator() if obj is missing: rv = gen.dump_locals(sys._getframe(1).f_locals) else: rv = gen.dump_object(obj) sys.stdout._write(rv)
python
def dump(obj=missing): """Print the object details to stdout._write (for the interactive console of the web debugger. """ gen = DebugReprGenerator() if obj is missing: rv = gen.dump_locals(sys._getframe(1).f_locals) else: rv = gen.dump_object(obj) sys.stdout._write(rv)
[ "def", "dump", "(", "obj", "=", "missing", ")", ":", "gen", "=", "DebugReprGenerator", "(", ")", "if", "obj", "is", "missing", ":", "rv", "=", "gen", ".", "dump_locals", "(", "sys", ".", "_getframe", "(", "1", ")", ".", "f_locals", ")", "else", ":"...
Print the object details to stdout._write (for the interactive console of the web debugger.
[ "Print", "the", "object", "details", "to", "stdout", ".", "_write", "(", "for", "the", "interactive", "console", "of", "the", "web", "debugger", "." ]
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/debug/repr.py#L55-L64
train
pallets/werkzeug
src/werkzeug/formparser.py
default_stream_factory
def default_stream_factory( total_content_length, filename, content_type, content_length=None ): """The stream factory that is used per default.""" max_size = 1024 * 500 if SpooledTemporaryFile is not None: return SpooledTemporaryFile(max_size=max_size, mode="wb+") if total_content_length is...
python
def default_stream_factory( total_content_length, filename, content_type, content_length=None ): """The stream factory that is used per default.""" max_size = 1024 * 500 if SpooledTemporaryFile is not None: return SpooledTemporaryFile(max_size=max_size, mode="wb+") if total_content_length is...
[ "def", "default_stream_factory", "(", "total_content_length", ",", "filename", ",", "content_type", ",", "content_length", "=", "None", ")", ":", "max_size", "=", "1024", "*", "500", "if", "SpooledTemporaryFile", "is", "not", "None", ":", "return", "SpooledTempora...
The stream factory that is used per default.
[ "The", "stream", "factory", "that", "is", "used", "per", "default", "." ]
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/formparser.py#L52-L61
train
pallets/werkzeug
src/werkzeug/formparser.py
exhaust_stream
def exhaust_stream(f): """Helper decorator for methods that exhausts the stream on return.""" def wrapper(self, stream, *args, **kwargs): try: return f(self, stream, *args, **kwargs) finally: exhaust = getattr(stream, "exhaust", None) if exhaust is not None: ...
python
def exhaust_stream(f): """Helper decorator for methods that exhausts the stream on return.""" def wrapper(self, stream, *args, **kwargs): try: return f(self, stream, *args, **kwargs) finally: exhaust = getattr(stream, "exhaust", None) if exhaust is not None: ...
[ "def", "exhaust_stream", "(", "f", ")", ":", "def", "wrapper", "(", "self", ",", "stream", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "try", ":", "return", "f", "(", "self", ",", "stream", ",", "*", "args", ",", "*", "*", "kwargs", ")...
Helper decorator for methods that exhausts the stream on return.
[ "Helper", "decorator", "for", "methods", "that", "exhausts", "the", "stream", "on", "return", "." ]
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/formparser.py#L125-L141
train
pallets/werkzeug
src/werkzeug/formparser.py
_line_parse
def _line_parse(line): """Removes line ending characters and returns a tuple (`stripped_line`, `is_terminated`). """ if line[-2:] in ["\r\n", b"\r\n"]: return line[:-2], True elif line[-1:] in ["\r", "\n", b"\r", b"\n"]: return line[:-1], True return line, False
python
def _line_parse(line): """Removes line ending characters and returns a tuple (`stripped_line`, `is_terminated`). """ if line[-2:] in ["\r\n", b"\r\n"]: return line[:-2], True elif line[-1:] in ["\r", "\n", b"\r", b"\n"]: return line[:-1], True return line, False
[ "def", "_line_parse", "(", "line", ")", ":", "if", "line", "[", "-", "2", ":", "]", "in", "[", "\"\\r\\n\"", ",", "b\"\\r\\n\"", "]", ":", "return", "line", "[", ":", "-", "2", "]", ",", "True", "elif", "line", "[", "-", "1", ":", "]", "in", ...
Removes line ending characters and returns a tuple (`stripped_line`, `is_terminated`).
[ "Removes", "line", "ending", "characters", "and", "returns", "a", "tuple", "(", "stripped_line", "is_terminated", ")", "." ]
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/formparser.py#L279-L287
train
pallets/werkzeug
src/werkzeug/formparser.py
FormDataParser.parse_from_environ
def parse_from_environ(self, environ): """Parses the information from the environment as form data. :param environ: the WSGI environment to be used for parsing. :return: A tuple in the form ``(stream, form, files)``. """ content_type = environ.get("CONTENT_TYPE", "") con...
python
def parse_from_environ(self, environ): """Parses the information from the environment as form data. :param environ: the WSGI environment to be used for parsing. :return: A tuple in the form ``(stream, form, files)``. """ content_type = environ.get("CONTENT_TYPE", "") con...
[ "def", "parse_from_environ", "(", "self", ",", "environ", ")", ":", "content_type", "=", "environ", ".", "get", "(", "\"CONTENT_TYPE\"", ",", "\"\"", ")", "content_length", "=", "get_content_length", "(", "environ", ")", "mimetype", ",", "options", "=", "parse...
Parses the information from the environment as form data. :param environ: the WSGI environment to be used for parsing. :return: A tuple in the form ``(stream, form, files)``.
[ "Parses", "the", "information", "from", "the", "environment", "as", "form", "data", "." ]
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/formparser.py#L197-L206
train
pallets/werkzeug
src/werkzeug/formparser.py
FormDataParser.parse
def parse(self, stream, mimetype, content_length, options=None): """Parses the information from the given stream, mimetype, content length and mimetype parameters. :param stream: an input stream :param mimetype: the mimetype of the data :param content_length: the content length ...
python
def parse(self, stream, mimetype, content_length, options=None): """Parses the information from the given stream, mimetype, content length and mimetype parameters. :param stream: an input stream :param mimetype: the mimetype of the data :param content_length: the content length ...
[ "def", "parse", "(", "self", ",", "stream", ",", "mimetype", ",", "content_length", ",", "options", "=", "None", ")", ":", "if", "(", "self", ".", "max_content_length", "is", "not", "None", "and", "content_length", "is", "not", "None", "and", "content_leng...
Parses the information from the given stream, mimetype, content length and mimetype parameters. :param stream: an input stream :param mimetype: the mimetype of the data :param content_length: the content length of the incoming data :param options: optional mimetype parameters (u...
[ "Parses", "the", "information", "from", "the", "given", "stream", "mimetype", "content", "length", "and", "mimetype", "parameters", "." ]
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/formparser.py#L208-L236
train
pallets/werkzeug
src/werkzeug/formparser.py
MultiPartParser._find_terminator
def _find_terminator(self, iterator): """The terminator might have some additional newlines before it. There is at least one application that sends additional newlines before headers (the python setuptools package). """ for line in iterator: if not line: ...
python
def _find_terminator(self, iterator): """The terminator might have some additional newlines before it. There is at least one application that sends additional newlines before headers (the python setuptools package). """ for line in iterator: if not line: ...
[ "def", "_find_terminator", "(", "self", ",", "iterator", ")", ":", "for", "line", "in", "iterator", ":", "if", "not", "line", ":", "break", "line", "=", "line", ".", "strip", "(", ")", "if", "line", ":", "return", "line", "return", "b\"\"" ]
The terminator might have some additional newlines before it. There is at least one application that sends additional newlines before headers (the python setuptools package).
[ "The", "terminator", "might", "have", "some", "additional", "newlines", "before", "it", ".", "There", "is", "at", "least", "one", "application", "that", "sends", "additional", "newlines", "before", "headers", "(", "the", "python", "setuptools", "package", ")", ...
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/formparser.py#L362-L373
train
pallets/werkzeug
src/werkzeug/formparser.py
MultiPartParser.parse_lines
def parse_lines(self, file, boundary, content_length, cap_at_buffer=True): """Generate parts of ``('begin_form', (headers, name))`` ``('begin_file', (headers, name, filename))`` ``('cont', bytestring)`` ``('end', None)`` Always obeys the grammar parts = ( begin_f...
python
def parse_lines(self, file, boundary, content_length, cap_at_buffer=True): """Generate parts of ``('begin_form', (headers, name))`` ``('begin_file', (headers, name, filename))`` ``('cont', bytestring)`` ``('end', None)`` Always obeys the grammar parts = ( begin_f...
[ "def", "parse_lines", "(", "self", ",", "file", ",", "boundary", ",", "content_length", ",", "cap_at_buffer", "=", "True", ")", ":", "next_part", "=", "b\"--\"", "+", "boundary", "last_part", "=", "next_part", "+", "b\"--\"", "iterator", "=", "chain", "(", ...
Generate parts of ``('begin_form', (headers, name))`` ``('begin_file', (headers, name, filename))`` ``('cont', bytestring)`` ``('end', None)`` Always obeys the grammar parts = ( begin_form cont* end | begin_file cont* end )*
[ "Generate", "parts", "of", "(", "begin_form", "(", "headers", "name", "))", "(", "begin_file", "(", "headers", "name", "filename", "))", "(", "cont", "bytestring", ")", "(", "end", "None", ")" ]
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/formparser.py#L426-L528
train
pallets/werkzeug
examples/coolmagic/application.py
make_app
def make_app(config=None): """ Factory function that creates a new `CoolmagicApplication` object. Optional WSGI middlewares should be applied here. """ config = config or {} app = CoolMagicApplication(config) # static stuff app = SharedDataMiddleware( app, {"/public": path.join(...
python
def make_app(config=None): """ Factory function that creates a new `CoolmagicApplication` object. Optional WSGI middlewares should be applied here. """ config = config or {} app = CoolMagicApplication(config) # static stuff app = SharedDataMiddleware( app, {"/public": path.join(...
[ "def", "make_app", "(", "config", "=", "None", ")", ":", "config", "=", "config", "or", "{", "}", "app", "=", "CoolMagicApplication", "(", "config", ")", "# static stuff", "app", "=", "SharedDataMiddleware", "(", "app", ",", "{", "\"/public\"", ":", "path"...
Factory function that creates a new `CoolmagicApplication` object. Optional WSGI middlewares should be applied here.
[ "Factory", "function", "that", "creates", "a", "new", "CoolmagicApplication", "object", ".", "Optional", "WSGI", "middlewares", "should", "be", "applied", "here", "." ]
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/examples/coolmagic/application.py#L69-L85
train
pallets/werkzeug
bench/wzbench.py
find_hg_tag
def find_hg_tag(path): """Returns the current node or tag for the given path.""" tags = {} try: client = subprocess.Popen( ["hg", "cat", "-r", "tip", ".hgtags"], stdout=subprocess.PIPE, cwd=path ) for line in client.communicate()[0].splitlines(): line = line.s...
python
def find_hg_tag(path): """Returns the current node or tag for the given path.""" tags = {} try: client = subprocess.Popen( ["hg", "cat", "-r", "tip", ".hgtags"], stdout=subprocess.PIPE, cwd=path ) for line in client.communicate()[0].splitlines(): line = line.s...
[ "def", "find_hg_tag", "(", "path", ")", ":", "tags", "=", "{", "}", "try", ":", "client", "=", "subprocess", ".", "Popen", "(", "[", "\"hg\"", ",", "\"cat\"", ",", "\"-r\"", ",", "\"tip\"", ",", "\".hgtags\"", "]", ",", "stdout", "=", "subprocess", "...
Returns the current node or tag for the given path.
[ "Returns", "the", "current", "node", "or", "tag", "for", "the", "given", "path", "." ]
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/bench/wzbench.py#L48-L72
train
pallets/werkzeug
bench/wzbench.py
load_werkzeug
def load_werkzeug(path): """Load werkzeug.""" sys.path[0] = path # get rid of already imported stuff wz.__dict__.clear() for key in sys.modules.keys(): if key.startswith("werkzeug.") or key == "werkzeug": sys.modules.pop(key, None) # import werkzeug again. import werkze...
python
def load_werkzeug(path): """Load werkzeug.""" sys.path[0] = path # get rid of already imported stuff wz.__dict__.clear() for key in sys.modules.keys(): if key.startswith("werkzeug.") or key == "werkzeug": sys.modules.pop(key, None) # import werkzeug again. import werkze...
[ "def", "load_werkzeug", "(", "path", ")", ":", "sys", ".", "path", "[", "0", "]", "=", "path", "# get rid of already imported stuff", "wz", ".", "__dict__", ".", "clear", "(", ")", "for", "key", "in", "sys", ".", "modules", ".", "keys", "(", ")", ":", ...
Load werkzeug.
[ "Load", "werkzeug", "." ]
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/bench/wzbench.py#L75-L108
train
pallets/werkzeug
bench/wzbench.py
bench
def bench(func): """Times a single function.""" sys.stdout.write("%44s " % format_func(func)) sys.stdout.flush() # figure out how many times we have to run the function to # get reliable timings. for i in xrange(3, 10): rounds = 1 << i t = timer() for _ in xrange(round...
python
def bench(func): """Times a single function.""" sys.stdout.write("%44s " % format_func(func)) sys.stdout.flush() # figure out how many times we have to run the function to # get reliable timings. for i in xrange(3, 10): rounds = 1 << i t = timer() for _ in xrange(round...
[ "def", "bench", "(", "func", ")", ":", "sys", ".", "stdout", ".", "write", "(", "\"%44s \"", "%", "format_func", "(", "func", ")", ")", "sys", ".", "stdout", ".", "flush", "(", ")", "# figure out how many times we have to run the function to", "# get reliable ...
Times a single function.
[ "Times", "a", "single", "function", "." ]
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/bench/wzbench.py#L128-L160
train
pallets/werkzeug
bench/wzbench.py
main
def main(): """The main entrypoint.""" from optparse import OptionParser parser = OptionParser(usage="%prog [options]") parser.add_option( "--werkzeug-path", "-p", dest="path", default="..", help="the path to the werkzeug package. defaults to cwd", ) pars...
python
def main(): """The main entrypoint.""" from optparse import OptionParser parser = OptionParser(usage="%prog [options]") parser.add_option( "--werkzeug-path", "-p", dest="path", default="..", help="the path to the werkzeug package. defaults to cwd", ) pars...
[ "def", "main", "(", ")", ":", "from", "optparse", "import", "OptionParser", "parser", "=", "OptionParser", "(", "usage", "=", "\"%prog [options]\"", ")", "parser", ".", "add_option", "(", "\"--werkzeug-path\"", ",", "\"-p\"", ",", "dest", "=", "\"path\"", ",",...
The main entrypoint.
[ "The", "main", "entrypoint", "." ]
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/bench/wzbench.py#L163-L198
train
pallets/werkzeug
bench/wzbench.py
compare
def compare(node1, node2): """Compares two Werkzeug hg versions.""" if not os.path.isdir("a"): print("error: comparison feature not initialized", file=sys.stderr) sys.exit(4) print("=" * 80) print("WERKZEUG INTERNAL BENCHMARK -- COMPARE MODE".center(80)) print("-" * 80) def _hg...
python
def compare(node1, node2): """Compares two Werkzeug hg versions.""" if not os.path.isdir("a"): print("error: comparison feature not initialized", file=sys.stderr) sys.exit(4) print("=" * 80) print("WERKZEUG INTERNAL BENCHMARK -- COMPARE MODE".center(80)) print("-" * 80) def _hg...
[ "def", "compare", "(", "node1", ",", "node2", ")", ":", "if", "not", "os", ".", "path", ".", "isdir", "(", "\"a\"", ")", ":", "print", "(", "\"error: comparison feature not initialized\"", ",", "file", "=", "sys", ".", "stderr", ")", "sys", ".", "exit", ...
Compares two Werkzeug hg versions.
[ "Compares", "two", "Werkzeug", "hg", "versions", "." ]
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/bench/wzbench.py#L208-L266
train
pallets/werkzeug
src/werkzeug/debug/tbtools.py
Traceback.filter_hidden_frames
def filter_hidden_frames(self): """Remove the frames according to the paste spec.""" for group in self.groups: group.filter_hidden_frames() self.frames[:] = [frame for group in self.groups for frame in group.frames]
python
def filter_hidden_frames(self): """Remove the frames according to the paste spec.""" for group in self.groups: group.filter_hidden_frames() self.frames[:] = [frame for group in self.groups for frame in group.frames]
[ "def", "filter_hidden_frames", "(", "self", ")", ":", "for", "group", "in", "self", ".", "groups", ":", "group", ".", "filter_hidden_frames", "(", ")", "self", ".", "frames", "[", ":", "]", "=", "[", "frame", "for", "group", "in", "self", ".", "groups"...
Remove the frames according to the paste spec.
[ "Remove", "the", "frames", "according", "to", "the", "paste", "spec", "." ]
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/debug/tbtools.py#L260-L265
train
pallets/werkzeug
src/werkzeug/debug/tbtools.py
Traceback.log
def log(self, logfile=None): """Log the ASCII traceback into a file object.""" if logfile is None: logfile = sys.stderr tb = self.plaintext.rstrip() + u"\n" logfile.write(to_native(tb, "utf-8", "replace"))
python
def log(self, logfile=None): """Log the ASCII traceback into a file object.""" if logfile is None: logfile = sys.stderr tb = self.plaintext.rstrip() + u"\n" logfile.write(to_native(tb, "utf-8", "replace"))
[ "def", "log", "(", "self", ",", "logfile", "=", "None", ")", ":", "if", "logfile", "is", "None", ":", "logfile", "=", "sys", ".", "stderr", "tb", "=", "self", ".", "plaintext", ".", "rstrip", "(", ")", "+", "u\"\\n\"", "logfile", ".", "write", "(",...
Log the ASCII traceback into a file object.
[ "Log", "the", "ASCII", "traceback", "into", "a", "file", "object", "." ]
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/debug/tbtools.py#L277-L282
train
pallets/werkzeug
src/werkzeug/debug/tbtools.py
Traceback.paste
def paste(self): """Create a paste and return the paste id.""" data = json.dumps( { "description": "Werkzeug Internal Server Error", "public": False, "files": {"traceback.txt": {"content": self.plaintext}}, } ).encode("utf-8...
python
def paste(self): """Create a paste and return the paste id.""" data = json.dumps( { "description": "Werkzeug Internal Server Error", "public": False, "files": {"traceback.txt": {"content": self.plaintext}}, } ).encode("utf-8...
[ "def", "paste", "(", "self", ")", ":", "data", "=", "json", ".", "dumps", "(", "{", "\"description\"", ":", "\"Werkzeug Internal Server Error\"", ",", "\"public\"", ":", "False", ",", "\"files\"", ":", "{", "\"traceback.txt\"", ":", "{", "\"content\"", ":", ...
Create a paste and return the paste id.
[ "Create", "a", "paste", "and", "return", "the", "paste", "id", "." ]
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/debug/tbtools.py#L284-L300
train
pallets/werkzeug
src/werkzeug/debug/tbtools.py
Traceback.render_summary
def render_summary(self, include_title=True): """Render the traceback for the interactive console.""" title = "" classes = ["traceback"] if not self.frames: classes.append("noframe-traceback") frames = [] else: library_frames = sum(frame.is_lib...
python
def render_summary(self, include_title=True): """Render the traceback for the interactive console.""" title = "" classes = ["traceback"] if not self.frames: classes.append("noframe-traceback") frames = [] else: library_frames = sum(frame.is_lib...
[ "def", "render_summary", "(", "self", ",", "include_title", "=", "True", ")", ":", "title", "=", "\"\"", "classes", "=", "[", "\"traceback\"", "]", "if", "not", "self", ".", "frames", ":", "classes", ".", "append", "(", "\"noframe-traceback\"", ")", "frame...
Render the traceback for the interactive console.
[ "Render", "the", "traceback", "for", "the", "interactive", "console", "." ]
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/debug/tbtools.py#L302-L330
train
pallets/werkzeug
src/werkzeug/debug/tbtools.py
Traceback.render_full
def render_full(self, evalex=False, secret=None, evalex_trusted=True): """Render the Full HTML page with the traceback info.""" exc = escape(self.exception) return PAGE_HTML % { "evalex": "true" if evalex else "false", "evalex_trusted": "true" if evalex_trusted else "fals...
python
def render_full(self, evalex=False, secret=None, evalex_trusted=True): """Render the Full HTML page with the traceback info.""" exc = escape(self.exception) return PAGE_HTML % { "evalex": "true" if evalex else "false", "evalex_trusted": "true" if evalex_trusted else "fals...
[ "def", "render_full", "(", "self", ",", "evalex", "=", "False", ",", "secret", "=", "None", ",", "evalex_trusted", "=", "True", ")", ":", "exc", "=", "escape", "(", "self", ".", "exception", ")", "return", "PAGE_HTML", "%", "{", "\"evalex\"", ":", "\"t...
Render the Full HTML page with the traceback info.
[ "Render", "the", "Full", "HTML", "page", "with", "the", "traceback", "info", "." ]
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/debug/tbtools.py#L332-L347
train
pallets/werkzeug
src/werkzeug/debug/tbtools.py
Group.exception
def exception(self): """String representation of the exception.""" buf = traceback.format_exception_only(self.exc_type, self.exc_value) rv = "".join(buf).strip() return to_unicode(rv, "utf-8", "replace")
python
def exception(self): """String representation of the exception.""" buf = traceback.format_exception_only(self.exc_type, self.exc_value) rv = "".join(buf).strip() return to_unicode(rv, "utf-8", "replace")
[ "def", "exception", "(", "self", ")", ":", "buf", "=", "traceback", ".", "format_exception_only", "(", "self", ".", "exc_type", ",", "self", ".", "exc_value", ")", "rv", "=", "\"\"", ".", "join", "(", "buf", ")", ".", "strip", "(", ")", "return", "to...
String representation of the exception.
[ "String", "representation", "of", "the", "exception", "." ]
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/debug/tbtools.py#L418-L422
train
pallets/werkzeug
src/werkzeug/debug/tbtools.py
Frame.render
def render(self, mark_lib=True): """Render a single frame in a traceback.""" return FRAME_HTML % { "id": self.id, "filename": escape(self.filename), "lineno": self.lineno, "function_name": escape(self.function_name), "lines": self.render_line_c...
python
def render(self, mark_lib=True): """Render a single frame in a traceback.""" return FRAME_HTML % { "id": self.id, "filename": escape(self.filename), "lineno": self.lineno, "function_name": escape(self.function_name), "lines": self.render_line_c...
[ "def", "render", "(", "self", ",", "mark_lib", "=", "True", ")", ":", "return", "FRAME_HTML", "%", "{", "\"id\"", ":", "self", ".", "id", ",", "\"filename\"", ":", "escape", "(", "self", ".", "filename", ")", ",", "\"lineno\"", ":", "self", ".", "lin...
Render a single frame in a traceback.
[ "Render", "a", "single", "frame", "in", "a", "traceback", "." ]
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/debug/tbtools.py#L476-L485
train
pallets/werkzeug
src/werkzeug/debug/tbtools.py
Frame.eval
def eval(self, code, mode="single"): """Evaluate code in the context of the frame.""" if isinstance(code, string_types): if PY2 and isinstance(code, text_type): # noqa code = UTF8_COOKIE + code.encode("utf-8") code = compile(code, "<interactive>", mode) r...
python
def eval(self, code, mode="single"): """Evaluate code in the context of the frame.""" if isinstance(code, string_types): if PY2 and isinstance(code, text_type): # noqa code = UTF8_COOKIE + code.encode("utf-8") code = compile(code, "<interactive>", mode) r...
[ "def", "eval", "(", "self", ",", "code", ",", "mode", "=", "\"single\"", ")", ":", "if", "isinstance", "(", "code", ",", "string_types", ")", ":", "if", "PY2", "and", "isinstance", "(", "code", ",", "text_type", ")", ":", "# noqa", "code", "=", "UTF8...
Evaluate code in the context of the frame.
[ "Evaluate", "code", "in", "the", "context", "of", "the", "frame", "." ]
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/debug/tbtools.py#L548-L554
train
pallets/werkzeug
src/werkzeug/wrappers/base_request.py
BaseRequest.application
def application(cls, f): """Decorate a function as responder that accepts the request as first argument. This works like the :func:`responder` decorator but the function is passed the request object as first argument and the request object will be closed automatically:: @Re...
python
def application(cls, f): """Decorate a function as responder that accepts the request as first argument. This works like the :func:`responder` decorator but the function is passed the request object as first argument and the request object will be closed automatically:: @Re...
[ "def", "application", "(", "cls", ",", "f", ")", ":", "#: return a callable that wraps the -2nd argument with the request", "#: and calls the function with all the arguments up to that one and", "#: the request. The return value is then called with the latest", "#: two arguments. This makes ...
Decorate a function as responder that accepts the request as first argument. This works like the :func:`responder` decorator but the function is passed the request object as first argument and the request object will be closed automatically:: @Request.application def my...
[ "Decorate", "a", "function", "as", "responder", "that", "accepts", "the", "request", "as", "first", "argument", ".", "This", "works", "like", "the", ":", "func", ":", "responder", "decorator", "but", "the", "function", "is", "passed", "the", "request", "obje...
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/wrappers/base_request.py#L207-L239
train