repo
stringlengths
7
55
path
stringlengths
4
223
func_name
stringlengths
1
134
original_string
stringlengths
75
104k
language
stringclasses
1 value
code
stringlengths
75
104k
code_tokens
listlengths
19
28.4k
docstring
stringlengths
1
46.9k
docstring_tokens
listlengths
1
1.97k
sha
stringlengths
40
40
url
stringlengths
87
315
partition
stringclasses
1 value
pallets/werkzeug
src/werkzeug/wrappers/base_request.py
BaseRequest._load_form_data
def _load_form_data(self): """Method used internally to retrieve submitted data. After calling this sets `form` and `files` on the request object to multi dicts filled with the incoming form data. As a matter of fact the input stream will be empty afterwards. You can also call this me...
python
def _load_form_data(self): """Method used internally to retrieve submitted data. After calling this sets `form` and `files` on the request object to multi dicts filled with the incoming form data. As a matter of fact the input stream will be empty afterwards. You can also call this me...
[ "def", "_load_form_data", "(", "self", ")", ":", "# abort early if we have already consumed the stream", "if", "\"form\"", "in", "self", ".", "__dict__", ":", "return", "_assert_not_shallow", "(", "self", ")", "if", "self", ".", "want_form_data_parsed", ":", "content_...
Method used internally to retrieve submitted data. After calling this sets `form` and `files` on the request object to multi dicts filled with the incoming form data. As a matter of fact the input stream will be empty afterwards. You can also call this method to force the parsing of t...
[ "Method", "used", "internally", "to", "retrieve", "submitted", "data", ".", "After", "calling", "this", "sets", "form", "and", "files", "on", "the", "request", "object", "to", "multi", "dicts", "filled", "with", "the", "incoming", "form", "data", ".", "As", ...
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/wrappers/base_request.py#L294-L327
train
pallets/werkzeug
src/werkzeug/wrappers/base_request.py
BaseRequest.close
def close(self): """Closes associated resources of this request object. This closes all file handles explicitly. You can also use the request object in a with statement which will automatically close it. .. versionadded:: 0.9 """ files = self.__dict__.get("files") ...
python
def close(self): """Closes associated resources of this request object. This closes all file handles explicitly. You can also use the request object in a with statement which will automatically close it. .. versionadded:: 0.9 """ files = self.__dict__.get("files") ...
[ "def", "close", "(", "self", ")", ":", "files", "=", "self", ".", "__dict__", ".", "get", "(", "\"files\"", ")", "for", "_key", ",", "value", "in", "iter_multi_items", "(", "files", "or", "(", ")", ")", ":", "value", ".", "close", "(", ")" ]
Closes associated resources of this request object. This closes all file handles explicitly. You can also use the request object in a with statement which will automatically close it. .. versionadded:: 0.9
[ "Closes", "associated", "resources", "of", "this", "request", "object", ".", "This", "closes", "all", "file", "handles", "explicitly", ".", "You", "can", "also", "use", "the", "request", "object", "in", "a", "with", "statement", "which", "will", "automatically...
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/wrappers/base_request.py#L341-L350
train
pallets/werkzeug
src/werkzeug/wrappers/base_request.py
BaseRequest.values
def values(self): """A :class:`werkzeug.datastructures.CombinedMultiDict` that combines :attr:`args` and :attr:`form`.""" args = [] for d in self.args, self.form: if not isinstance(d, MultiDict): d = MultiDict(d) args.append(d) return Combi...
python
def values(self): """A :class:`werkzeug.datastructures.CombinedMultiDict` that combines :attr:`args` and :attr:`form`.""" args = [] for d in self.args, self.form: if not isinstance(d, MultiDict): d = MultiDict(d) args.append(d) return Combi...
[ "def", "values", "(", "self", ")", ":", "args", "=", "[", "]", "for", "d", "in", "self", ".", "args", ",", "self", ".", "form", ":", "if", "not", "isinstance", "(", "d", ",", "MultiDict", ")", ":", "d", "=", "MultiDict", "(", "d", ")", "args", ...
A :class:`werkzeug.datastructures.CombinedMultiDict` that combines :attr:`args` and :attr:`form`.
[ "A", ":", "class", ":", "werkzeug", ".", "datastructures", ".", "CombinedMultiDict", "that", "combines", ":", "attr", ":", "args", "and", ":", "attr", ":", "form", "." ]
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/wrappers/base_request.py#L480-L488
train
pallets/werkzeug
src/werkzeug/wrappers/base_request.py
BaseRequest.cookies
def cookies(self): """A :class:`dict` with the contents of all cookies transmitted with the request.""" return parse_cookie( self.environ, self.charset, self.encoding_errors, cls=self.dict_storage_class, )
python
def cookies(self): """A :class:`dict` with the contents of all cookies transmitted with the request.""" return parse_cookie( self.environ, self.charset, self.encoding_errors, cls=self.dict_storage_class, )
[ "def", "cookies", "(", "self", ")", ":", "return", "parse_cookie", "(", "self", ".", "environ", ",", "self", ".", "charset", ",", "self", ".", "encoding_errors", ",", "cls", "=", "self", ".", "dict_storage_class", ",", ")" ]
A :class:`dict` with the contents of all cookies transmitted with the request.
[ "A", ":", "class", ":", "dict", "with", "the", "contents", "of", "all", "cookies", "transmitted", "with", "the", "request", "." ]
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/wrappers/base_request.py#L514-L522
train
pallets/werkzeug
src/werkzeug/wrappers/base_request.py
BaseRequest.path
def path(self): """Requested path as unicode. This works a bit like the regular path info in the WSGI environment but will always include a leading slash, even if the URL root is accessed. """ raw_path = wsgi_decoding_dance( self.environ.get("PATH_INFO") or "", self....
python
def path(self): """Requested path as unicode. This works a bit like the regular path info in the WSGI environment but will always include a leading slash, even if the URL root is accessed. """ raw_path = wsgi_decoding_dance( self.environ.get("PATH_INFO") or "", self....
[ "def", "path", "(", "self", ")", ":", "raw_path", "=", "wsgi_decoding_dance", "(", "self", ".", "environ", ".", "get", "(", "\"PATH_INFO\"", ")", "or", "\"\"", ",", "self", ".", "charset", ",", "self", ".", "encoding_errors", ")", "return", "\"/\"", "+",...
Requested path as unicode. This works a bit like the regular path info in the WSGI environment but will always include a leading slash, even if the URL root is accessed.
[ "Requested", "path", "as", "unicode", ".", "This", "works", "a", "bit", "like", "the", "regular", "path", "info", "in", "the", "WSGI", "environment", "but", "will", "always", "include", "a", "leading", "slash", "even", "if", "the", "URL", "root", "is", "...
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/wrappers/base_request.py#L532-L540
train
pallets/werkzeug
src/werkzeug/wrappers/base_request.py
BaseRequest.full_path
def full_path(self): """Requested path as unicode, including the query string.""" return self.path + u"?" + to_unicode(self.query_string, self.url_charset)
python
def full_path(self): """Requested path as unicode, including the query string.""" return self.path + u"?" + to_unicode(self.query_string, self.url_charset)
[ "def", "full_path", "(", "self", ")", ":", "return", "self", ".", "path", "+", "u\"?\"", "+", "to_unicode", "(", "self", ".", "query_string", ",", "self", ".", "url_charset", ")" ]
Requested path as unicode, including the query string.
[ "Requested", "path", "as", "unicode", "including", "the", "query", "string", "." ]
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/wrappers/base_request.py#L543-L545
train
pallets/werkzeug
src/werkzeug/wrappers/base_request.py
BaseRequest.script_root
def script_root(self): """The root path of the script without the trailing slash.""" raw_path = wsgi_decoding_dance( self.environ.get("SCRIPT_NAME") or "", self.charset, self.encoding_errors ) return raw_path.rstrip("/")
python
def script_root(self): """The root path of the script without the trailing slash.""" raw_path = wsgi_decoding_dance( self.environ.get("SCRIPT_NAME") or "", self.charset, self.encoding_errors ) return raw_path.rstrip("/")
[ "def", "script_root", "(", "self", ")", ":", "raw_path", "=", "wsgi_decoding_dance", "(", "self", ".", "environ", ".", "get", "(", "\"SCRIPT_NAME\"", ")", "or", "\"\"", ",", "self", ".", "charset", ",", "self", ".", "encoding_errors", ")", "return", "raw_p...
The root path of the script without the trailing slash.
[ "The", "root", "path", "of", "the", "script", "without", "the", "trailing", "slash", "." ]
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/wrappers/base_request.py#L548-L553
train
pallets/werkzeug
src/werkzeug/wrappers/base_request.py
BaseRequest.base_url
def base_url(self): """Like :attr:`url` but without the querystring See also: :attr:`trusted_hosts`. """ return get_current_url( self.environ, strip_querystring=True, trusted_hosts=self.trusted_hosts )
python
def base_url(self): """Like :attr:`url` but without the querystring See also: :attr:`trusted_hosts`. """ return get_current_url( self.environ, strip_querystring=True, trusted_hosts=self.trusted_hosts )
[ "def", "base_url", "(", "self", ")", ":", "return", "get_current_url", "(", "self", ".", "environ", ",", "strip_querystring", "=", "True", ",", "trusted_hosts", "=", "self", ".", "trusted_hosts", ")" ]
Like :attr:`url` but without the querystring See also: :attr:`trusted_hosts`.
[ "Like", ":", "attr", ":", "url", "but", "without", "the", "querystring", "See", "also", ":", ":", "attr", ":", "trusted_hosts", "." ]
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/wrappers/base_request.py#L563-L569
train
pallets/werkzeug
src/werkzeug/wrappers/base_request.py
BaseRequest.host_url
def host_url(self): """Just the host with scheme as IRI. See also: :attr:`trusted_hosts`. """ return get_current_url( self.environ, host_only=True, trusted_hosts=self.trusted_hosts )
python
def host_url(self): """Just the host with scheme as IRI. See also: :attr:`trusted_hosts`. """ return get_current_url( self.environ, host_only=True, trusted_hosts=self.trusted_hosts )
[ "def", "host_url", "(", "self", ")", ":", "return", "get_current_url", "(", "self", ".", "environ", ",", "host_only", "=", "True", ",", "trusted_hosts", "=", "self", ".", "trusted_hosts", ")" ]
Just the host with scheme as IRI. See also: :attr:`trusted_hosts`.
[ "Just", "the", "host", "with", "scheme", "as", "IRI", ".", "See", "also", ":", ":", "attr", ":", "trusted_hosts", "." ]
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/wrappers/base_request.py#L580-L586
train
pallets/werkzeug
src/werkzeug/wrappers/base_request.py
BaseRequest.access_route
def access_route(self): """If a forwarded header exists this is a list of all ip addresses from the client ip to the last proxy server. """ if "HTTP_X_FORWARDED_FOR" in self.environ: addr = self.environ["HTTP_X_FORWARDED_FOR"].split(",") return self.list_storage_c...
python
def access_route(self): """If a forwarded header exists this is a list of all ip addresses from the client ip to the last proxy server. """ if "HTTP_X_FORWARDED_FOR" in self.environ: addr = self.environ["HTTP_X_FORWARDED_FOR"].split(",") return self.list_storage_c...
[ "def", "access_route", "(", "self", ")", ":", "if", "\"HTTP_X_FORWARDED_FOR\"", "in", "self", ".", "environ", ":", "addr", "=", "self", ".", "environ", "[", "\"HTTP_X_FORWARDED_FOR\"", "]", ".", "split", "(", "\",\"", ")", "return", "self", ".", "list_storag...
If a forwarded header exists this is a list of all ip addresses from the client ip to the last proxy server.
[ "If", "a", "forwarded", "header", "exists", "this", "is", "a", "list", "of", "all", "ip", "addresses", "from", "the", "client", "ip", "to", "the", "last", "proxy", "server", "." ]
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/src/werkzeug/wrappers/base_request.py#L611-L620
train
pallets/werkzeug
examples/simplewiki/actions.py
on_show
def on_show(request, page_name): """Displays the page the user requests.""" revision_id = request.args.get("rev", type=int) query = RevisionedPage.query.filter_by(name=page_name) if revision_id: query = query.filter_by(revision_id=revision_id) revision_requested = True else: ...
python
def on_show(request, page_name): """Displays the page the user requests.""" revision_id = request.args.get("rev", type=int) query = RevisionedPage.query.filter_by(name=page_name) if revision_id: query = query.filter_by(revision_id=revision_id) revision_requested = True else: ...
[ "def", "on_show", "(", "request", ",", "page_name", ")", ":", "revision_id", "=", "request", ".", "args", ".", "get", "(", "\"rev\"", ",", "type", "=", "int", ")", "query", "=", "RevisionedPage", ".", "query", ".", "filter_by", "(", "name", "=", "page_...
Displays the page the user requests.
[ "Displays", "the", "page", "the", "user", "requests", "." ]
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/examples/simplewiki/actions.py#L29-L42
train
pallets/werkzeug
examples/simplewiki/actions.py
on_edit
def on_edit(request, page_name): """Edit the current revision of a page.""" change_note = error = "" revision = ( Revision.query.filter( (Page.name == page_name) & (Page.page_id == Revision.page_id) ) .order_by(Revision.revision_id.desc()) .first() ) if re...
python
def on_edit(request, page_name): """Edit the current revision of a page.""" change_note = error = "" revision = ( Revision.query.filter( (Page.name == page_name) & (Page.page_id == Revision.page_id) ) .order_by(Revision.revision_id.desc()) .first() ) if re...
[ "def", "on_edit", "(", "request", ",", "page_name", ")", ":", "change_note", "=", "error", "=", "\"\"", "revision", "=", "(", "Revision", ".", "query", ".", "filter", "(", "(", "Page", ".", "name", "==", "page_name", ")", "&", "(", "Page", ".", "page...
Edit the current revision of a page.
[ "Edit", "the", "current", "revision", "of", "a", "page", "." ]
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/examples/simplewiki/actions.py#L45-L85
train
pallets/werkzeug
examples/simplewiki/actions.py
on_log
def on_log(request, page_name): """Show the list of recent changes.""" page = Page.query.filter_by(name=page_name).first() if page is None: return page_missing(request, page_name, False) return Response(generate_template("action_log.html", page=page))
python
def on_log(request, page_name): """Show the list of recent changes.""" page = Page.query.filter_by(name=page_name).first() if page is None: return page_missing(request, page_name, False) return Response(generate_template("action_log.html", page=page))
[ "def", "on_log", "(", "request", ",", "page_name", ")", ":", "page", "=", "Page", ".", "query", ".", "filter_by", "(", "name", "=", "page_name", ")", ".", "first", "(", ")", "if", "page", "is", "None", ":", "return", "page_missing", "(", "request", "...
Show the list of recent changes.
[ "Show", "the", "list", "of", "recent", "changes", "." ]
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/examples/simplewiki/actions.py#L88-L93
train
pallets/werkzeug
examples/simplewiki/actions.py
on_diff
def on_diff(request, page_name): """Show the diff between two revisions.""" old = request.args.get("old", type=int) new = request.args.get("new", type=int) error = "" diff = page = old_rev = new_rev = None if not (old and new): error = "No revisions specified." else: revisio...
python
def on_diff(request, page_name): """Show the diff between two revisions.""" old = request.args.get("old", type=int) new = request.args.get("new", type=int) error = "" diff = page = old_rev = new_rev = None if not (old and new): error = "No revisions specified." else: revisio...
[ "def", "on_diff", "(", "request", ",", "page_name", ")", ":", "old", "=", "request", ".", "args", ".", "get", "(", "\"old\"", ",", "type", "=", "int", ")", "new", "=", "request", ".", "args", ".", "get", "(", "\"new\"", ",", "type", "=", "int", "...
Show the diff between two revisions.
[ "Show", "the", "diff", "between", "two", "revisions", "." ]
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/examples/simplewiki/actions.py#L96-L139
train
pallets/werkzeug
examples/simplewiki/actions.py
on_revert
def on_revert(request, page_name): """Revert an old revision.""" rev_id = request.args.get("rev", type=int) old_revision = page = None error = "No such revision" if request.method == "POST" and request.form.get("cancel"): return redirect(href(page_name)) if rev_id: old_revisio...
python
def on_revert(request, page_name): """Revert an old revision.""" rev_id = request.args.get("rev", type=int) old_revision = page = None error = "No such revision" if request.method == "POST" and request.form.get("cancel"): return redirect(href(page_name)) if rev_id: old_revisio...
[ "def", "on_revert", "(", "request", ",", "page_name", ")", ":", "rev_id", "=", "request", ".", "args", ".", "get", "(", "\"rev\"", ",", "type", "=", "int", ")", "old_revision", "=", "page", "=", "None", "error", "=", "\"No such revision\"", "if", "reques...
Revert an old revision.
[ "Revert", "an", "old", "revision", "." ]
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/examples/simplewiki/actions.py#L142-L188
train
pallets/werkzeug
examples/simplewiki/actions.py
page_missing
def page_missing(request, page_name, revision_requested, protected=False): """Displayed if page or revision does not exist.""" return Response( generate_template( "page_missing.html", page_name=page_name, revision_requested=revision_requested, protected=pr...
python
def page_missing(request, page_name, revision_requested, protected=False): """Displayed if page or revision does not exist.""" return Response( generate_template( "page_missing.html", page_name=page_name, revision_requested=revision_requested, protected=pr...
[ "def", "page_missing", "(", "request", ",", "page_name", ",", "revision_requested", ",", "protected", "=", "False", ")", ":", "return", "Response", "(", "generate_template", "(", "\"page_missing.html\"", ",", "page_name", "=", "page_name", ",", "revision_requested",...
Displayed if page or revision does not exist.
[ "Displayed", "if", "page", "or", "revision", "does", "not", "exist", "." ]
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/examples/simplewiki/actions.py#L191-L201
train
pallets/werkzeug
examples/manage-shorty.py
shell
def shell(no_ipython): """Start a new interactive python session.""" banner = "Interactive Werkzeug Shell" namespace = make_shell() if not no_ipython: try: try: from IPython.frontend.terminal.embed import InteractiveShellEmbed sh = InteractiveShellEmb...
python
def shell(no_ipython): """Start a new interactive python session.""" banner = "Interactive Werkzeug Shell" namespace = make_shell() if not no_ipython: try: try: from IPython.frontend.terminal.embed import InteractiveShellEmbed sh = InteractiveShellEmb...
[ "def", "shell", "(", "no_ipython", ")", ":", "banner", "=", "\"Interactive Werkzeug Shell\"", "namespace", "=", "make_shell", "(", ")", "if", "not", "no_ipython", ":", "try", ":", "try", ":", "from", "IPython", ".", "frontend", ".", "terminal", ".", "embed",...
Start a new interactive python session.
[ "Start", "a", "new", "interactive", "python", "session", "." ]
a220671d66755a94630a212378754bb432811158
https://github.com/pallets/werkzeug/blob/a220671d66755a94630a212378754bb432811158/examples/manage-shorty.py#L60-L81
train
marshmallow-code/marshmallow
src/marshmallow/schema.py
_get_fields
def _get_fields(attrs, field_class, pop=False, ordered=False): """Get fields from a class. If ordered=True, fields will sorted by creation index. :param attrs: Mapping of class attributes :param type field_class: Base field class :param bool pop: Remove matching fields """ fields = [ (f...
python
def _get_fields(attrs, field_class, pop=False, ordered=False): """Get fields from a class. If ordered=True, fields will sorted by creation index. :param attrs: Mapping of class attributes :param type field_class: Base field class :param bool pop: Remove matching fields """ fields = [ (f...
[ "def", "_get_fields", "(", "attrs", ",", "field_class", ",", "pop", "=", "False", ",", "ordered", "=", "False", ")", ":", "fields", "=", "[", "(", "field_name", ",", "field_value", ")", "for", "field_name", ",", "field_value", "in", "iteritems", "(", "at...
Get fields from a class. If ordered=True, fields will sorted by creation index. :param attrs: Mapping of class attributes :param type field_class: Base field class :param bool pop: Remove matching fields
[ "Get", "fields", "from", "a", "class", ".", "If", "ordered", "=", "True", "fields", "will", "sorted", "by", "creation", "index", "." ]
a6b6c4151f1fbf16f3774d4052ca2bddf6903750
https://github.com/marshmallow-code/marshmallow/blob/a6b6c4151f1fbf16f3774d4052ca2bddf6903750/src/marshmallow/schema.py#L35-L52
train
marshmallow-code/marshmallow
src/marshmallow/schema.py
_get_fields_by_mro
def _get_fields_by_mro(klass, field_class, ordered=False): """Collect fields from a class, following its method resolution order. The class itself is excluded from the search; only its parents are checked. Get fields from ``_declared_fields`` if available, else use ``__dict__``. :param type klass: Clas...
python
def _get_fields_by_mro(klass, field_class, ordered=False): """Collect fields from a class, following its method resolution order. The class itself is excluded from the search; only its parents are checked. Get fields from ``_declared_fields`` if available, else use ``__dict__``. :param type klass: Clas...
[ "def", "_get_fields_by_mro", "(", "klass", ",", "field_class", ",", "ordered", "=", "False", ")", ":", "mro", "=", "inspect", ".", "getmro", "(", "klass", ")", "# Loop over mro in reverse to maintain correct order of fields", "return", "sum", "(", "(", "_get_fields"...
Collect fields from a class, following its method resolution order. The class itself is excluded from the search; only its parents are checked. Get fields from ``_declared_fields`` if available, else use ``__dict__``. :param type klass: Class whose fields to retrieve :param type field_class: Base field...
[ "Collect", "fields", "from", "a", "class", "following", "its", "method", "resolution", "order", ".", "The", "class", "itself", "is", "excluded", "from", "the", "search", ";", "only", "its", "parents", "are", "checked", ".", "Get", "fields", "from", "_declare...
a6b6c4151f1fbf16f3774d4052ca2bddf6903750
https://github.com/marshmallow-code/marshmallow/blob/a6b6c4151f1fbf16f3774d4052ca2bddf6903750/src/marshmallow/schema.py#L56-L76
train
marshmallow-code/marshmallow
src/marshmallow/schema.py
SchemaMeta.resolve_hooks
def resolve_hooks(self): """Add in the decorated processors By doing this after constructing the class, we let standard inheritance do all the hard work. """ mro = inspect.getmro(self) hooks = defaultdict(list) for attr_name in dir(self): # Need to ...
python
def resolve_hooks(self): """Add in the decorated processors By doing this after constructing the class, we let standard inheritance do all the hard work. """ mro = inspect.getmro(self) hooks = defaultdict(list) for attr_name in dir(self): # Need to ...
[ "def", "resolve_hooks", "(", "self", ")", ":", "mro", "=", "inspect", ".", "getmro", "(", "self", ")", "hooks", "=", "defaultdict", "(", "list", ")", "for", "attr_name", "in", "dir", "(", "self", ")", ":", "# Need to look up the actual descriptor, not whatever...
Add in the decorated processors By doing this after constructing the class, we let standard inheritance do all the hard work.
[ "Add", "in", "the", "decorated", "processors" ]
a6b6c4151f1fbf16f3774d4052ca2bddf6903750
https://github.com/marshmallow-code/marshmallow/blob/a6b6c4151f1fbf16f3774d4052ca2bddf6903750/src/marshmallow/schema.py#L144-L181
train
marshmallow-code/marshmallow
src/marshmallow/schema.py
BaseSchema._call_and_store
def _call_and_store(getter_func, data, field_name, error_store, index=None): """Call ``getter_func`` with ``data`` as its argument, and store any `ValidationErrors`. :param callable getter_func: Function for getting the serialized/deserialized value from ``data``. :param data: The d...
python
def _call_and_store(getter_func, data, field_name, error_store, index=None): """Call ``getter_func`` with ``data`` as its argument, and store any `ValidationErrors`. :param callable getter_func: Function for getting the serialized/deserialized value from ``data``. :param data: The d...
[ "def", "_call_and_store", "(", "getter_func", ",", "data", ",", "field_name", ",", "error_store", ",", "index", "=", "None", ")", ":", "try", ":", "value", "=", "getter_func", "(", "data", ")", "except", "ValidationError", "as", "err", ":", "error_store", ...
Call ``getter_func`` with ``data`` as its argument, and store any `ValidationErrors`. :param callable getter_func: Function for getting the serialized/deserialized value from ``data``. :param data: The data passed to ``getter_func``. :param str field_name: Field name. :param...
[ "Call", "getter_func", "with", "data", "as", "its", "argument", "and", "store", "any", "ValidationErrors", "." ]
a6b6c4151f1fbf16f3774d4052ca2bddf6903750
https://github.com/marshmallow-code/marshmallow/blob/a6b6c4151f1fbf16f3774d4052ca2bddf6903750/src/marshmallow/schema.py#L416-L433
train
marshmallow-code/marshmallow
src/marshmallow/schema.py
BaseSchema._serialize
def _serialize( self, obj, fields_dict, error_store, many=False, accessor=None, dict_class=dict, index_errors=True, index=None, ): """Takes raw data (a dict, list, or other object) and a dict of fields to output and serializes the data based on those fields. :param o...
python
def _serialize( self, obj, fields_dict, error_store, many=False, accessor=None, dict_class=dict, index_errors=True, index=None, ): """Takes raw data (a dict, list, or other object) and a dict of fields to output and serializes the data based on those fields. :param o...
[ "def", "_serialize", "(", "self", ",", "obj", ",", "fields_dict", ",", "error_store", ",", "many", "=", "False", ",", "accessor", "=", "None", ",", "dict_class", "=", "dict", ",", "index_errors", "=", "True", ",", "index", "=", "None", ",", ")", ":", ...
Takes raw data (a dict, list, or other object) and a dict of fields to output and serializes the data based on those fields. :param obj: The actual object(s) from which the fields are taken from :param dict fields_dict: Mapping of field names to :class:`Field` objects. :param ErrorStore...
[ "Takes", "raw", "data", "(", "a", "dict", "list", "or", "other", "object", ")", "and", "a", "dict", "of", "fields", "to", "output", "and", "serializes", "the", "data", "based", "on", "those", "fields", "." ]
a6b6c4151f1fbf16f3774d4052ca2bddf6903750
https://github.com/marshmallow-code/marshmallow/blob/a6b6c4151f1fbf16f3774d4052ca2bddf6903750/src/marshmallow/schema.py#L435-L489
train
marshmallow-code/marshmallow
src/marshmallow/schema.py
BaseSchema.dump
def dump(self, obj, many=None): """Serialize an object to native Python data types according to this Schema's fields. :param obj: The object to serialize. :param bool many: Whether to serialize `obj` as a collection. If `None`, the value for `self.many` is used. :ret...
python
def dump(self, obj, many=None): """Serialize an object to native Python data types according to this Schema's fields. :param obj: The object to serialize. :param bool many: Whether to serialize `obj` as a collection. If `None`, the value for `self.many` is used. :ret...
[ "def", "dump", "(", "self", ",", "obj", ",", "many", "=", "None", ")", ":", "error_store", "=", "ErrorStore", "(", ")", "errors", "=", "{", "}", "many", "=", "self", ".", "many", "if", "many", "is", "None", "else", "bool", "(", "many", ")", "if",...
Serialize an object to native Python data types according to this Schema's fields. :param obj: The object to serialize. :param bool many: Whether to serialize `obj` as a collection. If `None`, the value for `self.many` is used. :return: A dict of serialized data :rty...
[ "Serialize", "an", "object", "to", "native", "Python", "data", "types", "according", "to", "this", "Schema", "s", "fields", "." ]
a6b6c4151f1fbf16f3774d4052ca2bddf6903750
https://github.com/marshmallow-code/marshmallow/blob/a6b6c4151f1fbf16f3774d4052ca2bddf6903750/src/marshmallow/schema.py#L491-L559
train
marshmallow-code/marshmallow
src/marshmallow/schema.py
BaseSchema.dumps
def dumps(self, obj, many=None, *args, **kwargs): """Same as :meth:`dump`, except return a JSON-encoded string. :param obj: The object to serialize. :param bool many: Whether to serialize `obj` as a collection. If `None`, the value for `self.many` is used. :return: A ``json`...
python
def dumps(self, obj, many=None, *args, **kwargs): """Same as :meth:`dump`, except return a JSON-encoded string. :param obj: The object to serialize. :param bool many: Whether to serialize `obj` as a collection. If `None`, the value for `self.many` is used. :return: A ``json`...
[ "def", "dumps", "(", "self", ",", "obj", ",", "many", "=", "None", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "serialized", "=", "self", ".", "dump", "(", "obj", ",", "many", "=", "many", ")", "return", "self", ".", "opts", ".", "rend...
Same as :meth:`dump`, except return a JSON-encoded string. :param obj: The object to serialize. :param bool many: Whether to serialize `obj` as a collection. If `None`, the value for `self.many` is used. :return: A ``json`` string :rtype: str .. versionadded:: 1.0.0...
[ "Same", "as", ":", "meth", ":", "dump", "except", "return", "a", "JSON", "-", "encoded", "string", "." ]
a6b6c4151f1fbf16f3774d4052ca2bddf6903750
https://github.com/marshmallow-code/marshmallow/blob/a6b6c4151f1fbf16f3774d4052ca2bddf6903750/src/marshmallow/schema.py#L561-L577
train
marshmallow-code/marshmallow
src/marshmallow/schema.py
BaseSchema._deserialize
def _deserialize( self, data, fields_dict, error_store, many=False, partial=False, unknown=RAISE, dict_class=dict, index_errors=True, index=None, ): """Deserialize ``data`` based on the schema defined by ``fields_dict``. :param dict data: The data to deserialize. :param dict...
python
def _deserialize( self, data, fields_dict, error_store, many=False, partial=False, unknown=RAISE, dict_class=dict, index_errors=True, index=None, ): """Deserialize ``data`` based on the schema defined by ``fields_dict``. :param dict data: The data to deserialize. :param dict...
[ "def", "_deserialize", "(", "self", ",", "data", ",", "fields_dict", ",", "error_store", ",", "many", "=", "False", ",", "partial", "=", "False", ",", "unknown", "=", "RAISE", ",", "dict_class", "=", "dict", ",", "index_errors", "=", "True", ",", "index"...
Deserialize ``data`` based on the schema defined by ``fields_dict``. :param dict data: The data to deserialize. :param dict fields_dict: Mapping of field names to :class:`Field` objects. :param ErrorStore error_store: Structure to store errors. :param bool many: Set to `True` if ``data`...
[ "Deserialize", "data", "based", "on", "the", "schema", "defined", "by", "fields_dict", "." ]
a6b6c4151f1fbf16f3774d4052ca2bddf6903750
https://github.com/marshmallow-code/marshmallow/blob/a6b6c4151f1fbf16f3774d4052ca2bddf6903750/src/marshmallow/schema.py#L579-L682
train
marshmallow-code/marshmallow
src/marshmallow/schema.py
BaseSchema.load
def load(self, data, many=None, partial=None, unknown=None): """Deserialize a data structure to an object defined by this Schema's fields. :param dict data: The data to deserialize. :param bool many: Whether to deserialize `data` as a collection. If `None`, the value for `self.many`...
python
def load(self, data, many=None, partial=None, unknown=None): """Deserialize a data structure to an object defined by this Schema's fields. :param dict data: The data to deserialize. :param bool many: Whether to deserialize `data` as a collection. If `None`, the value for `self.many`...
[ "def", "load", "(", "self", ",", "data", ",", "many", "=", "None", ",", "partial", "=", "None", ",", "unknown", "=", "None", ")", ":", "return", "self", ".", "_do_load", "(", "data", ",", "many", ",", "partial", "=", "partial", ",", "unknown", "=",...
Deserialize a data structure to an object defined by this Schema's fields. :param dict data: The data to deserialize. :param bool many: Whether to deserialize `data` as a collection. If `None`, the value for `self.many` is used. :param bool|tuple partial: Whether to ignore missing f...
[ "Deserialize", "a", "data", "structure", "to", "an", "object", "defined", "by", "this", "Schema", "s", "fields", "." ]
a6b6c4151f1fbf16f3774d4052ca2bddf6903750
https://github.com/marshmallow-code/marshmallow/blob/a6b6c4151f1fbf16f3774d4052ca2bddf6903750/src/marshmallow/schema.py#L684-L709
train
marshmallow-code/marshmallow
src/marshmallow/schema.py
BaseSchema.loads
def loads( self, json_data, many=None, partial=None, unknown=None, **kwargs ): """Same as :meth:`load`, except it takes a JSON string as input. :param str json_data: A JSON string of the data to deserialize. :param bool many: Whether to deserialize `obj` as a collection. If ...
python
def loads( self, json_data, many=None, partial=None, unknown=None, **kwargs ): """Same as :meth:`load`, except it takes a JSON string as input. :param str json_data: A JSON string of the data to deserialize. :param bool many: Whether to deserialize `obj` as a collection. If ...
[ "def", "loads", "(", "self", ",", "json_data", ",", "many", "=", "None", ",", "partial", "=", "None", ",", "unknown", "=", "None", ",", "*", "*", "kwargs", ")", ":", "data", "=", "self", ".", "opts", ".", "render_module", ".", "loads", "(", "json_d...
Same as :meth:`load`, except it takes a JSON string as input. :param str json_data: A JSON string of the data to deserialize. :param bool many: Whether to deserialize `obj` as a collection. If `None`, the value for `self.many` is used. :param bool|tuple partial: Whether to ignore mi...
[ "Same", "as", ":", "meth", ":", "load", "except", "it", "takes", "a", "JSON", "string", "as", "input", "." ]
a6b6c4151f1fbf16f3774d4052ca2bddf6903750
https://github.com/marshmallow-code/marshmallow/blob/a6b6c4151f1fbf16f3774d4052ca2bddf6903750/src/marshmallow/schema.py#L711-L737
train
marshmallow-code/marshmallow
src/marshmallow/schema.py
BaseSchema.validate
def validate(self, data, many=None, partial=None): """Validate `data` against the schema, returning a dictionary of validation errors. :param dict data: The data to validate. :param bool many: Whether to validate `data` as a collection. If `None`, the value for `self.many` i...
python
def validate(self, data, many=None, partial=None): """Validate `data` against the schema, returning a dictionary of validation errors. :param dict data: The data to validate. :param bool many: Whether to validate `data` as a collection. If `None`, the value for `self.many` i...
[ "def", "validate", "(", "self", ",", "data", ",", "many", "=", "None", ",", "partial", "=", "None", ")", ":", "try", ":", "self", ".", "_do_load", "(", "data", ",", "many", ",", "partial", "=", "partial", ",", "postprocess", "=", "False", ")", "exc...
Validate `data` against the schema, returning a dictionary of validation errors. :param dict data: The data to validate. :param bool many: Whether to validate `data` as a collection. If `None`, the value for `self.many` is used. :param bool|tuple partial: Whether to ignore m...
[ "Validate", "data", "against", "the", "schema", "returning", "a", "dictionary", "of", "validation", "errors", "." ]
a6b6c4151f1fbf16f3774d4052ca2bddf6903750
https://github.com/marshmallow-code/marshmallow/blob/a6b6c4151f1fbf16f3774d4052ca2bddf6903750/src/marshmallow/schema.py#L752-L772
train
marshmallow-code/marshmallow
src/marshmallow/schema.py
BaseSchema._do_load
def _do_load( self, data, many=None, partial=None, unknown=None, postprocess=True, ): """Deserialize `data`, returning the deserialized result. :param data: The data to deserialize. :param bool many: Whether to deserialize `data` as a collection. If `None`, the v...
python
def _do_load( self, data, many=None, partial=None, unknown=None, postprocess=True, ): """Deserialize `data`, returning the deserialized result. :param data: The data to deserialize. :param bool many: Whether to deserialize `data` as a collection. If `None`, the v...
[ "def", "_do_load", "(", "self", ",", "data", ",", "many", "=", "None", ",", "partial", "=", "None", ",", "unknown", "=", "None", ",", "postprocess", "=", "True", ",", ")", ":", "error_store", "=", "ErrorStore", "(", ")", "errors", "=", "{", "}", "m...
Deserialize `data`, returning the deserialized result. :param data: The data to deserialize. :param bool many: Whether to deserialize `data` as a collection. If `None`, the value for `self.many` is used. :param bool|tuple partial: Whether to validate required fields. If its value is...
[ "Deserialize", "data", "returning", "the", "deserialized", "result", "." ]
a6b6c4151f1fbf16f3774d4052ca2bddf6903750
https://github.com/marshmallow-code/marshmallow/blob/a6b6c4151f1fbf16f3774d4052ca2bddf6903750/src/marshmallow/schema.py#L776-L870
train
marshmallow-code/marshmallow
src/marshmallow/schema.py
BaseSchema._normalize_nested_options
def _normalize_nested_options(self): """Apply then flatten nested schema options""" if self.only is not None: # Apply the only option to nested fields. self.__apply_nested_option('only', self.only, 'intersection') # Remove the child field names from the only option. ...
python
def _normalize_nested_options(self): """Apply then flatten nested schema options""" if self.only is not None: # Apply the only option to nested fields. self.__apply_nested_option('only', self.only, 'intersection') # Remove the child field names from the only option. ...
[ "def", "_normalize_nested_options", "(", "self", ")", ":", "if", "self", ".", "only", "is", "not", "None", ":", "# Apply the only option to nested fields.", "self", ".", "__apply_nested_option", "(", "'only'", ",", "self", ".", "only", ",", "'intersection'", ")", ...
Apply then flatten nested schema options
[ "Apply", "then", "flatten", "nested", "schema", "options" ]
a6b6c4151f1fbf16f3774d4052ca2bddf6903750
https://github.com/marshmallow-code/marshmallow/blob/a6b6c4151f1fbf16f3774d4052ca2bddf6903750/src/marshmallow/schema.py#L872-L894
train
marshmallow-code/marshmallow
src/marshmallow/schema.py
BaseSchema.__apply_nested_option
def __apply_nested_option(self, option_name, field_names, set_operation): """Apply nested options to nested fields""" # Split nested field names on the first dot. nested_fields = [name.split('.', 1) for name in field_names if '.' in name] # Partition the nested field names by parent fiel...
python
def __apply_nested_option(self, option_name, field_names, set_operation): """Apply nested options to nested fields""" # Split nested field names on the first dot. nested_fields = [name.split('.', 1) for name in field_names if '.' in name] # Partition the nested field names by parent fiel...
[ "def", "__apply_nested_option", "(", "self", ",", "option_name", ",", "field_names", ",", "set_operation", ")", ":", "# Split nested field names on the first dot.", "nested_fields", "=", "[", "name", ".", "split", "(", "'.'", ",", "1", ")", "for", "name", "in", ...
Apply nested options to nested fields
[ "Apply", "nested", "options", "to", "nested", "fields" ]
a6b6c4151f1fbf16f3774d4052ca2bddf6903750
https://github.com/marshmallow-code/marshmallow/blob/a6b6c4151f1fbf16f3774d4052ca2bddf6903750/src/marshmallow/schema.py#L896-L913
train
marshmallow-code/marshmallow
src/marshmallow/schema.py
BaseSchema._init_fields
def _init_fields(self): """Update fields based on schema options.""" if self.opts.fields: available_field_names = self.set_class(self.opts.fields) else: available_field_names = self.set_class(self.declared_fields.keys()) if self.opts.additional: ...
python
def _init_fields(self): """Update fields based on schema options.""" if self.opts.fields: available_field_names = self.set_class(self.opts.fields) else: available_field_names = self.set_class(self.declared_fields.keys()) if self.opts.additional: ...
[ "def", "_init_fields", "(", "self", ")", ":", "if", "self", ".", "opts", ".", "fields", ":", "available_field_names", "=", "self", ".", "set_class", "(", "self", ".", "opts", ".", "fields", ")", "else", ":", "available_field_names", "=", "self", ".", "se...
Update fields based on schema options.
[ "Update", "fields", "based", "on", "schema", "options", "." ]
a6b6c4151f1fbf16f3774d4052ca2bddf6903750
https://github.com/marshmallow-code/marshmallow/blob/a6b6c4151f1fbf16f3774d4052ca2bddf6903750/src/marshmallow/schema.py#L915-L977
train
marshmallow-code/marshmallow
src/marshmallow/schema.py
BaseSchema._bind_field
def _bind_field(self, field_name, field_obj): """Bind field to the schema, setting any necessary attributes on the field (e.g. parent and name). Also set field load_only and dump_only values if field_name was specified in ``class Meta``. """ try: if field_nam...
python
def _bind_field(self, field_name, field_obj): """Bind field to the schema, setting any necessary attributes on the field (e.g. parent and name). Also set field load_only and dump_only values if field_name was specified in ``class Meta``. """ try: if field_nam...
[ "def", "_bind_field", "(", "self", ",", "field_name", ",", "field_obj", ")", ":", "try", ":", "if", "field_name", "in", "self", ".", "load_only", ":", "field_obj", ".", "load_only", "=", "True", "if", "field_name", "in", "self", ".", "dump_only", ":", "f...
Bind field to the schema, setting any necessary attributes on the field (e.g. parent and name). Also set field load_only and dump_only values if field_name was specified in ``class Meta``.
[ "Bind", "field", "to", "the", "schema", "setting", "any", "necessary", "attributes", "on", "the", "field", "(", "e", ".", "g", ".", "parent", "and", "name", ")", "." ]
a6b6c4151f1fbf16f3774d4052ca2bddf6903750
https://github.com/marshmallow-code/marshmallow/blob/a6b6c4151f1fbf16f3774d4052ca2bddf6903750/src/marshmallow/schema.py#L986-L1008
train
marshmallow-code/marshmallow
src/marshmallow/decorators.py
validates_schema
def validates_schema( fn=None, pass_many=False, pass_original=False, skip_on_field_errors=True, ): """Register a schema-level validator. By default, receives a single object at a time, regardless of whether ``many=True`` is passed to the `Schema`. If ``pass_many=True``, the raw data (which ...
python
def validates_schema( fn=None, pass_many=False, pass_original=False, skip_on_field_errors=True, ): """Register a schema-level validator. By default, receives a single object at a time, regardless of whether ``many=True`` is passed to the `Schema`. If ``pass_many=True``, the raw data (which ...
[ "def", "validates_schema", "(", "fn", "=", "None", ",", "pass_many", "=", "False", ",", "pass_original", "=", "False", ",", "skip_on_field_errors", "=", "True", ",", ")", ":", "return", "set_hook", "(", "fn", ",", "(", "VALIDATES_SCHEMA", ",", "pass_many", ...
Register a schema-level validator. By default, receives a single object at a time, regardless of whether ``many=True`` is passed to the `Schema`. If ``pass_many=True``, the raw data (which may be a collection) and the value for ``many`` is passed. If ``pass_original=True``, the original data (before u...
[ "Register", "a", "schema", "-", "level", "validator", "." ]
a6b6c4151f1fbf16f3774d4052ca2bddf6903750
https://github.com/marshmallow-code/marshmallow/blob/a6b6c4151f1fbf16f3774d4052ca2bddf6903750/src/marshmallow/decorators.py#L72-L98
train
marshmallow-code/marshmallow
src/marshmallow/decorators.py
post_dump
def post_dump(fn=None, pass_many=False, pass_original=False): """Register a method to invoke after serializing an object. The method receives the serialized object and returns the processed object. By default, receives a single object at a time, transparently handling the ``many`` argument passed to th...
python
def post_dump(fn=None, pass_many=False, pass_original=False): """Register a method to invoke after serializing an object. The method receives the serialized object and returns the processed object. By default, receives a single object at a time, transparently handling the ``many`` argument passed to th...
[ "def", "post_dump", "(", "fn", "=", "None", ",", "pass_many", "=", "False", ",", "pass_original", "=", "False", ")", ":", "return", "set_hook", "(", "fn", ",", "(", "POST_DUMP", ",", "pass_many", ")", ",", "pass_original", "=", "pass_original", ")" ]
Register a method to invoke after serializing an object. The method receives the serialized object and returns the processed object. By default, receives a single object at a time, transparently handling the ``many`` argument passed to the Schema. If ``pass_many=True``, the raw data (which may be a col...
[ "Register", "a", "method", "to", "invoke", "after", "serializing", "an", "object", ".", "The", "method", "receives", "the", "serialized", "object", "and", "returns", "the", "processed", "object", "." ]
a6b6c4151f1fbf16f3774d4052ca2bddf6903750
https://github.com/marshmallow-code/marshmallow/blob/a6b6c4151f1fbf16f3774d4052ca2bddf6903750/src/marshmallow/decorators.py#L112-L123
train
marshmallow-code/marshmallow
src/marshmallow/decorators.py
post_load
def post_load(fn=None, pass_many=False, pass_original=False): """Register a method to invoke after deserializing an object. The method receives the deserialized data and returns the processed data. By default, receives a single datum at a time, transparently handling the ``many`` argument passed to the...
python
def post_load(fn=None, pass_many=False, pass_original=False): """Register a method to invoke after deserializing an object. The method receives the deserialized data and returns the processed data. By default, receives a single datum at a time, transparently handling the ``many`` argument passed to the...
[ "def", "post_load", "(", "fn", "=", "None", ",", "pass_many", "=", "False", ",", "pass_original", "=", "False", ")", ":", "return", "set_hook", "(", "fn", ",", "(", "POST_LOAD", ",", "pass_many", ")", ",", "pass_original", "=", "pass_original", ")" ]
Register a method to invoke after deserializing an object. The method receives the deserialized data and returns the processed data. By default, receives a single datum at a time, transparently handling the ``many`` argument passed to the Schema. If ``pass_many=True``, the raw data (which may be a coll...
[ "Register", "a", "method", "to", "invoke", "after", "deserializing", "an", "object", ".", "The", "method", "receives", "the", "deserialized", "data", "and", "returns", "the", "processed", "data", "." ]
a6b6c4151f1fbf16f3774d4052ca2bddf6903750
https://github.com/marshmallow-code/marshmallow/blob/a6b6c4151f1fbf16f3774d4052ca2bddf6903750/src/marshmallow/decorators.py#L137-L148
train
marshmallow-code/marshmallow
src/marshmallow/decorators.py
set_hook
def set_hook(fn, key, **kwargs): """Mark decorated function as a hook to be picked up later. .. note:: Currently only works with functions and instance methods. Class and static methods are not supported. :return: Decorated function if supplied, else this decorator with its args bo...
python
def set_hook(fn, key, **kwargs): """Mark decorated function as a hook to be picked up later. .. note:: Currently only works with functions and instance methods. Class and static methods are not supported. :return: Decorated function if supplied, else this decorator with its args bo...
[ "def", "set_hook", "(", "fn", ",", "key", ",", "*", "*", "kwargs", ")", ":", "# Allow using this as either a decorator or a decorator factory.", "if", "fn", "is", "None", ":", "return", "functools", ".", "partial", "(", "set_hook", ",", "key", "=", "key", ",",...
Mark decorated function as a hook to be picked up later. .. note:: Currently only works with functions and instance methods. Class and static methods are not supported. :return: Decorated function if supplied, else this decorator with its args bound.
[ "Mark", "decorated", "function", "as", "a", "hook", "to", "be", "picked", "up", "later", "." ]
a6b6c4151f1fbf16f3774d4052ca2bddf6903750
https://github.com/marshmallow-code/marshmallow/blob/a6b6c4151f1fbf16f3774d4052ca2bddf6903750/src/marshmallow/decorators.py#L151-L175
train
marshmallow-code/marshmallow
src/marshmallow/validate.py
OneOf.options
def options(self, valuegetter=text_type): """Return a generator over the (value, label) pairs, where value is a string associated with each choice. This convenience method is useful to populate, for instance, a form select field. :param valuegetter: Can be a callable or a string. In the...
python
def options(self, valuegetter=text_type): """Return a generator over the (value, label) pairs, where value is a string associated with each choice. This convenience method is useful to populate, for instance, a form select field. :param valuegetter: Can be a callable or a string. In the...
[ "def", "options", "(", "self", ",", "valuegetter", "=", "text_type", ")", ":", "valuegetter", "=", "valuegetter", "if", "callable", "(", "valuegetter", ")", "else", "attrgetter", "(", "valuegetter", ")", "pairs", "=", "zip_longest", "(", "self", ".", "choice...
Return a generator over the (value, label) pairs, where value is a string associated with each choice. This convenience method is useful to populate, for instance, a form select field. :param valuegetter: Can be a callable or a string. In the former case, it must be a one-argument c...
[ "Return", "a", "generator", "over", "the", "(", "value", "label", ")", "pairs", "where", "value", "is", "a", "string", "associated", "with", "each", "choice", ".", "This", "convenience", "method", "is", "useful", "to", "populate", "for", "instance", "a", "...
a6b6c4151f1fbf16f3774d4052ca2bddf6903750
https://github.com/marshmallow-code/marshmallow/blob/a6b6c4151f1fbf16f3774d4052ca2bddf6903750/src/marshmallow/validate.py#L441-L455
train
marshmallow-code/marshmallow
src/marshmallow/error_store.py
merge_errors
def merge_errors(errors1, errors2): """Deeply merge two error messages. The format of ``errors1`` and ``errors2`` matches the ``message`` parameter of :exc:`marshmallow.exceptions.ValidationError`. """ if not errors1: return errors2 if not errors2: return errors1 if isinstan...
python
def merge_errors(errors1, errors2): """Deeply merge two error messages. The format of ``errors1`` and ``errors2`` matches the ``message`` parameter of :exc:`marshmallow.exceptions.ValidationError`. """ if not errors1: return errors2 if not errors2: return errors1 if isinstan...
[ "def", "merge_errors", "(", "errors1", ",", "errors2", ")", ":", "if", "not", "errors1", ":", "return", "errors2", "if", "not", "errors2", ":", "return", "errors1", "if", "isinstance", "(", "errors1", ",", "list", ")", ":", "if", "isinstance", "(", "erro...
Deeply merge two error messages. The format of ``errors1`` and ``errors2`` matches the ``message`` parameter of :exc:`marshmallow.exceptions.ValidationError`.
[ "Deeply", "merge", "two", "error", "messages", "." ]
a6b6c4151f1fbf16f3774d4052ca2bddf6903750
https://github.com/marshmallow-code/marshmallow/blob/a6b6c4151f1fbf16f3774d4052ca2bddf6903750/src/marshmallow/error_store.py#L35-L79
train
marshmallow-code/marshmallow
src/marshmallow/class_registry.py
register
def register(classname, cls): """Add a class to the registry of serializer classes. When a class is registered, an entry for both its classname and its full, module-qualified path are added to the registry. Example: :: class MyClass: pass register('MyClass', MyClass) ...
python
def register(classname, cls): """Add a class to the registry of serializer classes. When a class is registered, an entry for both its classname and its full, module-qualified path are added to the registry. Example: :: class MyClass: pass register('MyClass', MyClass) ...
[ "def", "register", "(", "classname", ",", "cls", ")", ":", "# Module where the class is located", "module", "=", "cls", ".", "__module__", "# Full module path to the class", "# e.g. user.schemas.UserSchema", "fullpath", "=", "'.'", ".", "join", "(", "[", "module", ","...
Add a class to the registry of serializer classes. When a class is registered, an entry for both its classname and its full, module-qualified path are added to the registry. Example: :: class MyClass: pass register('MyClass', MyClass) # Registry: # { # ...
[ "Add", "a", "class", "to", "the", "registry", "of", "serializer", "classes", ".", "When", "a", "class", "is", "registered", "an", "entry", "for", "both", "its", "classname", "and", "its", "full", "module", "-", "qualified", "path", "are", "added", "to", ...
a6b6c4151f1fbf16f3774d4052ca2bddf6903750
https://github.com/marshmallow-code/marshmallow/blob/a6b6c4151f1fbf16f3774d4052ca2bddf6903750/src/marshmallow/class_registry.py#L22-L60
train
marshmallow-code/marshmallow
src/marshmallow/class_registry.py
get_class
def get_class(classname, all=False): """Retrieve a class from the registry. :raises: marshmallow.exceptions.RegistryError if the class cannot be found or if there are multiple entries for the given class name. """ try: classes = _registry[classname] except KeyError: raise Re...
python
def get_class(classname, all=False): """Retrieve a class from the registry. :raises: marshmallow.exceptions.RegistryError if the class cannot be found or if there are multiple entries for the given class name. """ try: classes = _registry[classname] except KeyError: raise Re...
[ "def", "get_class", "(", "classname", ",", "all", "=", "False", ")", ":", "try", ":", "classes", "=", "_registry", "[", "classname", "]", "except", "KeyError", ":", "raise", "RegistryError", "(", "'Class with name {!r} was not found. You may need '", "'to import the...
Retrieve a class from the registry. :raises: marshmallow.exceptions.RegistryError if the class cannot be found or if there are multiple entries for the given class name.
[ "Retrieve", "a", "class", "from", "the", "registry", "." ]
a6b6c4151f1fbf16f3774d4052ca2bddf6903750
https://github.com/marshmallow-code/marshmallow/blob/a6b6c4151f1fbf16f3774d4052ca2bddf6903750/src/marshmallow/class_registry.py#L62-L80
train
marshmallow-code/marshmallow
src/marshmallow/fields.py
Field.get_value
def get_value(self, obj, attr, accessor=None, default=missing_): """Return the value for a given key from an object. :param object obj: The object to get the value from :param str attr: The attribute/key in `obj` to get the value from. :param callable accessor: A callable used to retrie...
python
def get_value(self, obj, attr, accessor=None, default=missing_): """Return the value for a given key from an object. :param object obj: The object to get the value from :param str attr: The attribute/key in `obj` to get the value from. :param callable accessor: A callable used to retrie...
[ "def", "get_value", "(", "self", ",", "obj", ",", "attr", ",", "accessor", "=", "None", ",", "default", "=", "missing_", ")", ":", "# NOTE: Use getattr instead of direct attribute access here so that", "# subclasses aren't required to define `attribute` member", "attribute", ...
Return the value for a given key from an object. :param object obj: The object to get the value from :param str attr: The attribute/key in `obj` to get the value from. :param callable accessor: A callable used to retrieve the value of `attr` from the object `obj`. Defaults to `marsh...
[ "Return", "the", "value", "for", "a", "given", "key", "from", "an", "object", "." ]
a6b6c4151f1fbf16f3774d4052ca2bddf6903750
https://github.com/marshmallow-code/marshmallow/blob/a6b6c4151f1fbf16f3774d4052ca2bddf6903750/src/marshmallow/fields.py#L204-L217
train
marshmallow-code/marshmallow
src/marshmallow/fields.py
Field._validate
def _validate(self, value): """Perform validation on ``value``. Raise a :exc:`ValidationError` if validation does not succeed. """ errors = [] kwargs = {} for validator in self.validators: try: r = validator(value) if not isinst...
python
def _validate(self, value): """Perform validation on ``value``. Raise a :exc:`ValidationError` if validation does not succeed. """ errors = [] kwargs = {} for validator in self.validators: try: r = validator(value) if not isinst...
[ "def", "_validate", "(", "self", ",", "value", ")", ":", "errors", "=", "[", "]", "kwargs", "=", "{", "}", "for", "validator", "in", "self", ".", "validators", ":", "try", ":", "r", "=", "validator", "(", "value", ")", "if", "not", "isinstance", "(...
Perform validation on ``value``. Raise a :exc:`ValidationError` if validation does not succeed.
[ "Perform", "validation", "on", "value", ".", "Raise", "a", ":", "exc", ":", "ValidationError", "if", "validation", "does", "not", "succeed", "." ]
a6b6c4151f1fbf16f3774d4052ca2bddf6903750
https://github.com/marshmallow-code/marshmallow/blob/a6b6c4151f1fbf16f3774d4052ca2bddf6903750/src/marshmallow/fields.py#L219-L237
train
marshmallow-code/marshmallow
src/marshmallow/fields.py
Field._validate_missing
def _validate_missing(self, value): """Validate missing values. Raise a :exc:`ValidationError` if `value` should be considered missing. """ if value is missing_: if hasattr(self, 'required') and self.required: self.fail('required') if value is None: ...
python
def _validate_missing(self, value): """Validate missing values. Raise a :exc:`ValidationError` if `value` should be considered missing. """ if value is missing_: if hasattr(self, 'required') and self.required: self.fail('required') if value is None: ...
[ "def", "_validate_missing", "(", "self", ",", "value", ")", ":", "if", "value", "is", "missing_", ":", "if", "hasattr", "(", "self", ",", "'required'", ")", "and", "self", ".", "required", ":", "self", ".", "fail", "(", "'required'", ")", "if", "value"...
Validate missing values. Raise a :exc:`ValidationError` if `value` should be considered missing.
[ "Validate", "missing", "values", ".", "Raise", "a", ":", "exc", ":", "ValidationError", "if", "value", "should", "be", "considered", "missing", "." ]
a6b6c4151f1fbf16f3774d4052ca2bddf6903750
https://github.com/marshmallow-code/marshmallow/blob/a6b6c4151f1fbf16f3774d4052ca2bddf6903750/src/marshmallow/fields.py#L253-L262
train
marshmallow-code/marshmallow
src/marshmallow/fields.py
Field.serialize
def serialize(self, attr, obj, accessor=None, **kwargs): """Pulls the value for the given key from the object, applies the field's formatting and returns the result. :param str attr: The attribute or key to get from the object. :param str obj: The object to pull the key from. :p...
python
def serialize(self, attr, obj, accessor=None, **kwargs): """Pulls the value for the given key from the object, applies the field's formatting and returns the result. :param str attr: The attribute or key to get from the object. :param str obj: The object to pull the key from. :p...
[ "def", "serialize", "(", "self", ",", "attr", ",", "obj", ",", "accessor", "=", "None", ",", "*", "*", "kwargs", ")", ":", "if", "self", ".", "_CHECK_ATTRIBUTE", ":", "value", "=", "self", ".", "get_value", "(", "obj", ",", "attr", ",", "accessor", ...
Pulls the value for the given key from the object, applies the field's formatting and returns the result. :param str attr: The attribute or key to get from the object. :param str obj: The object to pull the key from. :param callable accessor: Function used to pull values from ``obj``. ...
[ "Pulls", "the", "value", "for", "the", "given", "key", "from", "the", "object", "applies", "the", "field", "s", "formatting", "and", "returns", "the", "result", "." ]
a6b6c4151f1fbf16f3774d4052ca2bddf6903750
https://github.com/marshmallow-code/marshmallow/blob/a6b6c4151f1fbf16f3774d4052ca2bddf6903750/src/marshmallow/fields.py#L264-L283
train
marshmallow-code/marshmallow
src/marshmallow/fields.py
Field.deserialize
def deserialize(self, value, attr=None, data=None, **kwargs): """Deserialize ``value``. :param value: The value to be deserialized. :param str attr: The attribute/key in `data` to be deserialized. :param dict data: The raw input data passed to the `Schema.load`. :param dict kwar...
python
def deserialize(self, value, attr=None, data=None, **kwargs): """Deserialize ``value``. :param value: The value to be deserialized. :param str attr: The attribute/key in `data` to be deserialized. :param dict data: The raw input data passed to the `Schema.load`. :param dict kwar...
[ "def", "deserialize", "(", "self", ",", "value", ",", "attr", "=", "None", ",", "data", "=", "None", ",", "*", "*", "kwargs", ")", ":", "# Validate required fields, deserialize, then validate", "# deserialized value", "self", ".", "_validate_missing", "(", "value"...
Deserialize ``value``. :param value: The value to be deserialized. :param str attr: The attribute/key in `data` to be deserialized. :param dict data: The raw input data passed to the `Schema.load`. :param dict kwargs': Field-specific keyword arguments. :raise ValidationError: If...
[ "Deserialize", "value", "." ]
a6b6c4151f1fbf16f3774d4052ca2bddf6903750
https://github.com/marshmallow-code/marshmallow/blob/a6b6c4151f1fbf16f3774d4052ca2bddf6903750/src/marshmallow/fields.py#L285-L305
train
marshmallow-code/marshmallow
src/marshmallow/fields.py
Field._bind_to_schema
def _bind_to_schema(self, field_name, schema): """Update field with values from its parent schema. Called by :meth:`_bind_field<marshmallow.Schema._bind_field>`. :param str field_name: Field name set in schema. :param Schema schema: Parent schema. """ self.parent = s...
python
def _bind_to_schema(self, field_name, schema): """Update field with values from its parent schema. Called by :meth:`_bind_field<marshmallow.Schema._bind_field>`. :param str field_name: Field name set in schema. :param Schema schema: Parent schema. """ self.parent = s...
[ "def", "_bind_to_schema", "(", "self", ",", "field_name", ",", "schema", ")", ":", "self", ".", "parent", "=", "self", ".", "parent", "or", "schema", "self", ".", "name", "=", "self", ".", "name", "or", "field_name" ]
Update field with values from its parent schema. Called by :meth:`_bind_field<marshmallow.Schema._bind_field>`. :param str field_name: Field name set in schema. :param Schema schema: Parent schema.
[ "Update", "field", "with", "values", "from", "its", "parent", "schema", ".", "Called", "by", ":", "meth", ":", "_bind_field<marshmallow", ".", "Schema", ".", "_bind_field", ">", "." ]
a6b6c4151f1fbf16f3774d4052ca2bddf6903750
https://github.com/marshmallow-code/marshmallow/blob/a6b6c4151f1fbf16f3774d4052ca2bddf6903750/src/marshmallow/fields.py#L309-L317
train
marshmallow-code/marshmallow
src/marshmallow/fields.py
Field.root
def root(self): """Reference to the `Schema` that this field belongs to even if it is buried in a `List`. Return `None` for unbound fields. """ ret = self while hasattr(ret, 'parent') and ret.parent: ret = ret.parent return ret if isinstance(ret, SchemaABC) el...
python
def root(self): """Reference to the `Schema` that this field belongs to even if it is buried in a `List`. Return `None` for unbound fields. """ ret = self while hasattr(ret, 'parent') and ret.parent: ret = ret.parent return ret if isinstance(ret, SchemaABC) el...
[ "def", "root", "(", "self", ")", ":", "ret", "=", "self", "while", "hasattr", "(", "ret", ",", "'parent'", ")", "and", "ret", ".", "parent", ":", "ret", "=", "ret", ".", "parent", "return", "ret", "if", "isinstance", "(", "ret", ",", "SchemaABC", "...
Reference to the `Schema` that this field belongs to even if it is buried in a `List`. Return `None` for unbound fields.
[ "Reference", "to", "the", "Schema", "that", "this", "field", "belongs", "to", "even", "if", "it", "is", "buried", "in", "a", "List", ".", "Return", "None", "for", "unbound", "fields", "." ]
a6b6c4151f1fbf16f3774d4052ca2bddf6903750
https://github.com/marshmallow-code/marshmallow/blob/a6b6c4151f1fbf16f3774d4052ca2bddf6903750/src/marshmallow/fields.py#L366-L373
train
marshmallow-code/marshmallow
src/marshmallow/fields.py
Nested.schema
def schema(self): """The nested Schema object. .. versionchanged:: 1.0.0 Renamed from `serializer` to `schema` """ if not self.__schema: # Inherit context from parent. context = getattr(self.parent, 'context', {}) if isinstance(self.nested...
python
def schema(self): """The nested Schema object. .. versionchanged:: 1.0.0 Renamed from `serializer` to `schema` """ if not self.__schema: # Inherit context from parent. context = getattr(self.parent, 'context', {}) if isinstance(self.nested...
[ "def", "schema", "(", "self", ")", ":", "if", "not", "self", ".", "__schema", ":", "# Inherit context from parent.", "context", "=", "getattr", "(", "self", ".", "parent", ",", "'context'", ",", "{", "}", ")", "if", "isinstance", "(", "self", ".", "neste...
The nested Schema object. .. versionchanged:: 1.0.0 Renamed from `serializer` to `schema`
[ "The", "nested", "Schema", "object", "." ]
a6b6c4151f1fbf16f3774d4052ca2bddf6903750
https://github.com/marshmallow-code/marshmallow/blob/a6b6c4151f1fbf16f3774d4052ca2bddf6903750/src/marshmallow/fields.py#L435-L467
train
marshmallow-code/marshmallow
src/marshmallow/fields.py
Nested._deserialize
def _deserialize(self, value, attr, data, partial=None, **kwargs): """Same as :meth:`Field._deserialize` with additional ``partial`` argument. :param bool|tuple partial: For nested schemas, the ``partial`` parameter passed to `Schema.load`. .. versionchanged:: 3.0.0 Add...
python
def _deserialize(self, value, attr, data, partial=None, **kwargs): """Same as :meth:`Field._deserialize` with additional ``partial`` argument. :param bool|tuple partial: For nested schemas, the ``partial`` parameter passed to `Schema.load`. .. versionchanged:: 3.0.0 Add...
[ "def", "_deserialize", "(", "self", ",", "value", ",", "attr", ",", "data", ",", "partial", "=", "None", ",", "*", "*", "kwargs", ")", ":", "self", ".", "_test_collection", "(", "value", ")", "return", "self", ".", "_load", "(", "value", ",", "data",...
Same as :meth:`Field._deserialize` with additional ``partial`` argument. :param bool|tuple partial: For nested schemas, the ``partial`` parameter passed to `Schema.load`. .. versionchanged:: 3.0.0 Add ``partial`` parameter
[ "Same", "as", ":", "meth", ":", "Field", ".", "_deserialize", "with", "additional", "partial", "argument", "." ]
a6b6c4151f1fbf16f3774d4052ca2bddf6903750
https://github.com/marshmallow-code/marshmallow/blob/a6b6c4151f1fbf16f3774d4052ca2bddf6903750/src/marshmallow/fields.py#L499-L509
train
marshmallow-code/marshmallow
src/marshmallow/fields.py
UUID._validated
def _validated(self, value): """Format the value or raise a :exc:`ValidationError` if an error occurs.""" if value is None: return None if isinstance(value, uuid.UUID): return value try: if isinstance(value, bytes) and len(value) == 16: ...
python
def _validated(self, value): """Format the value or raise a :exc:`ValidationError` if an error occurs.""" if value is None: return None if isinstance(value, uuid.UUID): return value try: if isinstance(value, bytes) and len(value) == 16: ...
[ "def", "_validated", "(", "self", ",", "value", ")", ":", "if", "value", "is", "None", ":", "return", "None", "if", "isinstance", "(", "value", ",", "uuid", ".", "UUID", ")", ":", "return", "value", "try", ":", "if", "isinstance", "(", "value", ",", ...
Format the value or raise a :exc:`ValidationError` if an error occurs.
[ "Format", "the", "value", "or", "raise", "a", ":", "exc", ":", "ValidationError", "if", "an", "error", "occurs", "." ]
a6b6c4151f1fbf16f3774d4052ca2bddf6903750
https://github.com/marshmallow-code/marshmallow/blob/a6b6c4151f1fbf16f3774d4052ca2bddf6903750/src/marshmallow/fields.py#L728-L740
train
marshmallow-code/marshmallow
src/marshmallow/fields.py
Number._format_num
def _format_num(self, value): """Return the number value for value, given this field's `num_type`.""" # (value is True or value is False) is ~5x faster than isinstance(value, bool) if value is True or value is False: raise TypeError('value must be a Number, not a boolean.') r...
python
def _format_num(self, value): """Return the number value for value, given this field's `num_type`.""" # (value is True or value is False) is ~5x faster than isinstance(value, bool) if value is True or value is False: raise TypeError('value must be a Number, not a boolean.') r...
[ "def", "_format_num", "(", "self", ",", "value", ")", ":", "# (value is True or value is False) is ~5x faster than isinstance(value, bool)", "if", "value", "is", "True", "or", "value", "is", "False", ":", "raise", "TypeError", "(", "'value must be a Number, not a boolean.'"...
Return the number value for value, given this field's `num_type`.
[ "Return", "the", "number", "value", "for", "value", "given", "this", "field", "s", "num_type", "." ]
a6b6c4151f1fbf16f3774d4052ca2bddf6903750
https://github.com/marshmallow-code/marshmallow/blob/a6b6c4151f1fbf16f3774d4052ca2bddf6903750/src/marshmallow/fields.py#L767-L772
train
marshmallow-code/marshmallow
src/marshmallow/fields.py
Number._validated
def _validated(self, value): """Format the value or raise a :exc:`ValidationError` if an error occurs.""" if value is None: return None try: return self._format_num(value) except (TypeError, ValueError): self.fail('invalid', input=value) except...
python
def _validated(self, value): """Format the value or raise a :exc:`ValidationError` if an error occurs.""" if value is None: return None try: return self._format_num(value) except (TypeError, ValueError): self.fail('invalid', input=value) except...
[ "def", "_validated", "(", "self", ",", "value", ")", ":", "if", "value", "is", "None", ":", "return", "None", "try", ":", "return", "self", ".", "_format_num", "(", "value", ")", "except", "(", "TypeError", ",", "ValueError", ")", ":", "self", ".", "...
Format the value or raise a :exc:`ValidationError` if an error occurs.
[ "Format", "the", "value", "or", "raise", "a", ":", "exc", ":", "ValidationError", "if", "an", "error", "occurs", "." ]
a6b6c4151f1fbf16f3774d4052ca2bddf6903750
https://github.com/marshmallow-code/marshmallow/blob/a6b6c4151f1fbf16f3774d4052ca2bddf6903750/src/marshmallow/fields.py#L774-L783
train
marshmallow-code/marshmallow
src/marshmallow/fields.py
Number._serialize
def _serialize(self, value, attr, obj, **kwargs): """Return a string if `self.as_string=True`, otherwise return this field's `num_type`.""" ret = self._validated(value) return ( self._to_string(ret) if (self.as_string and ret not in (None, missing_)) else ret ...
python
def _serialize(self, value, attr, obj, **kwargs): """Return a string if `self.as_string=True`, otherwise return this field's `num_type`.""" ret = self._validated(value) return ( self._to_string(ret) if (self.as_string and ret not in (None, missing_)) else ret ...
[ "def", "_serialize", "(", "self", ",", "value", ",", "attr", ",", "obj", ",", "*", "*", "kwargs", ")", ":", "ret", "=", "self", ".", "_validated", "(", "value", ")", "return", "(", "self", ".", "_to_string", "(", "ret", ")", "if", "(", "self", "....
Return a string if `self.as_string=True`, otherwise return this field's `num_type`.
[ "Return", "a", "string", "if", "self", ".", "as_string", "=", "True", "otherwise", "return", "this", "field", "s", "num_type", "." ]
a6b6c4151f1fbf16f3774d4052ca2bddf6903750
https://github.com/marshmallow-code/marshmallow/blob/a6b6c4151f1fbf16f3774d4052ca2bddf6903750/src/marshmallow/fields.py#L788-L795
train
marshmallow-code/marshmallow
src/marshmallow/fields.py
Time._deserialize
def _deserialize(self, value, attr, data, **kwargs): """Deserialize an ISO8601-formatted time to a :class:`datetime.time` object.""" if not value: # falsy values are invalid self.fail('invalid') try: return utils.from_iso_time(value) except (AttributeError, TypeE...
python
def _deserialize(self, value, attr, data, **kwargs): """Deserialize an ISO8601-formatted time to a :class:`datetime.time` object.""" if not value: # falsy values are invalid self.fail('invalid') try: return utils.from_iso_time(value) except (AttributeError, TypeE...
[ "def", "_deserialize", "(", "self", ",", "value", ",", "attr", ",", "data", ",", "*", "*", "kwargs", ")", ":", "if", "not", "value", ":", "# falsy values are invalid", "self", ".", "fail", "(", "'invalid'", ")", "try", ":", "return", "utils", ".", "fro...
Deserialize an ISO8601-formatted time to a :class:`datetime.time` object.
[ "Deserialize", "an", "ISO8601", "-", "formatted", "time", "to", "a", ":", "class", ":", "datetime", ".", "time", "object", "." ]
a6b6c4151f1fbf16f3774d4052ca2bddf6903750
https://github.com/marshmallow-code/marshmallow/blob/a6b6c4151f1fbf16f3774d4052ca2bddf6903750/src/marshmallow/fields.py#L1143-L1150
train
marshmallow-code/marshmallow
src/marshmallow/utils.py
is_instance_or_subclass
def is_instance_or_subclass(val, class_): """Return True if ``val`` is either a subclass or instance of ``class_``.""" try: return issubclass(val, class_) except TypeError: return isinstance(val, class_)
python
def is_instance_or_subclass(val, class_): """Return True if ``val`` is either a subclass or instance of ``class_``.""" try: return issubclass(val, class_) except TypeError: return isinstance(val, class_)
[ "def", "is_instance_or_subclass", "(", "val", ",", "class_", ")", ":", "try", ":", "return", "issubclass", "(", "val", ",", "class_", ")", "except", "TypeError", ":", "return", "isinstance", "(", "val", ",", "class_", ")" ]
Return True if ``val`` is either a subclass or instance of ``class_``.
[ "Return", "True", "if", "val", "is", "either", "a", "subclass", "or", "instance", "of", "class_", "." ]
a6b6c4151f1fbf16f3774d4052ca2bddf6903750
https://github.com/marshmallow-code/marshmallow/blob/a6b6c4151f1fbf16f3774d4052ca2bddf6903750/src/marshmallow/utils.py#L72-L77
train
marshmallow-code/marshmallow
src/marshmallow/utils.py
pprint
def pprint(obj, *args, **kwargs): """Pretty-printing function that can pretty-print OrderedDicts like regular dictionaries. Useful for printing the output of :meth:`marshmallow.Schema.dump`. """ if isinstance(obj, collections.OrderedDict): print(json.dumps(obj, *args, **kwargs)) else: ...
python
def pprint(obj, *args, **kwargs): """Pretty-printing function that can pretty-print OrderedDicts like regular dictionaries. Useful for printing the output of :meth:`marshmallow.Schema.dump`. """ if isinstance(obj, collections.OrderedDict): print(json.dumps(obj, *args, **kwargs)) else: ...
[ "def", "pprint", "(", "obj", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "if", "isinstance", "(", "obj", ",", "collections", ".", "OrderedDict", ")", ":", "print", "(", "json", ".", "dumps", "(", "obj", ",", "*", "args", ",", "*", "*", ...
Pretty-printing function that can pretty-print OrderedDicts like regular dictionaries. Useful for printing the output of :meth:`marshmallow.Schema.dump`.
[ "Pretty", "-", "printing", "function", "that", "can", "pretty", "-", "print", "OrderedDicts", "like", "regular", "dictionaries", ".", "Useful", "for", "printing", "the", "output", "of", ":", "meth", ":", "marshmallow", ".", "Schema", ".", "dump", "." ]
a6b6c4151f1fbf16f3774d4052ca2bddf6903750
https://github.com/marshmallow-code/marshmallow/blob/a6b6c4151f1fbf16f3774d4052ca2bddf6903750/src/marshmallow/utils.py#L86-L94
train
marshmallow-code/marshmallow
src/marshmallow/utils.py
local_rfcformat
def local_rfcformat(dt): """Return the RFC822-formatted representation of a timezone-aware datetime with the UTC offset. """ weekday = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'][dt.weekday()] month = [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov'...
python
def local_rfcformat(dt): """Return the RFC822-formatted representation of a timezone-aware datetime with the UTC offset. """ weekday = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'][dt.weekday()] month = [ 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov'...
[ "def", "local_rfcformat", "(", "dt", ")", ":", "weekday", "=", "[", "'Mon'", ",", "'Tue'", ",", "'Wed'", ",", "'Thu'", ",", "'Fri'", ",", "'Sat'", ",", "'Sun'", "]", "[", "dt", ".", "weekday", "(", ")", "]", "month", "=", "[", "'Jan'", ",", "'Feb...
Return the RFC822-formatted representation of a timezone-aware datetime with the UTC offset.
[ "Return", "the", "RFC822", "-", "formatted", "representation", "of", "a", "timezone", "-", "aware", "datetime", "with", "the", "UTC", "offset", "." ]
a6b6c4151f1fbf16f3774d4052ca2bddf6903750
https://github.com/marshmallow-code/marshmallow/blob/a6b6c4151f1fbf16f3774d4052ca2bddf6903750/src/marshmallow/utils.py#L151-L164
train
marshmallow-code/marshmallow
src/marshmallow/utils.py
rfcformat
def rfcformat(dt, localtime=False): """Return the RFC822-formatted representation of a datetime object. :param datetime dt: The datetime. :param bool localtime: If ``True``, return the date relative to the local timezone instead of UTC, displaying the proper offset, e.g. "Sun, 10 Nov 2013 0...
python
def rfcformat(dt, localtime=False): """Return the RFC822-formatted representation of a datetime object. :param datetime dt: The datetime. :param bool localtime: If ``True``, return the date relative to the local timezone instead of UTC, displaying the proper offset, e.g. "Sun, 10 Nov 2013 0...
[ "def", "rfcformat", "(", "dt", ",", "localtime", "=", "False", ")", ":", "if", "not", "localtime", ":", "return", "formatdate", "(", "timegm", "(", "dt", ".", "utctimetuple", "(", ")", ")", ")", "else", ":", "return", "local_rfcformat", "(", "dt", ")" ...
Return the RFC822-formatted representation of a datetime object. :param datetime dt: The datetime. :param bool localtime: If ``True``, return the date relative to the local timezone instead of UTC, displaying the proper offset, e.g. "Sun, 10 Nov 2013 08:23:45 -0600"
[ "Return", "the", "RFC822", "-", "formatted", "representation", "of", "a", "datetime", "object", "." ]
a6b6c4151f1fbf16f3774d4052ca2bddf6903750
https://github.com/marshmallow-code/marshmallow/blob/a6b6c4151f1fbf16f3774d4052ca2bddf6903750/src/marshmallow/utils.py#L167-L178
train
marshmallow-code/marshmallow
src/marshmallow/utils.py
isoformat
def isoformat(dt, localtime=False, *args, **kwargs): """Return the ISO8601-formatted UTC representation of a datetime object.""" if localtime and dt.tzinfo is not None: localized = dt else: if dt.tzinfo is None: localized = UTC.localize(dt) else: localized = d...
python
def isoformat(dt, localtime=False, *args, **kwargs): """Return the ISO8601-formatted UTC representation of a datetime object.""" if localtime and dt.tzinfo is not None: localized = dt else: if dt.tzinfo is None: localized = UTC.localize(dt) else: localized = d...
[ "def", "isoformat", "(", "dt", ",", "localtime", "=", "False", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "if", "localtime", "and", "dt", ".", "tzinfo", "is", "not", "None", ":", "localized", "=", "dt", "else", ":", "if", "dt", ".", "tz...
Return the ISO8601-formatted UTC representation of a datetime object.
[ "Return", "the", "ISO8601", "-", "formatted", "UTC", "representation", "of", "a", "datetime", "object", "." ]
a6b6c4151f1fbf16f3774d4052ca2bddf6903750
https://github.com/marshmallow-code/marshmallow/blob/a6b6c4151f1fbf16f3774d4052ca2bddf6903750/src/marshmallow/utils.py#L199-L208
train
marshmallow-code/marshmallow
src/marshmallow/utils.py
from_rfc
def from_rfc(datestring, use_dateutil=True): """Parse a RFC822-formatted datetime string and return a datetime object. Use dateutil's parser if possible. https://stackoverflow.com/questions/885015/how-to-parse-a-rfc-2822-date-time-into-a-python-datetime """ # Use dateutil's parser if possible ...
python
def from_rfc(datestring, use_dateutil=True): """Parse a RFC822-formatted datetime string and return a datetime object. Use dateutil's parser if possible. https://stackoverflow.com/questions/885015/how-to-parse-a-rfc-2822-date-time-into-a-python-datetime """ # Use dateutil's parser if possible ...
[ "def", "from_rfc", "(", "datestring", ",", "use_dateutil", "=", "True", ")", ":", "# Use dateutil's parser if possible", "if", "dateutil_available", "and", "use_dateutil", ":", "return", "parser", ".", "parse", "(", "datestring", ")", "else", ":", "parsed", "=", ...
Parse a RFC822-formatted datetime string and return a datetime object. Use dateutil's parser if possible. https://stackoverflow.com/questions/885015/how-to-parse-a-rfc-2822-date-time-into-a-python-datetime
[ "Parse", "a", "RFC822", "-", "formatted", "datetime", "string", "and", "return", "a", "datetime", "object", "." ]
a6b6c4151f1fbf16f3774d4052ca2bddf6903750
https://github.com/marshmallow-code/marshmallow/blob/a6b6c4151f1fbf16f3774d4052ca2bddf6903750/src/marshmallow/utils.py#L211-L224
train
marshmallow-code/marshmallow
src/marshmallow/utils.py
from_iso_datetime
def from_iso_datetime(datetimestring, use_dateutil=True): """Parse an ISO8601-formatted datetime string and return a datetime object. Use dateutil's parser if possible and return a timezone-aware datetime. """ if not _iso8601_datetime_re.match(datetimestring): raise ValueError('Not a valid ISO8...
python
def from_iso_datetime(datetimestring, use_dateutil=True): """Parse an ISO8601-formatted datetime string and return a datetime object. Use dateutil's parser if possible and return a timezone-aware datetime. """ if not _iso8601_datetime_re.match(datetimestring): raise ValueError('Not a valid ISO8...
[ "def", "from_iso_datetime", "(", "datetimestring", ",", "use_dateutil", "=", "True", ")", ":", "if", "not", "_iso8601_datetime_re", ".", "match", "(", "datetimestring", ")", ":", "raise", "ValueError", "(", "'Not a valid ISO8601-formatted datetime string'", ")", "# Us...
Parse an ISO8601-formatted datetime string and return a datetime object. Use dateutil's parser if possible and return a timezone-aware datetime.
[ "Parse", "an", "ISO8601", "-", "formatted", "datetime", "string", "and", "return", "a", "datetime", "object", "." ]
a6b6c4151f1fbf16f3774d4052ca2bddf6903750
https://github.com/marshmallow-code/marshmallow/blob/a6b6c4151f1fbf16f3774d4052ca2bddf6903750/src/marshmallow/utils.py#L227-L239
train
marshmallow-code/marshmallow
src/marshmallow/utils.py
from_iso_time
def from_iso_time(timestring, use_dateutil=True): """Parse an ISO8601-formatted datetime string and return a datetime.time object. """ if not _iso8601_time_re.match(timestring): raise ValueError('Not a valid ISO8601-formatted time string') if dateutil_available and use_dateutil: retu...
python
def from_iso_time(timestring, use_dateutil=True): """Parse an ISO8601-formatted datetime string and return a datetime.time object. """ if not _iso8601_time_re.match(timestring): raise ValueError('Not a valid ISO8601-formatted time string') if dateutil_available and use_dateutil: retu...
[ "def", "from_iso_time", "(", "timestring", ",", "use_dateutil", "=", "True", ")", ":", "if", "not", "_iso8601_time_re", ".", "match", "(", "timestring", ")", ":", "raise", "ValueError", "(", "'Not a valid ISO8601-formatted time string'", ")", "if", "dateutil_availab...
Parse an ISO8601-formatted datetime string and return a datetime.time object.
[ "Parse", "an", "ISO8601", "-", "formatted", "datetime", "string", "and", "return", "a", "datetime", ".", "time", "object", "." ]
a6b6c4151f1fbf16f3774d4052ca2bddf6903750
https://github.com/marshmallow-code/marshmallow/blob/a6b6c4151f1fbf16f3774d4052ca2bddf6903750/src/marshmallow/utils.py#L242-L255
train
marshmallow-code/marshmallow
src/marshmallow/utils.py
set_value
def set_value(dct, key, value): """Set a value in a dict. If `key` contains a '.', it is assumed be a path (i.e. dot-delimited string) to the value's location. :: >>> d = {} >>> set_value(d, 'foo.bar', 42) >>> d {'foo': {'bar': 42}} """ if '.' in key: head, ...
python
def set_value(dct, key, value): """Set a value in a dict. If `key` contains a '.', it is assumed be a path (i.e. dot-delimited string) to the value's location. :: >>> d = {} >>> set_value(d, 'foo.bar', 42) >>> d {'foo': {'bar': 42}} """ if '.' in key: head, ...
[ "def", "set_value", "(", "dct", ",", "key", ",", "value", ")", ":", "if", "'.'", "in", "key", ":", "head", ",", "rest", "=", "key", ".", "split", "(", "'.'", ",", "1", ")", "target", "=", "dct", ".", "setdefault", "(", "head", ",", "{", "}", ...
Set a value in a dict. If `key` contains a '.', it is assumed be a path (i.e. dot-delimited string) to the value's location. :: >>> d = {} >>> set_value(d, 'foo.bar', 42) >>> d {'foo': {'bar': 42}}
[ "Set", "a", "value", "in", "a", "dict", ".", "If", "key", "contains", "a", ".", "it", "is", "assumed", "be", "a", "path", "(", "i", ".", "e", ".", "dot", "-", "delimited", "string", ")", "to", "the", "value", "s", "location", "." ]
a6b6c4151f1fbf16f3774d4052ca2bddf6903750
https://github.com/marshmallow-code/marshmallow/blob/a6b6c4151f1fbf16f3774d4052ca2bddf6903750/src/marshmallow/utils.py#L323-L344
train
marshmallow-code/marshmallow
src/marshmallow/utils.py
get_func_args
def get_func_args(func): """Given a callable, return a tuple of argument names. Handles `functools.partial` objects and class-based callables. .. versionchanged:: 3.0.0a1 Do not return bound arguments, eg. ``self``. """ if isinstance(func, functools.partial): return _signature(func....
python
def get_func_args(func): """Given a callable, return a tuple of argument names. Handles `functools.partial` objects and class-based callables. .. versionchanged:: 3.0.0a1 Do not return bound arguments, eg. ``self``. """ if isinstance(func, functools.partial): return _signature(func....
[ "def", "get_func_args", "(", "func", ")", ":", "if", "isinstance", "(", "func", ",", "functools", ".", "partial", ")", ":", "return", "_signature", "(", "func", ".", "func", ")", "if", "inspect", ".", "isfunction", "(", "func", ")", "or", "inspect", "....
Given a callable, return a tuple of argument names. Handles `functools.partial` objects and class-based callables. .. versionchanged:: 3.0.0a1 Do not return bound arguments, eg. ``self``.
[ "Given", "a", "callable", "return", "a", "tuple", "of", "argument", "names", ".", "Handles", "functools", ".", "partial", "objects", "and", "class", "-", "based", "callables", "." ]
a6b6c4151f1fbf16f3774d4052ca2bddf6903750
https://github.com/marshmallow-code/marshmallow/blob/a6b6c4151f1fbf16f3774d4052ca2bddf6903750/src/marshmallow/utils.py#L365-L377
train
marshmallow-code/marshmallow
src/marshmallow/utils.py
resolve_field_instance
def resolve_field_instance(cls_or_instance): """Return a Schema instance from a Schema class or instance. :param type|Schema cls_or_instance: Marshmallow Schema class or instance. """ if isinstance(cls_or_instance, type): if not issubclass(cls_or_instance, FieldABC): raise FieldInst...
python
def resolve_field_instance(cls_or_instance): """Return a Schema instance from a Schema class or instance. :param type|Schema cls_or_instance: Marshmallow Schema class or instance. """ if isinstance(cls_or_instance, type): if not issubclass(cls_or_instance, FieldABC): raise FieldInst...
[ "def", "resolve_field_instance", "(", "cls_or_instance", ")", ":", "if", "isinstance", "(", "cls_or_instance", ",", "type", ")", ":", "if", "not", "issubclass", "(", "cls_or_instance", ",", "FieldABC", ")", ":", "raise", "FieldInstanceResolutionError", "return", "...
Return a Schema instance from a Schema class or instance. :param type|Schema cls_or_instance: Marshmallow Schema class or instance.
[ "Return", "a", "Schema", "instance", "from", "a", "Schema", "class", "or", "instance", "." ]
a6b6c4151f1fbf16f3774d4052ca2bddf6903750
https://github.com/marshmallow-code/marshmallow/blob/a6b6c4151f1fbf16f3774d4052ca2bddf6903750/src/marshmallow/utils.py#L380-L392
train
marshmallow-code/marshmallow
src/marshmallow/utils.py
UTC.localize
def localize(self, dt, is_dst=False): """Convert naive time to local time""" if dt.tzinfo is not None: raise ValueError('Not naive datetime (tzinfo is already set)') return dt.replace(tzinfo=self)
python
def localize(self, dt, is_dst=False): """Convert naive time to local time""" if dt.tzinfo is not None: raise ValueError('Not naive datetime (tzinfo is already set)') return dt.replace(tzinfo=self)
[ "def", "localize", "(", "self", ",", "dt", ",", "is_dst", "=", "False", ")", ":", "if", "dt", ".", "tzinfo", "is", "not", "None", ":", "raise", "ValueError", "(", "'Not naive datetime (tzinfo is already set)'", ")", "return", "dt", ".", "replace", "(", "tz...
Convert naive time to local time
[ "Convert", "naive", "time", "to", "local", "time" ]
a6b6c4151f1fbf16f3774d4052ca2bddf6903750
https://github.com/marshmallow-code/marshmallow/blob/a6b6c4151f1fbf16f3774d4052ca2bddf6903750/src/marshmallow/utils.py#L127-L131
train
marshmallow-code/marshmallow
src/marshmallow/utils.py
UTC.normalize
def normalize(self, dt, is_dst=False): """Correct the timezone information on the given datetime""" if dt.tzinfo is self: return dt if dt.tzinfo is None: raise ValueError('Naive time - no tzinfo set') return dt.astimezone(self)
python
def normalize(self, dt, is_dst=False): """Correct the timezone information on the given datetime""" if dt.tzinfo is self: return dt if dt.tzinfo is None: raise ValueError('Naive time - no tzinfo set') return dt.astimezone(self)
[ "def", "normalize", "(", "self", ",", "dt", ",", "is_dst", "=", "False", ")", ":", "if", "dt", ".", "tzinfo", "is", "self", ":", "return", "dt", "if", "dt", ".", "tzinfo", "is", "None", ":", "raise", "ValueError", "(", "'Naive time - no tzinfo set'", "...
Correct the timezone information on the given datetime
[ "Correct", "the", "timezone", "information", "on", "the", "given", "datetime" ]
a6b6c4151f1fbf16f3774d4052ca2bddf6903750
https://github.com/marshmallow-code/marshmallow/blob/a6b6c4151f1fbf16f3774d4052ca2bddf6903750/src/marshmallow/utils.py#L133-L139
train
marshmallow-code/marshmallow
examples/peewee_example.py
check_auth
def check_auth(email, password): """Check if a username/password combination is valid. """ try: user = User.get(User.email == email) except User.DoesNotExist: return False return password == user.password
python
def check_auth(email, password): """Check if a username/password combination is valid. """ try: user = User.get(User.email == email) except User.DoesNotExist: return False return password == user.password
[ "def", "check_auth", "(", "email", ",", "password", ")", ":", "try", ":", "user", "=", "User", ".", "get", "(", "User", ".", "email", "==", "email", ")", "except", "User", ".", "DoesNotExist", ":", "return", "False", "return", "password", "==", "user",...
Check if a username/password combination is valid.
[ "Check", "if", "a", "username", "/", "password", "combination", "is", "valid", "." ]
a6b6c4151f1fbf16f3774d4052ca2bddf6903750
https://github.com/marshmallow-code/marshmallow/blob/a6b6c4151f1fbf16f3774d4052ca2bddf6903750/examples/peewee_example.py#L100-L107
train
pennersr/django-allauth
allauth/account/auth_backends.py
AuthenticationBackend._stash_user
def _stash_user(cls, user): """Now, be aware, the following is quite ugly, let me explain: Even if the user credentials match, the authentication can fail because Django's default ModelBackend calls user_can_authenticate(), which checks `is_active`. Now, earlier versions of allauth did ...
python
def _stash_user(cls, user): """Now, be aware, the following is quite ugly, let me explain: Even if the user credentials match, the authentication can fail because Django's default ModelBackend calls user_can_authenticate(), which checks `is_active`. Now, earlier versions of allauth did ...
[ "def", "_stash_user", "(", "cls", ",", "user", ")", ":", "global", "_stash", "ret", "=", "getattr", "(", "_stash", ",", "'user'", ",", "None", ")", "_stash", ".", "user", "=", "user", "return", "ret" ]
Now, be aware, the following is quite ugly, let me explain: Even if the user credentials match, the authentication can fail because Django's default ModelBackend calls user_can_authenticate(), which checks `is_active`. Now, earlier versions of allauth did not do this and simply returned...
[ "Now", "be", "aware", "the", "following", "is", "quite", "ugly", "let", "me", "explain", ":" ]
f70cb3d622f992f15fe9b57098e0b328445b664e
https://github.com/pennersr/django-allauth/blob/f70cb3d622f992f15fe9b57098e0b328445b664e/allauth/account/auth_backends.py#L68-L93
train
pennersr/django-allauth
allauth/socialaccount/providers/bitbucket_oauth2/views.py
BitbucketOAuth2Adapter.get_email
def get_email(self, token): """Fetches email address from email API endpoint""" resp = requests.get(self.emails_url, params={'access_token': token.token}) emails = resp.json().get('values', []) email = '' try: email = emails[0].get('email')...
python
def get_email(self, token): """Fetches email address from email API endpoint""" resp = requests.get(self.emails_url, params={'access_token': token.token}) emails = resp.json().get('values', []) email = '' try: email = emails[0].get('email')...
[ "def", "get_email", "(", "self", ",", "token", ")", ":", "resp", "=", "requests", ".", "get", "(", "self", ".", "emails_url", ",", "params", "=", "{", "'access_token'", ":", "token", ".", "token", "}", ")", "emails", "=", "resp", ".", "json", "(", ...
Fetches email address from email API endpoint
[ "Fetches", "email", "address", "from", "email", "API", "endpoint" ]
f70cb3d622f992f15fe9b57098e0b328445b664e
https://github.com/pennersr/django-allauth/blob/f70cb3d622f992f15fe9b57098e0b328445b664e/allauth/socialaccount/providers/bitbucket_oauth2/views.py#L29-L42
train
pennersr/django-allauth
allauth/account/adapter.py
DefaultAccountAdapter.is_email_verified
def is_email_verified(self, request, email): """ Checks whether or not the email address is already verified beyond allauth scope, for example, by having accepted an invitation before signing up. """ ret = False verified_email = request.session.get('account_verifi...
python
def is_email_verified(self, request, email): """ Checks whether or not the email address is already verified beyond allauth scope, for example, by having accepted an invitation before signing up. """ ret = False verified_email = request.session.get('account_verifi...
[ "def", "is_email_verified", "(", "self", ",", "request", ",", "email", ")", ":", "ret", "=", "False", "verified_email", "=", "request", ".", "session", ".", "get", "(", "'account_verified_email'", ")", "if", "verified_email", ":", "ret", "=", "verified_email",...
Checks whether or not the email address is already verified beyond allauth scope, for example, by having accepted an invitation before signing up.
[ "Checks", "whether", "or", "not", "the", "email", "address", "is", "already", "verified", "beyond", "allauth", "scope", "for", "example", "by", "having", "accepted", "an", "invitation", "before", "signing", "up", "." ]
f70cb3d622f992f15fe9b57098e0b328445b664e
https://github.com/pennersr/django-allauth/blob/f70cb3d622f992f15fe9b57098e0b328445b664e/allauth/account/adapter.py#L71-L81
train
pennersr/django-allauth
allauth/account/adapter.py
DefaultAccountAdapter.get_login_redirect_url
def get_login_redirect_url(self, request): """ Returns the default URL to redirect to after logging in. Note that URLs passed explicitly (e.g. by passing along a `next` GET parameter) take precedence over the value returned here. """ assert request.user.is_authenticated ...
python
def get_login_redirect_url(self, request): """ Returns the default URL to redirect to after logging in. Note that URLs passed explicitly (e.g. by passing along a `next` GET parameter) take precedence over the value returned here. """ assert request.user.is_authenticated ...
[ "def", "get_login_redirect_url", "(", "self", ",", "request", ")", ":", "assert", "request", ".", "user", ".", "is_authenticated", "url", "=", "getattr", "(", "settings", ",", "\"LOGIN_REDIRECT_URLNAME\"", ",", "None", ")", "if", "url", ":", "warnings", ".", ...
Returns the default URL to redirect to after logging in. Note that URLs passed explicitly (e.g. by passing along a `next` GET parameter) take precedence over the value returned here.
[ "Returns", "the", "default", "URL", "to", "redirect", "to", "after", "logging", "in", ".", "Note", "that", "URLs", "passed", "explicitly", "(", "e", ".", "g", ".", "by", "passing", "along", "a", "next", "GET", "parameter", ")", "take", "precedence", "ove...
f70cb3d622f992f15fe9b57098e0b328445b664e
https://github.com/pennersr/django-allauth/blob/f70cb3d622f992f15fe9b57098e0b328445b664e/allauth/account/adapter.py#L139-L153
train
pennersr/django-allauth
allauth/account/adapter.py
DefaultAccountAdapter.get_email_confirmation_redirect_url
def get_email_confirmation_redirect_url(self, request): """ The URL to return to after successful e-mail confirmation. """ if request.user.is_authenticated: if app_settings.EMAIL_CONFIRMATION_AUTHENTICATED_REDIRECT_URL: return \ app_settin...
python
def get_email_confirmation_redirect_url(self, request): """ The URL to return to after successful e-mail confirmation. """ if request.user.is_authenticated: if app_settings.EMAIL_CONFIRMATION_AUTHENTICATED_REDIRECT_URL: return \ app_settin...
[ "def", "get_email_confirmation_redirect_url", "(", "self", ",", "request", ")", ":", "if", "request", ".", "user", ".", "is_authenticated", ":", "if", "app_settings", ".", "EMAIL_CONFIRMATION_AUTHENTICATED_REDIRECT_URL", ":", "return", "app_settings", ".", "EMAIL_CONFIR...
The URL to return to after successful e-mail confirmation.
[ "The", "URL", "to", "return", "to", "after", "successful", "e", "-", "mail", "confirmation", "." ]
f70cb3d622f992f15fe9b57098e0b328445b664e
https://github.com/pennersr/django-allauth/blob/f70cb3d622f992f15fe9b57098e0b328445b664e/allauth/account/adapter.py#L164-L175
train
pennersr/django-allauth
allauth/account/adapter.py
DefaultAccountAdapter.populate_username
def populate_username(self, request, user): """ Fills in a valid username, if required and missing. If the username is already present it is assumed to be valid (unique). """ from .utils import user_username, user_email, user_field first_name = user_field(user, '...
python
def populate_username(self, request, user): """ Fills in a valid username, if required and missing. If the username is already present it is assumed to be valid (unique). """ from .utils import user_username, user_email, user_field first_name = user_field(user, '...
[ "def", "populate_username", "(", "self", ",", "request", ",", "user", ")", ":", "from", ".", "utils", "import", "user_username", ",", "user_email", ",", "user_field", "first_name", "=", "user_field", "(", "user", ",", "'first_name'", ")", "last_name", "=", "...
Fills in a valid username, if required and missing. If the username is already present it is assumed to be valid (unique).
[ "Fills", "in", "a", "valid", "username", "if", "required", "and", "missing", ".", "If", "the", "username", "is", "already", "present", "it", "is", "assumed", "to", "be", "valid", "(", "unique", ")", "." ]
f70cb3d622f992f15fe9b57098e0b328445b664e
https://github.com/pennersr/django-allauth/blob/f70cb3d622f992f15fe9b57098e0b328445b664e/allauth/account/adapter.py#L193-L212
train
pennersr/django-allauth
allauth/account/adapter.py
DefaultAccountAdapter.save_user
def save_user(self, request, user, form, commit=True): """ Saves a new `User` instance using information provided in the signup form. """ from .utils import user_username, user_email, user_field data = form.cleaned_data first_name = data.get('first_name') ...
python
def save_user(self, request, user, form, commit=True): """ Saves a new `User` instance using information provided in the signup form. """ from .utils import user_username, user_email, user_field data = form.cleaned_data first_name = data.get('first_name') ...
[ "def", "save_user", "(", "self", ",", "request", ",", "user", ",", "form", ",", "commit", "=", "True", ")", ":", "from", ".", "utils", "import", "user_username", ",", "user_email", ",", "user_field", "data", "=", "form", ".", "cleaned_data", "first_name", ...
Saves a new `User` instance using information provided in the signup form.
[ "Saves", "a", "new", "User", "instance", "using", "information", "provided", "in", "the", "signup", "form", "." ]
f70cb3d622f992f15fe9b57098e0b328445b664e
https://github.com/pennersr/django-allauth/blob/f70cb3d622f992f15fe9b57098e0b328445b664e/allauth/account/adapter.py#L217-L244
train
pennersr/django-allauth
allauth/account/adapter.py
DefaultAccountAdapter.clean_username
def clean_username(self, username, shallow=False): """ Validates the username. You can hook into this if you want to (dynamically) restrict what usernames can be chosen. """ for validator in app_settings.USERNAME_VALIDATORS: validator(username) # TODO: Add re...
python
def clean_username(self, username, shallow=False): """ Validates the username. You can hook into this if you want to (dynamically) restrict what usernames can be chosen. """ for validator in app_settings.USERNAME_VALIDATORS: validator(username) # TODO: Add re...
[ "def", "clean_username", "(", "self", ",", "username", ",", "shallow", "=", "False", ")", ":", "for", "validator", "in", "app_settings", ".", "USERNAME_VALIDATORS", ":", "validator", "(", "username", ")", "# TODO: Add regexp support to USERNAME_BLACKLIST", "username_b...
Validates the username. You can hook into this if you want to (dynamically) restrict what usernames can be chosen.
[ "Validates", "the", "username", ".", "You", "can", "hook", "into", "this", "if", "you", "want", "to", "(", "dynamically", ")", "restrict", "what", "usernames", "can", "be", "chosen", "." ]
f70cb3d622f992f15fe9b57098e0b328445b664e
https://github.com/pennersr/django-allauth/blob/f70cb3d622f992f15fe9b57098e0b328445b664e/allauth/account/adapter.py#L246-L278
train
pennersr/django-allauth
allauth/account/adapter.py
DefaultAccountAdapter.clean_password
def clean_password(self, password, user=None): """ Validates a password. You can hook into this if you want to restric the allowed password choices. """ min_length = app_settings.PASSWORD_MIN_LENGTH if min_length and len(password) < min_length: raise forms.Val...
python
def clean_password(self, password, user=None): """ Validates a password. You can hook into this if you want to restric the allowed password choices. """ min_length = app_settings.PASSWORD_MIN_LENGTH if min_length and len(password) < min_length: raise forms.Val...
[ "def", "clean_password", "(", "self", ",", "password", ",", "user", "=", "None", ")", ":", "min_length", "=", "app_settings", ".", "PASSWORD_MIN_LENGTH", "if", "min_length", "and", "len", "(", "password", ")", "<", "min_length", ":", "raise", "forms", ".", ...
Validates a password. You can hook into this if you want to restric the allowed password choices.
[ "Validates", "a", "password", ".", "You", "can", "hook", "into", "this", "if", "you", "want", "to", "restric", "the", "allowed", "password", "choices", "." ]
f70cb3d622f992f15fe9b57098e0b328445b664e
https://github.com/pennersr/django-allauth/blob/f70cb3d622f992f15fe9b57098e0b328445b664e/allauth/account/adapter.py#L287-L297
train
pennersr/django-allauth
allauth/account/adapter.py
DefaultAccountAdapter.add_message
def add_message(self, request, level, message_template, message_context=None, extra_tags=''): """ Wrapper of `django.contrib.messages.add_message`, that reads the message text from a template. """ if 'django.contrib.messages' in settings.INSTALLED_APPS: ...
python
def add_message(self, request, level, message_template, message_context=None, extra_tags=''): """ Wrapper of `django.contrib.messages.add_message`, that reads the message text from a template. """ if 'django.contrib.messages' in settings.INSTALLED_APPS: ...
[ "def", "add_message", "(", "self", ",", "request", ",", "level", ",", "message_template", ",", "message_context", "=", "None", ",", "extra_tags", "=", "''", ")", ":", "if", "'django.contrib.messages'", "in", "settings", ".", "INSTALLED_APPS", ":", "try", ":", ...
Wrapper of `django.contrib.messages.add_message`, that reads the message text from a template.
[ "Wrapper", "of", "django", ".", "contrib", ".", "messages", ".", "add_message", "that", "reads", "the", "message", "text", "from", "a", "template", "." ]
f70cb3d622f992f15fe9b57098e0b328445b664e
https://github.com/pennersr/django-allauth/blob/f70cb3d622f992f15fe9b57098e0b328445b664e/allauth/account/adapter.py#L304-L320
train
pennersr/django-allauth
allauth/account/adapter.py
DefaultAccountAdapter.confirm_email
def confirm_email(self, request, email_address): """ Marks the email address as confirmed on the db """ email_address.verified = True email_address.set_as_primary(conditional=True) email_address.save()
python
def confirm_email(self, request, email_address): """ Marks the email address as confirmed on the db """ email_address.verified = True email_address.set_as_primary(conditional=True) email_address.save()
[ "def", "confirm_email", "(", "self", ",", "request", ",", "email_address", ")", ":", "email_address", ".", "verified", "=", "True", "email_address", ".", "set_as_primary", "(", "conditional", "=", "True", ")", "email_address", ".", "save", "(", ")" ]
Marks the email address as confirmed on the db
[ "Marks", "the", "email", "address", "as", "confirmed", "on", "the", "db" ]
f70cb3d622f992f15fe9b57098e0b328445b664e
https://github.com/pennersr/django-allauth/blob/f70cb3d622f992f15fe9b57098e0b328445b664e/allauth/account/adapter.py#L396-L402
train
pennersr/django-allauth
allauth/account/adapter.py
DefaultAccountAdapter.get_email_confirmation_url
def get_email_confirmation_url(self, request, emailconfirmation): """Constructs the email confirmation (activation) url. Note that if you have architected your system such that email confirmations are sent outside of the request context `request` can be `None` here. """ ...
python
def get_email_confirmation_url(self, request, emailconfirmation): """Constructs the email confirmation (activation) url. Note that if you have architected your system such that email confirmations are sent outside of the request context `request` can be `None` here. """ ...
[ "def", "get_email_confirmation_url", "(", "self", ",", "request", ",", "emailconfirmation", ")", ":", "url", "=", "reverse", "(", "\"account_confirm_email\"", ",", "args", "=", "[", "emailconfirmation", ".", "key", "]", ")", "ret", "=", "build_absolute_uri", "("...
Constructs the email confirmation (activation) url. Note that if you have architected your system such that email confirmations are sent outside of the request context `request` can be `None` here.
[ "Constructs", "the", "email", "confirmation", "(", "activation", ")", "url", "." ]
f70cb3d622f992f15fe9b57098e0b328445b664e
https://github.com/pennersr/django-allauth/blob/f70cb3d622f992f15fe9b57098e0b328445b664e/allauth/account/adapter.py#L418-L431
train
pennersr/django-allauth
allauth/account/adapter.py
DefaultAccountAdapter.authenticate
def authenticate(self, request, **credentials): """Only authenticates, does not actually login. See `login`""" from allauth.account.auth_backends import AuthenticationBackend self.pre_authenticate(request, **credentials) AuthenticationBackend.unstash_authenticated_user() user = ...
python
def authenticate(self, request, **credentials): """Only authenticates, does not actually login. See `login`""" from allauth.account.auth_backends import AuthenticationBackend self.pre_authenticate(request, **credentials) AuthenticationBackend.unstash_authenticated_user() user = ...
[ "def", "authenticate", "(", "self", ",", "request", ",", "*", "*", "credentials", ")", ":", "from", "allauth", ".", "account", ".", "auth_backends", "import", "AuthenticationBackend", "self", ".", "pre_authenticate", "(", "request", ",", "*", "*", "credentials...
Only authenticates, does not actually login. See `login`
[ "Only", "authenticates", "does", "not", "actually", "login", ".", "See", "login" ]
f70cb3d622f992f15fe9b57098e0b328445b664e
https://github.com/pennersr/django-allauth/blob/f70cb3d622f992f15fe9b57098e0b328445b664e/allauth/account/adapter.py#L483-L498
train
pennersr/django-allauth
allauth/socialaccount/providers/mailchimp/provider.py
MailChimpProvider.extract_common_fields
def extract_common_fields(self, data): """Extract fields from a metadata query.""" return dict( dc=data.get('dc'), role=data.get('role'), account_name=data.get('accountname'), user_id=data.get('user_id'), login=data.get('login'), lo...
python
def extract_common_fields(self, data): """Extract fields from a metadata query.""" return dict( dc=data.get('dc'), role=data.get('role'), account_name=data.get('accountname'), user_id=data.get('user_id'), login=data.get('login'), lo...
[ "def", "extract_common_fields", "(", "self", ",", "data", ")", ":", "return", "dict", "(", "dc", "=", "data", ".", "get", "(", "'dc'", ")", ",", "role", "=", "data", ".", "get", "(", "'role'", ")", ",", "account_name", "=", "data", ".", "get", "(",...
Extract fields from a metadata query.
[ "Extract", "fields", "from", "a", "metadata", "query", "." ]
f70cb3d622f992f15fe9b57098e0b328445b664e
https://github.com/pennersr/django-allauth/blob/f70cb3d622f992f15fe9b57098e0b328445b664e/allauth/socialaccount/providers/mailchimp/provider.py#L35-L45
train
pennersr/django-allauth
allauth/socialaccount/providers/linkedin/views.py
LinkedInAPI.to_dict
def to_dict(self, xml): """ Convert XML structure to dict recursively, repeated keys entries are returned as in list containers. """ children = list(xml) if not children: return xml.text else: out = {} for node in list(xml): ...
python
def to_dict(self, xml): """ Convert XML structure to dict recursively, repeated keys entries are returned as in list containers. """ children = list(xml) if not children: return xml.text else: out = {} for node in list(xml): ...
[ "def", "to_dict", "(", "self", ",", "xml", ")", ":", "children", "=", "list", "(", "xml", ")", "if", "not", "children", ":", "return", "xml", ".", "text", "else", ":", "out", "=", "{", "}", "for", "node", "in", "list", "(", "xml", ")", ":", "if...
Convert XML structure to dict recursively, repeated keys entries are returned as in list containers.
[ "Convert", "XML", "structure", "to", "dict", "recursively", "repeated", "keys", "entries", "are", "returned", "as", "in", "list", "containers", "." ]
f70cb3d622f992f15fe9b57098e0b328445b664e
https://github.com/pennersr/django-allauth/blob/f70cb3d622f992f15fe9b57098e0b328445b664e/allauth/socialaccount/providers/linkedin/views.py#L32-L49
train
pennersr/django-allauth
allauth/socialaccount/templatetags/socialaccount.py
provider_login_url
def provider_login_url(parser, token): """ {% provider_login_url "facebook" next=bla %} {% provider_login_url "openid" openid="http://me.yahoo.com" next=bla %} """ bits = token.split_contents() provider_id = bits[1] params = token_kwargs(bits[2:], parser, support_legacy=False) return Pro...
python
def provider_login_url(parser, token): """ {% provider_login_url "facebook" next=bla %} {% provider_login_url "openid" openid="http://me.yahoo.com" next=bla %} """ bits = token.split_contents() provider_id = bits[1] params = token_kwargs(bits[2:], parser, support_legacy=False) return Pro...
[ "def", "provider_login_url", "(", "parser", ",", "token", ")", ":", "bits", "=", "token", ".", "split_contents", "(", ")", "provider_id", "=", "bits", "[", "1", "]", "params", "=", "token_kwargs", "(", "bits", "[", "2", ":", "]", ",", "parser", ",", ...
{% provider_login_url "facebook" next=bla %} {% provider_login_url "openid" openid="http://me.yahoo.com" next=bla %}
[ "{", "%", "provider_login_url", "facebook", "next", "=", "bla", "%", "}", "{", "%", "provider_login_url", "openid", "openid", "=", "http", ":", "//", "me", ".", "yahoo", ".", "com", "next", "=", "bla", "%", "}" ]
f70cb3d622f992f15fe9b57098e0b328445b664e
https://github.com/pennersr/django-allauth/blob/f70cb3d622f992f15fe9b57098e0b328445b664e/allauth/socialaccount/templatetags/socialaccount.py#L43-L51
train
pennersr/django-allauth
allauth/socialaccount/templatetags/socialaccount.py
get_social_accounts
def get_social_accounts(user): """ {% get_social_accounts user as accounts %} Then: {{accounts.twitter}} -- a list of connected Twitter accounts {{accounts.twitter.0}} -- the first Twitter account {% if accounts %} -- if there is at least one social account """ accounts = {}...
python
def get_social_accounts(user): """ {% get_social_accounts user as accounts %} Then: {{accounts.twitter}} -- a list of connected Twitter accounts {{accounts.twitter.0}} -- the first Twitter account {% if accounts %} -- if there is at least one social account """ accounts = {}...
[ "def", "get_social_accounts", "(", "user", ")", ":", "accounts", "=", "{", "}", "for", "account", "in", "user", ".", "socialaccount_set", ".", "all", "(", ")", ".", "iterator", "(", ")", ":", "providers", "=", "accounts", ".", "setdefault", "(", "account...
{% get_social_accounts user as accounts %} Then: {{accounts.twitter}} -- a list of connected Twitter accounts {{accounts.twitter.0}} -- the first Twitter account {% if accounts %} -- if there is at least one social account
[ "{", "%", "get_social_accounts", "user", "as", "accounts", "%", "}" ]
f70cb3d622f992f15fe9b57098e0b328445b664e
https://github.com/pennersr/django-allauth/blob/f70cb3d622f992f15fe9b57098e0b328445b664e/allauth/socialaccount/templatetags/socialaccount.py#L68-L81
train
pennersr/django-allauth
allauth/socialaccount/adapter.py
DefaultSocialAccountAdapter.save_user
def save_user(self, request, sociallogin, form=None): """ Saves a newly signed up social login. In case of auto-signup, the signup form is not available. """ u = sociallogin.user u.set_unusable_password() if form: get_account_adapter().save_user(reques...
python
def save_user(self, request, sociallogin, form=None): """ Saves a newly signed up social login. In case of auto-signup, the signup form is not available. """ u = sociallogin.user u.set_unusable_password() if form: get_account_adapter().save_user(reques...
[ "def", "save_user", "(", "self", ",", "request", ",", "sociallogin", ",", "form", "=", "None", ")", ":", "u", "=", "sociallogin", ".", "user", "u", ".", "set_unusable_password", "(", ")", "if", "form", ":", "get_account_adapter", "(", ")", ".", "save_use...
Saves a newly signed up social login. In case of auto-signup, the signup form is not available.
[ "Saves", "a", "newly", "signed", "up", "social", "login", ".", "In", "case", "of", "auto", "-", "signup", "the", "signup", "form", "is", "not", "available", "." ]
f70cb3d622f992f15fe9b57098e0b328445b664e
https://github.com/pennersr/django-allauth/blob/f70cb3d622f992f15fe9b57098e0b328445b664e/allauth/socialaccount/adapter.py#L71-L83
train
pennersr/django-allauth
allauth/socialaccount/adapter.py
DefaultSocialAccountAdapter.populate_user
def populate_user(self, request, sociallogin, data): """ Hook that can be used to further populate the user instance. For convenience, we populate several common fields. Note that the user instance being populated repres...
python
def populate_user(self, request, sociallogin, data): """ Hook that can be used to further populate the user instance. For convenience, we populate several common fields. Note that the user instance being populated repres...
[ "def", "populate_user", "(", "self", ",", "request", ",", "sociallogin", ",", "data", ")", ":", "username", "=", "data", ".", "get", "(", "'username'", ")", "first_name", "=", "data", ".", "get", "(", "'first_name'", ")", "last_name", "=", "data", ".", ...
Hook that can be used to further populate the user instance. For convenience, we populate several common fields. Note that the user instance being populated represents a suggested User instance that represents the social user that is in the process of being logged in. The User...
[ "Hook", "that", "can", "be", "used", "to", "further", "populate", "the", "user", "instance", "." ]
f70cb3d622f992f15fe9b57098e0b328445b664e
https://github.com/pennersr/django-allauth/blob/f70cb3d622f992f15fe9b57098e0b328445b664e/allauth/socialaccount/adapter.py#L85-L113
train
pennersr/django-allauth
allauth/socialaccount/adapter.py
DefaultSocialAccountAdapter.get_connect_redirect_url
def get_connect_redirect_url(self, request, socialaccount): """ Returns the default URL to redirect to after successfully connecting a social account. """ assert request.user.is_authenticated url = reverse('socialaccount_connections') return url
python
def get_connect_redirect_url(self, request, socialaccount): """ Returns the default URL to redirect to after successfully connecting a social account. """ assert request.user.is_authenticated url = reverse('socialaccount_connections') return url
[ "def", "get_connect_redirect_url", "(", "self", ",", "request", ",", "socialaccount", ")", ":", "assert", "request", ".", "user", ".", "is_authenticated", "url", "=", "reverse", "(", "'socialaccount_connections'", ")", "return", "url" ]
Returns the default URL to redirect to after successfully connecting a social account.
[ "Returns", "the", "default", "URL", "to", "redirect", "to", "after", "successfully", "connecting", "a", "social", "account", "." ]
f70cb3d622f992f15fe9b57098e0b328445b664e
https://github.com/pennersr/django-allauth/blob/f70cb3d622f992f15fe9b57098e0b328445b664e/allauth/socialaccount/adapter.py#L115-L122
train
pennersr/django-allauth
allauth/socialaccount/adapter.py
DefaultSocialAccountAdapter.validate_disconnect
def validate_disconnect(self, account, accounts): """ Validate whether or not the socialaccount account can be safely disconnected. """ if len(accounts) == 1: # No usable password would render the local account unusable if not account.user.has_usable_passw...
python
def validate_disconnect(self, account, accounts): """ Validate whether or not the socialaccount account can be safely disconnected. """ if len(accounts) == 1: # No usable password would render the local account unusable if not account.user.has_usable_passw...
[ "def", "validate_disconnect", "(", "self", ",", "account", ",", "accounts", ")", ":", "if", "len", "(", "accounts", ")", "==", "1", ":", "# No usable password would render the local account unusable", "if", "not", "account", ".", "user", ".", "has_usable_password", ...
Validate whether or not the socialaccount account can be safely disconnected.
[ "Validate", "whether", "or", "not", "the", "socialaccount", "account", "can", "be", "safely", "disconnected", "." ]
f70cb3d622f992f15fe9b57098e0b328445b664e
https://github.com/pennersr/django-allauth/blob/f70cb3d622f992f15fe9b57098e0b328445b664e/allauth/socialaccount/adapter.py#L124-L140
train
pennersr/django-allauth
allauth/utils.py
serialize_instance
def serialize_instance(instance): """ Since Django 1.6 items added to the session are no longer pickled, but JSON encoded by default. We are storing partially complete models in the session (user, account, token, ...). We cannot use standard Django serialization, as these are models are not "complet...
python
def serialize_instance(instance): """ Since Django 1.6 items added to the session are no longer pickled, but JSON encoded by default. We are storing partially complete models in the session (user, account, token, ...). We cannot use standard Django serialization, as these are models are not "complet...
[ "def", "serialize_instance", "(", "instance", ")", ":", "data", "=", "{", "}", "for", "k", ",", "v", "in", "instance", ".", "__dict__", ".", "items", "(", ")", ":", "if", "k", ".", "startswith", "(", "'_'", ")", "or", "callable", "(", "v", ")", "...
Since Django 1.6 items added to the session are no longer pickled, but JSON encoded by default. We are storing partially complete models in the session (user, account, token, ...). We cannot use standard Django serialization, as these are models are not "complete" yet. Serialization will start complaini...
[ "Since", "Django", "1", ".", "6", "items", "added", "to", "the", "session", "are", "no", "longer", "pickled", "but", "JSON", "encoded", "by", "default", ".", "We", "are", "storing", "partially", "complete", "models", "in", "the", "session", "(", "user", ...
f70cb3d622f992f15fe9b57098e0b328445b664e
https://github.com/pennersr/django-allauth/blob/f70cb3d622f992f15fe9b57098e0b328445b664e/allauth/utils.py#L167-L196
train
pennersr/django-allauth
allauth/utils.py
set_form_field_order
def set_form_field_order(form, field_order): """ This function is a verbatim copy of django.forms.Form.order_fields() to support field ordering below Django 1.9. field_order is a list of field names specifying the order. Append fields not included in the list in the default order for backward compa...
python
def set_form_field_order(form, field_order): """ This function is a verbatim copy of django.forms.Form.order_fields() to support field ordering below Django 1.9. field_order is a list of field names specifying the order. Append fields not included in the list in the default order for backward compa...
[ "def", "set_form_field_order", "(", "form", ",", "field_order", ")", ":", "if", "field_order", "is", "None", ":", "return", "fields", "=", "OrderedDict", "(", ")", "for", "key", "in", "field_order", ":", "try", ":", "fields", "[", "key", "]", "=", "form"...
This function is a verbatim copy of django.forms.Form.order_fields() to support field ordering below Django 1.9. field_order is a list of field names specifying the order. Append fields not included in the list in the default order for backward compatibility with subclasses not overriding field_order. ...
[ "This", "function", "is", "a", "verbatim", "copy", "of", "django", ".", "forms", ".", "Form", ".", "order_fields", "()", "to", "support", "field", "ordering", "below", "Django", "1", ".", "9", "." ]
f70cb3d622f992f15fe9b57098e0b328445b664e
https://github.com/pennersr/django-allauth/blob/f70cb3d622f992f15fe9b57098e0b328445b664e/allauth/utils.py#L235-L256
train
pennersr/django-allauth
allauth/utils.py
build_absolute_uri
def build_absolute_uri(request, location, protocol=None): """request.build_absolute_uri() helper Like request.build_absolute_uri, but gracefully handling the case where request is None. """ from .account import app_settings as account_settings if request is None: site = Site.objects.ge...
python
def build_absolute_uri(request, location, protocol=None): """request.build_absolute_uri() helper Like request.build_absolute_uri, but gracefully handling the case where request is None. """ from .account import app_settings as account_settings if request is None: site = Site.objects.ge...
[ "def", "build_absolute_uri", "(", "request", ",", "location", ",", "protocol", "=", "None", ")", ":", "from", ".", "account", "import", "app_settings", "as", "account_settings", "if", "request", "is", "None", ":", "site", "=", "Site", ".", "objects", ".", ...
request.build_absolute_uri() helper Like request.build_absolute_uri, but gracefully handling the case where request is None.
[ "request", ".", "build_absolute_uri", "()", "helper" ]
f70cb3d622f992f15fe9b57098e0b328445b664e
https://github.com/pennersr/django-allauth/blob/f70cb3d622f992f15fe9b57098e0b328445b664e/allauth/utils.py#L259-L291
train
pennersr/django-allauth
allauth/account/forms.py
_base_signup_form_class
def _base_signup_form_class(): """ Currently, we inherit from the custom form, if any. This is all not very elegant, though it serves a purpose: - There are two signup forms: one for local accounts, and one for social accounts - Both share a common base (BaseSignupForm) - Given the above...
python
def _base_signup_form_class(): """ Currently, we inherit from the custom form, if any. This is all not very elegant, though it serves a purpose: - There are two signup forms: one for local accounts, and one for social accounts - Both share a common base (BaseSignupForm) - Given the above...
[ "def", "_base_signup_form_class", "(", ")", ":", "if", "not", "app_settings", ".", "SIGNUP_FORM_CLASS", ":", "return", "_DummyCustomSignupForm", "try", ":", "fc_module", ",", "fc_classname", "=", "app_settings", ".", "SIGNUP_FORM_CLASS", ".", "rsplit", "(", "'.'", ...
Currently, we inherit from the custom form, if any. This is all not very elegant, though it serves a purpose: - There are two signup forms: one for local accounts, and one for social accounts - Both share a common base (BaseSignupForm) - Given the above, how to put in a custom signup form? Which...
[ "Currently", "we", "inherit", "from", "the", "custom", "form", "if", "any", ".", "This", "is", "all", "not", "very", "elegant", "though", "it", "serves", "a", "purpose", ":" ]
f70cb3d622f992f15fe9b57098e0b328445b664e
https://github.com/pennersr/django-allauth/blob/f70cb3d622f992f15fe9b57098e0b328445b664e/allauth/account/forms.py#L219-L258
train
pennersr/django-allauth
allauth/account/forms.py
LoginForm.user_credentials
def user_credentials(self): """ Provides the credentials required to authenticate the user for login. """ credentials = {} login = self.cleaned_data["login"] if app_settings.AUTHENTICATION_METHOD == AuthenticationMethod.EMAIL: credentials["email"] = lo...
python
def user_credentials(self): """ Provides the credentials required to authenticate the user for login. """ credentials = {} login = self.cleaned_data["login"] if app_settings.AUTHENTICATION_METHOD == AuthenticationMethod.EMAIL: credentials["email"] = lo...
[ "def", "user_credentials", "(", "self", ")", ":", "credentials", "=", "{", "}", "login", "=", "self", ".", "cleaned_data", "[", "\"login\"", "]", "if", "app_settings", ".", "AUTHENTICATION_METHOD", "==", "AuthenticationMethod", ".", "EMAIL", ":", "credentials", ...
Provides the credentials required to authenticate the user for login.
[ "Provides", "the", "credentials", "required", "to", "authenticate", "the", "user", "for", "login", "." ]
f70cb3d622f992f15fe9b57098e0b328445b664e
https://github.com/pennersr/django-allauth/blob/f70cb3d622f992f15fe9b57098e0b328445b664e/allauth/account/forms.py#L142-L160
train
pennersr/django-allauth
allauth/socialaccount/providers/facebook/locale.py
_build_locale_table
def _build_locale_table(filename_or_file): """ Parses the FacebookLocales.xml file and builds a dict relating every available language ('en, 'es, 'zh', ...) with a list of available regions for that language ('en' -> 'US', 'EN') and an (arbitrary) default region. """ # Require the XML parser mod...
python
def _build_locale_table(filename_or_file): """ Parses the FacebookLocales.xml file and builds a dict relating every available language ('en, 'es, 'zh', ...) with a list of available regions for that language ('en' -> 'US', 'EN') and an (arbitrary) default region. """ # Require the XML parser mod...
[ "def", "_build_locale_table", "(", "filename_or_file", ")", ":", "# Require the XML parser module only if we want the default mapping", "from", "xml", ".", "dom", ".", "minidom", "import", "parse", "dom", "=", "parse", "(", "filename_or_file", ")", "reps", "=", "dom", ...
Parses the FacebookLocales.xml file and builds a dict relating every available language ('en, 'es, 'zh', ...) with a list of available regions for that language ('en' -> 'US', 'EN') and an (arbitrary) default region.
[ "Parses", "the", "FacebookLocales", ".", "xml", "file", "and", "builds", "a", "dict", "relating", "every", "available", "language", "(", "en", "es", "zh", "...", ")", "with", "a", "list", "of", "available", "regions", "for", "that", "language", "(", "en", ...
f70cb3d622f992f15fe9b57098e0b328445b664e
https://github.com/pennersr/django-allauth/blob/f70cb3d622f992f15fe9b57098e0b328445b664e/allauth/socialaccount/providers/facebook/locale.py#L9-L37
train
pennersr/django-allauth
allauth/socialaccount/providers/facebook/locale.py
get_default_locale_callable
def get_default_locale_callable(): """ Wrapper function so that the default mapping is only built when needed """ exec_dir = os.path.dirname(os.path.realpath(__file__)) xml_path = os.path.join(exec_dir, 'data', 'FacebookLocales.xml') fb_locales = _build_locale_table(xml_path) def default_l...
python
def get_default_locale_callable(): """ Wrapper function so that the default mapping is only built when needed """ exec_dir = os.path.dirname(os.path.realpath(__file__)) xml_path = os.path.join(exec_dir, 'data', 'FacebookLocales.xml') fb_locales = _build_locale_table(xml_path) def default_l...
[ "def", "get_default_locale_callable", "(", ")", ":", "exec_dir", "=", "os", ".", "path", ".", "dirname", "(", "os", ".", "path", ".", "realpath", "(", "__file__", ")", ")", "xml_path", "=", "os", ".", "path", ".", "join", "(", "exec_dir", ",", "'data'"...
Wrapper function so that the default mapping is only built when needed
[ "Wrapper", "function", "so", "that", "the", "default", "mapping", "is", "only", "built", "when", "needed" ]
f70cb3d622f992f15fe9b57098e0b328445b664e
https://github.com/pennersr/django-allauth/blob/f70cb3d622f992f15fe9b57098e0b328445b664e/allauth/socialaccount/providers/facebook/locale.py#L40-L70
train
pennersr/django-allauth
allauth/socialaccount/app_settings.py
AppSettings.EMAIL_REQUIRED
def EMAIL_REQUIRED(self): """ The user is required to hand over an e-mail address when signing up """ from allauth.account import app_settings as account_settings return self._setting("EMAIL_REQUIRED", account_settings.EMAIL_REQUIRED)
python
def EMAIL_REQUIRED(self): """ The user is required to hand over an e-mail address when signing up """ from allauth.account import app_settings as account_settings return self._setting("EMAIL_REQUIRED", account_settings.EMAIL_REQUIRED)
[ "def", "EMAIL_REQUIRED", "(", "self", ")", ":", "from", "allauth", ".", "account", "import", "app_settings", "as", "account_settings", "return", "self", ".", "_setting", "(", "\"EMAIL_REQUIRED\"", ",", "account_settings", ".", "EMAIL_REQUIRED", ")" ]
The user is required to hand over an e-mail address when signing up
[ "The", "user", "is", "required", "to", "hand", "over", "an", "e", "-", "mail", "address", "when", "signing", "up" ]
f70cb3d622f992f15fe9b57098e0b328445b664e
https://github.com/pennersr/django-allauth/blob/f70cb3d622f992f15fe9b57098e0b328445b664e/allauth/socialaccount/app_settings.py#L40-L45
train
pennersr/django-allauth
allauth/socialaccount/app_settings.py
AppSettings.EMAIL_VERIFICATION
def EMAIL_VERIFICATION(self): """ See e-mail verification method """ from allauth.account import app_settings as account_settings return self._setting("EMAIL_VERIFICATION", account_settings.EMAIL_VERIFICATION)
python
def EMAIL_VERIFICATION(self): """ See e-mail verification method """ from allauth.account import app_settings as account_settings return self._setting("EMAIL_VERIFICATION", account_settings.EMAIL_VERIFICATION)
[ "def", "EMAIL_VERIFICATION", "(", "self", ")", ":", "from", "allauth", ".", "account", "import", "app_settings", "as", "account_settings", "return", "self", ".", "_setting", "(", "\"EMAIL_VERIFICATION\"", ",", "account_settings", ".", "EMAIL_VERIFICATION", ")" ]
See e-mail verification method
[ "See", "e", "-", "mail", "verification", "method" ]
f70cb3d622f992f15fe9b57098e0b328445b664e
https://github.com/pennersr/django-allauth/blob/f70cb3d622f992f15fe9b57098e0b328445b664e/allauth/socialaccount/app_settings.py#L48-L54
train
pennersr/django-allauth
allauth/socialaccount/providers/dataporten/provider.py
DataportenAccount.to_str
def to_str(self): ''' Returns string representation of a social account. Includes the name of the user. ''' dflt = super(DataportenAccount, self).to_str() return '%s (%s)' % ( self.account.extra_data.get('name', ''), dflt, )
python
def to_str(self): ''' Returns string representation of a social account. Includes the name of the user. ''' dflt = super(DataportenAccount, self).to_str() return '%s (%s)' % ( self.account.extra_data.get('name', ''), dflt, )
[ "def", "to_str", "(", "self", ")", ":", "dflt", "=", "super", "(", "DataportenAccount", ",", "self", ")", ".", "to_str", "(", ")", "return", "'%s (%s)'", "%", "(", "self", ".", "account", ".", "extra_data", ".", "get", "(", "'name'", ",", "''", ")", ...
Returns string representation of a social account. Includes the name of the user.
[ "Returns", "string", "representation", "of", "a", "social", "account", ".", "Includes", "the", "name", "of", "the", "user", "." ]
f70cb3d622f992f15fe9b57098e0b328445b664e
https://github.com/pennersr/django-allauth/blob/f70cb3d622f992f15fe9b57098e0b328445b664e/allauth/socialaccount/providers/dataporten/provider.py#L15-L24
train