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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
_split_sql | (sql) | Split *sql* on a single ``%s`` placeholder.
Split on the %s, perform %% replacement and return pre, post lists of
snippets.
| Split *sql* on a single ``%s`` placeholder. | def _split_sql(sql):
"""Split *sql* on a single ``%s`` placeholder.
Split on the %s, perform %% replacement and return pre, post lists of
snippets.
"""
curr = pre = []
post = []
tokens = _re.split(br'(%.)', sql)
for token in tokens:
if len(token) != 2 or token[:1] != b'%':
... | [
"def",
"_split_sql",
"(",
"sql",
")",
":",
"curr",
"=",
"pre",
"=",
"[",
"]",
"post",
"=",
"[",
"]",
"tokens",
"=",
"_re",
".",
"split",
"(",
"br'(%.)'",
",",
"sql",
")",
"for",
"token",
"in",
"tokens",
":",
"if",
"len",
"(",
"token",
")",
"!="... | [
1295,
0
] | [
1324,
20
] | python | en | ['en', 'da', 'en'] | True |
LoggingConnection.initialize | (self, logobj) | Initialize the connection to log to `!logobj`.
The `!logobj` parameter can be an open file object or a Logger/LoggerAdapter
instance from the standard logging module.
| Initialize the connection to log to `!logobj`. | def initialize(self, logobj):
"""Initialize the connection to log to `!logobj`.
The `!logobj` parameter can be an open file object or a Logger/LoggerAdapter
instance from the standard logging module.
"""
self._logobj = logobj
if _logging and isinstance(
l... | [
"def",
"initialize",
"(",
"self",
",",
"logobj",
")",
":",
"self",
".",
"_logobj",
"=",
"logobj",
"if",
"_logging",
"and",
"isinstance",
"(",
"logobj",
",",
"(",
"_logging",
".",
"Logger",
",",
"_logging",
".",
"LoggerAdapter",
")",
")",
":",
"self",
"... | [
410,
4
] | [
421,
38
] | python | en | ['en', 'en', 'en'] | True |
LoggingConnection.filter | (self, msg, curs) | Filter the query before logging it.
This is the method to overwrite to filter unwanted queries out of the
log or to add some extra data to the output. The default implementation
just does nothing.
| Filter the query before logging it. | def filter(self, msg, curs):
"""Filter the query before logging it.
This is the method to overwrite to filter unwanted queries out of the
log or to add some extra data to the output. The default implementation
just does nothing.
"""
return msg | [
"def",
"filter",
"(",
"self",
",",
"msg",
",",
"curs",
")",
":",
"return",
"msg"
] | [
423,
4
] | [
430,
18
] | python | en | ['en', 'en', 'en'] | True |
ReplicationCursor.create_replication_slot | (self, slot_name, slot_type=None, output_plugin=None) | Create streaming replication slot. | Create streaming replication slot. | def create_replication_slot(self, slot_name, slot_type=None, output_plugin=None):
"""Create streaming replication slot."""
command = "CREATE_REPLICATION_SLOT %s " % quote_ident(slot_name, self)
if slot_type is None:
slot_type = self.connection.replication_type
if slot_type... | [
"def",
"create_replication_slot",
"(",
"self",
",",
"slot_name",
",",
"slot_type",
"=",
"None",
",",
"output_plugin",
"=",
"None",
")",
":",
"command",
"=",
"\"CREATE_REPLICATION_SLOT %s \"",
"%",
"quote_ident",
"(",
"slot_name",
",",
"self",
")",
"if",
"slot_ty... | [
540,
4
] | [
568,
29
] | python | en | ['en', 'en', 'en'] | True |
ReplicationCursor.drop_replication_slot | (self, slot_name) | Drop streaming replication slot. | Drop streaming replication slot. | def drop_replication_slot(self, slot_name):
"""Drop streaming replication slot."""
command = "DROP_REPLICATION_SLOT %s" % quote_ident(slot_name, self)
self.execute(command) | [
"def",
"drop_replication_slot",
"(",
"self",
",",
"slot_name",
")",
":",
"command",
"=",
"\"DROP_REPLICATION_SLOT %s\"",
"%",
"quote_ident",
"(",
"slot_name",
",",
"self",
")",
"self",
".",
"execute",
"(",
"command",
")"
] | [
570,
4
] | [
574,
29
] | python | en | ['en', 'fil', 'en'] | True |
ReplicationCursor.start_replication | (
self, slot_name=None, slot_type=None, start_lsn=0,
timeline=0, options=None, decode=False, status_interval=10) | Start replication stream. | Start replication stream. | def start_replication(
self, slot_name=None, slot_type=None, start_lsn=0,
timeline=0, options=None, decode=False, status_interval=10):
"""Start replication stream."""
command = "START_REPLICATION "
if slot_type is None:
slot_type = self.connection.replicatio... | [
"def",
"start_replication",
"(",
"self",
",",
"slot_name",
"=",
"None",
",",
"slot_type",
"=",
"None",
",",
"start_lsn",
"=",
"0",
",",
"timeline",
"=",
"0",
",",
"options",
"=",
"None",
",",
"decode",
"=",
"False",
",",
"status_interval",
"=",
"10",
"... | [
576,
4
] | [
633,
68
] | python | en | ['en', 'sn', 'en'] | True |
HstoreAdapter._getquoted_8 | (self) | Use the operators available in PG pre-9.0. | Use the operators available in PG pre-9.0. | def _getquoted_8(self):
"""Use the operators available in PG pre-9.0."""
if not self.wrapped:
return b"''::hstore"
adapt = _ext.adapt
rv = []
for k, v in self.wrapped.items():
k = adapt(k)
k.prepare(self.conn)
k = k.getquoted()
... | [
"def",
"_getquoted_8",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"wrapped",
":",
"return",
"b\"''::hstore\"",
"adapt",
"=",
"_ext",
".",
"adapt",
"rv",
"=",
"[",
"]",
"for",
"k",
",",
"v",
"in",
"self",
".",
"wrapped",
".",
"items",
"(",
")"... | [
816,
4
] | [
838,
43
] | python | en | ['en', 'en', 'en'] | True |
HstoreAdapter._getquoted_9 | (self) | Use the hstore(text[], text[]) function. | Use the hstore(text[], text[]) function. | def _getquoted_9(self):
"""Use the hstore(text[], text[]) function."""
if not self.wrapped:
return b"''::hstore"
k = _ext.adapt(list(self.wrapped.keys()))
k.prepare(self.conn)
v = _ext.adapt(list(self.wrapped.values()))
v.prepare(self.conn)
return b"h... | [
"def",
"_getquoted_9",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"wrapped",
":",
"return",
"b\"''::hstore\"",
"k",
"=",
"_ext",
".",
"adapt",
"(",
"list",
"(",
"self",
".",
"wrapped",
".",
"keys",
"(",
")",
")",
")",
"k",
".",
"prepare",
"("... | [
840,
4
] | [
849,
72
] | python | en | ['en', 'en', 'en'] | True |
HstoreAdapter.parse | (self, s, cur, _bsdec=_re.compile(r"\\(.)")) | Parse an hstore representation in a Python string.
The hstore is represented as something like::
"a"=>"1", "b"=>"2"
with backslash-escaped strings.
| Parse an hstore representation in a Python string. | def parse(self, s, cur, _bsdec=_re.compile(r"\\(.)")):
"""Parse an hstore representation in a Python string.
The hstore is represented as something like::
"a"=>"1", "b"=>"2"
with backslash-escaped strings.
"""
if s is None:
return None
rv = {}
... | [
"def",
"parse",
"(",
"self",
",",
"s",
",",
"cur",
",",
"_bsdec",
"=",
"_re",
".",
"compile",
"(",
"r\"\\\\(.)\"",
")",
")",
":",
"if",
"s",
"is",
"None",
":",
"return",
"None",
"rv",
"=",
"{",
"}",
"start",
"=",
"0",
"for",
"m",
"in",
"self",
... | [
867,
4
] | [
897,
17
] | python | en | ['en', 'en', 'en'] | True |
HstoreAdapter.parse_unicode | (self, s, cur) | Parse an hstore returning unicode keys and values. | Parse an hstore returning unicode keys and values. | def parse_unicode(self, s, cur):
"""Parse an hstore returning unicode keys and values."""
if s is None:
return None
s = s.decode(_ext.encodings[cur.connection.encoding])
return self.parse(s, cur) | [
"def",
"parse_unicode",
"(",
"self",
",",
"s",
",",
"cur",
")",
":",
"if",
"s",
"is",
"None",
":",
"return",
"None",
"s",
"=",
"s",
".",
"decode",
"(",
"_ext",
".",
"encodings",
"[",
"cur",
".",
"connection",
".",
"encoding",
"]",
")",
"return",
... | [
900,
4
] | [
906,
33
] | python | en | ['en', 'en', 'en'] | True |
HstoreAdapter.get_oids | (self, conn_or_curs) | Return the lists of OID of the hstore and hstore[] types.
| Return the lists of OID of the hstore and hstore[] types.
| def get_oids(self, conn_or_curs):
"""Return the lists of OID of the hstore and hstore[] types.
"""
conn, curs = _solve_conn_curs(conn_or_curs)
# Store the transaction status of the connection to revert it after use
conn_status = conn.status
# column typarray not availab... | [
"def",
"get_oids",
"(",
"self",
",",
"conn_or_curs",
")",
":",
"conn",
",",
"curs",
"=",
"_solve_conn_curs",
"(",
"conn_or_curs",
")",
"# Store the transaction status of the connection to revert it after use",
"conn_status",
"=",
"conn",
".",
"status",
"# column typarray ... | [
909,
4
] | [
938,
37
] | python | en | ['en', 'en', 'en'] | True |
CompositeCaster.make | (self, values) | Return a new Python object representing the data being casted.
*values* is the list of attributes, already casted into their Python
representation.
You can subclass this method to :ref:`customize the composite cast
<custom-composite>`.
| Return a new Python object representing the data being casted. | def make(self, values):
"""Return a new Python object representing the data being casted.
*values* is the list of attributes, already casted into their Python
representation.
You can subclass this method to :ref:`customize the composite cast
<custom-composite>`.
"""
... | [
"def",
"make",
"(",
"self",
",",
"values",
")",
":",
"return",
"self",
".",
"_ctor",
"(",
"values",
")"
] | [
1046,
4
] | [
1056,
33
] | python | en | ['en', 'en', 'en'] | True |
CompositeCaster._from_db | (self, name, conn_or_curs) | Return a `CompositeCaster` instance for the type *name*.
Raise `ProgrammingError` if the type is not found.
| Return a `CompositeCaster` instance for the type *name*. | def _from_db(self, name, conn_or_curs):
"""Return a `CompositeCaster` instance for the type *name*.
Raise `ProgrammingError` if the type is not found.
"""
conn, curs = _solve_conn_curs(conn_or_curs)
# Store the transaction status of the connection to revert it after use
... | [
"def",
"_from_db",
"(",
"self",
",",
"name",
",",
"conn_or_curs",
")",
":",
"conn",
",",
"curs",
"=",
"_solve_conn_curs",
"(",
"conn_or_curs",
")",
"# Store the transaction status of the connection to revert it after use",
"conn_status",
"=",
"conn",
".",
"status",
"#... | [
1086,
4
] | [
1133,
47
] | python | en | ['en', 'en', 'en'] | True |
FixedOffsetTimezone.__new__ | (cls, offset=None, name=None) | Return a suitable instance created earlier if it exists
| Return a suitable instance created earlier if it exists
| def __new__(cls, offset=None, name=None):
"""Return a suitable instance created earlier if it exists
"""
key = (offset, name)
try:
return cls._cache[key]
except KeyError:
tz = super(FixedOffsetTimezone, cls).__new__(cls, offset, name)
cls._cach... | [
"def",
"__new__",
"(",
"cls",
",",
"offset",
"=",
"None",
",",
"name",
"=",
"None",
")",
":",
"key",
"=",
"(",
"offset",
",",
"name",
")",
"try",
":",
"return",
"cls",
".",
"_cache",
"[",
"key",
"]",
"except",
"KeyError",
":",
"tz",
"=",
"super",... | [
60,
4
] | [
69,
21
] | python | en | ['en', 'en', 'en'] | True |
build_scripts.copy_scripts | (self) | r"""Copy each script listed in 'self.scripts'; if it's marked as a
Python script in the Unix way (first line matches 'first_line_re',
ie. starts with "\#!" and contains "python"), then adjust the first
line to refer to the current Python interpreter as we copy.
| r"""Copy each script listed in 'self.scripts'; if it's marked as a
Python script in the Unix way (first line matches 'first_line_re',
ie. starts with "\#!" and contains "python"), then adjust the first
line to refer to the current Python interpreter as we copy.
| def copy_scripts(self):
r"""Copy each script listed in 'self.scripts'; if it's marked as a
Python script in the Unix way (first line matches 'first_line_re',
ie. starts with "\#!" and contains "python"), then adjust the first
line to refer to the current Python interpreter as we copy.
... | [
"def",
"copy_scripts",
"(",
"self",
")",
":",
"self",
".",
"mkpath",
"(",
"self",
".",
"build_dir",
")",
"outfiles",
"=",
"[",
"]",
"updated_files",
"=",
"[",
"]",
"for",
"script",
"in",
"self",
".",
"scripts",
":",
"adjust",
"=",
"False",
"script",
... | [
52,
4
] | [
151,
38
] | python | en | ['en', 'en', 'en'] | True |
pre_sql_setup | (self) |
Do any necessary class setup immediately prior to producing SQL. This
is for things that can't necessarily be done in __init__ because we
might not have all the pieces in place at that time.
|
Do any necessary class setup immediately prior to producing SQL. This
is for things that can't necessarily be done in __init__ because we
might not have all the pieces in place at that time.
| def pre_sql_setup(self):
"""
Do any necessary class setup immediately prior to producing SQL. This
is for things that can't necessarily be done in __init__ because we
might not have all the pieces in place at that time.
"""
self.setup_query()
order_by = self.get_o... | [
"def",
"pre_sql_setup",
"(",
"self",
")",
":",
"self",
".",
"setup_query",
"(",
")",
"order_by",
"=",
"self",
".",
"get_order_by",
"(",
")",
"self",
".",
"where",
",",
"self",
".",
"having",
"=",
"self",
".",
"query",
".",
"where",
".",
"split_having",... | [
44,
4
] | [
56,
47
] | python | en | ['en', 'error', 'th'] | False |
get_group_by | (self, select, order_by) |
Return a list of 2-tuples of form (sql, params).
The logic of what exactly the GROUP BY clause contains is hard
to describe in other words than "if it passes the test suite,
then it is correct".
|
Return a list of 2-tuples of form (sql, params). | def get_group_by(self, select, order_by):
"""
Return a list of 2-tuples of form (sql, params).
The logic of what exactly the GROUP BY clause contains is hard
to describe in other words than "if it passes the test suite,
then it is correct".
"""
# Some examples:
... | [
"def",
"get_group_by",
"(",
"self",
",",
"select",
",",
"order_by",
")",
":",
"# Some examples:",
"# SomeModel.objects.annotate(Count('somecol'))",
"# GROUP BY: all fields of the model",
"#",
"# SomeModel.objects.values('name').annotate(Count('somecol'))",
"# GROUP BY: na... | [
58,
4
] | [
142,
21
] | python | en | ['en', 'error', 'th'] | False |
get_select | (self) |
Return three values:
- a list of 3-tuples of (expression, (sql, params), alias)
- a klass_info structure,
- a dictionary of annotations
The (sql, params) is what the expression will produce, and alias is the
"AS alias" for the column (possibly None).
The klass_... |
Return three values:
- a list of 3-tuples of (expression, (sql, params), alias)
- a klass_info structure,
- a dictionary of annotations | def get_select(self):
"""
Return three values:
- a list of 3-tuples of (expression, (sql, params), alias)
- a klass_info structure,
- a dictionary of annotations
The (sql, params) is what the expression will produce, and alias is the
"AS alias" for the column (po... | [
"def",
"get_select",
"(",
"self",
")",
":",
"select",
"=",
"[",
"]",
"klass_info",
"=",
"None",
"annotations",
"=",
"{",
"}",
"select_idx",
"=",
"0",
"for",
"alias",
",",
"(",
"sql",
",",
"params",
")",
"in",
"self",
".",
"query",
".",
"extra_select"... | [
194,
4
] | [
264,
43
] | python | en | ['en', 'error', 'th'] | False |
get_order_by | (self) |
Return a list of 2-tuples of form (expr, (sql, params, is_ref)) for the
ORDER BY clause.
The order_by clause can alter the select clause (for example it
can add aliases to clauses that do not yet have one, or it can
add totally new select clauses).
|
Return a list of 2-tuples of form (expr, (sql, params, is_ref)) for the
ORDER BY clause. | def get_order_by(self):
"""
Return a list of 2-tuples of form (expr, (sql, params, is_ref)) for the
ORDER BY clause.
The order_by clause can alter the select clause (for example it
can add aliases to clauses that do not yet have one, or it can
add totally new select clau... | [
"def",
"get_order_by",
"(",
"self",
")",
":",
"if",
"self",
".",
"query",
".",
"extra_order_by",
":",
"ordering",
"=",
"self",
".",
"query",
".",
"extra_order_by",
"elif",
"not",
"self",
".",
"query",
".",
"default_ordering",
":",
"ordering",
"=",
"self",
... | [
266,
4
] | [
388,
21
] | python | en | ['en', 'error', 'th'] | False |
quote_name_unless_alias | (self, name) |
A wrapper around connection.ops.quote_name that doesn't quote aliases
for table names. This avoids problems with some SQL dialects that treat
quoted strings specially (e.g. PostgreSQL).
|
A wrapper around connection.ops.quote_name that doesn't quote aliases
for table names. This avoids problems with some SQL dialects that treat
quoted strings specially (e.g. PostgreSQL).
| def quote_name_unless_alias(self, name):
"""
A wrapper around connection.ops.quote_name that doesn't quote aliases
for table names. This avoids problems with some SQL dialects that treat
quoted strings specially (e.g. PostgreSQL).
"""
if name in self.quote_cache:
... | [
"def",
"quote_name_unless_alias",
"(",
"self",
",",
"name",
")",
":",
"if",
"name",
"in",
"self",
".",
"quote_cache",
":",
"return",
"self",
".",
"quote_cache",
"[",
"name",
"]",
"if",
"(",
"(",
"name",
"in",
"self",
".",
"query",
".",
"alias_map",
"an... | [
400,
4
] | [
415,
16
] | python | en | ['en', 'error', 'th'] | False |
FormMixin.get_initial | (self) | Return the initial data to use for forms on this view. | Return the initial data to use for forms on this view. | def get_initial(self):
"""Return the initial data to use for forms on this view."""
return self.initial.copy() | [
"def",
"get_initial",
"(",
"self",
")",
":",
"return",
"self",
".",
"initial",
".",
"copy",
"(",
")"
] | [
16,
4
] | [
18,
34
] | python | en | ['en', 'en', 'en'] | True |
FormMixin.get_prefix | (self) | Return the prefix to use for forms. | Return the prefix to use for forms. | def get_prefix(self):
"""Return the prefix to use for forms."""
return self.prefix | [
"def",
"get_prefix",
"(",
"self",
")",
":",
"return",
"self",
".",
"prefix"
] | [
20,
4
] | [
22,
26
] | python | en | ['en', 'en', 'en'] | True |
FormMixin.get_form_class | (self) | Return the form class to use. | Return the form class to use. | def get_form_class(self):
"""Return the form class to use."""
return self.form_class | [
"def",
"get_form_class",
"(",
"self",
")",
":",
"return",
"self",
".",
"form_class"
] | [
24,
4
] | [
26,
30
] | python | en | ['en', 'en', 'en'] | True |
FormMixin.get_form | (self, form_class=None) | Return an instance of the form to be used in this view. | Return an instance of the form to be used in this view. | def get_form(self, form_class=None):
"""Return an instance of the form to be used in this view."""
if form_class is None:
form_class = self.get_form_class()
return form_class(**self.get_form_kwargs()) | [
"def",
"get_form",
"(",
"self",
",",
"form_class",
"=",
"None",
")",
":",
"if",
"form_class",
"is",
"None",
":",
"form_class",
"=",
"self",
".",
"get_form_class",
"(",
")",
"return",
"form_class",
"(",
"*",
"*",
"self",
".",
"get_form_kwargs",
"(",
")",
... | [
28,
4
] | [
32,
51
] | python | en | ['en', 'en', 'en'] | True |
FormMixin.get_form_kwargs | (self) | Return the keyword arguments for instantiating the form. | Return the keyword arguments for instantiating the form. | def get_form_kwargs(self):
"""Return the keyword arguments for instantiating the form."""
kwargs = {
'initial': self.get_initial(),
'prefix': self.get_prefix(),
}
if self.request.method in ('POST', 'PUT'):
kwargs.update({
'data': self.... | [
"def",
"get_form_kwargs",
"(",
"self",
")",
":",
"kwargs",
"=",
"{",
"'initial'",
":",
"self",
".",
"get_initial",
"(",
")",
",",
"'prefix'",
":",
"self",
".",
"get_prefix",
"(",
")",
",",
"}",
"if",
"self",
".",
"request",
".",
"method",
"in",
"(",
... | [
34,
4
] | [
46,
21
] | python | en | ['en', 'da', 'en'] | True |
FormMixin.get_success_url | (self) | Return the URL to redirect to after processing a valid form. | Return the URL to redirect to after processing a valid form. | def get_success_url(self):
"""Return the URL to redirect to after processing a valid form."""
if not self.success_url:
raise ImproperlyConfigured("No URL to redirect to. Provide a success_url.")
return str(self.success_url) | [
"def",
"get_success_url",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"success_url",
":",
"raise",
"ImproperlyConfigured",
"(",
"\"No URL to redirect to. Provide a success_url.\"",
")",
"return",
"str",
"(",
"self",
".",
"success_url",
")"
] | [
48,
4
] | [
52,
36
] | python | en | ['en', 'en', 'en'] | True |
FormMixin.form_valid | (self, form) | If the form is valid, redirect to the supplied URL. | If the form is valid, redirect to the supplied URL. | def form_valid(self, form):
"""If the form is valid, redirect to the supplied URL."""
return HttpResponseRedirect(self.get_success_url()) | [
"def",
"form_valid",
"(",
"self",
",",
"form",
")",
":",
"return",
"HttpResponseRedirect",
"(",
"self",
".",
"get_success_url",
"(",
")",
")"
] | [
54,
4
] | [
56,
59
] | python | en | ['en', 'en', 'en'] | True |
FormMixin.form_invalid | (self, form) | If the form is invalid, render the invalid form. | If the form is invalid, render the invalid form. | def form_invalid(self, form):
"""If the form is invalid, render the invalid form."""
return self.render_to_response(self.get_context_data(form=form)) | [
"def",
"form_invalid",
"(",
"self",
",",
"form",
")",
":",
"return",
"self",
".",
"render_to_response",
"(",
"self",
".",
"get_context_data",
"(",
"form",
"=",
"form",
")",
")"
] | [
58,
4
] | [
60,
72
] | python | en | ['en', 'en', 'en'] | True |
FormMixin.get_context_data | (self, **kwargs) | Insert the form into the context dict. | Insert the form into the context dict. | def get_context_data(self, **kwargs):
"""Insert the form into the context dict."""
if 'form' not in kwargs:
kwargs['form'] = self.get_form()
return super().get_context_data(**kwargs) | [
"def",
"get_context_data",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"'form'",
"not",
"in",
"kwargs",
":",
"kwargs",
"[",
"'form'",
"]",
"=",
"self",
".",
"get_form",
"(",
")",
"return",
"super",
"(",
")",
".",
"get_context_data",
"(",
"*... | [
62,
4
] | [
66,
49
] | python | en | ['en', 'en', 'en'] | True |
ModelFormMixin.get_form_class | (self) | Return the form class to use in this view. | Return the form class to use in this view. | def get_form_class(self):
"""Return the form class to use in this view."""
if self.fields is not None and self.form_class:
raise ImproperlyConfigured(
"Specifying both 'fields' and 'form_class' is not permitted."
)
if self.form_class:
return se... | [
"def",
"get_form_class",
"(",
"self",
")",
":",
"if",
"self",
".",
"fields",
"is",
"not",
"None",
"and",
"self",
".",
"form_class",
":",
"raise",
"ImproperlyConfigured",
"(",
"\"Specifying both 'fields' and 'form_class' is not permitted.\"",
")",
"if",
"self",
".",
... | [
73,
4
] | [
100,
75
] | python | en | ['en', 'en', 'en'] | True |
ModelFormMixin.get_form_kwargs | (self) | Return the keyword arguments for instantiating the form. | Return the keyword arguments for instantiating the form. | def get_form_kwargs(self):
"""Return the keyword arguments for instantiating the form."""
kwargs = super().get_form_kwargs()
if hasattr(self, 'object'):
kwargs.update({'instance': self.object})
return kwargs | [
"def",
"get_form_kwargs",
"(",
"self",
")",
":",
"kwargs",
"=",
"super",
"(",
")",
".",
"get_form_kwargs",
"(",
")",
"if",
"hasattr",
"(",
"self",
",",
"'object'",
")",
":",
"kwargs",
".",
"update",
"(",
"{",
"'instance'",
":",
"self",
".",
"object",
... | [
102,
4
] | [
107,
21
] | python | en | ['en', 'da', 'en'] | True |
ModelFormMixin.get_success_url | (self) | Return the URL to redirect to after processing a valid form. | Return the URL to redirect to after processing a valid form. | def get_success_url(self):
"""Return the URL to redirect to after processing a valid form."""
if self.success_url:
url = self.success_url.format(**self.object.__dict__)
else:
try:
url = self.object.get_absolute_url()
except AttributeError:
... | [
"def",
"get_success_url",
"(",
"self",
")",
":",
"if",
"self",
".",
"success_url",
":",
"url",
"=",
"self",
".",
"success_url",
".",
"format",
"(",
"*",
"*",
"self",
".",
"object",
".",
"__dict__",
")",
"else",
":",
"try",
":",
"url",
"=",
"self",
... | [
109,
4
] | [
120,
18
] | python | en | ['en', 'en', 'en'] | True |
ModelFormMixin.form_valid | (self, form) | If the form is valid, save the associated model. | If the form is valid, save the associated model. | def form_valid(self, form):
"""If the form is valid, save the associated model."""
self.object = form.save()
return super().form_valid(form) | [
"def",
"form_valid",
"(",
"self",
",",
"form",
")",
":",
"self",
".",
"object",
"=",
"form",
".",
"save",
"(",
")",
"return",
"super",
"(",
")",
".",
"form_valid",
"(",
"form",
")"
] | [
122,
4
] | [
125,
39
] | python | en | ['en', 'en', 'en'] | True |
ProcessFormView.get | (self, request, *args, **kwargs) | Handle GET requests: instantiate a blank version of the form. | Handle GET requests: instantiate a blank version of the form. | def get(self, request, *args, **kwargs):
"""Handle GET requests: instantiate a blank version of the form."""
return self.render_to_response(self.get_context_data()) | [
"def",
"get",
"(",
"self",
",",
"request",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
"self",
".",
"render_to_response",
"(",
"self",
".",
"get_context_data",
"(",
")",
")"
] | [
130,
4
] | [
132,
63
] | python | en | ['en', 'en', 'en'] | True |
ProcessFormView.post | (self, request, *args, **kwargs) |
Handle POST requests: instantiate a form instance with the passed
POST variables and then check if it's valid.
|
Handle POST requests: instantiate a form instance with the passed
POST variables and then check if it's valid.
| def post(self, request, *args, **kwargs):
"""
Handle POST requests: instantiate a form instance with the passed
POST variables and then check if it's valid.
"""
form = self.get_form()
if form.is_valid():
return self.form_valid(form)
else:
r... | [
"def",
"post",
"(",
"self",
",",
"request",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"form",
"=",
"self",
".",
"get_form",
"(",
")",
"if",
"form",
".",
"is_valid",
"(",
")",
":",
"return",
"self",
".",
"form_valid",
"(",
"form",
")",
... | [
134,
4
] | [
143,
42
] | python | en | ['en', 'error', 'th'] | False |
DeletionMixin.delete | (self, request, *args, **kwargs) |
Call the delete() method on the fetched object and then redirect to the
success URL.
|
Call the delete() method on the fetched object and then redirect to the
success URL.
| def delete(self, request, *args, **kwargs):
"""
Call the delete() method on the fetched object and then redirect to the
success URL.
"""
self.object = self.get_object()
success_url = self.get_success_url()
self.object.delete()
return HttpResponseRedirect(s... | [
"def",
"delete",
"(",
"self",
",",
"request",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"object",
"=",
"self",
".",
"get_object",
"(",
")",
"success_url",
"=",
"self",
".",
"get_success_url",
"(",
")",
"self",
".",
"object",
... | [
205,
4
] | [
213,
48
] | python | en | ['en', 'error', 'th'] | False |
FallbackTest.stored_messages_count | (self, storage, response) |
Return the storage totals from both cookie and session backends.
|
Return the storage totals from both cookie and session backends.
| def stored_messages_count(self, storage, response):
"""
Return the storage totals from both cookie and session backends.
"""
total = (self.stored_cookie_messages_count(storage, response) +
self.stored_session_messages_count(storage, response))
return total | [
"def",
"stored_messages_count",
"(",
"self",
",",
"storage",
",",
"response",
")",
":",
"total",
"=",
"(",
"self",
".",
"stored_cookie_messages_count",
"(",
"storage",
",",
"response",
")",
"+",
"self",
".",
"stored_session_messages_count",
"(",
"storage",
",",
... | [
33,
4
] | [
39,
20
] | python | en | ['en', 'error', 'th'] | False |
FallbackTest.test_no_fallback | (self) |
Confirms that:
(1) A short number of messages whose data size doesn't exceed what is
allowed in a cookie will all be stored in the CookieBackend.
(2) If the CookieBackend can store all messages, the SessionBackend
won't be written to at all.
|
Confirms that: | def test_no_fallback(self):
"""
Confirms that:
(1) A short number of messages whose data size doesn't exceed what is
allowed in a cookie will all be stored in the CookieBackend.
(2) If the CookieBackend can store all messages, the SessionBackend
won't be written to at a... | [
"def",
"test_no_fallback",
"(",
"self",
")",
":",
"storage",
"=",
"self",
".",
"get_storage",
"(",
")",
"response",
"=",
"self",
".",
"get_response",
"(",
")",
"# Overwrite the _store method of the fallback storage to prove it isn't",
"# used (it would cause a TypeError: 'N... | [
116,
4
] | [
140,
44
] | python | en | ['en', 'error', 'th'] | False |
FallbackTest.test_session_fallback | (self) |
Confirms that, if the data exceeds what is allowed in a cookie,
messages which did not fit are stored in the SessionBackend.
|
Confirms that, if the data exceeds what is allowed in a cookie,
messages which did not fit are stored in the SessionBackend.
| def test_session_fallback(self):
"""
Confirms that, if the data exceeds what is allowed in a cookie,
messages which did not fit are stored in the SessionBackend.
"""
storage = self.get_storage()
response = self.get_response()
# see comment in CookieText.test_cook... | [
"def",
"test_session_fallback",
"(",
"self",
")",
":",
"storage",
"=",
"self",
".",
"get_storage",
"(",
")",
"response",
"=",
"self",
".",
"get_response",
"(",
")",
"# see comment in CookieText.test_cookie_max_length",
"msg_size",
"=",
"int",
"(",
"(",
"CookieStor... | [
142,
4
] | [
159,
44
] | python | en | ['en', 'error', 'th'] | False |
FallbackTest.test_session_fallback_only | (self) |
Confirms that large messages, none of which fit in a cookie, are stored
in the SessionBackend (and nothing is stored in the CookieBackend).
|
Confirms that large messages, none of which fit in a cookie, are stored
in the SessionBackend (and nothing is stored in the CookieBackend).
| def test_session_fallback_only(self):
"""
Confirms that large messages, none of which fit in a cookie, are stored
in the SessionBackend (and nothing is stored in the CookieBackend).
"""
storage = self.get_storage()
response = self.get_response()
storage.add(const... | [
"def",
"test_session_fallback_only",
"(",
"self",
")",
":",
"storage",
"=",
"self",
".",
"get_storage",
"(",
")",
"response",
"=",
"self",
".",
"get_response",
"(",
")",
"storage",
".",
"add",
"(",
"constants",
".",
"INFO",
",",
"'x'",
"*",
"5000",
")",
... | [
161,
4
] | [
175,
44
] | python | en | ['en', 'error', 'th'] | False |
get_openapi_fixture | (endpoint: str, method: str, status_code: str = "200") | Fetch a fixture from the full spec object. | Fetch a fixture from the full spec object. | def get_openapi_fixture(endpoint: str, method: str, status_code: str = "200") -> Dict[str, Any]:
"""Fetch a fixture from the full spec object."""
return get_schema(endpoint, method, status_code)["example"] | [
"def",
"get_openapi_fixture",
"(",
"endpoint",
":",
"str",
",",
"method",
":",
"str",
",",
"status_code",
":",
"str",
"=",
"\"200\"",
")",
"->",
"Dict",
"[",
"str",
",",
"Any",
"]",
":",
"return",
"get_schema",
"(",
"endpoint",
",",
"method",
",",
"sta... | [
205,
0
] | [
207,
63
] | python | en | ['en', 'en', 'en'] | True |
get_openapi_description | (endpoint: str, method: str) | Fetch a description from the full spec object. | Fetch a description from the full spec object. | def get_openapi_description(endpoint: str, method: str) -> str:
"""Fetch a description from the full spec object."""
return openapi_spec.openapi()["paths"][endpoint][method.lower()]["description"] | [
"def",
"get_openapi_description",
"(",
"endpoint",
":",
"str",
",",
"method",
":",
"str",
")",
"->",
"str",
":",
"return",
"openapi_spec",
".",
"openapi",
"(",
")",
"[",
"\"paths\"",
"]",
"[",
"endpoint",
"]",
"[",
"method",
".",
"lower",
"(",
")",
"]"... | [
210,
0
] | [
212,
83
] | python | en | ['en', 'en', 'en'] | True |
fix_events | (content: Dict[str, Any]) | Remove undocumented events from events array. This is a makeshift
function so that further documentation of `/events` can happen with
only zulip.yaml changes and minimal other changes. It should be removed
as soon as `/events` documentation is complete.
| Remove undocumented events from events array. This is a makeshift
function so that further documentation of `/events` can happen with
only zulip.yaml changes and minimal other changes. It should be removed
as soon as `/events` documentation is complete.
| def fix_events(content: Dict[str, Any]) -> None:
"""Remove undocumented events from events array. This is a makeshift
function so that further documentation of `/events` can happen with
only zulip.yaml changes and minimal other changes. It should be removed
as soon as `/events` documentation is complete... | [
"def",
"fix_events",
"(",
"content",
":",
"Dict",
"[",
"str",
",",
"Any",
"]",
")",
"->",
"None",
":",
"# 'user' is deprecated so remove its occurrences from the events array",
"for",
"event",
"in",
"content",
"[",
"\"events\"",
"]",
":",
"event",
".",
"pop",
"(... | [
255,
0
] | [
263,
31
] | python | en | ['en', 'en', 'en'] | True |
validate_against_openapi_schema | (
content: Dict[str, Any],
path: str,
method: str,
status_code: str,
display_brief_error: bool = False,
) | Compare a "content" dict with the defined schema for a specific method
in an endpoint. Return true if validated and false if skipped.
| Compare a "content" dict with the defined schema for a specific method
in an endpoint. Return true if validated and false if skipped.
| def validate_against_openapi_schema(
content: Dict[str, Any],
path: str,
method: str,
status_code: str,
display_brief_error: bool = False,
) -> bool:
"""Compare a "content" dict with the defined schema for a specific method
in an endpoint. Return true if validated and false if skipped.
"... | [
"def",
"validate_against_openapi_schema",
"(",
"content",
":",
"Dict",
"[",
"str",
",",
"Any",
"]",
",",
"path",
":",
"str",
",",
"method",
":",
"str",
",",
"status_code",
":",
"str",
",",
"display_brief_error",
":",
"bool",
"=",
"False",
",",
")",
"->",... | [
266,
0
] | [
353,
15
] | python | en | ['en', 'en', 'en'] | True |
validate_schema | (schema: Dict[str, Any]) | Check if opaque objects are present in the OpenAPI spec; this is an
important part of our policy for ensuring every detail of Zulip's
API responses is correct.
This is done by checking for the presence of the
`additionalProperties` attribute for all objects (dictionaries).
| Check if opaque objects are present in the OpenAPI spec; this is an
important part of our policy for ensuring every detail of Zulip's
API responses is correct. | def validate_schema(schema: Dict[str, Any]) -> None:
"""Check if opaque objects are present in the OpenAPI spec; this is an
important part of our policy for ensuring every detail of Zulip's
API responses is correct.
This is done by checking for the presence of the
`additionalProperties` attribute f... | [
"def",
"validate_schema",
"(",
"schema",
":",
"Dict",
"[",
"str",
",",
"Any",
"]",
")",
"->",
"None",
":",
"if",
"\"oneOf\"",
"in",
"schema",
":",
"for",
"subschema",
"in",
"schema",
"[",
"\"oneOf\"",
"]",
":",
"validate_schema",
"(",
"subschema",
")",
... | [
356,
0
] | [
378,
59
] | python | en | ['en', 'en', 'en'] | True |
to_python_type | (py_type: str) | Transform an OpenAPI-like type to a Python one.
https://swagger.io/docs/specification/data-models/data-types
| Transform an OpenAPI-like type to a Python one.
https://swagger.io/docs/specification/data-models/data-types
| def to_python_type(py_type: str) -> type:
"""Transform an OpenAPI-like type to a Python one.
https://swagger.io/docs/specification/data-models/data-types
"""
TYPES = {
"string": str,
"number": float,
"integer": int,
"boolean": bool,
"array": list,
"object"... | [
"def",
"to_python_type",
"(",
"py_type",
":",
"str",
")",
"->",
"type",
":",
"TYPES",
"=",
"{",
"\"string\"",
":",
"str",
",",
"\"number\"",
":",
"float",
",",
"\"integer\"",
":",
"int",
",",
"\"boolean\"",
":",
"bool",
",",
"\"array\"",
":",
"list",
"... | [
381,
0
] | [
394,
25
] | python | en | ['en', 'haw', 'en'] | True |
OpenAPISpec.openapi | (self) | Reload the OpenAPI file if it has been modified after the last time
it was read, and then return the parsed data.
| Reload the OpenAPI file if it has been modified after the last time
it was read, and then return the parsed data.
| def openapi(self) -> Dict[str, Any]:
"""Reload the OpenAPI file if it has been modified after the last time
it was read, and then return the parsed data.
"""
self.check_reload()
assert len(self._openapi) > 0
return self._openapi | [
"def",
"openapi",
"(",
"self",
")",
"->",
"Dict",
"[",
"str",
",",
"Any",
"]",
":",
"self",
".",
"check_reload",
"(",
")",
"assert",
"len",
"(",
"self",
".",
"_openapi",
")",
">",
"0",
"return",
"self",
".",
"_openapi"
] | [
148,
4
] | [
154,
28
] | python | en | ['en', 'en', 'en'] | True |
OpenAPISpec.endpoints_dict | (self) | Reload the OpenAPI file if it has been modified after the last time
it was read, and then return the parsed data.
| Reload the OpenAPI file if it has been modified after the last time
it was read, and then return the parsed data.
| def endpoints_dict(self) -> Dict[str, str]:
"""Reload the OpenAPI file if it has been modified after the last time
it was read, and then return the parsed data.
"""
self.check_reload()
assert len(self._endpoints_dict) > 0
return self._endpoints_dict | [
"def",
"endpoints_dict",
"(",
"self",
")",
"->",
"Dict",
"[",
"str",
",",
"str",
"]",
":",
"self",
".",
"check_reload",
"(",
")",
"assert",
"len",
"(",
"self",
".",
"_endpoints_dict",
")",
">",
"0",
"return",
"self",
".",
"_endpoints_dict"
] | [
156,
4
] | [
162,
35
] | python | en | ['en', 'en', 'en'] | True |
OpenAPISpec.request_validator | (self) | Reload the OpenAPI file if it has been modified after the last time
it was read, and then return the openapi_core validator object. Similar
to preceding functions. Used for proper access to OpenAPI objects.
| Reload the OpenAPI file if it has been modified after the last time
it was read, and then return the openapi_core validator object. Similar
to preceding functions. Used for proper access to OpenAPI objects.
| def request_validator(self) -> RequestValidator:
"""Reload the OpenAPI file if it has been modified after the last time
it was read, and then return the openapi_core validator object. Similar
to preceding functions. Used for proper access to OpenAPI objects.
"""
self.check_reload... | [
"def",
"request_validator",
"(",
"self",
")",
"->",
"RequestValidator",
":",
"self",
".",
"check_reload",
"(",
")",
"assert",
"self",
".",
"_request_validator",
"is",
"not",
"None",
"return",
"self",
".",
"_request_validator"
] | [
164,
4
] | [
171,
38
] | python | en | ['en', 'en', 'en'] | True |
_check_dist_requires_python | (
dist, # type: pkg_resources.Distribution
version_info, # type: Tuple[int, int, int]
ignore_requires_python=False, # type: bool
) |
Check whether the given Python version is compatible with a distribution's
"Requires-Python" value.
:param version_info: A 3-tuple of ints representing the Python
major-minor-micro version to check.
:param ignore_requires_python: Whether to ignore the "Requires-Python"
value if the giv... |
Check whether the given Python version is compatible with a distribution's
"Requires-Python" value. | def _check_dist_requires_python(
dist, # type: pkg_resources.Distribution
version_info, # type: Tuple[int, int, int]
ignore_requires_python=False, # type: bool
):
# type: (...) -> None
"""
Check whether the given Python version is compatible with a distribution's
"Requires-Python" value.
... | [
"def",
"_check_dist_requires_python",
"(",
"dist",
",",
"# type: pkg_resources.Distribution",
"version_info",
",",
"# type: Tuple[int, int, int]",
"ignore_requires_python",
"=",
"False",
",",
"# type: bool",
")",
":",
"# type: (...) -> None",
"requires_python",
"=",
"get_requir... | [
57,
0
] | [
102,
10
] | python | en | ['en', 'error', 'th'] | False |
Resolver.resolve | (self, root_reqs, check_supported_wheels) | Resolve what operations need to be done
As a side-effect of this method, the packages (and their dependencies)
are downloaded, unpacked and prepared for installation. This
preparation is done by ``pip.operations.prepare``.
Once PyPI has static dependency metadata available, it would be... | Resolve what operations need to be done | def resolve(self, root_reqs, check_supported_wheels):
# type: (List[InstallRequirement], bool) -> RequirementSet
"""Resolve what operations need to be done
As a side-effect of this method, the packages (and their dependencies)
are downloaded, unpacked and prepared for installation. This... | [
"def",
"resolve",
"(",
"self",
",",
"root_reqs",
",",
"check_supported_wheels",
")",
":",
"# type: (List[InstallRequirement], bool) -> RequirementSet",
"requirement_set",
"=",
"RequirementSet",
"(",
"check_supported_wheels",
"=",
"check_supported_wheels",
")",
"for",
"req",
... | [
152,
4
] | [
186,
30
] | python | en | ['en', 'en', 'en'] | True |
Resolver._set_req_to_reinstall | (self, req) |
Set a requirement to be installed.
|
Set a requirement to be installed.
| def _set_req_to_reinstall(self, req):
# type: (InstallRequirement) -> None
"""
Set a requirement to be installed.
"""
# Don't uninstall the conflict if doing a user install and the
# conflict is not a user install.
if not self.use_user_site or dist_in_usersite(req... | [
"def",
"_set_req_to_reinstall",
"(",
"self",
",",
"req",
")",
":",
"# type: (InstallRequirement) -> None",
"# Don't uninstall the conflict if doing a user install and the",
"# conflict is not a user install.",
"if",
"not",
"self",
".",
"use_user_site",
"or",
"dist_in_usersite",
"... | [
198,
4
] | [
207,
31
] | python | en | ['en', 'error', 'th'] | False |
Resolver._check_skip_installed | (self, req_to_install) | Check if req_to_install should be skipped.
This will check if the req is installed, and whether we should upgrade
or reinstall it, taking into account all the relevant user options.
After calling this req_to_install will only have satisfied_by set to
None if the req_to_install is to be... | Check if req_to_install should be skipped. | def _check_skip_installed(self, req_to_install):
# type: (InstallRequirement) -> Optional[str]
"""Check if req_to_install should be skipped.
This will check if the req is installed, and whether we should upgrade
or reinstall it, taking into account all the relevant user options.
... | [
"def",
"_check_skip_installed",
"(",
"self",
",",
"req_to_install",
")",
":",
"# type: (InstallRequirement) -> Optional[str]",
"if",
"self",
".",
"ignore_installed",
":",
"return",
"None",
"req_to_install",
".",
"check_if_exists",
"(",
"self",
".",
"use_user_site",
")",... | [
209,
4
] | [
260,
19
] | python | en | ['en', 'en', 'en'] | True |
Resolver._populate_link | (self, req) | Ensure that if a link can be found for this, that it is found.
Note that req.link may still be None - if the requirement is already
installed and not needed to be upgraded based on the return value of
_is_upgrade_allowed().
If preparer.require_hashes is True, don't use the wheel cache,... | Ensure that if a link can be found for this, that it is found. | def _populate_link(self, req):
# type: (InstallRequirement) -> None
"""Ensure that if a link can be found for this, that it is found.
Note that req.link may still be None - if the requirement is already
installed and not needed to be upgraded based on the return value of
_is_upg... | [
"def",
"_populate_link",
"(",
"self",
",",
"req",
")",
":",
"# type: (InstallRequirement) -> None",
"upgrade",
"=",
"self",
".",
"_is_upgrade_allowed",
"(",
"req",
")",
"if",
"req",
".",
"link",
"is",
"None",
":",
"req",
".",
"link",
"=",
"self",
".",
"fin... | [
262,
4
] | [
291,
39
] | python | en | ['en', 'en', 'en'] | True |
Resolver._get_abstract_dist_for | (self, req) | Takes a InstallRequirement and returns a single AbstractDist \
representing a prepared variant of the same.
| Takes a InstallRequirement and returns a single AbstractDist \
representing a prepared variant of the same.
| def _get_abstract_dist_for(self, req):
# type: (InstallRequirement) -> AbstractDistribution
"""Takes a InstallRequirement and returns a single AbstractDist \
representing a prepared variant of the same.
"""
if req.editable:
return self.preparer.prepare_editable_requir... | [
"def",
"_get_abstract_dist_for",
"(",
"self",
",",
"req",
")",
":",
"# type: (InstallRequirement) -> AbstractDistribution",
"if",
"req",
".",
"editable",
":",
"return",
"self",
".",
"preparer",
".",
"prepare_editable_requirement",
"(",
"req",
")",
"# satisfied_by is onl... | [
293,
4
] | [
341,
28
] | python | en | ['en', 'en', 'en'] | True |
Resolver._resolve_one | (
self,
requirement_set, # type: RequirementSet
req_to_install, # type: InstallRequirement
) | Prepare a single requirements file.
:return: A list of additional InstallRequirements to also install.
| Prepare a single requirements file. | def _resolve_one(
self,
requirement_set, # type: RequirementSet
req_to_install, # type: InstallRequirement
):
# type: (...) -> List[InstallRequirement]
"""Prepare a single requirements file.
:return: A list of additional InstallRequirements to also install.
... | [
"def",
"_resolve_one",
"(",
"self",
",",
"requirement_set",
",",
"# type: RequirementSet",
"req_to_install",
",",
"# type: InstallRequirement",
")",
":",
"# type: (...) -> List[InstallRequirement]",
"# Tell user what we are doing for this requirement:",
"# obtain (editable), skipping, ... | [
343,
4
] | [
430,
24
] | python | en | ['en', 'it', 'en'] | True |
Resolver.get_installation_order | (self, req_set) | Create the installation order.
The installation order is topological - requirements are installed
before the requiring thing. We break cycles at an arbitrary point,
and make no other guarantees.
| Create the installation order. | def get_installation_order(self, req_set):
# type: (RequirementSet) -> List[InstallRequirement]
"""Create the installation order.
The installation order is topological - requirements are installed
before the requiring thing. We break cycles at an arbitrary point,
and make no oth... | [
"def",
"get_installation_order",
"(",
"self",
",",
"req_set",
")",
":",
"# type: (RequirementSet) -> List[InstallRequirement]",
"# The current implementation, which we may change at any point",
"# installs the user specified things in the order given, except when",
"# dependencies must come ea... | [
432,
4
] | [
458,
20
] | python | en | ['en', 'en', 'en'] | True |
StateManager.get_resource_services | (self) | Return the list of services with clonesquad:group-name tags
| Return the list of services with clonesquad:group-name tags
| def get_resource_services(self):
""" Return the list of services with clonesquad:group-name tags
"""
services = []
for r in self.get_resources():
arn = r["ResourceARN"]
m = re.search("^arn:[a-z]+:([a-z0-9]+):([-a-z0-9]+):([0-9]+):(.+)", arn)
if m[1] ... | [
"def",
"get_resource_services",
"(",
"self",
")",
":",
"services",
"=",
"[",
"]",
"for",
"r",
"in",
"self",
".",
"get_resources",
"(",
")",
":",
"arn",
"=",
"r",
"[",
"\"ResourceARN\"",
"]",
"m",
"=",
"re",
".",
"search",
"(",
"\"^arn:[a-z]+:([a-z0-9]+):... | [
55,
4
] | [
64,
23
] | python | en | ['en', 'en', 'en'] | True |
classes | (field) |
Returns CSS classes of a field
|
Returns CSS classes of a field
| def classes(field):
"""
Returns CSS classes of a field
"""
return field.widget.attrs.get("class", None) | [
"def",
"classes",
"(",
"field",
")",
":",
"return",
"field",
".",
"widget",
".",
"attrs",
".",
"get",
"(",
"\"class\"",
",",
"None",
")"
] | [
50,
0
] | [
54,
48
] | python | en | ['en', 'ja', 'th'] | False |
css_class | (field) |
Returns widgets class name in lowercase
|
Returns widgets class name in lowercase
| def css_class(field):
"""
Returns widgets class name in lowercase
"""
return field.field.widget.__class__.__name__.lower() | [
"def",
"css_class",
"(",
"field",
")",
":",
"return",
"field",
".",
"field",
".",
"widget",
".",
"__class__",
".",
"__name__",
".",
"lower",
"(",
")"
] | [
58,
0
] | [
62,
56
] | python | en | ['en', 'ja', 'th'] | False |
pairwise | (iterable) | s -> (s0,s1), (s2,s3), (s4, s5), ... | s -> (s0,s1), (s2,s3), (s4, s5), ... | def pairwise(iterable):
"""s -> (s0,s1), (s2,s3), (s4, s5), ..."""
a = iter(iterable)
return zip(a, a) | [
"def",
"pairwise",
"(",
"iterable",
")",
":",
"a",
"=",
"iter",
"(",
"iterable",
")",
"return",
"zip",
"(",
"a",
",",
"a",
")"
] | [
65,
0
] | [
68,
20
] | python | en | ['en', 'sr', 'hi'] | False |
crispy_field | (parser, token) |
{% crispy_field field attrs %}
|
{% crispy_field field attrs %}
| def crispy_field(parser, token):
"""
{% crispy_field field attrs %}
"""
token = token.split_contents()
field = token.pop(1)
attrs = {}
# We need to pop tag name, or pairwise would fail
token.pop(0)
for attribute_name, value in pairwise(token):
attrs[attribute_name... | [
"def",
"crispy_field",
"(",
"parser",
",",
"token",
")",
":",
"token",
"=",
"token",
".",
"split_contents",
"(",
")",
"field",
"=",
"token",
".",
"pop",
"(",
"1",
")",
"attrs",
"=",
"{",
"}",
"# We need to pop tag name, or pairwise would fail\r",
"token",
".... | [
158,
0
] | [
171,
40
] | python | en | ['en', 'ja', 'th'] | False |
crispy_addon | (field, append="", prepend="", form_show_labels=True) |
Renders a form field using bootstrap's prepended or appended text::
{% crispy_addon form.my_field prepend="$" append=".00" %}
You can also just prepend or append like so
{% crispy_addon form.my_field prepend="$" %}
{% crispy_addon form.my_field append=".00" %}
|
Renders a form field using bootstrap's prepended or appended text::
{% crispy_addon form.my_field prepend="$" append=".00" %}
You can also just prepend or append like so
{% crispy_addon form.my_field prepend="$" %}
{% crispy_addon form.my_field append=".00" %}
| def crispy_addon(field, append="", prepend="", form_show_labels=True):
"""
Renders a form field using bootstrap's prepended or appended text::
{% crispy_addon form.my_field prepend="$" append=".00" %}
You can also just prepend or append like so
{% crispy_addon form.my_field prepen... | [
"def",
"crispy_addon",
"(",
"field",
",",
"append",
"=",
"\"\"",
",",
"prepend",
"=",
"\"\"",
",",
"form_show_labels",
"=",
"True",
")",
":",
"if",
"field",
":",
"context",
"=",
"Context",
"(",
"{",
"\"field\"",
":",
"field",
",",
"\"form_show_errors\"",
... | [
175,
0
] | [
197,
35
] | python | en | ['en', 'ja', 'th'] | False |
get_internal_wsgi_application | () |
Loads and returns the WSGI application as configured by the user in
``settings.WSGI_APPLICATION``. With the default ``startproject`` layout,
this will be the ``application`` object in ``projectname/wsgi.py``.
This function, and the ``WSGI_APPLICATION`` setting itself, are only useful
for Django's ... |
Loads and returns the WSGI application as configured by the user in
``settings.WSGI_APPLICATION``. With the default ``startproject`` layout,
this will be the ``application`` object in ``projectname/wsgi.py``. | def get_internal_wsgi_application():
"""
Loads and returns the WSGI application as configured by the user in
``settings.WSGI_APPLICATION``. With the default ``startproject`` layout,
this will be the ``application`` object in ``projectname/wsgi.py``.
This function, and the ``WSGI_APPLICATION`` setti... | [
"def",
"get_internal_wsgi_application",
"(",
")",
":",
"from",
"django",
".",
"conf",
"import",
"settings",
"app_path",
"=",
"getattr",
"(",
"settings",
",",
"'WSGI_APPLICATION'",
")",
"if",
"app_path",
"is",
"None",
":",
"return",
"get_wsgi_application",
"(",
"... | [
26,
0
] | [
57,
38
] | python | en | ['en', 'error', 'th'] | False |
WSGIServer.server_bind | (self) | Override server_bind to store the server name. | Override server_bind to store the server name. | def server_bind(self):
"""Override server_bind to store the server name."""
super(WSGIServer, self).server_bind()
self.setup_environ() | [
"def",
"server_bind",
"(",
"self",
")",
":",
"super",
"(",
"WSGIServer",
",",
"self",
")",
".",
"server_bind",
"(",
")",
"self",
".",
"setup_environ",
"(",
")"
] | [
70,
4
] | [
73,
28
] | python | en | ['en', 'en', 'en'] | True |
EventAwaiterThread.__init__ | (self, event_callback, exchange, subscription_ids, timeout_minutes=20) |
:param event_callback: A function to call when an event is received.
:type event_callback: function[respa_exchange.ews.notifications.StreamingEvent]
:param exchange: The Exchange configuration the thread is bound to
:type exchange: respa_exchange.models.ExchangeConfiguration
:pa... |
:param event_callback: A function to call when an event is received.
:type event_callback: function[respa_exchange.ews.notifications.StreamingEvent]
:param exchange: The Exchange configuration the thread is bound to
:type exchange: respa_exchange.models.ExchangeConfiguration
:pa... | def __init__(self, event_callback, exchange, subscription_ids, timeout_minutes=20):
"""
:param event_callback: A function to call when an event is received.
:type event_callback: function[respa_exchange.ews.notifications.StreamingEvent]
:param exchange: The Exchange configuration the thr... | [
"def",
"__init__",
"(",
"self",
",",
"event_callback",
",",
"exchange",
",",
"subscription_ids",
",",
"timeout_minutes",
"=",
"20",
")",
":",
"assert",
"callable",
"(",
"event_callback",
")",
"self",
".",
"event_callback",
"=",
"event_callback",
"self",
".",
"... | [
34,
4
] | [
53,
79
] | python | en | ['en', 'error', 'th'] | False |
EventAwaiterThread.run | (self) | Method representing the thread's activity. (See superclass.) | Method representing the thread's activity. (See superclass.) | def run(self):
"""Method representing the thread's activity. (See superclass.)"""
sess = self.exchange.get_ews_session()
failures = 0
last_loop_time = 0
while not self.please_stop:
try:
event_req = GetStreamingEventsRequest(
subscri... | [
"def",
"run",
"(",
"self",
")",
":",
"sess",
"=",
"self",
".",
"exchange",
".",
"get_ews_session",
"(",
")",
"failures",
"=",
"0",
"last_loop_time",
"=",
"0",
"while",
"not",
"self",
".",
"please_stop",
":",
"try",
":",
"event_req",
"=",
"GetStreamingEve... | [
55,
4
] | [
99,
26
] | python | en | ['en', 'en', 'en'] | True |
ExchangeListener.manage_subscriptions | (self) |
Ensure the subscription map is up to date.
This is called periodically by the `subscription_manage_timer` timeout.
|
Ensure the subscription map is up to date. | def manage_subscriptions(self):
"""
Ensure the subscription map is up to date.
This is called periodically by the `subscription_manage_timer` timeout.
"""
resources = set(get_active_download_resources(exchange_configs=[self.exchange]))
new_resources = set(resources) - se... | [
"def",
"manage_subscriptions",
"(",
"self",
")",
":",
"resources",
"=",
"set",
"(",
"get_active_download_resources",
"(",
"exchange_configs",
"=",
"[",
"self",
".",
"exchange",
"]",
")",
")",
"new_resources",
"=",
"set",
"(",
"resources",
")",
"-",
"set",
"(... | [
114,
4
] | [
149,
42
] | python | en | ['en', 'error', 'th'] | False |
ExchangeListener.subscribe_resource | (self, resource) |
Attempt to create an Exchange subscription for the given resource.
:param resource: The resource to subscribe.
:type resource: respa_exchange.models.Resource
|
Attempt to create an Exchange subscription for the given resource. | def subscribe_resource(self, resource):
"""
Attempt to create an Exchange subscription for the given resource.
:param resource: The resource to subscribe.
:type resource: respa_exchange.models.Resource
"""
assert self.exchange == resource.exchange
sess = self.exc... | [
"def",
"subscribe_resource",
"(",
"self",
",",
"resource",
")",
":",
"assert",
"self",
".",
"exchange",
"==",
"resource",
".",
"exchange",
"sess",
"=",
"self",
".",
"exchange",
".",
"get_ews_session",
"(",
")",
"sub",
"=",
"SubscribeRequest",
"(",
"resource"... | [
151,
4
] | [
163,
68
] | python | en | ['en', 'error', 'th'] | False |
ExchangeListener.unsubscribe_resource | (self, resource) |
Attempt to remove an existing Exchange subscription for the given resource.
If we don't know about a subscription for that resource, nothing happens
and False is returned.
:param resource: The resource to subscribe.
:type resource: respa_exchange.models.Resource
:retur... |
Attempt to remove an existing Exchange subscription for the given resource. | def unsubscribe_resource(self, resource):
"""
Attempt to remove an existing Exchange subscription for the given resource.
If we don't know about a subscription for that resource, nothing happens
and False is returned.
:param resource: The resource to subscribe.
:type re... | [
"def",
"unsubscribe_resource",
"(",
"self",
",",
"resource",
")",
":",
"assert",
"self",
".",
"exchange",
"==",
"resource",
".",
"exchange",
"sub_id",
"=",
"self",
".",
"resource_to_subscription_map",
".",
"pop",
"(",
"resource",
",",
"None",
")",
"if",
"not... | [
165,
4
] | [
185,
19
] | python | en | ['en', 'error', 'th'] | False |
ExchangeListener.spawn_thread | (self) |
Spawn event awaiter thread for newly created subscriptions.
|
Spawn event awaiter thread for newly created subscriptions.
| def spawn_thread(self):
"""
Spawn event awaiter thread for newly created subscriptions.
"""
if self.listener_thread and not self.listener_thread.dead:
return
subscription_ids = self.resource_to_subscription_map.values()
self.listener_thread = EventAwaiterThr... | [
"def",
"spawn_thread",
"(",
"self",
")",
":",
"if",
"self",
".",
"listener_thread",
"and",
"not",
"self",
".",
"listener_thread",
".",
"dead",
":",
"return",
"subscription_ids",
"=",
"self",
".",
"resource_to_subscription_map",
".",
"values",
"(",
")",
"self",... | [
187,
4
] | [
202,
67
] | python | en | ['en', 'error', 'th'] | False |
ExchangeListener.close | (self) |
Close all related resources (unsubscribe in Exchange and reap threads).
This is called automatically by `.start()` when the loop ends, but it should be
safe to call from wherever.
|
Close all related resources (unsubscribe in Exchange and reap threads). | def close(self):
"""
Close all related resources (unsubscribe in Exchange and reap threads).
This is called automatically by `.start()` when the loop ends, but it should be
safe to call from wherever.
"""
self.please_stop = True
if self.listener_thread:
... | [
"def",
"close",
"(",
"self",
")",
":",
"self",
".",
"please_stop",
"=",
"True",
"if",
"self",
".",
"listener_thread",
":",
"self",
".",
"listener_thread",
".",
"stop",
"(",
")",
"for",
"resource",
"in",
"list",
"(",
"self",
".",
"resource_to_subscription_m... | [
225,
4
] | [
236,
47
] | python | en | ['en', 'error', 'th'] | False |
NotificationListener.start | (self) |
Start the listener.
This method will not return unless an unexpected exception occurs,
or if `.stop()` is called (likely from another thread of control).
|
Start the listener. | def start(self):
"""
Start the listener.
This method will not return unless an unexpected exception occurs,
or if `.stop()` is called (likely from another thread of control).
"""
self.subscription_manage_timer.reset()
self.database_reconnect_timer.reset()
... | [
"def",
"start",
"(",
"self",
")",
":",
"self",
".",
"subscription_manage_timer",
".",
"reset",
"(",
")",
"self",
".",
"database_reconnect_timer",
".",
"reset",
"(",
")",
"self",
".",
"_please_stop",
"=",
"False",
"log",
".",
"debug",
"(",
"'Starting listener... | [
262,
4
] | [
282,
24
] | python | en | ['en', 'error', 'th'] | False |
NotificationListener.stop | (self) |
Stop the listener, if it's active.
In bad situations, this might not actually do anything, though.
|
Stop the listener, if it's active. | def stop(self):
"""
Stop the listener, if it's active.
In bad situations, this might not actually do anything, though.
"""
self._please_stop = True | [
"def",
"stop",
"(",
"self",
")",
":",
"self",
".",
"_please_stop",
"=",
"True"
] | [
284,
4
] | [
290,
32
] | python | en | ['en', 'error', 'th'] | False |
NotificationListener.step | (self) |
Run a single step of the listener management loop.
This is a semi-public API; you shouldn't need to have to call
this unless you're reimplementing the `.start()` loop yourself.
|
Run a single step of the listener management loop. | def step(self):
"""
Run a single step of the listener management loop.
This is a semi-public API; you shouldn't need to have to call
this unless you're reimplementing the `.start()` loop yourself.
"""
self.subscription_manage_timer.check()
self.database_reconnect... | [
"def",
"step",
"(",
"self",
")",
":",
"self",
".",
"subscription_manage_timer",
".",
"check",
"(",
")",
"self",
".",
"database_reconnect_timer",
".",
"check",
"(",
")",
"# handle_events() will sleep if no events are available",
"self",
".",
"handle_events",
"(",
")"... | [
292,
4
] | [
302,
28
] | python | en | ['en', 'error', 'th'] | False |
NotificationListener.post_event | (self, event) |
Post an event into the listener's event queue.
(The queue is drained by `handle_events`.)
This is the API by which respa_exchange.listener.EventAwaiterThread
objects interface with the listener.
If you are subclassing NotificationListener, this would be a
spectacularly... |
Post an event into the listener's event queue.
(The queue is drained by `handle_events`.) | def post_event(self, event):
"""
Post an event into the listener's event queue.
(The queue is drained by `handle_events`.)
This is the API by which respa_exchange.listener.EventAwaiterThread
objects interface with the listener.
If you are subclassing NotificationListene... | [
"def",
"post_event",
"(",
"self",
",",
"event",
")",
":",
"self",
".",
"events",
".",
"put",
"(",
"event",
")",
"log",
".",
"debug",
"(",
"'Event received: %s'",
",",
"event",
")"
] | [
304,
4
] | [
319,
46
] | python | en | ['en', 'error', 'th'] | False |
NotificationListener.reconnect_database | (self) |
Reconnect all Django databases.
This is run periodically to ensure we won't get "Database
has gone away" or whatnot since we're holding an idle connection.
|
Reconnect all Django databases. | def reconnect_database(self):
"""
Reconnect all Django databases.
This is run periodically to ensure we won't get "Database
has gone away" or whatnot since we're holding an idle connection.
"""
for conn in connections.all():
try:
conn.connect(... | [
"def",
"reconnect_database",
"(",
"self",
")",
":",
"for",
"conn",
"in",
"connections",
".",
"all",
"(",
")",
":",
"try",
":",
"conn",
".",
"connect",
"(",
")",
"except",
"Exception",
"as",
"e",
":",
"log",
".",
"exception",
"(",
"'Failed reconnecting %s... | [
321,
4
] | [
332,
74
] | python | en | ['en', 'error', 'th'] | False |
NotificationListener.handle_events | (self) |
Process whatever events are in the event queue.
Returns when the event queue is drained.
|
Process whatever events are in the event queue. | def handle_events(self):
"""
Process whatever events are in the event queue.
Returns when the event queue is drained.
"""
changed_resources = set()
while True:
try:
event = self.events.get(timeout=1)
if hasattr(self.events, 'ta... | [
"def",
"handle_events",
"(",
"self",
")",
":",
"changed_resources",
"=",
"set",
"(",
")",
"while",
"True",
":",
"try",
":",
"event",
"=",
"self",
".",
"events",
".",
"get",
"(",
"timeout",
"=",
"1",
")",
"if",
"hasattr",
"(",
"self",
".",
"events",
... | [
338,
4
] | [
373,
40
] | python | en | ['en', 'error', 'th'] | False |
DatabaseSchemaEditor._alter_column_type_sql | (self, table, column, type) |
Makes ALTER TYPE with SERIAL make sense.
|
Makes ALTER TYPE with SERIAL make sense.
| def _alter_column_type_sql(self, table, column, type):
"""
Makes ALTER TYPE with SERIAL make sense.
"""
if type.lower() == "serial":
sequence_name = "%s_%s_seq" % (table, column)
return (
(
self.sql_alter_column_type % {
... | [
"def",
"_alter_column_type_sql",
"(",
"self",
",",
"table",
",",
"column",
",",
"type",
")",
":",
"if",
"type",
".",
"lower",
"(",
")",
"==",
"\"serial\"",
":",
"sequence_name",
"=",
"\"%s_%s_seq\"",
"%",
"(",
"table",
",",
"column",
")",
"return",
"(",
... | [
14,
4
] | [
62,
96
] | python | en | ['en', 'error', 'th'] | False |
load_images | (input_dir, batch_shape) | Read png images from input directory in batches.
Args:
input_dir: input directory
batch_shape: shape of minibatch array, i.e. [batch_size, height, width, 3]
Yields:
filenames: list file names without path of each image
Lenght of this list could be less than batch_size, in this case o... | Read png images from input directory in batches. | def load_images(input_dir, batch_shape):
"""Read png images from input directory in batches.
Args:
input_dir: input directory
batch_shape: shape of minibatch array, i.e. [batch_size, height, width, 3]
Yields:
filenames: list file names without path of each image
Lenght of this li... | [
"def",
"load_images",
"(",
"input_dir",
",",
"batch_shape",
")",
":",
"images",
"=",
"np",
".",
"zeros",
"(",
"batch_shape",
")",
"filenames",
"=",
"[",
"]",
"idx",
"=",
"0",
"batch_size",
"=",
"batch_shape",
"[",
"0",
"]",
"for",
"filepath",
"in",
"tf... | [
40,
0
] | [
70,
31
] | python | en | ['en', 'en', 'en'] | True |
sparse_l1_descent | (
x,
logits,
y=None,
eps=1.0,
q=99,
clip_min=None,
clip_max=None,
clip_grad=False,
targeted=False,
sanity_checks=True,
) |
TensorFlow implementation of the Dense L1 Descent Method.
:param x: the input placeholder
:param logits: output of model.get_logits
:param y: (optional) A placeholder for the true labels. If targeted
is true, then provide the target label. Otherwise, only provide
this parame... |
TensorFlow implementation of the Dense L1 Descent Method.
:param x: the input placeholder
:param logits: output of model.get_logits
:param y: (optional) A placeholder for the true labels. If targeted
is true, then provide the target label. Otherwise, only provide
this parame... | def sparse_l1_descent(
x,
logits,
y=None,
eps=1.0,
q=99,
clip_min=None,
clip_max=None,
clip_grad=False,
targeted=False,
sanity_checks=True,
):
"""
TensorFlow implementation of the Dense L1 Descent Method.
:param x: the input placeholder
:param logits: output of mo... | [
"def",
"sparse_l1_descent",
"(",
"x",
",",
"logits",
",",
"y",
"=",
"None",
",",
"eps",
"=",
"1.0",
",",
"q",
"=",
"99",
",",
"clip_min",
"=",
"None",
",",
"clip_max",
"=",
"None",
",",
"clip_grad",
"=",
"False",
",",
"targeted",
"=",
"False",
",",... | [
258,
0
] | [
364,
16
] | python | en | ['en', 'error', 'th'] | False |
SparseL1Descent.__init__ | (self, model, sess=None, dtypestr="float32", **kwargs) |
Create a SparseL1Descent instance.
Note: the model parameter should be an instance of the
cleverhans.model.Model abstraction provided by CleverHans.
|
Create a SparseL1Descent instance.
Note: the model parameter should be an instance of the
cleverhans.model.Model abstraction provided by CleverHans.
| def __init__(self, model, sess=None, dtypestr="float32", **kwargs):
"""
Create a SparseL1Descent instance.
Note: the model parameter should be an instance of the
cleverhans.model.Model abstraction provided by CleverHans.
"""
super(SparseL1Descent, self).__init__(
... | [
"def",
"__init__",
"(",
"self",
",",
"model",
",",
"sess",
"=",
"None",
",",
"dtypestr",
"=",
"\"float32\"",
",",
"*",
"*",
"kwargs",
")",
":",
"super",
"(",
"SparseL1Descent",
",",
"self",
")",
".",
"__init__",
"(",
"model",
",",
"sess",
"=",
"sess"... | [
35,
4
] | [
54,
87
] | python | en | ['en', 'error', 'th'] | False |
SparseL1Descent.generate | (self, x, **kwargs) |
Generate symbolic graph for adversarial examples and return.
:param x: The model's symbolic inputs.
:param kwargs: See `parse_params`
|
Generate symbolic graph for adversarial examples and return. | def generate(self, x, **kwargs):
"""
Generate symbolic graph for adversarial examples and return.
:param x: The model's symbolic inputs.
:param kwargs: See `parse_params`
"""
# Parse and save attack-specific parameters
assert self.parse_params(**kwargs)
... | [
"def",
"generate",
"(",
"self",
",",
"x",
",",
"*",
"*",
"kwargs",
")",
":",
"# Parse and save attack-specific parameters",
"assert",
"self",
".",
"parse_params",
"(",
"*",
"*",
"kwargs",
")",
"asserts",
"=",
"[",
"]",
"# If a data range was specified, check that ... | [
56,
4
] | [
167,
20
] | python | en | ['en', 'error', 'th'] | False |
SparseL1Descent.parse_params | (
self,
eps=10.0,
eps_iter=1.0,
nb_iter=20,
y=None,
clip_min=None,
clip_max=None,
y_target=None,
rand_init=False,
clip_grad=False,
grad_sparsity=99,
sanity_checks=True,
**kwargs
) |
Take in a dictionary of parameters and applies attack-specific checks
before saving them as attributes.
Attack-specific parameters:
:param eps: (optional float) maximum distortion of adversarial example
compared to original input
:param eps_iter: (optional ... |
Take in a dictionary of parameters and applies attack-specific checks
before saving them as attributes. | def parse_params(
self,
eps=10.0,
eps_iter=1.0,
nb_iter=20,
y=None,
clip_min=None,
clip_max=None,
y_target=None,
rand_init=False,
clip_grad=False,
grad_sparsity=99,
sanity_checks=True,
**kwargs
):
"""
... | [
"def",
"parse_params",
"(",
"self",
",",
"eps",
"=",
"10.0",
",",
"eps_iter",
"=",
"1.0",
",",
"nb_iter",
"=",
"20",
",",
"y",
"=",
"None",
",",
"clip_min",
"=",
"None",
",",
"clip_max",
"=",
"None",
",",
"y_target",
"=",
"None",
",",
"rand_init",
... | [
169,
4
] | [
255,
19
] | python | en | ['en', 'error', 'th'] | False |
get_connection | (backend=None, fail_silently=False, **kwds) | Load an email backend and return an instance of it.
If backend is None (default) settings.EMAIL_BACKEND is used.
Both fail_silently and other keyword arguments are used in the
constructor of the backend.
| Load an email backend and return an instance of it. | def get_connection(backend=None, fail_silently=False, **kwds):
"""Load an email backend and return an instance of it.
If backend is None (default) settings.EMAIL_BACKEND is used.
Both fail_silently and other keyword arguments are used in the
constructor of the backend.
"""
klass = import_strin... | [
"def",
"get_connection",
"(",
"backend",
"=",
"None",
",",
"fail_silently",
"=",
"False",
",",
"*",
"*",
"kwds",
")",
":",
"klass",
"=",
"import_string",
"(",
"backend",
"or",
"settings",
".",
"EMAIL_BACKEND",
")",
"return",
"klass",
"(",
"fail_silently",
... | [
28,
0
] | [
37,
53
] | python | en | ['en', 'en', 'en'] | True |
send_mail | (subject, message, from_email, recipient_list,
fail_silently=False, auth_user=None, auth_password=None,
connection=None, html_message=None) |
Easy wrapper for sending a single message to a recipient list. All members
of the recipient list will see the other recipients in the 'To' field.
If auth_user is None, the EMAIL_HOST_USER setting is used.
If auth_password is None, the EMAIL_HOST_PASSWORD setting is used.
Note: The API for this me... |
Easy wrapper for sending a single message to a recipient list. All members
of the recipient list will see the other recipients in the 'To' field. | def send_mail(subject, message, from_email, recipient_list,
fail_silently=False, auth_user=None, auth_password=None,
connection=None, html_message=None):
"""
Easy wrapper for sending a single message to a recipient list. All members
of the recipient list will see the other recipi... | [
"def",
"send_mail",
"(",
"subject",
",",
"message",
",",
"from_email",
",",
"recipient_list",
",",
"fail_silently",
"=",
"False",
",",
"auth_user",
"=",
"None",
",",
"auth_password",
"=",
"None",
",",
"connection",
"=",
"None",
",",
"html_message",
"=",
"Non... | [
40,
0
] | [
61,
22
] | python | en | ['en', 'error', 'th'] | False |
send_mass_mail | (datatuple, fail_silently=False, auth_user=None,
auth_password=None, connection=None) |
Given a datatuple of (subject, message, from_email, recipient_list), sends
each message to each recipient list. Returns the number of emails sent.
If from_email is None, the DEFAULT_FROM_EMAIL setting is used.
If auth_user and auth_password are set, they're used to log in.
If auth_user is None, th... |
Given a datatuple of (subject, message, from_email, recipient_list), sends
each message to each recipient list. Returns the number of emails sent. | def send_mass_mail(datatuple, fail_silently=False, auth_user=None,
auth_password=None, connection=None):
"""
Given a datatuple of (subject, message, from_email, recipient_list), sends
each message to each recipient list. Returns the number of emails sent.
If from_email is None, the D... | [
"def",
"send_mass_mail",
"(",
"datatuple",
",",
"fail_silently",
"=",
"False",
",",
"auth_user",
"=",
"None",
",",
"auth_password",
"=",
"None",
",",
"connection",
"=",
"None",
")",
":",
"connection",
"=",
"connection",
"or",
"get_connection",
"(",
"username",... | [
64,
0
] | [
84,
45
] | python | en | ['en', 'error', 'th'] | False |
mail_admins | (subject, message, fail_silently=False, connection=None,
html_message=None) | Sends a message to the admins, as defined by the ADMINS setting. | Sends a message to the admins, as defined by the ADMINS setting. | def mail_admins(subject, message, fail_silently=False, connection=None,
html_message=None):
"""Sends a message to the admins, as defined by the ADMINS setting."""
if not settings.ADMINS:
return
mail = EmailMultiAlternatives('%s%s' % (settings.EMAIL_SUBJECT_PREFIX, subject),
... | [
"def",
"mail_admins",
"(",
"subject",
",",
"message",
",",
"fail_silently",
"=",
"False",
",",
"connection",
"=",
"None",
",",
"html_message",
"=",
"None",
")",
":",
"if",
"not",
"settings",
".",
"ADMINS",
":",
"return",
"mail",
"=",
"EmailMultiAlternatives"... | [
87,
0
] | [
97,
42
] | python | en | ['en', 'en', 'en'] | True |
mail_managers | (subject, message, fail_silently=False, connection=None,
html_message=None) | Sends a message to the managers, as defined by the MANAGERS setting. | Sends a message to the managers, as defined by the MANAGERS setting. | def mail_managers(subject, message, fail_silently=False, connection=None,
html_message=None):
"""Sends a message to the managers, as defined by the MANAGERS setting."""
if not settings.MANAGERS:
return
mail = EmailMultiAlternatives('%s%s' % (settings.EMAIL_SUBJECT_PREFIX, subject),... | [
"def",
"mail_managers",
"(",
"subject",
",",
"message",
",",
"fail_silently",
"=",
"False",
",",
"connection",
"=",
"None",
",",
"html_message",
"=",
"None",
")",
":",
"if",
"not",
"settings",
".",
"MANAGERS",
":",
"return",
"mail",
"=",
"EmailMultiAlternati... | [
100,
0
] | [
110,
42
] | python | en | ['en', 'en', 'en'] | True |
build_py.get_data_files | (self) | Generate list of '(package,src_dir,build_dir,filenames)' tuples | Generate list of '(package,src_dir,build_dir,filenames)' tuples | def get_data_files(self):
"""Generate list of '(package,src_dir,build_dir,filenames)' tuples"""
data = []
if not self.packages:
return data
for package in self.packages:
# Locate package source directory
src_dir = self.get_package_dir(package)
... | [
"def",
"get_data_files",
"(",
"self",
")",
":",
"data",
"=",
"[",
"]",
"if",
"not",
"self",
".",
"packages",
":",
"return",
"data",
"for",
"package",
"in",
"self",
".",
"packages",
":",
"# Locate package source directory",
"src_dir",
"=",
"self",
".",
"get... | [
96,
4
] | [
118,
19
] | python | en | ['en', 'af', 'en'] | True |
build_py.find_data_files | (self, package, src_dir) | Return filenames for package's data files in 'src_dir | Return filenames for package's data files in 'src_dir | def find_data_files(self, package, src_dir):
"""Return filenames for package's data files in 'src_dir'"""
globs = (self.package_data.get('', [])
+ self.package_data.get(package, []))
files = []
for pattern in globs:
# Each pattern has to be converted to a pla... | [
"def",
"find_data_files",
"(",
"self",
",",
"package",
",",
"src_dir",
")",
":",
"globs",
"=",
"(",
"self",
".",
"package_data",
".",
"get",
"(",
"''",
",",
"[",
"]",
")",
"+",
"self",
".",
"package_data",
".",
"get",
"(",
"package",
",",
"[",
"]",... | [
120,
4
] | [
131,
20
] | python | en | ['en', 'no', 'en'] | True |
build_py.build_package_data | (self) | Copy data files into build directory | Copy data files into build directory | def build_package_data(self):
"""Copy data files into build directory"""
lastdir = None
for package, src_dir, build_dir, filenames in self.data_files:
for filename in filenames:
target = os.path.join(build_dir, filename)
self.mkpath(os.path.dirname(tar... | [
"def",
"build_package_data",
"(",
"self",
")",
":",
"lastdir",
"=",
"None",
"for",
"package",
",",
"src_dir",
",",
"build_dir",
",",
"filenames",
"in",
"self",
".",
"data_files",
":",
"for",
"filename",
"in",
"filenames",
":",
"target",
"=",
"os",
".",
"... | [
133,
4
] | [
141,
51
] | python | en | ['en', 'en', 'en'] | True |
build_py.get_package_dir | (self, package) | Return the directory, relative to the top of the source
distribution, where package 'package' should be found
(at least according to the 'package_dir' option, if any). | Return the directory, relative to the top of the source
distribution, where package 'package' should be found
(at least according to the 'package_dir' option, if any). | def get_package_dir(self, package):
"""Return the directory, relative to the top of the source
distribution, where package 'package' should be found
(at least according to the 'package_dir' option, if any)."""
path = package.split('.')
if not self.package_dir:
... | [
"def",
"get_package_dir",
"(",
"self",
",",
"package",
")",
":",
"path",
"=",
"package",
".",
"split",
"(",
"'.'",
")",
"if",
"not",
"self",
".",
"package_dir",
":",
"if",
"path",
":",
"return",
"os",
".",
"path",
".",
"join",
"(",
"*",
"path",
")"... | [
143,
4
] | [
180,
29
] | python | en | ['en', 'en', 'en'] | True |
build_py.find_modules | (self) | Finds individually-specified Python modules, ie. those listed by
module name in 'self.py_modules'. Returns a list of tuples (package,
module_base, filename): 'package' is a tuple of the path through
package-space to the module; 'module_base' is the bare (no
packages, no dots) module nam... | Finds individually-specified Python modules, ie. those listed by
module name in 'self.py_modules'. Returns a list of tuples (package,
module_base, filename): 'package' is a tuple of the path through
package-space to the module; 'module_base' is the bare (no
packages, no dots) module nam... | def find_modules(self):
"""Finds individually-specified Python modules, ie. those listed by
module name in 'self.py_modules'. Returns a list of tuples (package,
module_base, filename): 'package' is a tuple of the path through
package-space to the module; 'module_base' is the bare (no
... | [
"def",
"find_modules",
"(",
"self",
")",
":",
"# Map package names to tuples of useful info about the package:",
"# (package_dir, checked)",
"# package_dir - the directory where we'll find source files for",
"# this package",
"# checked - true if we have checked that the package directory",... | [
231,
4
] | [
281,
22
] | python | en | ['en', 'en', 'en'] | True |
build_py.find_all_modules | (self) | Compute the list of all modules that will be built, whether
they are specified one-module-at-a-time ('self.py_modules') or
by whole packages ('self.packages'). Return a list of tuples
(package, module, module_file), just like 'find_modules()' and
'find_package_modules()' do. | Compute the list of all modules that will be built, whether
they are specified one-module-at-a-time ('self.py_modules') or
by whole packages ('self.packages'). Return a list of tuples
(package, module, module_file), just like 'find_modules()' and
'find_package_modules()' do. | def find_all_modules(self):
"""Compute the list of all modules that will be built, whether
they are specified one-module-at-a-time ('self.py_modules') or
by whole packages ('self.packages'). Return a list of tuples
(package, module, module_file), just like 'find_modules()' and
'... | [
"def",
"find_all_modules",
"(",
"self",
")",
":",
"modules",
"=",
"[",
"]",
"if",
"self",
".",
"py_modules",
":",
"modules",
".",
"extend",
"(",
"self",
".",
"find_modules",
"(",
")",
")",
"if",
"self",
".",
"packages",
":",
"for",
"package",
"in",
"... | [
283,
4
] | [
297,
22
] | python | en | ['en', 'en', 'en'] | True |
get_ogr_db_string | () |
Construct the DB string that GDAL will use to inspect the database.
GDAL will create its own connection to the database, so we re-use the
connection settings from the Django test.
|
Construct the DB string that GDAL will use to inspect the database.
GDAL will create its own connection to the database, so we re-use the
connection settings from the Django test.
| def get_ogr_db_string():
"""
Construct the DB string that GDAL will use to inspect the database.
GDAL will create its own connection to the database, so we re-use the
connection settings from the Django test.
"""
db = connections.databases['default']
# Map from the django backend into the O... | [
"def",
"get_ogr_db_string",
"(",
")",
":",
"db",
"=",
"connections",
".",
"databases",
"[",
"'default'",
"]",
"# Map from the django backend into the OGR driver name and database identifier",
"# http://www.gdal.org/ogr/ogr_formats.html",
"#",
"# TODO: Support Oracle (OCI).",
"drive... | [
127,
0
] | [
174,
33
] | python | en | ['en', 'error', 'th'] | False |
_xml_escape | (data) | Escape &, <, >, ", ', etc. in a string of data. | Escape &, <, >, ", ', etc. in a string of data. | def _xml_escape(data):
"""Escape &, <, >, ", ', etc. in a string of data."""
# ampersand must be replaced first
from_symbols = '&><"\''
to_symbols = ('&'+s+';' for s in "amp gt lt quot apos".split())
for from_,to_ in zip(from_symbols, to_symbols):
data = data.replace(from_, to_)
... | [
"def",
"_xml_escape",
"(",
"data",
")",
":",
"# ampersand must be replaced first\r",
"from_symbols",
"=",
"'&><\"\\''",
"to_symbols",
"=",
"(",
"'&'",
"+",
"s",
"+",
"';'",
"for",
"s",
"in",
"\"amp gt lt quot apos\"",
".",
"split",
"(",
")",
")",
"for",
"from_... | [
184,
0
] | [
192,
15
] | python | en | ['en', 'en', 'en'] | True |
col | (loc,strg) | Returns current column within a string, counting newlines as line separators.
The first column is number 1.
Note: the default parsing behavior is to expand tabs in the input string
before starting the parsing process. See L{I{ParserElement.parseString}<ParserElement.parseString>} for more information
... | Returns current column within a string, counting newlines as line separators.
The first column is number 1.
Note: the default parsing behavior is to expand tabs in the input string
before starting the parsing process. See L{I{ParserElement.parseString}<ParserElement.parseString>} for more information
... | def col (loc,strg):
"""Returns current column within a string, counting newlines as line separators.
The first column is number 1.
Note: the default parsing behavior is to expand tabs in the input string
before starting the parsing process. See L{I{ParserElement.parseString}<ParserElement.parseStrin... | [
"def",
"col",
"(",
"loc",
",",
"strg",
")",
":",
"s",
"=",
"strg",
"return",
"1",
"if",
"0",
"<",
"loc",
"<",
"len",
"(",
"s",
")",
"and",
"s",
"[",
"loc",
"-",
"1",
"]",
"==",
"'\\n'",
"else",
"loc",
"-",
"s",
".",
"rfind",
"(",
"\"\\n\"",... | [
967,
0
] | [
978,
82
] | python | en | ['en', 'en', 'en'] | True |
lineno | (loc,strg) | Returns current line number within a string, counting newlines as line separators.
The first line is number 1.
Note: the default parsing behavior is to expand tabs in the input string
before starting the parsing process. See L{I{ParserElement.parseString}<ParserElement.parseString>} for more information
... | Returns current line number within a string, counting newlines as line separators.
The first line is number 1.
Note: the default parsing behavior is to expand tabs in the input string
before starting the parsing process. See L{I{ParserElement.parseString}<ParserElement.parseString>} for more information
... | def lineno(loc,strg):
"""Returns current line number within a string, counting newlines as line separators.
The first line is number 1.
Note: the default parsing behavior is to expand tabs in the input string
before starting the parsing process. See L{I{ParserElement.parseString}<ParserElement.parse... | [
"def",
"lineno",
"(",
"loc",
",",
"strg",
")",
":",
"return",
"strg",
".",
"count",
"(",
"\"\\n\"",
",",
"0",
",",
"loc",
")",
"+",
"1"
] | [
980,
0
] | [
990,
37
] | python | en | ['en', 'en', 'en'] | True |
line | ( loc, strg ) | Returns the line of text containing loc within a string, counting newlines as line separators.
| Returns the line of text containing loc within a string, counting newlines as line separators.
| def line( loc, strg ):
"""Returns the line of text containing loc within a string, counting newlines as line separators.
"""
lastCR = strg.rfind("\n", 0, loc)
nextCR = strg.find("\n", loc)
if nextCR >= 0:
return strg[lastCR+1:nextCR]
else:
return strg[lastCR+1:] | [
"def",
"line",
"(",
"loc",
",",
"strg",
")",
":",
"lastCR",
"=",
"strg",
".",
"rfind",
"(",
"\"\\n\"",
",",
"0",
",",
"loc",
")",
"nextCR",
"=",
"strg",
".",
"find",
"(",
"\"\\n\"",
",",
"loc",
")",
"if",
"nextCR",
">=",
"0",
":",
"return",
"st... | [
992,
0
] | [
1000,
30
] | 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.