docstring_tokens
stringlengths
0
76.5k
code_tokens
stringlengths
75
1.81M
label_window
listlengths
4
2.12k
html_url
stringlengths
74
116
file_name
stringlengths
3
311
return rv.encode(encoding) # type: ignore
<mask> stacklevel=2, <mask> ) <mask> <mask> if isinstance(rv, str): <mask> return rv.encode(encoding) <mask> <mask> return rv <mask> <mask> <mask> def dump(obj, fp, app=None, **kwargs): </s> Add initial type hints This should make it easier for users to correc...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/77237093da25438c88b0a74c374a397d4bf823eb
src/flask/json/__init__.py
def dump( obj: t.Any, fp: t.IO[str], app: t.Optional["Flask"] = None, **kwargs: t.Any ) -> None:
<mask> <mask> return rv <mask> <mask> <mask> def dump(obj, fp, app=None, **kwargs): <mask> """Serialize an object to JSON written to a file object. <mask> <mask> Takes the same arguments as the built-in :func:`json.dump`, with <mask> some defaults from application configuration. <mask> <...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/77237093da25438c88b0a74c374a397d4bf823eb
src/flask/json/__init__.py
fp = io.TextIOWrapper(fp, encoding or "utf-8") # type: ignore
<mask> try: <mask> fp.write("") <mask> except TypeError: <mask> show_warning = True <mask> fp = io.TextIOWrapper(fp, encoding or "utf-8") <mask> <mask> if show_warning: <mask> warnings.warn( <mask> "Writing to a binary file, and the 'encoding' argument, ...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/77237093da25438c88b0a74c374a397d4bf823eb
src/flask/json/__init__.py
def loads(s: str, app: t.Optional["Flask"] = None, **kwargs: t.Any) -> t.Any:
<mask> <mask> _json.dump(obj, fp, **kwargs) <mask> <mask> <mask> def loads(s, app=None, **kwargs): <mask> """Deserialize an object from a string of JSON. <mask> <mask> Takes the same arguments as the built-in :func:`json.loads`, with <mask> some defaults from application configuration. <ma...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/77237093da25438c88b0a74c374a397d4bf823eb
src/flask/json/__init__.py
def load(fp: t.IO[str], app: t.Optional["Flask"] = None, **kwargs: t.Any) -> t.Any:
<mask> <mask> return _json.loads(s, **kwargs) <mask> <mask> <mask> def load(fp, app=None, **kwargs): <mask> """Deserialize an object from JSON read from a file object. <mask> <mask> Takes the same arguments as the built-in :func:`json.load`, with <mask> some defaults from application config...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/77237093da25438c88b0a74c374a397d4bf823eb
src/flask/json/__init__.py
fp = io.TextIOWrapper(fp, encoding) # type: ignore
<mask> stacklevel=2, <mask> ) <mask> <mask> if isinstance(fp.read(0), bytes): <mask> fp = io.TextIOWrapper(fp, encoding) <mask> <mask> return _json.load(fp, **kwargs) <mask> <mask> <mask> def htmlsafe_dumps(obj, **kwargs): </s> Add initial type hints This shou...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/77237093da25438c88b0a74c374a397d4bf823eb
src/flask/json/__init__.py
def htmlsafe_dumps(obj: t.Any, **kwargs: t.Any) -> str:
<mask> <mask> return _json.load(fp, **kwargs) <mask> <mask> <mask> def htmlsafe_dumps(obj, **kwargs): <mask> """Serialize an object to a string of JSON with :func:`dumps`, then <mask> replace HTML-unsafe characters with Unicode escapes and mark the <mask> result safe with :class:`~markupsafe....
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/77237093da25438c88b0a74c374a397d4bf823eb
src/flask/json/__init__.py
def htmlsafe_dump(obj: t.Any, fp: t.IO[str], **kwargs: t.Any) -> None:
<mask> """ <mask> return _jinja_htmlsafe_dumps(obj, dumps=dumps, **kwargs) <mask> <mask> <mask> def htmlsafe_dump(obj, fp, **kwargs): <mask> """Serialize an object to JSON written to a file object, replacing <mask> HTML-unsafe characters with Unicode escapes. See <mask> :func:`htmlsafe_dum...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/77237093da25438c88b0a74c374a397d4bf823eb
src/flask/json/__init__.py
def jsonify(*args: t.Any, **kwargs: t.Any) -> "Response":
<mask> """ <mask> fp.write(htmlsafe_dumps(obj, **kwargs)) <mask> <mask> <mask> def jsonify(*args, **kwargs): <mask> """Serialize data to JSON and wrap it in a :class:`~flask.Response` <mask> with the :mimetype:`application/json` mimetype. <mask> <mask> Uses :func:`dumps` to serialize the...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/77237093da25438c88b0a74c374a397d4bf823eb
src/flask/json/__init__.py
import typing as t
<mask> <mask> app.session_interface.serializer.register(TagOrderedDict, index=0) <mask> """ <mask> from base64 import b64decode <mask> from base64 import b64encode <mask> from datetime import datetime <mask> from uuid import UUID <mask> <mask> from markupsafe import Markup </s> Add initial type hints T...
[ "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/77237093da25438c88b0a74c374a397d4bf823eb
src/flask/json/tag.py
key: t.Optional[str] = None
<mask> __slots__ = ("serializer",) <mask> <mask> #: The tag to mark the serialized object with. If ``None``, this tag is <mask> #: only used as an intermediate step during tagging. <mask> key = None <mask> <mask> def __init__(self, serializer): <mask> """Create a tagger for the giv...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/77237093da25438c88b0a74c374a397d4bf823eb
src/flask/json/tag.py
def __init__(self, serializer: "TaggedJSONSerializer") -> None:
<mask> #: The tag to mark the serialized object with. If ``None``, this tag is <mask> #: only used as an intermediate step during tagging. <mask> key = None <mask> <mask> def __init__(self, serializer): <mask> """Create a tagger for the given serializer.""" <mask> self.serializer...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/77237093da25438c88b0a74c374a397d4bf823eb
src/flask/json/tag.py
def check(self, value: t.Any) -> bool:
<mask> def __init__(self, serializer): <mask> """Create a tagger for the given serializer.""" <mask> self.serializer = serializer <mask> <mask> def check(self, value): <mask> """Check if the given value should be tagged by this tag.""" <mask> raise NotImplementedError <m...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/77237093da25438c88b0a74c374a397d4bf823eb
src/flask/json/tag.py
def to_json(self, value: t.Any) -> t.Any:
<mask> def check(self, value): <mask> """Check if the given value should be tagged by this tag.""" <mask> raise NotImplementedError <mask> <mask> def to_json(self, value): <mask> """Convert the Python object to an object that is a valid JSON type. <mask> The tag will be a...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/77237093da25438c88b0a74c374a397d4bf823eb
src/flask/json/tag.py
def to_python(self, value: t.Any) -> t.Any:
<mask> """Convert the Python object to an object that is a valid JSON type. <mask> The tag will be added later.""" <mask> raise NotImplementedError <mask> <mask> def to_python(self, value): <mask> """Convert the JSON representation back to the correct type. The tag <mask> ...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/77237093da25438c88b0a74c374a397d4bf823eb
src/flask/json/tag.py
def tag(self, value: t.Any) -> t.Any:
<mask> """Convert the JSON representation back to the correct type. The tag <mask> will already be removed.""" <mask> raise NotImplementedError <mask> <mask> def tag(self, value): <mask> """Convert the value to a valid JSON type and add the tag structure <mask> around...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/77237093da25438c88b0a74c374a397d4bf823eb
src/flask/json/tag.py
def check(self, value: t.Any) -> bool:
<mask> <mask> __slots__ = () <mask> key = " di" <mask> <mask> def check(self, value): <mask> return ( <mask> isinstance(value, dict) <mask> and len(value) == 1 <mask> and next(iter(value)) in self.serializer.tags <mask> ) </s> Add initial type...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/77237093da25438c88b0a74c374a397d4bf823eb
src/flask/json/tag.py
def to_json(self, value: t.Any) -> t.Any:
<mask> and len(value) == 1 <mask> and next(iter(value)) in self.serializer.tags <mask> ) <mask> <mask> def to_json(self, value): <mask> key = next(iter(value)) <mask> return {f"{key}__": self.serializer.tag(value[key])} <mask> <mask> def to_python(self,...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/77237093da25438c88b0a74c374a397d4bf823eb
src/flask/json/tag.py
def to_python(self, value: t.Any) -> t.Any:
<mask> def to_json(self, value): <mask> key = next(iter(value)) <mask> return {f"{key}__": self.serializer.tag(value[key])} <mask> <mask> def to_python(self, value): <mask> key = next(iter(value)) <mask> return {key[:-2]: value[key]} <mask> <mask> <mask> class PassDi...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/77237093da25438c88b0a74c374a397d4bf823eb
src/flask/json/tag.py
def check(self, value: t.Any) -> bool:
<mask> <mask> class PassDict(JSONTag): <mask> __slots__ = () <mask> <mask> def check(self, value): <mask> return isinstance(value, dict) <mask> <mask> def to_json(self, value): <mask> # JSON objects may only have string keys, so don't bother tagging the <mask> # key here...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/77237093da25438c88b0a74c374a397d4bf823eb
src/flask/json/tag.py
def to_json(self, value: t.Any) -> t.Any:
<mask> <mask> def check(self, value): <mask> return isinstance(value, dict) <mask> <mask> def to_json(self, value): <mask> # JSON objects may only have string keys, so don't bother tagging the <mask> # key here. <mask> return {k: self.serializer.tag(v) for k, v in value...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/77237093da25438c88b0a74c374a397d4bf823eb
src/flask/json/tag.py
def check(self, value: t.Any) -> bool:
<mask> class TagTuple(JSONTag): <mask> __slots__ = () <mask> key = " t" <mask> <mask> def check(self, value): <mask> return isinstance(value, tuple) <mask> <mask> def to_json(self, value): <mask> return [self.serializer.tag(item) for item in value] <mask> </s> Add initial t...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/77237093da25438c88b0a74c374a397d4bf823eb
src/flask/json/tag.py
def to_json(self, value: t.Any) -> t.Any:
<mask> <mask> def check(self, value): <mask> return isinstance(value, tuple) <mask> <mask> def to_json(self, value): <mask> return [self.serializer.tag(item) for item in value] <mask> <mask> def to_python(self, value): <mask> return tuple(value) <mask> </s> Add initial...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/77237093da25438c88b0a74c374a397d4bf823eb
src/flask/json/tag.py
def to_python(self, value: t.Any) -> t.Any:
<mask> <mask> def to_json(self, value): <mask> return [self.serializer.tag(item) for item in value] <mask> <mask> def to_python(self, value): <mask> return tuple(value) <mask> <mask> <mask> class PassList(JSONTag): <mask> __slots__ = () </s> Add initial type hints This should...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/77237093da25438c88b0a74c374a397d4bf823eb
src/flask/json/tag.py
def check(self, value: t.Any) -> bool:
<mask> <mask> class PassList(JSONTag): <mask> __slots__ = () <mask> <mask> def check(self, value): <mask> return isinstance(value, list) <mask> <mask> def to_json(self, value): <mask> return [self.serializer.tag(item) for item in value] <mask> </s> Add initial type hints This...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/77237093da25438c88b0a74c374a397d4bf823eb
src/flask/json/tag.py
def to_json(self, value: t.Any) -> t.Any:
<mask> <mask> def check(self, value): <mask> return isinstance(value, list) <mask> <mask> def to_json(self, value): <mask> return [self.serializer.tag(item) for item in value] <mask> <mask> tag = to_json <mask> <mask> </s> Add initial type hints This should make it easier fo...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/77237093da25438c88b0a74c374a397d4bf823eb
src/flask/json/tag.py
def check(self, value: t.Any) -> bool:
<mask> class TagBytes(JSONTag): <mask> __slots__ = () <mask> key = " b" <mask> <mask> def check(self, value): <mask> return isinstance(value, bytes) <mask> <mask> def to_json(self, value): <mask> return b64encode(value).decode("ascii") <mask> </s> Add initial type hints Th...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/77237093da25438c88b0a74c374a397d4bf823eb
src/flask/json/tag.py
def to_json(self, value: t.Any) -> t.Any:
<mask> <mask> def check(self, value): <mask> return isinstance(value, bytes) <mask> <mask> def to_json(self, value): <mask> return b64encode(value).decode("ascii") <mask> <mask> def to_python(self, value): <mask> return b64decode(value) <mask> </s> Add initial type hin...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/77237093da25438c88b0a74c374a397d4bf823eb
src/flask/json/tag.py
def to_python(self, value: t.Any) -> t.Any:
<mask> <mask> def to_json(self, value): <mask> return b64encode(value).decode("ascii") <mask> <mask> def to_python(self, value): <mask> return b64decode(value) <mask> <mask> <mask> class TagMarkup(JSONTag): <mask> """Serialize anything matching the :class:`~markupsafe.Markup` A...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/77237093da25438c88b0a74c374a397d4bf823eb
src/flask/json/tag.py
def check(self, value: t.Any) -> bool:
<mask> <mask> __slots__ = () <mask> key = " m" <mask> <mask> def check(self, value): <mask> return callable(getattr(value, "__html__", None)) <mask> <mask> def to_json(self, value): <mask> return str(value.__html__()) <mask> </s> Add initial type hints This should make it...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/77237093da25438c88b0a74c374a397d4bf823eb
src/flask/json/tag.py
def to_json(self, value: t.Any) -> t.Any:
<mask> <mask> def check(self, value): <mask> return callable(getattr(value, "__html__", None)) <mask> <mask> def to_json(self, value): <mask> return str(value.__html__()) <mask> <mask> def to_python(self, value): <mask> return Markup(value) <mask> </s> Add initial type...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/77237093da25438c88b0a74c374a397d4bf823eb
src/flask/json/tag.py
def to_python(self, value: t.Any) -> t.Any:
<mask> <mask> def to_json(self, value): <mask> return str(value.__html__()) <mask> <mask> def to_python(self, value): <mask> return Markup(value) <mask> <mask> <mask> class TagUUID(JSONTag): <mask> __slots__ = () </s> Add initial type hints This should make it easier for user...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/77237093da25438c88b0a74c374a397d4bf823eb
src/flask/json/tag.py
def check(self, value: t.Any) -> bool:
<mask> class TagUUID(JSONTag): <mask> __slots__ = () <mask> key = " u" <mask> <mask> def check(self, value): <mask> return isinstance(value, UUID) <mask> <mask> def to_json(self, value): <mask> return value.hex <mask> </s> Add initial type hints This should make it easier ...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/77237093da25438c88b0a74c374a397d4bf823eb
src/flask/json/tag.py
def to_json(self, value: t.Any) -> t.Any:
<mask> <mask> def check(self, value): <mask> return isinstance(value, UUID) <mask> <mask> def to_json(self, value): <mask> return value.hex <mask> <mask> def to_python(self, value): <mask> return UUID(value) <mask> </s> Add initial type hints This should make it easie...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/77237093da25438c88b0a74c374a397d4bf823eb
src/flask/json/tag.py
def to_python(self, value: t.Any) -> t.Any:
<mask> <mask> def to_json(self, value): <mask> return value.hex <mask> <mask> def to_python(self, value): <mask> return UUID(value) <mask> <mask> <mask> class TagDateTime(JSONTag): <mask> __slots__ = () </s> Add initial type hints This should make it easier for users to corre...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/77237093da25438c88b0a74c374a397d4bf823eb
src/flask/json/tag.py
def check(self, value: t.Any) -> bool:
<mask> class TagDateTime(JSONTag): <mask> __slots__ = () <mask> key = " d" <mask> <mask> def check(self, value): <mask> return isinstance(value, datetime) <mask> <mask> def to_json(self, value): <mask> return http_date(value) <mask> </s> Add initial type hints This should ...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/77237093da25438c88b0a74c374a397d4bf823eb
src/flask/json/tag.py
def to_json(self, value: t.Any) -> t.Any:
<mask> <mask> def check(self, value): <mask> return isinstance(value, datetime) <mask> <mask> def to_json(self, value): <mask> return http_date(value) <mask> <mask> def to_python(self, value): <mask> return parse_date(value) <mask> </s> Add initial type hints This sho...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/77237093da25438c88b0a74c374a397d4bf823eb
src/flask/json/tag.py
def to_python(self, value: t.Any) -> t.Any:
<mask> <mask> def to_json(self, value): <mask> return http_date(value) <mask> <mask> def to_python(self, value): <mask> return parse_date(value) <mask> <mask> <mask> class TaggedJSONSerializer: <mask> """Serializer that uses a tag system to compactly represent objects that </s...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/77237093da25438c88b0a74c374a397d4bf823eb
src/flask/json/tag.py
def __init__(self) -> None: self.tags: t.Dict[str, JSONTag] = {} self.order: t.List[JSONTag] = []
<mask> TagUUID, <mask> TagDateTime, <mask> ] <mask> <mask> def __init__(self): <mask> self.tags = {} <mask> self.order = [] <mask> <mask> for cls in self.default_tags: <mask> self.register(cls) <mask> <mask> def register(self, tag_class, for...
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/77237093da25438c88b0a74c374a397d4bf823eb
src/flask/json/tag.py
def register( self, tag_class: t.Type[JSONTag], force: bool = False, index: t.Optional[int] = None, ) -> None:
<mask> <mask> for cls in self.default_tags: <mask> self.register(cls) <mask> <mask> def register(self, tag_class, force=False, index=None): <mask> """Register a new tag with this serializer. <mask> <mask> :param tag_class: tag class to register. Will be instantiated wi...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/77237093da25438c88b0a74c374a397d4bf823eb
src/flask/json/tag.py
def tag(self, value: t.Any) -> t.Dict[str, t.Any]:
<mask> self.order.append(tag) <mask> else: <mask> self.order.insert(index, tag) <mask> <mask> def tag(self, value): <mask> """Convert a value to a tagged representation if necessary.""" <mask> for tag in self.order: <mask> if tag.check(value): <m...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/77237093da25438c88b0a74c374a397d4bf823eb
src/flask/json/tag.py
def untag(self, value: t.Dict[str, t.Any]) -> t.Any:
<mask> return tag.tag(value) <mask> <mask> return value <mask> <mask> def untag(self, value): <mask> """Convert a tagged representation back to the original type.""" <mask> if len(value) != 1: <mask> return value <mask> <mask> key = next(iter(...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/77237093da25438c88b0a74c374a397d4bf823eb
src/flask/json/tag.py
def dumps(self, value: t.Any) -> str:
<mask> return value <mask> <mask> return self.tags[key].to_python(value[key]) <mask> <mask> def dumps(self, value): <mask> """Tag the value and dump it to a compact JSON string.""" <mask> return dumps(self.tag(value), separators=(",", ":")) <mask> <mask> def loads...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/77237093da25438c88b0a74c374a397d4bf823eb
src/flask/json/tag.py
def loads(self, value: str) -> t.Any:
<mask> def dumps(self, value): <mask> """Tag the value and dump it to a compact JSON string.""" <mask> return dumps(self.tag(value), separators=(",", ":")) <mask> <mask> def loads(self, value): <mask> """Load data from a JSON string and deserialized any tagged objects.""" <mask> ...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep" ]
https://github.com/pallets/flask/commit/77237093da25438c88b0a74c374a397d4bf823eb
src/flask/json/tag.py
import typing as t
<mask> import logging <mask> import sys <mask> <mask> from werkzeug.local import LocalProxy <mask> <mask> from .globals import request <mask> </s> Add initial type hints This should make it easier for users to correctly use Flask. The hints are from Quart.
[ "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/77237093da25438c88b0a74c374a397d4bf823eb
src/flask/logging.py
if t.TYPE_CHECKING: from .app import Flask
<mask> <mask> from .globals import request <mask> <mask> <mask> @LocalProxy <mask> def wsgi_errors_stream() -> t.TextIO: <mask> """Find the most appropriate error stream for the application. If a request </s> Add initial type hints This should make it easier for users to correctly use Flask. The hints a...
[ "keep", "keep", "add", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/77237093da25438c88b0a74c374a397d4bf823eb
src/flask/logging.py
def wsgi_errors_stream() -> t.TextIO:
<mask> from .globals import request <mask> <mask> <mask> @LocalProxy <mask> def wsgi_errors_stream(): <mask> """Find the most appropriate error stream for the application. If a request <mask> is active, log to ``wsgi.errors``, otherwise use ``sys.stderr``. <mask> <mask> If you configure your own...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/77237093da25438c88b0a74c374a397d4bf823eb
src/flask/logging.py
def has_level_handler(logger: logging.Logger) -> bool:
<mask> """ <mask> return request.environ["wsgi.errors"] if request else sys.stderr <mask> <mask> <mask> def has_level_handler(logger): <mask> """Check if there is a handler in the logging chain that will handle the <mask> given logger's :meth:`effective level <~logging.Logger.getEffectiveLevel>...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/77237093da25438c88b0a74c374a397d4bf823eb
src/flask/logging.py
current = current.parent # type: ignore
<mask> <mask> if not current.propagate: <mask> break <mask> <mask> current = current.parent <mask> <mask> return False <mask> <mask> <mask> #: Log messages to :func:`~flask.logging.wsgi_errors_stream` with the format </s> Add initial type hints This should make it easier...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/77237093da25438c88b0a74c374a397d4bf823eb
src/flask/logging.py
default_handler = logging.StreamHandler(wsgi_errors_stream) # type: ignore
<mask> <mask> <mask> #: Log messages to :func:`~flask.logging.wsgi_errors_stream` with the format <mask> #: ``[%(asctime)s] %(levelname)s in %(module)s: %(message)s``. <mask> default_handler = logging.StreamHandler(wsgi_errors_stream) <mask> default_handler.setFormatter( <mask> logging.Formatter("[%(asctim...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/77237093da25438c88b0a74c374a397d4bf823eb
src/flask/logging.py
def create_logger(app: "Flask") -> logging.Logger:
<mask> logging.Formatter("[%(asctime)s] %(levelname)s in %(module)s: %(message)s") <mask> ) <mask> <mask> <mask> def create_logger(app): <mask> """Get the Flask app's logger and configure it if needed. <mask> <mask> The logger name will be the same as <mask> :attr:`app.import_name <flask.Fla...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/77237093da25438c88b0a74c374a397d4bf823eb
src/flask/logging.py
import typing as t
<mask> import importlib.util <mask> import os <mask> import pkgutil <mask> import sys <mask> from collections import defaultdict <mask> from functools import update_wrapper <mask> from json import JSONDecoder <mask> from json import JSONEncoder </s> Add initial type hints This should make it easier for users ...
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/77237093da25438c88b0a74c374a397d4bf823eb
src/flask/scaffold.py
from json import JSONDecoder from json import JSONEncoder
<mask> import typing as t <mask> from collections import defaultdict <mask> from functools import update_wrapper <mask> <mask> from jinja2 import FileSystemLoader <mask> from werkzeug.exceptions import default_exceptions <mask> from werkzeug.exceptions import HTTPException </s> Add initial type hints This sho...
[ "keep", "keep", "add", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/77237093da25438c88b0a74c374a397d4bf823eb
src/flask/scaffold.py
from .typing import AfterRequestCallable from .typing import AppOrBlueprintKey from .typing import BeforeRequestCallable from .typing import ErrorHandlerCallable from .typing import TeardownCallable from .typing import TemplateContextProcessorCallable from .typing import URLDefaultCallable from .typing import URLValueP...
<mask> from .helpers import send_from_directory <mask> from .templating import _default_template_ctx_processor <mask> <mask> # a singleton sentinel value for parameter defaults <mask> _sentinel = object() <mask> <mask> <mask> def setupmethod(f: t.Callable) -> t.Callable: </s> Add initial type hints This sh...
[ "keep", "add", "keep", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/77237093da25438c88b0a74c374a397d4bf823eb
src/flask/scaffold.py
def setupmethod(f: t.Callable) -> t.Callable:
<mask> # a singleton sentinel value for parameter defaults <mask> _sentinel = object() <mask> <mask> <mask> def setupmethod(f): <mask> """Wraps a method so that it performs a check in debug mode if the <mask> first request was already handled. <mask> """ <mask> <mask> def wrapper_func(self,...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/77237093da25438c88b0a74c374a397d4bf823eb
src/flask/scaffold.py
def wrapper_func(self, *args: t.Any, **kwargs: t.Any) -> t.Any:
<mask> """Wraps a method so that it performs a check in debug mode if the <mask> first request was already handled. <mask> """ <mask> <mask> def wrapper_func(self, *args, **kwargs): <mask> if self._is_setup_finished(): <mask> raise AssertionError( <mask> "A s...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/77237093da25438c88b0a74c374a397d4bf823eb
src/flask/scaffold.py
_static_folder: t.Optional[str] = None _static_url_path: t.Optional[str] = None
<mask> .. versionadded:: 2.0 <mask> """ <mask> <mask> name: str <mask> _static_folder = None <mask> _static_url_path = None <mask> <mask> #: JSON encoder class used by :func:`flask.json.dumps`. If a <mask> #: blueprint sets this, it will be used instead of the app's value. <mask>...
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/77237093da25438c88b0a74c374a397d4bf823eb
src/flask/scaffold.py
self.teardown_request_funcs: t.Dict[ AppOrBlueprintKey, t.List[TeardownCallable] ] = defaultdict(list)
<mask> #: decorator. <mask> #: <mask> #: This data structure is internal. It should not be modified <mask> #: directly and its format may change at any time. <mask> self.teardown_request_funcs = defaultdict(list) <mask> <mask> #: A data structure of functions to c...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/77237093da25438c88b0a74c374a397d4bf823eb
src/flask/scaffold.py
self.template_context_processors: t.Dict[ AppOrBlueprintKey, t.List[TemplateContextProcessorCallable] ] = defaultdict(list, {None: [_default_template_ctx_processor]})
<mask> #: decorator. <mask> #: <mask> #: This data structure is internal. It should not be modified <mask> #: directly and its format may change at any time. <mask> self.template_context_processors = defaultdict( <mask> list, {None: [_default_template_ctx_proces...
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/77237093da25438c88b0a74c374a397d4bf823eb
src/flask/scaffold.py
self.url_value_preprocessors: t.Dict[ AppOrBlueprintKey, t.List[URLValuePreprocessorCallable], ] = defaultdict(list)
<mask> #: :meth:`url_value_preprocessor` decorator. <mask> #: <mask> #: This data structure is internal. It should not be modified <mask> #: directly and its format may change at any time. <mask> self.url_value_preprocessors = defaultdict(list) <mask> <mask> #: A ...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/77237093da25438c88b0a74c374a397d4bf823eb
src/flask/scaffold.py
self.url_default_functions: t.Dict[ AppOrBlueprintKey, t.List[URLDefaultCallable] ] = defaultdict(list)
<mask> #: decorator. <mask> #: <mask> #: This data structure is internal. It should not be modified <mask> #: directly and its format may change at any time. <mask> self.url_default_functions = defaultdict(list) <mask> <mask> def __repr__(self): <mask> return...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/77237093da25438c88b0a74c374a397d4bf823eb
src/flask/scaffold.py
def __repr__(self) -> str:
<mask> #: This data structure is internal. It should not be modified <mask> #: directly and its format may change at any time. <mask> self.url_default_functions = defaultdict(list) <mask> <mask> def __repr__(self): <mask> return f"<{type(self).__name__} {self.name!r}>" <mask>...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/77237093da25438c88b0a74c374a397d4bf823eb
src/flask/scaffold.py
def _is_setup_finished(self) -> bool:
<mask> <mask> def __repr__(self): <mask> return f"<{type(self).__name__} {self.name!r}>" <mask> <mask> def _is_setup_finished(self): <mask> raise NotImplementedError <mask> <mask> @property <mask> def static_folder(self): <mask> """The absolute path to the configured...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/77237093da25438c88b0a74c374a397d4bf823eb
src/flask/scaffold.py
def static_folder(self) -> t.Optional[str]:
<mask> def _is_setup_finished(self): <mask> raise NotImplementedError <mask> <mask> @property <mask> def static_folder(self): <mask> """The absolute path to the configured static folder. ``None`` <mask> if no static folder is set. <mask> """ <mask> if self._...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/77237093da25438c88b0a74c374a397d4bf823eb
src/flask/scaffold.py
else: return None
<mask> if self._static_folder is not None: <mask> return os.path.join(self.root_path, self._static_folder) <mask> <mask> @static_folder.setter <mask> def static_folder(self, value: t.Optional[str]) -> None: <mask> if value is not None: <mask> value = os.fspath(val...
[ "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/77237093da25438c88b0a74c374a397d4bf823eb
src/flask/scaffold.py
def static_folder(self, value: t.Optional[str]) -> None:
<mask> if self._static_folder is not None: <mask> return os.path.join(self.root_path, self._static_folder) <mask> <mask> @static_folder.setter <mask> def static_folder(self, value): <mask> if value is not None: <mask> value = os.fspath(value).rstrip(r"\/") <mask>...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/77237093da25438c88b0a74c374a397d4bf823eb
src/flask/scaffold.py
def has_static_folder(self) -> bool:
<mask> <mask> self._static_folder = value <mask> <mask> @property <mask> def has_static_folder(self): <mask> """``True`` if :attr:`static_folder` is set. <mask> <mask> .. versionadded:: 0.5 <mask> """ <mask> return self.static_folder is not None </s> Add ini...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/77237093da25438c88b0a74c374a397d4bf823eb
src/flask/scaffold.py
def static_url_path(self) -> t.Optional[str]:
<mask> """ <mask> return self.static_folder is not None <mask> <mask> @property <mask> def static_url_path(self): <mask> """The URL prefix that the static route will be accessible from. <mask> <mask> If it was not configured during init, it is derived from <mask> ...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/77237093da25438c88b0a74c374a397d4bf823eb
src/flask/scaffold.py
return None
<mask> basename = os.path.basename(self.static_folder) <mask> return f"/{basename}".rstrip("/") <mask> <mask> @static_url_path.setter <mask> def static_url_path(self, value: t.Optional[str]) -> None: <mask> if value is not None: <mask> value = value.rstrip("/"...
[ "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/77237093da25438c88b0a74c374a397d4bf823eb
src/flask/scaffold.py
def static_url_path(self, value: t.Optional[str]) -> None:
<mask> basename = os.path.basename(self.static_folder) <mask> return f"/{basename}".rstrip("/") <mask> <mask> @static_url_path.setter <mask> def static_url_path(self, value): <mask> if value is not None: <mask> value = value.rstrip("/") <mask> <mask> ...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/77237093da25438c88b0a74c374a397d4bf823eb
src/flask/scaffold.py
def get_send_file_max_age(self, filename: str) -> t.Optional[int]:
<mask> value = value.rstrip("/") <mask> <mask> self._static_url_path = value <mask> <mask> def get_send_file_max_age(self, filename): <mask> """Used by :func:`send_file` to determine the ``max_age`` cache <mask> value for a given file path if it wasn't passed. <mask> ...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/77237093da25438c88b0a74c374a397d4bf823eb
src/flask/scaffold.py
def send_static_file(self, filename: str) -> "Response":
<mask> return None <mask> <mask> return int(value.total_seconds()) <mask> <mask> def send_static_file(self, filename): <mask> """The view function used to serve files from <mask> :attr:`static_folder`. A route is automatically registered for <mask> this view at ...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/77237093da25438c88b0a74c374a397d4bf823eb
src/flask/scaffold.py
return send_from_directory( t.cast(str, self.static_folder), filename, max_age=max_age )
<mask> <mask> # send_file only knows to call get_send_file_max_age on the app, <mask> # call it here so it works for blueprints too. <mask> max_age = self.get_send_file_max_age(filename) <mask> return send_from_directory(self.static_folder, filename, max_age=max_age) <mask> <mas...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/77237093da25438c88b0a74c374a397d4bf823eb
src/flask/scaffold.py
def jinja_loader(self) -> t.Optional[FileSystemLoader]:
<mask> max_age = self.get_send_file_max_age(filename) <mask> return send_from_directory(self.static_folder, filename, max_age=max_age) <mask> <mask> @locked_cached_property <mask> def jinja_loader(self): <mask> """The Jinja loader for this object's templates. By default this <mas...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/77237093da25438c88b0a74c374a397d4bf823eb
src/flask/scaffold.py
else: return None
<mask> """ <mask> if self.template_folder is not None: <mask> return FileSystemLoader(os.path.join(self.root_path, self.template_folder)) <mask> <mask> def open_resource(self, resource: str, mode: str = "rb") -> t.IO[t.AnyStr]: <mask> """Open a resource file relative to :a...
[ "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/77237093da25438c88b0a74c374a397d4bf823eb
src/flask/scaffold.py
def open_resource(self, resource: str, mode: str = "rb") -> t.IO[t.AnyStr]:
<mask> """ <mask> if self.template_folder is not None: <mask> return FileSystemLoader(os.path.join(self.root_path, self.template_folder)) <mask> <mask> def open_resource(self, resource, mode="rb"): <mask> """Open a resource file relative to :attr:`root_path` for <mask> ...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/77237093da25438c88b0a74c374a397d4bf823eb
src/flask/scaffold.py
def _method_route(self, method: str, rule: str, options: dict) -> t.Callable:
<mask> raise ValueError("Resources can only be opened for reading.") <mask> <mask> return open(os.path.join(self.root_path, resource), mode) <mask> <mask> def _method_route(self, method, rule, options): <mask> if "methods" in options: <mask> raise TypeError("Use the ...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/77237093da25438c88b0a74c374a397d4bf823eb
src/flask/scaffold.py
def get(self, rule: str, **options: t.Any) -> t.Callable:
<mask> raise TypeError("Use the 'route' decorator to use the 'methods' argument.") <mask> <mask> return self.route(rule, methods=[method], **options) <mask> <mask> def get(self, rule, **options): <mask> """Shortcut for :meth:`route` with ``methods=["GET"]``. <mask> <mask> ...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/77237093da25438c88b0a74c374a397d4bf823eb
src/flask/scaffold.py
def post(self, rule: str, **options: t.Any) -> t.Callable:
<mask> .. versionadded:: 2.0 <mask> """ <mask> return self._method_route("GET", rule, options) <mask> <mask> def post(self, rule, **options): <mask> """Shortcut for :meth:`route` with ``methods=["POST"]``. <mask> <mask> .. versionadded:: 2.0 <mask> """ <ma...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/77237093da25438c88b0a74c374a397d4bf823eb
src/flask/scaffold.py
def put(self, rule: str, **options: t.Any) -> t.Callable:
<mask> .. versionadded:: 2.0 <mask> """ <mask> return self._method_route("POST", rule, options) <mask> <mask> def put(self, rule, **options): <mask> """Shortcut for :meth:`route` with ``methods=["PUT"]``. <mask> <mask> .. versionadded:: 2.0 <mask> """ <mas...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/77237093da25438c88b0a74c374a397d4bf823eb
src/flask/scaffold.py
def delete(self, rule: str, **options: t.Any) -> t.Callable:
<mask> .. versionadded:: 2.0 <mask> """ <mask> return self._method_route("PUT", rule, options) <mask> <mask> def delete(self, rule, **options): <mask> """Shortcut for :meth:`route` with ``methods=["DELETE"]``. <mask> <mask> .. versionadded:: 2.0 <mask> """ ...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/77237093da25438c88b0a74c374a397d4bf823eb
src/flask/scaffold.py
def patch(self, rule: str, **options: t.Any) -> t.Callable:
<mask> .. versionadded:: 2.0 <mask> """ <mask> return self._method_route("DELETE", rule, options) <mask> <mask> def patch(self, rule, **options): <mask> """Shortcut for :meth:`route` with ``methods=["PATCH"]``. <mask> <mask> .. versionadded:: 2.0 <mask> """...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/77237093da25438c88b0a74c374a397d4bf823eb
src/flask/scaffold.py
def route(self, rule: str, **options: t.Any) -> t.Callable:
<mask> .. versionadded:: 2.0 <mask> """ <mask> return self._method_route("PATCH", rule, options) <mask> <mask> def route(self, rule, **options): <mask> """Decorate a view function to register it with the given URL <mask> rule and options. Calls :meth:`add_url_rule`, w...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/77237093da25438c88b0a74c374a397d4bf823eb
src/flask/scaffold.py
def decorator(f: t.Callable) -> t.Callable:
<mask> :param options: Extra options passed to the <mask> :class:`~werkzeug.routing.Rule` object. <mask> """ <mask> <mask> def decorator(f): <mask> endpoint = options.pop("endpoint", None) <mask> self.add_url_rule(rule, endpoint, f, **options) <mask> ...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/77237093da25438c88b0a74c374a397d4bf823eb
src/flask/scaffold.py
rule: str, endpoint: t.Optional[str] = None, view_func: t.Optional[t.Callable] = None, provide_automatic_options: t.Optional[bool] = None, **options: t.Any, ) -> t.Callable:
<mask> <mask> @setupmethod <mask> def add_url_rule( <mask> self, <mask> rule, <mask> endpoint=None, <mask> view_func=None, <mask> provide_automatic_options=None, <mask> **options, <mask> ): <mask> """Register a rule for routing incoming req...
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/77237093da25438c88b0a74c374a397d4bf823eb
src/flask/scaffold.py
def endpoint(self, endpoint: str) -> t.Callable:
<mask> :class:`~werkzeug.routing.Rule` object. <mask> """ <mask> raise NotImplementedError <mask> <mask> def endpoint(self, endpoint): <mask> """Decorate a view function to register it for the given <mask> endpoint. Used if a rule is added without a ``view_func`` ...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/77237093da25438c88b0a74c374a397d4bf823eb
src/flask/scaffold.py
def before_request(self, f: BeforeRequestCallable) -> BeforeRequestCallable:
<mask> <mask> return decorator <mask> <mask> @setupmethod <mask> def before_request(self, f): <mask> """Register a function to run before each request. <mask> <mask> For example, this can be used to open a database connection, or <mask> to load the logged in user from...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/77237093da25438c88b0a74c374a397d4bf823eb
src/flask/scaffold.py
def after_request(self, f: AfterRequestCallable) -> AfterRequestCallable:
<mask> self.before_request_funcs.setdefault(None, []).append(self.ensure_sync(f)) <mask> return f <mask> <mask> @setupmethod <mask> def after_request(self, f): <mask> """Register a function to run after each request to this object. <mask> <mask> The function is called w...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/77237093da25438c88b0a74c374a397d4bf823eb
src/flask/scaffold.py
def teardown_request(self, f: TeardownCallable) -> TeardownCallable:
<mask> self.after_request_funcs.setdefault(None, []).append(self.ensure_sync(f)) <mask> return f <mask> <mask> @setupmethod <mask> def teardown_request(self, f): <mask> """Register a function to be run at the end of each request, <mask> regardless of whether there was an ...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/77237093da25438c88b0a74c374a397d4bf823eb
src/flask/scaffold.py
def context_processor( self, f: TemplateContextProcessorCallable ) -> TemplateContextProcessorCallable:
<mask> self.teardown_request_funcs.setdefault(None, []).append(self.ensure_sync(f)) <mask> return f <mask> <mask> @setupmethod <mask> def context_processor(self, f): <mask> """Registers a template context processor function.""" <mask> self.template_context_processors[None...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/77237093da25438c88b0a74c374a397d4bf823eb
src/flask/scaffold.py
def url_value_preprocessor( self, f: URLValuePreprocessorCallable ) -> URLValuePreprocessorCallable:
<mask> self.template_context_processors[None].append(f) <mask> return f <mask> <mask> @setupmethod <mask> def url_value_preprocessor(self, f): <mask> """Register a URL value preprocessor function for all view <mask> functions in the application. These functions will be ca...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/77237093da25438c88b0a74c374a397d4bf823eb
src/flask/scaffold.py
def url_defaults(self, f: URLDefaultCallable) -> URLDefaultCallable:
<mask> self.url_value_preprocessors[None].append(f) <mask> return f <mask> <mask> @setupmethod <mask> def url_defaults(self, f): <mask> """Callback function for URL defaults for all view functions of the <mask> application. It's called with the endpoint and values and sh...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/77237093da25438c88b0a74c374a397d4bf823eb
src/flask/scaffold.py
def errorhandler( self, code_or_exception: t.Union[t.Type[Exception], int] ) -> t.Callable:
<mask> self.url_default_functions[None].append(f) <mask> return f <mask> <mask> @setupmethod <mask> def errorhandler(self, code_or_exception): <mask> """Register a function to handle errors by code or exception class. <mask> <mask> A decorator that is used to register a...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/77237093da25438c88b0a74c374a397d4bf823eb
src/flask/scaffold.py
def decorator(f: ErrorHandlerCallable) -> ErrorHandlerCallable:
<mask> :param code_or_exception: the code as integer for the handler, or <mask> an arbitrary exception <mask> """ <mask> <mask> def decorator(f): <mask> self.register_error_handler(code_or_exception, f) <mask> return f <mask> <...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/77237093da25438c88b0a74c374a397d4bf823eb
src/flask/scaffold.py
def register_error_handler( self, code_or_exception: t.Union[t.Type[Exception], int], f: ErrorHandlerCallable, ) -> None:
<mask> <mask> return decorator <mask> <mask> @setupmethod <mask> def register_error_handler(self, code_or_exception, f): <mask> """Alternative error attach function to the :meth:`errorhandler` <mask> decorator that is more straightforward to use for non decorator <mask> ...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/77237093da25438c88b0a74c374a397d4bf823eb
src/flask/scaffold.py
def _get_exc_class_and_code( exc_class_or_code: t.Union[t.Type[Exception], int] ) -> t.Tuple[t.Type[Exception], t.Optional[int]]:
<mask> <mask> self.error_handler_spec[None][code][exc_class] = self.ensure_sync(f) <mask> <mask> @staticmethod <mask> def _get_exc_class_and_code(exc_class_or_code): <mask> """Get the exception class being handled. For HTTP status codes <mask> or ``HTTPException`` subclasses, re...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/77237093da25438c88b0a74c374a397d4bf823eb
src/flask/scaffold.py
exc_class: t.Type[Exception]
<mask> <mask> :param exc_class_or_code: Any exception class, or an HTTP status <mask> code as an integer. <mask> """ <mask> if isinstance(exc_class_or_code, int): <mask> exc_class = default_exceptions[exc_class_or_code] <mask> else: <mask> exc...
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/77237093da25438c88b0a74c374a397d4bf823eb
src/flask/scaffold.py
def ensure_sync(self, func: t.Callable) -> t.Callable:
<mask> return exc_class, exc_class.code <mask> else: <mask> return exc_class, None <mask> <mask> def ensure_sync(self, func): <mask> raise NotImplementedError() <mask> <mask> <mask> def _endpoint_from_view_func(view_func): <mask> """Internal helper that retur...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/77237093da25438c88b0a74c374a397d4bf823eb
src/flask/scaffold.py
def _endpoint_from_view_func(view_func: t.Callable) -> str:
<mask> def ensure_sync(self, func): <mask> raise NotImplementedError() <mask> <mask> <mask> def _endpoint_from_view_func(view_func): <mask> """Internal helper that returns the default endpoint for a given <mask> function. This always is the function name. <mask> """ <mask> assert...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/77237093da25438c88b0a74c374a397d4bf823eb
src/flask/scaffold.py
def get_root_path(import_name: str) -> str:
<mask> assert view_func is not None, "expected view func if endpoint is not provided." <mask> return view_func.__name__ <mask> <mask> <mask> def get_root_path(import_name): <mask> """Find the root path of a package, or the path that contains a <mask> module. If it cannot be found, returns the c...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/pallets/flask/commit/77237093da25438c88b0a74c374a397d4bf823eb
src/flask/scaffold.py