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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
get_realms_and_streams_for_archiving | () |
This function constructs a list of (realm, streams_of_the_realm) tuples
where each realm is a Realm that requires calling the archiving functions on it,
and streams_of_the_realm is a list of streams of the realm to call archive_stream_messages with.
The purpose of this is performance - for servers wit... |
This function constructs a list of (realm, streams_of_the_realm) tuples
where each realm is a Realm that requires calling the archiving functions on it,
and streams_of_the_realm is a list of streams of the realm to call archive_stream_messages with. | def get_realms_and_streams_for_archiving() -> List[Tuple[Realm, List[Stream]]]:
"""
This function constructs a list of (realm, streams_of_the_realm) tuples
where each realm is a Realm that requires calling the archiving functions on it,
and streams_of_the_realm is a list of streams of the realm to call ... | [
"def",
"get_realms_and_streams_for_archiving",
"(",
")",
"->",
"List",
"[",
"Tuple",
"[",
"Realm",
",",
"List",
"[",
"Stream",
"]",
"]",
"]",
":",
"realm_id_to_realm",
"=",
"{",
"}",
"realm_id_to_streams_list",
":",
"Dict",
"[",
"int",
",",
"List",
"[",
"S... | [
438,
0
] | [
485,
5
] | python | en | ['en', 'error', 'th'] | False |
restore_retention_policy_deletions_for_stream | (stream: Stream) |
Utility function for calling in the Django shell if a stream's policy was
set to something too aggressive and the administrator wants to restore
the messages deleted as a result.
|
Utility function for calling in the Django shell if a stream's policy was
set to something too aggressive and the administrator wants to restore
the messages deleted as a result.
| def restore_retention_policy_deletions_for_stream(stream: Stream) -> None:
"""
Utility function for calling in the Django shell if a stream's policy was
set to something too aggressive and the administrator wants to restore
the messages deleted as a result.
"""
relevant_transactions = ArchiveTra... | [
"def",
"restore_retention_policy_deletions_for_stream",
"(",
"stream",
":",
"Stream",
")",
"->",
"None",
":",
"relevant_transactions",
"=",
"ArchiveTransaction",
".",
"objects",
".",
"filter",
"(",
"archivedmessage__recipient",
"=",
"stream",
".",
"recipient",
",",
"t... | [
656,
0
] | [
666,
74
] | python | en | ['en', 'error', 'th'] | False |
infix | (bp, func) |
Creates an infix operator, given a binding power and a function that
evaluates the node
|
Creates an infix operator, given a binding power and a function that
evaluates the node
| def infix(bp, func):
"""
Creates an infix operator, given a binding power and a function that
evaluates the node
"""
class Operator(TokenBase):
lbp = bp
def led(self, left, parser):
self.first = left
self.second = parser.expression(bp)
return self... | [
"def",
"infix",
"(",
"bp",
",",
"func",
")",
":",
"class",
"Operator",
"(",
"TokenBase",
")",
":",
"lbp",
"=",
"bp",
"def",
"led",
"(",
"self",
",",
"left",
",",
"parser",
")",
":",
"self",
".",
"first",
"=",
"left",
"self",
".",
"second",
"=",
... | [
43,
0
] | [
65,
19
] | python | en | ['en', 'error', 'th'] | False |
prefix | (bp, func) |
Creates a prefix operator, given a binding power and a function that
evaluates the node.
|
Creates a prefix operator, given a binding power and a function that
evaluates the node.
| def prefix(bp, func):
"""
Creates a prefix operator, given a binding power and a function that
evaluates the node.
"""
class Operator(TokenBase):
lbp = bp
def nud(self, parser):
self.first = parser.expression(bp)
self.second = None
return self
... | [
"def",
"prefix",
"(",
"bp",
",",
"func",
")",
":",
"class",
"Operator",
"(",
"TokenBase",
")",
":",
"lbp",
"=",
"bp",
"def",
"nud",
"(",
"self",
",",
"parser",
")",
":",
"self",
".",
"first",
"=",
"parser",
".",
"expression",
"(",
"bp",
")",
"sel... | [
68,
0
] | [
87,
19
] | python | en | ['en', 'error', 'th'] | False |
TokenBase.display | (self) |
Returns what to display in error messages for this node
|
Returns what to display in error messages for this node
| def display(self):
"""
Returns what to display in error messages for this node
"""
return self.id | [
"def",
"display",
"(",
"self",
")",
":",
"return",
"self",
".",
"id"
] | [
32,
4
] | [
36,
22
] | python | en | ['en', 'error', 'th'] | False |
i16le | (c, o=0) |
Converts a 2-bytes (16 bits) string to an unsigned integer.
:param c: string containing bytes to convert
:param o: offset of bytes to convert in string
|
Converts a 2-bytes (16 bits) string to an unsigned integer. | def i16le(c, o=0):
"""
Converts a 2-bytes (16 bits) string to an unsigned integer.
:param c: string containing bytes to convert
:param o: offset of bytes to convert in string
"""
return unpack_from("<H", c, o)[0] | [
"def",
"i16le",
"(",
"c",
",",
"o",
"=",
"0",
")",
":",
"return",
"unpack_from",
"(",
"\"<H\"",
",",
"c",
",",
"o",
")",
"[",
"0",
"]"
] | [
29,
0
] | [
36,
37
] | python | en | ['en', 'error', 'th'] | False |
si16le | (c, o=0) |
Converts a 2-bytes (16 bits) string to a signed integer.
:param c: string containing bytes to convert
:param o: offset of bytes to convert in string
|
Converts a 2-bytes (16 bits) string to a signed integer. | def si16le(c, o=0):
"""
Converts a 2-bytes (16 bits) string to a signed integer.
:param c: string containing bytes to convert
:param o: offset of bytes to convert in string
"""
return unpack_from("<h", c, o)[0] | [
"def",
"si16le",
"(",
"c",
",",
"o",
"=",
"0",
")",
":",
"return",
"unpack_from",
"(",
"\"<h\"",
",",
"c",
",",
"o",
")",
"[",
"0",
"]"
] | [
39,
0
] | [
46,
37
] | python | en | ['en', 'error', 'th'] | False |
i32le | (c, o=0) |
Converts a 4-bytes (32 bits) string to an unsigned integer.
:param c: string containing bytes to convert
:param o: offset of bytes to convert in string
|
Converts a 4-bytes (32 bits) string to an unsigned integer. | def i32le(c, o=0):
"""
Converts a 4-bytes (32 bits) string to an unsigned integer.
:param c: string containing bytes to convert
:param o: offset of bytes to convert in string
"""
return unpack_from("<I", c, o)[0] | [
"def",
"i32le",
"(",
"c",
",",
"o",
"=",
"0",
")",
":",
"return",
"unpack_from",
"(",
"\"<I\"",
",",
"c",
",",
"o",
")",
"[",
"0",
"]"
] | [
49,
0
] | [
56,
37
] | python | en | ['en', 'error', 'th'] | False |
si32le | (c, o=0) |
Converts a 4-bytes (32 bits) string to a signed integer.
:param c: string containing bytes to convert
:param o: offset of bytes to convert in string
|
Converts a 4-bytes (32 bits) string to a signed integer. | def si32le(c, o=0):
"""
Converts a 4-bytes (32 bits) string to a signed integer.
:param c: string containing bytes to convert
:param o: offset of bytes to convert in string
"""
return unpack_from("<i", c, o)[0] | [
"def",
"si32le",
"(",
"c",
",",
"o",
"=",
"0",
")",
":",
"return",
"unpack_from",
"(",
"\"<i\"",
",",
"c",
",",
"o",
")",
"[",
"0",
"]"
] | [
59,
0
] | [
66,
37
] | python | en | ['en', 'error', 'th'] | False |
UnitSerializer.get_extra_fields | (self, includes, context) | Define extra fields that can be included via query parameters. Method from ExtraDataMixin. | Define extra fields that can be included via query parameters. Method from ExtraDataMixin. | def get_extra_fields(self, includes, context):
""" Define extra fields that can be included via query parameters. Method from ExtraDataMixin."""
extra_fields = {}
if 'accessibility_summaries' in includes:
# TODO: think about populating "unknown" results here if no data is available
... | [
"def",
"get_extra_fields",
"(",
"self",
",",
"includes",
",",
"context",
")",
":",
"extra_fields",
"=",
"{",
"}",
"if",
"'accessibility_summaries'",
"in",
"includes",
":",
"# TODO: think about populating \"unknown\" results here if no data is available",
"extra_fields",
"["... | [
40,
4
] | [
47,
27
] | python | en | ['en', 'en', 'en'] | True |
XFrameOptionsMiddlewareTest.test_same_origin | (self) |
Tests that the X_FRAME_OPTIONS setting can be set to SAMEORIGIN to
have the middleware use that value for the HTTP header.
|
Tests that the X_FRAME_OPTIONS setting can be set to SAMEORIGIN to
have the middleware use that value for the HTTP header.
| def test_same_origin(self):
"""
Tests that the X_FRAME_OPTIONS setting can be set to SAMEORIGIN to
have the middleware use that value for the HTTP header.
"""
with override_settings(X_FRAME_OPTIONS='SAMEORIGIN'):
r = XFrameOptionsMiddleware().process_response(HttpRequ... | [
"def",
"test_same_origin",
"(",
"self",
")",
":",
"with",
"override_settings",
"(",
"X_FRAME_OPTIONS",
"=",
"'SAMEORIGIN'",
")",
":",
"r",
"=",
"XFrameOptionsMiddleware",
"(",
")",
".",
"process_response",
"(",
"HttpRequest",
"(",
")",
",",
"HttpResponse",
"(",
... | [
455,
4
] | [
468,
64
] | python | en | ['en', 'error', 'th'] | False |
XFrameOptionsMiddlewareTest.test_deny | (self) |
Tests that the X_FRAME_OPTIONS setting can be set to DENY to
have the middleware use that value for the HTTP header.
|
Tests that the X_FRAME_OPTIONS setting can be set to DENY to
have the middleware use that value for the HTTP header.
| def test_deny(self):
"""
Tests that the X_FRAME_OPTIONS setting can be set to DENY to
have the middleware use that value for the HTTP header.
"""
with override_settings(X_FRAME_OPTIONS='DENY'):
r = XFrameOptionsMiddleware().process_response(HttpRequest(),
... | [
"def",
"test_deny",
"(",
"self",
")",
":",
"with",
"override_settings",
"(",
"X_FRAME_OPTIONS",
"=",
"'DENY'",
")",
":",
"r",
"=",
"XFrameOptionsMiddleware",
"(",
")",
".",
"process_response",
"(",
"HttpRequest",
"(",
")",
",",
"HttpResponse",
"(",
")",
")",... | [
470,
4
] | [
483,
58
] | python | en | ['en', 'error', 'th'] | False |
XFrameOptionsMiddlewareTest.test_defaults_sameorigin | (self) |
Tests that if the X_FRAME_OPTIONS setting is not set then it defaults
to SAMEORIGIN.
|
Tests that if the X_FRAME_OPTIONS setting is not set then it defaults
to SAMEORIGIN.
| def test_defaults_sameorigin(self):
"""
Tests that if the X_FRAME_OPTIONS setting is not set then it defaults
to SAMEORIGIN.
"""
with override_settings(X_FRAME_OPTIONS=None):
del settings.X_FRAME_OPTIONS # restored by override_settings
r = XFrameOptions... | [
"def",
"test_defaults_sameorigin",
"(",
"self",
")",
":",
"with",
"override_settings",
"(",
"X_FRAME_OPTIONS",
"=",
"None",
")",
":",
"del",
"settings",
".",
"X_FRAME_OPTIONS",
"# restored by override_settings",
"r",
"=",
"XFrameOptionsMiddleware",
"(",
")",
".",
"p... | [
485,
4
] | [
494,
64
] | python | en | ['en', 'error', 'th'] | False |
XFrameOptionsMiddlewareTest.test_dont_set_if_set | (self) |
Tests that if the X-Frame-Options header is already set then the
middleware does not attempt to override it.
|
Tests that if the X-Frame-Options header is already set then the
middleware does not attempt to override it.
| def test_dont_set_if_set(self):
"""
Tests that if the X-Frame-Options header is already set then the
middleware does not attempt to override it.
"""
with override_settings(X_FRAME_OPTIONS='DENY'):
response = HttpResponse()
response['X-Frame-Options'] = 'SA... | [
"def",
"test_dont_set_if_set",
"(",
"self",
")",
":",
"with",
"override_settings",
"(",
"X_FRAME_OPTIONS",
"=",
"'DENY'",
")",
":",
"response",
"=",
"HttpResponse",
"(",
")",
"response",
"[",
"'X-Frame-Options'",
"]",
"=",
"'SAMEORIGIN'",
"r",
"=",
"XFrameOption... | [
496,
4
] | [
513,
58
] | python | en | ['en', 'error', 'th'] | False |
XFrameOptionsMiddlewareTest.test_response_exempt | (self) |
Tests that if the response has a xframe_options_exempt attribute set
to False then it still sets the header, but if it's set to True then
it does not.
|
Tests that if the response has a xframe_options_exempt attribute set
to False then it still sets the header, but if it's set to True then
it does not.
| def test_response_exempt(self):
"""
Tests that if the response has a xframe_options_exempt attribute set
to False then it still sets the header, but if it's set to True then
it does not.
"""
with override_settings(X_FRAME_OPTIONS='SAMEORIGIN'):
response = Http... | [
"def",
"test_response_exempt",
"(",
"self",
")",
":",
"with",
"override_settings",
"(",
"X_FRAME_OPTIONS",
"=",
"'SAMEORIGIN'",
")",
":",
"response",
"=",
"HttpResponse",
"(",
")",
"response",
".",
"xframe_options_exempt",
"=",
"False",
"r",
"=",
"XFrameOptionsMid... | [
515,
4
] | [
532,
66
] | python | en | ['en', 'error', 'th'] | False |
XFrameOptionsMiddlewareTest.test_is_extendable | (self) |
Tests that the XFrameOptionsMiddleware method that determines the
X-Frame-Options header value can be overridden based on something in
the request or response.
|
Tests that the XFrameOptionsMiddleware method that determines the
X-Frame-Options header value can be overridden based on something in
the request or response.
| def test_is_extendable(self):
"""
Tests that the XFrameOptionsMiddleware method that determines the
X-Frame-Options header value can be overridden based on something in
the request or response.
"""
class OtherXFrameOptionsMiddleware(XFrameOptionsMiddleware):
#... | [
"def",
"test_is_extendable",
"(",
"self",
")",
":",
"class",
"OtherXFrameOptionsMiddleware",
"(",
"XFrameOptionsMiddleware",
")",
":",
"# This is just an example for testing purposes...",
"def",
"get_xframe_options_value",
"(",
"self",
",",
"request",
",",
"response",
")",
... | [
534,
4
] | [
565,
58
] | python | en | ['en', 'error', 'th'] | False |
GZipMiddlewareTest.test_compress_response | (self) |
Tests that compression is performed on responses with compressible content.
|
Tests that compression is performed on responses with compressible content.
| def test_compress_response(self):
"""
Tests that compression is performed on responses with compressible content.
"""
r = GZipMiddleware().process_response(self.req, self.resp)
self.assertEqual(self.decompress(r.content), self.compressible_string)
self.assertEqual(r.get('... | [
"def",
"test_compress_response",
"(",
"self",
")",
":",
"r",
"=",
"GZipMiddleware",
"(",
")",
".",
"process_response",
"(",
"self",
".",
"req",
",",
"self",
".",
"resp",
")",
"self",
".",
"assertEqual",
"(",
"self",
".",
"decompress",
"(",
"r",
".",
"c... | [
597,
4
] | [
604,
70
] | python | en | ['en', 'error', 'th'] | False |
GZipMiddlewareTest.test_compress_streaming_response | (self) |
Tests that compression is performed on responses with streaming content.
|
Tests that compression is performed on responses with streaming content.
| def test_compress_streaming_response(self):
"""
Tests that compression is performed on responses with streaming content.
"""
r = GZipMiddleware().process_response(self.req, self.stream_resp)
self.assertEqual(self.decompress(b''.join(r)), b''.join(self.sequence))
self.asse... | [
"def",
"test_compress_streaming_response",
"(",
"self",
")",
":",
"r",
"=",
"GZipMiddleware",
"(",
")",
".",
"process_response",
"(",
"self",
".",
"req",
",",
"self",
".",
"stream_resp",
")",
"self",
".",
"assertEqual",
"(",
"self",
".",
"decompress",
"(",
... | [
606,
4
] | [
613,
56
] | python | en | ['en', 'error', 'th'] | False |
GZipMiddlewareTest.test_compress_non_200_response | (self) |
Tests that compression is performed on responses with a status other than 200.
See #10762.
|
Tests that compression is performed on responses with a status other than 200.
See #10762.
| def test_compress_non_200_response(self):
"""
Tests that compression is performed on responses with a status other than 200.
See #10762.
"""
self.resp.status_code = 404
r = GZipMiddleware().process_response(self.req, self.resp)
self.assertEqual(self.decompress(r.c... | [
"def",
"test_compress_non_200_response",
"(",
"self",
")",
":",
"self",
".",
"resp",
".",
"status_code",
"=",
"404",
"r",
"=",
"GZipMiddleware",
"(",
")",
".",
"process_response",
"(",
"self",
".",
"req",
",",
"self",
".",
"resp",
")",
"self",
".",
"asse... | [
615,
4
] | [
623,
59
] | python | en | ['en', 'error', 'th'] | False |
GZipMiddlewareTest.test_no_compress_short_response | (self) |
Tests that compression isn't performed on responses with short content.
|
Tests that compression isn't performed on responses with short content.
| def test_no_compress_short_response(self):
"""
Tests that compression isn't performed on responses with short content.
"""
self.resp.content = self.short_string
r = GZipMiddleware().process_response(self.req, self.resp)
self.assertEqual(r.content, self.short_string)
... | [
"def",
"test_no_compress_short_response",
"(",
"self",
")",
":",
"self",
".",
"resp",
".",
"content",
"=",
"self",
".",
"short_string",
"r",
"=",
"GZipMiddleware",
"(",
")",
".",
"process_response",
"(",
"self",
".",
"req",
",",
"self",
".",
"resp",
")",
... | [
625,
4
] | [
632,
57
] | python | en | ['en', 'error', 'th'] | False |
GZipMiddlewareTest.test_no_compress_compressed_response | (self) |
Tests that compression isn't performed on responses that are already compressed.
|
Tests that compression isn't performed on responses that are already compressed.
| def test_no_compress_compressed_response(self):
"""
Tests that compression isn't performed on responses that are already compressed.
"""
self.resp['Content-Encoding'] = 'deflate'
r = GZipMiddleware().process_response(self.req, self.resp)
self.assertEqual(r.content, self.c... | [
"def",
"test_no_compress_compressed_response",
"(",
"self",
")",
":",
"self",
".",
"resp",
"[",
"'Content-Encoding'",
"]",
"=",
"'deflate'",
"r",
"=",
"GZipMiddleware",
"(",
")",
".",
"process_response",
"(",
"self",
".",
"req",
",",
"self",
".",
"resp",
")"... | [
634,
4
] | [
641,
62
] | python | en | ['en', 'error', 'th'] | False |
GZipMiddlewareTest.test_no_compress_uncompressible_response | (self) |
Tests that compression isn't performed on responses with uncompressible content.
|
Tests that compression isn't performed on responses with uncompressible content.
| def test_no_compress_uncompressible_response(self):
"""
Tests that compression isn't performed on responses with uncompressible content.
"""
self.resp.content = self.uncompressible_string
r = GZipMiddleware().process_response(self.req, self.resp)
self.assertEqual(r.conten... | [
"def",
"test_no_compress_uncompressible_response",
"(",
"self",
")",
":",
"self",
".",
"resp",
".",
"content",
"=",
"self",
".",
"uncompressible_string",
"r",
"=",
"GZipMiddleware",
"(",
")",
".",
"process_response",
"(",
"self",
".",
"req",
",",
"self",
".",
... | [
643,
4
] | [
650,
57
] | python | en | ['en', 'error', 'th'] | False |
get_tag_uri | (url, date) |
Creates a TagURI.
See http://web.archive.org/web/20110514113830/http://diveintomark.org/archives/2004/05/28/howto-atom-id
|
Creates a TagURI. | def get_tag_uri(url, date):
"""
Creates a TagURI.
See http://web.archive.org/web/20110514113830/http://diveintomark.org/archives/2004/05/28/howto-atom-id
"""
bits = urlparse(url)
d = ''
if date is not None:
d = ',%s' % datetime_safe.new_datetime(date).strftime('%Y-%m-%d')
return... | [
"def",
"get_tag_uri",
"(",
"url",
",",
"date",
")",
":",
"bits",
"=",
"urlparse",
"(",
"url",
")",
"d",
"=",
"''",
"if",
"date",
"is",
"not",
"None",
":",
"d",
"=",
"',%s'",
"%",
"datetime_safe",
".",
"new_datetime",
"(",
"date",
")",
".",
"strftim... | [
72,
0
] | [
82,
74
] | python | en | ['en', 'error', 'th'] | False |
SyndicationFeed.add_item | (self, title, link, description, author_email=None,
author_name=None, author_link=None, pubdate=None, comments=None,
unique_id=None, unique_id_is_permalink=None, enclosure=None,
categories=(), item_copyright=None, ttl=None, updateddate=None, **kwargs) |
Adds an item to the feed. All args are expected to be Python Unicode
objects except pubdate and updateddate, which are datetime.datetime
objects, and enclosure, which is an instance of the Enclosure class.
|
Adds an item to the feed. All args are expected to be Python Unicode
objects except pubdate and updateddate, which are datetime.datetime
objects, and enclosure, which is an instance of the Enclosure class.
| def add_item(self, title, link, description, author_email=None,
author_name=None, author_link=None, pubdate=None, comments=None,
unique_id=None, unique_id_is_permalink=None, enclosure=None,
categories=(), item_copyright=None, ttl=None, updateddate=None, **kwargs):
"""
... | [
"def",
"add_item",
"(",
"self",
",",
"title",
",",
"link",
",",
"description",
",",
"author_email",
"=",
"None",
",",
"author_name",
"=",
"None",
",",
"author_link",
"=",
"None",
",",
"pubdate",
"=",
"None",
",",
"comments",
"=",
"None",
",",
"unique_id"... | [
114,
4
] | [
147,
31
] | python | en | ['en', 'error', 'th'] | False |
SyndicationFeed.root_attributes | (self) |
Return extra attributes to place on the root (i.e. feed/channel) element.
Called from write().
|
Return extra attributes to place on the root (i.e. feed/channel) element.
Called from write().
| def root_attributes(self):
"""
Return extra attributes to place on the root (i.e. feed/channel) element.
Called from write().
"""
return {} | [
"def",
"root_attributes",
"(",
"self",
")",
":",
"return",
"{",
"}"
] | [
152,
4
] | [
157,
17
] | python | en | ['en', 'error', 'th'] | False |
SyndicationFeed.add_root_elements | (self, handler) |
Add elements in the root (i.e. feed/channel) element. Called
from write().
|
Add elements in the root (i.e. feed/channel) element. Called
from write().
| def add_root_elements(self, handler):
"""
Add elements in the root (i.e. feed/channel) element. Called
from write().
"""
pass | [
"def",
"add_root_elements",
"(",
"self",
",",
"handler",
")",
":",
"pass"
] | [
159,
4
] | [
164,
12
] | python | en | ['en', 'error', 'th'] | False |
SyndicationFeed.item_attributes | (self, item) |
Return extra attributes to place on each item (i.e. item/entry) element.
|
Return extra attributes to place on each item (i.e. item/entry) element.
| def item_attributes(self, item):
"""
Return extra attributes to place on each item (i.e. item/entry) element.
"""
return {} | [
"def",
"item_attributes",
"(",
"self",
",",
"item",
")",
":",
"return",
"{",
"}"
] | [
166,
4
] | [
170,
17
] | python | en | ['en', 'error', 'th'] | False |
SyndicationFeed.add_item_elements | (self, handler, item) |
Add elements on each item (i.e. item/entry) element.
|
Add elements on each item (i.e. item/entry) element.
| def add_item_elements(self, handler, item):
"""
Add elements on each item (i.e. item/entry) element.
"""
pass | [
"def",
"add_item_elements",
"(",
"self",
",",
"handler",
",",
"item",
")",
":",
"pass"
] | [
172,
4
] | [
176,
12
] | python | en | ['en', 'error', 'th'] | False |
SyndicationFeed.write | (self, outfile, encoding) |
Outputs the feed in the given encoding to outfile, which is a file-like
object. Subclasses should override this.
|
Outputs the feed in the given encoding to outfile, which is a file-like
object. Subclasses should override this.
| def write(self, outfile, encoding):
"""
Outputs the feed in the given encoding to outfile, which is a file-like
object. Subclasses should override this.
"""
raise NotImplementedError('subclasses of SyndicationFeed must provide a write() method') | [
"def",
"write",
"(",
"self",
",",
"outfile",
",",
"encoding",
")",
":",
"raise",
"NotImplementedError",
"(",
"'subclasses of SyndicationFeed must provide a write() method'",
")"
] | [
178,
4
] | [
183,
96
] | python | en | ['en', 'error', 'th'] | False |
SyndicationFeed.writeString | (self, encoding) |
Returns the feed in the given encoding as a string.
|
Returns the feed in the given encoding as a string.
| def writeString(self, encoding):
"""
Returns the feed in the given encoding as a string.
"""
s = StringIO()
self.write(s, encoding)
return s.getvalue() | [
"def",
"writeString",
"(",
"self",
",",
"encoding",
")",
":",
"s",
"=",
"StringIO",
"(",
")",
"self",
".",
"write",
"(",
"s",
",",
"encoding",
")",
"return",
"s",
".",
"getvalue",
"(",
")"
] | [
185,
4
] | [
191,
27
] | python | en | ['en', 'error', 'th'] | False |
SyndicationFeed.latest_post_date | (self) |
Returns the latest item's pubdate or updateddate. If no items
have either of these attributes this returns the current date/time.
|
Returns the latest item's pubdate or updateddate. If no items
have either of these attributes this returns the current date/time.
| def latest_post_date(self):
"""
Returns the latest item's pubdate or updateddate. If no items
have either of these attributes this returns the current date/time.
"""
latest_date = None
date_keys = ('updateddate', 'pubdate')
for item in self.items:
for... | [
"def",
"latest_post_date",
"(",
"self",
")",
":",
"latest_date",
"=",
"None",
"date_keys",
"=",
"(",
"'updateddate'",
",",
"'pubdate'",
")",
"for",
"item",
"in",
"self",
".",
"items",
":",
"for",
"date_key",
"in",
"date_keys",
":",
"item_date",
"=",
"item"... | [
193,
4
] | [
208,
53
] | python | en | ['en', 'error', 'th'] | False |
Enclosure.__init__ | (self, url, length, mime_type) | All args are expected to be Python Unicode objects | All args are expected to be Python Unicode objects | def __init__(self, url, length, mime_type):
"All args are expected to be Python Unicode objects"
self.length, self.mime_type = length, mime_type
self.url = iri_to_uri(url) | [
"def",
"__init__",
"(",
"self",
",",
"url",
",",
"length",
",",
"mime_type",
")",
":",
"self",
".",
"length",
",",
"self",
".",
"mime_type",
"=",
"length",
",",
"mime_type",
"self",
".",
"url",
"=",
"iri_to_uri",
"(",
"url",
")"
] | [
213,
4
] | [
216,
34
] | python | en | ['en', 'en', 'en'] | True |
_script_names | (dist, script_name, is_gui) | Create the fully qualified name of the files created by
{console,gui}_scripts for the given ``dist``.
Returns the list of file names
| Create the fully qualified name of the files created by
{console,gui}_scripts for the given ``dist``.
Returns the list of file names
| def _script_names(dist, script_name, is_gui):
# type: (Distribution, str, bool) -> List[str]
"""Create the fully qualified name of the files created by
{console,gui}_scripts for the given ``dist``.
Returns the list of file names
"""
if dist_in_usersite(dist):
bin_dir = bin_user
else:... | [
"def",
"_script_names",
"(",
"dist",
",",
"script_name",
",",
"is_gui",
")",
":",
"# type: (Distribution, str, bool) -> List[str]",
"if",
"dist_in_usersite",
"(",
"dist",
")",
":",
"bin_dir",
"=",
"bin_user",
"else",
":",
"bin_dir",
"=",
"bin_py",
"exe_name",
"=",... | [
38,
0
] | [
57,
26
] | python | en | ['en', 'en', 'en'] | True |
uninstallation_paths | (dist) |
Yield all the uninstallation paths for dist based on RECORD-without-.py[co]
Yield paths to all the files in RECORD. For each .py file in RECORD, add
the .pyc and .pyo in the same directory.
UninstallPathSet.add() takes care of the __pycache__ .py[co].
|
Yield all the uninstallation paths for dist based on RECORD-without-.py[co] | def uninstallation_paths(dist):
# type: (Distribution) -> Iterator[str]
"""
Yield all the uninstallation paths for dist based on RECORD-without-.py[co]
Yield paths to all the files in RECORD. For each .py file in RECORD, add
the .pyc and .pyo in the same directory.
UninstallPathSet.add() takes... | [
"def",
"uninstallation_paths",
"(",
"dist",
")",
":",
"# type: (Distribution) -> Iterator[str]",
"r",
"=",
"csv",
".",
"reader",
"(",
"FakeFile",
"(",
"dist",
".",
"get_metadata_lines",
"(",
"'RECORD'",
")",
")",
")",
"for",
"row",
"in",
"r",
":",
"path",
"=... | [
74,
0
] | [
94,
22
] | python | en | ['en', 'error', 'th'] | False |
compact | (paths) | Compact a path set to contain the minimal number of paths
necessary to contain all paths in the set. If /a/path/ and
/a/path/to/a/file.txt are both in the set, leave only the
shorter path. | Compact a path set to contain the minimal number of paths
necessary to contain all paths in the set. If /a/path/ and
/a/path/to/a/file.txt are both in the set, leave only the
shorter path. | def compact(paths):
# type: (Iterable[str]) -> Set[str]
"""Compact a path set to contain the minimal number of paths
necessary to contain all paths in the set. If /a/path/ and
/a/path/to/a/file.txt are both in the set, leave only the
shorter path."""
sep = os.path.sep
short_paths = set() #... | [
"def",
"compact",
"(",
"paths",
")",
":",
"# type: (Iterable[str]) -> Set[str]",
"sep",
"=",
"os",
".",
"path",
".",
"sep",
"short_paths",
"=",
"set",
"(",
")",
"# type: Set[str]",
"for",
"path",
"in",
"sorted",
"(",
"paths",
",",
"key",
"=",
"len",
")",
... | [
97,
0
] | [
114,
22
] | python | en | ['en', 'en', 'en'] | True |
compress_for_rename | (paths) | Returns a set containing the paths that need to be renamed.
This set may include directories when the original sequence of paths
included every file on disk.
| Returns a set containing the paths that need to be renamed. | def compress_for_rename(paths):
# type: (Iterable[str]) -> Set[str]
"""Returns a set containing the paths that need to be renamed.
This set may include directories when the original sequence of paths
included every file on disk.
"""
case_map = dict((os.path.normcase(p), p) for p in paths)
r... | [
"def",
"compress_for_rename",
"(",
"paths",
")",
":",
"# type: (Iterable[str]) -> Set[str]",
"case_map",
"=",
"dict",
"(",
"(",
"os",
".",
"path",
".",
"normcase",
"(",
"p",
")",
",",
"p",
")",
"for",
"p",
"in",
"paths",
")",
"remaining",
"=",
"set",
"("... | [
117,
0
] | [
154,
64
] | python | en | ['en', 'en', 'en'] | True |
compress_for_output_listing | (paths) | Returns a tuple of 2 sets of which paths to display to user
The first set contains paths that would be deleted. Files of a package
are not added and the top-level directory of the package has a '*' added
at the end - to signify that all it's contents are removed.
The second set contains files that wou... | Returns a tuple of 2 sets of which paths to display to user | def compress_for_output_listing(paths):
# type: (Iterable[str]) -> Tuple[Set[str], Set[str]]
"""Returns a tuple of 2 sets of which paths to display to user
The first set contains paths that would be deleted. Files of a package
are not added and the top-level directory of the package has a '*' added
... | [
"def",
"compress_for_output_listing",
"(",
"paths",
")",
":",
"# type: (Iterable[str]) -> Tuple[Set[str], Set[str]]",
"will_remove",
"=",
"set",
"(",
"paths",
")",
"will_skip",
"=",
"set",
"(",
")",
"# Determine folders and files",
"folders",
"=",
"set",
"(",
")",
"fi... | [
157,
0
] | [
205,
33
] | python | en | ['en', 'en', 'en'] | True |
StashedUninstallPathSet._get_directory_stash | (self, path) | Stashes a directory.
Directories are stashed adjacent to their original location if
possible, or else moved/copied into the user's temp dir. | Stashes a directory. | def _get_directory_stash(self, path):
# type: (str) -> str
"""Stashes a directory.
Directories are stashed adjacent to their original location if
possible, or else moved/copied into the user's temp dir."""
try:
save_dir = AdjacentTempDirectory(path) # type: TempDir... | [
"def",
"_get_directory_stash",
"(",
"self",
",",
"path",
")",
":",
"# type: (str) -> str",
"try",
":",
"save_dir",
"=",
"AdjacentTempDirectory",
"(",
"path",
")",
"# type: TempDirectory",
"except",
"OSError",
":",
"save_dir",
"=",
"TempDirectory",
"(",
"kind",
"="... | [
220,
4
] | [
233,
28
] | python | en | ['en', 'en', 'en'] | True |
StashedUninstallPathSet._get_file_stash | (self, path) | Stashes a file.
If no root has been provided, one will be created for the directory
in the user's temp directory. | Stashes a file. | def _get_file_stash(self, path):
# type: (str) -> str
"""Stashes a file.
If no root has been provided, one will be created for the directory
in the user's temp directory."""
path = os.path.normcase(path)
head, old_head = os.path.dirname(path), None
save_dir = Non... | [
"def",
"_get_file_stash",
"(",
"self",
",",
"path",
")",
":",
"# type: (str) -> str",
"path",
"=",
"os",
".",
"path",
".",
"normcase",
"(",
"path",
")",
"head",
",",
"old_head",
"=",
"os",
".",
"path",
".",
"dirname",
"(",
"path",
")",
",",
"None",
"... | [
235,
4
] | [
261,
28
] | python | en | ['en', 'en', 'en'] | True |
StashedUninstallPathSet.stash | (self, path) | Stashes the directory or file and returns its new location.
Handle symlinks as files to avoid modifying the symlink targets.
| Stashes the directory or file and returns its new location.
Handle symlinks as files to avoid modifying the symlink targets.
| def stash(self, path):
# type: (str) -> str
"""Stashes the directory or file and returns its new location.
Handle symlinks as files to avoid modifying the symlink targets.
"""
path_is_dir = os.path.isdir(path) and not os.path.islink(path)
if path_is_dir:
new_p... | [
"def",
"stash",
"(",
"self",
",",
"path",
")",
":",
"# type: (str) -> str",
"path_is_dir",
"=",
"os",
".",
"path",
".",
"isdir",
"(",
"path",
")",
"and",
"not",
"os",
".",
"path",
".",
"islink",
"(",
"path",
")",
"if",
"path_is_dir",
":",
"new_path",
... | [
263,
4
] | [
283,
23
] | python | en | ['en', 'en', 'en'] | True |
StashedUninstallPathSet.commit | (self) | Commits the uninstall by removing stashed files. | Commits the uninstall by removing stashed files. | def commit(self):
# type: () -> None
"""Commits the uninstall by removing stashed files."""
for _, save_dir in self._save_dirs.items():
save_dir.cleanup()
self._moves = []
self._save_dirs = {} | [
"def",
"commit",
"(",
"self",
")",
":",
"# type: () -> None",
"for",
"_",
",",
"save_dir",
"in",
"self",
".",
"_save_dirs",
".",
"items",
"(",
")",
":",
"save_dir",
".",
"cleanup",
"(",
")",
"self",
".",
"_moves",
"=",
"[",
"]",
"self",
".",
"_save_d... | [
285,
4
] | [
291,
28
] | python | en | ['en', 'en', 'en'] | True |
StashedUninstallPathSet.rollback | (self) | Undoes the uninstall by moving stashed files back. | Undoes the uninstall by moving stashed files back. | def rollback(self):
# type: () -> None
"""Undoes the uninstall by moving stashed files back."""
for p in self._moves:
logger.info("Moving to %s\n from %s", *p)
for new_path, path in self._moves:
try:
logger.debug('Replacing %s from %s', new_path, ... | [
"def",
"rollback",
"(",
"self",
")",
":",
"# type: () -> None",
"for",
"p",
"in",
"self",
".",
"_moves",
":",
"logger",
".",
"info",
"(",
"\"Moving to %s\\n from %s\"",
",",
"*",
"p",
")",
"for",
"new_path",
",",
"path",
"in",
"self",
".",
"_moves",
":",... | [
293,
4
] | [
311,
21
] | python | en | ['en', 'en', 'en'] | True |
UninstallPathSet._permitted | (self, path) |
Return True if the given path is one we are permitted to
remove/modify, False otherwise.
|
Return True if the given path is one we are permitted to
remove/modify, False otherwise. | def _permitted(self, path):
# type: (str) -> bool
"""
Return True if the given path is one we are permitted to
remove/modify, False otherwise.
"""
return is_local(path) | [
"def",
"_permitted",
"(",
"self",
",",
"path",
")",
":",
"# type: (str) -> bool",
"return",
"is_local",
"(",
"path",
")"
] | [
330,
4
] | [
337,
29
] | python | en | ['en', 'error', 'th'] | False |
UninstallPathSet.remove | (self, auto_confirm=False, verbose=False) | Remove paths in ``self.paths`` with confirmation (unless
``auto_confirm`` is True). | Remove paths in ``self.paths`` with confirmation (unless
``auto_confirm`` is True). | def remove(self, auto_confirm=False, verbose=False):
# type: (bool, bool) -> None
"""Remove paths in ``self.paths`` with confirmation (unless
``auto_confirm`` is True)."""
if not self.paths:
logger.info(
"Can't uninstall '%s'. No files were found to uninstall... | [
"def",
"remove",
"(",
"self",
",",
"auto_confirm",
"=",
"False",
",",
"verbose",
"=",
"False",
")",
":",
"# type: (bool, bool) -> None",
"if",
"not",
"self",
".",
"paths",
":",
"logger",
".",
"info",
"(",
"\"Can't uninstall '%s'. No files were found to uninstall.\""... | [
369,
4
] | [
399,
77
] | python | en | ['en', 'en', 'en'] | True |
UninstallPathSet._allowed_to_proceed | (self, verbose) | Display which files would be deleted and prompt for confirmation
| Display which files would be deleted and prompt for confirmation
| def _allowed_to_proceed(self, verbose):
# type: (bool) -> bool
"""Display which files would be deleted and prompt for confirmation
"""
def _display(msg, paths):
# type: (str, Iterable[str]) -> None
if not paths:
return
logger.info(msg... | [
"def",
"_allowed_to_proceed",
"(",
"self",
",",
"verbose",
")",
":",
"# type: (bool) -> bool",
"def",
"_display",
"(",
"msg",
",",
"paths",
")",
":",
"# type: (str, Iterable[str]) -> None",
"if",
"not",
"paths",
":",
"return",
"logger",
".",
"info",
"(",
"msg",
... | [
401,
4
] | [
430,
56
] | python | en | ['en', 'en', 'en'] | True |
UninstallPathSet.rollback | (self) | Rollback the changes previously made by remove(). | Rollback the changes previously made by remove(). | def rollback(self):
# type: () -> None
"""Rollback the changes previously made by remove()."""
if not self._moved_paths.can_rollback:
logger.error(
"Can't roll back %s; was not uninstalled",
self.dist.project_name,
)
return
... | [
"def",
"rollback",
"(",
"self",
")",
":",
"# type: () -> None",
"if",
"not",
"self",
".",
"_moved_paths",
".",
"can_rollback",
":",
"logger",
".",
"error",
"(",
"\"Can't roll back %s; was not uninstalled\"",
",",
"self",
".",
"dist",
".",
"project_name",
",",
")... | [
432,
4
] | [
444,
26
] | python | en | ['en', 'en', 'en'] | True |
UninstallPathSet.commit | (self) | Remove temporary save dir: rollback will no longer be possible. | Remove temporary save dir: rollback will no longer be possible. | def commit(self):
# type: () -> None
"""Remove temporary save dir: rollback will no longer be possible."""
self._moved_paths.commit() | [
"def",
"commit",
"(",
"self",
")",
":",
"# type: () -> None",
"self",
".",
"_moved_paths",
".",
"commit",
"(",
")"
] | [
446,
4
] | [
449,
34
] | python | en | ['en', 'en', 'en'] | True |
ld_mnist | () | Load training and test data. | Load training and test data. | def ld_mnist():
"""Load training and test data."""
train_transforms = torchvision.transforms.Compose(
[torchvision.transforms.ToTensor()]
)
test_transforms = torchvision.transforms.Compose(
[torchvision.transforms.ToTensor()]
)
# Load MNIST dataset
train_dataset = MNISTDatas... | [
"def",
"ld_mnist",
"(",
")",
":",
"train_transforms",
"=",
"torchvision",
".",
"transforms",
".",
"Compose",
"(",
"[",
"torchvision",
".",
"transforms",
".",
"ToTensor",
"(",
")",
"]",
")",
"test_transforms",
"=",
"torchvision",
".",
"transforms",
".",
"Comp... | [
75,
0
] | [
96,
57
] | python | en | ['en', 'en', 'en'] | True |
ModelBackend.user_can_authenticate | (self, user) |
Reject users with is_active=False. Custom user models that don't have
that attribute are allowed.
|
Reject users with is_active=False. Custom user models that don't have
that attribute are allowed.
| def user_can_authenticate(self, user):
"""
Reject users with is_active=False. Custom user models that don't have
that attribute are allowed.
"""
is_active = getattr(user, 'is_active', None)
return is_active or is_active is None | [
"def",
"user_can_authenticate",
"(",
"self",
",",
"user",
")",
":",
"is_active",
"=",
"getattr",
"(",
"user",
",",
"'is_active'",
",",
"None",
")",
"return",
"is_active",
"or",
"is_active",
"is",
"None"
] | [
54,
4
] | [
60,
45
] | python | en | ['en', 'error', 'th'] | False |
ModelBackend._get_permissions | (self, user_obj, obj, from_name) |
Return the permissions of `user_obj` from `from_name`. `from_name` can
be either "group" or "user" to return permissions from
`_get_group_permissions` or `_get_user_permissions` respectively.
|
Return the permissions of `user_obj` from `from_name`. `from_name` can
be either "group" or "user" to return permissions from
`_get_group_permissions` or `_get_user_permissions` respectively.
| def _get_permissions(self, user_obj, obj, from_name):
"""
Return the permissions of `user_obj` from `from_name`. `from_name` can
be either "group" or "user" to return permissions from
`_get_group_permissions` or `_get_user_permissions` respectively.
"""
if not user_obj.is... | [
"def",
"_get_permissions",
"(",
"self",
",",
"user_obj",
",",
"obj",
",",
"from_name",
")",
":",
"if",
"not",
"user_obj",
".",
"is_active",
"or",
"user_obj",
".",
"is_anonymous",
"or",
"obj",
"is",
"not",
"None",
":",
"return",
"set",
"(",
")",
"perm_cac... | [
70,
4
] | [
87,
49
] | python | en | ['en', 'error', 'th'] | False |
ModelBackend.get_user_permissions | (self, user_obj, obj=None) |
Return a set of permission strings the user `user_obj` has from their
`user_permissions`.
|
Return a set of permission strings the user `user_obj` has from their
`user_permissions`.
| def get_user_permissions(self, user_obj, obj=None):
"""
Return a set of permission strings the user `user_obj` has from their
`user_permissions`.
"""
return self._get_permissions(user_obj, obj, 'user') | [
"def",
"get_user_permissions",
"(",
"self",
",",
"user_obj",
",",
"obj",
"=",
"None",
")",
":",
"return",
"self",
".",
"_get_permissions",
"(",
"user_obj",
",",
"obj",
",",
"'user'",
")"
] | [
89,
4
] | [
94,
59
] | python | en | ['en', 'error', 'th'] | False |
ModelBackend.get_group_permissions | (self, user_obj, obj=None) |
Return a set of permission strings the user `user_obj` has from the
groups they belong.
|
Return a set of permission strings the user `user_obj` has from the
groups they belong.
| def get_group_permissions(self, user_obj, obj=None):
"""
Return a set of permission strings the user `user_obj` has from the
groups they belong.
"""
return self._get_permissions(user_obj, obj, 'group') | [
"def",
"get_group_permissions",
"(",
"self",
",",
"user_obj",
",",
"obj",
"=",
"None",
")",
":",
"return",
"self",
".",
"_get_permissions",
"(",
"user_obj",
",",
"obj",
",",
"'group'",
")"
] | [
96,
4
] | [
101,
60
] | python | en | ['en', 'error', 'th'] | False |
ModelBackend.has_module_perms | (self, user_obj, app_label) |
Return True if user_obj has any permissions in the given app_label.
|
Return True if user_obj has any permissions in the given app_label.
| def has_module_perms(self, user_obj, app_label):
"""
Return True if user_obj has any permissions in the given app_label.
"""
return user_obj.is_active and any(
perm[:perm.index('.')] == app_label
for perm in self.get_all_permissions(user_obj)
) | [
"def",
"has_module_perms",
"(",
"self",
",",
"user_obj",
",",
"app_label",
")",
":",
"return",
"user_obj",
".",
"is_active",
"and",
"any",
"(",
"perm",
"[",
":",
"perm",
".",
"index",
"(",
"'.'",
")",
"]",
"==",
"app_label",
"for",
"perm",
"in",
"self"... | [
113,
4
] | [
120,
9
] | python | en | ['en', 'error', 'th'] | False |
ModelBackend.with_perm | (self, perm, is_active=True, include_superusers=True, obj=None) |
Return users that have permission "perm". By default, filter out
inactive users and include superusers.
|
Return users that have permission "perm". By default, filter out
inactive users and include superusers.
| def with_perm(self, perm, is_active=True, include_superusers=True, obj=None):
"""
Return users that have permission "perm". By default, filter out
inactive users and include superusers.
"""
if isinstance(perm, str):
try:
app_label, codename = perm.spli... | [
"def",
"with_perm",
"(",
"self",
",",
"perm",
",",
"is_active",
"=",
"True",
",",
"include_superusers",
"=",
"True",
",",
"obj",
"=",
"None",
")",
":",
"if",
"isinstance",
"(",
"perm",
",",
"str",
")",
":",
"try",
":",
"app_label",
",",
"codename",
"... | [
122,
4
] | [
156,
56
] | python | en | ['en', 'error', 'th'] | False |
RemoteUserBackend.authenticate | (self, request, remote_user) |
The username passed as ``remote_user`` is considered trusted. Return
the ``User`` object with the given username. Create a new ``User``
object if ``create_unknown_user`` is ``True``.
Return None if ``create_unknown_user`` is ``False`` and a ``User``
object with the given userna... |
The username passed as ``remote_user`` is considered trusted. Return
the ``User`` object with the given username. Create a new ``User``
object if ``create_unknown_user`` is ``True``. | def authenticate(self, request, remote_user):
"""
The username passed as ``remote_user`` is considered trusted. Return
the ``User`` object with the given username. Create a new ``User``
object if ``create_unknown_user`` is ``True``.
Return None if ``create_unknown_user`` is ``Fa... | [
"def",
"authenticate",
"(",
"self",
",",
"request",
",",
"remote_user",
")",
":",
"if",
"not",
"remote_user",
":",
"return",
"user",
"=",
"None",
"username",
"=",
"self",
".",
"clean_username",
"(",
"remote_user",
")",
"# Note that this could be accomplished in on... | [
186,
4
] | [
224,
65
] | python | en | ['en', 'error', 'th'] | False |
RemoteUserBackend.clean_username | (self, username) |
Perform any cleaning on the "username" prior to using it to get or
create the user object. Return the cleaned username.
By default, return the username unchanged.
|
Perform any cleaning on the "username" prior to using it to get or
create the user object. Return the cleaned username. | def clean_username(self, username):
"""
Perform any cleaning on the "username" prior to using it to get or
create the user object. Return the cleaned username.
By default, return the username unchanged.
"""
return username | [
"def",
"clean_username",
"(",
"self",
",",
"username",
")",
":",
"return",
"username"
] | [
226,
4
] | [
233,
23
] | python | en | ['en', 'error', 'th'] | False |
RemoteUserBackend.configure_user | (self, request, user) |
Configure a user after creation and return the updated user.
By default, return the user unmodified.
|
Configure a user after creation and return the updated user. | def configure_user(self, request, user):
"""
Configure a user after creation and return the updated user.
By default, return the user unmodified.
"""
return user | [
"def",
"configure_user",
"(",
"self",
",",
"request",
",",
"user",
")",
":",
"return",
"user"
] | [
235,
4
] | [
241,
19
] | python | en | ['en', 'error', 'th'] | False |
make_command | (*args) |
Create a CommandArgs object.
|
Create a CommandArgs object.
| def make_command(*args):
# type: (Union[str, HiddenText, CommandArgs]) -> CommandArgs
"""
Create a CommandArgs object.
"""
command_args = [] # type: CommandArgs
for arg in args:
# Check for list instead of CommandArgs since CommandArgs is
# only known during type-checking.
... | [
"def",
"make_command",
"(",
"*",
"args",
")",
":",
"# type: (Union[str, HiddenText, CommandArgs]) -> CommandArgs",
"command_args",
"=",
"[",
"]",
"# type: CommandArgs",
"for",
"arg",
"in",
"args",
":",
"# Check for list instead of CommandArgs since CommandArgs is",
"# only know... | [
29,
0
] | [
44,
23
] | python | en | ['en', 'error', 'th'] | False |
format_command_args | (args) |
Format command arguments for display.
|
Format command arguments for display.
| def format_command_args(args):
# type: (Union[List[str], CommandArgs]) -> str
"""
Format command arguments for display.
"""
# For HiddenText arguments, display the redacted form by calling str().
# Also, we don't apply str() to arguments that aren't HiddenText since
# this can trigger a Unic... | [
"def",
"format_command_args",
"(",
"args",
")",
":",
"# type: (Union[List[str], CommandArgs]) -> str",
"# For HiddenText arguments, display the redacted form by calling str().",
"# Also, we don't apply str() to arguments that aren't HiddenText since",
"# this can trigger a UnicodeDecodeError in Py... | [
47,
0
] | [
60,
5
] | python | en | ['en', 'error', 'th'] | False |
reveal_command_args | (args) |
Return the arguments in their raw, unredacted form.
|
Return the arguments in their raw, unredacted form.
| def reveal_command_args(args):
# type: (Union[List[str], CommandArgs]) -> List[str]
"""
Return the arguments in their raw, unredacted form.
"""
return [
arg.secret if isinstance(arg, HiddenText) else arg for arg in args
] | [
"def",
"reveal_command_args",
"(",
"args",
")",
":",
"# type: (Union[List[str], CommandArgs]) -> List[str]",
"return",
"[",
"arg",
".",
"secret",
"if",
"isinstance",
"(",
"arg",
",",
"HiddenText",
")",
"else",
"arg",
"for",
"arg",
"in",
"args",
"]"
] | [
63,
0
] | [
70,
5
] | python | en | ['en', 'error', 'th'] | False |
make_subprocess_output_error | (
cmd_args, # type: Union[List[str], CommandArgs]
cwd, # type: Optional[str]
lines, # type: List[Text]
exit_status, # type: int
) |
Create and return the error message to use to log a subprocess error
with command output.
:param lines: A list of lines, each ending with a newline.
|
Create and return the error message to use to log a subprocess error
with command output. | def make_subprocess_output_error(
cmd_args, # type: Union[List[str], CommandArgs]
cwd, # type: Optional[str]
lines, # type: List[Text]
exit_status, # type: int
):
# type: (...) -> Text
"""
Create and return the error message to use to log a subprocess error
with comm... | [
"def",
"make_subprocess_output_error",
"(",
"cmd_args",
",",
"# type: Union[List[str], CommandArgs]",
"cwd",
",",
"# type: Optional[str]",
"lines",
",",
"# type: List[Text]",
"exit_status",
",",
"# type: int",
")",
":",
"# type: (...) -> Text",
"command",
"=",
"format_command... | [
73,
0
] | [
112,
14
] | python | en | ['en', 'error', 'th'] | False |
call_subprocess | (
cmd, # type: Union[List[str], CommandArgs]
show_stdout=False, # type: bool
cwd=None, # type: Optional[str]
on_returncode='raise', # type: str
extra_ok_returncodes=None, # type: Optional[Iterable[int]]
command_desc=None, # type: Optional[str]
extra_environ=None, # type: Optional[Mapp... |
Args:
show_stdout: if true, use INFO to log the subprocess's stderr and
stdout streams. Otherwise, use DEBUG. Defaults to False.
extra_ok_returncodes: an iterable of integer return codes that are
acceptable, in addition to 0. Defaults to None, which means [].
unset_environ: an i... |
Args:
show_stdout: if true, use INFO to log the subprocess's stderr and
stdout streams. Otherwise, use DEBUG. Defaults to False.
extra_ok_returncodes: an iterable of integer return codes that are
acceptable, in addition to 0. Defaults to None, which means [].
unset_environ: an i... | def call_subprocess(
cmd, # type: Union[List[str], CommandArgs]
show_stdout=False, # type: bool
cwd=None, # type: Optional[str]
on_returncode='raise', # type: str
extra_ok_returncodes=None, # type: Optional[Iterable[int]]
command_desc=None, # type: Optional[str]
extra_environ=None, # ... | [
"def",
"call_subprocess",
"(",
"cmd",
",",
"# type: Union[List[str], CommandArgs]",
"show_stdout",
"=",
"False",
",",
"# type: bool",
"cwd",
"=",
"None",
",",
"# type: Optional[str]",
"on_returncode",
"=",
"'raise'",
",",
"# type: str",
"extra_ok_returncodes",
"=",
"Non... | [
115,
0
] | [
251,
30
] | python | en | ['en', 'error', 'th'] | False |
runner_with_spinner_message | (message) | Provide a subprocess_runner that shows a spinner message.
Intended for use with for pep517's Pep517HookCaller. Thus, the runner has
an API that matches what's expected by Pep517HookCaller.subprocess_runner.
| Provide a subprocess_runner that shows a spinner message. | def runner_with_spinner_message(message):
# type: (str) -> Callable[..., None]
"""Provide a subprocess_runner that shows a spinner message.
Intended for use with for pep517's Pep517HookCaller. Thus, the runner has
an API that matches what's expected by Pep517HookCaller.subprocess_runner.
"""
d... | [
"def",
"runner_with_spinner_message",
"(",
"message",
")",
":",
"# type: (str) -> Callable[..., None]",
"def",
"runner",
"(",
"cmd",
",",
"# type: List[str]",
"cwd",
"=",
"None",
",",
"# type: Optional[str]",
"extra_environ",
"=",
"None",
"# type: Optional[Mapping[str, Any]... | [
254,
0
] | [
276,
17
] | python | en | ['en', 'en', 'en'] | True |
RequestMethods.request | (self, method, url, fields=None, headers=None, **urlopen_kw) |
Make a request using :meth:`urlopen` with the appropriate encoding of
``fields`` based on the ``method`` used.
This is a convenience method that requires the least amount of manual
effort. It can be used in most situations, while still having the
option to drop down to more spe... |
Make a request using :meth:`urlopen` with the appropriate encoding of
``fields`` based on the ``method`` used. | def request(self, method, url, fields=None, headers=None, **urlopen_kw):
"""
Make a request using :meth:`urlopen` with the appropriate encoding of
``fields`` based on the ``method`` used.
This is a convenience method that requires the least amount of manual
effort. It can be use... | [
"def",
"request",
"(",
"self",
",",
"method",
",",
"url",
",",
"fields",
"=",
"None",
",",
"headers",
"=",
"None",
",",
"*",
"*",
"urlopen_kw",
")",
":",
"method",
"=",
"method",
".",
"upper",
"(",
")",
"urlopen_kw",
"[",
"\"request_url\"",
"]",
"=",... | [
58,
4
] | [
80,
13
] | python | en | ['en', 'error', 'th'] | False |
RequestMethods.request_encode_url | (self, method, url, fields=None, headers=None, **urlopen_kw) |
Make a request using :meth:`urlopen` with the ``fields`` encoded in
the url. This is useful for request methods like GET, HEAD, DELETE, etc.
|
Make a request using :meth:`urlopen` with the ``fields`` encoded in
the url. This is useful for request methods like GET, HEAD, DELETE, etc.
| def request_encode_url(self, method, url, fields=None, headers=None, **urlopen_kw):
"""
Make a request using :meth:`urlopen` with the ``fields`` encoded in
the url. This is useful for request methods like GET, HEAD, DELETE, etc.
"""
if headers is None:
headers = self.... | [
"def",
"request_encode_url",
"(",
"self",
",",
"method",
",",
"url",
",",
"fields",
"=",
"None",
",",
"headers",
"=",
"None",
",",
"*",
"*",
"urlopen_kw",
")",
":",
"if",
"headers",
"is",
"None",
":",
"headers",
"=",
"self",
".",
"headers",
"extra_kw",... | [
82,
4
] | [
96,
52
] | python | en | ['en', 'error', 'th'] | False |
RequestMethods.request_encode_body | (
self,
method,
url,
fields=None,
headers=None,
encode_multipart=True,
multipart_boundary=None,
**urlopen_kw
) |
Make a request using :meth:`urlopen` with the ``fields`` encoded in
the body. This is useful for request methods like POST, PUT, PATCH, etc.
When ``encode_multipart=True`` (default), then
:meth:`urllib3.filepost.encode_multipart_formdata` is used to encode
the payload with the ... |
Make a request using :meth:`urlopen` with the ``fields`` encoded in
the body. This is useful for request methods like POST, PUT, PATCH, etc. | def request_encode_body(
self,
method,
url,
fields=None,
headers=None,
encode_multipart=True,
multipart_boundary=None,
**urlopen_kw
):
"""
Make a request using :meth:`urlopen` with the ``fields`` encoded in
the body. This is use... | [
"def",
"request_encode_body",
"(",
"self",
",",
"method",
",",
"url",
",",
"fields",
"=",
"None",
",",
"headers",
"=",
"None",
",",
"encode_multipart",
"=",
"True",
",",
"multipart_boundary",
"=",
"None",
",",
"*",
"*",
"urlopen_kw",
")",
":",
"if",
"hea... | [
98,
4
] | [
170,
52
] | python | en | ['en', 'error', 'th'] | False |
IsActiveTestCase.test_is_active_field_default | (self) |
tests that the default value for is_active is provided
|
tests that the default value for is_active is provided
| def test_is_active_field_default(self):
"""
tests that the default value for is_active is provided
"""
UserModel = get_user_model()
user = UserModel(username='foo')
self.assertEqual(user.is_active, True)
# you can set the attribute - but it will not save
u... | [
"def",
"test_is_active_field_default",
"(",
"self",
")",
":",
"UserModel",
"=",
"get_user_model",
"(",
")",
"user",
"=",
"UserModel",
"(",
"username",
"=",
"'foo'",
")",
"self",
".",
"assertEqual",
"(",
"user",
".",
"is_active",
",",
"True",
")",
"# you can ... | [
183,
4
] | [
196,
54
] | python | en | ['en', 'error', 'th'] | False |
_get_gid | (name) | Returns a gid, given a group name. | Returns a gid, given a group name. | def _get_gid(name):
"""Returns a gid, given a group name."""
if getgrnam is None or name is None:
return None
try:
result = getgrnam(name)
except KeyError:
result = None
if result is not None:
return result[2]
return None | [
"def",
"_get_gid",
"(",
"name",
")",
":",
"if",
"getgrnam",
"is",
"None",
"or",
"name",
"is",
"None",
":",
"return",
"None",
"try",
":",
"result",
"=",
"getgrnam",
"(",
"name",
")",
"except",
"KeyError",
":",
"result",
"=",
"None",
"if",
"result",
"i... | [
30,
0
] | [
40,
15
] | python | en | ['en', 'en', 'en'] | True |
_get_uid | (name) | Returns an uid, given a user name. | Returns an uid, given a user name. | def _get_uid(name):
"""Returns an uid, given a user name."""
if getpwnam is None or name is None:
return None
try:
result = getpwnam(name)
except KeyError:
result = None
if result is not None:
return result[2]
return None | [
"def",
"_get_uid",
"(",
"name",
")",
":",
"if",
"getpwnam",
"is",
"None",
"or",
"name",
"is",
"None",
":",
"return",
"None",
"try",
":",
"result",
"=",
"getpwnam",
"(",
"name",
")",
"except",
"KeyError",
":",
"result",
"=",
"None",
"if",
"result",
"i... | [
42,
0
] | [
52,
15
] | python | en | ['en', 'en', 'en'] | True |
make_tarball | (base_name, base_dir, compress="gzip", verbose=0, dry_run=0,
owner=None, group=None) | Create a (possibly compressed) tar file from all the files under
'base_dir'.
'compress' must be "gzip" (the default), "bzip2", "xz", "compress", or
None. ("compress" will be deprecated in Python 3.2)
'owner' and 'group' can be used to define an owner and a group for the
archive that is being buil... | Create a (possibly compressed) tar file from all the files under
'base_dir'. | def make_tarball(base_name, base_dir, compress="gzip", verbose=0, dry_run=0,
owner=None, group=None):
"""Create a (possibly compressed) tar file from all the files under
'base_dir'.
'compress' must be "gzip" (the default), "bzip2", "xz", "compress", or
None. ("compress" will be deprec... | [
"def",
"make_tarball",
"(",
"base_name",
",",
"base_dir",
",",
"compress",
"=",
"\"gzip\"",
",",
"verbose",
"=",
"0",
",",
"dry_run",
"=",
"0",
",",
"owner",
"=",
"None",
",",
"group",
"=",
"None",
")",
":",
"tar_compression",
"=",
"{",
"'gzip'",
":",
... | [
54,
0
] | [
124,
23
] | python | en | ['en', 'en', 'en'] | True |
make_zipfile | (base_name, base_dir, verbose=0, dry_run=0) | Create a zip file from all the files under 'base_dir'.
The output zip file will be named 'base_name' + ".zip". Uses either the
"zipfile" Python module (if available) or the InfoZIP "zip" utility
(if installed and found on the default search path). If neither tool is
available, raises DistutilsExecErr... | Create a zip file from all the files under 'base_dir'. | def make_zipfile(base_name, base_dir, verbose=0, dry_run=0):
"""Create a zip file from all the files under 'base_dir'.
The output zip file will be named 'base_name' + ".zip". Uses either the
"zipfile" Python module (if available) or the InfoZIP "zip" utility
(if installed and found on the default sear... | [
"def",
"make_zipfile",
"(",
"base_name",
",",
"base_dir",
",",
"verbose",
"=",
"0",
",",
"dry_run",
"=",
"0",
")",
":",
"zip_filename",
"=",
"base_name",
"+",
"\".zip\"",
"mkpath",
"(",
"os",
".",
"path",
".",
"dirname",
"(",
"zip_filename",
")",
",",
... | [
126,
0
] | [
184,
23
] | python | en | ['en', 'en', 'en'] | True |
check_archive_formats | (formats) | Returns the first format from the 'format' list that is unknown.
If all formats are known, returns None
| Returns the first format from the 'format' list that is unknown. | def check_archive_formats(formats):
"""Returns the first format from the 'format' list that is unknown.
If all formats are known, returns None
"""
for format in formats:
if format not in ARCHIVE_FORMATS:
return format
return None | [
"def",
"check_archive_formats",
"(",
"formats",
")",
":",
"for",
"format",
"in",
"formats",
":",
"if",
"format",
"not",
"in",
"ARCHIVE_FORMATS",
":",
"return",
"format",
"return",
"None"
] | [
195,
0
] | [
203,
15
] | python | en | ['en', 'en', 'en'] | True |
make_archive | (base_name, format, root_dir=None, base_dir=None, verbose=0,
dry_run=0, owner=None, group=None) | Create an archive file (eg. zip or tar).
'base_name' is the name of the file to create, minus any format-specific
extension; 'format' is the archive format: one of "zip", "tar", "gztar",
"bztar", "xztar", or "ztar".
'root_dir' is a directory that will be the root directory of the
archive; ie. we t... | Create an archive file (eg. zip or tar). | def make_archive(base_name, format, root_dir=None, base_dir=None, verbose=0,
dry_run=0, owner=None, group=None):
"""Create an archive file (eg. zip or tar).
'base_name' is the name of the file to create, minus any format-specific
extension; 'format' is the archive format: one of "zip", "ta... | [
"def",
"make_archive",
"(",
"base_name",
",",
"format",
",",
"root_dir",
"=",
"None",
",",
"base_dir",
"=",
"None",
",",
"verbose",
"=",
"0",
",",
"dry_run",
"=",
"0",
",",
"owner",
"=",
"None",
",",
"group",
"=",
"None",
")",
":",
"save_cwd",
"=",
... | [
205,
0
] | [
255,
19
] | python | en | ['en', 'gd', 'en'] | True |
loadImageSeries | (filelist=None) | create a list of :py:class:`~PIL.Image.Image` objects for use in a montage | create a list of :py:class:`~PIL.Image.Image` objects for use in a montage | def loadImageSeries(filelist=None):
"""create a list of :py:class:`~PIL.Image.Image` objects for use in a montage"""
if filelist is None or len(filelist) < 1:
return
imglist = []
for img in filelist:
if not os.path.exists(img):
print("unable to find %s" % img)
co... | [
"def",
"loadImageSeries",
"(",
"filelist",
"=",
"None",
")",
":",
"if",
"filelist",
"is",
"None",
"or",
"len",
"(",
"filelist",
")",
"<",
"1",
":",
"return",
"imglist",
"=",
"[",
"]",
"for",
"img",
"in",
"filelist",
":",
"if",
"not",
"os",
".",
"pa... | [
207,
0
] | [
226,
18
] | python | en | ['en', 'en', 'en'] | True |
EditMessageSideEffectsTest._login_and_send_original_stream_message | (
self, content: str, enable_online_push_notifications: bool = False
) |
Note our conventions here:
Hamlet is our logged in user (and sender).
Cordelia is the receiver we care about.
Scotland is the stream we send messages to.
|
Note our conventions here: | def _login_and_send_original_stream_message(
self, content: str, enable_online_push_notifications: bool = False
) -> int:
"""
Note our conventions here:
Hamlet is our logged in user (and sender).
Cordelia is the receiver we care about.
Scotland is the str... | [
"def",
"_login_and_send_original_stream_message",
"(",
"self",
",",
"content",
":",
"str",
",",
"enable_online_push_notifications",
":",
"bool",
"=",
"False",
")",
"->",
"int",
":",
"hamlet",
"=",
"self",
".",
"example_user",
"(",
"\"hamlet\"",
")",
"cordelia",
... | [
45,
4
] | [
71,
25
] | python | en | ['en', 'error', 'th'] | False |
EditMessageSideEffectsTest._get_queued_data_for_message_update | (
self, message_id: int, content: str, expect_short_circuit: bool = False
) |
This function updates a message with a post to
/json/messages/(message_id).
By using mocks, we are able to capture two pieces of data:
enqueue_kwargs: These are the arguments passed in to
maybe_enqueue_notifications.
queue_messages: These a... |
This function updates a message with a post to
/json/messages/(message_id). | def _get_queued_data_for_message_update(
self, message_id: int, content: str, expect_short_circuit: bool = False
) -> Dict[str, Any]:
"""
This function updates a message with a post to
/json/messages/(message_id).
By using mocks, we are able to capture two pieces of data:
... | [
"def",
"_get_queued_data_for_message_update",
"(",
"self",
",",
"message_id",
":",
"int",
",",
"content",
":",
"str",
",",
"expect_short_circuit",
":",
"bool",
"=",
"False",
")",
"->",
"Dict",
"[",
"str",
",",
"Any",
"]",
":",
"url",
"=",
"\"/json/messages/\... | [
73,
4
] | [
139,
9
] | python | en | ['en', 'error', 'th'] | False |
EditMessageSideEffectsTest._turn_on_stream_push_for_cordelia | (self) |
conventions:
Cordelia is the message receiver we care about.
Scotland is our stream.
|
conventions:
Cordelia is the message receiver we care about.
Scotland is our stream.
| def _turn_on_stream_push_for_cordelia(self) -> None:
"""
conventions:
Cordelia is the message receiver we care about.
Scotland is our stream.
"""
cordelia = self.example_user("cordelia")
stream = self.subscribe(cordelia, "Scotland")
recipient = str... | [
"def",
"_turn_on_stream_push_for_cordelia",
"(",
"self",
")",
"->",
"None",
":",
"cordelia",
"=",
"self",
".",
"example_user",
"(",
"\"cordelia\"",
")",
"stream",
"=",
"self",
".",
"subscribe",
"(",
"cordelia",
",",
"\"Scotland\"",
")",
"recipient",
"=",
"stre... | [
223,
4
] | [
237,
36
] | python | en | ['en', 'error', 'th'] | False |
EditMessageSideEffectsTest._cordelia_connected_to_zulip | (self) |
Right now the easiest way to make Cordelia look
connected to Zulip is to mock the function below.
This is a bit blunt, as it affects other users too,
but we only really look at Cordelia's data, anyway.
|
Right now the easiest way to make Cordelia look
connected to Zulip is to mock the function below. | def _cordelia_connected_to_zulip(self) -> Any:
"""
Right now the easiest way to make Cordelia look
connected to Zulip is to mock the function below.
This is a bit blunt, as it affects other users too,
but we only really look at Cordelia's data, anyway.
"""
return... | [
"def",
"_cordelia_connected_to_zulip",
"(",
"self",
")",
"->",
"Any",
":",
"return",
"mock",
".",
"patch",
"(",
"\"zerver.tornado.event_queue.receiver_is_off_zulip\"",
",",
"return_value",
"=",
"False",
",",
")"
] | [
249,
4
] | [
260,
9
] | python | en | ['en', 'error', 'th'] | False |
extract_cookies_to_jar | (jar, request, response) | Extract the cookies from the response into a CookieJar.
:param jar: cookielib.CookieJar (not necessarily a RequestsCookieJar)
:param request: our own requests.Request object
:param response: urllib3.HTTPResponse object
| Extract the cookies from the response into a CookieJar. | def extract_cookies_to_jar(jar, request, response):
"""Extract the cookies from the response into a CookieJar.
:param jar: cookielib.CookieJar (not necessarily a RequestsCookieJar)
:param request: our own requests.Request object
:param response: urllib3.HTTPResponse object
"""
if not (hasattr(r... | [
"def",
"extract_cookies_to_jar",
"(",
"jar",
",",
"request",
",",
"response",
")",
":",
"if",
"not",
"(",
"hasattr",
"(",
"response",
",",
"'_original_response'",
")",
"and",
"response",
".",
"_original_response",
")",
":",
"return",
"# the _original_response fiel... | [
117,
0
] | [
131,
33
] | python | en | ['en', 'en', 'en'] | True |
get_cookie_header | (jar, request) |
Produce an appropriate Cookie header string to be sent with `request`, or None.
:rtype: str
|
Produce an appropriate Cookie header string to be sent with `request`, or None. | def get_cookie_header(jar, request):
"""
Produce an appropriate Cookie header string to be sent with `request`, or None.
:rtype: str
"""
r = MockRequest(request)
jar.add_cookie_header(r)
return r.get_new_headers().get('Cookie') | [
"def",
"get_cookie_header",
"(",
"jar",
",",
"request",
")",
":",
"r",
"=",
"MockRequest",
"(",
"request",
")",
"jar",
".",
"add_cookie_header",
"(",
"r",
")",
"return",
"r",
".",
"get_new_headers",
"(",
")",
".",
"get",
"(",
"'Cookie'",
")"
] | [
134,
0
] | [
142,
44
] | python | en | ['en', 'error', 'th'] | False |
remove_cookie_by_name | (cookiejar, name, domain=None, path=None) | Unsets a cookie by name, by default over all domains and paths.
Wraps CookieJar.clear(), is O(n).
| Unsets a cookie by name, by default over all domains and paths. | def remove_cookie_by_name(cookiejar, name, domain=None, path=None):
"""Unsets a cookie by name, by default over all domains and paths.
Wraps CookieJar.clear(), is O(n).
"""
clearables = []
for cookie in cookiejar:
if cookie.name != name:
continue
if domain is not None an... | [
"def",
"remove_cookie_by_name",
"(",
"cookiejar",
",",
"name",
",",
"domain",
"=",
"None",
",",
"path",
"=",
"None",
")",
":",
"clearables",
"=",
"[",
"]",
"for",
"cookie",
"in",
"cookiejar",
":",
"if",
"cookie",
".",
"name",
"!=",
"name",
":",
"contin... | [
145,
0
] | [
161,
43
] | python | en | ['en', 'en', 'en'] | True |
create_cookie | (name, value, **kwargs) | Make a cookie from underspecified parameters.
By default, the pair of `name` and `value` will be set for the domain ''
and sent on every request (this is sometimes called a "supercookie").
| Make a cookie from underspecified parameters. | def create_cookie(name, value, **kwargs):
"""Make a cookie from underspecified parameters.
By default, the pair of `name` and `value` will be set for the domain ''
and sent on every request (this is sometimes called a "supercookie").
"""
result = {
'version': 0,
'name': name,
... | [
"def",
"create_cookie",
"(",
"name",
",",
"value",
",",
"*",
"*",
"kwargs",
")",
":",
"result",
"=",
"{",
"'version'",
":",
"0",
",",
"'name'",
":",
"name",
",",
"'value'",
":",
"value",
",",
"'port'",
":",
"None",
",",
"'domain'",
":",
"''",
",",
... | [
440,
0
] | [
473,
37
] | python | en | ['en', 'en', 'en'] | True |
morsel_to_cookie | (morsel) | Convert a Morsel object into a Cookie containing the one k/v pair. | Convert a Morsel object into a Cookie containing the one k/v pair. | def morsel_to_cookie(morsel):
"""Convert a Morsel object into a Cookie containing the one k/v pair."""
expires = None
if morsel['max-age']:
try:
expires = int(time.time() + int(morsel['max-age']))
except ValueError:
raise TypeError('max-age: %s must be integer' % mor... | [
"def",
"morsel_to_cookie",
"(",
"morsel",
")",
":",
"expires",
"=",
"None",
"if",
"morsel",
"[",
"'max-age'",
"]",
":",
"try",
":",
"expires",
"=",
"int",
"(",
"time",
".",
"time",
"(",
")",
"+",
"int",
"(",
"morsel",
"[",
"'max-age'",
"]",
")",
")... | [
476,
0
] | [
504,
5
] | python | en | ['en', 'en', 'en'] | True |
cookiejar_from_dict | (cookie_dict, cookiejar=None, overwrite=True) | Returns a CookieJar from a key/value dictionary.
:param cookie_dict: Dict of key/values to insert into CookieJar.
:param cookiejar: (optional) A cookiejar to add the cookies to.
:param overwrite: (optional) If False, will not replace cookies
already in the jar with new ones.
:rtype: CookieJar
... | Returns a CookieJar from a key/value dictionary. | def cookiejar_from_dict(cookie_dict, cookiejar=None, overwrite=True):
"""Returns a CookieJar from a key/value dictionary.
:param cookie_dict: Dict of key/values to insert into CookieJar.
:param cookiejar: (optional) A cookiejar to add the cookies to.
:param overwrite: (optional) If False, will not repl... | [
"def",
"cookiejar_from_dict",
"(",
"cookie_dict",
",",
"cookiejar",
"=",
"None",
",",
"overwrite",
"=",
"True",
")",
":",
"if",
"cookiejar",
"is",
"None",
":",
"cookiejar",
"=",
"RequestsCookieJar",
"(",
")",
"if",
"cookie_dict",
"is",
"not",
"None",
":",
... | [
507,
0
] | [
525,
20
] | python | en | ['en', 'en', 'en'] | True |
merge_cookies | (cookiejar, cookies) | Add cookies to cookiejar and returns a merged CookieJar.
:param cookiejar: CookieJar object to add the cookies to.
:param cookies: Dictionary or CookieJar object to be added.
:rtype: CookieJar
| Add cookies to cookiejar and returns a merged CookieJar. | def merge_cookies(cookiejar, cookies):
"""Add cookies to cookiejar and returns a merged CookieJar.
:param cookiejar: CookieJar object to add the cookies to.
:param cookies: Dictionary or CookieJar object to be added.
:rtype: CookieJar
"""
if not isinstance(cookiejar, cookielib.CookieJar):
... | [
"def",
"merge_cookies",
"(",
"cookiejar",
",",
"cookies",
")",
":",
"if",
"not",
"isinstance",
"(",
"cookiejar",
",",
"cookielib",
".",
"CookieJar",
")",
":",
"raise",
"ValueError",
"(",
"'You can only merge into CookieJar'",
")",
"if",
"isinstance",
"(",
"cooki... | [
528,
0
] | [
548,
20
] | python | en | ['en', 'af', 'en'] | True |
MockRequest.add_header | (self, key, val) | cookielib has no legitimate use for this method; add it back if you find one. | cookielib has no legitimate use for this method; add it back if you find one. | def add_header(self, key, val):
"""cookielib has no legitimate use for this method; add it back if you find one."""
raise NotImplementedError("Cookie headers should be added with add_unredirected_header()") | [
"def",
"add_header",
"(",
"self",
",",
"key",
",",
"val",
")",
":",
"raise",
"NotImplementedError",
"(",
"\"Cookie headers should be added with add_unredirected_header()\"",
")"
] | [
73,
4
] | [
75,
98
] | python | en | ['en', 'en', 'en'] | True |
MockResponse.__init__ | (self, headers) | Make a MockResponse for `cookielib` to read.
:param headers: a httplib.HTTPMessage or analogous carrying the headers
| Make a MockResponse for `cookielib` to read. | def __init__(self, headers):
"""Make a MockResponse for `cookielib` to read.
:param headers: a httplib.HTTPMessage or analogous carrying the headers
"""
self._headers = headers | [
"def",
"__init__",
"(",
"self",
",",
"headers",
")",
":",
"self",
".",
"_headers",
"=",
"headers"
] | [
103,
4
] | [
108,
31
] | python | en | ['en', 'en', 'en'] | True |
RequestsCookieJar.get | (self, name, default=None, domain=None, path=None) | Dict-like get() that also supports optional domain and path args in
order to resolve naming collisions from using one cookie jar over
multiple domains.
.. warning:: operation is O(n), not O(1).
| Dict-like get() that also supports optional domain and path args in
order to resolve naming collisions from using one cookie jar over
multiple domains. | def get(self, name, default=None, domain=None, path=None):
"""Dict-like get() that also supports optional domain and path args in
order to resolve naming collisions from using one cookie jar over
multiple domains.
.. warning:: operation is O(n), not O(1).
"""
try:
... | [
"def",
"get",
"(",
"self",
",",
"name",
",",
"default",
"=",
"None",
",",
"domain",
"=",
"None",
",",
"path",
"=",
"None",
")",
":",
"try",
":",
"return",
"self",
".",
"_find_no_duplicates",
"(",
"name",
",",
"domain",
",",
"path",
")",
"except",
"... | [
188,
4
] | [
198,
26
] | python | en | ['en', 'en', 'en'] | True |
RequestsCookieJar.set | (self, name, value, **kwargs) | Dict-like set() that also supports optional domain and path args in
order to resolve naming collisions from using one cookie jar over
multiple domains.
| Dict-like set() that also supports optional domain and path args in
order to resolve naming collisions from using one cookie jar over
multiple domains.
| def set(self, name, value, **kwargs):
"""Dict-like set() that also supports optional domain and path args in
order to resolve naming collisions from using one cookie jar over
multiple domains.
"""
# support client code that unsets cookies by assignment of a None value:
if... | [
"def",
"set",
"(",
"self",
",",
"name",
",",
"value",
",",
"*",
"*",
"kwargs",
")",
":",
"# support client code that unsets cookies by assignment of a None value:",
"if",
"value",
"is",
"None",
":",
"remove_cookie_by_name",
"(",
"self",
",",
"name",
",",
"domain",... | [
200,
4
] | [
215,
16
] | python | en | ['en', 'en', 'en'] | True |
RequestsCookieJar.iterkeys | (self) | Dict-like iterkeys() that returns an iterator of names of cookies
from the jar.
.. seealso:: itervalues() and iteritems().
| Dict-like iterkeys() that returns an iterator of names of cookies
from the jar. | def iterkeys(self):
"""Dict-like iterkeys() that returns an iterator of names of cookies
from the jar.
.. seealso:: itervalues() and iteritems().
"""
for cookie in iter(self):
yield cookie.name | [
"def",
"iterkeys",
"(",
"self",
")",
":",
"for",
"cookie",
"in",
"iter",
"(",
"self",
")",
":",
"yield",
"cookie",
".",
"name"
] | [
217,
4
] | [
224,
29
] | python | en | ['en', 'en', 'en'] | True |
RequestsCookieJar.keys | (self) | Dict-like keys() that returns a list of names of cookies from the
jar.
.. seealso:: values() and items().
| Dict-like keys() that returns a list of names of cookies from the
jar. | def keys(self):
"""Dict-like keys() that returns a list of names of cookies from the
jar.
.. seealso:: values() and items().
"""
return list(self.iterkeys()) | [
"def",
"keys",
"(",
"self",
")",
":",
"return",
"list",
"(",
"self",
".",
"iterkeys",
"(",
")",
")"
] | [
226,
4
] | [
232,
36
] | python | en | ['en', 'en', 'en'] | True |
RequestsCookieJar.itervalues | (self) | Dict-like itervalues() that returns an iterator of values of cookies
from the jar.
.. seealso:: iterkeys() and iteritems().
| Dict-like itervalues() that returns an iterator of values of cookies
from the jar. | def itervalues(self):
"""Dict-like itervalues() that returns an iterator of values of cookies
from the jar.
.. seealso:: iterkeys() and iteritems().
"""
for cookie in iter(self):
yield cookie.value | [
"def",
"itervalues",
"(",
"self",
")",
":",
"for",
"cookie",
"in",
"iter",
"(",
"self",
")",
":",
"yield",
"cookie",
".",
"value"
] | [
234,
4
] | [
241,
30
] | python | en | ['en', 'en', 'en'] | True |
RequestsCookieJar.values | (self) | Dict-like values() that returns a list of values of cookies from the
jar.
.. seealso:: keys() and items().
| Dict-like values() that returns a list of values of cookies from the
jar. | def values(self):
"""Dict-like values() that returns a list of values of cookies from the
jar.
.. seealso:: keys() and items().
"""
return list(self.itervalues()) | [
"def",
"values",
"(",
"self",
")",
":",
"return",
"list",
"(",
"self",
".",
"itervalues",
"(",
")",
")"
] | [
243,
4
] | [
249,
38
] | python | en | ['en', 'en', 'en'] | True |
RequestsCookieJar.iteritems | (self) | Dict-like iteritems() that returns an iterator of name-value tuples
from the jar.
.. seealso:: iterkeys() and itervalues().
| Dict-like iteritems() that returns an iterator of name-value tuples
from the jar. | def iteritems(self):
"""Dict-like iteritems() that returns an iterator of name-value tuples
from the jar.
.. seealso:: iterkeys() and itervalues().
"""
for cookie in iter(self):
yield cookie.name, cookie.value | [
"def",
"iteritems",
"(",
"self",
")",
":",
"for",
"cookie",
"in",
"iter",
"(",
"self",
")",
":",
"yield",
"cookie",
".",
"name",
",",
"cookie",
".",
"value"
] | [
251,
4
] | [
258,
43
] | python | en | ['en', 'en', 'en'] | True |
RequestsCookieJar.items | (self) | Dict-like items() that returns a list of name-value tuples from the
jar. Allows client-code to call ``dict(RequestsCookieJar)`` and get a
vanilla python dict of key value pairs.
.. seealso:: keys() and values().
| Dict-like items() that returns a list of name-value tuples from the
jar. Allows client-code to call ``dict(RequestsCookieJar)`` and get a
vanilla python dict of key value pairs. | def items(self):
"""Dict-like items() that returns a list of name-value tuples from the
jar. Allows client-code to call ``dict(RequestsCookieJar)`` and get a
vanilla python dict of key value pairs.
.. seealso:: keys() and values().
"""
return list(self.iteritems()) | [
"def",
"items",
"(",
"self",
")",
":",
"return",
"list",
"(",
"self",
".",
"iteritems",
"(",
")",
")"
] | [
260,
4
] | [
267,
37
] | python | en | ['en', 'en', 'en'] | True |
RequestsCookieJar.list_domains | (self) | Utility method to list all the domains in the jar. | Utility method to list all the domains in the jar. | def list_domains(self):
"""Utility method to list all the domains in the jar."""
domains = []
for cookie in iter(self):
if cookie.domain not in domains:
domains.append(cookie.domain)
return domains | [
"def",
"list_domains",
"(",
"self",
")",
":",
"domains",
"=",
"[",
"]",
"for",
"cookie",
"in",
"iter",
"(",
"self",
")",
":",
"if",
"cookie",
".",
"domain",
"not",
"in",
"domains",
":",
"domains",
".",
"append",
"(",
"cookie",
".",
"domain",
")",
"... | [
269,
4
] | [
275,
22
] | python | en | ['en', 'en', 'en'] | True |
RequestsCookieJar.list_paths | (self) | Utility method to list all the paths in the jar. | Utility method to list all the paths in the jar. | def list_paths(self):
"""Utility method to list all the paths in the jar."""
paths = []
for cookie in iter(self):
if cookie.path not in paths:
paths.append(cookie.path)
return paths | [
"def",
"list_paths",
"(",
"self",
")",
":",
"paths",
"=",
"[",
"]",
"for",
"cookie",
"in",
"iter",
"(",
"self",
")",
":",
"if",
"cookie",
".",
"path",
"not",
"in",
"paths",
":",
"paths",
".",
"append",
"(",
"cookie",
".",
"path",
")",
"return",
"... | [
277,
4
] | [
283,
20
] | python | en | ['en', 'en', 'en'] | True |
RequestsCookieJar.multiple_domains | (self) | Returns True if there are multiple domains in the jar.
Returns False otherwise.
:rtype: bool
| Returns True if there are multiple domains in the jar.
Returns False otherwise. | def multiple_domains(self):
"""Returns True if there are multiple domains in the jar.
Returns False otherwise.
:rtype: bool
"""
domains = []
for cookie in iter(self):
if cookie.domain is not None and cookie.domain in domains:
return True
... | [
"def",
"multiple_domains",
"(",
"self",
")",
":",
"domains",
"=",
"[",
"]",
"for",
"cookie",
"in",
"iter",
"(",
"self",
")",
":",
"if",
"cookie",
".",
"domain",
"is",
"not",
"None",
"and",
"cookie",
".",
"domain",
"in",
"domains",
":",
"return",
"Tru... | [
285,
4
] | [
296,
20
] | python | en | ['en', 'en', 'en'] | True |
RequestsCookieJar.get_dict | (self, domain=None, path=None) | Takes as an argument an optional domain and path and returns a plain
old Python dict of name-value pairs of cookies that meet the
requirements.
:rtype: dict
| Takes as an argument an optional domain and path and returns a plain
old Python dict of name-value pairs of cookies that meet the
requirements. | def get_dict(self, domain=None, path=None):
"""Takes as an argument an optional domain and path and returns a plain
old Python dict of name-value pairs of cookies that meet the
requirements.
:rtype: dict
"""
dictionary = {}
for cookie in iter(self):
i... | [
"def",
"get_dict",
"(",
"self",
",",
"domain",
"=",
"None",
",",
"path",
"=",
"None",
")",
":",
"dictionary",
"=",
"{",
"}",
"for",
"cookie",
"in",
"iter",
"(",
"self",
")",
":",
"if",
"(",
"(",
"domain",
"is",
"None",
"or",
"cookie",
".",
"domai... | [
298,
4
] | [
312,
25
] | python | en | ['en', 'en', 'en'] | True |
RequestsCookieJar.__getitem__ | (self, name) | Dict-like __getitem__() for compatibility with client code. Throws
exception if there are more than one cookie with name. In that case,
use the more explicit get() method instead.
.. warning:: operation is O(n), not O(1).
| Dict-like __getitem__() for compatibility with client code. Throws
exception if there are more than one cookie with name. In that case,
use the more explicit get() method instead. | def __getitem__(self, name):
"""Dict-like __getitem__() for compatibility with client code. Throws
exception if there are more than one cookie with name. In that case,
use the more explicit get() method instead.
.. warning:: operation is O(n), not O(1).
"""
return self._... | [
"def",
"__getitem__",
"(",
"self",
",",
"name",
")",
":",
"return",
"self",
".",
"_find_no_duplicates",
"(",
"name",
")"
] | [
320,
4
] | [
327,
45
] | 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.