Search is not available for this dataset
identifier stringlengths 1 155 | parameters stringlengths 2 6.09k | docstring stringlengths 11 63.4k | docstring_summary stringlengths 0 63.4k | function stringlengths 29 99.8k | function_tokens list | start_point list | end_point list | language stringclasses 1
value | docstring_language stringlengths 2 7 | docstring_language_predictions stringlengths 18 23 | is_langid_reliable stringclasses 2
values |
|---|---|---|---|---|---|---|---|---|---|---|---|
_SixMetaPathImporter.get_code | (self, fullname) | Return None
Required, if is_package is implemented | Return None | def get_code(self, fullname):
"""Return None
Required, if is_package is implemented"""
self.__get_module(fullname) # eventually raises ImportError
return None | [
"def",
"get_code",
"(",
"self",
",",
"fullname",
")",
":",
"self",
".",
"__get_module",
"(",
"fullname",
")",
"# eventually raises ImportError",
"return",
"None"
] | [
217,
4
] | [
222,
19
] | python | en | ['en', 'co', 'en'] | False |
SingleObjectMixin.get_object | (self, queryset=None) |
Return the object the view is displaying.
Require `self.queryset` and a `pk` or `slug` argument in the URLconf.
Subclasses can override this to return any object.
|
Return the object the view is displaying. | def get_object(self, queryset=None):
"""
Return the object the view is displaying.
Require `self.queryset` and a `pk` or `slug` argument in the URLconf.
Subclasses can override this to return any object.
"""
# Use a custom queryset if provided; this is required for subcl... | [
"def",
"get_object",
"(",
"self",
",",
"queryset",
"=",
"None",
")",
":",
"# Use a custom queryset if provided; this is required for subclasses",
"# like DateDetailView",
"if",
"queryset",
"is",
"None",
":",
"queryset",
"=",
"self",
".",
"get_queryset",
"(",
")",
"# N... | [
19,
4
] | [
55,
18
] | python | en | ['en', 'error', 'th'] | False |
SingleObjectMixin.get_queryset | (self) |
Return the `QuerySet` that will be used to look up the object.
This method is called by the default implementation of get_object() and
may not be called if get_object() is overridden.
|
Return the `QuerySet` that will be used to look up the object. | def get_queryset(self):
"""
Return the `QuerySet` that will be used to look up the object.
This method is called by the default implementation of get_object() and
may not be called if get_object() is overridden.
"""
if self.queryset is None:
if self.model:
... | [
"def",
"get_queryset",
"(",
"self",
")",
":",
"if",
"self",
".",
"queryset",
"is",
"None",
":",
"if",
"self",
".",
"model",
":",
"return",
"self",
".",
"model",
".",
"_default_manager",
".",
"all",
"(",
")",
"else",
":",
"raise",
"ImproperlyConfigured",
... | [
57,
4
] | [
75,
34
] | python | en | ['en', 'error', 'th'] | False |
SingleObjectMixin.get_slug_field | (self) | Get the name of a slug field to be used to look up by slug. | Get the name of a slug field to be used to look up by slug. | def get_slug_field(self):
"""Get the name of a slug field to be used to look up by slug."""
return self.slug_field | [
"def",
"get_slug_field",
"(",
"self",
")",
":",
"return",
"self",
".",
"slug_field"
] | [
77,
4
] | [
79,
30
] | python | en | ['en', 'en', 'en'] | True |
SingleObjectMixin.get_context_object_name | (self, obj) | Get the name to use for the object. | Get the name to use for the object. | def get_context_object_name(self, obj):
"""Get the name to use for the object."""
if self.context_object_name:
return self.context_object_name
elif isinstance(obj, models.Model):
return obj._meta.model_name
else:
return None | [
"def",
"get_context_object_name",
"(",
"self",
",",
"obj",
")",
":",
"if",
"self",
".",
"context_object_name",
":",
"return",
"self",
".",
"context_object_name",
"elif",
"isinstance",
"(",
"obj",
",",
"models",
".",
"Model",
")",
":",
"return",
"obj",
".",
... | [
81,
4
] | [
88,
23
] | python | en | ['en', 'en', 'en'] | True |
SingleObjectMixin.get_context_data | (self, **kwargs) | Insert the single object into the context dict. | Insert the single object into the context dict. | def get_context_data(self, **kwargs):
"""Insert the single object into the context dict."""
context = {}
if self.object:
context['object'] = self.object
context_object_name = self.get_context_object_name(self.object)
if context_object_name:
con... | [
"def",
"get_context_data",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"context",
"=",
"{",
"}",
"if",
"self",
".",
"object",
":",
"context",
"[",
"'object'",
"]",
"=",
"self",
".",
"object",
"context_object_name",
"=",
"self",
".",
"get_context_obje... | [
90,
4
] | [
99,
50
] | python | en | ['en', 'en', 'en'] | True |
SingleObjectTemplateResponseMixin.get_template_names | (self) |
Return a list of template names to be used for the request. May not be
called if render_to_response() is overridden. Return the following list:
* the value of ``template_name`` on the view (if provided)
* the contents of the ``template_name_field`` field on the
object instanc... |
Return a list of template names to be used for the request. May not be
called if render_to_response() is overridden. Return the following list: | def get_template_names(self):
"""
Return a list of template names to be used for the request. May not be
called if render_to_response() is overridden. Return the following list:
* the value of ``template_name`` on the view (if provided)
* the contents of the ``template_name_fiel... | [
"def",
"get_template_names",
"(",
"self",
")",
":",
"try",
":",
"names",
"=",
"super",
"(",
")",
".",
"get_template_names",
"(",
")",
"except",
"ImproperlyConfigured",
":",
"# If template_name isn't specified, it's not a problem --",
"# we just start with an empty list.",
... | [
114,
4
] | [
160,
20
] | python | en | ['en', 'error', 'th'] | False |
bytes_to_text | (s, encoding) |
Convert bytes objects to strings, using the given encoding. Illegally
encoded input characters are replaced with Unicode "unknown" codepoint
(\ufffd).
Return any non-bytes objects without change.
|
Convert bytes objects to strings, using the given encoding. Illegally
encoded input characters are replaced with Unicode "unknown" codepoint
(\ufffd). | def bytes_to_text(s, encoding):
"""
Convert bytes objects to strings, using the given encoding. Illegally
encoded input characters are replaced with Unicode "unknown" codepoint
(\ufffd).
Return any non-bytes objects without change.
"""
if isinstance(s, bytes):
return str(s, encoding... | [
"def",
"bytes_to_text",
"(",
"s",
",",
"encoding",
")",
":",
"if",
"isinstance",
"(",
"s",
",",
"bytes",
")",
":",
"return",
"str",
"(",
"s",
",",
"encoding",
",",
"'replace'",
")",
"else",
":",
"return",
"s"
] | [
639,
0
] | [
650,
16
] | python | en | ['en', 'error', 'th'] | False |
split_domain_port | (host) |
Return a (domain, port) tuple from a given host.
Returned domain is lowercased. If the host is invalid, the domain will be
empty.
|
Return a (domain, port) tuple from a given host. | def split_domain_port(host):
"""
Return a (domain, port) tuple from a given host.
Returned domain is lowercased. If the host is invalid, the domain will be
empty.
"""
host = host.lower()
if not host_validation_re.match(host):
return '', ''
if host[-1] == ']':
# It's an... | [
"def",
"split_domain_port",
"(",
"host",
")",
":",
"host",
"=",
"host",
".",
"lower",
"(",
")",
"if",
"not",
"host_validation_re",
".",
"match",
"(",
"host",
")",
":",
"return",
"''",
",",
"''",
"if",
"host",
"[",
"-",
"1",
"]",
"==",
"']'",
":",
... | [
653,
0
] | [
672,
23
] | python | en | ['en', 'error', 'th'] | False |
validate_host | (host, allowed_hosts) |
Validate the given host for this site.
Check that the host looks valid and matches a host or host pattern in the
given list of ``allowed_hosts``. Any pattern beginning with a period
matches a domain and all its subdomains (e.g. ``.example.com`` matches
``example.com`` and any subdomain), ``*`` mat... |
Validate the given host for this site. | def validate_host(host, allowed_hosts):
"""
Validate the given host for this site.
Check that the host looks valid and matches a host or host pattern in the
given list of ``allowed_hosts``. Any pattern beginning with a period
matches a domain and all its subdomains (e.g. ``.example.com`` matches
... | [
"def",
"validate_host",
"(",
"host",
",",
"allowed_hosts",
")",
":",
"return",
"any",
"(",
"pattern",
"==",
"'*'",
"or",
"is_same_domain",
"(",
"host",
",",
"pattern",
")",
"for",
"pattern",
"in",
"allowed_hosts",
")"
] | [
675,
0
] | [
690,
92
] | python | en | ['en', 'error', 'th'] | False |
HttpRequest.accepted_types | (self) | Return a list of MediaType instances. | Return a list of MediaType instances. | def accepted_types(self):
"""Return a list of MediaType instances."""
return parse_accept_header(self.headers.get('Accept', '*/*')) | [
"def",
"accepted_types",
"(",
"self",
")",
":",
"return",
"parse_accept_header",
"(",
"self",
".",
"headers",
".",
"get",
"(",
"'Accept'",
",",
"'*/*'",
")",
")"
] | [
90,
4
] | [
92,
69
] | python | en | ['en', 'en', 'en'] | True |
HttpRequest._set_content_type_params | (self, meta) | Set content_type, content_params, and encoding. | Set content_type, content_params, and encoding. | def _set_content_type_params(self, meta):
"""Set content_type, content_params, and encoding."""
self.content_type, self.content_params = cgi.parse_header(meta.get('CONTENT_TYPE', ''))
if 'charset' in self.content_params:
try:
codecs.lookup(self.content_params['charset... | [
"def",
"_set_content_type_params",
"(",
"self",
",",
"meta",
")",
":",
"self",
".",
"content_type",
",",
"self",
".",
"content_params",
"=",
"cgi",
".",
"parse_header",
"(",
"meta",
".",
"get",
"(",
"'CONTENT_TYPE'",
",",
"''",
")",
")",
"if",
"'charset'",... | [
100,
4
] | [
109,
62
] | python | en | ['en', 'en', 'en'] | True |
HttpRequest._get_raw_host | (self) |
Return the HTTP host using the environment or request headers. Skip
allowed hosts protection, so may return an insecure host.
|
Return the HTTP host using the environment or request headers. Skip
allowed hosts protection, so may return an insecure host.
| def _get_raw_host(self):
"""
Return the HTTP host using the environment or request headers. Skip
allowed hosts protection, so may return an insecure host.
"""
# We try three options, in order of decreasing preference.
if settings.USE_X_FORWARDED_HOST and (
... | [
"def",
"_get_raw_host",
"(",
"self",
")",
":",
"# We try three options, in order of decreasing preference.",
"if",
"settings",
".",
"USE_X_FORWARDED_HOST",
"and",
"(",
"'HTTP_X_FORWARDED_HOST'",
"in",
"self",
".",
"META",
")",
":",
"host",
"=",
"self",
".",
"META",
... | [
111,
4
] | [
128,
19
] | python | en | ['en', 'error', 'th'] | False |
HttpRequest.get_host | (self) | Return the HTTP host using the environment or request headers. | Return the HTTP host using the environment or request headers. | def get_host(self):
"""Return the HTTP host using the environment or request headers."""
host = self._get_raw_host()
# Allow variants of localhost if ALLOWED_HOSTS is empty and DEBUG=True.
allowed_hosts = settings.ALLOWED_HOSTS
if settings.DEBUG and not allowed_hosts:
... | [
"def",
"get_host",
"(",
"self",
")",
":",
"host",
"=",
"self",
".",
"_get_raw_host",
"(",
")",
"# Allow variants of localhost if ALLOWED_HOSTS is empty and DEBUG=True.",
"allowed_hosts",
"=",
"settings",
".",
"ALLOWED_HOSTS",
"if",
"settings",
".",
"DEBUG",
"and",
"no... | [
130,
4
] | [
148,
37
] | python | en | ['en', 'en', 'en'] | True |
HttpRequest.get_port | (self) | Return the port number for the request as a string. | Return the port number for the request as a string. | def get_port(self):
"""Return the port number for the request as a string."""
if settings.USE_X_FORWARDED_PORT and 'HTTP_X_FORWARDED_PORT' in self.META:
port = self.META['HTTP_X_FORWARDED_PORT']
else:
port = self.META['SERVER_PORT']
return str(port) | [
"def",
"get_port",
"(",
"self",
")",
":",
"if",
"settings",
".",
"USE_X_FORWARDED_PORT",
"and",
"'HTTP_X_FORWARDED_PORT'",
"in",
"self",
".",
"META",
":",
"port",
"=",
"self",
".",
"META",
"[",
"'HTTP_X_FORWARDED_PORT'",
"]",
"else",
":",
"port",
"=",
"self"... | [
150,
4
] | [
156,
24
] | python | en | ['en', 'en', 'en'] | True |
HttpRequest.get_signed_cookie | (self, key, default=RAISE_ERROR, salt='', max_age=None) |
Attempt to return a signed cookie. If the signature fails or the
cookie has expired, raise an exception, unless the `default` argument
is provided, in which case return that value.
|
Attempt to return a signed cookie. If the signature fails or the
cookie has expired, raise an exception, unless the `default` argument
is provided, in which case return that value.
| def get_signed_cookie(self, key, default=RAISE_ERROR, salt='', max_age=None):
"""
Attempt to return a signed cookie. If the signature fails or the
cookie has expired, raise an exception, unless the `default` argument
is provided, in which case return that value.
"""
try:... | [
"def",
"get_signed_cookie",
"(",
"self",
",",
"key",
",",
"default",
"=",
"RAISE_ERROR",
",",
"salt",
"=",
"''",
",",
"max_age",
"=",
"None",
")",
":",
"try",
":",
"cookie_value",
"=",
"self",
".",
"COOKIES",
"[",
"key",
"]",
"except",
"KeyError",
":",... | [
173,
4
] | [
194,
20
] | python | en | ['en', 'error', 'th'] | False |
HttpRequest.get_raw_uri | (self) |
Return an absolute URI from variables available in this request. Skip
allowed hosts protection, so may return insecure URI.
|
Return an absolute URI from variables available in this request. Skip
allowed hosts protection, so may return insecure URI.
| def get_raw_uri(self):
"""
Return an absolute URI from variables available in this request. Skip
allowed hosts protection, so may return insecure URI.
"""
return '{scheme}://{host}{path}'.format(
scheme=self.scheme,
host=self._get_raw_host(),
p... | [
"def",
"get_raw_uri",
"(",
"self",
")",
":",
"return",
"'{scheme}://{host}{path}'",
".",
"format",
"(",
"scheme",
"=",
"self",
".",
"scheme",
",",
"host",
"=",
"self",
".",
"_get_raw_host",
"(",
")",
",",
"path",
"=",
"self",
".",
"get_full_path",
"(",
"... | [
196,
4
] | [
205,
9
] | python | en | ['en', 'error', 'th'] | False |
HttpRequest.build_absolute_uri | (self, location=None) |
Build an absolute URI from the location and the variables available in
this request. If no ``location`` is specified, build the absolute URI
using request.get_full_path(). If the location is absolute, convert it
to an RFC 3987 compliant URI and return it. If location is relative or
... |
Build an absolute URI from the location and the variables available in
this request. If no ``location`` is specified, build the absolute URI
using request.get_full_path(). If the location is absolute, convert it
to an RFC 3987 compliant URI and return it. If location is relative or
... | def build_absolute_uri(self, location=None):
"""
Build an absolute URI from the location and the variables available in
this request. If no ``location`` is specified, build the absolute URI
using request.get_full_path(). If the location is absolute, convert it
to an RFC 3987 comp... | [
"def",
"build_absolute_uri",
"(",
"self",
",",
"location",
"=",
"None",
")",
":",
"if",
"location",
"is",
"None",
":",
"# Make it an absolute url (but schemeless and domainless) for the",
"# edge case that the path starts with '//'.",
"location",
"=",
"'//%s'",
"%",
"self",... | [
207,
4
] | [
241,
35
] | python | en | ['en', 'error', 'th'] | False |
HttpRequest._get_scheme | (self) |
Hook for subclasses like WSGIRequest to implement. Return 'http' by
default.
|
Hook for subclasses like WSGIRequest to implement. Return 'http' by
default.
| def _get_scheme(self):
"""
Hook for subclasses like WSGIRequest to implement. Return 'http' by
default.
"""
return 'http' | [
"def",
"_get_scheme",
"(",
"self",
")",
":",
"return",
"'http'"
] | [
247,
4
] | [
252,
21
] | python | en | ['en', 'error', 'th'] | False |
HttpRequest.encoding | (self, val) |
Set the encoding used for GET/POST accesses. If the GET or POST
dictionary has already been created, remove and recreate it on the
next access (so that it is decoded correctly).
|
Set the encoding used for GET/POST accesses. If the GET or POST
dictionary has already been created, remove and recreate it on the
next access (so that it is decoded correctly).
| def encoding(self, val):
"""
Set the encoding used for GET/POST accesses. If the GET or POST
dictionary has already been created, remove and recreate it on the
next access (so that it is decoded correctly).
"""
self._encoding = val
if hasattr(self, 'GET'):
... | [
"def",
"encoding",
"(",
"self",
",",
"val",
")",
":",
"self",
".",
"_encoding",
"=",
"val",
"if",
"hasattr",
"(",
"self",
",",
"'GET'",
")",
":",
"del",
"self",
".",
"GET",
"if",
"hasattr",
"(",
"self",
",",
"'_post'",
")",
":",
"del",
"self",
".... | [
285,
4
] | [
295,
26
] | python | en | ['en', 'error', 'th'] | False |
HttpRequest.parse_file_upload | (self, META, post_data) | Return a tuple of (POST QueryDict, FILES MultiValueDict). | Return a tuple of (POST QueryDict, FILES MultiValueDict). | def parse_file_upload(self, META, post_data):
"""Return a tuple of (POST QueryDict, FILES MultiValueDict)."""
self.upload_handlers = ImmutableList(
self.upload_handlers,
warning="You cannot alter upload handlers after the upload has been processed."
)
parser = Mul... | [
"def",
"parse_file_upload",
"(",
"self",
",",
"META",
",",
"post_data",
")",
":",
"self",
".",
"upload_handlers",
"=",
"ImmutableList",
"(",
"self",
".",
"upload_handlers",
",",
"warning",
"=",
"\"You cannot alter upload handlers after the upload has been processed.\"",
... | [
314,
4
] | [
321,
29
] | python | en | ['en', 'la', 'en'] | True |
HttpRequest._load_post_and_files | (self) | Populate self._post and self._files if the content-type is a form type | Populate self._post and self._files if the content-type is a form type | def _load_post_and_files(self):
"""Populate self._post and self._files if the content-type is a form type"""
if self.method != 'POST':
self._post, self._files = QueryDict(encoding=self._encoding), MultiValueDict()
return
if self._read_started and not hasattr(self, '_body'... | [
"def",
"_load_post_and_files",
"(",
"self",
")",
":",
"if",
"self",
".",
"method",
"!=",
"'POST'",
":",
"self",
".",
"_post",
",",
"self",
".",
"_files",
"=",
"QueryDict",
"(",
"encoding",
"=",
"self",
".",
"_encoding",
")",
",",
"MultiValueDict",
"(",
... | [
345,
4
] | [
372,
90
] | python | en | ['en', 'en', 'en'] | True |
HttpHeaders.__getitem__ | (self, key) | Allow header lookup using underscores in place of hyphens. | Allow header lookup using underscores in place of hyphens. | def __getitem__(self, key):
"""Allow header lookup using underscores in place of hyphens."""
return super().__getitem__(key.replace('_', '-')) | [
"def",
"__getitem__",
"(",
"self",
",",
"key",
")",
":",
"return",
"super",
"(",
")",
".",
"__getitem__",
"(",
"key",
".",
"replace",
"(",
"'_'",
",",
"'-'",
")",
")"
] | [
421,
4
] | [
423,
57
] | python | en | ['en', 'en', 'en'] | True |
QueryDict.fromkeys | (cls, iterable, value='', mutable=False, encoding=None) |
Return a new QueryDict with keys (may be repeated) from an iterable and
values from value.
|
Return a new QueryDict with keys (may be repeated) from an iterable and
values from value.
| def fromkeys(cls, iterable, value='', mutable=False, encoding=None):
"""
Return a new QueryDict with keys (may be repeated) from an iterable and
values from value.
"""
q = cls('', mutable=True, encoding=encoding)
for key in iterable:
q.appendlist(key, value)
... | [
"def",
"fromkeys",
"(",
"cls",
",",
"iterable",
",",
"value",
"=",
"''",
",",
"mutable",
"=",
"False",
",",
"encoding",
"=",
"None",
")",
":",
"q",
"=",
"cls",
"(",
"''",
",",
"mutable",
"=",
"True",
",",
"encoding",
"=",
"encoding",
")",
"for",
... | [
485,
4
] | [
495,
16
] | python | en | ['en', 'error', 'th'] | False |
QueryDict.copy | (self) | Return a mutable copy of this object. | Return a mutable copy of this object. | def copy(self):
"""Return a mutable copy of this object."""
return self.__deepcopy__({}) | [
"def",
"copy",
"(",
"self",
")",
":",
"return",
"self",
".",
"__deepcopy__",
"(",
"{",
"}",
")"
] | [
568,
4
] | [
570,
36
] | python | en | ['en', 'en', 'en'] | True |
QueryDict.urlencode | (self, safe=None) |
Return an encoded string of all query string arguments.
`safe` specifies characters which don't require quoting, for example::
>>> q = QueryDict(mutable=True)
>>> q['next'] = '/a&b/'
>>> q.urlencode()
'next=%2Fa%26b%2F'
>>> q.urlencode(safe=... |
Return an encoded string of all query string arguments. | def urlencode(self, safe=None):
"""
Return an encoded string of all query string arguments.
`safe` specifies characters which don't require quoting, for example::
>>> q = QueryDict(mutable=True)
>>> q['next'] = '/a&b/'
>>> q.urlencode()
'next=%2F... | [
"def",
"urlencode",
"(",
"self",
",",
"safe",
"=",
"None",
")",
":",
"output",
"=",
"[",
"]",
"if",
"safe",
":",
"safe",
"=",
"safe",
".",
"encode",
"(",
"self",
".",
"encoding",
")",
"def",
"encode",
"(",
"k",
",",
"v",
")",
":",
"return",
"'%... | [
572,
4
] | [
599,
31
] | python | en | ['en', 'error', 'th'] | False |
register_range | (pgrange, pyrange, conn_or_curs, globally=False) | Create and register an adapter and the typecasters to convert between
a PostgreSQL |range|_ type and a PostgreSQL `Range` subclass.
:param pgrange: the name of the PostgreSQL |range| type. Can be
schema-qualified
:param pyrange: a `Range` strict subclass, or just a name to give to a new
cla... | Create and register an adapter and the typecasters to convert between
a PostgreSQL |range|_ type and a PostgreSQL `Range` subclass. | def register_range(pgrange, pyrange, conn_or_curs, globally=False):
"""Create and register an adapter and the typecasters to convert between
a PostgreSQL |range|_ type and a PostgreSQL `Range` subclass.
:param pgrange: the name of the PostgreSQL |range| type. Can be
schema-qualified
:param pyra... | [
"def",
"register_range",
"(",
"pgrange",
",",
"pyrange",
",",
"conn_or_curs",
",",
"globally",
"=",
"False",
")",
":",
"caster",
"=",
"RangeCaster",
".",
"_from_db",
"(",
"pgrange",
",",
"pyrange",
",",
"conn_or_curs",
")",
"caster",
".",
"_register",
"(",
... | [
209,
0
] | [
237,
17
] | python | en | ['en', 'en', 'en'] | True |
Range.lower | (self) | The lower bound of the range. `!None` if empty or unbound. | The lower bound of the range. `!None` if empty or unbound. | def lower(self):
"""The lower bound of the range. `!None` if empty or unbound."""
return self._lower | [
"def",
"lower",
"(",
"self",
")",
":",
"return",
"self",
".",
"_lower"
] | [
78,
4
] | [
80,
26
] | python | en | ['en', 'en', 'en'] | True |
Range.upper | (self) | The upper bound of the range. `!None` if empty or unbound. | The upper bound of the range. `!None` if empty or unbound. | def upper(self):
"""The upper bound of the range. `!None` if empty or unbound."""
return self._upper | [
"def",
"upper",
"(",
"self",
")",
":",
"return",
"self",
".",
"_upper"
] | [
83,
4
] | [
85,
26
] | python | en | ['en', 'en', 'en'] | True |
Range.isempty | (self) | `!True` if the range is empty. | `!True` if the range is empty. | def isempty(self):
"""`!True` if the range is empty."""
return self._bounds is None | [
"def",
"isempty",
"(",
"self",
")",
":",
"return",
"self",
".",
"_bounds",
"is",
"None"
] | [
88,
4
] | [
90,
35
] | python | en | ['en', 'sr', 'en'] | True |
Range.lower_inf | (self) | `!True` if the range doesn't have a lower bound. | `!True` if the range doesn't have a lower bound. | def lower_inf(self):
"""`!True` if the range doesn't have a lower bound."""
if self._bounds is None:
return False
return self._lower is None | [
"def",
"lower_inf",
"(",
"self",
")",
":",
"if",
"self",
".",
"_bounds",
"is",
"None",
":",
"return",
"False",
"return",
"self",
".",
"_lower",
"is",
"None"
] | [
93,
4
] | [
97,
34
] | python | en | ['en', 'en', 'en'] | True |
Range.upper_inf | (self) | `!True` if the range doesn't have an upper bound. | `!True` if the range doesn't have an upper bound. | def upper_inf(self):
"""`!True` if the range doesn't have an upper bound."""
if self._bounds is None:
return False
return self._upper is None | [
"def",
"upper_inf",
"(",
"self",
")",
":",
"if",
"self",
".",
"_bounds",
"is",
"None",
":",
"return",
"False",
"return",
"self",
".",
"_upper",
"is",
"None"
] | [
100,
4
] | [
104,
34
] | python | en | ['en', 'en', 'en'] | True |
Range.lower_inc | (self) | `!True` if the lower bound is included in the range. | `!True` if the lower bound is included in the range. | def lower_inc(self):
"""`!True` if the lower bound is included in the range."""
if self._bounds is None or self._lower is None:
return False
return self._bounds[0] == '[' | [
"def",
"lower_inc",
"(",
"self",
")",
":",
"if",
"self",
".",
"_bounds",
"is",
"None",
"or",
"self",
".",
"_lower",
"is",
"None",
":",
"return",
"False",
"return",
"self",
".",
"_bounds",
"[",
"0",
"]",
"==",
"'['"
] | [
107,
4
] | [
111,
37
] | python | en | ['en', 'en', 'en'] | True |
Range.upper_inc | (self) | `!True` if the upper bound is included in the range. | `!True` if the upper bound is included in the range. | def upper_inc(self):
"""`!True` if the upper bound is included in the range."""
if self._bounds is None or self._upper is None:
return False
return self._bounds[1] == ']' | [
"def",
"upper_inc",
"(",
"self",
")",
":",
"if",
"self",
".",
"_bounds",
"is",
"None",
"or",
"self",
".",
"_upper",
"is",
"None",
":",
"return",
"False",
"return",
"self",
".",
"_bounds",
"[",
"1",
"]",
"==",
"']'"
] | [
114,
4
] | [
118,
37
] | python | en | ['en', 'en', 'en'] | True |
RangeCaster._create_ranges | (self, pgrange, pyrange) | Create Range and RangeAdapter classes if needed. | Create Range and RangeAdapter classes if needed. | def _create_ranges(self, pgrange, pyrange):
"""Create Range and RangeAdapter classes if needed."""
# if got a string create a new RangeAdapter concrete type (with a name)
# else take it as an adapter. Passing an adapter should be considered
# an implementation detail and is not documente... | [
"def",
"_create_ranges",
"(",
"self",
",",
"pgrange",
",",
"pyrange",
")",
":",
"# if got a string create a new RangeAdapter concrete type (with a name)",
"# else take it as an adapter. Passing an adapter should be considered",
"# an implementation detail and is not documented. It is current... | [
309,
4
] | [
342,
68
] | python | en | ['en', 'sn', 'en'] | True |
RangeCaster._from_db | (self, name, pyrange, conn_or_curs) | Return a `RangeCaster` instance for the type *pgrange*.
Raise `ProgrammingError` if the type is not found.
| Return a `RangeCaster` instance for the type *pgrange*. | def _from_db(self, name, pyrange, conn_or_curs):
"""Return a `RangeCaster` instance for the type *pgrange*.
Raise `ProgrammingError` if the type is not found.
"""
from psycopg2.extensions import STATUS_IN_TRANSACTION
from psycopg2.extras import _solve_conn_curs
conn, cur... | [
"def",
"_from_db",
"(",
"self",
",",
"name",
",",
"pyrange",
",",
"conn_or_curs",
")",
":",
"from",
"psycopg2",
".",
"extensions",
"import",
"STATUS_IN_TRANSACTION",
"from",
"psycopg2",
".",
"extras",
"import",
"_solve_conn_curs",
"conn",
",",
"curs",
"=",
"_s... | [
345,
4
] | [
398,
59
] | python | en | ['en', 'no', 'en'] | True |
csrf_exempt | (view_func) | Mark a view function as being exempt from the CSRF view protection. | Mark a view function as being exempt from the CSRF view protection. | def csrf_exempt(view_func):
"""Mark a view function as being exempt from the CSRF view protection."""
# view_func.csrf_exempt = True would also work, but decorators are nicer
# if they don't have side effects, so return a new function.
def wrapped_view(*args, **kwargs):
return view_func(*args, *... | [
"def",
"csrf_exempt",
"(",
"view_func",
")",
":",
"# view_func.csrf_exempt = True would also work, but decorators are nicer",
"# if they don't have side effects, so return a new function.",
"def",
"wrapped_view",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
... | [
48,
0
] | [
55,
41
] | python | en | ['en', 'en', 'en'] | True |
get_current_site | (request) |
Check if contrib.sites is installed and return either the current
``Site`` object or a ``RequestSite`` object based on the request.
|
Check if contrib.sites is installed and return either the current
``Site`` object or a ``RequestSite`` object based on the request.
| def get_current_site(request):
"""
Check if contrib.sites is installed and return either the current
``Site`` object or a ``RequestSite`` object based on the request.
"""
# Imports are inside the function because its point is to avoid importing
# the Site models when django.contrib.sites isn't i... | [
"def",
"get_current_site",
"(",
"request",
")",
":",
"# Imports are inside the function because its point is to avoid importing",
"# the Site models when django.contrib.sites isn't installed.",
"if",
"apps",
".",
"is_installed",
"(",
"'django.contrib.sites'",
")",
":",
"from",
".",... | [
3,
0
] | [
15,
35
] | python | en | ['en', 'error', 'th'] | False |
scaled_dot_product_attention | (q, k, v) | Calculate the attention weights.
q, k, v must have matching leading dimensions.
k, v must have matching penultimate dimension, i.e.: seq_len_k = seq_len_v.
The mask has different shapes depending on its type(padding or look ahead)
but it must be broadcastable for addition.
Args:
q: query shape ... | Calculate the attention weights.
q, k, v must have matching leading dimensions.
k, v must have matching penultimate dimension, i.e.: seq_len_k = seq_len_v.
The mask has different shapes depending on its type(padding or look ahead)
but it must be broadcastable for addition. | def scaled_dot_product_attention(q, k, v):
"""Calculate the attention weights.
q, k, v must have matching leading dimensions.
k, v must have matching penultimate dimension, i.e.: seq_len_k = seq_len_v.
The mask has different shapes depending on its type(padding or look ahead)
but it must be broadcas... | [
"def",
"scaled_dot_product_attention",
"(",
"q",
",",
"k",
",",
"v",
")",
":",
"matmul_qk",
"=",
"tf",
".",
"matmul",
"(",
"q",
",",
"k",
",",
"transpose_b",
"=",
"True",
")",
"# (..., seq_len_q, seq_len_k)",
"# scale matmul_qk",
"dk",
"=",
"tf",
".",
"cas... | [
58,
0
] | [
88,
36
] | python | en | ['en', 'en', 'en'] | True |
SelfAttention.__init__ | (self, d_model, spatial_dims, positional_encoding=True, name="self_attention") |
d_model : number of output channels
spatial_dim : spatial dimensions of input tensor (x , y)
if positional_encoding: depth must correspond to input channel number
adapted from: https://www.tensorflow.org/tutorials/text/transformer
|
d_model : number of output channels
spatial_dim : spatial dimensions of input tensor (x , y)
if positional_encoding: depth must correspond to input channel number
adapted from: https://www.tensorflow.org/tutorials/text/transformer
| def __init__(self, d_model, spatial_dims, positional_encoding=True, name="self_attention"):
'''
d_model : number of output channels
spatial_dim : spatial dimensions of input tensor (x , y)
if positional_encoding: depth must correspond to input channel number
adapt... | [
"def",
"__init__",
"(",
"self",
",",
"d_model",
",",
"spatial_dims",
",",
"positional_encoding",
"=",
"True",
",",
"name",
"=",
"\"self_attention\"",
")",
":",
"super",
"(",
")",
".",
"__init__",
"(",
"name",
"=",
"name",
")",
"self",
".",
"d_model",
"="... | [
6,
4
] | [
22,
90
] | python | en | ['en', 'error', 'th'] | False |
SelfAttention.call | (self, x) |
x : tensor with shape (batch_size, y, x, channels)
|
x : tensor with shape (batch_size, y, x, channels)
| def call(self, x):
'''
x : tensor with shape (batch_size, y, x, channels)
'''
shape = tf.shape(x)
batch_size = shape[0]
#spatial_dims = shape[1:-1]
#spatial_dim = tf.reduce_prod(spatial_dims)
depth_dim = shape[3]
if self.positional_encoding:
... | [
"def",
"call",
"(",
"self",
",",
"x",
")",
":",
"shape",
"=",
"tf",
".",
"shape",
"(",
"x",
")",
"batch_size",
"=",
"shape",
"[",
"0",
"]",
"#spatial_dims = shape[1:-1]",
"#spatial_dim = tf.reduce_prod(spatial_dims)",
"depth_dim",
"=",
"shape",
"[",
"3",
"]"... | [
24,
4
] | [
53,
40
] | python | en | ['en', 'error', 'th'] | False |
MigrationRecorder.Migration | (cls) |
Lazy load to avoid AppRegistryNotReady if installed apps import
MigrationRecorder.
|
Lazy load to avoid AppRegistryNotReady if installed apps import
MigrationRecorder.
| def Migration(cls):
"""
Lazy load to avoid AppRegistryNotReady if installed apps import
MigrationRecorder.
"""
if cls._migration_class is None:
class Migration(models.Model):
app = models.CharField(max_length=255)
name = models.CharFiel... | [
"def",
"Migration",
"(",
"cls",
")",
":",
"if",
"cls",
".",
"_migration_class",
"is",
"None",
":",
"class",
"Migration",
"(",
"models",
".",
"Model",
")",
":",
"app",
"=",
"models",
".",
"CharField",
"(",
"max_length",
"=",
"255",
")",
"name",
"=",
"... | [
23,
4
] | [
43,
35
] | python | en | ['en', 'error', 'th'] | False |
MigrationRecorder.has_table | (self) | Return True if the django_migrations table exists. | Return True if the django_migrations table exists. | def has_table(self):
"""Return True if the django_migrations table exists."""
with self.connection.cursor() as cursor:
tables = self.connection.introspection.table_names(cursor)
return self.Migration._meta.db_table in tables | [
"def",
"has_table",
"(",
"self",
")",
":",
"with",
"self",
".",
"connection",
".",
"cursor",
"(",
")",
"as",
"cursor",
":",
"tables",
"=",
"self",
".",
"connection",
".",
"introspection",
".",
"table_names",
"(",
"cursor",
")",
"return",
"self",
".",
"... | [
52,
4
] | [
56,
54
] | python | en | ['en', 'ca', 'en'] | True |
MigrationRecorder.ensure_schema | (self) | Ensure the table exists and has the correct schema. | Ensure the table exists and has the correct schema. | def ensure_schema(self):
"""Ensure the table exists and has the correct schema."""
# If the table's there, that's fine - we've never changed its schema
# in the codebase.
if self.has_table():
return
# Make the table
try:
with self.connection.schema... | [
"def",
"ensure_schema",
"(",
"self",
")",
":",
"# If the table's there, that's fine - we've never changed its schema",
"# in the codebase.",
"if",
"self",
".",
"has_table",
"(",
")",
":",
"return",
"# Make the table",
"try",
":",
"with",
"self",
".",
"connection",
".",
... | [
58,
4
] | [
69,
99
] | python | en | ['en', 'en', 'en'] | True |
MigrationRecorder.applied_migrations | (self) |
Return a dict mapping (app_name, migration_name) to Migration instances
for all applied migrations.
|
Return a dict mapping (app_name, migration_name) to Migration instances
for all applied migrations.
| def applied_migrations(self):
"""
Return a dict mapping (app_name, migration_name) to Migration instances
for all applied migrations.
"""
if self.has_table():
return {(migration.app, migration.name): migration for migration in self.migration_qs}
else:
... | [
"def",
"applied_migrations",
"(",
"self",
")",
":",
"if",
"self",
".",
"has_table",
"(",
")",
":",
"return",
"{",
"(",
"migration",
".",
"app",
",",
"migration",
".",
"name",
")",
":",
"migration",
"for",
"migration",
"in",
"self",
".",
"migration_qs",
... | [
71,
4
] | [
81,
21
] | python | en | ['en', 'error', 'th'] | False |
MigrationRecorder.record_applied | (self, app, name) | Record that a migration was applied. | Record that a migration was applied. | def record_applied(self, app, name):
"""Record that a migration was applied."""
self.ensure_schema()
self.migration_qs.create(app=app, name=name) | [
"def",
"record_applied",
"(",
"self",
",",
"app",
",",
"name",
")",
":",
"self",
".",
"ensure_schema",
"(",
")",
"self",
".",
"migration_qs",
".",
"create",
"(",
"app",
"=",
"app",
",",
"name",
"=",
"name",
")"
] | [
83,
4
] | [
86,
52
] | python | en | ['en', 'en', 'en'] | True |
MigrationRecorder.record_unapplied | (self, app, name) | Record that a migration was unapplied. | Record that a migration was unapplied. | def record_unapplied(self, app, name):
"""Record that a migration was unapplied."""
self.ensure_schema()
self.migration_qs.filter(app=app, name=name).delete() | [
"def",
"record_unapplied",
"(",
"self",
",",
"app",
",",
"name",
")",
":",
"self",
".",
"ensure_schema",
"(",
")",
"self",
".",
"migration_qs",
".",
"filter",
"(",
"app",
"=",
"app",
",",
"name",
"=",
"name",
")",
".",
"delete",
"(",
")"
] | [
88,
4
] | [
91,
61
] | python | en | ['en', 'en', 'en'] | True |
MigrationRecorder.flush | (self) | Delete all migration records. Useful for testing migrations. | Delete all migration records. Useful for testing migrations. | def flush(self):
"""Delete all migration records. Useful for testing migrations."""
self.migration_qs.all().delete() | [
"def",
"flush",
"(",
"self",
")",
":",
"self",
".",
"migration_qs",
".",
"all",
"(",
")",
".",
"delete",
"(",
")"
] | [
93,
4
] | [
95,
40
] | python | en | ['en', 'en', 'en'] | True |
command_randomnumber | (bot, user, channel, args) | Prints a random number. | Prints a random number. | def command_randomnumber(bot, user, channel, args):
"Prints a random number."
return bot.say(channel, "5") | [
"def",
"command_randomnumber",
"(",
"bot",
",",
"user",
",",
"channel",
",",
"args",
")",
":",
"return",
"bot",
".",
"say",
"(",
"channel",
",",
"\"5\"",
")"
] | [
3,
0
] | [
5,
32
] | python | en | ['en', 'ca', 'en'] | True |
command_roll | (bot, user, channel, args) | Roll the dice! Usage: roll [<count>] [<sides>]. | Roll the dice! Usage: roll [<count>] [<sides>]. | def command_roll(bot, user, channel, args):
"Roll the dice! Usage: roll [<count>] [<sides>]."
if not args:
return bot.say(channel, "Usage: roll [<count>] [<sides>].")
args = args.split()
if len(args) > 2:
return
elif len(args) == 2:
count, sides = args[0], args[1]
else:... | [
"def",
"command_roll",
"(",
"bot",
",",
"user",
",",
"channel",
",",
"args",
")",
":",
"if",
"not",
"args",
":",
"return",
"bot",
".",
"say",
"(",
"channel",
",",
"\"Usage: roll [<count>] [<sides>].\"",
")",
"args",
"=",
"args",
".",
"split",
"(",
")",
... | [
8,
0
] | [
31,
52
] | python | en | ['en', 'en', 'en'] | True |
command_range | (bot, user, channel, args) | Returns a random number in a range. Usage: range <max>. | Returns a random number in a range. Usage: range <max>. | def command_range(bot, user, channel, args):
"Returns a random number in a range. Usage: range <max>."
if not args or not args.isdigit():
return bot.say(channel, "Usage: range <max>.")
return bot.say(channel, "{}".format(random.randrange(int(args)))) | [
"def",
"command_range",
"(",
"bot",
",",
"user",
",",
"channel",
",",
"args",
")",
":",
"if",
"not",
"args",
"or",
"not",
"args",
".",
"isdigit",
"(",
")",
":",
"return",
"bot",
".",
"say",
"(",
"channel",
",",
"\"Usage: range <max>.\"",
")",
"return",... | [
34,
0
] | [
40,
69
] | python | en | ['en', 'da', 'en'] | True |
command_8ball | (bot, user, channel, args) | Ask the magic 8ball anything and he will tell you what to do. | Ask the magic 8ball anything and he will tell you what to do. | def command_8ball(bot, user, channel, args):
"Ask the magic 8ball anything and he will tell you what to do."
phrases = ["It is certain", "It is decidedly so", "Without a doubt",
"Yes definitely", "You may rely on it", "As I see it, yes",
"Most likely", "Outlook good", "Signs poin... | [
"def",
"command_8ball",
"(",
"bot",
",",
"user",
",",
"channel",
",",
"args",
")",
":",
"phrases",
"=",
"[",
"\"It is certain\"",
",",
"\"It is decidedly so\"",
",",
"\"Without a doubt\"",
",",
"\"Yes definitely\"",
",",
"\"You may rely on it\"",
",",
"\"As I see it... | [
43,
0
] | [
56,
68
] | python | en | ['en', 'en', 'en'] | True |
command_cointoss | (bot, user, channel, args) | Flip a coin! | Flip a coin! | def command_cointoss(bot, user, channel, args):
"Flip a coin!"
if random.random() > 0.5:
bot.say(channel, "Heads!")
else:
bot.say(channel, "Tails!") | [
"def",
"command_cointoss",
"(",
"bot",
",",
"user",
",",
"channel",
",",
"args",
")",
":",
"if",
"random",
".",
"random",
"(",
")",
">",
"0.5",
":",
"bot",
".",
"say",
"(",
"channel",
",",
"\"Heads!\"",
")",
"else",
":",
"bot",
".",
"say",
"(",
"... | [
59,
0
] | [
64,
34
] | python | en | ['es', 'gl', 'en'] | False |
call | () | Responds to incoming calls using Twilio Add-ons | Responds to incoming calls using Twilio Add-ons | def call():
"""Responds to incoming calls using Twilio Add-ons"""
# Start our TwiML response
response = twiml.Response()
# Decode the JSON included in the 'AddOns' field
add_ons = json.loads(request.values['AddOns'])
# If the Whitepages add-on found nothing, return immediately
if 'whitepag... | [
"def",
"call",
"(",
")",
":",
"# Start our TwiML response",
"response",
"=",
"twiml",
".",
"Response",
"(",
")",
"# Decode the JSON included in the 'AddOns' field",
"add_ons",
"=",
"json",
".",
"loads",
"(",
"request",
".",
"values",
"[",
"'AddOns'",
"]",
")",
"... | [
9,
0
] | [
50,
24
] | python | en | ['en', 'en', 'en'] | True |
ScriptMaker._build_shebang | (self, executable, post_interp) |
Build a shebang line. In the simple case (on Windows, or a shebang line
which is not too long or contains spaces) use a simple formulation for
the shebang. Otherwise, use /bin/sh as the executable, with a contrived
shebang which allows the script to run either under Python or sh, using
... |
Build a shebang line. In the simple case (on Windows, or a shebang line
which is not too long or contains spaces) use a simple formulation for
the shebang. Otherwise, use /bin/sh as the executable, with a contrived
shebang which allows the script to run either under Python or sh, using
... | def _build_shebang(self, executable, post_interp):
"""
Build a shebang line. In the simple case (on Windows, or a shebang line
which is not too long or contains spaces) use a simple formulation for
the shebang. Otherwise, use /bin/sh as the executable, with a contrived
shebang wh... | [
"def",
"_build_shebang",
"(",
"self",
",",
"executable",
",",
"post_interp",
")",
":",
"if",
"os",
".",
"name",
"!=",
"'posix'",
":",
"simple_shebang",
"=",
"True",
"else",
":",
"# Add 3 for '#!' prefix and newline suffix.",
"shebang_length",
"=",
"len",
"(",
"e... | [
126,
4
] | [
155,
21
] | python | en | ['en', 'error', 'th'] | False |
ScriptMaker.make | (self, specification, options=None) |
Make a script.
:param specification: The specification, which is either a valid export
entry specification (to make a script from a
callable) or a filename (to make a script by
copying from a source location).
... |
Make a script. | def make(self, specification, options=None):
"""
Make a script.
:param specification: The specification, which is either a valid export
entry specification (to make a script from a
callable) or a filename (to make a script by
... | [
"def",
"make",
"(",
"self",
",",
"specification",
",",
"options",
"=",
"None",
")",
":",
"filenames",
"=",
"[",
"]",
"entry",
"=",
"get_export_entry",
"(",
"specification",
")",
"if",
"entry",
"is",
"None",
":",
"self",
".",
"_copy_script",
"(",
"specifi... | [
394,
4
] | [
411,
24
] | python | en | ['en', 'error', 'th'] | False |
ScriptMaker.make_multiple | (self, specifications, options=None) |
Take a list of specifications and make scripts from them,
:param specifications: A list of specifications.
:return: A list of all absolute pathnames written to,
|
Take a list of specifications and make scripts from them,
:param specifications: A list of specifications.
:return: A list of all absolute pathnames written to,
| def make_multiple(self, specifications, options=None):
"""
Take a list of specifications and make scripts from them,
:param specifications: A list of specifications.
:return: A list of all absolute pathnames written to,
"""
filenames = []
for specification in spec... | [
"def",
"make_multiple",
"(",
"self",
",",
"specifications",
",",
"options",
"=",
"None",
")",
":",
"filenames",
"=",
"[",
"]",
"for",
"specification",
"in",
"specifications",
":",
"filenames",
".",
"extend",
"(",
"self",
".",
"make",
"(",
"specification",
... | [
413,
4
] | [
422,
24
] | python | en | ['en', 'error', 'th'] | False |
Widget.format_value | (self, value) |
Return a value as it should appear when rendered in a template.
|
Return a value as it should appear when rendered in a template.
| def format_value(self, value):
"""
Return a value as it should appear when rendered in a template.
"""
if value == '' or value is None:
return None
if self.is_localized:
return formats.localize_input(value)
return str(value) | [
"def",
"format_value",
"(",
"self",
",",
"value",
")",
":",
"if",
"value",
"==",
"''",
"or",
"value",
"is",
"None",
":",
"return",
"None",
"if",
"self",
".",
"is_localized",
":",
"return",
"formats",
".",
"localize_input",
"(",
"value",
")",
"return",
... | [
221,
4
] | [
229,
25
] | python | en | ['en', 'error', 'th'] | False |
Widget.render | (self, name, value, attrs=None, renderer=None) | Render the widget as an HTML string. | Render the widget as an HTML string. | def render(self, name, value, attrs=None, renderer=None):
"""Render the widget as an HTML string."""
context = self.get_context(name, value, attrs)
return self._render(self.template_name, context, renderer) | [
"def",
"render",
"(",
"self",
",",
"name",
",",
"value",
",",
"attrs",
"=",
"None",
",",
"renderer",
"=",
"None",
")",
":",
"context",
"=",
"self",
".",
"get_context",
"(",
"name",
",",
"value",
",",
"attrs",
")",
"return",
"self",
".",
"_render",
... | [
243,
4
] | [
246,
66
] | python | en | ['en', 'lb', 'en'] | True |
Widget.build_attrs | (self, base_attrs, extra_attrs=None) | Build an attribute dictionary. | Build an attribute dictionary. | def build_attrs(self, base_attrs, extra_attrs=None):
"""Build an attribute dictionary."""
return {**base_attrs, **(extra_attrs or {})} | [
"def",
"build_attrs",
"(",
"self",
",",
"base_attrs",
",",
"extra_attrs",
"=",
"None",
")",
":",
"return",
"{",
"*",
"*",
"base_attrs",
",",
"*",
"*",
"(",
"extra_attrs",
"or",
"{",
"}",
")",
"}"
] | [
253,
4
] | [
255,
52
] | python | en | ['en', 'en', 'en'] | True |
Widget.value_from_datadict | (self, data, files, name) |
Given a dictionary of data and this widget's name, return the value
of this widget or None if it's not provided.
|
Given a dictionary of data and this widget's name, return the value
of this widget or None if it's not provided.
| def value_from_datadict(self, data, files, name):
"""
Given a dictionary of data and this widget's name, return the value
of this widget or None if it's not provided.
"""
return data.get(name) | [
"def",
"value_from_datadict",
"(",
"self",
",",
"data",
",",
"files",
",",
"name",
")",
":",
"return",
"data",
".",
"get",
"(",
"name",
")"
] | [
257,
4
] | [
262,
29
] | python | en | ['en', 'error', 'th'] | False |
Widget.id_for_label | (self, id_) |
Return the HTML ID attribute of this Widget for use by a <label>,
given the ID of the field. Return None if no ID is available.
This hook is necessary because some widgets have multiple HTML
elements and, thus, multiple IDs. In that case, this method should
return an ID value t... |
Return the HTML ID attribute of this Widget for use by a <label>,
given the ID of the field. Return None if no ID is available. | def id_for_label(self, id_):
"""
Return the HTML ID attribute of this Widget for use by a <label>,
given the ID of the field. Return None if no ID is available.
This hook is necessary because some widgets have multiple HTML
elements and, thus, multiple IDs. In that case, this me... | [
"def",
"id_for_label",
"(",
"self",
",",
"id_",
")",
":",
"return",
"id_"
] | [
267,
4
] | [
277,
18
] | python | en | ['en', 'error', 'th'] | False |
FileInput.format_value | (self, value) | File input never renders a value. | File input never renders a value. | def format_value(self, value):
"""File input never renders a value."""
return | [
"def",
"format_value",
"(",
"self",
",",
"value",
")",
":",
"return"
] | [
383,
4
] | [
385,
14
] | python | en | ['hu', 'en', 'en'] | True |
FileInput.value_from_datadict | (self, data, files, name) | File widgets take data from FILES, not POST | File widgets take data from FILES, not POST | def value_from_datadict(self, data, files, name):
"File widgets take data from FILES, not POST"
return files.get(name) | [
"def",
"value_from_datadict",
"(",
"self",
",",
"data",
",",
"files",
",",
"name",
")",
":",
"return",
"files",
".",
"get",
"(",
"name",
")"
] | [
387,
4
] | [
389,
30
] | python | en | ['en', 'en', 'en'] | True |
ClearableFileInput.clear_checkbox_name | (self, name) |
Given the name of the file input, return the name of the clear checkbox
input.
|
Given the name of the file input, return the name of the clear checkbox
input.
| def clear_checkbox_name(self, name):
"""
Given the name of the file input, return the name of the clear checkbox
input.
"""
return name + '-clear' | [
"def",
"clear_checkbox_name",
"(",
"self",
",",
"name",
")",
":",
"return",
"name",
"+",
"'-clear'"
] | [
407,
4
] | [
412,
30
] | python | en | ['en', 'error', 'th'] | False |
ClearableFileInput.clear_checkbox_id | (self, name) |
Given the name of the clear checkbox input, return the HTML id for it.
|
Given the name of the clear checkbox input, return the HTML id for it.
| def clear_checkbox_id(self, name):
"""
Given the name of the clear checkbox input, return the HTML id for it.
"""
return name + '_id' | [
"def",
"clear_checkbox_id",
"(",
"self",
",",
"name",
")",
":",
"return",
"name",
"+",
"'_id'"
] | [
414,
4
] | [
418,
27
] | python | en | ['en', 'error', 'th'] | False |
ClearableFileInput.is_initial | (self, value) |
Return whether value is considered to be initial value.
|
Return whether value is considered to be initial value.
| def is_initial(self, value):
"""
Return whether value is considered to be initial value.
"""
return bool(value and getattr(value, 'url', False)) | [
"def",
"is_initial",
"(",
"self",
",",
"value",
")",
":",
"return",
"bool",
"(",
"value",
"and",
"getattr",
"(",
"value",
",",
"'url'",
",",
"False",
")",
")"
] | [
420,
4
] | [
424,
59
] | python | en | ['en', 'error', 'th'] | False |
ClearableFileInput.format_value | (self, value) |
Return the file object if it has a defined url attribute.
|
Return the file object if it has a defined url attribute.
| def format_value(self, value):
"""
Return the file object if it has a defined url attribute.
"""
if self.is_initial(value):
return value | [
"def",
"format_value",
"(",
"self",
",",
"value",
")",
":",
"if",
"self",
".",
"is_initial",
"(",
"value",
")",
":",
"return",
"value"
] | [
426,
4
] | [
431,
24
] | python | en | ['en', 'error', 'th'] | False |
CheckboxInput.format_value | (self, value) | Only return the 'value' attribute if value isn't empty. | Only return the 'value' attribute if value isn't empty. | def format_value(self, value):
"""Only return the 'value' attribute if value isn't empty."""
if value is True or value is False or value is None or value == '':
return
return str(value) | [
"def",
"format_value",
"(",
"self",
",",
"value",
")",
":",
"if",
"value",
"is",
"True",
"or",
"value",
"is",
"False",
"or",
"value",
"is",
"None",
"or",
"value",
"==",
"''",
":",
"return",
"return",
"str",
"(",
"value",
")"
] | [
521,
4
] | [
525,
25
] | python | en | ['en', 'en', 'en'] | True |
ChoiceWidget.subwidgets | (self, name, value, attrs=None) |
Yield all "subwidgets" of this widget. Used to enable iterating
options from a BoundField for choice widgets.
|
Yield all "subwidgets" of this widget. Used to enable iterating
options from a BoundField for choice widgets.
| def subwidgets(self, name, value, attrs=None):
"""
Yield all "subwidgets" of this widget. Used to enable iterating
options from a BoundField for choice widgets.
"""
value = self.format_value(value)
yield from self.options(name, value, attrs) | [
"def",
"subwidgets",
"(",
"self",
",",
"name",
",",
"value",
",",
"attrs",
"=",
"None",
")",
":",
"value",
"=",
"self",
".",
"format_value",
"(",
"value",
")",
"yield",
"from",
"self",
".",
"options",
"(",
"name",
",",
"value",
",",
"attrs",
")"
] | [
573,
4
] | [
579,
51
] | python | en | ['en', 'error', 'th'] | False |
ChoiceWidget.options | (self, name, value, attrs=None) | Yield a flat list of options for this widgets. | Yield a flat list of options for this widgets. | def options(self, name, value, attrs=None):
"""Yield a flat list of options for this widgets."""
for group in self.optgroups(name, value, attrs):
yield from group[1] | [
"def",
"options",
"(",
"self",
",",
"name",
",",
"value",
",",
"attrs",
"=",
"None",
")",
":",
"for",
"group",
"in",
"self",
".",
"optgroups",
"(",
"name",
",",
"value",
",",
"attrs",
")",
":",
"yield",
"from",
"group",
"[",
"1",
"]"
] | [
581,
4
] | [
584,
31
] | python | en | ['en', 'en', 'en'] | True |
ChoiceWidget.optgroups | (self, name, value, attrs=None) | Return a list of optgroups for this widget. | Return a list of optgroups for this widget. | def optgroups(self, name, value, attrs=None):
"""Return a list of optgroups for this widget."""
groups = []
has_selected = False
for index, (option_value, option_label) in enumerate(self.choices):
if option_value is None:
option_value = ''
subgro... | [
"def",
"optgroups",
"(",
"self",
",",
"name",
",",
"value",
",",
"attrs",
"=",
"None",
")",
":",
"groups",
"=",
"[",
"]",
"has_selected",
"=",
"False",
"for",
"index",
",",
"(",
"option_value",
",",
"option_label",
")",
"in",
"enumerate",
"(",
"self",
... | [
586,
4
] | [
618,
21
] | python | en | ['en', 'en', 'en'] | True |
ChoiceWidget.id_for_label | (self, id_, index='0') |
Use an incremented id for each option where the main widget
references the zero index.
|
Use an incremented id for each option where the main widget
references the zero index.
| def id_for_label(self, id_, index='0'):
"""
Use an incremented id for each option where the main widget
references the zero index.
"""
if id_ and self.add_id_index:
id_ = '%s_%s' % (id_, index)
return id_ | [
"def",
"id_for_label",
"(",
"self",
",",
"id_",
",",
"index",
"=",
"'0'",
")",
":",
"if",
"id_",
"and",
"self",
".",
"add_id_index",
":",
"id_",
"=",
"'%s_%s'",
"%",
"(",
"id_",
",",
"index",
")",
"return",
"id_"
] | [
646,
4
] | [
653,
18
] | python | en | ['en', 'error', 'th'] | False |
ChoiceWidget.format_value | (self, value) | Return selected values as a list. | Return selected values as a list. | def format_value(self, value):
"""Return selected values as a list."""
if value is None and self.allow_multiple_selected:
return []
if not isinstance(value, (tuple, list)):
value = [value]
return [str(v) if v is not None else '' for v in value] | [
"def",
"format_value",
"(",
"self",
",",
"value",
")",
":",
"if",
"value",
"is",
"None",
"and",
"self",
".",
"allow_multiple_selected",
":",
"return",
"[",
"]",
"if",
"not",
"isinstance",
"(",
"value",
",",
"(",
"tuple",
",",
"list",
")",
")",
":",
"... | [
664,
4
] | [
670,
63
] | python | en | ['en', 'en', 'en'] | True |
Select._choice_has_empty_value | (choice) | Return True if the choice's value is empty string or None. | Return True if the choice's value is empty string or None. | def _choice_has_empty_value(choice):
"""Return True if the choice's value is empty string or None."""
value, _ = choice
return value is None or value == '' | [
"def",
"_choice_has_empty_value",
"(",
"choice",
")",
":",
"value",
",",
"_",
"=",
"choice",
"return",
"value",
"is",
"None",
"or",
"value",
"==",
"''"
] | [
688,
4
] | [
691,
43
] | python | en | ['en', 'en', 'en'] | True |
Select.use_required_attribute | (self, initial) |
Don't render 'required' if the first <option> has a value, as that's
invalid HTML.
|
Don't render 'required' if the first <option> has a value, as that's
invalid HTML.
| def use_required_attribute(self, initial):
"""
Don't render 'required' if the first <option> has a value, as that's
invalid HTML.
"""
use_required_attribute = super().use_required_attribute(initial)
# 'required' is always okay for <select multiple>.
if self.allow_... | [
"def",
"use_required_attribute",
"(",
"self",
",",
"initial",
")",
":",
"use_required_attribute",
"=",
"super",
"(",
")",
".",
"use_required_attribute",
"(",
"initial",
")",
"# 'required' is always okay for <select multiple>.",
"if",
"self",
".",
"allow_multiple_selected"... | [
693,
4
] | [
704,
113
] | python | en | ['en', 'error', 'th'] | False |
CheckboxSelectMultiple.id_for_label | (self, id_, index=None) |
Don't include for="field_0" in <label> because clicking such a label
would toggle the first checkbox.
|
Don't include for="field_0" in <label> because clicking such a label
would toggle the first checkbox.
| def id_for_label(self, id_, index=None):
"""
Don't include for="field_0" in <label> because clicking such a label
would toggle the first checkbox.
"""
if index is None:
return ''
return super().id_for_label(id_, index) | [
"def",
"id_for_label",
"(",
"self",
",",
"id_",
",",
"index",
"=",
"None",
")",
":",
"if",
"index",
"is",
"None",
":",
"return",
"''",
"return",
"super",
"(",
")",
".",
"id_for_label",
"(",
"id_",
",",
"index",
")"
] | [
783,
4
] | [
790,
47
] | python | en | ['en', 'error', 'th'] | False |
MultiWidget.decompress | (self, value) |
Return a list of decompressed values for the given compressed value.
The given value can be assumed to be valid, but not necessarily
non-empty.
|
Return a list of decompressed values for the given compressed value.
The given value can be assumed to be valid, but not necessarily
non-empty.
| def decompress(self, value):
"""
Return a list of decompressed values for the given compressed value.
The given value can be assumed to be valid, but not necessarily
non-empty.
"""
raise NotImplementedError('Subclasses must implement this method.') | [
"def",
"decompress",
"(",
"self",
",",
"value",
")",
":",
"raise",
"NotImplementedError",
"(",
"'Subclasses must implement this method.'",
")"
] | [
868,
4
] | [
874,
75
] | python | en | ['en', 'error', 'th'] | False |
MultiWidget._get_media | (self) |
Media for a multiwidget is the combination of all media of the
subwidgets.
|
Media for a multiwidget is the combination of all media of the
subwidgets.
| def _get_media(self):
"""
Media for a multiwidget is the combination of all media of the
subwidgets.
"""
media = Media()
for w in self.widgets:
media = media + w.media
return media | [
"def",
"_get_media",
"(",
"self",
")",
":",
"media",
"=",
"Media",
"(",
")",
"for",
"w",
"in",
"self",
".",
"widgets",
":",
"media",
"=",
"media",
"+",
"w",
".",
"media",
"return",
"media"
] | [
876,
4
] | [
884,
20
] | python | en | ['en', 'error', 'th'] | False |
SelectDateWidget.format_value | (self, value) |
Return a dict containing the year, month, and day of the current value.
Use dict instead of a datetime to allow invalid dates such as February
31 to display correctly.
|
Return a dict containing the year, month, and day of the current value.
Use dict instead of a datetime to allow invalid dates such as February
31 to display correctly.
| def format_value(self, value):
"""
Return a dict containing the year, month, and day of the current value.
Use dict instead of a datetime to allow invalid dates such as February
31 to display correctly.
"""
year, month, day = None, None, None
if isinstance(value, ... | [
"def",
"format_value",
"(",
"self",
",",
"value",
")",
":",
"year",
",",
"month",
",",
"day",
"=",
"None",
",",
"None",
",",
"None",
"if",
"isinstance",
"(",
"value",
",",
"(",
"datetime",
".",
"date",
",",
"datetime",
".",
"datetime",
")",
")",
":... | [
1020,
4
] | [
1043,
57
] | python | en | ['en', 'error', 'th'] | False |
Result.output | (self) | The (standard) output as unicode string. | The (standard) output as unicode string. | def output(self):
"""The (standard) output as unicode string."""
return self.stdout | [
"def",
"output",
"(",
"self",
")",
":",
"return",
"self",
".",
"stdout"
] | [
91,
4
] | [
93,
26
] | python | en | ['en', 'en', 'en'] | True |
Result.stdout | (self) | The standard output as unicode string. | The standard output as unicode string. | def stdout(self):
"""The standard output as unicode string."""
return self.stdout_bytes.decode(self.runner.charset, 'replace') \
.replace('\r\n', '\n') | [
"def",
"stdout",
"(",
"self",
")",
":",
"return",
"self",
".",
"stdout_bytes",
".",
"decode",
"(",
"self",
".",
"runner",
".",
"charset",
",",
"'replace'",
")",
".",
"replace",
"(",
"'\\r\\n'",
",",
"'\\n'",
")"
] | [
96,
4
] | [
99,
34
] | python | en | ['en', 'en', 'en'] | True |
Result.stderr | (self) | The standard error as unicode string. | The standard error as unicode string. | def stderr(self):
"""The standard error as unicode string."""
if not self.stderr_bytes:
raise ValueError("stderr not separately captured")
return self.stderr_bytes.decode(self.runner.charset, 'replace') \
.replace('\r\n', '\n') | [
"def",
"stderr",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"stderr_bytes",
":",
"raise",
"ValueError",
"(",
"\"stderr not separately captured\"",
")",
"return",
"self",
".",
"stderr_bytes",
".",
"decode",
"(",
"self",
".",
"runner",
".",
"charset",
",... | [
102,
4
] | [
107,
34
] | python | en | ['en', 'en', 'en'] | True |
CliRunner.get_default_prog_name | (self, cli) | Given a command object it will return the default program name
for it. The default is the `name` attribute or ``"root"`` if not
set.
| Given a command object it will return the default program name
for it. The default is the `name` attribute or ``"root"`` if not
set.
| def get_default_prog_name(self, cli):
"""Given a command object it will return the default program name
for it. The default is the `name` attribute or ``"root"`` if not
set.
"""
return cli.name or 'root' | [
"def",
"get_default_prog_name",
"(",
"self",
",",
"cli",
")",
":",
"return",
"cli",
".",
"name",
"or",
"'root'"
] | [
147,
4
] | [
152,
33
] | python | en | ['en', 'en', 'en'] | True |
CliRunner.make_env | (self, overrides=None) | Returns the environment overrides for invoking a script. | Returns the environment overrides for invoking a script. | def make_env(self, overrides=None):
"""Returns the environment overrides for invoking a script."""
rv = dict(self.env)
if overrides:
rv.update(overrides)
return rv | [
"def",
"make_env",
"(",
"self",
",",
"overrides",
"=",
"None",
")",
":",
"rv",
"=",
"dict",
"(",
"self",
".",
"env",
")",
"if",
"overrides",
":",
"rv",
".",
"update",
"(",
"overrides",
")",
"return",
"rv"
] | [
154,
4
] | [
159,
17
] | python | en | ['en', 'en', 'en'] | True |
CliRunner.isolation | (self, input=None, env=None, color=False) | A context manager that sets up the isolation for invoking of a
command line tool. This sets up stdin with the given input data
and `os.environ` with the overrides from the given dictionary.
This also rebinds some internals in Click to be mocked (like the
prompt functionality).
... | A context manager that sets up the isolation for invoking of a
command line tool. This sets up stdin with the given input data
and `os.environ` with the overrides from the given dictionary.
This also rebinds some internals in Click to be mocked (like the
prompt functionality). | def isolation(self, input=None, env=None, color=False):
"""A context manager that sets up the isolation for invoking of a
command line tool. This sets up stdin with the given input data
and `os.environ` with the overrides from the given dictionary.
This also rebinds some internals in Cl... | [
"def",
"isolation",
"(",
"self",
",",
"input",
"=",
"None",
",",
"env",
"=",
"None",
",",
"color",
"=",
"False",
")",
":",
"input",
"=",
"make_input_stream",
"(",
"input",
",",
"self",
".",
"charset",
")",
"old_stdin",
"=",
"sys",
".",
"stdin",
"old_... | [
162,
4
] | [
277,
63
] | python | en | ['en', 'en', 'en'] | True |
CliRunner.invoke | (self, cli, args=None, input=None, env=None,
catch_exceptions=True, color=False, mix_stderr=False, **extra) | Invokes a command in an isolated environment. The arguments are
forwarded directly to the command line script, the `extra` keyword
arguments are passed to the :meth:`~clickpkg.Command.main` function of
the command.
This returns a :class:`Result` object.
.. versionadded:: 3.0
... | Invokes a command in an isolated environment. The arguments are
forwarded directly to the command line script, the `extra` keyword
arguments are passed to the :meth:`~clickpkg.Command.main` function of
the command. | def invoke(self, cli, args=None, input=None, env=None,
catch_exceptions=True, color=False, mix_stderr=False, **extra):
"""Invokes a command in an isolated environment. The arguments are
forwarded directly to the command line script, the `extra` keyword
arguments are passed to the... | [
"def",
"invoke",
"(",
"self",
",",
"cli",
",",
"args",
"=",
"None",
",",
"input",
"=",
"None",
",",
"env",
"=",
"None",
",",
"catch_exceptions",
"=",
"True",
",",
"color",
"=",
"False",
",",
"mix_stderr",
"=",
"False",
",",
"*",
"*",
"extra",
")",
... | [
279,
4
] | [
356,
40
] | python | en | ['en', 'en', 'en'] | True |
CliRunner.isolated_filesystem | (self) | A context manager that creates a temporary folder and changes
the current working directory to it for isolated filesystem tests.
| A context manager that creates a temporary folder and changes
the current working directory to it for isolated filesystem tests.
| def isolated_filesystem(self):
"""A context manager that creates a temporary folder and changes
the current working directory to it for isolated filesystem tests.
"""
cwd = os.getcwd()
t = tempfile.mkdtemp()
os.chdir(t)
try:
yield t
finally:
... | [
"def",
"isolated_filesystem",
"(",
"self",
")",
":",
"cwd",
"=",
"os",
".",
"getcwd",
"(",
")",
"t",
"=",
"tempfile",
".",
"mkdtemp",
"(",
")",
"os",
".",
"chdir",
"(",
"t",
")",
"try",
":",
"yield",
"t",
"finally",
":",
"os",
".",
"chdir",
"(",
... | [
359,
4
] | [
373,
20
] | python | en | ['en', 'en', 'en'] | True |
infCallUtil.callmethod | (self, val, fname, args) | make method in fname on the obj ref 'val | make method in fname on the obj ref 'val | def callmethod(self, val, fname, args):
"make method in fname on the obj ref 'val'"
methodcall = "( (" + str(val.type) + ")" + "(" + str(val).split()[0] + ") )" + "->" + fname + "("
cnt = 0
for arg in args:
if (cnt):
methodcall += ","
try:
methodcall += "( (" + str(arg.type) + ")" + "(" + str(arg... | [
"def",
"callmethod",
"(",
"self",
",",
"val",
",",
"fname",
",",
"args",
")",
":",
"methodcall",
"=",
"\"( (\"",
"+",
"str",
"(",
"val",
".",
"type",
")",
"+",
"\")\"",
"+",
"\"(\"",
"+",
"str",
"(",
"val",
")",
".",
"split",
"(",
")",
"[",
"0"... | [
10,
1
] | [
26,
39
] | python | en | ['en', 'da', 'en'] | True |
infCallUtil.callfunc | (self, fname, args) | make call fname(args) | make call fname(args) | def callfunc(self, fname, args):
"make call fname(args)"
funccall = fname + "("
cnt = 0
for val in args:
if (cnt):
funccall += ","
funccall += "( (" + str(val.type) + ")" + "(" + str(val).split()[0] + ") )"
cnt+=1
funccall += ")"
#print ("funccall = ", funccall)
return gdb.parse_and_eval(func... | [
"def",
"callfunc",
"(",
"self",
",",
"fname",
",",
"args",
")",
":",
"funccall",
"=",
"fname",
"+",
"\"(\"",
"cnt",
"=",
"0",
"for",
"val",
"in",
"args",
":",
"if",
"(",
"cnt",
")",
":",
"funccall",
"+=",
"\",\"",
"funccall",
"+=",
"\"( (\"",
"+",
... | [
28,
1
] | [
39,
37
] | python | en | ['en', 'ceb', 'en'] | True |
_parse_arguments | (argv) | Parses command-line arguments. | Parses command-line arguments. | def _parse_arguments(argv):
"""Parses command-line arguments."""
parser = argparse.ArgumentParser()
parser.add_argument(
'--game',
help='Which open ai gym game to play',
type=str,
default='CartPole-v0')
parser.add_argument(
'--episodes',
help='The number o... | [
"def",
"_parse_arguments",
"(",
"argv",
")",
":",
"parser",
"=",
"argparse",
".",
"ArgumentParser",
"(",
")",
"parser",
".",
"add_argument",
"(",
"'--game'",
",",
"help",
"=",
"'Which open ai gym game to play'",
",",
"type",
"=",
"str",
",",
"default",
"=",
... | [
33,
0
] | [
94,
40
] | python | en | ['en', 'fr', 'en'] | True |
_run | (game, network_params, memory_params, ops) | Sets up and runs the gaming simulation.
Initializes TensorFlow, the training agent, and the game environment.
The agent plays the game from the starting state for a number of
episodes set by the user.
Args:
args: The arguments from the command line parsed by_parse_arguments.
| Sets up and runs the gaming simulation. | def _run(game, network_params, memory_params, ops):
"""Sets up and runs the gaming simulation.
Initializes TensorFlow, the training agent, and the game environment.
The agent plays the game from the starting state for a number of
episodes set by the user.
Args:
args: The arguments from the c... | [
"def",
"_run",
"(",
"game",
",",
"network_params",
",",
"memory_params",
",",
"ops",
")",
":",
"# Setup TensorBoard Writer.",
"trial_id",
"=",
"json",
".",
"loads",
"(",
"os",
".",
"environ",
".",
"get",
"(",
"'TF_CONFIG'",
",",
"'{}'",
")",
")",
".",
"g... | [
97,
0
] | [
162,
56
] | python | en | ['en', 'fil', 'en'] | True |
_play | (agent, env, training, recorder=None) | Plays through one episode of the game.
Initializes TensorFlow, the training agent, and the game environment.
The agent plays the game from the starting state for a number of
episodes set by the user.
Args:
agent: The actor learning to play in the given environment.
env: The environment for... | Plays through one episode of the game. | def _play(agent, env, training, recorder=None):
"""Plays through one episode of the game.
Initializes TensorFlow, the training agent, and the game environment.
The agent plays the game from the starting state for a number of
episodes set by the user.
Args:
agent: The actor learning to play i... | [
"def",
"_play",
"(",
"agent",
",",
"env",
",",
"training",
",",
"recorder",
"=",
"None",
")",
":",
"episode_reward",
"=",
"0",
"# The total reward for an episode.",
"state",
"=",
"env",
".",
"reset",
"(",
")",
".",
"tolist",
"(",
")",
"# Set up Environment a... | [
165,
0
] | [
201,
25
] | python | en | ['en', 'en', 'en'] | True |
_create_agent | (env, network_params, memory_params) | Creates a Reinforcement Learning agent.
Args:
env: The environment for the agent to act in.
network_params: Parameters to build actor-critic neural networks.
memory_params: Parameters to an actor-critic memory buffer.
Returns:
An RL agent.
| Creates a Reinforcement Learning agent. | def _create_agent(env, network_params, memory_params):
"""Creates a Reinforcement Learning agent.
Args:
env: The environment for the agent to act in.
network_params: Parameters to build actor-critic neural networks.
memory_params: Parameters to an actor-critic memory buffer.
Returns:
... | [
"def",
"_create_agent",
"(",
"env",
",",
"network_params",
",",
"memory_params",
")",
":",
"space_shape",
"=",
"env",
".",
"observation_space",
".",
"shape",
"[",
"0",
"]",
"action_size",
"=",
"env",
".",
"action_space",
".",
"n",
"actor",
",",
"critic",
"... | [
204,
0
] | [
220,
66
] | python | en | ['en', 'en', 'en'] | True |
_record_video | (env, agent, output_path) | Records a video of an agent playing a gaming simulation.
Args:
env: The environment for the agent to act in.
agent: An RL agent created by _create_agent.
output_path (str): The directory path of where to save the recording.
| Records a video of an agent playing a gaming simulation. | def _record_video(env, agent, output_path):
"""Records a video of an agent playing a gaming simulation.
Args:
env: The environment for the agent to act in.
agent: An RL agent created by _create_agent.
output_path (str): The directory path of where to save the recording.
"""
video_reco... | [
"def",
"_record_video",
"(",
"env",
",",
"agent",
",",
"output_path",
")",
":",
"video_recorder",
"=",
"VideoRecorder",
"(",
"env",
",",
"RECORDING_NAME",
")",
"_play",
"(",
"agent",
",",
"env",
",",
"False",
",",
"recorder",
"=",
"video_recorder",
")",
"v... | [
223,
0
] | [
242,
49
] | python | en | ['en', 'en', 'en'] | True |
main | () | Parses command line arguments and kicks off the gaming simulation. | Parses command line arguments and kicks off the gaming simulation. | def main():
"""Parses command line arguments and kicks off the gaming simulation."""
args = _parse_arguments(sys.argv[1:])[0]
network_params = (
args.learning_rate, args.critic_weight, args.hidden_neurons, args.entropy)
memory_params = (args.gamma, args.batch_size)
ops = argparse.Namespace(*... | [
"def",
"main",
"(",
")",
":",
"args",
"=",
"_parse_arguments",
"(",
"sys",
".",
"argv",
"[",
"1",
":",
"]",
")",
"[",
"0",
"]",
"network_params",
"=",
"(",
"args",
".",
"learning_rate",
",",
"args",
".",
"critic_weight",
",",
"args",
".",
"hidden_neu... | [
245,
0
] | [
257,
55
] | python | en | ['en', 'en', 'en'] | True |
ResponseHeaders.__init__ | (self, data) |
Populate the initial data using __setitem__ to ensure values are
correctly encoded.
|
Populate the initial data using __setitem__ to ensure values are
correctly encoded.
| def __init__(self, data):
"""
Populate the initial data using __setitem__ to ensure values are
correctly encoded.
"""
if not isinstance(data, Mapping):
data = {k: v for k, v in _destruct_iterable_mapping_values(data)}
self._store = {}
for header, value... | [
"def",
"__init__",
"(",
"self",
",",
"data",
")",
":",
"if",
"not",
"isinstance",
"(",
"data",
",",
"Mapping",
")",
":",
"data",
"=",
"{",
"k",
":",
"v",
"for",
"k",
",",
"v",
"in",
"_destruct_iterable_mapping_values",
"(",
"data",
")",
"}",
"self",
... | [
29,
4
] | [
38,
32
] | python | en | ['en', 'error', 'th'] | False |
ResponseHeaders._convert_to_charset | (self, value, charset, mime_encode=False) |
Convert headers key/value to ascii/latin-1 native strings.
`charset` must be 'ascii' or 'latin-1'. If `mime_encode` is True and
`value` can't be represented in the given charset, apply MIME-encoding.
|
Convert headers key/value to ascii/latin-1 native strings.
`charset` must be 'ascii' or 'latin-1'. If `mime_encode` is True and
`value` can't be represented in the given charset, apply MIME-encoding.
| def _convert_to_charset(self, value, charset, mime_encode=False):
"""
Convert headers key/value to ascii/latin-1 native strings.
`charset` must be 'ascii' or 'latin-1'. If `mime_encode` is True and
`value` can't be represented in the given charset, apply MIME-encoding.
"""
... | [
"def",
"_convert_to_charset",
"(",
"self",
",",
"value",
",",
"charset",
",",
"mime_encode",
"=",
"False",
")",
":",
"if",
"not",
"isinstance",
"(",
"value",
",",
"(",
"bytes",
",",
"str",
")",
")",
":",
"value",
"=",
"str",
"(",
"value",
")",
"if",
... | [
40,
4
] | [
66,
20
] | python | en | ['en', 'error', 'th'] | False |
HttpResponseBase.serialize_headers | (self) | HTTP headers as a bytestring. | HTTP headers as a bytestring. | def serialize_headers(self):
"""HTTP headers as a bytestring."""
def to_bytes(val, encoding):
return val if isinstance(val, bytes) else val.encode(encoding)
headers = [
(to_bytes(key, 'ascii') + b': ' + to_bytes(value, 'latin-1'))
for key, value in self.heade... | [
"def",
"serialize_headers",
"(",
"self",
")",
":",
"def",
"to_bytes",
"(",
"val",
",",
"encoding",
")",
":",
"return",
"val",
"if",
"isinstance",
"(",
"val",
",",
"bytes",
")",
"else",
"val",
".",
"encode",
"(",
"encoding",
")",
"headers",
"=",
"[",
... | [
153,
4
] | [
162,
36
] | python | en | ['en', 'sv', 'en'] | True |
HttpResponseBase.has_header | (self, header) | Case-insensitive check for a header. | Case-insensitive check for a header. | def has_header(self, header):
"""Case-insensitive check for a header."""
return header in self.headers | [
"def",
"has_header",
"(",
"self",
",",
"header",
")",
":",
"return",
"header",
"in",
"self",
".",
"headers"
] | [
179,
4
] | [
181,
37
] | python | en | ['en', 'en', 'en'] | True |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.