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 | CommonResponseDescriptorsMixin.mimetype | The mimetype (content type without charset etc.) | src/werkzeug/wrappers/common_descriptors.py | def mimetype(self):
"""The mimetype (content type without charset etc.)"""
ct = self.headers.get("content-type")
if ct:
return ct.split(";")[0].strip() | def mimetype(self):
"""The mimetype (content type without charset etc.)"""
ct = self.headers.get("content-type")
if ct:
return ct.split(";")[0].strip() | [
"The",
"mimetype",
"(",
"content",
"type",
"without",
"charset",
"etc",
".",
")"
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/wrappers/common_descriptors.py#L136-L140 | [
"def",
"mimetype",
"(",
"self",
")",
":",
"ct",
"=",
"self",
".",
"headers",
".",
"get",
"(",
"\"content-type\"",
")",
"if",
"ct",
":",
"return",
"ct",
".",
"split",
"(",
"\";\"",
")",
"[",
"0",
"]",
".",
"strip",
"(",
")"
] | a220671d66755a94630a212378754bb432811158 |
train | CommonResponseDescriptorsMixin.mimetype_params | The mimetype parameters as dict. For example if the
content type is ``text/html; charset=utf-8`` the params would be
``{'charset': 'utf-8'}``.
.. versionadded:: 0.5 | src/werkzeug/wrappers/common_descriptors.py | def mimetype_params(self):
"""The mimetype parameters as dict. For example if the
content type is ``text/html; charset=utf-8`` the params would be
``{'charset': 'utf-8'}``.
.. versionadded:: 0.5
"""
def on_update(d):
self.headers["Content-Type"] = dump_optio... | def mimetype_params(self):
"""The mimetype parameters as dict. For example if the
content type is ``text/html; charset=utf-8`` the params would be
``{'charset': 'utf-8'}``.
.. versionadded:: 0.5
"""
def on_update(d):
self.headers["Content-Type"] = dump_optio... | [
"The",
"mimetype",
"parameters",
"as",
"dict",
".",
"For",
"example",
"if",
"the",
"content",
"type",
"is",
"text",
"/",
"html",
";",
"charset",
"=",
"utf",
"-",
"8",
"the",
"params",
"would",
"be",
"{",
"charset",
":",
"utf",
"-",
"8",
"}",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/wrappers/common_descriptors.py#L147-L159 | [
"def",
"mimetype_params",
"(",
"self",
")",
":",
"def",
"on_update",
"(",
"d",
")",
":",
"self",
".",
"headers",
"[",
"\"Content-Type\"",
"]",
"=",
"dump_options_header",
"(",
"self",
".",
"mimetype",
",",
"d",
")",
"d",
"=",
"parse_options_header",
"(",
... | a220671d66755a94630a212378754bb432811158 |
train | page_index | Index of all pages. | examples/simplewiki/specialpages.py | def page_index(request):
"""Index of all pages."""
letters = {}
for page in Page.query.order_by(Page.name):
letters.setdefault(page.name.capitalize()[0], []).append(page)
return Response(
generate_template("page_index.html", letters=sorted(letters.items()))
) | def page_index(request):
"""Index of all pages."""
letters = {}
for page in Page.query.order_by(Page.name):
letters.setdefault(page.name.capitalize()[0], []).append(page)
return Response(
generate_template("page_index.html", letters=sorted(letters.items()))
) | [
"Index",
"of",
"all",
"pages",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/examples/simplewiki/specialpages.py#L20-L27 | [
"def",
"page_index",
"(",
"request",
")",
":",
"letters",
"=",
"{",
"}",
"for",
"page",
"in",
"Page",
".",
"query",
".",
"order_by",
"(",
"Page",
".",
"name",
")",
":",
"letters",
".",
"setdefault",
"(",
"page",
".",
"name",
".",
"capitalize",
"(",
... | a220671d66755a94630a212378754bb432811158 |
train | recent_changes | Display the recent changes. | examples/simplewiki/specialpages.py | def recent_changes(request):
"""Display the recent changes."""
page = max(1, request.args.get("page", type=int))
query = RevisionedPage.query.order_by(RevisionedPage.revision_id.desc())
return Response(
generate_template(
"recent_changes.html",
pagination=Pagination(query... | def recent_changes(request):
"""Display the recent changes."""
page = max(1, request.args.get("page", type=int))
query = RevisionedPage.query.order_by(RevisionedPage.revision_id.desc())
return Response(
generate_template(
"recent_changes.html",
pagination=Pagination(query... | [
"Display",
"the",
"recent",
"changes",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/examples/simplewiki/specialpages.py#L30-L39 | [
"def",
"recent_changes",
"(",
"request",
")",
":",
"page",
"=",
"max",
"(",
"1",
",",
"request",
".",
"args",
".",
"get",
"(",
"\"page\"",
",",
"type",
"=",
"int",
")",
")",
"query",
"=",
"RevisionedPage",
".",
"query",
".",
"order_by",
"(",
"Revisio... | a220671d66755a94630a212378754bb432811158 |
train | make_app | Helper function that creates a plnt app. | examples/manage-plnt.py | def make_app():
"""Helper function that creates a plnt app."""
from plnt import Plnt
database_uri = os.environ.get("PLNT_DATABASE_URI")
app = Plnt(database_uri or "sqlite:////tmp/plnt.db")
app.bind_to_context()
return app | def make_app():
"""Helper function that creates a plnt app."""
from plnt import Plnt
database_uri = os.environ.get("PLNT_DATABASE_URI")
app = Plnt(database_uri or "sqlite:////tmp/plnt.db")
app.bind_to_context()
return app | [
"Helper",
"function",
"that",
"creates",
"a",
"plnt",
"app",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/examples/manage-plnt.py#L18-L25 | [
"def",
"make_app",
"(",
")",
":",
"from",
"plnt",
"import",
"Plnt",
"database_uri",
"=",
"os",
".",
"environ",
".",
"get",
"(",
"\"PLNT_DATABASE_URI\"",
")",
"app",
"=",
"Plnt",
"(",
"database_uri",
"or",
"\"sqlite:////tmp/plnt.db\"",
")",
"app",
".",
"bind_... | a220671d66755a94630a212378754bb432811158 |
train | initdb | Initialize the database | examples/manage-plnt.py | def initdb():
"""Initialize the database"""
from plnt.database import Blog, session
make_app().init_database()
# and now fill in some python blogs everybody should read (shamelessly
# added my own blog too)
blogs = [
Blog(
"Armin Ronacher",
"http://lucumr.pocoo.o... | def initdb():
"""Initialize the database"""
from plnt.database import Blog, session
make_app().init_database()
# and now fill in some python blogs everybody should read (shamelessly
# added my own blog too)
blogs = [
Blog(
"Armin Ronacher",
"http://lucumr.pocoo.o... | [
"Initialize",
"the",
"database"
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/examples/manage-plnt.py#L34-L76 | [
"def",
"initdb",
"(",
")",
":",
"from",
"plnt",
".",
"database",
"import",
"Blog",
",",
"session",
"make_app",
"(",
")",
".",
"init_database",
"(",
")",
"# and now fill in some python blogs everybody should read (shamelessly",
"# added my own blog too)",
"blogs",
"=",
... | a220671d66755a94630a212378754bb432811158 |
train | runserver | Start a new development server. | examples/manage-plnt.py | def runserver(hostname, port, no_reloader, debugger, no_evalex, threaded, processes):
"""Start a new development server."""
app = make_app()
reloader = not no_reloader
evalex = not no_evalex
run_simple(
hostname,
port,
app,
use_reloader=reloader,
use_debugger=... | def runserver(hostname, port, no_reloader, debugger, no_evalex, threaded, processes):
"""Start a new development server."""
app = make_app()
reloader = not no_reloader
evalex = not no_evalex
run_simple(
hostname,
port,
app,
use_reloader=reloader,
use_debugger=... | [
"Start",
"a",
"new",
"development",
"server",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/examples/manage-plnt.py#L87-L101 | [
"def",
"runserver",
"(",
"hostname",
",",
"port",
",",
"no_reloader",
",",
"debugger",
",",
"no_evalex",
",",
"threaded",
",",
"processes",
")",
":",
"app",
"=",
"make_app",
"(",
")",
"reloader",
"=",
"not",
"no_reloader",
"evalex",
"=",
"not",
"no_evalex"... | a220671d66755a94630a212378754bb432811158 |
train | iter_multi_items | Iterates over the items of a mapping yielding keys and values
without dropping any from more complex structures. | src/werkzeug/datastructures.py | def iter_multi_items(mapping):
"""Iterates over the items of a mapping yielding keys and values
without dropping any from more complex structures.
"""
if isinstance(mapping, MultiDict):
for item in iteritems(mapping, multi=True):
yield item
elif isinstance(mapping, dict):
... | def iter_multi_items(mapping):
"""Iterates over the items of a mapping yielding keys and values
without dropping any from more complex structures.
"""
if isinstance(mapping, MultiDict):
for item in iteritems(mapping, multi=True):
yield item
elif isinstance(mapping, dict):
... | [
"Iterates",
"over",
"the",
"items",
"of",
"a",
"mapping",
"yielding",
"keys",
"and",
"values",
"without",
"dropping",
"any",
"from",
"more",
"complex",
"structures",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/datastructures.py#L39-L55 | [
"def",
"iter_multi_items",
"(",
"mapping",
")",
":",
"if",
"isinstance",
"(",
"mapping",
",",
"MultiDict",
")",
":",
"for",
"item",
"in",
"iteritems",
"(",
"mapping",
",",
"multi",
"=",
"True",
")",
":",
"yield",
"item",
"elif",
"isinstance",
"(",
"mappi... | a220671d66755a94630a212378754bb432811158 |
train | TypeConversionDict.get | Return the default value if the requested data doesn't exist.
If `type` is provided and is a callable it should convert the value,
return it or raise a :exc:`ValueError` if that is not possible. In
this case the function will return the default as if the value was not
found:
>>... | src/werkzeug/datastructures.py | def get(self, key, default=None, type=None):
"""Return the default value if the requested data doesn't exist.
If `type` is provided and is a callable it should convert the value,
return it or raise a :exc:`ValueError` if that is not possible. In
this case the function will return the de... | def get(self, key, default=None, type=None):
"""Return the default value if the requested data doesn't exist.
If `type` is provided and is a callable it should convert the value,
return it or raise a :exc:`ValueError` if that is not possible. In
this case the function will return the de... | [
"Return",
"the",
"default",
"value",
"if",
"the",
"requested",
"data",
"doesn",
"t",
"exist",
".",
"If",
"type",
"is",
"provided",
"and",
"is",
"a",
"callable",
"it",
"should",
"convert",
"the",
"value",
"return",
"it",
"or",
"raise",
"a",
":",
"exc",
... | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/datastructures.py#L292-L322 | [
"def",
"get",
"(",
"self",
",",
"key",
",",
"default",
"=",
"None",
",",
"type",
"=",
"None",
")",
":",
"try",
":",
"rv",
"=",
"self",
"[",
"key",
"]",
"except",
"KeyError",
":",
"return",
"default",
"if",
"type",
"is",
"not",
"None",
":",
"try",... | a220671d66755a94630a212378754bb432811158 |
train | _CacheControl._get_cache_value | Used internally by the accessor properties. | src/werkzeug/datastructures.py | def _get_cache_value(self, key, empty, type):
"""Used internally by the accessor properties."""
if type is bool:
return key in self
if key in self:
value = self[key]
if value is None:
return empty
elif type is not None:
... | def _get_cache_value(self, key, empty, type):
"""Used internally by the accessor properties."""
if type is bool:
return key in self
if key in self:
value = self[key]
if value is None:
return empty
elif type is not None:
... | [
"Used",
"internally",
"by",
"the",
"accessor",
"properties",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/datastructures.py#L1914-L1927 | [
"def",
"_get_cache_value",
"(",
"self",
",",
"key",
",",
"empty",
",",
"type",
")",
":",
"if",
"type",
"is",
"bool",
":",
"return",
"key",
"in",
"self",
"if",
"key",
"in",
"self",
":",
"value",
"=",
"self",
"[",
"key",
"]",
"if",
"value",
"is",
"... | a220671d66755a94630a212378754bb432811158 |
train | _CacheControl._set_cache_value | Used internally by the accessor properties. | src/werkzeug/datastructures.py | def _set_cache_value(self, key, value, type):
"""Used internally by the accessor properties."""
if type is bool:
if value:
self[key] = None
else:
self.pop(key, None)
else:
if value is None:
self.pop(key)
... | def _set_cache_value(self, key, value, type):
"""Used internally by the accessor properties."""
if type is bool:
if value:
self[key] = None
else:
self.pop(key, None)
else:
if value is None:
self.pop(key)
... | [
"Used",
"internally",
"by",
"the",
"accessor",
"properties",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/datastructures.py#L1929-L1942 | [
"def",
"_set_cache_value",
"(",
"self",
",",
"key",
",",
"value",
",",
"type",
")",
":",
"if",
"type",
"is",
"bool",
":",
"if",
"value",
":",
"self",
"[",
"key",
"]",
"=",
"None",
"else",
":",
"self",
".",
"pop",
"(",
"key",
",",
"None",
")",
"... | a220671d66755a94630a212378754bb432811158 |
train | HeaderSet.remove | Remove a header from the set. This raises an :exc:`KeyError` if the
header is not in the set.
.. versionchanged:: 0.5
In older versions a :exc:`IndexError` was raised instead of a
:exc:`KeyError` if the object was missing.
:param header: the header to be removed. | src/werkzeug/datastructures.py | def remove(self, header):
"""Remove a header from the set. This raises an :exc:`KeyError` if the
header is not in the set.
.. versionchanged:: 0.5
In older versions a :exc:`IndexError` was raised instead of a
:exc:`KeyError` if the object was missing.
:param he... | def remove(self, header):
"""Remove a header from the set. This raises an :exc:`KeyError` if the
header is not in the set.
.. versionchanged:: 0.5
In older versions a :exc:`IndexError` was raised instead of a
:exc:`KeyError` if the object was missing.
:param he... | [
"Remove",
"a",
"header",
"from",
"the",
"set",
".",
"This",
"raises",
"an",
":",
"exc",
":",
"KeyError",
"if",
"the",
"header",
"is",
"not",
"in",
"the",
"set",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/datastructures.py#L2045-L2064 | [
"def",
"remove",
"(",
"self",
",",
"header",
")",
":",
"key",
"=",
"header",
".",
"lower",
"(",
")",
"if",
"key",
"not",
"in",
"self",
".",
"_set",
":",
"raise",
"KeyError",
"(",
"header",
")",
"self",
".",
"_set",
".",
"remove",
"(",
"key",
")",... | a220671d66755a94630a212378754bb432811158 |
train | HeaderSet.update | Add all the headers from the iterable to the set.
:param iterable: updates the set with the items from the iterable. | src/werkzeug/datastructures.py | def update(self, iterable):
"""Add all the headers from the iterable to the set.
:param iterable: updates the set with the items from the iterable.
"""
inserted_any = False
for header in iterable:
key = header.lower()
if key not in self._set:
... | def update(self, iterable):
"""Add all the headers from the iterable to the set.
:param iterable: updates the set with the items from the iterable.
"""
inserted_any = False
for header in iterable:
key = header.lower()
if key not in self._set:
... | [
"Add",
"all",
"the",
"headers",
"from",
"the",
"iterable",
"to",
"the",
"set",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/datastructures.py#L2066-L2079 | [
"def",
"update",
"(",
"self",
",",
"iterable",
")",
":",
"inserted_any",
"=",
"False",
"for",
"header",
"in",
"iterable",
":",
"key",
"=",
"header",
".",
"lower",
"(",
")",
"if",
"key",
"not",
"in",
"self",
".",
"_set",
":",
"self",
".",
"_headers",
... | a220671d66755a94630a212378754bb432811158 |
train | HeaderSet.find | Return the index of the header in the set or return -1 if not found.
:param header: the header to be looked up. | src/werkzeug/datastructures.py | def find(self, header):
"""Return the index of the header in the set or return -1 if not found.
:param header: the header to be looked up.
"""
header = header.lower()
for idx, item in enumerate(self._headers):
if item.lower() == header:
return idx
... | def find(self, header):
"""Return the index of the header in the set or return -1 if not found.
:param header: the header to be looked up.
"""
header = header.lower()
for idx, item in enumerate(self._headers):
if item.lower() == header:
return idx
... | [
"Return",
"the",
"index",
"of",
"the",
"header",
"in",
"the",
"set",
"or",
"return",
"-",
"1",
"if",
"not",
"found",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/datastructures.py#L2091-L2100 | [
"def",
"find",
"(",
"self",
",",
"header",
")",
":",
"header",
"=",
"header",
".",
"lower",
"(",
")",
"for",
"idx",
",",
"item",
"in",
"enumerate",
"(",
"self",
".",
"_headers",
")",
":",
"if",
"item",
".",
"lower",
"(",
")",
"==",
"header",
":",... | a220671d66755a94630a212378754bb432811158 |
train | HeaderSet.index | Return the index of the header in the set or raise an
:exc:`IndexError`.
:param header: the header to be looked up. | src/werkzeug/datastructures.py | def index(self, header):
"""Return the index of the header in the set or raise an
:exc:`IndexError`.
:param header: the header to be looked up.
"""
rv = self.find(header)
if rv < 0:
raise IndexError(header)
return rv | def index(self, header):
"""Return the index of the header in the set or raise an
:exc:`IndexError`.
:param header: the header to be looked up.
"""
rv = self.find(header)
if rv < 0:
raise IndexError(header)
return rv | [
"Return",
"the",
"index",
"of",
"the",
"header",
"in",
"the",
"set",
"or",
"raise",
"an",
":",
"exc",
":",
"IndexError",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/datastructures.py#L2102-L2111 | [
"def",
"index",
"(",
"self",
",",
"header",
")",
":",
"rv",
"=",
"self",
".",
"find",
"(",
"header",
")",
"if",
"rv",
"<",
"0",
":",
"raise",
"IndexError",
"(",
"header",
")",
"return",
"rv"
] | a220671d66755a94630a212378754bb432811158 |
train | HeaderSet.clear | Clear the set. | src/werkzeug/datastructures.py | def clear(self):
"""Clear the set."""
self._set.clear()
del self._headers[:]
if self.on_update is not None:
self.on_update(self) | def clear(self):
"""Clear the set."""
self._set.clear()
del self._headers[:]
if self.on_update is not None:
self.on_update(self) | [
"Clear",
"the",
"set",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/datastructures.py#L2113-L2118 | [
"def",
"clear",
"(",
"self",
")",
":",
"self",
".",
"_set",
".",
"clear",
"(",
")",
"del",
"self",
".",
"_headers",
"[",
":",
"]",
"if",
"self",
".",
"on_update",
"is",
"not",
"None",
":",
"self",
".",
"on_update",
"(",
"self",
")"
] | a220671d66755a94630a212378754bb432811158 |
train | HeaderSet.as_set | Return the set as real python set type. When calling this, all
the items are converted to lowercase and the ordering is lost.
:param preserve_casing: if set to `True` the items in the set returned
will have the original case like in the
:... | src/werkzeug/datastructures.py | def as_set(self, preserve_casing=False):
"""Return the set as real python set type. When calling this, all
the items are converted to lowercase and the ordering is lost.
:param preserve_casing: if set to `True` the items in the set returned
will have the origina... | def as_set(self, preserve_casing=False):
"""Return the set as real python set type. When calling this, all
the items are converted to lowercase and the ordering is lost.
:param preserve_casing: if set to `True` the items in the set returned
will have the origina... | [
"Return",
"the",
"set",
"as",
"real",
"python",
"set",
"type",
".",
"When",
"calling",
"this",
"all",
"the",
"items",
"are",
"converted",
"to",
"lowercase",
"and",
"the",
"ordering",
"is",
"lost",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/datastructures.py#L2120-L2131 | [
"def",
"as_set",
"(",
"self",
",",
"preserve_casing",
"=",
"False",
")",
":",
"if",
"preserve_casing",
":",
"return",
"set",
"(",
"self",
".",
"_headers",
")",
"return",
"set",
"(",
"self",
".",
"_set",
")"
] | a220671d66755a94630a212378754bb432811158 |
train | ETags.as_set | Convert the `ETags` object into a python set. Per default all the
weak etags are not part of this set. | src/werkzeug/datastructures.py | def as_set(self, include_weak=False):
"""Convert the `ETags` object into a python set. Per default all the
weak etags are not part of this set."""
rv = set(self._strong)
if include_weak:
rv.update(self._weak)
return rv | def as_set(self, include_weak=False):
"""Convert the `ETags` object into a python set. Per default all the
weak etags are not part of this set."""
rv = set(self._strong)
if include_weak:
rv.update(self._weak)
return rv | [
"Convert",
"the",
"ETags",
"object",
"into",
"a",
"python",
"set",
".",
"Per",
"default",
"all",
"the",
"weak",
"etags",
"are",
"not",
"part",
"of",
"this",
"set",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/datastructures.py#L2183-L2189 | [
"def",
"as_set",
"(",
"self",
",",
"include_weak",
"=",
"False",
")",
":",
"rv",
"=",
"set",
"(",
"self",
".",
"_strong",
")",
"if",
"include_weak",
":",
"rv",
".",
"update",
"(",
"self",
".",
"_weak",
")",
"return",
"rv"
] | a220671d66755a94630a212378754bb432811158 |
train | ETags.contains_raw | When passed a quoted tag it will check if this tag is part of the
set. If the tag is weak it is checked against weak and strong tags,
otherwise strong only. | src/werkzeug/datastructures.py | def contains_raw(self, etag):
"""When passed a quoted tag it will check if this tag is part of the
set. If the tag is weak it is checked against weak and strong tags,
otherwise strong only."""
etag, weak = unquote_etag(etag)
if weak:
return self.contains_weak(etag)
... | def contains_raw(self, etag):
"""When passed a quoted tag it will check if this tag is part of the
set. If the tag is weak it is checked against weak and strong tags,
otherwise strong only."""
etag, weak = unquote_etag(etag)
if weak:
return self.contains_weak(etag)
... | [
"When",
"passed",
"a",
"quoted",
"tag",
"it",
"will",
"check",
"if",
"this",
"tag",
"is",
"part",
"of",
"the",
"set",
".",
"If",
"the",
"tag",
"is",
"weak",
"it",
"is",
"checked",
"against",
"weak",
"and",
"strong",
"tags",
"otherwise",
"strong",
"only... | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/datastructures.py#L2211-L2218 | [
"def",
"contains_raw",
"(",
"self",
",",
"etag",
")",
":",
"etag",
",",
"weak",
"=",
"unquote_etag",
"(",
"etag",
")",
"if",
"weak",
":",
"return",
"self",
".",
"contains_weak",
"(",
"etag",
")",
"return",
"self",
".",
"contains",
"(",
"etag",
")"
] | a220671d66755a94630a212378754bb432811158 |
train | ETags.to_header | Convert the etags set into a HTTP header string. | src/werkzeug/datastructures.py | def to_header(self):
"""Convert the etags set into a HTTP header string."""
if self.star_tag:
return "*"
return ", ".join(
['"%s"' % x for x in self._strong] + ['W/"%s"' % x for x in self._weak]
) | def to_header(self):
"""Convert the etags set into a HTTP header string."""
if self.star_tag:
return "*"
return ", ".join(
['"%s"' % x for x in self._strong] + ['W/"%s"' % x for x in self._weak]
) | [
"Convert",
"the",
"etags",
"set",
"into",
"a",
"HTTP",
"header",
"string",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/datastructures.py#L2220-L2226 | [
"def",
"to_header",
"(",
"self",
")",
":",
"if",
"self",
".",
"star_tag",
":",
"return",
"\"*\"",
"return",
"\", \"",
".",
"join",
"(",
"[",
"'\"%s\"'",
"%",
"x",
"for",
"x",
"in",
"self",
".",
"_strong",
"]",
"+",
"[",
"'W/\"%s\"'",
"%",
"x",
"for... | a220671d66755a94630a212378754bb432811158 |
train | IfRange.to_header | Converts the object back into an HTTP header. | src/werkzeug/datastructures.py | def to_header(self):
"""Converts the object back into an HTTP header."""
if self.date is not None:
return http_date(self.date)
if self.etag is not None:
return quote_etag(self.etag)
return "" | def to_header(self):
"""Converts the object back into an HTTP header."""
if self.date is not None:
return http_date(self.date)
if self.etag is not None:
return quote_etag(self.etag)
return "" | [
"Converts",
"the",
"object",
"back",
"into",
"an",
"HTTP",
"header",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/datastructures.py#L2271-L2277 | [
"def",
"to_header",
"(",
"self",
")",
":",
"if",
"self",
".",
"date",
"is",
"not",
"None",
":",
"return",
"http_date",
"(",
"self",
".",
"date",
")",
"if",
"self",
".",
"etag",
"is",
"not",
"None",
":",
"return",
"quote_etag",
"(",
"self",
".",
"et... | a220671d66755a94630a212378754bb432811158 |
train | Range.range_for_length | If the range is for bytes, the length is not None and there is
exactly one range and it is satisfiable it returns a ``(start, stop)``
tuple, otherwise `None`. | src/werkzeug/datastructures.py | def range_for_length(self, length):
"""If the range is for bytes, the length is not None and there is
exactly one range and it is satisfiable it returns a ``(start, stop)``
tuple, otherwise `None`.
"""
if self.units != "bytes" or length is None or len(self.ranges) != 1:
... | def range_for_length(self, length):
"""If the range is for bytes, the length is not None and there is
exactly one range and it is satisfiable it returns a ``(start, stop)``
tuple, otherwise `None`.
"""
if self.units != "bytes" or length is None or len(self.ranges) != 1:
... | [
"If",
"the",
"range",
"is",
"for",
"bytes",
"the",
"length",
"is",
"not",
"None",
"and",
"there",
"is",
"exactly",
"one",
"range",
"and",
"it",
"is",
"satisfiable",
"it",
"returns",
"a",
"(",
"start",
"stop",
")",
"tuple",
"otherwise",
"None",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/datastructures.py#L2310-L2323 | [
"def",
"range_for_length",
"(",
"self",
",",
"length",
")",
":",
"if",
"self",
".",
"units",
"!=",
"\"bytes\"",
"or",
"length",
"is",
"None",
"or",
"len",
"(",
"self",
".",
"ranges",
")",
"!=",
"1",
":",
"return",
"None",
"start",
",",
"end",
"=",
... | a220671d66755a94630a212378754bb432811158 |
train | Range.make_content_range | Creates a :class:`~werkzeug.datastructures.ContentRange` object
from the current range and given content length. | src/werkzeug/datastructures.py | def make_content_range(self, length):
"""Creates a :class:`~werkzeug.datastructures.ContentRange` object
from the current range and given content length.
"""
rng = self.range_for_length(length)
if rng is not None:
return ContentRange(self.units, rng[0], rng[1], length... | def make_content_range(self, length):
"""Creates a :class:`~werkzeug.datastructures.ContentRange` object
from the current range and given content length.
"""
rng = self.range_for_length(length)
if rng is not None:
return ContentRange(self.units, rng[0], rng[1], length... | [
"Creates",
"a",
":",
"class",
":",
"~werkzeug",
".",
"datastructures",
".",
"ContentRange",
"object",
"from",
"the",
"current",
"range",
"and",
"given",
"content",
"length",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/datastructures.py#L2325-L2331 | [
"def",
"make_content_range",
"(",
"self",
",",
"length",
")",
":",
"rng",
"=",
"self",
".",
"range_for_length",
"(",
"length",
")",
"if",
"rng",
"is",
"not",
"None",
":",
"return",
"ContentRange",
"(",
"self",
".",
"units",
",",
"rng",
"[",
"0",
"]",
... | a220671d66755a94630a212378754bb432811158 |
train | Range.to_header | Converts the object back into an HTTP header. | src/werkzeug/datastructures.py | def to_header(self):
"""Converts the object back into an HTTP header."""
ranges = []
for begin, end in self.ranges:
if end is None:
ranges.append("%s-" % begin if begin >= 0 else str(begin))
else:
ranges.append("%s-%s" % (begin, end - 1))
... | def to_header(self):
"""Converts the object back into an HTTP header."""
ranges = []
for begin, end in self.ranges:
if end is None:
ranges.append("%s-" % begin if begin >= 0 else str(begin))
else:
ranges.append("%s-%s" % (begin, end - 1))
... | [
"Converts",
"the",
"object",
"back",
"into",
"an",
"HTTP",
"header",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/datastructures.py#L2333-L2341 | [
"def",
"to_header",
"(",
"self",
")",
":",
"ranges",
"=",
"[",
"]",
"for",
"begin",
",",
"end",
"in",
"self",
".",
"ranges",
":",
"if",
"end",
"is",
"None",
":",
"ranges",
".",
"append",
"(",
"\"%s-\"",
"%",
"begin",
"if",
"begin",
">=",
"0",
"el... | a220671d66755a94630a212378754bb432811158 |
train | Range.to_content_range_header | Converts the object into `Content-Range` HTTP header,
based on given length | src/werkzeug/datastructures.py | def to_content_range_header(self, length):
"""Converts the object into `Content-Range` HTTP header,
based on given length
"""
range_for_length = self.range_for_length(length)
if range_for_length is not None:
return "%s %d-%d/%d" % (
self.units,
... | def to_content_range_header(self, length):
"""Converts the object into `Content-Range` HTTP header,
based on given length
"""
range_for_length = self.range_for_length(length)
if range_for_length is not None:
return "%s %d-%d/%d" % (
self.units,
... | [
"Converts",
"the",
"object",
"into",
"Content",
"-",
"Range",
"HTTP",
"header",
"based",
"on",
"given",
"length"
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/datastructures.py#L2343-L2355 | [
"def",
"to_content_range_header",
"(",
"self",
",",
"length",
")",
":",
"range_for_length",
"=",
"self",
".",
"range_for_length",
"(",
"length",
")",
"if",
"range_for_length",
"is",
"not",
"None",
":",
"return",
"\"%s %d-%d/%d\"",
"%",
"(",
"self",
".",
"units... | a220671d66755a94630a212378754bb432811158 |
train | WWWAuthenticate.set_digest | Clear the auth info and enable digest auth. | src/werkzeug/datastructures.py | def set_digest(
self, realm, nonce, qop=("auth",), opaque=None, algorithm=None, stale=False
):
"""Clear the auth info and enable digest auth."""
d = {
"__auth_type__": "digest",
"realm": realm,
"nonce": nonce,
"qop": dump_header(qop),
}... | def set_digest(
self, realm, nonce, qop=("auth",), opaque=None, algorithm=None, stale=False
):
"""Clear the auth info and enable digest auth."""
d = {
"__auth_type__": "digest",
"realm": realm,
"nonce": nonce,
"qop": dump_header(qop),
}... | [
"Clear",
"the",
"auth",
"info",
"and",
"enable",
"digest",
"auth",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/datastructures.py#L2538-L2557 | [
"def",
"set_digest",
"(",
"self",
",",
"realm",
",",
"nonce",
",",
"qop",
"=",
"(",
"\"auth\"",
",",
")",
",",
"opaque",
"=",
"None",
",",
"algorithm",
"=",
"None",
",",
"stale",
"=",
"False",
")",
":",
"d",
"=",
"{",
"\"__auth_type__\"",
":",
"\"d... | a220671d66755a94630a212378754bb432811158 |
train | WWWAuthenticate.to_header | Convert the stored values into a WWW-Authenticate header. | src/werkzeug/datastructures.py | def to_header(self):
"""Convert the stored values into a WWW-Authenticate header."""
d = dict(self)
auth_type = d.pop("__auth_type__", None) or "basic"
return "%s %s" % (
auth_type.title(),
", ".join(
[
"%s=%s"
... | def to_header(self):
"""Convert the stored values into a WWW-Authenticate header."""
d = dict(self)
auth_type = d.pop("__auth_type__", None) or "basic"
return "%s %s" % (
auth_type.title(),
", ".join(
[
"%s=%s"
... | [
"Convert",
"the",
"stored",
"values",
"into",
"a",
"WWW",
"-",
"Authenticate",
"header",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/datastructures.py#L2559-L2577 | [
"def",
"to_header",
"(",
"self",
")",
":",
"d",
"=",
"dict",
"(",
"self",
")",
"auth_type",
"=",
"d",
".",
"pop",
"(",
"\"__auth_type__\"",
",",
"None",
")",
"or",
"\"basic\"",
"return",
"\"%s %s\"",
"%",
"(",
"auth_type",
".",
"title",
"(",
")",
","... | a220671d66755a94630a212378754bb432811158 |
train | WWWAuthenticate.auth_property | A static helper function for subclasses to add extra authentication
system properties onto a class::
class FooAuthenticate(WWWAuthenticate):
special_realm = auth_property('special_realm')
For more information have a look at the sourcecode to see how the
regular prop... | src/werkzeug/datastructures.py | def auth_property(name, doc=None): # noqa: B902
"""A static helper function for subclasses to add extra authentication
system properties onto a class::
class FooAuthenticate(WWWAuthenticate):
special_realm = auth_property('special_realm')
For more information have ... | def auth_property(name, doc=None): # noqa: B902
"""A static helper function for subclasses to add extra authentication
system properties onto a class::
class FooAuthenticate(WWWAuthenticate):
special_realm = auth_property('special_realm')
For more information have ... | [
"A",
"static",
"helper",
"function",
"for",
"subclasses",
"to",
"add",
"extra",
"authentication",
"system",
"properties",
"onto",
"a",
"class",
"::"
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/datastructures.py#L2585-L2602 | [
"def",
"auth_property",
"(",
"name",
",",
"doc",
"=",
"None",
")",
":",
"# noqa: B902",
"def",
"_set_value",
"(",
"self",
",",
"value",
")",
":",
"if",
"value",
"is",
"None",
":",
"self",
".",
"pop",
"(",
"name",
",",
"None",
")",
"else",
":",
"sel... | a220671d66755a94630a212378754bb432811158 |
train | FileStorage.save | Save the file to a destination path or file object. If the
destination is a file object you have to close it yourself after the
call. The buffer size is the number of bytes held in memory during
the copy process. It defaults to 16KB.
For secure file saving also have a look at :func:`... | src/werkzeug/datastructures.py | def save(self, dst, buffer_size=16384):
"""Save the file to a destination path or file object. If the
destination is a file object you have to close it yourself after the
call. The buffer size is the number of bytes held in memory during
the copy process. It defaults to 16KB.
... | def save(self, dst, buffer_size=16384):
"""Save the file to a destination path or file object. If the
destination is a file object you have to close it yourself after the
call. The buffer size is the number of bytes held in memory during
the copy process. It defaults to 16KB.
... | [
"Save",
"the",
"file",
"to",
"a",
"destination",
"path",
"or",
"file",
"object",
".",
"If",
"the",
"destination",
"is",
"a",
"file",
"object",
"you",
"have",
"to",
"close",
"it",
"yourself",
"after",
"the",
"call",
".",
"The",
"buffer",
"size",
"is",
"... | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/datastructures.py#L2766-L2790 | [
"def",
"save",
"(",
"self",
",",
"dst",
",",
"buffer_size",
"=",
"16384",
")",
":",
"from",
"shutil",
"import",
"copyfileobj",
"close_dst",
"=",
"False",
"if",
"isinstance",
"(",
"dst",
",",
"string_types",
")",
":",
"dst",
"=",
"open",
"(",
"dst",
","... | a220671d66755a94630a212378754bb432811158 |
train | BaseResponse.force_type | Enforce that the WSGI response is a response object of the current
type. Werkzeug will use the :class:`BaseResponse` internally in many
situations like the exceptions. If you call :meth:`get_response` on an
exception you will get back a regular :class:`BaseResponse` object, even
if you... | src/werkzeug/wrappers/base_response.py | def force_type(cls, response, environ=None):
"""Enforce that the WSGI response is a response object of the current
type. Werkzeug will use the :class:`BaseResponse` internally in many
situations like the exceptions. If you call :meth:`get_response` on an
exception you will get back a r... | def force_type(cls, response, environ=None):
"""Enforce that the WSGI response is a response object of the current
type. Werkzeug will use the :class:`BaseResponse` internally in many
situations like the exceptions. If you call :meth:`get_response` on an
exception you will get back a r... | [
"Enforce",
"that",
"the",
"WSGI",
"response",
"is",
"a",
"response",
"object",
"of",
"the",
"current",
"type",
".",
"Werkzeug",
"will",
"use",
"the",
":",
"class",
":",
"BaseResponse",
"internally",
"in",
"many",
"situations",
"like",
"the",
"exceptions",
".... | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/wrappers/base_response.py#L235-L271 | [
"def",
"force_type",
"(",
"cls",
",",
"response",
",",
"environ",
"=",
"None",
")",
":",
"if",
"not",
"isinstance",
"(",
"response",
",",
"BaseResponse",
")",
":",
"if",
"environ",
"is",
"None",
":",
"raise",
"TypeError",
"(",
"\"cannot convert WSGI applicat... | a220671d66755a94630a212378754bb432811158 |
train | BaseResponse.from_app | Create a new response object from an application output. This
works best if you pass it an application that returns a generator all
the time. Sometimes applications may use the `write()` callable
returned by the `start_response` function. This tries to resolve such
edge cases automati... | src/werkzeug/wrappers/base_response.py | def from_app(cls, app, environ, buffered=False):
"""Create a new response object from an application output. This
works best if you pass it an application that returns a generator all
the time. Sometimes applications may use the `write()` callable
returned by the `start_response` funct... | def from_app(cls, app, environ, buffered=False):
"""Create a new response object from an application output. This
works best if you pass it an application that returns a generator all
the time. Sometimes applications may use the `write()` callable
returned by the `start_response` funct... | [
"Create",
"a",
"new",
"response",
"object",
"from",
"an",
"application",
"output",
".",
"This",
"works",
"best",
"if",
"you",
"pass",
"it",
"an",
"application",
"that",
"returns",
"a",
"generator",
"all",
"the",
"time",
".",
"Sometimes",
"applications",
"may... | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/wrappers/base_response.py#L274-L287 | [
"def",
"from_app",
"(",
"cls",
",",
"app",
",",
"environ",
",",
"buffered",
"=",
"False",
")",
":",
"return",
"cls",
"(",
"*",
"_run_wsgi_app",
"(",
"app",
",",
"environ",
",",
"buffered",
")",
")"
] | a220671d66755a94630a212378754bb432811158 |
train | BaseResponse.calculate_content_length | Returns the content length if available or `None` otherwise. | src/werkzeug/wrappers/base_response.py | def calculate_content_length(self):
"""Returns the content length if available or `None` otherwise."""
try:
self._ensure_sequence()
except RuntimeError:
return None
return sum(len(x) for x in self.iter_encoded()) | def calculate_content_length(self):
"""Returns the content length if available or `None` otherwise."""
try:
self._ensure_sequence()
except RuntimeError:
return None
return sum(len(x) for x in self.iter_encoded()) | [
"Returns",
"the",
"content",
"length",
"if",
"available",
"or",
"None",
"otherwise",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/wrappers/base_response.py#L366-L372 | [
"def",
"calculate_content_length",
"(",
"self",
")",
":",
"try",
":",
"self",
".",
"_ensure_sequence",
"(",
")",
"except",
"RuntimeError",
":",
"return",
"None",
"return",
"sum",
"(",
"len",
"(",
"x",
")",
"for",
"x",
"in",
"self",
".",
"iter_encoded",
"... | a220671d66755a94630a212378754bb432811158 |
train | BaseResponse.make_sequence | Converts the response iterator in a list. By default this happens
automatically if required. If `implicit_sequence_conversion` is
disabled, this method is not automatically called and some properties
might raise exceptions. This also encodes all the items.
.. versionadded:: 0.6 | src/werkzeug/wrappers/base_response.py | def make_sequence(self):
"""Converts the response iterator in a list. By default this happens
automatically if required. If `implicit_sequence_conversion` is
disabled, this method is not automatically called and some properties
might raise exceptions. This also encodes all the items.
... | def make_sequence(self):
"""Converts the response iterator in a list. By default this happens
automatically if required. If `implicit_sequence_conversion` is
disabled, this method is not automatically called and some properties
might raise exceptions. This also encodes all the items.
... | [
"Converts",
"the",
"response",
"iterator",
"in",
"a",
"list",
".",
"By",
"default",
"this",
"happens",
"automatically",
"if",
"required",
".",
"If",
"implicit_sequence_conversion",
"is",
"disabled",
"this",
"method",
"is",
"not",
"automatically",
"called",
"and",
... | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/wrappers/base_response.py#L399-L414 | [
"def",
"make_sequence",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"is_sequence",
":",
"# if we consume an iterable we have to ensure that the close",
"# method of the iterable is called if available when we tear",
"# down the response",
"close",
"=",
"getattr",
"(",
"sel... | a220671d66755a94630a212378754bb432811158 |
train | BaseResponse.set_cookie | Sets a cookie. The parameters are the same as in the cookie `Morsel`
object in the Python standard library but it accepts unicode data, too.
A warning is raised if the size of the cookie header exceeds
:attr:`max_cookie_size`, but the header will still be set.
:param key: the key (name... | src/werkzeug/wrappers/base_response.py | def set_cookie(
self,
key,
value="",
max_age=None,
expires=None,
path="/",
domain=None,
secure=False,
httponly=False,
samesite=None,
):
"""Sets a cookie. The parameters are the same as in the cookie `Morsel`
object in th... | def set_cookie(
self,
key,
value="",
max_age=None,
expires=None,
path="/",
domain=None,
secure=False,
httponly=False,
samesite=None,
):
"""Sets a cookie. The parameters are the same as in the cookie `Morsel`
object in th... | [
"Sets",
"a",
"cookie",
".",
"The",
"parameters",
"are",
"the",
"same",
"as",
"in",
"the",
"cookie",
"Morsel",
"object",
"in",
"the",
"Python",
"standard",
"library",
"but",
"it",
"accepts",
"unicode",
"data",
"too",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/wrappers/base_response.py#L429-L483 | [
"def",
"set_cookie",
"(",
"self",
",",
"key",
",",
"value",
"=",
"\"\"",
",",
"max_age",
"=",
"None",
",",
"expires",
"=",
"None",
",",
"path",
"=",
"\"/\"",
",",
"domain",
"=",
"None",
",",
"secure",
"=",
"False",
",",
"httponly",
"=",
"False",
",... | a220671d66755a94630a212378754bb432811158 |
train | BaseResponse.close | Close the wrapped response if possible. You can also use the object
in a with statement which will automatically close it.
.. versionadded:: 0.9
Can now be used in a with statement. | src/werkzeug/wrappers/base_response.py | def close(self):
"""Close the wrapped response if possible. You can also use the object
in a with statement which will automatically close it.
.. versionadded:: 0.9
Can now be used in a with statement.
"""
if hasattr(self.response, "close"):
self.response... | def close(self):
"""Close the wrapped response if possible. You can also use the object
in a with statement which will automatically close it.
.. versionadded:: 0.9
Can now be used in a with statement.
"""
if hasattr(self.response, "close"):
self.response... | [
"Close",
"the",
"wrapped",
"response",
"if",
"possible",
".",
"You",
"can",
"also",
"use",
"the",
"object",
"in",
"a",
"with",
"statement",
"which",
"will",
"automatically",
"close",
"it",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/wrappers/base_response.py#L522-L532 | [
"def",
"close",
"(",
"self",
")",
":",
"if",
"hasattr",
"(",
"self",
".",
"response",
",",
"\"close\"",
")",
":",
"self",
".",
"response",
".",
"close",
"(",
")",
"for",
"func",
"in",
"self",
".",
"_on_close",
":",
"func",
"(",
")"
] | a220671d66755a94630a212378754bb432811158 |
train | BaseResponse.get_wsgi_headers | This is automatically called right before the response is started
and returns headers modified for the given environment. It returns a
copy of the headers from the response with some modifications applied
if necessary.
For example the location header (if present) is joined with the roo... | src/werkzeug/wrappers/base_response.py | def get_wsgi_headers(self, environ):
"""This is automatically called right before the response is started
and returns headers modified for the given environment. It returns a
copy of the headers from the response with some modifications applied
if necessary.
For example the loc... | def get_wsgi_headers(self, environ):
"""This is automatically called right before the response is started
and returns headers modified for the given environment. It returns a
copy of the headers from the response with some modifications applied
if necessary.
For example the loc... | [
"This",
"is",
"automatically",
"called",
"right",
"before",
"the",
"response",
"is",
"started",
"and",
"returns",
"headers",
"modified",
"for",
"the",
"given",
"environment",
".",
"It",
"returns",
"a",
"copy",
"of",
"the",
"headers",
"from",
"the",
"response",... | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/wrappers/base_response.py#L553-L644 | [
"def",
"get_wsgi_headers",
"(",
"self",
",",
"environ",
")",
":",
"headers",
"=",
"Headers",
"(",
"self",
".",
"headers",
")",
"location",
"=",
"None",
"content_location",
"=",
"None",
"content_length",
"=",
"None",
"status",
"=",
"self",
".",
"status_code",... | a220671d66755a94630a212378754bb432811158 |
train | BaseResponse.get_wsgi_response | Returns the final WSGI response as tuple. The first item in
the tuple is the application iterator, the second the status and
the third the list of headers. The response returned is created
specially for the given environment. For example if the request
method in the WSGI environment i... | src/werkzeug/wrappers/base_response.py | def get_wsgi_response(self, environ):
"""Returns the final WSGI response as tuple. The first item in
the tuple is the application iterator, the second the status and
the third the list of headers. The response returned is created
specially for the given environment. For example if the... | def get_wsgi_response(self, environ):
"""Returns the final WSGI response as tuple. The first item in
the tuple is the application iterator, the second the status and
the third the list of headers. The response returned is created
specially for the given environment. For example if the... | [
"Returns",
"the",
"final",
"WSGI",
"response",
"as",
"tuple",
".",
"The",
"first",
"item",
"in",
"the",
"tuple",
"is",
"the",
"application",
"iterator",
"the",
"second",
"the",
"status",
"and",
"the",
"third",
"the",
"list",
"of",
"headers",
".",
"The",
... | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/wrappers/base_response.py#L675-L690 | [
"def",
"get_wsgi_response",
"(",
"self",
",",
"environ",
")",
":",
"headers",
"=",
"self",
".",
"get_wsgi_headers",
"(",
"environ",
")",
"app_iter",
"=",
"self",
".",
"get_app_iter",
"(",
"environ",
")",
"return",
"app_iter",
",",
"self",
".",
"status",
",... | a220671d66755a94630a212378754bb432811158 |
train | pbkdf2_bin | Returns a binary digest for the PBKDF2 hash algorithm of `data`
with the given `salt`. It iterates `iterations` times and produces a
key of `keylen` bytes. By default, SHA-256 is used as hash function;
a different hashlib `hashfunc` can be provided.
.. versionadded:: 0.9
:param data: the data to d... | src/werkzeug/security.py | def pbkdf2_bin(
data, salt, iterations=DEFAULT_PBKDF2_ITERATIONS, keylen=None, hashfunc=None
):
"""Returns a binary digest for the PBKDF2 hash algorithm of `data`
with the given `salt`. It iterates `iterations` times and produces a
key of `keylen` bytes. By default, SHA-256 is used as hash function;
... | def pbkdf2_bin(
data, salt, iterations=DEFAULT_PBKDF2_ITERATIONS, keylen=None, hashfunc=None
):
"""Returns a binary digest for the PBKDF2 hash algorithm of `data`
with the given `salt`. It iterates `iterations` times and produces a
key of `keylen` bytes. By default, SHA-256 is used as hash function;
... | [
"Returns",
"a",
"binary",
"digest",
"for",
"the",
"PBKDF2",
"hash",
"algorithm",
"of",
"data",
"with",
"the",
"given",
"salt",
".",
"It",
"iterates",
"iterations",
"times",
"and",
"produces",
"a",
"key",
"of",
"keylen",
"bytes",
".",
"By",
"default",
"SHA"... | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/security.py#L57-L87 | [
"def",
"pbkdf2_bin",
"(",
"data",
",",
"salt",
",",
"iterations",
"=",
"DEFAULT_PBKDF2_ITERATIONS",
",",
"keylen",
"=",
"None",
",",
"hashfunc",
"=",
"None",
")",
":",
"if",
"not",
"hashfunc",
":",
"hashfunc",
"=",
"\"sha256\"",
"data",
"=",
"to_bytes",
"(... | a220671d66755a94630a212378754bb432811158 |
train | _hash_internal | Internal password hash helper. Supports plaintext without salt,
unsalted and salted passwords. In case salted passwords are used
hmac is used. | src/werkzeug/security.py | def _hash_internal(method, salt, password):
"""Internal password hash helper. Supports plaintext without salt,
unsalted and salted passwords. In case salted passwords are used
hmac is used.
"""
if method == "plain":
return password, method
if isinstance(password, text_type):
p... | def _hash_internal(method, salt, password):
"""Internal password hash helper. Supports plaintext without salt,
unsalted and salted passwords. In case salted passwords are used
hmac is used.
"""
if method == "plain":
return password, method
if isinstance(password, text_type):
p... | [
"Internal",
"password",
"hash",
"helper",
".",
"Supports",
"plaintext",
"without",
"salt",
"unsalted",
"and",
"salted",
"passwords",
".",
"In",
"case",
"salted",
"passwords",
"are",
"used",
"hmac",
"is",
"used",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/security.py#L127-L161 | [
"def",
"_hash_internal",
"(",
"method",
",",
"salt",
",",
"password",
")",
":",
"if",
"method",
"==",
"\"plain\"",
":",
"return",
"password",
",",
"method",
"if",
"isinstance",
"(",
"password",
",",
"text_type",
")",
":",
"password",
"=",
"password",
".",
... | a220671d66755a94630a212378754bb432811158 |
train | safe_join | Safely join `directory` and one or more untrusted `pathnames`. If this
cannot be done, this function returns ``None``.
:param directory: the base directory.
:param pathnames: the untrusted pathnames relative to that directory. | src/werkzeug/security.py | def safe_join(directory, *pathnames):
"""Safely join `directory` and one or more untrusted `pathnames`. If this
cannot be done, this function returns ``None``.
:param directory: the base directory.
:param pathnames: the untrusted pathnames relative to that directory.
"""
parts = [directory]
... | def safe_join(directory, *pathnames):
"""Safely join `directory` and one or more untrusted `pathnames`. If this
cannot be done, this function returns ``None``.
:param directory: the base directory.
:param pathnames: the untrusted pathnames relative to that directory.
"""
parts = [directory]
... | [
"Safely",
"join",
"directory",
"and",
"one",
"or",
"more",
"untrusted",
"pathnames",
".",
"If",
"this",
"cannot",
"be",
"done",
"this",
"function",
"returns",
"None",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/security.py#L224-L241 | [
"def",
"safe_join",
"(",
"directory",
",",
"*",
"pathnames",
")",
":",
"parts",
"=",
"[",
"directory",
"]",
"for",
"filename",
"in",
"pathnames",
":",
"if",
"filename",
"!=",
"\"\"",
":",
"filename",
"=",
"posixpath",
".",
"normpath",
"(",
"filename",
")... | a220671d66755a94630a212378754bb432811158 |
train | generate_adhoc_ssl_context | Generates an adhoc SSL context for the development server. | src/werkzeug/serving.py | def generate_adhoc_ssl_context():
"""Generates an adhoc SSL context for the development server."""
crypto = _get_openssl_crypto_module()
import tempfile
import atexit
cert, pkey = generate_adhoc_ssl_pair()
cert_handle, cert_file = tempfile.mkstemp()
pkey_handle, pkey_file = tempfile.mkstemp... | def generate_adhoc_ssl_context():
"""Generates an adhoc SSL context for the development server."""
crypto = _get_openssl_crypto_module()
import tempfile
import atexit
cert, pkey = generate_adhoc_ssl_pair()
cert_handle, cert_file = tempfile.mkstemp()
pkey_handle, pkey_file = tempfile.mkstemp... | [
"Generates",
"an",
"adhoc",
"SSL",
"context",
"for",
"the",
"development",
"server",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/serving.py#L532-L549 | [
"def",
"generate_adhoc_ssl_context",
"(",
")",
":",
"crypto",
"=",
"_get_openssl_crypto_module",
"(",
")",
"import",
"tempfile",
"import",
"atexit",
"cert",
",",
"pkey",
"=",
"generate_adhoc_ssl_pair",
"(",
")",
"cert_handle",
",",
"cert_file",
"=",
"tempfile",
".... | a220671d66755a94630a212378754bb432811158 |
train | load_ssl_context | Loads SSL context from cert/private key files and optional protocol.
Many parameters are directly taken from the API of
:py:class:`ssl.SSLContext`.
:param cert_file: Path of the certificate to use.
:param pkey_file: Path of the private key to use. If not given, the key
will be obt... | src/werkzeug/serving.py | def load_ssl_context(cert_file, pkey_file=None, protocol=None):
"""Loads SSL context from cert/private key files and optional protocol.
Many parameters are directly taken from the API of
:py:class:`ssl.SSLContext`.
:param cert_file: Path of the certificate to use.
:param pkey_file: Path of the priv... | def load_ssl_context(cert_file, pkey_file=None, protocol=None):
"""Loads SSL context from cert/private key files and optional protocol.
Many parameters are directly taken from the API of
:py:class:`ssl.SSLContext`.
:param cert_file: Path of the certificate to use.
:param pkey_file: Path of the priv... | [
"Loads",
"SSL",
"context",
"from",
"cert",
"/",
"private",
"key",
"files",
"and",
"optional",
"protocol",
".",
"Many",
"parameters",
"are",
"directly",
"taken",
"from",
"the",
"API",
"of",
":",
"py",
":",
"class",
":",
"ssl",
".",
"SSLContext",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/serving.py#L552-L567 | [
"def",
"load_ssl_context",
"(",
"cert_file",
",",
"pkey_file",
"=",
"None",
",",
"protocol",
"=",
"None",
")",
":",
"if",
"protocol",
"is",
"None",
":",
"protocol",
"=",
"ssl",
".",
"PROTOCOL_SSLv23",
"ctx",
"=",
"_SSLContext",
"(",
"protocol",
")",
"ctx",... | a220671d66755a94630a212378754bb432811158 |
train | is_ssl_error | Checks if the given error (or the current one) is an SSL error. | src/werkzeug/serving.py | def is_ssl_error(error=None):
"""Checks if the given error (or the current one) is an SSL error."""
exc_types = (ssl.SSLError,)
try:
from OpenSSL.SSL import Error
exc_types += (Error,)
except ImportError:
pass
if error is None:
error = sys.exc_info()[1]
return i... | def is_ssl_error(error=None):
"""Checks if the given error (or the current one) is an SSL error."""
exc_types = (ssl.SSLError,)
try:
from OpenSSL.SSL import Error
exc_types += (Error,)
except ImportError:
pass
if error is None:
error = sys.exc_info()[1]
return i... | [
"Checks",
"if",
"the",
"given",
"error",
"(",
"or",
"the",
"current",
"one",
")",
"is",
"an",
"SSL",
"error",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/serving.py#L596-L608 | [
"def",
"is_ssl_error",
"(",
"error",
"=",
"None",
")",
":",
"exc_types",
"=",
"(",
"ssl",
".",
"SSLError",
",",
")",
"try",
":",
"from",
"OpenSSL",
".",
"SSL",
"import",
"Error",
"exc_types",
"+=",
"(",
"Error",
",",
")",
"except",
"ImportError",
":",
... | a220671d66755a94630a212378754bb432811158 |
train | select_address_family | Return ``AF_INET4``, ``AF_INET6``, or ``AF_UNIX`` depending on
the host and port. | src/werkzeug/serving.py | def select_address_family(host, port):
"""Return ``AF_INET4``, ``AF_INET6``, or ``AF_UNIX`` depending on
the host and port."""
# disabled due to problems with current ipv6 implementations
# and various operating systems. Probably this code also is
# not supposed to work, but I can't come up with an... | def select_address_family(host, port):
"""Return ``AF_INET4``, ``AF_INET6``, or ``AF_UNIX`` depending on
the host and port."""
# disabled due to problems with current ipv6 implementations
# and various operating systems. Probably this code also is
# not supposed to work, but I can't come up with an... | [
"Return",
"AF_INET4",
"AF_INET6",
"or",
"AF_UNIX",
"depending",
"on",
"the",
"host",
"and",
"port",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/serving.py#L611-L630 | [
"def",
"select_address_family",
"(",
"host",
",",
"port",
")",
":",
"# disabled due to problems with current ipv6 implementations",
"# and various operating systems. Probably this code also is",
"# not supposed to work, but I can't come up with any other",
"# ways to implement this.",
"# tr... | a220671d66755a94630a212378754bb432811158 |
train | get_sockaddr | Return a fully qualified socket address that can be passed to
:func:`socket.bind`. | src/werkzeug/serving.py | def get_sockaddr(host, port, family):
"""Return a fully qualified socket address that can be passed to
:func:`socket.bind`."""
if family == af_unix:
return host.split("://", 1)[1]
try:
res = socket.getaddrinfo(
host, port, family, socket.SOCK_STREAM, socket.IPPROTO_TCP
... | def get_sockaddr(host, port, family):
"""Return a fully qualified socket address that can be passed to
:func:`socket.bind`."""
if family == af_unix:
return host.split("://", 1)[1]
try:
res = socket.getaddrinfo(
host, port, family, socket.SOCK_STREAM, socket.IPPROTO_TCP
... | [
"Return",
"a",
"fully",
"qualified",
"socket",
"address",
"that",
"can",
"be",
"passed",
"to",
":",
"func",
":",
"socket",
".",
"bind",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/serving.py#L633-L644 | [
"def",
"get_sockaddr",
"(",
"host",
",",
"port",
",",
"family",
")",
":",
"if",
"family",
"==",
"af_unix",
":",
"return",
"host",
".",
"split",
"(",
"\"://\"",
",",
"1",
")",
"[",
"1",
"]",
"try",
":",
"res",
"=",
"socket",
".",
"getaddrinfo",
"(",... | a220671d66755a94630a212378754bb432811158 |
train | run_simple | Start a WSGI application. Optional features include a reloader,
multithreading and fork support.
This function has a command-line interface too::
python -m werkzeug.serving --help
.. versionadded:: 0.5
`static_files` was added to simplify serving of static files as well
as `passthro... | src/werkzeug/serving.py | def run_simple(
hostname,
port,
application,
use_reloader=False,
use_debugger=False,
use_evalex=True,
extra_files=None,
reloader_interval=1,
reloader_type="auto",
threaded=False,
processes=1,
request_handler=None,
static_files=None,
passthrough_errors=False,
s... | def run_simple(
hostname,
port,
application,
use_reloader=False,
use_debugger=False,
use_evalex=True,
extra_files=None,
reloader_interval=1,
reloader_type="auto",
threaded=False,
processes=1,
request_handler=None,
static_files=None,
passthrough_errors=False,
s... | [
"Start",
"a",
"WSGI",
"application",
".",
"Optional",
"features",
"include",
"a",
"reloader",
"multithreading",
"and",
"fork",
"support",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/serving.py#L814-L990 | [
"def",
"run_simple",
"(",
"hostname",
",",
"port",
",",
"application",
",",
"use_reloader",
"=",
"False",
",",
"use_debugger",
"=",
"False",
",",
"use_evalex",
"=",
"True",
",",
"extra_files",
"=",
"None",
",",
"reloader_interval",
"=",
"1",
",",
"reloader_t... | a220671d66755a94630a212378754bb432811158 |
train | main | A simple command-line interface for :py:func:`run_simple`. | src/werkzeug/serving.py | def main():
"""A simple command-line interface for :py:func:`run_simple`."""
# in contrast to argparse, this works at least under Python < 2.7
import optparse
from .utils import import_string
parser = optparse.OptionParser(usage="Usage: %prog [options] app_module:app_object")
parser.add_option... | def main():
"""A simple command-line interface for :py:func:`run_simple`."""
# in contrast to argparse, this works at least under Python < 2.7
import optparse
from .utils import import_string
parser = optparse.OptionParser(usage="Usage: %prog [options] app_module:app_object")
parser.add_option... | [
"A",
"simple",
"command",
"-",
"line",
"interface",
"for",
":",
"py",
":",
"func",
":",
"run_simple",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/serving.py#L1001-L1051 | [
"def",
"main",
"(",
")",
":",
"# in contrast to argparse, this works at least under Python < 2.7",
"import",
"optparse",
"from",
".",
"utils",
"import",
"import_string",
"parser",
"=",
"optparse",
".",
"OptionParser",
"(",
"usage",
"=",
"\"Usage: %prog [options] app_module:... | a220671d66755a94630a212378754bb432811158 |
train | WSGIRequestHandler.handle | Handles a request ignoring dropped connections. | src/werkzeug/serving.py | def handle(self):
"""Handles a request ignoring dropped connections."""
rv = None
try:
rv = BaseHTTPRequestHandler.handle(self)
except (_ConnectionError, socket.timeout) as e:
self.connection_dropped(e)
except Exception as e:
if self.server.ssl... | def handle(self):
"""Handles a request ignoring dropped connections."""
rv = None
try:
rv = BaseHTTPRequestHandler.handle(self)
except (_ConnectionError, socket.timeout) as e:
self.connection_dropped(e)
except Exception as e:
if self.server.ssl... | [
"Handles",
"a",
"request",
"ignoring",
"dropped",
"connections",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/serving.py#L321-L333 | [
"def",
"handle",
"(",
"self",
")",
":",
"rv",
"=",
"None",
"try",
":",
"rv",
"=",
"BaseHTTPRequestHandler",
".",
"handle",
"(",
"self",
")",
"except",
"(",
"_ConnectionError",
",",
"socket",
".",
"timeout",
")",
"as",
"e",
":",
"self",
".",
"connection... | a220671d66755a94630a212378754bb432811158 |
train | WSGIRequestHandler.initiate_shutdown | A horrible, horrible way to kill the server for Python 2.6 and
later. It's the best we can do. | src/werkzeug/serving.py | def initiate_shutdown(self):
"""A horrible, horrible way to kill the server for Python 2.6 and
later. It's the best we can do.
"""
# Windows does not provide SIGKILL, go with SIGTERM then.
sig = getattr(signal, "SIGKILL", signal.SIGTERM)
# reloader active
if is_r... | def initiate_shutdown(self):
"""A horrible, horrible way to kill the server for Python 2.6 and
later. It's the best we can do.
"""
# Windows does not provide SIGKILL, go with SIGTERM then.
sig = getattr(signal, "SIGKILL", signal.SIGTERM)
# reloader active
if is_r... | [
"A",
"horrible",
"horrible",
"way",
"to",
"kill",
"the",
"server",
"for",
"Python",
"2",
".",
"6",
"and",
"later",
".",
"It",
"s",
"the",
"best",
"we",
"can",
"do",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/serving.py#L335-L347 | [
"def",
"initiate_shutdown",
"(",
"self",
")",
":",
"# Windows does not provide SIGKILL, go with SIGTERM then.",
"sig",
"=",
"getattr",
"(",
"signal",
",",
"\"SIGKILL\"",
",",
"signal",
".",
"SIGTERM",
")",
"# reloader active",
"if",
"is_running_from_reloader",
"(",
")",... | a220671d66755a94630a212378754bb432811158 |
train | WSGIRequestHandler.handle_one_request | Handle a single HTTP request. | src/werkzeug/serving.py | def handle_one_request(self):
"""Handle a single HTTP request."""
self.raw_requestline = self.rfile.readline()
if not self.raw_requestline:
self.close_connection = 1
elif self.parse_request():
return self.run_wsgi() | def handle_one_request(self):
"""Handle a single HTTP request."""
self.raw_requestline = self.rfile.readline()
if not self.raw_requestline:
self.close_connection = 1
elif self.parse_request():
return self.run_wsgi() | [
"Handle",
"a",
"single",
"HTTP",
"request",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/serving.py#L354-L360 | [
"def",
"handle_one_request",
"(",
"self",
")",
":",
"self",
".",
"raw_requestline",
"=",
"self",
".",
"rfile",
".",
"readline",
"(",
")",
"if",
"not",
"self",
".",
"raw_requestline",
":",
"self",
".",
"close_connection",
"=",
"1",
"elif",
"self",
".",
"p... | a220671d66755a94630a212378754bb432811158 |
train | WSGIRequestHandler.send_response | Send the response header and log the response code. | src/werkzeug/serving.py | def send_response(self, code, message=None):
"""Send the response header and log the response code."""
self.log_request(code)
if message is None:
message = code in self.responses and self.responses[code][0] or ""
if self.request_version != "HTTP/0.9":
hdr = "%s %d... | def send_response(self, code, message=None):
"""Send the response header and log the response code."""
self.log_request(code)
if message is None:
message = code in self.responses and self.responses[code][0] or ""
if self.request_version != "HTTP/0.9":
hdr = "%s %d... | [
"Send",
"the",
"response",
"header",
"and",
"log",
"the",
"response",
"code",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/serving.py#L362-L369 | [
"def",
"send_response",
"(",
"self",
",",
"code",
",",
"message",
"=",
"None",
")",
":",
"self",
".",
"log_request",
"(",
"code",
")",
"if",
"message",
"is",
"None",
":",
"message",
"=",
"code",
"in",
"self",
".",
"responses",
"and",
"self",
".",
"re... | a220671d66755a94630a212378754bb432811158 |
train | WSGIRequestHandler.get_header_items | Get an iterable list of key/value pairs representing headers.
This function provides Python 2/3 compatibility as related to the
parsing of request headers. Python 2.7 is not compliant with
RFC 3875 Section 4.1.18 which requires multiple values for headers
to be provided. This function w... | src/werkzeug/serving.py | def get_header_items(self):
"""
Get an iterable list of key/value pairs representing headers.
This function provides Python 2/3 compatibility as related to the
parsing of request headers. Python 2.7 is not compliant with
RFC 3875 Section 4.1.18 which requires multiple values for... | def get_header_items(self):
"""
Get an iterable list of key/value pairs representing headers.
This function provides Python 2/3 compatibility as related to the
parsing of request headers. Python 2.7 is not compliant with
RFC 3875 Section 4.1.18 which requires multiple values for... | [
"Get",
"an",
"iterable",
"list",
"of",
"key",
"/",
"value",
"pairs",
"representing",
"headers",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/serving.py#L430-L460 | [
"def",
"get_header_items",
"(",
"self",
")",
":",
"if",
"PY2",
":",
"# For Python 2, process the headers manually according to",
"# W3C RFC 2616 Section 4.2.",
"items",
"=",
"[",
"]",
"for",
"header",
"in",
"self",
".",
"headers",
".",
"headers",
":",
"# Remove \"\\n\... | a220671d66755a94630a212378754bb432811158 |
train | _has_level_handler | Check if there is a handler in the logging chain that will handle
the given logger's effective level. | src/werkzeug/_internal.py | def _has_level_handler(logger):
"""Check if there is a handler in the logging chain that will handle
the given logger's effective level.
"""
level = logger.getEffectiveLevel()
current = logger
while current:
if any(handler.level <= level for handler in current.handlers):
ret... | def _has_level_handler(logger):
"""Check if there is a handler in the logging chain that will handle
the given logger's effective level.
"""
level = logger.getEffectiveLevel()
current = logger
while current:
if any(handler.level <= level for handler in current.handlers):
ret... | [
"Check",
"if",
"there",
"is",
"a",
"handler",
"in",
"the",
"logging",
"chain",
"that",
"will",
"handle",
"the",
"given",
"logger",
"s",
"effective",
"level",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/_internal.py#L75-L91 | [
"def",
"_has_level_handler",
"(",
"logger",
")",
":",
"level",
"=",
"logger",
".",
"getEffectiveLevel",
"(",
")",
"current",
"=",
"logger",
"while",
"current",
":",
"if",
"any",
"(",
"handler",
".",
"level",
"<=",
"level",
"for",
"handler",
"in",
"current"... | a220671d66755a94630a212378754bb432811158 |
train | _log | Log a message to the 'werkzeug' logger.
The logger is created the first time it is needed. If there is no
level set, it is set to :data:`logging.INFO`. If there is no handler
for the logger's effective level, a :class:`logging.StreamHandler`
is added. | src/werkzeug/_internal.py | def _log(type, message, *args, **kwargs):
"""Log a message to the 'werkzeug' logger.
The logger is created the first time it is needed. If there is no
level set, it is set to :data:`logging.INFO`. If there is no handler
for the logger's effective level, a :class:`logging.StreamHandler`
is added.
... | def _log(type, message, *args, **kwargs):
"""Log a message to the 'werkzeug' logger.
The logger is created the first time it is needed. If there is no
level set, it is set to :data:`logging.INFO`. If there is no handler
for the logger's effective level, a :class:`logging.StreamHandler`
is added.
... | [
"Log",
"a",
"message",
"to",
"the",
"werkzeug",
"logger",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/_internal.py#L94-L113 | [
"def",
"_log",
"(",
"type",
",",
"message",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"global",
"_logger",
"if",
"_logger",
"is",
"None",
":",
"_logger",
"=",
"logging",
".",
"getLogger",
"(",
"\"werkzeug\"",
")",
"if",
"_logger",
".",
"le... | a220671d66755a94630a212378754bb432811158 |
train | _parse_signature | Return a signature object for the function. | src/werkzeug/_internal.py | def _parse_signature(func):
"""Return a signature object for the function."""
if hasattr(func, "im_func"):
func = func.im_func
# if we have a cached validator for this function, return it
parse = _signature_cache.get(func)
if parse is not None:
return parse
# inspect the functi... | def _parse_signature(func):
"""Return a signature object for the function."""
if hasattr(func, "im_func"):
func = func.im_func
# if we have a cached validator for this function, return it
parse = _signature_cache.get(func)
if parse is not None:
return parse
# inspect the functi... | [
"Return",
"a",
"signature",
"object",
"for",
"the",
"function",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/_internal.py#L116-L191 | [
"def",
"_parse_signature",
"(",
"func",
")",
":",
"if",
"hasattr",
"(",
"func",
",",
"\"im_func\"",
")",
":",
"func",
"=",
"func",
".",
"im_func",
"# if we have a cached validator for this function, return it",
"parse",
"=",
"_signature_cache",
".",
"get",
"(",
"f... | a220671d66755a94630a212378754bb432811158 |
train | _date_to_unix | Converts a timetuple, integer or datetime object into the seconds from
epoch in utc. | src/werkzeug/_internal.py | def _date_to_unix(arg):
"""Converts a timetuple, integer or datetime object into the seconds from
epoch in utc.
"""
if isinstance(arg, datetime):
arg = arg.utctimetuple()
elif isinstance(arg, integer_types + (float,)):
return int(arg)
year, month, day, hour, minute, second = arg[... | def _date_to_unix(arg):
"""Converts a timetuple, integer or datetime object into the seconds from
epoch in utc.
"""
if isinstance(arg, datetime):
arg = arg.utctimetuple()
elif isinstance(arg, integer_types + (float,)):
return int(arg)
year, month, day, hour, minute, second = arg[... | [
"Converts",
"a",
"timetuple",
"integer",
"or",
"datetime",
"object",
"into",
"the",
"seconds",
"from",
"epoch",
"in",
"utc",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/_internal.py#L194-L207 | [
"def",
"_date_to_unix",
"(",
"arg",
")",
":",
"if",
"isinstance",
"(",
"arg",
",",
"datetime",
")",
":",
"arg",
"=",
"arg",
".",
"utctimetuple",
"(",
")",
"elif",
"isinstance",
"(",
"arg",
",",
"integer_types",
"+",
"(",
"float",
",",
")",
")",
":",
... | a220671d66755a94630a212378754bb432811158 |
train | _cookie_parse_impl | Lowlevel cookie parsing facility that operates on bytes. | src/werkzeug/_internal.py | def _cookie_parse_impl(b):
"""Lowlevel cookie parsing facility that operates on bytes."""
i = 0
n = len(b)
while i < n:
match = _cookie_re.search(b + b";", i)
if not match:
break
key = match.group("key").strip()
value = match.group("val") or b""
i = ... | def _cookie_parse_impl(b):
"""Lowlevel cookie parsing facility that operates on bytes."""
i = 0
n = len(b)
while i < n:
match = _cookie_re.search(b + b";", i)
if not match:
break
key = match.group("key").strip()
value = match.group("val") or b""
i = ... | [
"Lowlevel",
"cookie",
"parsing",
"facility",
"that",
"operates",
"on",
"bytes",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/_internal.py#L315-L329 | [
"def",
"_cookie_parse_impl",
"(",
"b",
")",
":",
"i",
"=",
"0",
"n",
"=",
"len",
"(",
"b",
")",
"while",
"i",
"<",
"n",
":",
"match",
"=",
"_cookie_re",
".",
"search",
"(",
"b",
"+",
"b\";\"",
",",
"i",
")",
"if",
"not",
"match",
":",
"break",
... | a220671d66755a94630a212378754bb432811158 |
train | _easteregg | Like the name says. But who knows how it works? | src/werkzeug/_internal.py | def _easteregg(app=None):
"""Like the name says. But who knows how it works?"""
def bzzzzzzz(gyver):
import base64
import zlib
return zlib.decompress(base64.b64decode(gyver)).decode("ascii")
gyver = u"\n".join(
[
x + (77 - len(x)) * u" "
for x in b... | def _easteregg(app=None):
"""Like the name says. But who knows how it works?"""
def bzzzzzzz(gyver):
import base64
import zlib
return zlib.decompress(base64.b64decode(gyver)).decode("ascii")
gyver = u"\n".join(
[
x + (77 - len(x)) * u" "
for x in b... | [
"Like",
"the",
"name",
"says",
".",
"But",
"who",
"knows",
"how",
"it",
"works?"
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/_internal.py#L391-L473 | [
"def",
"_easteregg",
"(",
"app",
"=",
"None",
")",
":",
"def",
"bzzzzzzz",
"(",
"gyver",
")",
":",
"import",
"base64",
"import",
"zlib",
"return",
"zlib",
".",
"decompress",
"(",
"base64",
".",
"b64decode",
"(",
"gyver",
")",
")",
".",
"decode",
"(",
... | a220671d66755a94630a212378754bb432811158 |
train | get_pin_and_cookie_name | Given an application object this returns a semi-stable 9 digit pin
code and a random key. The hope is that this is stable between
restarts to not make debugging particularly frustrating. If the pin
was forcefully disabled this returns `None`.
Second item in the resulting tuple is the cookie name for ... | src/werkzeug/debug/__init__.py | def get_pin_and_cookie_name(app):
"""Given an application object this returns a semi-stable 9 digit pin
code and a random key. The hope is that this is stable between
restarts to not make debugging particularly frustrating. If the pin
was forcefully disabled this returns `None`.
Second item in th... | def get_pin_and_cookie_name(app):
"""Given an application object this returns a semi-stable 9 digit pin
code and a random key. The hope is that this is stable between
restarts to not make debugging particularly frustrating. If the pin
was forcefully disabled this returns `None`.
Second item in th... | [
"Given",
"an",
"application",
"object",
"this",
"returns",
"a",
"semi",
"-",
"stable",
"9",
"digit",
"pin",
"code",
"and",
"a",
"random",
"key",
".",
"The",
"hope",
"is",
"that",
"this",
"is",
"stable",
"between",
"restarts",
"to",
"not",
"make",
"debugg... | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/debug/__init__.py#L120-L200 | [
"def",
"get_pin_and_cookie_name",
"(",
"app",
")",
":",
"pin",
"=",
"os",
".",
"environ",
".",
"get",
"(",
"\"WERKZEUG_DEBUG_PIN\"",
")",
"rv",
"=",
"None",
"num",
"=",
"None",
"# Pin was explicitly disabled",
"if",
"pin",
"==",
"\"off\"",
":",
"return",
"No... | a220671d66755a94630a212378754bb432811158 |
train | DebuggedApplication.pin_cookie_name | The name of the pin cookie. | src/werkzeug/debug/__init__.py | def pin_cookie_name(self):
"""The name of the pin cookie."""
if not hasattr(self, "_pin_cookie"):
self._pin, self._pin_cookie = get_pin_and_cookie_name(self.app)
return self._pin_cookie | def pin_cookie_name(self):
"""The name of the pin cookie."""
if not hasattr(self, "_pin_cookie"):
self._pin, self._pin_cookie = get_pin_and_cookie_name(self.app)
return self._pin_cookie | [
"The",
"name",
"of",
"the",
"pin",
"cookie",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/debug/__init__.py#L278-L282 | [
"def",
"pin_cookie_name",
"(",
"self",
")",
":",
"if",
"not",
"hasattr",
"(",
"self",
",",
"\"_pin_cookie\"",
")",
":",
"self",
".",
"_pin",
",",
"self",
".",
"_pin_cookie",
"=",
"get_pin_and_cookie_name",
"(",
"self",
".",
"app",
")",
"return",
"self",
... | a220671d66755a94630a212378754bb432811158 |
train | DebuggedApplication.execute_command | Execute a command in a console. | src/werkzeug/debug/__init__.py | def execute_command(self, request, command, frame):
"""Execute a command in a console."""
return Response(frame.console.eval(command), mimetype="text/html") | def execute_command(self, request, command, frame):
"""Execute a command in a console."""
return Response(frame.console.eval(command), mimetype="text/html") | [
"Execute",
"a",
"command",
"in",
"a",
"console",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/debug/__init__.py#L333-L335 | [
"def",
"execute_command",
"(",
"self",
",",
"request",
",",
"command",
",",
"frame",
")",
":",
"return",
"Response",
"(",
"frame",
".",
"console",
".",
"eval",
"(",
"command",
")",
",",
"mimetype",
"=",
"\"text/html\"",
")"
] | a220671d66755a94630a212378754bb432811158 |
train | DebuggedApplication.display_console | Display a standalone shell. | src/werkzeug/debug/__init__.py | def display_console(self, request):
"""Display a standalone shell."""
if 0 not in self.frames:
if self.console_init_func is None:
ns = {}
else:
ns = dict(self.console_init_func())
ns.setdefault("app", self.app)
self.frames[0... | def display_console(self, request):
"""Display a standalone shell."""
if 0 not in self.frames:
if self.console_init_func is None:
ns = {}
else:
ns = dict(self.console_init_func())
ns.setdefault("app", self.app)
self.frames[0... | [
"Display",
"a",
"standalone",
"shell",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/debug/__init__.py#L337-L350 | [
"def",
"display_console",
"(",
"self",
",",
"request",
")",
":",
"if",
"0",
"not",
"in",
"self",
".",
"frames",
":",
"if",
"self",
".",
"console_init_func",
"is",
"None",
":",
"ns",
"=",
"{",
"}",
"else",
":",
"ns",
"=",
"dict",
"(",
"self",
".",
... | a220671d66755a94630a212378754bb432811158 |
train | DebuggedApplication.get_resource | Return a static resource from the shared folder. | src/werkzeug/debug/__init__.py | def get_resource(self, request, filename):
"""Return a static resource from the shared folder."""
filename = join("shared", basename(filename))
try:
data = pkgutil.get_data(__package__, filename)
except OSError:
data = None
if data is not None:
... | def get_resource(self, request, filename):
"""Return a static resource from the shared folder."""
filename = join("shared", basename(filename))
try:
data = pkgutil.get_data(__package__, filename)
except OSError:
data = None
if data is not None:
... | [
"Return",
"a",
"static",
"resource",
"from",
"the",
"shared",
"folder",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/debug/__init__.py#L357-L367 | [
"def",
"get_resource",
"(",
"self",
",",
"request",
",",
"filename",
")",
":",
"filename",
"=",
"join",
"(",
"\"shared\"",
",",
"basename",
"(",
"filename",
")",
")",
"try",
":",
"data",
"=",
"pkgutil",
".",
"get_data",
"(",
"__package__",
",",
"filename... | a220671d66755a94630a212378754bb432811158 |
train | DebuggedApplication.check_pin_trust | Checks if the request passed the pin test. This returns `True` if the
request is trusted on a pin/cookie basis and returns `False` if not.
Additionally if the cookie's stored pin hash is wrong it will return
`None` so that appropriate action can be taken. | src/werkzeug/debug/__init__.py | def check_pin_trust(self, environ):
"""Checks if the request passed the pin test. This returns `True` if the
request is trusted on a pin/cookie basis and returns `False` if not.
Additionally if the cookie's stored pin hash is wrong it will return
`None` so that appropriate action can be... | def check_pin_trust(self, environ):
"""Checks if the request passed the pin test. This returns `True` if the
request is trusted on a pin/cookie basis and returns `False` if not.
Additionally if the cookie's stored pin hash is wrong it will return
`None` so that appropriate action can be... | [
"Checks",
"if",
"the",
"request",
"passed",
"the",
"pin",
"test",
".",
"This",
"returns",
"True",
"if",
"the",
"request",
"is",
"trusted",
"on",
"a",
"pin",
"/",
"cookie",
"basis",
"and",
"returns",
"False",
"if",
"not",
".",
"Additionally",
"if",
"the",... | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/debug/__init__.py#L369-L385 | [
"def",
"check_pin_trust",
"(",
"self",
",",
"environ",
")",
":",
"if",
"self",
".",
"pin",
"is",
"None",
":",
"return",
"True",
"val",
"=",
"parse_cookie",
"(",
"environ",
")",
".",
"get",
"(",
"self",
".",
"pin_cookie_name",
")",
"if",
"not",
"val",
... | a220671d66755a94630a212378754bb432811158 |
train | DebuggedApplication.pin_auth | Authenticates with the pin. | src/werkzeug/debug/__init__.py | def pin_auth(self, request):
"""Authenticates with the pin."""
exhausted = False
auth = False
trust = self.check_pin_trust(request.environ)
# If the trust return value is `None` it means that the cookie is
# set but the stored pin hash value is bad. This means that the
... | def pin_auth(self, request):
"""Authenticates with the pin."""
exhausted = False
auth = False
trust = self.check_pin_trust(request.environ)
# If the trust return value is `None` it means that the cookie is
# set but the stored pin hash value is bad. This means that the
... | [
"Authenticates",
"with",
"the",
"pin",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/debug/__init__.py#L391-L436 | [
"def",
"pin_auth",
"(",
"self",
",",
"request",
")",
":",
"exhausted",
"=",
"False",
"auth",
"=",
"False",
"trust",
"=",
"self",
".",
"check_pin_trust",
"(",
"request",
".",
"environ",
")",
"# If the trust return value is `None` it means that the cookie is",
"# set ... | a220671d66755a94630a212378754bb432811158 |
train | DebuggedApplication.log_pin_request | Log the pin if needed. | src/werkzeug/debug/__init__.py | def log_pin_request(self):
"""Log the pin if needed."""
if self.pin_logging and self.pin is not None:
_log(
"info", " * To enable the debugger you need to enter the security pin:"
)
_log("info", " * Debugger pin code: %s" % self.pin)
return Res... | def log_pin_request(self):
"""Log the pin if needed."""
if self.pin_logging and self.pin is not None:
_log(
"info", " * To enable the debugger you need to enter the security pin:"
)
_log("info", " * Debugger pin code: %s" % self.pin)
return Res... | [
"Log",
"the",
"pin",
"if",
"needed",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/debug/__init__.py#L438-L445 | [
"def",
"log_pin_request",
"(",
"self",
")",
":",
"if",
"self",
".",
"pin_logging",
"and",
"self",
".",
"pin",
"is",
"not",
"None",
":",
"_log",
"(",
"\"info\"",
",",
"\" * To enable the debugger you need to enter the security pin:\"",
")",
"_log",
"(",
"\"info\"",... | a220671d66755a94630a212378754bb432811158 |
train | unquote_header_value | r"""Unquotes a header value. (Reversal of :func:`quote_header_value`).
This does not use the real unquoting but what browsers are actually
using for quoting.
.. versionadded:: 0.5
:param value: the header value to unquote. | src/werkzeug/http.py | def unquote_header_value(value, is_filename=False):
r"""Unquotes a header value. (Reversal of :func:`quote_header_value`).
This does not use the real unquoting but what browsers are actually
using for quoting.
.. versionadded:: 0.5
:param value: the header value to unquote.
"""
if value a... | def unquote_header_value(value, is_filename=False):
r"""Unquotes a header value. (Reversal of :func:`quote_header_value`).
This does not use the real unquoting but what browsers are actually
using for quoting.
.. versionadded:: 0.5
:param value: the header value to unquote.
"""
if value a... | [
"r",
"Unquotes",
"a",
"header",
"value",
".",
"(",
"Reversal",
"of",
":",
"func",
":",
"quote_header_value",
")",
".",
"This",
"does",
"not",
"use",
"the",
"real",
"unquoting",
"but",
"what",
"browsers",
"are",
"actually",
"using",
"for",
"quoting",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/http.py#L235-L258 | [
"def",
"unquote_header_value",
"(",
"value",
",",
"is_filename",
"=",
"False",
")",
":",
"if",
"value",
"and",
"value",
"[",
"0",
"]",
"==",
"value",
"[",
"-",
"1",
"]",
"==",
"'\"'",
":",
"# this is not the real unquoting, but fixing this so that the",
"# RFC i... | a220671d66755a94630a212378754bb432811158 |
train | dump_options_header | The reverse function to :func:`parse_options_header`.
:param header: the header to dump
:param options: a dict of options to append. | src/werkzeug/http.py | def dump_options_header(header, options):
"""The reverse function to :func:`parse_options_header`.
:param header: the header to dump
:param options: a dict of options to append.
"""
segments = []
if header is not None:
segments.append(header)
for key, value in iteritems(options):
... | def dump_options_header(header, options):
"""The reverse function to :func:`parse_options_header`.
:param header: the header to dump
:param options: a dict of options to append.
"""
segments = []
if header is not None:
segments.append(header)
for key, value in iteritems(options):
... | [
"The",
"reverse",
"function",
"to",
":",
"func",
":",
"parse_options_header",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/http.py#L261-L275 | [
"def",
"dump_options_header",
"(",
"header",
",",
"options",
")",
":",
"segments",
"=",
"[",
"]",
"if",
"header",
"is",
"not",
"None",
":",
"segments",
".",
"append",
"(",
"header",
")",
"for",
"key",
",",
"value",
"in",
"iteritems",
"(",
"options",
")... | a220671d66755a94630a212378754bb432811158 |
train | dump_header | Dump an HTTP header again. This is the reversal of
:func:`parse_list_header`, :func:`parse_set_header` and
:func:`parse_dict_header`. This also quotes strings that include an
equals sign unless you pass it as dict of key, value pairs.
>>> dump_header({'foo': 'bar baz'})
'foo="bar baz"'
>>> du... | src/werkzeug/http.py | def dump_header(iterable, allow_token=True):
"""Dump an HTTP header again. This is the reversal of
:func:`parse_list_header`, :func:`parse_set_header` and
:func:`parse_dict_header`. This also quotes strings that include an
equals sign unless you pass it as dict of key, value pairs.
>>> dump_heade... | def dump_header(iterable, allow_token=True):
"""Dump an HTTP header again. This is the reversal of
:func:`parse_list_header`, :func:`parse_set_header` and
:func:`parse_dict_header`. This also quotes strings that include an
equals sign unless you pass it as dict of key, value pairs.
>>> dump_heade... | [
"Dump",
"an",
"HTTP",
"header",
"again",
".",
"This",
"is",
"the",
"reversal",
"of",
":",
"func",
":",
"parse_list_header",
":",
"func",
":",
"parse_set_header",
"and",
":",
"func",
":",
"parse_dict_header",
".",
"This",
"also",
"quotes",
"strings",
"that",
... | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/http.py#L278-L304 | [
"def",
"dump_header",
"(",
"iterable",
",",
"allow_token",
"=",
"True",
")",
":",
"if",
"isinstance",
"(",
"iterable",
",",
"dict",
")",
":",
"items",
"=",
"[",
"]",
"for",
"key",
",",
"value",
"in",
"iteritems",
"(",
"iterable",
")",
":",
"if",
"val... | a220671d66755a94630a212378754bb432811158 |
train | parse_dict_header | Parse lists of key, value pairs as described by RFC 2068 Section 2 and
convert them into a python dict (or any other mapping object created from
the type with a dict like interface provided by the `cls` argument):
>>> d = parse_dict_header('foo="is a fish", bar="as well"')
>>> type(d) is dict
True
... | src/werkzeug/http.py | def parse_dict_header(value, cls=dict):
"""Parse lists of key, value pairs as described by RFC 2068 Section 2 and
convert them into a python dict (or any other mapping object created from
the type with a dict like interface provided by the `cls` argument):
>>> d = parse_dict_header('foo="is a fish", ba... | def parse_dict_header(value, cls=dict):
"""Parse lists of key, value pairs as described by RFC 2068 Section 2 and
convert them into a python dict (or any other mapping object created from
the type with a dict like interface provided by the `cls` argument):
>>> d = parse_dict_header('foo="is a fish", ba... | [
"Parse",
"lists",
"of",
"key",
"value",
"pairs",
"as",
"described",
"by",
"RFC",
"2068",
"Section",
"2",
"and",
"convert",
"them",
"into",
"a",
"python",
"dict",
"(",
"or",
"any",
"other",
"mapping",
"object",
"created",
"from",
"the",
"type",
"with",
"a... | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/http.py#L337-L375 | [
"def",
"parse_dict_header",
"(",
"value",
",",
"cls",
"=",
"dict",
")",
":",
"result",
"=",
"cls",
"(",
")",
"if",
"not",
"isinstance",
"(",
"value",
",",
"text_type",
")",
":",
"# XXX: validate",
"value",
"=",
"bytes_to_wsgi",
"(",
"value",
")",
"for",
... | a220671d66755a94630a212378754bb432811158 |
train | parse_options_header | Parse a ``Content-Type`` like header into a tuple with the content
type and the options:
>>> parse_options_header('text/html; charset=utf8')
('text/html', {'charset': 'utf8'})
This should not be used to parse ``Cache-Control`` like headers that use
a slightly different format. For these headers u... | src/werkzeug/http.py | def parse_options_header(value, multiple=False):
"""Parse a ``Content-Type`` like header into a tuple with the content
type and the options:
>>> parse_options_header('text/html; charset=utf8')
('text/html', {'charset': 'utf8'})
This should not be used to parse ``Cache-Control`` like headers that u... | def parse_options_header(value, multiple=False):
"""Parse a ``Content-Type`` like header into a tuple with the content
type and the options:
>>> parse_options_header('text/html; charset=utf8')
('text/html', {'charset': 'utf8'})
This should not be used to parse ``Cache-Control`` like headers that u... | [
"Parse",
"a",
"Content",
"-",
"Type",
"like",
"header",
"into",
"a",
"tuple",
"with",
"the",
"content",
"type",
"and",
"the",
"options",
":"
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/http.py#L378-L447 | [
"def",
"parse_options_header",
"(",
"value",
",",
"multiple",
"=",
"False",
")",
":",
"if",
"not",
"value",
":",
"return",
"\"\"",
",",
"{",
"}",
"result",
"=",
"[",
"]",
"value",
"=",
"\",\"",
"+",
"value",
".",
"replace",
"(",
"\"\\n\"",
",",
"\",\... | a220671d66755a94630a212378754bb432811158 |
train | parse_accept_header | Parses an HTTP Accept-* header. This does not implement a complete
valid algorithm but one that supports at least value and quality
extraction.
Returns a new :class:`Accept` object (basically a list of ``(value, quality)``
tuples sorted by the quality with some additional accessor methods).
The s... | src/werkzeug/http.py | def parse_accept_header(value, cls=None):
"""Parses an HTTP Accept-* header. This does not implement a complete
valid algorithm but one that supports at least value and quality
extraction.
Returns a new :class:`Accept` object (basically a list of ``(value, quality)``
tuples sorted by the quality w... | def parse_accept_header(value, cls=None):
"""Parses an HTTP Accept-* header. This does not implement a complete
valid algorithm but one that supports at least value and quality
extraction.
Returns a new :class:`Accept` object (basically a list of ``(value, quality)``
tuples sorted by the quality w... | [
"Parses",
"an",
"HTTP",
"Accept",
"-",
"*",
"header",
".",
"This",
"does",
"not",
"implement",
"a",
"complete",
"valid",
"algorithm",
"but",
"one",
"that",
"supports",
"at",
"least",
"value",
"and",
"quality",
"extraction",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/http.py#L450-L480 | [
"def",
"parse_accept_header",
"(",
"value",
",",
"cls",
"=",
"None",
")",
":",
"if",
"cls",
"is",
"None",
":",
"cls",
"=",
"Accept",
"if",
"not",
"value",
":",
"return",
"cls",
"(",
"None",
")",
"result",
"=",
"[",
"]",
"for",
"match",
"in",
"_acce... | a220671d66755a94630a212378754bb432811158 |
train | parse_cache_control_header | Parse a cache control header. The RFC differs between response and
request cache control, this method does not. It's your responsibility
to not use the wrong control statements.
.. versionadded:: 0.5
The `cls` was added. If not specified an immutable
:class:`~werkzeug.datastructures.Reques... | src/werkzeug/http.py | def parse_cache_control_header(value, on_update=None, cls=None):
"""Parse a cache control header. The RFC differs between response and
request cache control, this method does not. It's your responsibility
to not use the wrong control statements.
.. versionadded:: 0.5
The `cls` was added. If n... | def parse_cache_control_header(value, on_update=None, cls=None):
"""Parse a cache control header. The RFC differs between response and
request cache control, this method does not. It's your responsibility
to not use the wrong control statements.
.. versionadded:: 0.5
The `cls` was added. If n... | [
"Parse",
"a",
"cache",
"control",
"header",
".",
"The",
"RFC",
"differs",
"between",
"response",
"and",
"request",
"cache",
"control",
"this",
"method",
"does",
"not",
".",
"It",
"s",
"your",
"responsibility",
"to",
"not",
"use",
"the",
"wrong",
"control",
... | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/http.py#L483-L504 | [
"def",
"parse_cache_control_header",
"(",
"value",
",",
"on_update",
"=",
"None",
",",
"cls",
"=",
"None",
")",
":",
"if",
"cls",
"is",
"None",
":",
"cls",
"=",
"RequestCacheControl",
"if",
"not",
"value",
":",
"return",
"cls",
"(",
"None",
",",
"on_upda... | a220671d66755a94630a212378754bb432811158 |
train | parse_set_header | Parse a set-like header and return a
:class:`~werkzeug.datastructures.HeaderSet` object:
>>> hs = parse_set_header('token, "quoted value"')
The return value is an object that treats the items case-insensitively
and keeps the order of the items:
>>> 'TOKEN' in hs
True
>>> hs.index('quoted ... | src/werkzeug/http.py | def parse_set_header(value, on_update=None):
"""Parse a set-like header and return a
:class:`~werkzeug.datastructures.HeaderSet` object:
>>> hs = parse_set_header('token, "quoted value"')
The return value is an object that treats the items case-insensitively
and keeps the order of the items:
... | def parse_set_header(value, on_update=None):
"""Parse a set-like header and return a
:class:`~werkzeug.datastructures.HeaderSet` object:
>>> hs = parse_set_header('token, "quoted value"')
The return value is an object that treats the items case-insensitively
and keeps the order of the items:
... | [
"Parse",
"a",
"set",
"-",
"like",
"header",
"and",
"return",
"a",
":",
"class",
":",
"~werkzeug",
".",
"datastructures",
".",
"HeaderSet",
"object",
":"
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/http.py#L507-L534 | [
"def",
"parse_set_header",
"(",
"value",
",",
"on_update",
"=",
"None",
")",
":",
"if",
"not",
"value",
":",
"return",
"HeaderSet",
"(",
"None",
",",
"on_update",
")",
"return",
"HeaderSet",
"(",
"parse_list_header",
"(",
"value",
")",
",",
"on_update",
")... | a220671d66755a94630a212378754bb432811158 |
train | parse_authorization_header | Parse an HTTP basic/digest authorization header transmitted by the web
browser. The return value is either `None` if the header was invalid or
not given, otherwise an :class:`~werkzeug.datastructures.Authorization`
object.
:param value: the authorization header to parse.
:return: a :class:`~werkze... | src/werkzeug/http.py | def parse_authorization_header(value):
"""Parse an HTTP basic/digest authorization header transmitted by the web
browser. The return value is either `None` if the header was invalid or
not given, otherwise an :class:`~werkzeug.datastructures.Authorization`
object.
:param value: the authorization h... | def parse_authorization_header(value):
"""Parse an HTTP basic/digest authorization header transmitted by the web
browser. The return value is either `None` if the header was invalid or
not given, otherwise an :class:`~werkzeug.datastructures.Authorization`
object.
:param value: the authorization h... | [
"Parse",
"an",
"HTTP",
"basic",
"/",
"digest",
"authorization",
"header",
"transmitted",
"by",
"the",
"web",
"browser",
".",
"The",
"return",
"value",
"is",
"either",
"None",
"if",
"the",
"header",
"was",
"invalid",
"or",
"not",
"given",
"otherwise",
"an",
... | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/http.py#L537-L574 | [
"def",
"parse_authorization_header",
"(",
"value",
")",
":",
"if",
"not",
"value",
":",
"return",
"value",
"=",
"wsgi_to_bytes",
"(",
"value",
")",
"try",
":",
"auth_type",
",",
"auth_info",
"=",
"value",
".",
"split",
"(",
"None",
",",
"1",
")",
"auth_t... | a220671d66755a94630a212378754bb432811158 |
train | parse_www_authenticate_header | Parse an HTTP WWW-Authenticate header into a
:class:`~werkzeug.datastructures.WWWAuthenticate` object.
:param value: a WWW-Authenticate header to parse.
:param on_update: an optional callable that is called every time a value
on the :class:`~werkzeug.datastructures.WWWAuthenticate`
... | src/werkzeug/http.py | def parse_www_authenticate_header(value, on_update=None):
"""Parse an HTTP WWW-Authenticate header into a
:class:`~werkzeug.datastructures.WWWAuthenticate` object.
:param value: a WWW-Authenticate header to parse.
:param on_update: an optional callable that is called every time a value
... | def parse_www_authenticate_header(value, on_update=None):
"""Parse an HTTP WWW-Authenticate header into a
:class:`~werkzeug.datastructures.WWWAuthenticate` object.
:param value: a WWW-Authenticate header to parse.
:param on_update: an optional callable that is called every time a value
... | [
"Parse",
"an",
"HTTP",
"WWW",
"-",
"Authenticate",
"header",
"into",
"a",
":",
"class",
":",
"~werkzeug",
".",
"datastructures",
".",
"WWWAuthenticate",
"object",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/http.py#L577-L594 | [
"def",
"parse_www_authenticate_header",
"(",
"value",
",",
"on_update",
"=",
"None",
")",
":",
"if",
"not",
"value",
":",
"return",
"WWWAuthenticate",
"(",
"on_update",
"=",
"on_update",
")",
"try",
":",
"auth_type",
",",
"auth_info",
"=",
"value",
".",
"spl... | a220671d66755a94630a212378754bb432811158 |
train | parse_if_range_header | Parses an if-range header which can be an etag or a date. Returns
a :class:`~werkzeug.datastructures.IfRange` object.
.. versionadded:: 0.7 | src/werkzeug/http.py | def parse_if_range_header(value):
"""Parses an if-range header which can be an etag or a date. Returns
a :class:`~werkzeug.datastructures.IfRange` object.
.. versionadded:: 0.7
"""
if not value:
return IfRange()
date = parse_date(value)
if date is not None:
return IfRange(d... | def parse_if_range_header(value):
"""Parses an if-range header which can be an etag or a date. Returns
a :class:`~werkzeug.datastructures.IfRange` object.
.. versionadded:: 0.7
"""
if not value:
return IfRange()
date = parse_date(value)
if date is not None:
return IfRange(d... | [
"Parses",
"an",
"if",
"-",
"range",
"header",
"which",
"can",
"be",
"an",
"etag",
"or",
"a",
"date",
".",
"Returns",
"a",
":",
"class",
":",
"~werkzeug",
".",
"datastructures",
".",
"IfRange",
"object",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/http.py#L597-L609 | [
"def",
"parse_if_range_header",
"(",
"value",
")",
":",
"if",
"not",
"value",
":",
"return",
"IfRange",
"(",
")",
"date",
"=",
"parse_date",
"(",
"value",
")",
"if",
"date",
"is",
"not",
"None",
":",
"return",
"IfRange",
"(",
"date",
"=",
"date",
")",
... | a220671d66755a94630a212378754bb432811158 |
train | parse_date | Parse one of the following date formats into a datetime object:
.. sourcecode:: text
Sun, 06 Nov 1994 08:49:37 GMT ; RFC 822, updated by RFC 1123
Sunday, 06-Nov-94 08:49:37 GMT ; RFC 850, obsoleted by RFC 1036
Sun Nov 6 08:49:37 1994 ; ANSI C's asctime() format
If parsing fail... | src/werkzeug/http.py | def parse_date(value):
"""Parse one of the following date formats into a datetime object:
.. sourcecode:: text
Sun, 06 Nov 1994 08:49:37 GMT ; RFC 822, updated by RFC 1123
Sunday, 06-Nov-94 08:49:37 GMT ; RFC 850, obsoleted by RFC 1036
Sun Nov 6 08:49:37 1994 ; ANSI C's asctime... | def parse_date(value):
"""Parse one of the following date formats into a datetime object:
.. sourcecode:: text
Sun, 06 Nov 1994 08:49:37 GMT ; RFC 822, updated by RFC 1123
Sunday, 06-Nov-94 08:49:37 GMT ; RFC 850, obsoleted by RFC 1036
Sun Nov 6 08:49:37 1994 ; ANSI C's asctime... | [
"Parse",
"one",
"of",
"the",
"following",
"date",
"formats",
"into",
"a",
"datetime",
"object",
":"
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/http.py#L780-L809 | [
"def",
"parse_date",
"(",
"value",
")",
":",
"if",
"value",
":",
"t",
"=",
"parsedate_tz",
"(",
"value",
".",
"strip",
"(",
")",
")",
"if",
"t",
"is",
"not",
"None",
":",
"try",
":",
"year",
"=",
"t",
"[",
"0",
"]",
"# unfortunately that function doe... | a220671d66755a94630a212378754bb432811158 |
train | _dump_date | Used for `http_date` and `cookie_date`. | src/werkzeug/http.py | def _dump_date(d, delim):
"""Used for `http_date` and `cookie_date`."""
if d is None:
d = gmtime()
elif isinstance(d, datetime):
d = d.utctimetuple()
elif isinstance(d, (integer_types, float)):
d = gmtime(d)
return "%s, %02d%s%s%s%s %02d:%02d:%02d GMT" % (
("Mon", "Tu... | def _dump_date(d, delim):
"""Used for `http_date` and `cookie_date`."""
if d is None:
d = gmtime()
elif isinstance(d, datetime):
d = d.utctimetuple()
elif isinstance(d, (integer_types, float)):
d = gmtime(d)
return "%s, %02d%s%s%s%s %02d:%02d:%02d GMT" % (
("Mon", "Tu... | [
"Used",
"for",
"http_date",
"and",
"cookie_date",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/http.py#L812-L843 | [
"def",
"_dump_date",
"(",
"d",
",",
"delim",
")",
":",
"if",
"d",
"is",
"None",
":",
"d",
"=",
"gmtime",
"(",
")",
"elif",
"isinstance",
"(",
"d",
",",
"datetime",
")",
":",
"d",
"=",
"d",
".",
"utctimetuple",
"(",
")",
"elif",
"isinstance",
"(",... | a220671d66755a94630a212378754bb432811158 |
train | parse_age | Parses a base-10 integer count of seconds into a timedelta.
If parsing fails, the return value is `None`.
:param value: a string consisting of an integer represented in base-10
:return: a :class:`datetime.timedelta` object or `None`. | src/werkzeug/http.py | def parse_age(value=None):
"""Parses a base-10 integer count of seconds into a timedelta.
If parsing fails, the return value is `None`.
:param value: a string consisting of an integer represented in base-10
:return: a :class:`datetime.timedelta` object or `None`.
"""
if not value:
retu... | def parse_age(value=None):
"""Parses a base-10 integer count of seconds into a timedelta.
If parsing fails, the return value is `None`.
:param value: a string consisting of an integer represented in base-10
:return: a :class:`datetime.timedelta` object or `None`.
"""
if not value:
retu... | [
"Parses",
"a",
"base",
"-",
"10",
"integer",
"count",
"of",
"seconds",
"into",
"a",
"timedelta",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/http.py#L875-L894 | [
"def",
"parse_age",
"(",
"value",
"=",
"None",
")",
":",
"if",
"not",
"value",
":",
"return",
"None",
"try",
":",
"seconds",
"=",
"int",
"(",
"value",
")",
"except",
"ValueError",
":",
"return",
"None",
"if",
"seconds",
"<",
"0",
":",
"return",
"None... | a220671d66755a94630a212378754bb432811158 |
train | dump_age | Formats the duration as a base-10 integer.
:param age: should be an integer number of seconds,
a :class:`datetime.timedelta` object, or,
if the age is unknown, `None` (default). | src/werkzeug/http.py | def dump_age(age=None):
"""Formats the duration as a base-10 integer.
:param age: should be an integer number of seconds,
a :class:`datetime.timedelta` object, or,
if the age is unknown, `None` (default).
"""
if age is None:
return
if isinstance(age, timedelt... | def dump_age(age=None):
"""Formats the duration as a base-10 integer.
:param age: should be an integer number of seconds,
a :class:`datetime.timedelta` object, or,
if the age is unknown, `None` (default).
"""
if age is None:
return
if isinstance(age, timedelt... | [
"Formats",
"the",
"duration",
"as",
"a",
"base",
"-",
"10",
"integer",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/http.py#L897-L915 | [
"def",
"dump_age",
"(",
"age",
"=",
"None",
")",
":",
"if",
"age",
"is",
"None",
":",
"return",
"if",
"isinstance",
"(",
"age",
",",
"timedelta",
")",
":",
"# do the equivalent of Python 2.7's timedelta.total_seconds(),",
"# but disregarding fractional seconds",
"age"... | a220671d66755a94630a212378754bb432811158 |
train | is_resource_modified | Convenience method for conditional requests.
:param environ: the WSGI environment of the request to be checked.
:param etag: the etag for the response for comparison.
:param data: or alternatively the data of the response to automatically
generate an etag using :func:`generate_etag`.
:... | src/werkzeug/http.py | def is_resource_modified(
environ, etag=None, data=None, last_modified=None, ignore_if_range=True
):
"""Convenience method for conditional requests.
:param environ: the WSGI environment of the request to be checked.
:param etag: the etag for the response for comparison.
:param data: or alternativel... | def is_resource_modified(
environ, etag=None, data=None, last_modified=None, ignore_if_range=True
):
"""Convenience method for conditional requests.
:param environ: the WSGI environment of the request to be checked.
:param etag: the etag for the response for comparison.
:param data: or alternativel... | [
"Convenience",
"method",
"for",
"conditional",
"requests",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/http.py#L918-L982 | [
"def",
"is_resource_modified",
"(",
"environ",
",",
"etag",
"=",
"None",
",",
"data",
"=",
"None",
",",
"last_modified",
"=",
"None",
",",
"ignore_if_range",
"=",
"True",
")",
":",
"if",
"etag",
"is",
"None",
"and",
"data",
"is",
"not",
"None",
":",
"e... | a220671d66755a94630a212378754bb432811158 |
train | remove_entity_headers | Remove all entity headers from a list or :class:`Headers` object. This
operation works in-place. `Expires` and `Content-Location` headers are
by default not removed. The reason for this is :rfc:`2616` section
10.3.5 which specifies some entity headers that should be sent.
.. versionchanged:: 0.5
... | src/werkzeug/http.py | def remove_entity_headers(headers, allowed=("expires", "content-location")):
"""Remove all entity headers from a list or :class:`Headers` object. This
operation works in-place. `Expires` and `Content-Location` headers are
by default not removed. The reason for this is :rfc:`2616` section
10.3.5 which... | def remove_entity_headers(headers, allowed=("expires", "content-location")):
"""Remove all entity headers from a list or :class:`Headers` object. This
operation works in-place. `Expires` and `Content-Location` headers are
by default not removed. The reason for this is :rfc:`2616` section
10.3.5 which... | [
"Remove",
"all",
"entity",
"headers",
"from",
"a",
"list",
"or",
":",
"class",
":",
"Headers",
"object",
".",
"This",
"operation",
"works",
"in",
"-",
"place",
".",
"Expires",
"and",
"Content",
"-",
"Location",
"headers",
"are",
"by",
"default",
"not",
"... | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/http.py#L985-L1003 | [
"def",
"remove_entity_headers",
"(",
"headers",
",",
"allowed",
"=",
"(",
"\"expires\"",
",",
"\"content-location\"",
")",
")",
":",
"allowed",
"=",
"set",
"(",
"x",
".",
"lower",
"(",
")",
"for",
"x",
"in",
"allowed",
")",
"headers",
"[",
":",
"]",
"=... | a220671d66755a94630a212378754bb432811158 |
train | remove_hop_by_hop_headers | Remove all HTTP/1.1 "Hop-by-Hop" headers from a list or
:class:`Headers` object. This operation works in-place.
.. versionadded:: 0.5
:param headers: a list or :class:`Headers` object. | src/werkzeug/http.py | def remove_hop_by_hop_headers(headers):
"""Remove all HTTP/1.1 "Hop-by-Hop" headers from a list or
:class:`Headers` object. This operation works in-place.
.. versionadded:: 0.5
:param headers: a list or :class:`Headers` object.
"""
headers[:] = [
(key, value) for key, value in headers... | def remove_hop_by_hop_headers(headers):
"""Remove all HTTP/1.1 "Hop-by-Hop" headers from a list or
:class:`Headers` object. This operation works in-place.
.. versionadded:: 0.5
:param headers: a list or :class:`Headers` object.
"""
headers[:] = [
(key, value) for key, value in headers... | [
"Remove",
"all",
"HTTP",
"/",
"1",
".",
"1",
"Hop",
"-",
"by",
"-",
"Hop",
"headers",
"from",
"a",
"list",
"or",
":",
"class",
":",
"Headers",
"object",
".",
"This",
"operation",
"works",
"in",
"-",
"place",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/http.py#L1006-L1016 | [
"def",
"remove_hop_by_hop_headers",
"(",
"headers",
")",
":",
"headers",
"[",
":",
"]",
"=",
"[",
"(",
"key",
",",
"value",
")",
"for",
"key",
",",
"value",
"in",
"headers",
"if",
"not",
"is_hop_by_hop_header",
"(",
"key",
")",
"]"
] | a220671d66755a94630a212378754bb432811158 |
train | parse_cookie | Parse a cookie. Either from a string or WSGI environ.
Per default encoding errors are ignored. If you want a different behavior
you can set `errors` to ``'replace'`` or ``'strict'``. In strict mode a
:exc:`HTTPUnicodeError` is raised.
.. versionchanged:: 0.5
This function now returns a :clas... | src/werkzeug/http.py | def parse_cookie(header, charset="utf-8", errors="replace", cls=None):
"""Parse a cookie. Either from a string or WSGI environ.
Per default encoding errors are ignored. If you want a different behavior
you can set `errors` to ``'replace'`` or ``'strict'``. In strict mode a
:exc:`HTTPUnicodeError` is... | def parse_cookie(header, charset="utf-8", errors="replace", cls=None):
"""Parse a cookie. Either from a string or WSGI environ.
Per default encoding errors are ignored. If you want a different behavior
you can set `errors` to ``'replace'`` or ``'strict'``. In strict mode a
:exc:`HTTPUnicodeError` is... | [
"Parse",
"a",
"cookie",
".",
"Either",
"from",
"a",
"string",
"or",
"WSGI",
"environ",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/http.py#L1041-L1083 | [
"def",
"parse_cookie",
"(",
"header",
",",
"charset",
"=",
"\"utf-8\"",
",",
"errors",
"=",
"\"replace\"",
",",
"cls",
"=",
"None",
")",
":",
"if",
"isinstance",
"(",
"header",
",",
"dict",
")",
":",
"header",
"=",
"header",
".",
"get",
"(",
"\"HTTP_CO... | a220671d66755a94630a212378754bb432811158 |
train | dump_cookie | Creates a new Set-Cookie header without the ``Set-Cookie`` prefix
The parameters are the same as in the cookie Morsel object in the
Python standard library but it accepts unicode data, too.
On Python 3 the return value of this function will be a unicode
string, on Python 2 it will be a native string. ... | src/werkzeug/http.py | def dump_cookie(
key,
value="",
max_age=None,
expires=None,
path="/",
domain=None,
secure=False,
httponly=False,
charset="utf-8",
sync_expires=True,
max_size=4093,
samesite=None,
):
"""Creates a new Set-Cookie header without the ``Set-Cookie`` prefix
The parameter... | def dump_cookie(
key,
value="",
max_age=None,
expires=None,
path="/",
domain=None,
secure=False,
httponly=False,
charset="utf-8",
sync_expires=True,
max_size=4093,
samesite=None,
):
"""Creates a new Set-Cookie header without the ``Set-Cookie`` prefix
The parameter... | [
"Creates",
"a",
"new",
"Set",
"-",
"Cookie",
"header",
"without",
"the",
"Set",
"-",
"Cookie",
"prefix",
"The",
"parameters",
"are",
"the",
"same",
"as",
"in",
"the",
"cookie",
"Morsel",
"object",
"in",
"the",
"Python",
"standard",
"library",
"but",
"it",
... | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/http.py#L1086-L1219 | [
"def",
"dump_cookie",
"(",
"key",
",",
"value",
"=",
"\"\"",
",",
"max_age",
"=",
"None",
",",
"expires",
"=",
"None",
",",
"path",
"=",
"\"/\"",
",",
"domain",
"=",
"None",
",",
"secure",
"=",
"False",
",",
"httponly",
"=",
"False",
",",
"charset",
... | a220671d66755a94630a212378754bb432811158 |
train | is_byte_range_valid | Checks if a given byte content range is valid for the given length.
.. versionadded:: 0.7 | src/werkzeug/http.py | def is_byte_range_valid(start, stop, length):
"""Checks if a given byte content range is valid for the given length.
.. versionadded:: 0.7
"""
if (start is None) != (stop is None):
return False
elif start is None:
return length is None or length >= 0
elif length is None:
... | def is_byte_range_valid(start, stop, length):
"""Checks if a given byte content range is valid for the given length.
.. versionadded:: 0.7
"""
if (start is None) != (stop is None):
return False
elif start is None:
return length is None or length >= 0
elif length is None:
... | [
"Checks",
"if",
"a",
"given",
"byte",
"content",
"range",
"is",
"valid",
"for",
"the",
"given",
"length",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/http.py#L1222-L1235 | [
"def",
"is_byte_range_valid",
"(",
"start",
",",
"stop",
",",
"length",
")",
":",
"if",
"(",
"start",
"is",
"None",
")",
"!=",
"(",
"stop",
"is",
"None",
")",
":",
"return",
"False",
"elif",
"start",
"is",
"None",
":",
"return",
"length",
"is",
"None... | a220671d66755a94630a212378754bb432811158 |
train | expose | Expose this function to the web layer. | examples/plnt/utils.py | def expose(url_rule, endpoint=None, **kwargs):
"""Expose this function to the web layer."""
def decorate(f):
e = endpoint or f.__name__
endpoints[e] = f
url_map.add(Rule(url_rule, endpoint=e, **kwargs))
return f
return decorate | def expose(url_rule, endpoint=None, **kwargs):
"""Expose this function to the web layer."""
def decorate(f):
e = endpoint or f.__name__
endpoints[e] = f
url_map.add(Rule(url_rule, endpoint=e, **kwargs))
return f
return decorate | [
"Expose",
"this",
"function",
"to",
"the",
"web",
"layer",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/examples/plnt/utils.py#L64-L73 | [
"def",
"expose",
"(",
"url_rule",
",",
"endpoint",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"def",
"decorate",
"(",
"f",
")",
":",
"e",
"=",
"endpoint",
"or",
"f",
".",
"__name__",
"endpoints",
"[",
"e",
"]",
"=",
"f",
"url_map",
".",
"add... | a220671d66755a94630a212378754bb432811158 |
train | render_template | Render a template into a response. | examples/plnt/utils.py | def render_template(template_name, **context):
"""Render a template into a response."""
tmpl = jinja_env.get_template(template_name)
context["url_for"] = url_for
return Response(tmpl.render(context), mimetype="text/html") | def render_template(template_name, **context):
"""Render a template into a response."""
tmpl = jinja_env.get_template(template_name)
context["url_for"] = url_for
return Response(tmpl.render(context), mimetype="text/html") | [
"Render",
"a",
"template",
"into",
"a",
"response",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/examples/plnt/utils.py#L76-L80 | [
"def",
"render_template",
"(",
"template_name",
",",
"*",
"*",
"context",
")",
":",
"tmpl",
"=",
"jinja_env",
".",
"get_template",
"(",
"template_name",
")",
"context",
"[",
"\"url_for\"",
"]",
"=",
"url_for",
"return",
"Response",
"(",
"tmpl",
".",
"render"... | a220671d66755a94630a212378754bb432811158 |
train | nl2p | Add paragraphs to a text. | examples/plnt/utils.py | def nl2p(s):
"""Add paragraphs to a text."""
return u"\n".join(u"<p>%s</p>" % p for p in _par_re.split(s)) | def nl2p(s):
"""Add paragraphs to a text."""
return u"\n".join(u"<p>%s</p>" % p for p in _par_re.split(s)) | [
"Add",
"paragraphs",
"to",
"a",
"text",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/examples/plnt/utils.py#L83-L85 | [
"def",
"nl2p",
"(",
"s",
")",
":",
"return",
"u\"\\n\"",
".",
"join",
"(",
"u\"<p>%s</p>\"",
"%",
"p",
"for",
"p",
"in",
"_par_re",
".",
"split",
"(",
"s",
")",
")"
] | a220671d66755a94630a212378754bb432811158 |
train | strip_tags | Resolve HTML entities and remove tags from a string. | examples/plnt/utils.py | def strip_tags(s):
"""Resolve HTML entities and remove tags from a string."""
def handle_match(m):
name = m.group(1)
if name in html_entities:
return unichr(html_entities[name])
if name[:2] in ("#x", "#X"):
try:
return unichr(int(name[2:], 16))
... | def strip_tags(s):
"""Resolve HTML entities and remove tags from a string."""
def handle_match(m):
name = m.group(1)
if name in html_entities:
return unichr(html_entities[name])
if name[:2] in ("#x", "#X"):
try:
return unichr(int(name[2:], 16))
... | [
"Resolve",
"HTML",
"entities",
"and",
"remove",
"tags",
"from",
"a",
"string",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/examples/plnt/utils.py#L93-L112 | [
"def",
"strip_tags",
"(",
"s",
")",
":",
"def",
"handle_match",
"(",
"m",
")",
":",
"name",
"=",
"m",
".",
"group",
"(",
"1",
")",
"if",
"name",
"in",
"html_entities",
":",
"return",
"unichr",
"(",
"html_entities",
"[",
"name",
"]",
")",
"if",
"nam... | a220671d66755a94630a212378754bb432811158 |
train | JSONMixin.is_json | Check if the mimetype indicates JSON data, either
:mimetype:`application/json` or :mimetype:`application/*+json`. | src/werkzeug/wrappers/json.py | def is_json(self):
"""Check if the mimetype indicates JSON data, either
:mimetype:`application/json` or :mimetype:`application/*+json`.
"""
mt = self.mimetype
return (
mt == "application/json"
or mt.startswith("application/")
and mt.endswith("+... | def is_json(self):
"""Check if the mimetype indicates JSON data, either
:mimetype:`application/json` or :mimetype:`application/*+json`.
"""
mt = self.mimetype
return (
mt == "application/json"
or mt.startswith("application/")
and mt.endswith("+... | [
"Check",
"if",
"the",
"mimetype",
"indicates",
"JSON",
"data",
"either",
":",
"mimetype",
":",
"application",
"/",
"json",
"or",
":",
"mimetype",
":",
"application",
"/",
"*",
"+",
"json",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/wrappers/json.py#L72-L81 | [
"def",
"is_json",
"(",
"self",
")",
":",
"mt",
"=",
"self",
".",
"mimetype",
"return",
"(",
"mt",
"==",
"\"application/json\"",
"or",
"mt",
".",
"startswith",
"(",
"\"application/\"",
")",
"and",
"mt",
".",
"endswith",
"(",
"\"+json\"",
")",
")"
] | a220671d66755a94630a212378754bb432811158 |
train | JSONMixin.get_json | Parse :attr:`data` as JSON.
If the mimetype does not indicate JSON
(:mimetype:`application/json`, see :meth:`is_json`), this
returns ``None``.
If parsing fails, :meth:`on_json_loading_failed` is called and
its return value is used as the return value.
:param force: Ign... | src/werkzeug/wrappers/json.py | def get_json(self, force=False, silent=False, cache=True):
"""Parse :attr:`data` as JSON.
If the mimetype does not indicate JSON
(:mimetype:`application/json`, see :meth:`is_json`), this
returns ``None``.
If parsing fails, :meth:`on_json_loading_failed` is called and
it... | def get_json(self, force=False, silent=False, cache=True):
"""Parse :attr:`data` as JSON.
If the mimetype does not indicate JSON
(:mimetype:`application/json`, see :meth:`is_json`), this
returns ``None``.
If parsing fails, :meth:`on_json_loading_failed` is called and
it... | [
"Parse",
":",
"attr",
":",
"data",
"as",
"JSON",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/wrappers/json.py#L94-L137 | [
"def",
"get_json",
"(",
"self",
",",
"force",
"=",
"False",
",",
"silent",
"=",
"False",
",",
"cache",
"=",
"True",
")",
":",
"if",
"cache",
"and",
"self",
".",
"_cached_json",
"[",
"silent",
"]",
"is",
"not",
"Ellipsis",
":",
"return",
"self",
".",
... | a220671d66755a94630a212378754bb432811158 |
train | ProxyFix._get_trusted_comma | Get the real value from a comma-separated header based on the
configured number of trusted proxies.
:param trusted: Number of values to trust in the header.
:param value: Header value to parse.
:return: The real value, or ``None`` if there are fewer values
than the number of... | src/werkzeug/middleware/proxy_fix.py | def _get_trusted_comma(self, trusted, value):
"""Get the real value from a comma-separated header based on the
configured number of trusted proxies.
:param trusted: Number of values to trust in the header.
:param value: Header value to parse.
:return: The real value, or ``None``... | def _get_trusted_comma(self, trusted, value):
"""Get the real value from a comma-separated header based on the
configured number of trusted proxies.
:param trusted: Number of values to trust in the header.
:param value: Header value to parse.
:return: The real value, or ``None``... | [
"Get",
"the",
"real",
"value",
"from",
"a",
"comma",
"-",
"separated",
"header",
"based",
"on",
"the",
"configured",
"number",
"of",
"trusted",
"proxies",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/middleware/proxy_fix.py#L93-L108 | [
"def",
"_get_trusted_comma",
"(",
"self",
",",
"trusted",
",",
"value",
")",
":",
"if",
"not",
"(",
"trusted",
"and",
"value",
")",
":",
"return",
"values",
"=",
"[",
"x",
".",
"strip",
"(",
")",
"for",
"x",
"in",
"value",
".",
"split",
"(",
"\",\"... | a220671d66755a94630a212378754bb432811158 |
train | sync | Performs a synchronization. Articles that are already syncronized aren't
touched anymore. | examples/plnt/sync.py | def sync():
"""
Performs a synchronization. Articles that are already syncronized aren't
touched anymore.
"""
for blog in Blog.query.all():
# parse the feed. feedparser.parse will never given an exception
# but the bozo bit might be defined.
feed = feedparser.parse(blog.feed_... | def sync():
"""
Performs a synchronization. Articles that are already syncronized aren't
touched anymore.
"""
for blog in Blog.query.all():
# parse the feed. feedparser.parse will never given an exception
# but the bozo bit might be defined.
feed = feedparser.parse(blog.feed_... | [
"Performs",
"a",
"synchronization",
".",
"Articles",
"that",
"are",
"already",
"syncronized",
"aren",
"t",
"touched",
"anymore",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/examples/plnt/sync.py#L26-L109 | [
"def",
"sync",
"(",
")",
":",
"for",
"blog",
"in",
"Blog",
".",
"query",
".",
"all",
"(",
")",
":",
"# parse the feed. feedparser.parse will never given an exception",
"# but the bozo bit might be defined.",
"feed",
"=",
"feedparser",
".",
"parse",
"(",
"blog",
".",... | a220671d66755a94630a212378754bb432811158 |
train | _make_fast_url_quote | Precompile the translation table for a URL encoding function.
Unlike :func:`url_quote`, the generated function only takes the
string to quote.
:param charset: The charset to encode the result with.
:param errors: How to handle encoding errors.
:param safe: An optional sequence of safe characters t... | src/werkzeug/urls.py | def _make_fast_url_quote(charset="utf-8", errors="strict", safe="/:", unsafe=""):
"""Precompile the translation table for a URL encoding function.
Unlike :func:`url_quote`, the generated function only takes the
string to quote.
:param charset: The charset to encode the result with.
:param errors: ... | def _make_fast_url_quote(charset="utf-8", errors="strict", safe="/:", unsafe=""):
"""Precompile the translation table for a URL encoding function.
Unlike :func:`url_quote`, the generated function only takes the
string to quote.
:param charset: The charset to encode the result with.
:param errors: ... | [
"Precompile",
"the",
"translation",
"table",
"for",
"a",
"URL",
"encoding",
"function",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/urls.py#L487-L517 | [
"def",
"_make_fast_url_quote",
"(",
"charset",
"=",
"\"utf-8\"",
",",
"errors",
"=",
"\"strict\"",
",",
"safe",
"=",
"\"/:\"",
",",
"unsafe",
"=",
"\"\"",
")",
":",
"if",
"isinstance",
"(",
"safe",
",",
"text_type",
")",
":",
"safe",
"=",
"safe",
".",
... | a220671d66755a94630a212378754bb432811158 |
train | url_unquote_plus | URL decode a single string with the given `charset` and decode "+" to
whitespace.
Per default encoding errors are ignored. If you want a different behavior
you can set `errors` to ``'replace'`` or ``'strict'``. In strict mode a
:exc:`HTTPUnicodeError` is raised.
:param s: The string to unquote.
... | src/werkzeug/urls.py | def url_unquote_plus(s, charset="utf-8", errors="replace"):
"""URL decode a single string with the given `charset` and decode "+" to
whitespace.
Per default encoding errors are ignored. If you want a different behavior
you can set `errors` to ``'replace'`` or ``'strict'``. In strict mode a
:exc:`... | def url_unquote_plus(s, charset="utf-8", errors="replace"):
"""URL decode a single string with the given `charset` and decode "+" to
whitespace.
Per default encoding errors are ignored. If you want a different behavior
you can set `errors` to ``'replace'`` or ``'strict'``. In strict mode a
:exc:`... | [
"URL",
"decode",
"a",
"single",
"string",
"with",
"the",
"given",
"charset",
"and",
"decode",
"+",
"to",
"whitespace",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/urls.py#L614-L631 | [
"def",
"url_unquote_plus",
"(",
"s",
",",
"charset",
"=",
"\"utf-8\"",
",",
"errors",
"=",
"\"replace\"",
")",
":",
"if",
"isinstance",
"(",
"s",
",",
"text_type",
")",
":",
"s",
"=",
"s",
".",
"replace",
"(",
"u\"+\"",
",",
"u\" \"",
")",
"else",
":... | a220671d66755a94630a212378754bb432811158 |
train | _codec_error_url_quote | Used in :func:`uri_to_iri` after unquoting to re-quote any
invalid bytes. | src/werkzeug/urls.py | def _codec_error_url_quote(e):
"""Used in :func:`uri_to_iri` after unquoting to re-quote any
invalid bytes.
"""
out = _fast_url_quote(e.object[e.start : e.end])
if PY2:
out = out.decode("utf-8")
return out, e.end | def _codec_error_url_quote(e):
"""Used in :func:`uri_to_iri` after unquoting to re-quote any
invalid bytes.
"""
out = _fast_url_quote(e.object[e.start : e.end])
if PY2:
out = out.decode("utf-8")
return out, e.end | [
"Used",
"in",
":",
"func",
":",
"uri_to_iri",
"after",
"unquoting",
"to",
"re",
"-",
"quote",
"any",
"invalid",
"bytes",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/urls.py#L668-L677 | [
"def",
"_codec_error_url_quote",
"(",
"e",
")",
":",
"out",
"=",
"_fast_url_quote",
"(",
"e",
".",
"object",
"[",
"e",
".",
"start",
":",
"e",
".",
"end",
"]",
")",
"if",
"PY2",
":",
"out",
"=",
"out",
".",
"decode",
"(",
"\"utf-8\"",
")",
"return"... | a220671d66755a94630a212378754bb432811158 |
train | url_join | Join a base URL and a possibly relative URL to form an absolute
interpretation of the latter.
:param base: the base URL for the join operation.
:param url: the URL to join.
:param allow_fragments: indicates whether fragments should be allowed. | src/werkzeug/urls.py | def url_join(base, url, allow_fragments=True):
"""Join a base URL and a possibly relative URL to form an absolute
interpretation of the latter.
:param base: the base URL for the join operation.
:param url: the URL to join.
:param allow_fragments: indicates whether fragments should be allowed.
"... | def url_join(base, url, allow_fragments=True):
"""Join a base URL and a possibly relative URL to form an absolute
interpretation of the latter.
:param base: the base URL for the join operation.
:param url: the URL to join.
:param allow_fragments: indicates whether fragments should be allowed.
"... | [
"Join",
"a",
"base",
"URL",
"and",
"a",
"possibly",
"relative",
"URL",
"to",
"form",
"an",
"absolute",
"interpretation",
"of",
"the",
"latter",
"."
] | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/urls.py#L975-L1039 | [
"def",
"url_join",
"(",
"base",
",",
"url",
",",
"allow_fragments",
"=",
"True",
")",
":",
"if",
"isinstance",
"(",
"base",
",",
"tuple",
")",
":",
"base",
"=",
"url_unparse",
"(",
"base",
")",
"if",
"isinstance",
"(",
"url",
",",
"tuple",
")",
":",
... | a220671d66755a94630a212378754bb432811158 |
train | BaseURL.ascii_host | Works exactly like :attr:`host` but will return a result that
is restricted to ASCII. If it finds a netloc that is not ASCII
it will attempt to idna decode it. This is useful for socket
operations when the URL might include internationalized characters. | src/werkzeug/urls.py | def ascii_host(self):
"""Works exactly like :attr:`host` but will return a result that
is restricted to ASCII. If it finds a netloc that is not ASCII
it will attempt to idna decode it. This is useful for socket
operations when the URL might include internationalized characters.
... | def ascii_host(self):
"""Works exactly like :attr:`host` but will return a result that
is restricted to ASCII. If it finds a netloc that is not ASCII
it will attempt to idna decode it. This is useful for socket
operations when the URL might include internationalized characters.
... | [
"Works",
"exactly",
"like",
":",
"attr",
":",
"host",
"but",
"will",
"return",
"a",
"result",
"that",
"is",
"restricted",
"to",
"ASCII",
".",
"If",
"it",
"finds",
"a",
"netloc",
"that",
"is",
"not",
"ASCII",
"it",
"will",
"attempt",
"to",
"idna",
"deco... | pallets/werkzeug | python | https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/urls.py#L81-L93 | [
"def",
"ascii_host",
"(",
"self",
")",
":",
"rv",
"=",
"self",
".",
"host",
"if",
"rv",
"is",
"not",
"None",
"and",
"isinstance",
"(",
"rv",
",",
"text_type",
")",
":",
"try",
":",
"rv",
"=",
"_encode_idna",
"(",
"rv",
")",
"except",
"UnicodeError",
... | a220671d66755a94630a212378754bb432811158 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.