partition stringclasses 3
values | func_name stringlengths 1 134 | docstring stringlengths 1 46.9k | path stringlengths 4 223 | original_string stringlengths 75 104k | code stringlengths 75 104k | docstring_tokens listlengths 1 1.97k | repo stringlengths 7 55 | language stringclasses 1
value | url stringlengths 87 315 | code_tokens listlengths 19 28.4k | sha stringlengths 40 40 |
|---|---|---|---|---|---|---|---|---|---|---|---|
train | BaseURL.port | The port in the URL as an integer if it was present, `None`
otherwise. This does not fill in default ports. | src/werkzeug/urls.py | 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):
"""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... | [
"The",
"port",
"in",
"the",
"URL",
"as",
"an",
"integer",
"if",
"it",
"was",
"present",
"None",
"otherwise",
".",
"This",
"does",
"not",
"fill",
"in",
"default",
"ports",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/urls.py#L96-L105 | [
"def",
"port",
"(",
"self",
")",
":",
"try",
":",
"rv",
"=",
"int",
"(",
"to_native",
"(",
"self",
".",
"_split_host",
"(",
")",
"[",
"1",
"]",
")",
")",
"if",
"0",
"<=",
"rv",
"<=",
"65535",
":",
"return",
"rv",
"except",
"(",
"ValueError",
",... | a220671d66755a94630a212378754bb432811158 |
train | BaseURL.get_file_location | 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... | src/werkzeug/urls.py | 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):
"""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
... | [
"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... | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/urls.py#L210-L268 | [
"def",
"get_file_location",
"(",
"self",
",",
"pathformat",
"=",
"None",
")",
":",
"if",
"self",
".",
"scheme",
"!=",
"\"file\"",
":",
"return",
"None",
",",
"None",
"path",
"=",
"url_unquote",
"(",
"self",
".",
"path",
")",
"host",
"=",
"self",
".",
... | a220671d66755a94630a212378754bb432811158 |
train | generate_template | Load and generate a template. | examples/simplewiki/utils.py | 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):
"""Load and generate a template."""
context.update(href=href, format_datetime=format_datetime)
return template_loader.load(template_name).generate(**context) | [
"Load",
"and",
"generate",
"a",
"template",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/examples/simplewiki/utils.py#L54-L57 | [
"def",
"generate_template",
"(",
"template_name",
",",
"*",
"*",
"context",
")",
":",
"context",
".",
"update",
"(",
"href",
"=",
"href",
",",
"format_datetime",
"=",
"format_datetime",
")",
"return",
"template_loader",
".",
"load",
"(",
"template_name",
")",
... | a220671d66755a94630a212378754bb432811158 |
train | href | Simple function for URL generation. Position arguments are used for the
URL path and keyword arguments are used for the url parameters. | examples/simplewiki/utils.py | 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):
"""
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... | [
"Simple",
"function",
"for",
"URL",
"generation",
".",
"Position",
"arguments",
"are",
"used",
"for",
"the",
"URL",
"path",
"and",
"keyword",
"arguments",
"are",
"used",
"for",
"the",
"url",
"parameters",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/examples/simplewiki/utils.py#L65-L75 | [
"def",
"href",
"(",
"*",
"args",
",",
"*",
"*",
"kw",
")",
":",
"result",
"=",
"[",
"(",
"request",
".",
"script_root",
"if",
"request",
"else",
"\"\"",
")",
"+",
"\"/\"",
"]",
"for",
"idx",
",",
"arg",
"in",
"enumerate",
"(",
"args",
")",
":",
... | a220671d66755a94630a212378754bb432811158 |
train | parse_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: | src/werkzeug/routing.py | 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):
"""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... | [
"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... | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/routing.py#L202-L231 | [
"def",
"parse_rule",
"(",
"rule",
")",
":",
"pos",
"=",
"0",
"end",
"=",
"len",
"(",
"rule",
")",
"do_match",
"=",
"_rule_re",
".",
"match",
"used_names",
"=",
"set",
"(",
")",
"while",
"pos",
"<",
"end",
":",
"m",
"=",
"do_match",
"(",
"rule",
"... | a220671d66755a94630a212378754bb432811158 |
train | Map.is_endpoint_expecting | 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... | src/werkzeug/routing.py | 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):
"""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... | [
"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... | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/routing.py#L1523-L1541 | [
"def",
"is_endpoint_expecting",
"(",
"self",
",",
"endpoint",
",",
"*",
"arguments",
")",
":",
"self",
".",
"update",
"(",
")",
"arguments",
"=",
"set",
"(",
"arguments",
")",
"for",
"rule",
"in",
"self",
".",
"_rules_by_endpoint",
"[",
"endpoint",
"]",
... | a220671d66755a94630a212378754bb432811158 |
train | Map.iter_rules | 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 | src/werkzeug/routing.py | 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):
"""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... | [
"Iterate",
"over",
"all",
"rules",
"or",
"the",
"rules",
"of",
"an",
"endpoint",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/routing.py#L1543-L1553 | [
"def",
"iter_rules",
"(",
"self",
",",
"endpoint",
"=",
"None",
")",
":",
"self",
".",
"update",
"(",
")",
"if",
"endpoint",
"is",
"not",
"None",
":",
"return",
"iter",
"(",
"self",
".",
"_rules_by_endpoint",
"[",
"endpoint",
"]",
")",
"return",
"iter"... | a220671d66755a94630a212378754bb432811158 |
train | Map.add | 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` | src/werkzeug/routing.py | 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):
"""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)
... | [
"Add",
"a",
"new",
"rule",
"or",
"factory",
"to",
"the",
"map",
"and",
"bind",
"it",
".",
"Requires",
"that",
"the",
"rule",
"is",
"not",
"bound",
"to",
"another",
"map",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/routing.py#L1555-L1565 | [
"def",
"add",
"(",
"self",
",",
"rulefactory",
")",
":",
"for",
"rule",
"in",
"rulefactory",
".",
"get_rules",
"(",
"self",
")",
":",
"rule",
".",
"bind",
"(",
"self",
")",
"self",
".",
"_rules",
".",
"append",
"(",
"rule",
")",
"self",
".",
"_rule... | a220671d66755a94630a212378754bb432811158 |
train | Map.bind | 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... | src/werkzeug/routing.py | 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_n... | [
"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... | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/routing.py#L1567-L1625 | [
"def",
"bind",
"(",
"self",
",",
"server_name",
",",
"script_name",
"=",
"None",
",",
"subdomain",
"=",
"None",
",",
"url_scheme",
"=",
"\"http\"",
",",
"default_method",
"=",
"\"GET\"",
",",
"path_info",
"=",
"None",
",",
"query_args",
"=",
"None",
",",
... | a220671d66755a94630a212378754bb432811158 |
train | Map.bind_to_environ | 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... | src/werkzeug/routing.py | 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):
"""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... | [
"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"... | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/routing.py#L1627-L1701 | [
"def",
"bind_to_environ",
"(",
"self",
",",
"environ",
",",
"server_name",
"=",
"None",
",",
"subdomain",
"=",
"None",
")",
":",
"environ",
"=",
"_get_environ",
"(",
"environ",
")",
"wsgi_server_name",
"=",
"get_host",
"(",
"environ",
")",
".",
"lower",
"(... | a220671d66755a94630a212378754bb432811158 |
train | Map.update | Called before matching and building to keep the compiled rules
in the correct order after things changed. | src/werkzeug/routing.py | 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):
"""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... | [
"Called",
"before",
"matching",
"and",
"building",
"to",
"keep",
"the",
"compiled",
"rules",
"in",
"the",
"correct",
"order",
"after",
"things",
"changed",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/routing.py#L1703-L1717 | [
"def",
"update",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"_remap",
":",
"return",
"with",
"self",
".",
"_remap_lock",
":",
"if",
"not",
"self",
".",
"_remap",
":",
"return",
"self",
".",
"_rules",
".",
"sort",
"(",
"key",
"=",
"lambda",
"x... | a220671d66755a94630a212378754bb432811158 |
train | MapAdapter.dispatch | 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... | src/werkzeug/routing.py | 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
):
"""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 ... | [
"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",... | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/routing.py#L1753-L1807 | [
"def",
"dispatch",
"(",
"self",
",",
"view_func",
",",
"path_info",
"=",
"None",
",",
"method",
"=",
"None",
",",
"catch_http_exceptions",
"=",
"False",
")",
":",
"try",
":",
"try",
":",
"endpoint",
",",
"args",
"=",
"self",
".",
"match",
"(",
"path_in... | a220671d66755a94630a212378754bb432811158 |
train | MapAdapter.allowed_methods | Returns the valid methods that match for a given path.
.. versionadded:: 0.7 | src/werkzeug/routing.py | 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):
"""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:
... | [
"Returns",
"the",
"valid",
"methods",
"that",
"match",
"for",
"a",
"given",
"path",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/routing.py#L1979-L1990 | [
"def",
"allowed_methods",
"(",
"self",
",",
"path_info",
"=",
"None",
")",
":",
"try",
":",
"self",
".",
"match",
"(",
"path_info",
",",
"method",
"=",
"\"--\"",
")",
"except",
"MethodNotAllowed",
"as",
"e",
":",
"return",
"e",
".",
"valid_methods",
"exc... | a220671d66755a94630a212378754bb432811158 |
train | MapAdapter.get_host | 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. | src/werkzeug/routing.py | 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):
"""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... | [
"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",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/routing.py#L1992-L2006 | [
"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\"",
"... | a220671d66755a94630a212378754bb432811158 |
train | MapAdapter.get_default_redirect | A helper that returns the URL to redirect to if it finds one.
This is used for default redirecting only.
:internal: | src/werkzeug/routing.py | 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):
"""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... | [
"A",
"helper",
"that",
"returns",
"the",
"URL",
"to",
"redirect",
"to",
"if",
"it",
"finds",
"one",
".",
"This",
"is",
"used",
"for",
"default",
"redirecting",
"only",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/routing.py#L2008-L2024 | [
"def",
"get_default_redirect",
"(",
"self",
",",
"rule",
",",
"method",
",",
"values",
",",
"query_args",
")",
":",
"assert",
"self",
".",
"map",
".",
"redirect_defaults",
"for",
"r",
"in",
"self",
".",
"map",
".",
"_rules_by_endpoint",
"[",
"rule",
".",
... | a220671d66755a94630a212378754bb432811158 |
train | MapAdapter.make_redirect_url | Creates a redirect URL.
:internal: | src/werkzeug/routing.py | 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):
"""Creates a redirect URL.
:internal:
"""
suffix = ""
if query_args:
suffix = "?" + self.encode_query_args(query_args)
return str(
"%s://%s/%s%s"
% (
... | [
"Creates",
"a",
"redirect",
"URL",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/routing.py#L2031-L2049 | [
"def",
"make_redirect_url",
"(",
"self",
",",
"path_info",
",",
"query_args",
"=",
"None",
",",
"domain_part",
"=",
"None",
")",
":",
"suffix",
"=",
"\"\"",
"if",
"query_args",
":",
"suffix",
"=",
"\"?\"",
"+",
"self",
".",
"encode_query_args",
"(",
"query... | a220671d66755a94630a212378754bb432811158 |
train | MapAdapter._partial_build | Helper for :meth:`build`. Returns subdomain and path for the
rule that accepts this endpoint, values and method.
:internal: | src/werkzeug/routing.py | 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):
"""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... | [
"Helper",
"for",
":",
"meth",
":",
"build",
".",
"Returns",
"subdomain",
"and",
"path",
"for",
"the",
"rule",
"that",
"accepts",
"this",
"endpoint",
"values",
"and",
"method",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/routing.py#L2061-L2081 | [
"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",
"(",... | a220671d66755a94630a212378754bb432811158 |
train | MapAdapter.build | 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.... | src/werkzeug/routing.py | 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,
):
"""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... | [
"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",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/routing.py#L2083-L2200 | [
"def",
"build",
"(",
"self",
",",
"endpoint",
",",
"values",
"=",
"None",
",",
"method",
"=",
"None",
",",
"force_external",
"=",
"False",
",",
"append_unknown",
"=",
"True",
",",
")",
":",
"self",
".",
"map",
".",
"update",
"(",
")",
"if",
"values",... | a220671d66755a94630a212378754bb432811158 |
train | export | Decorator for registering view functions and adding
templates to it. | examples/coolmagic/utils.py | 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):
"""
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 ... | [
"Decorator",
"for",
"registering",
"view",
"functions",
"and",
"adding",
"templates",
"to",
"it",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/examples/coolmagic/utils.py#L33-L55 | [
"def",
"export",
"(",
"string",
",",
"template",
"=",
"None",
",",
"*",
"*",
"extra",
")",
":",
"def",
"wrapped",
"(",
"f",
")",
":",
"endpoint",
"=",
"(",
"f",
".",
"__module__",
"+",
"\".\"",
"+",
"f",
".",
"__name__",
")",
"[",
"16",
":",
"]... | a220671d66755a94630a212378754bb432811158 |
train | LocalStack.push | Pushes a new item to the stack | src/werkzeug/local.py | 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):
"""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 | [
"Pushes",
"a",
"new",
"item",
"to",
"the",
"stack"
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/local.py#L142-L148 | [
"def",
"push",
"(",
"self",
",",
"obj",
")",
":",
"rv",
"=",
"getattr",
"(",
"self",
".",
"_local",
",",
"\"stack\"",
",",
"None",
")",
"if",
"rv",
"is",
"None",
":",
"self",
".",
"_local",
".",
"stack",
"=",
"rv",
"=",
"[",
"]",
"rv",
".",
"... | a220671d66755a94630a212378754bb432811158 |
train | LocalStack.pop | Removes the topmost item from the stack, will return the
old value or `None` if the stack was already empty. | src/werkzeug/local.py | 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):
"""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... | [
"Removes",
"the",
"topmost",
"item",
"from",
"the",
"stack",
"will",
"return",
"the",
"old",
"value",
"or",
"None",
"if",
"the",
"stack",
"was",
"already",
"empty",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/local.py#L150-L161 | [
"def",
"pop",
"(",
"self",
")",
":",
"stack",
"=",
"getattr",
"(",
"self",
".",
"_local",
",",
"\"stack\"",
",",
"None",
")",
"if",
"stack",
"is",
"None",
":",
"return",
"None",
"elif",
"len",
"(",
"stack",
")",
"==",
"1",
":",
"release_local",
"("... | a220671d66755a94630a212378754bb432811158 |
train | LocalManager.make_middleware | Wrap a WSGI application so that cleaning up happens after
request end. | src/werkzeug/local.py | 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):
"""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 | [
"Wrap",
"a",
"WSGI",
"application",
"so",
"that",
"cleaning",
"up",
"happens",
"after",
"request",
"end",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/local.py#L225-L233 | [
"def",
"make_middleware",
"(",
"self",
",",
"app",
")",
":",
"def",
"application",
"(",
"environ",
",",
"start_response",
")",
":",
"return",
"ClosingIterator",
"(",
"app",
"(",
"environ",
",",
"start_response",
")",
",",
"self",
".",
"cleanup",
")",
"retu... | a220671d66755a94630a212378754bb432811158 |
train | ETagResponseMixin._wrap_response | Wrap existing Response in case of Range Request context. | src/werkzeug/wrappers/etag.py | 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):
"""Wrap existing Response in case of Range Request context."""
if self.status_code == 206:
self.response = _RangeWrapper(self.response, start, length) | [
"Wrap",
"existing",
"Response",
"in",
"case",
"of",
"Range",
"Request",
"context",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/wrappers/etag.py#L112-L115 | [
"def",
"_wrap_response",
"(",
"self",
",",
"start",
",",
"length",
")",
":",
"if",
"self",
".",
"status_code",
"==",
"206",
":",
"self",
".",
"response",
"=",
"_RangeWrapper",
"(",
"self",
".",
"response",
",",
"start",
",",
"length",
")"
] | a220671d66755a94630a212378754bb432811158 |
train | ETagResponseMixin._is_range_request_processable | Return ``True`` if `Range` header is present and if underlying
resource is considered unchanged when compared with `If-Range` header. | src/werkzeug/wrappers/etag.py | 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 ``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(
... | [
"Return",
"True",
"if",
"Range",
"header",
"is",
"present",
"and",
"if",
"underlying",
"resource",
"is",
"considered",
"unchanged",
"when",
"compared",
"with",
"If",
"-",
"Range",
"header",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/wrappers/etag.py#L117-L130 | [
"def",
"_is_range_request_processable",
"(",
"self",
",",
"environ",
")",
":",
"return",
"(",
"\"HTTP_IF_RANGE\"",
"not",
"in",
"environ",
"or",
"not",
"is_resource_modified",
"(",
"environ",
",",
"self",
".",
"headers",
".",
"get",
"(",
"\"etag\"",
")",
",",
... | a220671d66755a94630a212378754bb432811158 |
train | ETagResponseMixin._process_range_request | 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.... | src/werkzeug/wrappers/etag.py | 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):
"""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
... | [
"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... | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/wrappers/etag.py#L132-L166 | [
"def",
"_process_range_request",
"(",
"self",
",",
"environ",
",",
"complete_length",
"=",
"None",
",",
"accept_ranges",
"=",
"None",
")",
":",
"from",
".",
".",
"exceptions",
"import",
"RequestedRangeNotSatisfiable",
"if",
"accept_ranges",
"is",
"None",
":",
"r... | a220671d66755a94630a212378754bb432811158 |
train | ETagResponseMixin.make_conditional | 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... | src/werkzeug/wrappers/etag.py | 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
):
"""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... | [
"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",
... | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/wrappers/etag.py#L168-L234 | [
"def",
"make_conditional",
"(",
"self",
",",
"request_or_environ",
",",
"accept_ranges",
"=",
"False",
",",
"complete_length",
"=",
"None",
")",
":",
"environ",
"=",
"_get_environ",
"(",
"request_or_environ",
")",
"if",
"environ",
"[",
"\"REQUEST_METHOD\"",
"]",
... | a220671d66755a94630a212378754bb432811158 |
train | ETagResponseMixin.add_etag | Add an etag for the current response if there is none yet. | src/werkzeug/wrappers/etag.py | 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):
"""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) | [
"Add",
"an",
"etag",
"for",
"the",
"current",
"response",
"if",
"there",
"is",
"none",
"yet",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/wrappers/etag.py#L236-L239 | [
"def",
"add_etag",
"(",
"self",
",",
"overwrite",
"=",
"False",
",",
"weak",
"=",
"False",
")",
":",
"if",
"overwrite",
"or",
"\"etag\"",
"not",
"in",
"self",
".",
"headers",
":",
"self",
".",
"set_etag",
"(",
"generate_etag",
"(",
"self",
".",
"get_da... | a220671d66755a94630a212378754bb432811158 |
train | ETagResponseMixin.set_etag | Set the etag, and override the old one if there was one. | src/werkzeug/wrappers/etag.py | 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):
"""Set the etag, and override the old one if there was one."""
self.headers["ETag"] = quote_etag(etag, weak) | [
"Set",
"the",
"etag",
"and",
"override",
"the",
"old",
"one",
"if",
"there",
"was",
"one",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/wrappers/etag.py#L241-L243 | [
"def",
"set_etag",
"(",
"self",
",",
"etag",
",",
"weak",
"=",
"False",
")",
":",
"self",
".",
"headers",
"[",
"\"ETag\"",
"]",
"=",
"quote_etag",
"(",
"etag",
",",
"weak",
")"
] | a220671d66755a94630a212378754bb432811158 |
train | ETagResponseMixin.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`. | src/werkzeug/wrappers/etag.py | 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):
"""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... | [
"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",... | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/wrappers/etag.py#L251-L258 | [
"def",
"freeze",
"(",
"self",
",",
"no_etag",
"=",
"False",
")",
":",
"if",
"not",
"no_etag",
":",
"self",
".",
"add_etag",
"(",
")",
"super",
"(",
"ETagResponseMixin",
",",
"self",
")",
".",
"freeze",
"(",
")"
] | a220671d66755a94630a212378754bb432811158 |
train | get_host | 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... | src/werkzeug/wsgi.py | 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):
"""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.
... | [
"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",
... | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/wsgi.py#L145-L179 | [
"def",
"get_host",
"(",
"environ",
",",
"trusted_hosts",
"=",
"None",
")",
":",
"if",
"\"HTTP_HOST\"",
"in",
"environ",
":",
"rv",
"=",
"environ",
"[",
"\"HTTP_HOST\"",
"]",
"if",
"environ",
"[",
"\"wsgi.url_scheme\"",
"]",
"==",
"\"http\"",
"and",
"rv",
"... | a220671d66755a94630a212378754bb432811158 |
train | get_query_string | 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... | src/werkzeug/wsgi.py | 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):
"""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... | [
"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",
"... | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/wsgi.py#L238-L252 | [
"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... | a220671d66755a94630a212378754bb432811158 |
train | 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 environment. The URLs might also be IRIs.
If the path info could not be determined, `None` is returned.
Some examples:
>>> extract_path_info... | src/werkzeug/wsgi.py | 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,
):
"""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... | [
"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... | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/wsgi.py#L369-L462 | [
"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... | a220671d66755a94630a212378754bb432811158 |
train | make_line_iter | 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 ... | src/werkzeug/wsgi.py | 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):
"""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... | [
"Safely",
"iterates",
"line",
"-",
"based",
"over",
"an",
"input",
"stream",
".",
"If",
"the",
"input",
"stream",
"is",
"not",
"a",
":",
"class",
":",
"LimitedStream",
"the",
"limit",
"parameter",
"is",
"mandatory",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/wsgi.py#L687-L769 | [
"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... | a220671d66755a94630a212378754bb432811158 |
train | make_chunk_iter | 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... | src/werkzeug/wsgi.py | 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
):
"""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... | [
"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... | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/wsgi.py#L772-L842 | [
"def",
"make_chunk_iter",
"(",
"stream",
",",
"separator",
",",
"limit",
"=",
"None",
",",
"buffer_size",
"=",
"10",
"*",
"1024",
",",
"cap_at_buffer",
"=",
"False",
")",
":",
"_iter",
"=",
"_make_chunk_iter",
"(",
"stream",
",",
"limit",
",",
"buffer_size... | a220671d66755a94630a212378754bb432811158 |
train | _is_ascii_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. | src/werkzeug/filesystem.py | 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):
"""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:
... | [
"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",
... | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/filesystem.py#L21-L31 | [
"def",
"_is_ascii_encoding",
"(",
"encoding",
")",
":",
"if",
"encoding",
"is",
"None",
":",
"return",
"False",
"try",
":",
"return",
"codecs",
".",
"lookup",
"(",
"encoding",
")",
".",
"name",
"==",
"\"ascii\"",
"except",
"LookupError",
":",
"return",
"Fa... | a220671d66755a94630a212378754bb432811158 |
train | 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:`filesystem-encoding` for the exact
behavior... | src/werkzeug/filesystem.py | 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():
"""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... | [
"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",
... | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/filesystem.py#L42-L64 | [
"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",
")",
":",
... | a220671d66755a94630a212378754bb432811158 |
train | _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. | src/werkzeug/_reloader.py | 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():
"""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... | [
"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... | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/_reloader.py#L14-L40 | [
"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... | a220671d66755a94630a212378754bb432811158 |
train | _find_observable_paths | Finds all paths that should be observed. | src/werkzeug/_reloader.py | 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):
"""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... | [
"Finds",
"all",
"paths",
"that",
"should",
"be",
"observed",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/_reloader.py#L43-L60 | [
"def",
"_find_observable_paths",
"(",
"extra_files",
"=",
"None",
")",
":",
"rv",
"=",
"set",
"(",
"os",
".",
"path",
".",
"dirname",
"(",
"os",
".",
"path",
".",
"abspath",
"(",
"x",
")",
")",
"if",
"os",
".",
"path",
".",
"isfile",
"(",
"x",
")... | a220671d66755a94630a212378754bb432811158 |
train | _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 program other than python) | src/werkzeug/_reloader.py | 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():
"""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... | [
"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",
... | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/_reloader.py#L63-L113 | [
"def",
"_get_args_for_reloading",
"(",
")",
":",
"rv",
"=",
"[",
"sys",
".",
"executable",
"]",
"py_script",
"=",
"os",
".",
"path",
".",
"abspath",
"(",
"sys",
".",
"argv",
"[",
"0",
"]",
")",
"args",
"=",
"sys",
".",
"argv",
"[",
"1",
":",
"]",... | a220671d66755a94630a212378754bb432811158 |
train | _find_common_roots | Out of some paths it finds the common roots that need monitoring. | src/werkzeug/_reloader.py | 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):
"""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, {}... | [
"Out",
"of",
"some",
"paths",
"it",
"finds",
"the",
"common",
"roots",
"that",
"need",
"monitoring",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/_reloader.py#L116-L135 | [
"def",
"_find_common_roots",
"(",
"paths",
")",
":",
"paths",
"=",
"[",
"x",
".",
"split",
"(",
"os",
".",
"path",
".",
"sep",
")",
"for",
"x",
"in",
"paths",
"]",
"root",
"=",
"{",
"}",
"for",
"chunks",
"in",
"sorted",
"(",
"paths",
",",
"key",
... | a220671d66755a94630a212378754bb432811158 |
train | ensure_echo_on | Ensure that echo mode is enabled. Some tools such as PDB disable
it which causes usability issues after reload. | src/werkzeug/_reloader.py | 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():
"""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... | [
"Ensure",
"that",
"echo",
"mode",
"is",
"enabled",
".",
"Some",
"tools",
"such",
"as",
"PDB",
"disable",
"it",
"which",
"causes",
"usability",
"issues",
"after",
"reload",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/_reloader.py#L302-L315 | [
"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",... | a220671d66755a94630a212378754bb432811158 |
train | run_with_reloader | Run the given function in an independent python interpreter. | src/werkzeug/_reloader.py | 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"):
"""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:
... | [
"Run",
"the",
"given",
"function",
"in",
"an",
"independent",
"python",
"interpreter",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/_reloader.py#L318-L334 | [
"def",
"run_with_reloader",
"(",
"main_func",
",",
"extra_files",
"=",
"None",
",",
"interval",
"=",
"1",
",",
"reloader_type",
"=",
"\"auto\"",
")",
":",
"import",
"signal",
"reloader",
"=",
"reloader_loops",
"[",
"reloader_type",
"]",
"(",
"extra_files",
","... | a220671d66755a94630a212378754bb432811158 |
train | ReloaderLoop.restart_with_reloader | Spawn a new Python interpreter with the same arguments as this one,
but running the reloader thread. | src/werkzeug/_reloader.py | 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):
"""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... | [
"Spawn",
"a",
"new",
"Python",
"interpreter",
"with",
"the",
"same",
"arguments",
"as",
"this",
"one",
"but",
"running",
"the",
"reloader",
"thread",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/_reloader.py#L153-L178 | [
"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... | a220671d66755a94630a212378754bb432811158 |
train | SimpleWiki.dispatch_request | Dispatch an incoming request. | examples/simplewiki/application.py | 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):
"""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... | [
"Dispatch",
"an",
"incoming",
"request",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/examples/simplewiki/application.py#L64-L100 | [
"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... | a220671d66755a94630a212378754bb432811158 |
train | get_content_type | 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... | src/werkzeug/utils.py | 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):
"""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... | [
"Returns",
"the",
"full",
"content",
"type",
"string",
"with",
"charset",
"for",
"a",
"mimetype",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/utils.py#L291-L313 | [
"def",
"get_content_type",
"(",
"mimetype",
",",
"charset",
")",
":",
"if",
"(",
"mimetype",
".",
"startswith",
"(",
"\"text/\"",
")",
"or",
"mimetype",
"in",
"_charset_mimetypes",
"or",
"mimetype",
".",
"endswith",
"(",
"\"+xml\"",
")",
")",
":",
"mimetype"... | a220671d66755a94630a212378754bb432811158 |
train | detect_utf_encoding | 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... | src/werkzeug/utils.py | 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):
"""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... | [
"Detect",
"which",
"UTF",
"encoding",
"was",
"used",
"to",
"encode",
"the",
"given",
"bytes",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/utils.py#L316-L360 | [
"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",
"... | a220671d66755a94630a212378754bb432811158 |
train | format_string | 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... | src/werkzeug/utils.py | 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):
"""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... | [
"String",
"-",
"template",
"format",
"a",
"string",
":"
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/utils.py#L363-L382 | [
"def",
"format_string",
"(",
"string",
",",
"context",
")",
":",
"def",
"lookup_arg",
"(",
"match",
")",
":",
"x",
"=",
"context",
"[",
"match",
".",
"group",
"(",
"1",
")",
"or",
"match",
".",
"group",
"(",
"2",
")",
"]",
"if",
"not",
"isinstance"... | a220671d66755a94630a212378754bb432811158 |
train | secure_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 function also makes sure that the file i... | src/werkzeug/utils.py | 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):
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... | [
"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",
":",
... | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/utils.py#L385-L432 | [
"def",
"secure_filename",
"(",
"filename",
")",
":",
"if",
"isinstance",
"(",
"filename",
",",
"text_type",
")",
":",
"from",
"unicodedata",
"import",
"normalize",
"filename",
"=",
"normalize",
"(",
"\"NFKD\"",
",",
"filename",
")",
".",
"encode",
"(",
"\"as... | a220671d66755a94630a212378754bb432811158 |
train | escape | 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. | src/werkzeug/utils.py | 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):
"""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 ... | [
"Replace",
"special",
"characters",
"&",
"<",
">",
"and",
"(",
")",
"to",
"HTML",
"-",
"safe",
"sequences",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/utils.py#L435-L459 | [
"def",
"escape",
"(",
"s",
")",
":",
"if",
"s",
"is",
"None",
":",
"return",
"\"\"",
"elif",
"hasattr",
"(",
"s",
",",
"\"__html__\"",
")",
":",
"return",
"text_type",
"(",
"s",
".",
"__html__",
"(",
")",
")",
"if",
"not",
"isinstance",
"(",
"s",
... | a220671d66755a94630a212378754bb432811158 |
train | find_modules | 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... | src/werkzeug/utils.py | 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):
"""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... | [
"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... | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/utils.py#L584-L613 | [
"def",
"find_modules",
"(",
"import_path",
",",
"include_packages",
"=",
"False",
",",
"recursive",
"=",
"False",
")",
":",
"module",
"=",
"import_string",
"(",
"import_path",
")",
"path",
"=",
"getattr",
"(",
"module",
",",
"\"__path__\"",
",",
"None",
")",... | a220671d66755a94630a212378754bb432811158 |
train | validate_arguments | 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... | src/werkzeug/utils.py | 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):
"""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... | [
"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",
"... | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/utils.py#L616-L666 | [
"def",
"validate_arguments",
"(",
"func",
",",
"args",
",",
"kwargs",
",",
"drop_extra",
"=",
"True",
")",
":",
"parser",
"=",
"_parse_signature",
"(",
"func",
")",
"args",
",",
"kwargs",
",",
"missing",
",",
"extra",
",",
"extra_positional",
"=",
"parser"... | a220671d66755a94630a212378754bb432811158 |
train | bind_arguments | 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... | src/werkzeug/utils.py | 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):
"""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... | [
"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... | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/utils.py#L669-L707 | [
"def",
"bind_arguments",
"(",
"func",
",",
"args",
",",
"kwargs",
")",
":",
"(",
"args",
",",
"kwargs",
",",
"missing",
",",
"extra",
",",
"extra_positional",
",",
"arg_spec",
",",
"vararg_var",
",",
"kwarg_var",
",",
")",
"=",
"_parse_signature",
"(",
"... | a220671d66755a94630a212378754bb432811158 |
train | index | Show the index page or any an offset of it. | examples/plnt/views.py | 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):
"""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]... | [
"Show",
"the",
"index",
"page",
"or",
"any",
"an",
"offset",
"of",
"it",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/examples/plnt/views.py#L25-L37 | [
"def",
"index",
"(",
"request",
",",
"page",
")",
":",
"days",
"=",
"[",
"]",
"days_found",
"=",
"set",
"(",
")",
"query",
"=",
"Entry",
".",
"query",
".",
"order_by",
"(",
"Entry",
".",
"pub_date",
".",
"desc",
"(",
")",
")",
"pagination",
"=",
... | a220671d66755a94630a212378754bb432811158 |
train | dump | Print the object details to stdout._write (for the interactive
console of the web debugger. | src/werkzeug/debug/repr.py | 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):
"""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) | [
"Print",
"the",
"object",
"details",
"to",
"stdout",
".",
"_write",
"(",
"for",
"the",
"interactive",
"console",
"of",
"the",
"web",
"debugger",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/debug/repr.py#L55-L64 | [
"def",
"dump",
"(",
"obj",
"=",
"missing",
")",
":",
"gen",
"=",
"DebugReprGenerator",
"(",
")",
"if",
"obj",
"is",
"missing",
":",
"rv",
"=",
"gen",
".",
"dump_locals",
"(",
"sys",
".",
"_getframe",
"(",
"1",
")",
".",
"f_locals",
")",
"else",
":"... | a220671d66755a94630a212378754bb432811158 |
train | default_stream_factory | The stream factory that is used per default. | src/werkzeug/formparser.py | 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
):
"""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... | [
"The",
"stream",
"factory",
"that",
"is",
"used",
"per",
"default",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/formparser.py#L52-L61 | [
"def",
"default_stream_factory",
"(",
"total_content_length",
",",
"filename",
",",
"content_type",
",",
"content_length",
"=",
"None",
")",
":",
"max_size",
"=",
"1024",
"*",
"500",
"if",
"SpooledTemporaryFile",
"is",
"not",
"None",
":",
"return",
"SpooledTempora... | a220671d66755a94630a212378754bb432811158 |
train | exhaust_stream | Helper decorator for methods that exhausts the stream on return. | src/werkzeug/formparser.py | 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):
"""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:
... | [
"Helper",
"decorator",
"for",
"methods",
"that",
"exhausts",
"the",
"stream",
"on",
"return",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/formparser.py#L125-L141 | [
"def",
"exhaust_stream",
"(",
"f",
")",
":",
"def",
"wrapper",
"(",
"self",
",",
"stream",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"try",
":",
"return",
"f",
"(",
"self",
",",
"stream",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")... | a220671d66755a94630a212378754bb432811158 |
train | _line_parse | Removes line ending characters and returns a tuple (`stripped_line`,
`is_terminated`). | src/werkzeug/formparser.py | 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):
"""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 | [
"Removes",
"line",
"ending",
"characters",
"and",
"returns",
"a",
"tuple",
"(",
"stripped_line",
"is_terminated",
")",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/formparser.py#L279-L287 | [
"def",
"_line_parse",
"(",
"line",
")",
":",
"if",
"line",
"[",
"-",
"2",
":",
"]",
"in",
"[",
"\"\\r\\n\"",
",",
"b\"\\r\\n\"",
"]",
":",
"return",
"line",
"[",
":",
"-",
"2",
"]",
",",
"True",
"elif",
"line",
"[",
"-",
"1",
":",
"]",
"in",
... | a220671d66755a94630a212378754bb432811158 |
train | FormDataParser.parse_from_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)``. | src/werkzeug/formparser.py | 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):
"""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... | [
"Parses",
"the",
"information",
"from",
"the",
"environment",
"as",
"form",
"data",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/formparser.py#L197-L206 | [
"def",
"parse_from_environ",
"(",
"self",
",",
"environ",
")",
":",
"content_type",
"=",
"environ",
".",
"get",
"(",
"\"CONTENT_TYPE\"",
",",
"\"\"",
")",
"content_length",
"=",
"get_content_length",
"(",
"environ",
")",
"mimetype",
",",
"options",
"=",
"parse... | a220671d66755a94630a212378754bb432811158 |
train | FormDataParser.parse | 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... | src/werkzeug/formparser.py | 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):
"""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 ... | [
"Parses",
"the",
"information",
"from",
"the",
"given",
"stream",
"mimetype",
"content",
"length",
"and",
"mimetype",
"parameters",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/formparser.py#L208-L236 | [
"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... | a220671d66755a94630a212378754bb432811158 |
train | MultiPartParser._find_terminator | 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). | src/werkzeug/formparser.py | 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):
"""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:
... | [
"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",
")",
... | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/formparser.py#L362-L373 | [
"def",
"_find_terminator",
"(",
"self",
",",
"iterator",
")",
":",
"for",
"line",
"in",
"iterator",
":",
"if",
"not",
"line",
":",
"break",
"line",
"=",
"line",
".",
"strip",
"(",
")",
"if",
"line",
":",
"return",
"line",
"return",
"b\"\""
] | a220671d66755a94630a212378754bb432811158 |
train | MultiPartParser.parse_lines | 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 )* | src/werkzeug/formparser.py | 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):
"""Generate parts of
``('begin_form', (headers, name))``
``('begin_file', (headers, name, filename))``
``('cont', bytestring)``
``('end', None)``
Always obeys the grammar
parts = ( begin_f... | [
"Generate",
"parts",
"of",
"(",
"begin_form",
"(",
"headers",
"name",
"))",
"(",
"begin_file",
"(",
"headers",
"name",
"filename",
"))",
"(",
"cont",
"bytestring",
")",
"(",
"end",
"None",
")"
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/formparser.py#L426-L528 | [
"def",
"parse_lines",
"(",
"self",
",",
"file",
",",
"boundary",
",",
"content_length",
",",
"cap_at_buffer",
"=",
"True",
")",
":",
"next_part",
"=",
"b\"--\"",
"+",
"boundary",
"last_part",
"=",
"next_part",
"+",
"b\"--\"",
"iterator",
"=",
"chain",
"(",
... | a220671d66755a94630a212378754bb432811158 |
train | make_app | Factory function that creates a new `CoolmagicApplication`
object. Optional WSGI middlewares should be applied here. | examples/coolmagic/application.py | 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):
"""
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(... | [
"Factory",
"function",
"that",
"creates",
"a",
"new",
"CoolmagicApplication",
"object",
".",
"Optional",
"WSGI",
"middlewares",
"should",
"be",
"applied",
"here",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/examples/coolmagic/application.py#L69-L85 | [
"def",
"make_app",
"(",
"config",
"=",
"None",
")",
":",
"config",
"=",
"config",
"or",
"{",
"}",
"app",
"=",
"CoolMagicApplication",
"(",
"config",
")",
"# static stuff",
"app",
"=",
"SharedDataMiddleware",
"(",
"app",
",",
"{",
"\"/public\"",
":",
"path"... | a220671d66755a94630a212378754bb432811158 |
train | find_hg_tag | Returns the current node or tag for the given path. | bench/wzbench.py | 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):
"""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... | [
"Returns",
"the",
"current",
"node",
"or",
"tag",
"for",
"the",
"given",
"path",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/bench/wzbench.py#L48-L72 | [
"def",
"find_hg_tag",
"(",
"path",
")",
":",
"tags",
"=",
"{",
"}",
"try",
":",
"client",
"=",
"subprocess",
".",
"Popen",
"(",
"[",
"\"hg\"",
",",
"\"cat\"",
",",
"\"-r\"",
",",
"\"tip\"",
",",
"\".hgtags\"",
"]",
",",
"stdout",
"=",
"subprocess",
"... | a220671d66755a94630a212378754bb432811158 |
train | load_werkzeug | Load werkzeug. | bench/wzbench.py | 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):
"""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... | [
"Load",
"werkzeug",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/bench/wzbench.py#L75-L108 | [
"def",
"load_werkzeug",
"(",
"path",
")",
":",
"sys",
".",
"path",
"[",
"0",
"]",
"=",
"path",
"# get rid of already imported stuff",
"wz",
".",
"__dict__",
".",
"clear",
"(",
")",
"for",
"key",
"in",
"sys",
".",
"modules",
".",
"keys",
"(",
")",
":",
... | a220671d66755a94630a212378754bb432811158 |
train | bench | Times a single function. | bench/wzbench.py | 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):
"""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... | [
"Times",
"a",
"single",
"function",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/bench/wzbench.py#L128-L160 | [
"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 ... | a220671d66755a94630a212378754bb432811158 |
train | main | The main entrypoint. | bench/wzbench.py | 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():
"""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... | [
"The",
"main",
"entrypoint",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/bench/wzbench.py#L163-L198 | [
"def",
"main",
"(",
")",
":",
"from",
"optparse",
"import",
"OptionParser",
"parser",
"=",
"OptionParser",
"(",
"usage",
"=",
"\"%prog [options]\"",
")",
"parser",
".",
"add_option",
"(",
"\"--werkzeug-path\"",
",",
"\"-p\"",
",",
"dest",
"=",
"\"path\"",
",",... | a220671d66755a94630a212378754bb432811158 |
train | compare | Compares two Werkzeug hg versions. | bench/wzbench.py | 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):
"""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... | [
"Compares",
"two",
"Werkzeug",
"hg",
"versions",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/bench/wzbench.py#L208-L266 | [
"def",
"compare",
"(",
"node1",
",",
"node2",
")",
":",
"if",
"not",
"os",
".",
"path",
".",
"isdir",
"(",
"\"a\"",
")",
":",
"print",
"(",
"\"error: comparison feature not initialized\"",
",",
"file",
"=",
"sys",
".",
"stderr",
")",
"sys",
".",
"exit",
... | a220671d66755a94630a212378754bb432811158 |
train | Traceback.filter_hidden_frames | Remove the frames according to the paste spec. | src/werkzeug/debug/tbtools.py | 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):
"""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] | [
"Remove",
"the",
"frames",
"according",
"to",
"the",
"paste",
"spec",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/debug/tbtools.py#L260-L265 | [
"def",
"filter_hidden_frames",
"(",
"self",
")",
":",
"for",
"group",
"in",
"self",
".",
"groups",
":",
"group",
".",
"filter_hidden_frames",
"(",
")",
"self",
".",
"frames",
"[",
":",
"]",
"=",
"[",
"frame",
"for",
"group",
"in",
"self",
".",
"groups"... | a220671d66755a94630a212378754bb432811158 |
train | Traceback.log | Log the ASCII traceback into a file object. | src/werkzeug/debug/tbtools.py | 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):
"""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")) | [
"Log",
"the",
"ASCII",
"traceback",
"into",
"a",
"file",
"object",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/debug/tbtools.py#L277-L282 | [
"def",
"log",
"(",
"self",
",",
"logfile",
"=",
"None",
")",
":",
"if",
"logfile",
"is",
"None",
":",
"logfile",
"=",
"sys",
".",
"stderr",
"tb",
"=",
"self",
".",
"plaintext",
".",
"rstrip",
"(",
")",
"+",
"u\"\\n\"",
"logfile",
".",
"write",
"(",... | a220671d66755a94630a212378754bb432811158 |
train | Traceback.paste | Create a paste and return the paste id. | src/werkzeug/debug/tbtools.py | 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):
"""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... | [
"Create",
"a",
"paste",
"and",
"return",
"the",
"paste",
"id",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/debug/tbtools.py#L284-L300 | [
"def",
"paste",
"(",
"self",
")",
":",
"data",
"=",
"json",
".",
"dumps",
"(",
"{",
"\"description\"",
":",
"\"Werkzeug Internal Server Error\"",
",",
"\"public\"",
":",
"False",
",",
"\"files\"",
":",
"{",
"\"traceback.txt\"",
":",
"{",
"\"content\"",
":",
... | a220671d66755a94630a212378754bb432811158 |
train | Traceback.render_summary | Render the traceback for the interactive console. | src/werkzeug/debug/tbtools.py | 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):
"""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... | [
"Render",
"the",
"traceback",
"for",
"the",
"interactive",
"console",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/debug/tbtools.py#L302-L330 | [
"def",
"render_summary",
"(",
"self",
",",
"include_title",
"=",
"True",
")",
":",
"title",
"=",
"\"\"",
"classes",
"=",
"[",
"\"traceback\"",
"]",
"if",
"not",
"self",
".",
"frames",
":",
"classes",
".",
"append",
"(",
"\"noframe-traceback\"",
")",
"frame... | a220671d66755a94630a212378754bb432811158 |
train | Traceback.render_full | Render the Full HTML page with the traceback info. | src/werkzeug/debug/tbtools.py | 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):
"""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... | [
"Render",
"the",
"Full",
"HTML",
"page",
"with",
"the",
"traceback",
"info",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/debug/tbtools.py#L332-L347 | [
"def",
"render_full",
"(",
"self",
",",
"evalex",
"=",
"False",
",",
"secret",
"=",
"None",
",",
"evalex_trusted",
"=",
"True",
")",
":",
"exc",
"=",
"escape",
"(",
"self",
".",
"exception",
")",
"return",
"PAGE_HTML",
"%",
"{",
"\"evalex\"",
":",
"\"t... | a220671d66755a94630a212378754bb432811158 |
train | Group.exception | String representation of the exception. | src/werkzeug/debug/tbtools.py | 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):
"""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") | [
"String",
"representation",
"of",
"the",
"exception",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/debug/tbtools.py#L418-L422 | [
"def",
"exception",
"(",
"self",
")",
":",
"buf",
"=",
"traceback",
".",
"format_exception_only",
"(",
"self",
".",
"exc_type",
",",
"self",
".",
"exc_value",
")",
"rv",
"=",
"\"\"",
".",
"join",
"(",
"buf",
")",
".",
"strip",
"(",
")",
"return",
"to... | a220671d66755a94630a212378754bb432811158 |
train | Frame.render | Render a single frame in a traceback. | src/werkzeug/debug/tbtools.py | 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):
"""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... | [
"Render",
"a",
"single",
"frame",
"in",
"a",
"traceback",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/debug/tbtools.py#L476-L485 | [
"def",
"render",
"(",
"self",
",",
"mark_lib",
"=",
"True",
")",
":",
"return",
"FRAME_HTML",
"%",
"{",
"\"id\"",
":",
"self",
".",
"id",
",",
"\"filename\"",
":",
"escape",
"(",
"self",
".",
"filename",
")",
",",
"\"lineno\"",
":",
"self",
".",
"lin... | a220671d66755a94630a212378754bb432811158 |
train | Frame.eval | Evaluate code in the context of the frame. | src/werkzeug/debug/tbtools.py | 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"):
"""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... | [
"Evaluate",
"code",
"in",
"the",
"context",
"of",
"the",
"frame",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/debug/tbtools.py#L548-L554 | [
"def",
"eval",
"(",
"self",
",",
"code",
",",
"mode",
"=",
"\"single\"",
")",
":",
"if",
"isinstance",
"(",
"code",
",",
"string_types",
")",
":",
"if",
"PY2",
"and",
"isinstance",
"(",
"code",
",",
"text_type",
")",
":",
"# noqa",
"code",
"=",
"UTF8... | a220671d66755a94630a212378754bb432811158 |
train | BaseRequest.application | 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... | src/werkzeug/wrappers/base_request.py | 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):
"""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... | [
"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... | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/wrappers/base_request.py#L207-L239 | [
"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 ... | a220671d66755a94630a212378754bb432811158 |
train | BaseRequest._load_form_data | Method used internally to retrieve submitted data. After calling
this sets `form` and `files` on the request object to multi dicts
filled with the incoming form data. As a matter of fact the input
stream will be empty afterwards. You can also call this method to
force the parsing of t... | src/werkzeug/wrappers/base_request.py | def _load_form_data(self):
"""Method used internally to retrieve submitted data. After calling
this sets `form` and `files` on the request object to multi dicts
filled with the incoming form data. As a matter of fact the input
stream will be empty afterwards. You can also call this me... | def _load_form_data(self):
"""Method used internally to retrieve submitted data. After calling
this sets `form` and `files` on the request object to multi dicts
filled with the incoming form data. As a matter of fact the input
stream will be empty afterwards. You can also call this me... | [
"Method",
"used",
"internally",
"to",
"retrieve",
"submitted",
"data",
".",
"After",
"calling",
"this",
"sets",
"form",
"and",
"files",
"on",
"the",
"request",
"object",
"to",
"multi",
"dicts",
"filled",
"with",
"the",
"incoming",
"form",
"data",
".",
"As",
... | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/wrappers/base_request.py#L294-L327 | [
"def",
"_load_form_data",
"(",
"self",
")",
":",
"# abort early if we have already consumed the stream",
"if",
"\"form\"",
"in",
"self",
".",
"__dict__",
":",
"return",
"_assert_not_shallow",
"(",
"self",
")",
"if",
"self",
".",
"want_form_data_parsed",
":",
"content_... | a220671d66755a94630a212378754bb432811158 |
train | BaseRequest.close | Closes associated resources of this request object. This
closes all file handles explicitly. You can also use the request
object in a with statement which will automatically close it.
.. versionadded:: 0.9 | src/werkzeug/wrappers/base_request.py | def close(self):
"""Closes associated resources of this request object. This
closes all file handles explicitly. You can also use the request
object in a with statement which will automatically close it.
.. versionadded:: 0.9
"""
files = self.__dict__.get("files")
... | def close(self):
"""Closes associated resources of this request object. This
closes all file handles explicitly. You can also use the request
object in a with statement which will automatically close it.
.. versionadded:: 0.9
"""
files = self.__dict__.get("files")
... | [
"Closes",
"associated",
"resources",
"of",
"this",
"request",
"object",
".",
"This",
"closes",
"all",
"file",
"handles",
"explicitly",
".",
"You",
"can",
"also",
"use",
"the",
"request",
"object",
"in",
"a",
"with",
"statement",
"which",
"will",
"automatically... | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/wrappers/base_request.py#L341-L350 | [
"def",
"close",
"(",
"self",
")",
":",
"files",
"=",
"self",
".",
"__dict__",
".",
"get",
"(",
"\"files\"",
")",
"for",
"_key",
",",
"value",
"in",
"iter_multi_items",
"(",
"files",
"or",
"(",
")",
")",
":",
"value",
".",
"close",
"(",
")"
] | a220671d66755a94630a212378754bb432811158 |
train | BaseRequest.values | A :class:`werkzeug.datastructures.CombinedMultiDict` that combines
:attr:`args` and :attr:`form`. | src/werkzeug/wrappers/base_request.py | def values(self):
"""A :class:`werkzeug.datastructures.CombinedMultiDict` that combines
:attr:`args` and :attr:`form`."""
args = []
for d in self.args, self.form:
if not isinstance(d, MultiDict):
d = MultiDict(d)
args.append(d)
return Combi... | def values(self):
"""A :class:`werkzeug.datastructures.CombinedMultiDict` that combines
:attr:`args` and :attr:`form`."""
args = []
for d in self.args, self.form:
if not isinstance(d, MultiDict):
d = MultiDict(d)
args.append(d)
return Combi... | [
"A",
":",
"class",
":",
"werkzeug",
".",
"datastructures",
".",
"CombinedMultiDict",
"that",
"combines",
":",
"attr",
":",
"args",
"and",
":",
"attr",
":",
"form",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/wrappers/base_request.py#L480-L488 | [
"def",
"values",
"(",
"self",
")",
":",
"args",
"=",
"[",
"]",
"for",
"d",
"in",
"self",
".",
"args",
",",
"self",
".",
"form",
":",
"if",
"not",
"isinstance",
"(",
"d",
",",
"MultiDict",
")",
":",
"d",
"=",
"MultiDict",
"(",
"d",
")",
"args",
... | a220671d66755a94630a212378754bb432811158 |
train | BaseRequest.cookies | A :class:`dict` with the contents of all cookies transmitted with
the request. | src/werkzeug/wrappers/base_request.py | def cookies(self):
"""A :class:`dict` with the contents of all cookies transmitted with
the request."""
return parse_cookie(
self.environ,
self.charset,
self.encoding_errors,
cls=self.dict_storage_class,
) | def cookies(self):
"""A :class:`dict` with the contents of all cookies transmitted with
the request."""
return parse_cookie(
self.environ,
self.charset,
self.encoding_errors,
cls=self.dict_storage_class,
) | [
"A",
":",
"class",
":",
"dict",
"with",
"the",
"contents",
"of",
"all",
"cookies",
"transmitted",
"with",
"the",
"request",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/wrappers/base_request.py#L514-L522 | [
"def",
"cookies",
"(",
"self",
")",
":",
"return",
"parse_cookie",
"(",
"self",
".",
"environ",
",",
"self",
".",
"charset",
",",
"self",
".",
"encoding_errors",
",",
"cls",
"=",
"self",
".",
"dict_storage_class",
",",
")"
] | a220671d66755a94630a212378754bb432811158 |
train | BaseRequest.path | Requested path as unicode. This works a bit like the regular path
info in the WSGI environment but will always include a leading slash,
even if the URL root is accessed. | src/werkzeug/wrappers/base_request.py | def path(self):
"""Requested path as unicode. This works a bit like the regular path
info in the WSGI environment but will always include a leading slash,
even if the URL root is accessed.
"""
raw_path = wsgi_decoding_dance(
self.environ.get("PATH_INFO") or "", self.... | def path(self):
"""Requested path as unicode. This works a bit like the regular path
info in the WSGI environment but will always include a leading slash,
even if the URL root is accessed.
"""
raw_path = wsgi_decoding_dance(
self.environ.get("PATH_INFO") or "", self.... | [
"Requested",
"path",
"as",
"unicode",
".",
"This",
"works",
"a",
"bit",
"like",
"the",
"regular",
"path",
"info",
"in",
"the",
"WSGI",
"environment",
"but",
"will",
"always",
"include",
"a",
"leading",
"slash",
"even",
"if",
"the",
"URL",
"root",
"is",
"... | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/wrappers/base_request.py#L532-L540 | [
"def",
"path",
"(",
"self",
")",
":",
"raw_path",
"=",
"wsgi_decoding_dance",
"(",
"self",
".",
"environ",
".",
"get",
"(",
"\"PATH_INFO\"",
")",
"or",
"\"\"",
",",
"self",
".",
"charset",
",",
"self",
".",
"encoding_errors",
")",
"return",
"\"/\"",
"+",... | a220671d66755a94630a212378754bb432811158 |
train | BaseRequest.full_path | Requested path as unicode, including the query string. | src/werkzeug/wrappers/base_request.py | def full_path(self):
"""Requested path as unicode, including the query string."""
return self.path + u"?" + to_unicode(self.query_string, self.url_charset) | def full_path(self):
"""Requested path as unicode, including the query string."""
return self.path + u"?" + to_unicode(self.query_string, self.url_charset) | [
"Requested",
"path",
"as",
"unicode",
"including",
"the",
"query",
"string",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/wrappers/base_request.py#L543-L545 | [
"def",
"full_path",
"(",
"self",
")",
":",
"return",
"self",
".",
"path",
"+",
"u\"?\"",
"+",
"to_unicode",
"(",
"self",
".",
"query_string",
",",
"self",
".",
"url_charset",
")"
] | a220671d66755a94630a212378754bb432811158 |
train | BaseRequest.script_root | The root path of the script without the trailing slash. | src/werkzeug/wrappers/base_request.py | def script_root(self):
"""The root path of the script without the trailing slash."""
raw_path = wsgi_decoding_dance(
self.environ.get("SCRIPT_NAME") or "", self.charset, self.encoding_errors
)
return raw_path.rstrip("/") | def script_root(self):
"""The root path of the script without the trailing slash."""
raw_path = wsgi_decoding_dance(
self.environ.get("SCRIPT_NAME") or "", self.charset, self.encoding_errors
)
return raw_path.rstrip("/") | [
"The",
"root",
"path",
"of",
"the",
"script",
"without",
"the",
"trailing",
"slash",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/wrappers/base_request.py#L548-L553 | [
"def",
"script_root",
"(",
"self",
")",
":",
"raw_path",
"=",
"wsgi_decoding_dance",
"(",
"self",
".",
"environ",
".",
"get",
"(",
"\"SCRIPT_NAME\"",
")",
"or",
"\"\"",
",",
"self",
".",
"charset",
",",
"self",
".",
"encoding_errors",
")",
"return",
"raw_p... | a220671d66755a94630a212378754bb432811158 |
train | BaseRequest.base_url | Like :attr:`url` but without the querystring
See also: :attr:`trusted_hosts`. | src/werkzeug/wrappers/base_request.py | def base_url(self):
"""Like :attr:`url` but without the querystring
See also: :attr:`trusted_hosts`.
"""
return get_current_url(
self.environ, strip_querystring=True, trusted_hosts=self.trusted_hosts
) | def base_url(self):
"""Like :attr:`url` but without the querystring
See also: :attr:`trusted_hosts`.
"""
return get_current_url(
self.environ, strip_querystring=True, trusted_hosts=self.trusted_hosts
) | [
"Like",
":",
"attr",
":",
"url",
"but",
"without",
"the",
"querystring",
"See",
"also",
":",
":",
"attr",
":",
"trusted_hosts",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/wrappers/base_request.py#L563-L569 | [
"def",
"base_url",
"(",
"self",
")",
":",
"return",
"get_current_url",
"(",
"self",
".",
"environ",
",",
"strip_querystring",
"=",
"True",
",",
"trusted_hosts",
"=",
"self",
".",
"trusted_hosts",
")"
] | a220671d66755a94630a212378754bb432811158 |
train | BaseRequest.host_url | Just the host with scheme as IRI.
See also: :attr:`trusted_hosts`. | src/werkzeug/wrappers/base_request.py | def host_url(self):
"""Just the host with scheme as IRI.
See also: :attr:`trusted_hosts`.
"""
return get_current_url(
self.environ, host_only=True, trusted_hosts=self.trusted_hosts
) | def host_url(self):
"""Just the host with scheme as IRI.
See also: :attr:`trusted_hosts`.
"""
return get_current_url(
self.environ, host_only=True, trusted_hosts=self.trusted_hosts
) | [
"Just",
"the",
"host",
"with",
"scheme",
"as",
"IRI",
".",
"See",
"also",
":",
":",
"attr",
":",
"trusted_hosts",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/wrappers/base_request.py#L580-L586 | [
"def",
"host_url",
"(",
"self",
")",
":",
"return",
"get_current_url",
"(",
"self",
".",
"environ",
",",
"host_only",
"=",
"True",
",",
"trusted_hosts",
"=",
"self",
".",
"trusted_hosts",
")"
] | a220671d66755a94630a212378754bb432811158 |
train | BaseRequest.access_route | If a forwarded header exists this is a list of all ip addresses
from the client ip to the last proxy server. | src/werkzeug/wrappers/base_request.py | def access_route(self):
"""If a forwarded header exists this is a list of all ip addresses
from the client ip to the last proxy server.
"""
if "HTTP_X_FORWARDED_FOR" in self.environ:
addr = self.environ["HTTP_X_FORWARDED_FOR"].split(",")
return self.list_storage_c... | def access_route(self):
"""If a forwarded header exists this is a list of all ip addresses
from the client ip to the last proxy server.
"""
if "HTTP_X_FORWARDED_FOR" in self.environ:
addr = self.environ["HTTP_X_FORWARDED_FOR"].split(",")
return self.list_storage_c... | [
"If",
"a",
"forwarded",
"header",
"exists",
"this",
"is",
"a",
"list",
"of",
"all",
"ip",
"addresses",
"from",
"the",
"client",
"ip",
"to",
"the",
"last",
"proxy",
"server",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/wrappers/base_request.py#L611-L620 | [
"def",
"access_route",
"(",
"self",
")",
":",
"if",
"\"HTTP_X_FORWARDED_FOR\"",
"in",
"self",
".",
"environ",
":",
"addr",
"=",
"self",
".",
"environ",
"[",
"\"HTTP_X_FORWARDED_FOR\"",
"]",
".",
"split",
"(",
"\",\"",
")",
"return",
"self",
".",
"list_storag... | a220671d66755a94630a212378754bb432811158 |
train | on_show | Displays the page the user requests. | examples/simplewiki/actions.py | def on_show(request, page_name):
"""Displays the page the user requests."""
revision_id = request.args.get("rev", type=int)
query = RevisionedPage.query.filter_by(name=page_name)
if revision_id:
query = query.filter_by(revision_id=revision_id)
revision_requested = True
else:
... | def on_show(request, page_name):
"""Displays the page the user requests."""
revision_id = request.args.get("rev", type=int)
query = RevisionedPage.query.filter_by(name=page_name)
if revision_id:
query = query.filter_by(revision_id=revision_id)
revision_requested = True
else:
... | [
"Displays",
"the",
"page",
"the",
"user",
"requests",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/examples/simplewiki/actions.py#L29-L42 | [
"def",
"on_show",
"(",
"request",
",",
"page_name",
")",
":",
"revision_id",
"=",
"request",
".",
"args",
".",
"get",
"(",
"\"rev\"",
",",
"type",
"=",
"int",
")",
"query",
"=",
"RevisionedPage",
".",
"query",
".",
"filter_by",
"(",
"name",
"=",
"page_... | a220671d66755a94630a212378754bb432811158 |
train | on_edit | Edit the current revision of a page. | examples/simplewiki/actions.py | def on_edit(request, page_name):
"""Edit the current revision of a page."""
change_note = error = ""
revision = (
Revision.query.filter(
(Page.name == page_name) & (Page.page_id == Revision.page_id)
)
.order_by(Revision.revision_id.desc())
.first()
)
if re... | def on_edit(request, page_name):
"""Edit the current revision of a page."""
change_note = error = ""
revision = (
Revision.query.filter(
(Page.name == page_name) & (Page.page_id == Revision.page_id)
)
.order_by(Revision.revision_id.desc())
.first()
)
if re... | [
"Edit",
"the",
"current",
"revision",
"of",
"a",
"page",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/examples/simplewiki/actions.py#L45-L85 | [
"def",
"on_edit",
"(",
"request",
",",
"page_name",
")",
":",
"change_note",
"=",
"error",
"=",
"\"\"",
"revision",
"=",
"(",
"Revision",
".",
"query",
".",
"filter",
"(",
"(",
"Page",
".",
"name",
"==",
"page_name",
")",
"&",
"(",
"Page",
".",
"page... | a220671d66755a94630a212378754bb432811158 |
train | on_log | Show the list of recent changes. | examples/simplewiki/actions.py | def on_log(request, page_name):
"""Show the list of recent changes."""
page = Page.query.filter_by(name=page_name).first()
if page is None:
return page_missing(request, page_name, False)
return Response(generate_template("action_log.html", page=page)) | def on_log(request, page_name):
"""Show the list of recent changes."""
page = Page.query.filter_by(name=page_name).first()
if page is None:
return page_missing(request, page_name, False)
return Response(generate_template("action_log.html", page=page)) | [
"Show",
"the",
"list",
"of",
"recent",
"changes",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/examples/simplewiki/actions.py#L88-L93 | [
"def",
"on_log",
"(",
"request",
",",
"page_name",
")",
":",
"page",
"=",
"Page",
".",
"query",
".",
"filter_by",
"(",
"name",
"=",
"page_name",
")",
".",
"first",
"(",
")",
"if",
"page",
"is",
"None",
":",
"return",
"page_missing",
"(",
"request",
"... | a220671d66755a94630a212378754bb432811158 |
train | on_diff | Show the diff between two revisions. | examples/simplewiki/actions.py | def on_diff(request, page_name):
"""Show the diff between two revisions."""
old = request.args.get("old", type=int)
new = request.args.get("new", type=int)
error = ""
diff = page = old_rev = new_rev = None
if not (old and new):
error = "No revisions specified."
else:
revisio... | def on_diff(request, page_name):
"""Show the diff between two revisions."""
old = request.args.get("old", type=int)
new = request.args.get("new", type=int)
error = ""
diff = page = old_rev = new_rev = None
if not (old and new):
error = "No revisions specified."
else:
revisio... | [
"Show",
"the",
"diff",
"between",
"two",
"revisions",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/examples/simplewiki/actions.py#L96-L139 | [
"def",
"on_diff",
"(",
"request",
",",
"page_name",
")",
":",
"old",
"=",
"request",
".",
"args",
".",
"get",
"(",
"\"old\"",
",",
"type",
"=",
"int",
")",
"new",
"=",
"request",
".",
"args",
".",
"get",
"(",
"\"new\"",
",",
"type",
"=",
"int",
"... | a220671d66755a94630a212378754bb432811158 |
train | on_revert | Revert an old revision. | examples/simplewiki/actions.py | def on_revert(request, page_name):
"""Revert an old revision."""
rev_id = request.args.get("rev", type=int)
old_revision = page = None
error = "No such revision"
if request.method == "POST" and request.form.get("cancel"):
return redirect(href(page_name))
if rev_id:
old_revisio... | def on_revert(request, page_name):
"""Revert an old revision."""
rev_id = request.args.get("rev", type=int)
old_revision = page = None
error = "No such revision"
if request.method == "POST" and request.form.get("cancel"):
return redirect(href(page_name))
if rev_id:
old_revisio... | [
"Revert",
"an",
"old",
"revision",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/examples/simplewiki/actions.py#L142-L188 | [
"def",
"on_revert",
"(",
"request",
",",
"page_name",
")",
":",
"rev_id",
"=",
"request",
".",
"args",
".",
"get",
"(",
"\"rev\"",
",",
"type",
"=",
"int",
")",
"old_revision",
"=",
"page",
"=",
"None",
"error",
"=",
"\"No such revision\"",
"if",
"reques... | a220671d66755a94630a212378754bb432811158 |
train | page_missing | Displayed if page or revision does not exist. | examples/simplewiki/actions.py | def page_missing(request, page_name, revision_requested, protected=False):
"""Displayed if page or revision does not exist."""
return Response(
generate_template(
"page_missing.html",
page_name=page_name,
revision_requested=revision_requested,
protected=pr... | def page_missing(request, page_name, revision_requested, protected=False):
"""Displayed if page or revision does not exist."""
return Response(
generate_template(
"page_missing.html",
page_name=page_name,
revision_requested=revision_requested,
protected=pr... | [
"Displayed",
"if",
"page",
"or",
"revision",
"does",
"not",
"exist",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/examples/simplewiki/actions.py#L191-L201 | [
"def",
"page_missing",
"(",
"request",
",",
"page_name",
",",
"revision_requested",
",",
"protected",
"=",
"False",
")",
":",
"return",
"Response",
"(",
"generate_template",
"(",
"\"page_missing.html\"",
",",
"page_name",
"=",
"page_name",
",",
"revision_requested",... | a220671d66755a94630a212378754bb432811158 |
train | shell | Start a new interactive python session. | examples/manage-shorty.py | def shell(no_ipython):
"""Start a new interactive python session."""
banner = "Interactive Werkzeug Shell"
namespace = make_shell()
if not no_ipython:
try:
try:
from IPython.frontend.terminal.embed import InteractiveShellEmbed
sh = InteractiveShellEmb... | def shell(no_ipython):
"""Start a new interactive python session."""
banner = "Interactive Werkzeug Shell"
namespace = make_shell()
if not no_ipython:
try:
try:
from IPython.frontend.terminal.embed import InteractiveShellEmbed
sh = InteractiveShellEmb... | [
"Start",
"a",
"new",
"interactive",
"python",
"session",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/examples/manage-shorty.py#L60-L81 | [
"def",
"shell",
"(",
"no_ipython",
")",
":",
"banner",
"=",
"\"Interactive Werkzeug Shell\"",
"namespace",
"=",
"make_shell",
"(",
")",
"if",
"not",
"no_ipython",
":",
"try",
":",
"try",
":",
"from",
"IPython",
".",
"frontend",
".",
"terminal",
".",
"embed",... | a220671d66755a94630a212378754bb432811158 |
train | _get_fields | Get fields from a class. If ordered=True, fields will sorted by creation index.
:param attrs: Mapping of class attributes
:param type field_class: Base field class
:param bool pop: Remove matching fields | src/marshmallow/schema.py | def _get_fields(attrs, field_class, pop=False, ordered=False):
"""Get fields from a class. If ordered=True, fields will sorted by creation index.
:param attrs: Mapping of class attributes
:param type field_class: Base field class
:param bool pop: Remove matching fields
"""
fields = [
(f... | def _get_fields(attrs, field_class, pop=False, ordered=False):
"""Get fields from a class. If ordered=True, fields will sorted by creation index.
:param attrs: Mapping of class attributes
:param type field_class: Base field class
:param bool pop: Remove matching fields
"""
fields = [
(f... | [
"Get",
"fields",
"from",
"a",
"class",
".",
"If",
"ordered",
"=",
"True",
"fields",
"will",
"sorted",
"by",
"creation",
"index",
"."
] | marshmallow-code/marshmallow | python | https://github.com/marshmallow-code/marshmallow/blob/a6b6c4151f1fbf16f3774d4052ca2bddf6903750/src/marshmallow/schema.py#L35-L52 | [
"def",
"_get_fields",
"(",
"attrs",
",",
"field_class",
",",
"pop",
"=",
"False",
",",
"ordered",
"=",
"False",
")",
":",
"fields",
"=",
"[",
"(",
"field_name",
",",
"field_value",
")",
"for",
"field_name",
",",
"field_value",
"in",
"iteritems",
"(",
"at... | a6b6c4151f1fbf16f3774d4052ca2bddf6903750 |
train | _get_fields_by_mro | Collect fields from a class, following its method resolution order. The
class itself is excluded from the search; only its parents are checked. Get
fields from ``_declared_fields`` if available, else use ``__dict__``.
:param type klass: Class whose fields to retrieve
:param type field_class: Base field... | src/marshmallow/schema.py | def _get_fields_by_mro(klass, field_class, ordered=False):
"""Collect fields from a class, following its method resolution order. The
class itself is excluded from the search; only its parents are checked. Get
fields from ``_declared_fields`` if available, else use ``__dict__``.
:param type klass: Clas... | def _get_fields_by_mro(klass, field_class, ordered=False):
"""Collect fields from a class, following its method resolution order. The
class itself is excluded from the search; only its parents are checked. Get
fields from ``_declared_fields`` if available, else use ``__dict__``.
:param type klass: Clas... | [
"Collect",
"fields",
"from",
"a",
"class",
"following",
"its",
"method",
"resolution",
"order",
".",
"The",
"class",
"itself",
"is",
"excluded",
"from",
"the",
"search",
";",
"only",
"its",
"parents",
"are",
"checked",
".",
"Get",
"fields",
"from",
"_declare... | marshmallow-code/marshmallow | python | https://github.com/marshmallow-code/marshmallow/blob/a6b6c4151f1fbf16f3774d4052ca2bddf6903750/src/marshmallow/schema.py#L56-L76 | [
"def",
"_get_fields_by_mro",
"(",
"klass",
",",
"field_class",
",",
"ordered",
"=",
"False",
")",
":",
"mro",
"=",
"inspect",
".",
"getmro",
"(",
"klass",
")",
"# Loop over mro in reverse to maintain correct order of fields",
"return",
"sum",
"(",
"(",
"_get_fields"... | a6b6c4151f1fbf16f3774d4052ca2bddf6903750 |
train | SchemaMeta.resolve_hooks | Add in the decorated processors
By doing this after constructing the class, we let standard inheritance
do all the hard work. | src/marshmallow/schema.py | def resolve_hooks(self):
"""Add in the decorated processors
By doing this after constructing the class, we let standard inheritance
do all the hard work.
"""
mro = inspect.getmro(self)
hooks = defaultdict(list)
for attr_name in dir(self):
# Need to ... | def resolve_hooks(self):
"""Add in the decorated processors
By doing this after constructing the class, we let standard inheritance
do all the hard work.
"""
mro = inspect.getmro(self)
hooks = defaultdict(list)
for attr_name in dir(self):
# Need to ... | [
"Add",
"in",
"the",
"decorated",
"processors"
] | marshmallow-code/marshmallow | python | https://github.com/marshmallow-code/marshmallow/blob/a6b6c4151f1fbf16f3774d4052ca2bddf6903750/src/marshmallow/schema.py#L144-L181 | [
"def",
"resolve_hooks",
"(",
"self",
")",
":",
"mro",
"=",
"inspect",
".",
"getmro",
"(",
"self",
")",
"hooks",
"=",
"defaultdict",
"(",
"list",
")",
"for",
"attr_name",
"in",
"dir",
"(",
"self",
")",
":",
"# Need to look up the actual descriptor, not whatever... | a6b6c4151f1fbf16f3774d4052ca2bddf6903750 |
train | BaseSchema._call_and_store | Call ``getter_func`` with ``data`` as its argument, and store any `ValidationErrors`.
:param callable getter_func: Function for getting the serialized/deserialized
value from ``data``.
:param data: The data passed to ``getter_func``.
:param str field_name: Field name.
:param... | src/marshmallow/schema.py | def _call_and_store(getter_func, data, field_name, error_store, index=None):
"""Call ``getter_func`` with ``data`` as its argument, and store any `ValidationErrors`.
:param callable getter_func: Function for getting the serialized/deserialized
value from ``data``.
:param data: The d... | def _call_and_store(getter_func, data, field_name, error_store, index=None):
"""Call ``getter_func`` with ``data`` as its argument, and store any `ValidationErrors`.
:param callable getter_func: Function for getting the serialized/deserialized
value from ``data``.
:param data: The d... | [
"Call",
"getter_func",
"with",
"data",
"as",
"its",
"argument",
"and",
"store",
"any",
"ValidationErrors",
"."
] | marshmallow-code/marshmallow | python | https://github.com/marshmallow-code/marshmallow/blob/a6b6c4151f1fbf16f3774d4052ca2bddf6903750/src/marshmallow/schema.py#L416-L433 | [
"def",
"_call_and_store",
"(",
"getter_func",
",",
"data",
",",
"field_name",
",",
"error_store",
",",
"index",
"=",
"None",
")",
":",
"try",
":",
"value",
"=",
"getter_func",
"(",
"data",
")",
"except",
"ValidationError",
"as",
"err",
":",
"error_store",
... | a6b6c4151f1fbf16f3774d4052ca2bddf6903750 |
train | BaseSchema._serialize | Takes raw data (a dict, list, or other object) and a dict of
fields to output and serializes the data based on those fields.
:param obj: The actual object(s) from which the fields are taken from
:param dict fields_dict: Mapping of field names to :class:`Field` objects.
:param ErrorStore... | src/marshmallow/schema.py | def _serialize(
self, obj, fields_dict, error_store, many=False,
accessor=None, dict_class=dict, index_errors=True,
index=None,
):
"""Takes raw data (a dict, list, or other object) and a dict of
fields to output and serializes the data based on those fields.
:param o... | def _serialize(
self, obj, fields_dict, error_store, many=False,
accessor=None, dict_class=dict, index_errors=True,
index=None,
):
"""Takes raw data (a dict, list, or other object) and a dict of
fields to output and serializes the data based on those fields.
:param o... | [
"Takes",
"raw",
"data",
"(",
"a",
"dict",
"list",
"or",
"other",
"object",
")",
"and",
"a",
"dict",
"of",
"fields",
"to",
"output",
"and",
"serializes",
"the",
"data",
"based",
"on",
"those",
"fields",
"."
] | marshmallow-code/marshmallow | python | https://github.com/marshmallow-code/marshmallow/blob/a6b6c4151f1fbf16f3774d4052ca2bddf6903750/src/marshmallow/schema.py#L435-L489 | [
"def",
"_serialize",
"(",
"self",
",",
"obj",
",",
"fields_dict",
",",
"error_store",
",",
"many",
"=",
"False",
",",
"accessor",
"=",
"None",
",",
"dict_class",
"=",
"dict",
",",
"index_errors",
"=",
"True",
",",
"index",
"=",
"None",
",",
")",
":",
... | a6b6c4151f1fbf16f3774d4052ca2bddf6903750 |
train | BaseSchema.dump | Serialize an object to native Python data types according to this
Schema's fields.
:param obj: The object to serialize.
:param bool many: Whether to serialize `obj` as a collection. If `None`, the value
for `self.many` is used.
:return: A dict of serialized data
:rty... | src/marshmallow/schema.py | def dump(self, obj, many=None):
"""Serialize an object to native Python data types according to this
Schema's fields.
:param obj: The object to serialize.
:param bool many: Whether to serialize `obj` as a collection. If `None`, the value
for `self.many` is used.
:ret... | def dump(self, obj, many=None):
"""Serialize an object to native Python data types according to this
Schema's fields.
:param obj: The object to serialize.
:param bool many: Whether to serialize `obj` as a collection. If `None`, the value
for `self.many` is used.
:ret... | [
"Serialize",
"an",
"object",
"to",
"native",
"Python",
"data",
"types",
"according",
"to",
"this",
"Schema",
"s",
"fields",
"."
] | marshmallow-code/marshmallow | python | https://github.com/marshmallow-code/marshmallow/blob/a6b6c4151f1fbf16f3774d4052ca2bddf6903750/src/marshmallow/schema.py#L491-L559 | [
"def",
"dump",
"(",
"self",
",",
"obj",
",",
"many",
"=",
"None",
")",
":",
"error_store",
"=",
"ErrorStore",
"(",
")",
"errors",
"=",
"{",
"}",
"many",
"=",
"self",
".",
"many",
"if",
"many",
"is",
"None",
"else",
"bool",
"(",
"many",
")",
"if",... | a6b6c4151f1fbf16f3774d4052ca2bddf6903750 |
train | BaseSchema.dumps | Same as :meth:`dump`, except return a JSON-encoded string.
:param obj: The object to serialize.
:param bool many: Whether to serialize `obj` as a collection. If `None`, the value
for `self.many` is used.
:return: A ``json`` string
:rtype: str
.. versionadded:: 1.0.0... | src/marshmallow/schema.py | def dumps(self, obj, many=None, *args, **kwargs):
"""Same as :meth:`dump`, except return a JSON-encoded string.
:param obj: The object to serialize.
:param bool many: Whether to serialize `obj` as a collection. If `None`, the value
for `self.many` is used.
:return: A ``json`... | def dumps(self, obj, many=None, *args, **kwargs):
"""Same as :meth:`dump`, except return a JSON-encoded string.
:param obj: The object to serialize.
:param bool many: Whether to serialize `obj` as a collection. If `None`, the value
for `self.many` is used.
:return: A ``json`... | [
"Same",
"as",
":",
"meth",
":",
"dump",
"except",
"return",
"a",
"JSON",
"-",
"encoded",
"string",
"."
] | marshmallow-code/marshmallow | python | https://github.com/marshmallow-code/marshmallow/blob/a6b6c4151f1fbf16f3774d4052ca2bddf6903750/src/marshmallow/schema.py#L561-L577 | [
"def",
"dumps",
"(",
"self",
",",
"obj",
",",
"many",
"=",
"None",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"serialized",
"=",
"self",
".",
"dump",
"(",
"obj",
",",
"many",
"=",
"many",
")",
"return",
"self",
".",
"opts",
".",
"rend... | a6b6c4151f1fbf16f3774d4052ca2bddf6903750 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.