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_image_dimensions | (file_or_path, close=False) |
Returns the (width, height) of an image, given an open file or a path. Set
'close' to True to close the file at the end if it is initially in an open
state.
|
Returns the (width, height) of an image, given an open file or a path. Set
'close' to True to close the file at the end if it is initially in an open
state.
| def get_image_dimensions(file_or_path, close=False):
"""
Returns the (width, height) of an image, given an open file or a path. Set
'close' to True to close the file at the end if it is initially in an open
state.
"""
from PIL import ImageFile as PillowImageFile
p = PillowImageFile.Parser(... | [
"def",
"get_image_dimensions",
"(",
"file_or_path",
",",
"close",
"=",
"False",
")",
":",
"from",
"PIL",
"import",
"ImageFile",
"as",
"PillowImageFile",
"p",
"=",
"PillowImageFile",
".",
"Parser",
"(",
")",
"if",
"hasattr",
"(",
"file_or_path",
",",
"'read'",
... | [
31,
0
] | [
73,
31
] | python | en | ['en', 'error', 'th'] | False |
QueryTestCase.test_db_selection | (self) | Check that querysets will use the default database by default | Check that querysets will use the default database by default | def test_db_selection(self):
"Check that querysets will use the default database by default"
self.assertEqual(Book.objects.db, DEFAULT_DB_ALIAS)
self.assertEqual(Book.objects.all().db, DEFAULT_DB_ALIAS)
self.assertEqual(Book.objects.using('other').db, 'other')
self.assertEqual(... | [
"def",
"test_db_selection",
"(",
"self",
")",
":",
"self",
".",
"assertEqual",
"(",
"Book",
".",
"objects",
".",
"db",
",",
"DEFAULT_DB_ALIAS",
")",
"self",
".",
"assertEqual",
"(",
"Book",
".",
"objects",
".",
"all",
"(",
")",
".",
"db",
",",
"DEFAULT... | [
22,
4
] | [
30,
76
] | python | en | ['en', 'en', 'en'] | True |
QueryTestCase.test_default_creation | (self) | Objects created on the default database don't leak onto other databases | Objects created on the default database don't leak onto other databases | def test_default_creation(self):
"Objects created on the default database don't leak onto other databases"
# Create a book on the default database using create()
Book.objects.create(title="Pro Django",
published=datetime.date(2008, 12, 16))
# Create a book on... | [
"def",
"test_default_creation",
"(",
"self",
")",
":",
"# Create a book on the default database using create()",
"Book",
".",
"objects",
".",
"create",
"(",
"title",
"=",
"\"Pro Django\"",
",",
"published",
"=",
"datetime",
".",
"date",
"(",
"2008",
",",
"12",
","... | [
32,
4
] | [
67,
9
] | python | en | ['en', 'en', 'en'] | True |
QueryTestCase.test_other_creation | (self) | Objects created on another database don't leak onto the default database | Objects created on another database don't leak onto the default database | def test_other_creation(self):
"Objects created on another database don't leak onto the default database"
# Create a book on the second database
Book.objects.using('other').create(title="Pro Django",
published=datetime.date(2008, 12, 16))
# Cre... | [
"def",
"test_other_creation",
"(",
"self",
")",
":",
"# Create a book on the second database",
"Book",
".",
"objects",
".",
"using",
"(",
"'other'",
")",
".",
"create",
"(",
"title",
"=",
"\"Pro Django\"",
",",
"published",
"=",
"datetime",
".",
"date",
"(",
"... | [
69,
4
] | [
112,
9
] | python | en | ['en', 'en', 'en'] | True |
QueryTestCase.test_basic_queries | (self) | Queries are constrained to a single database | Queries are constrained to a single database | def test_basic_queries(self):
"Queries are constrained to a single database"
dive = Book.objects.using('other').create(title="Dive into Python",
published=datetime.date(2009, 5, 4))
dive = Book.objects.using('other').get(published=datetime.date(... | [
"def",
"test_basic_queries",
"(",
"self",
")",
":",
"dive",
"=",
"Book",
".",
"objects",
".",
"using",
"(",
"'other'",
")",
".",
"create",
"(",
"title",
"=",
"\"Dive into Python\"",
",",
"published",
"=",
"datetime",
".",
"date",
"(",
"2009",
",",
"5",
... | [
114,
4
] | [
144,
55
] | python | en | ['en', 'en', 'en'] | True |
QueryTestCase.test_m2m_separation | (self) | M2M fields are constrained to a single database | M2M fields are constrained to a single database | def test_m2m_separation(self):
"M2M fields are constrained to a single database"
# Create a book and author on the default database
pro = Book.objects.create(title="Pro Django",
published=datetime.date(2008, 12, 16))
marty = Person.objects.create(name="... | [
"def",
"test_m2m_separation",
"(",
"self",
")",
":",
"# Create a book and author on the default database",
"pro",
"=",
"Book",
".",
"objects",
".",
"create",
"(",
"title",
"=",
"\"Pro Django\"",
",",
"published",
"=",
"datetime",
".",
"date",
"(",
"2008",
",",
"... | [
146,
4
] | [
189,
33
] | python | en | ['en', 'en', 'en'] | True |
QueryTestCase.test_m2m_forward_operations | (self) | M2M forward manipulations are all constrained to a single DB | M2M forward manipulations are all constrained to a single DB | def test_m2m_forward_operations(self):
"M2M forward manipulations are all constrained to a single DB"
# Create a book and author on the other database
dive = Book.objects.using('other').create(title="Dive into Python",
published=datetime.date(200... | [
"def",
"test_m2m_forward_operations",
"(",
"self",
")",
":",
"# Create a book and author on the other database",
"dive",
"=",
"Book",
".",
"objects",
".",
"using",
"(",
"'other'",
")",
".",
"create",
"(",
"title",
"=",
"\"Dive into Python\"",
",",
"published",
"=",
... | [
191,
4
] | [
232,
33
] | python | en | ['en', 'en', 'en'] | True |
QueryTestCase.test_m2m_reverse_operations | (self) | M2M reverse manipulations are all constrained to a single DB | M2M reverse manipulations are all constrained to a single DB | def test_m2m_reverse_operations(self):
"M2M reverse manipulations are all constrained to a single DB"
# Create a book and author on the other database
dive = Book.objects.using('other').create(title="Dive into Python",
published=datetime.date(200... | [
"def",
"test_m2m_reverse_operations",
"(",
"self",
")",
":",
"# Create a book and author on the other database",
"dive",
"=",
"Book",
".",
"objects",
".",
"using",
"(",
"'other'",
")",
".",
"create",
"(",
"title",
"=",
"\"Dive into Python\"",
",",
"published",
"=",
... | [
234,
4
] | [
275,
29
] | python | en | ['en', 'en', 'en'] | True |
QueryTestCase.test_m2m_cross_database_protection | (self) | Operations that involve sharing M2M objects across databases raise an error | Operations that involve sharing M2M objects across databases raise an error | def test_m2m_cross_database_protection(self):
"Operations that involve sharing M2M objects across databases raise an error"
# Create a book and author on the default database
pro = Book.objects.create(title="Pro Django",
published=datetime.date(2008, 12, 16))
marty = Person.... | [
"def",
"test_m2m_cross_database_protection",
"(",
"self",
")",
":",
"# Create a book and author on the default database",
"pro",
"=",
"Book",
".",
"objects",
".",
"create",
"(",
"title",
"=",
"\"Pro Django\"",
",",
"published",
"=",
"datetime",
".",
"date",
"(",
"20... | [
277,
4
] | [
313,
44
] | python | en | ['en', 'en', 'en'] | True |
QueryTestCase.test_m2m_deletion | (self) | Cascaded deletions of m2m relations issue queries on the right database | Cascaded deletions of m2m relations issue queries on the right database | def test_m2m_deletion(self):
"Cascaded deletions of m2m relations issue queries on the right database"
# Create a book and author on the other database
dive = Book.objects.using('other').create(title="Dive into Python",
published=datetime.date(20... | [
"def",
"test_m2m_deletion",
"(",
"self",
")",
":",
"# Create a book and author on the other database",
"dive",
"=",
"Book",
".",
"objects",
".",
"using",
"(",
"'other'",
")",
".",
"create",
"(",
"title",
"=",
"\"Dive into Python\"",
",",
"published",
"=",
"datetim... | [
315,
4
] | [
373,
80
] | python | en | ['en', 'en', 'en'] | True |
QueryTestCase.test_foreign_key_separation | (self) | FK fields are constrained to a single database | FK fields are constrained to a single database | def test_foreign_key_separation(self):
"FK fields are constrained to a single database"
# Create a book and author on the default database
pro = Book.objects.create(title="Pro Django",
published=datetime.date(2008, 12, 16))
george = Person.objects.creat... | [
"def",
"test_foreign_key_separation",
"(",
"self",
")",
":",
"# Create a book and author on the default database",
"pro",
"=",
"Book",
".",
"objects",
".",
"create",
"(",
"title",
"=",
"\"Pro Django\"",
",",
"published",
"=",
"datetime",
".",
"date",
"(",
"2008",
... | [
375,
4
] | [
419,
33
] | python | en | ['en', 'en', 'en'] | True |
QueryTestCase.test_foreign_key_reverse_operations | (self) | FK reverse manipulations are all constrained to a single DB | FK reverse manipulations are all constrained to a single DB | def test_foreign_key_reverse_operations(self):
"FK reverse manipulations are all constrained to a single DB"
dive = Book.objects.using('other').create(title="Dive into Python",
published=datetime.date(2009, 5, 4))
chris = Person.objects.using('other').create(name="Chris Mills")
... | [
"def",
"test_foreign_key_reverse_operations",
"(",
"self",
")",
":",
"dive",
"=",
"Book",
".",
"objects",
".",
"using",
"(",
"'other'",
")",
".",
"create",
"(",
"title",
"=",
"\"Dive into Python\"",
",",
"published",
"=",
"datetime",
".",
"date",
"(",
"2009"... | [
421,
4
] | [
464,
15
] | python | en | ['en', 'en', 'en'] | True |
QueryTestCase.test_foreign_key_cross_database_protection | (self) | Operations that involve sharing FK objects across databases raise an error | Operations that involve sharing FK objects across databases raise an error | def test_foreign_key_cross_database_protection(self):
"Operations that involve sharing FK objects across databases raise an error"
# Create a book and author on the default database
pro = Book.objects.create(title="Pro Django",
published=datetime.date(2008, 12, 16))
marty = ... | [
"def",
"test_foreign_key_cross_database_protection",
"(",
"self",
")",
":",
"# Create a book and author on the default database",
"pro",
"=",
"Book",
".",
"objects",
".",
"create",
"(",
"title",
"=",
"\"Pro Django\"",
",",
"published",
"=",
"datetime",
".",
"date",
"(... | [
466,
4
] | [
490,
38
] | python | en | ['en', 'en', 'en'] | True |
QueryTestCase.test_foreign_key_deletion | (self) | Cascaded deletions of Foreign Key relations issue queries on the right database | Cascaded deletions of Foreign Key relations issue queries on the right database | def test_foreign_key_deletion(self):
"Cascaded deletions of Foreign Key relations issue queries on the right database"
mark = Person.objects.using('other').create(name="Mark Pilgrim")
Pet.objects.using('other').create(name="Fido", owner=mark)
# Check the initial state
self.asser... | [
"def",
"test_foreign_key_deletion",
"(",
"self",
")",
":",
"mark",
"=",
"Person",
".",
"objects",
".",
"using",
"(",
"'other'",
")",
".",
"create",
"(",
"name",
"=",
"\"Mark Pilgrim\"",
")",
"Pet",
".",
"objects",
".",
"using",
"(",
"'other'",
")",
".",
... | [
492,
4
] | [
512,
63
] | python | en | ['en', 'en', 'en'] | True |
QueryTestCase.test_foreign_key_validation | (self) | ForeignKey.validate() uses the correct database | ForeignKey.validate() uses the correct database | def test_foreign_key_validation(self):
"ForeignKey.validate() uses the correct database"
mickey = Person.objects.using('other').create(name="Mickey")
pluto = Pet.objects.using('other').create(name="Pluto", owner=mickey)
self.assertEqual(None, pluto.full_clean()) | [
"def",
"test_foreign_key_validation",
"(",
"self",
")",
":",
"mickey",
"=",
"Person",
".",
"objects",
".",
"using",
"(",
"'other'",
")",
".",
"create",
"(",
"name",
"=",
"\"Mickey\"",
")",
"pluto",
"=",
"Pet",
".",
"objects",
".",
"using",
"(",
"'other'"... | [
514,
4
] | [
518,
50
] | python | en | ['en', 'zu', 'en'] | True |
QueryTestCase.test_o2o_separation | (self) | OneToOne fields are constrained to a single database | OneToOne fields are constrained to a single database | def test_o2o_separation(self):
"OneToOne fields are constrained to a single database"
# Create a user and profile on the default database
alice = User.objects.db_manager('default').create_user('alice', 'alice@example.com')
alice_profile = UserProfile.objects.using('default').create(user=... | [
"def",
"test_o2o_separation",
"(",
"self",
")",
":",
"# Create a user and profile on the default database",
"alice",
"=",
"User",
".",
"objects",
".",
"db_manager",
"(",
"'default'",
")",
".",
"create_user",
"(",
"'alice'",
",",
"'alice@example.com'",
")",
"alice_prof... | [
520,
4
] | [
554,
58
] | python | en | ['en', 'en', 'en'] | True |
QueryTestCase.test_o2o_cross_database_protection | (self) | Operations that involve sharing FK objects across databases raise an error | Operations that involve sharing FK objects across databases raise an error | def test_o2o_cross_database_protection(self):
"Operations that involve sharing FK objects across databases raise an error"
# Create a user and profile on the default database
alice = User.objects.db_manager('default').create_user('alice', 'alice@example.com')
# Create a user and profile... | [
"def",
"test_o2o_cross_database_protection",
"(",
"self",
")",
":",
"# Create a user and profile on the default database",
"alice",
"=",
"User",
".",
"objects",
".",
"db_manager",
"(",
"'default'",
")",
".",
"create_user",
"(",
"'alice'",
",",
"'alice@example.com'",
")"... | [
556,
4
] | [
625,
56
] | python | en | ['en', 'en', 'en'] | True |
QueryTestCase.test_generic_key_separation | (self) | Generic fields are constrained to a single database | Generic fields are constrained to a single database | def test_generic_key_separation(self):
"Generic fields are constrained to a single database"
# Create a book and author on the default database
pro = Book.objects.create(title="Pro Django",
published=datetime.date(2008, 12, 16))
review1 = Review.objects... | [
"def",
"test_generic_key_separation",
"(",
"self",
")",
":",
"# Create a book and author on the default database",
"pro",
"=",
"Book",
".",
"objects",
".",
"create",
"(",
"title",
"=",
"\"Pro Django\"",
",",
"published",
"=",
"datetime",
".",
"date",
"(",
"2008",
... | [
627,
4
] | [
652,
30
] | python | en | ['en', 'en', 'en'] | True |
QueryTestCase.test_generic_key_reverse_operations | (self) | Generic reverse manipulations are all constrained to a single DB | Generic reverse manipulations are all constrained to a single DB | def test_generic_key_reverse_operations(self):
"Generic reverse manipulations are all constrained to a single DB"
dive = Book.objects.using('other').create(title="Dive into Python",
published=datetime.date(2009, 5, 4))
temp = Book.objects.using(... | [
"def",
"test_generic_key_reverse_operations",
"(",
"self",
")",
":",
"dive",
"=",
"Book",
".",
"objects",
".",
"using",
"(",
"'other'",
")",
".",
"create",
"(",
"title",
"=",
"\"Dive into Python\"",
",",
"published",
"=",
"datetime",
".",
"date",
"(",
"2009"... | [
654,
4
] | [
696,
29
] | python | en | ['en', 'en', 'en'] | True |
QueryTestCase.test_generic_key_cross_database_protection | (self) | Operations that involve sharing generic key objects across databases raise an error | Operations that involve sharing generic key objects across databases raise an error | def test_generic_key_cross_database_protection(self):
"Operations that involve sharing generic key objects across databases raise an error"
# Create a book and author on the default database
pro = Book.objects.create(title="Pro Django",
published=datetime.date(2... | [
"def",
"test_generic_key_cross_database_protection",
"(",
"self",
")",
":",
"# Create a book and author on the default database",
"pro",
"=",
"Book",
".",
"objects",
".",
"create",
"(",
"title",
"=",
"\"Pro Django\"",
",",
"published",
"=",
"datetime",
".",
"date",
"(... | [
698,
4
] | [
742,
46
] | python | en | ['en', 'en', 'en'] | True |
QueryTestCase.test_generic_key_deletion | (self) | Cascaded deletions of Generic Key relations issue queries on the right database | Cascaded deletions of Generic Key relations issue queries on the right database | def test_generic_key_deletion(self):
"Cascaded deletions of Generic Key relations issue queries on the right database"
dive = Book.objects.using('other').create(title="Dive into Python",
published=datetime.date(2009, 5, 4))
Review.objects.using('... | [
"def",
"test_generic_key_deletion",
"(",
"self",
")",
":",
"dive",
"=",
"Book",
".",
"objects",
".",
"using",
"(",
"'other'",
")",
".",
"create",
"(",
"title",
"=",
"\"Dive into Python\"",
",",
"published",
"=",
"datetime",
".",
"date",
"(",
"2009",
",",
... | [
744,
4
] | [
765,
66
] | python | en | ['en', 'en', 'en'] | True |
QueryTestCase.test_ordering | (self) | get_next_by_XXX commands stick to a single database | get_next_by_XXX commands stick to a single database | def test_ordering(self):
"get_next_by_XXX commands stick to a single database"
Book.objects.create(title="Pro Django",
published=datetime.date(2008, 12, 16))
dive = Book.objects.using('other').create(title="Dive into Python",
... | [
"def",
"test_ordering",
"(",
"self",
")",
":",
"Book",
".",
"objects",
".",
"create",
"(",
"title",
"=",
"\"Pro Django\"",
",",
"published",
"=",
"datetime",
".",
"date",
"(",
"2008",
",",
"12",
",",
"16",
")",
")",
"dive",
"=",
"Book",
".",
"objects... | [
767,
4
] | [
779,
83
] | python | en | ['it', 'en', 'en'] | True |
QueryTestCase.test_raw | (self) | test the raw() method across databases | test the raw() method across databases | def test_raw(self):
"test the raw() method across databases"
dive = Book.objects.using('other').create(title="Dive into Python",
published=datetime.date(2009, 5, 4))
val = Book.objects.db_manager("other").raw('SELECT id FROM multiple_database_book')
self.assertQuerysetEqual(v... | [
"def",
"test_raw",
"(",
"self",
")",
":",
"dive",
"=",
"Book",
".",
"objects",
".",
"using",
"(",
"'other'",
")",
".",
"create",
"(",
"title",
"=",
"\"Dive into Python\"",
",",
"published",
"=",
"datetime",
".",
"date",
"(",
"2009",
",",
"5",
",",
"4... | [
781,
4
] | [
789,
66
] | python | en | ['en', 'en', 'en'] | True |
QueryTestCase.test_select_related | (self) | Database assignment is retained if an object is retrieved with select_related() | Database assignment is retained if an object is retrieved with select_related() | def test_select_related(self):
"Database assignment is retained if an object is retrieved with select_related()"
# Create a book and author on the other database
mark = Person.objects.using('other').create(name="Mark Pilgrim")
Book.objects.using('other').create(title="Dive into Python",
... | [
"def",
"test_select_related",
"(",
"self",
")",
":",
"# Create a book and author on the other database",
"mark",
"=",
"Person",
".",
"objects",
".",
"using",
"(",
"'other'",
")",
".",
"create",
"(",
"name",
"=",
"\"Mark Pilgrim\"",
")",
"Book",
".",
"objects",
"... | [
791,
4
] | [
803,
56
] | python | en | ['en', 'en', 'en'] | True |
QueryTestCase.test_subquery | (self) | Make sure as_sql works with subqueries and primary/replica. | Make sure as_sql works with subqueries and primary/replica. | def test_subquery(self):
"""Make sure as_sql works with subqueries and primary/replica."""
sub = Person.objects.using('other').filter(name='fff')
qs = Book.objects.filter(editor__in=sub)
# When you call __str__ on the query object, it doesn't know about using
# so it falls back ... | [
"def",
"test_subquery",
"(",
"self",
")",
":",
"sub",
"=",
"Person",
".",
"objects",
".",
"using",
"(",
"'other'",
")",
".",
"filter",
"(",
"name",
"=",
"'fff'",
")",
"qs",
"=",
"Book",
".",
"objects",
".",
"filter",
"(",
"editor__in",
"=",
"sub",
... | [
805,
4
] | [
818,
20
] | python | en | ['en', 'en', 'en'] | True |
QueryTestCase.test_related_manager | (self) | Related managers return managers, not querysets | Related managers return managers, not querysets | def test_related_manager(self):
"Related managers return managers, not querysets"
mark = Person.objects.using('other').create(name="Mark Pilgrim")
# extra_arg is removed by the BookManager's implementation of
# create(); but the BookManager's implementation won't get called
# un... | [
"def",
"test_related_manager",
"(",
"self",
")",
":",
"mark",
"=",
"Person",
".",
"objects",
".",
"using",
"(",
"'other'",
")",
".",
"create",
"(",
"name",
"=",
"\"Mark Pilgrim\"",
")",
"# extra_arg is removed by the BookManager's implementation of",
"# create(); but ... | [
820,
4
] | [
841,
49
] | python | en | ['fr', 'en', 'en'] | True |
RouterTestCase.test_db_selection | (self) | Check that querysets obey the router for db suggestions | Check that querysets obey the router for db suggestions | def test_db_selection(self):
"Check that querysets obey the router for db suggestions"
self.assertEqual(Book.objects.db, 'other')
self.assertEqual(Book.objects.all().db, 'other')
self.assertEqual(Book.objects.using('default').db, 'default')
self.assertEqual(Book.objects.db_mana... | [
"def",
"test_db_selection",
"(",
"self",
")",
":",
"self",
".",
"assertEqual",
"(",
"Book",
".",
"objects",
".",
"db",
",",
"'other'",
")",
"self",
".",
"assertEqual",
"(",
"Book",
".",
"objects",
".",
"all",
"(",
")",
".",
"db",
",",
"'other'",
")",... | [
879,
4
] | [
887,
80
] | python | en | ['en', 'en', 'en'] | True |
RouterTestCase.test_migrate_selection | (self) | Synchronization behavior is predictable | Synchronization behavior is predictable | def test_migrate_selection(self):
"Synchronization behavior is predictable"
self.assertTrue(router.allow_migrate('default', User))
self.assertTrue(router.allow_migrate('default', Book))
self.assertTrue(router.allow_migrate('other', User))
self.assertTrue(router.allow_migrate('o... | [
"def",
"test_migrate_selection",
"(",
"self",
")",
":",
"self",
".",
"assertTrue",
"(",
"router",
".",
"allow_migrate",
"(",
"'default'",
",",
"User",
")",
")",
"self",
".",
"assertTrue",
"(",
"router",
".",
"allow_migrate",
"(",
"'default'",
",",
"Book",
... | [
889,
4
] | [
915,
61
] | python | en | ['en', 'de', 'en'] | True |
RouterTestCase.test_partial_router | (self) | A router can choose to implement a subset of methods | A router can choose to implement a subset of methods | def test_partial_router(self):
"A router can choose to implement a subset of methods"
dive = Book.objects.using('other').create(title="Dive into Python",
published=datetime.date(2009, 5, 4))
# First check the baseline behavior.
self.ass... | [
"def",
"test_partial_router",
"(",
"self",
")",
":",
"dive",
"=",
"Book",
".",
"objects",
".",
"using",
"(",
"'other'",
")",
".",
"create",
"(",
"title",
"=",
"\"Dive into Python\"",
",",
"published",
"=",
"datetime",
".",
"date",
"(",
"2009",
",",
"5",
... | [
917,
4
] | [
946,
62
] | python | en | ['en', 'en', 'en'] | True |
RouterTestCase.test_foreign_key_cross_database_protection | (self) | Foreign keys can cross databases if they two databases have a common source | Foreign keys can cross databases if they two databases have a common source | def test_foreign_key_cross_database_protection(self):
"Foreign keys can cross databases if they two databases have a common source"
# Create a book and author on the default database
pro = Book.objects.using('default').create(title="Pro Django",
... | [
"def",
"test_foreign_key_cross_database_protection",
"(",
"self",
")",
":",
"# Create a book and author on the default database",
"pro",
"=",
"Book",
".",
"objects",
".",
"using",
"(",
"'default'",
")",
".",
"create",
"(",
"title",
"=",
"\"Pro Django\"",
",",
"publish... | [
1005,
4
] | [
1133,
54
] | python | en | ['en', 'en', 'en'] | True |
RouterTestCase.test_m2m_cross_database_protection | (self) | M2M relations can cross databases if the database share a source | M2M relations can cross databases if the database share a source | def test_m2m_cross_database_protection(self):
"M2M relations can cross databases if the database share a source"
# Create books and authors on the inverse to the usual database
pro = Book.objects.using('other').create(pk=1, title="Pro Django",
pub... | [
"def",
"test_m2m_cross_database_protection",
"(",
"self",
")",
":",
"# Create books and authors on the inverse to the usual database",
"pro",
"=",
"Book",
".",
"objects",
".",
"using",
"(",
"'other'",
")",
".",
"create",
"(",
"pk",
"=",
"1",
",",
"title",
"=",
"\"... | [
1135,
4
] | [
1249,
50
] | python | en | ['en', 'en', 'en'] | True |
RouterTestCase.test_o2o_cross_database_protection | (self) | Operations that involve sharing FK objects across databases raise an error | Operations that involve sharing FK objects across databases raise an error | def test_o2o_cross_database_protection(self):
"Operations that involve sharing FK objects across databases raise an error"
# Create a user and profile on the default database
alice = User.objects.db_manager('default').create_user('alice', 'alice@example.com')
# Create a user and profile... | [
"def",
"test_o2o_cross_database_protection",
"(",
"self",
")",
":",
"# Create a user and profile on the default database",
"alice",
"=",
"User",
".",
"objects",
".",
"db_manager",
"(",
"'default'",
")",
".",
"create_user",
"(",
"'alice'",
",",
"'alice@example.com'",
")"... | [
1251,
4
] | [
1273,
50
] | python | en | ['en', 'en', 'en'] | True |
RouterTestCase.test_generic_key_cross_database_protection | (self) | Generic Key operations can span databases if they share a source | Generic Key operations can span databases if they share a source | def test_generic_key_cross_database_protection(self):
"Generic Key operations can span databases if they share a source"
# Create a book and author on the default database
pro = Book.objects.using(
'default').create(title="Pro Django", published=datetime.date(2008, 12, 16))
... | [
"def",
"test_generic_key_cross_database_protection",
"(",
"self",
")",
":",
"# Create a book and author on the default database",
"pro",
"=",
"Book",
".",
"objects",
".",
"using",
"(",
"'default'",
")",
".",
"create",
"(",
"title",
"=",
"\"Pro Django\"",
",",
"publish... | [
1275,
4
] | [
1356,
50
] | python | en | ['en', 'en', 'en'] | True |
RouterTestCase.test_m2m_managers | (self) | M2M relations are represented by managers, and can be controlled like managers | M2M relations are represented by managers, and can be controlled like managers | def test_m2m_managers(self):
"M2M relations are represented by managers, and can be controlled like managers"
pro = Book.objects.using('other').create(pk=1, title="Pro Django",
published=datetime.date(2008, 12, 16))
marty = Person.objects.using('... | [
"def",
"test_m2m_managers",
"(",
"self",
")",
":",
"pro",
"=",
"Book",
".",
"objects",
".",
"using",
"(",
"'other'",
")",
".",
"create",
"(",
"pk",
"=",
"1",
",",
"title",
"=",
"\"Pro Django\"",
",",
"published",
"=",
"datetime",
".",
"date",
"(",
"2... | [
1358,
4
] | [
1371,
82
] | python | en | ['en', 'en', 'en'] | True |
RouterTestCase.test_foreign_key_managers | (self) | FK reverse relations are represented by managers, and can be controlled like managers | FK reverse relations are represented by managers, and can be controlled like managers | def test_foreign_key_managers(self):
"FK reverse relations are represented by managers, and can be controlled like managers"
marty = Person.objects.using('other').create(pk=1, name="Marty Alchin")
Book.objects.using('other').create(pk=1, title="Pro Django",
... | [
"def",
"test_foreign_key_managers",
"(",
"self",
")",
":",
"marty",
"=",
"Person",
".",
"objects",
".",
"using",
"(",
"'other'",
")",
".",
"create",
"(",
"pk",
"=",
"1",
",",
"name",
"=",
"\"Marty Alchin\"",
")",
"Book",
".",
"objects",
".",
"using",
"... | [
1373,
4
] | [
1382,
80
] | python | en | ['en', 'en', 'en'] | True |
RouterTestCase.test_generic_key_managers | (self) | Generic key relations are represented by managers, and can be controlled like managers | Generic key relations are represented by managers, and can be controlled like managers | def test_generic_key_managers(self):
"Generic key relations are represented by managers, and can be controlled like managers"
pro = Book.objects.using('other').create(title="Pro Django",
published=datetime.date(2008, 12, 16))
Review.objects.using... | [
"def",
"test_generic_key_managers",
"(",
"self",
")",
":",
"pro",
"=",
"Book",
".",
"objects",
".",
"using",
"(",
"'other'",
")",
".",
"create",
"(",
"title",
"=",
"\"Pro Django\"",
",",
"published",
"=",
"datetime",
".",
"date",
"(",
"2008",
",",
"12",
... | [
1384,
4
] | [
1394,
79
] | python | en | ['en', 'en', 'en'] | True |
RouterTestCase.test_subquery | (self) | Make sure as_sql works with subqueries and primary/replica. | Make sure as_sql works with subqueries and primary/replica. | def test_subquery(self):
"""Make sure as_sql works with subqueries and primary/replica."""
# Create a book and author on the other database
mark = Person.objects.using('other').create(name="Mark Pilgrim")
Book.objects.using('other').create(title="Dive into Python",
... | [
"def",
"test_subquery",
"(",
"self",
")",
":",
"# Create a book and author on the other database",
"mark",
"=",
"Person",
".",
"objects",
".",
"using",
"(",
"'other'",
")",
".",
"create",
"(",
"name",
"=",
"\"Mark Pilgrim\"",
")",
"Book",
".",
"objects",
".",
... | [
1396,
4
] | [
1414,
88
] | python | en | ['en', 'en', 'en'] | True |
AuthTestCase.test_auth_manager | (self) | The methods on the auth manager obey database hints | The methods on the auth manager obey database hints | def test_auth_manager(self):
"The methods on the auth manager obey database hints"
# Create one user using default allocation policy
User.objects.create_user('alice', 'alice@example.com')
# Create another user, explicitly specifying the database
User.objects.db_manager('default'... | [
"def",
"test_auth_manager",
"(",
"self",
")",
":",
"# Create one user using default allocation policy",
"User",
".",
"objects",
".",
"create_user",
"(",
"'alice'",
",",
"'alice@example.com'",
")",
"# Create another user, explicitly specifying the database",
"User",
".",
"obje... | [
1443,
4
] | [
1469,
64
] | python | en | ['en', 'en', 'en'] | True |
AuthTestCase.test_dumpdata | (self) | Check that dumpdata honors allow_migrate restrictions on the router | Check that dumpdata honors allow_migrate restrictions on the router | def test_dumpdata(self):
"Check that dumpdata honors allow_migrate restrictions on the router"
User.objects.create_user('alice', 'alice@example.com')
User.objects.db_manager('default').create_user('bob', 'bob@example.com')
# Check that dumping the default database doesn't try to include... | [
"def",
"test_dumpdata",
"(",
"self",
")",
":",
"User",
".",
"objects",
".",
"create_user",
"(",
"'alice'",
",",
"'alice@example.com'",
")",
"User",
".",
"objects",
".",
"db_manager",
"(",
"'default'",
")",
".",
"create_user",
"(",
"'bob'",
",",
"'bob@example... | [
1471,
4
] | [
1487,
73
] | python | en | ['en', 'en', 'en'] | True |
AntiPetRouter.allow_migrate | (self, db, model) | Make sure the auth app only appears on the 'other' db | Make sure the auth app only appears on the 'other' db | def allow_migrate(self, db, model):
"Make sure the auth app only appears on the 'other' db"
if db == 'other':
return model._meta.object_name == 'Pet'
else:
return model._meta.object_name != 'Pet' | [
"def",
"allow_migrate",
"(",
"self",
",",
"db",
",",
"model",
")",
":",
"if",
"db",
"==",
"'other'",
":",
"return",
"model",
".",
"_meta",
".",
"object_name",
"==",
"'Pet'",
"else",
":",
"return",
"model",
".",
"_meta",
".",
"object_name",
"!=",
"'Pet'... | [
1494,
4
] | [
1499,
51
] | python | en | ['en', 'en', 'en'] | True |
FixtureTestCase.test_fixture_loading | (self) | Multi-db fixtures are loaded correctly | Multi-db fixtures are loaded correctly | def test_fixture_loading(self):
"Multi-db fixtures are loaded correctly"
# Check that "Pro Django" exists on the default database, but not on other database
try:
Book.objects.get(title="Pro Django")
Book.objects.using('default').get(title="Pro Django")
except Book... | [
"def",
"test_fixture_loading",
"(",
"self",
")",
":",
"# Check that \"Pro Django\" exists on the default database, but not on other database",
"try",
":",
"Book",
".",
"objects",
".",
"get",
"(",
"title",
"=",
"\"Pro Django\"",
")",
"Book",
".",
"objects",
".",
"using",... | [
1515,
4
] | [
1553,
88
] | python | en | ['en', 'en', 'en'] | True |
FixtureTestCase.test_pseudo_empty_fixtures | (self) | A fixture can contain entries, but lead to nothing in the database; this shouldn't raise an error (ref #14068) | A fixture can contain entries, but lead to nothing in the database; this shouldn't raise an error (ref #14068) | def test_pseudo_empty_fixtures(self):
"A fixture can contain entries, but lead to nothing in the database; this shouldn't raise an error (ref #14068)"
new_io = StringIO()
management.call_command('loaddata', 'pets', stdout=new_io, stderr=new_io)
command_output = new_io.getvalue().strip()
... | [
"def",
"test_pseudo_empty_fixtures",
"(",
"self",
")",
":",
"new_io",
"=",
"StringIO",
"(",
")",
"management",
".",
"call_command",
"(",
"'loaddata'",
",",
"'pets'",
",",
"stdout",
"=",
"new_io",
",",
"stderr",
"=",
"new_io",
")",
"command_output",
"=",
"new... | [
1555,
4
] | [
1561,
90
] | python | en | ['en', 'en', 'en'] | True |
SignalTests._write_to_other | (self) | Sends all writes to 'other'. | Sends all writes to 'other'. | def _write_to_other(self):
"Sends all writes to 'other'."
router.routers = [WriteToOtherRouter()] | [
"def",
"_write_to_other",
"(",
"self",
")",
":",
"router",
".",
"routers",
"=",
"[",
"WriteToOtherRouter",
"(",
")",
"]"
] | [
1599,
4
] | [
1601,
47
] | python | en | ['en', 'en', 'en'] | True |
SignalTests._write_to_default | (self) | Sends all writes to the default DB | Sends all writes to the default DB | def _write_to_default(self):
"Sends all writes to the default DB"
router.routers = self.old_routers | [
"def",
"_write_to_default",
"(",
"self",
")",
":",
"router",
".",
"routers",
"=",
"self",
".",
"old_routers"
] | [
1603,
4
] | [
1605,
41
] | python | en | ['en', 'en', 'en'] | True |
SignalTests.test_database_arg_save_and_delete | (self) |
Tests that the pre/post_save signal contains the correct database.
(#13552)
|
Tests that the pre/post_save signal contains the correct database.
(#13552)
| def test_database_arg_save_and_delete(self):
"""
Tests that the pre/post_save signal contains the correct database.
(#13552)
"""
# Make some signal receivers
pre_save_receiver = DatabaseReceiver()
post_save_receiver = DatabaseReceiver()
pre_delete_receiver... | [
"def",
"test_database_arg_save_and_delete",
"(",
"self",
")",
":",
"# Make some signal receivers",
"pre_save_receiver",
"=",
"DatabaseReceiver",
"(",
")",
"post_save_receiver",
"=",
"DatabaseReceiver",
"(",
")",
"pre_delete_receiver",
"=",
"DatabaseReceiver",
"(",
")",
"p... | [
1607,
4
] | [
1643,
84
] | python | en | ['en', 'error', 'th'] | False |
SignalTests.test_database_arg_m2m | (self) |
Test that the m2m_changed signal has a correct database arg (#13552)
|
Test that the m2m_changed signal has a correct database arg (#13552)
| def test_database_arg_m2m(self):
"""
Test that the m2m_changed signal has a correct database arg (#13552)
"""
# Make a receiver
receiver = DatabaseReceiver()
# Connect it
signals.m2m_changed.connect(receiver=receiver)
# Create the models that will be used... | [
"def",
"test_database_arg_m2m",
"(",
"self",
")",
":",
"# Make a receiver",
"receiver",
"=",
"DatabaseReceiver",
"(",
")",
"# Connect it",
"signals",
".",
"m2m_changed",
".",
"connect",
"(",
"receiver",
"=",
"receiver",
")",
"# Create the models that will be used for th... | [
1645,
4
] | [
1695,
53
] | python | en | ['en', 'error', 'th'] | False |
RouterAttributeErrorTestCase.test_attribute_error_read | (self) | Check that the AttributeError from AttributeErrorRouter bubbles up | Check that the AttributeError from AttributeErrorRouter bubbles up | def test_attribute_error_read(self):
"Check that the AttributeError from AttributeErrorRouter bubbles up"
router.routers = [] # Reset routers so we can save a Book instance
b = Book.objects.create(title="Pro Django",
published=datetime.date(2008, 12, 16))
... | [
"def",
"test_attribute_error_read",
"(",
"self",
")",
":",
"router",
".",
"routers",
"=",
"[",
"]",
"# Reset routers so we can save a Book instance",
"b",
"=",
"Book",
".",
"objects",
".",
"create",
"(",
"title",
"=",
"\"Pro Django\"",
",",
"published",
"=",
"da... | [
1717,
4
] | [
1723,
68
] | python | en | ['en', 'en', 'en'] | True |
RouterAttributeErrorTestCase.test_attribute_error_save | (self) | Check that the AttributeError from AttributeErrorRouter bubbles up | Check that the AttributeError from AttributeErrorRouter bubbles up | def test_attribute_error_save(self):
"Check that the AttributeError from AttributeErrorRouter bubbles up"
dive = Book()
dive.title = "Dive into Python"
dive.published = datetime.date(2009, 5, 4)
self.assertRaises(AttributeError, dive.save) | [
"def",
"test_attribute_error_save",
"(",
"self",
")",
":",
"dive",
"=",
"Book",
"(",
")",
"dive",
".",
"title",
"=",
"\"Dive into Python\"",
"dive",
".",
"published",
"=",
"datetime",
".",
"date",
"(",
"2009",
",",
"5",
",",
"4",
")",
"self",
".",
"ass... | [
1725,
4
] | [
1730,
52
] | python | en | ['en', 'en', 'en'] | True |
RouterAttributeErrorTestCase.test_attribute_error_delete | (self) | Check that the AttributeError from AttributeErrorRouter bubbles up | Check that the AttributeError from AttributeErrorRouter bubbles up | def test_attribute_error_delete(self):
"Check that the AttributeError from AttributeErrorRouter bubbles up"
router.routers = [] # Reset routers so we can save our Book, Person instances
b = Book.objects.create(title="Pro Django",
published=datetime.date(2008, 12,... | [
"def",
"test_attribute_error_delete",
"(",
"self",
")",
":",
"router",
".",
"routers",
"=",
"[",
"]",
"# Reset routers so we can save our Book, Person instances",
"b",
"=",
"Book",
".",
"objects",
".",
"create",
"(",
"title",
"=",
"\"Pro Django\"",
",",
"published",... | [
1732,
4
] | [
1741,
51
] | python | en | ['en', 'en', 'en'] | True |
RouterAttributeErrorTestCase.test_attribute_error_m2m | (self) | Check that the AttributeError from AttributeErrorRouter bubbles up | Check that the AttributeError from AttributeErrorRouter bubbles up | def test_attribute_error_m2m(self):
"Check that the AttributeError from AttributeErrorRouter bubbles up"
router.routers = [] # Reset routers so we can save our Book, Person instances
b = Book.objects.create(title="Pro Django",
published=datetime.date(2008, 12, 16... | [
"def",
"test_attribute_error_m2m",
"(",
"self",
")",
":",
"router",
".",
"routers",
"=",
"[",
"]",
"# Reset routers so we can save our Book, Person instances",
"b",
"=",
"Book",
".",
"objects",
".",
"create",
"(",
"title",
"=",
"\"Pro Django\"",
",",
"published",
... | [
1743,
4
] | [
1750,
69
] | python | en | ['en', 'en', 'en'] | True |
MigrateTestCase.test_migrate_to_other_database | (self) | Regression test for #16039: migrate with --database option. | Regression test for #16039: migrate with --database option. | def test_migrate_to_other_database(self):
"""Regression test for #16039: migrate with --database option."""
cts = ContentType.objects.using('other').filter(app_label='multiple_database')
count = cts.count()
self.assertGreater(count, 0)
cts.delete()
management.call_comma... | [
"def",
"test_migrate_to_other_database",
"(",
"self",
")",
":",
"cts",
"=",
"ContentType",
".",
"objects",
".",
"using",
"(",
"'other'",
")",
".",
"filter",
"(",
"app_label",
"=",
"'multiple_database'",
")",
"count",
"=",
"cts",
".",
"count",
"(",
")",
"se... | [
1807,
4
] | [
1817,
44
] | python | en | ['en', 'en', 'en'] | True |
MigrateTestCase.test_migrate_to_other_database_with_router | (self) | Regression test for #16039: migrate with --database option. | Regression test for #16039: migrate with --database option. | def test_migrate_to_other_database_with_router(self):
"""Regression test for #16039: migrate with --database option."""
cts = ContentType.objects.using('other').filter(app_label='multiple_database')
cts.delete()
try:
old_routers = router.routers
router.routers = ... | [
"def",
"test_migrate_to_other_database_with_router",
"(",
"self",
")",
":",
"cts",
"=",
"ContentType",
".",
"objects",
".",
"using",
"(",
"'other'",
")",
".",
"filter",
"(",
"app_label",
"=",
"'multiple_database'",
")",
"cts",
".",
"delete",
"(",
")",
"try",
... | [
1819,
4
] | [
1832,
40
] | python | en | ['en', 'en', 'en'] | True |
PasswordResetTokenGenerator.make_token | (self, user) |
Returns a token that can be used once to do a password reset
for the given user.
|
Returns a token that can be used once to do a password reset
for the given user.
| def make_token(self, user):
"""
Returns a token that can be used once to do a password reset
for the given user.
"""
return self._make_token_with_timestamp(user, self._num_days(self._today())) | [
"def",
"make_token",
"(",
"self",
",",
"user",
")",
":",
"return",
"self",
".",
"_make_token_with_timestamp",
"(",
"user",
",",
"self",
".",
"_num_days",
"(",
"self",
".",
"_today",
"(",
")",
")",
")"
] | [
12,
4
] | [
17,
83
] | python | en | ['en', 'error', 'th'] | False |
PasswordResetTokenGenerator.check_token | (self, user, token) |
Check that a password reset token is correct for a given user.
|
Check that a password reset token is correct for a given user.
| def check_token(self, user, token):
"""
Check that a password reset token is correct for a given user.
"""
# Parse the token
try:
ts_b36, hash = token.split("-")
except ValueError:
return False
try:
ts = base36_to_int(ts_b36)
... | [
"def",
"check_token",
"(",
"self",
",",
"user",
",",
"token",
")",
":",
"# Parse the token",
"try",
":",
"ts_b36",
",",
"hash",
"=",
"token",
".",
"split",
"(",
"\"-\"",
")",
"except",
"ValueError",
":",
"return",
"False",
"try",
":",
"ts",
"=",
"base3... | [
19,
4
] | [
42,
19
] | python | en | ['en', 'error', 'th'] | False |
SeleniumTestCaseBase.__new__ | (cls, name, bases, attrs) |
Dynamically create new classes and add them to the test module when
multiple browsers specs are provided (e.g. --selenium=firefox,chrome).
|
Dynamically create new classes and add them to the test module when
multiple browsers specs are provided (e.g. --selenium=firefox,chrome).
| def __new__(cls, name, bases, attrs):
"""
Dynamically create new classes and add them to the test module when
multiple browsers specs are provided (e.g. --selenium=firefox,chrome).
"""
test_class = super().__new__(cls, name, bases, attrs)
# If the test class is either bro... | [
"def",
"__new__",
"(",
"cls",
",",
"name",
",",
"bases",
",",
"attrs",
")",
":",
"test_class",
"=",
"super",
"(",
")",
".",
"__new__",
"(",
"cls",
",",
"name",
",",
"bases",
",",
"attrs",
")",
"# If the test class is either browser-specific or a test base, ret... | [
22,
4
] | [
60,
66
] | python | en | ['en', 'error', 'th'] | False |
SessionStore.load | (self) |
Load the data from the key itself instead of fetching from some
external data store. Opposite of _get_session_key(), raise BadSignature
if signature fails.
|
Load the data from the key itself instead of fetching from some
external data store. Opposite of _get_session_key(), raise BadSignature
if signature fails.
| def load(self):
"""
Load the data from the key itself instead of fetching from some
external data store. Opposite of _get_session_key(), raise BadSignature
if signature fails.
"""
try:
return signing.loads(
self.session_key,
ser... | [
"def",
"load",
"(",
"self",
")",
":",
"try",
":",
"return",
"signing",
".",
"loads",
"(",
"self",
".",
"session_key",
",",
"serializer",
"=",
"self",
".",
"serializer",
",",
"# This doesn't handle non-default expiry dates, see #19201",
"max_age",
"=",
"self",
".... | [
6,
4
] | [
24,
17
] | python | en | ['en', 'error', 'th'] | False |
SessionStore.create | (self) |
To create a new key, set the modified flag so that the cookie is set
on the client for the current request.
|
To create a new key, set the modified flag so that the cookie is set
on the client for the current request.
| def create(self):
"""
To create a new key, set the modified flag so that the cookie is set
on the client for the current request.
"""
self.modified = True | [
"def",
"create",
"(",
"self",
")",
":",
"self",
".",
"modified",
"=",
"True"
] | [
26,
4
] | [
31,
28
] | python | en | ['en', 'error', 'th'] | False |
SessionStore.save | (self, must_create=False) |
To save, get the session key as a securely signed string and then set
the modified flag so that the cookie is set on the client for the
current request.
|
To save, get the session key as a securely signed string and then set
the modified flag so that the cookie is set on the client for the
current request.
| def save(self, must_create=False):
"""
To save, get the session key as a securely signed string and then set
the modified flag so that the cookie is set on the client for the
current request.
"""
self._session_key = self._get_session_key()
self.modified = True | [
"def",
"save",
"(",
"self",
",",
"must_create",
"=",
"False",
")",
":",
"self",
".",
"_session_key",
"=",
"self",
".",
"_get_session_key",
"(",
")",
"self",
".",
"modified",
"=",
"True"
] | [
33,
4
] | [
40,
28
] | python | en | ['en', 'error', 'th'] | False |
SessionStore.exists | (self, session_key=None) |
This method makes sense when you're talking to a shared resource, but
it doesn't matter when you're storing the information in the client's
cookie.
|
This method makes sense when you're talking to a shared resource, but
it doesn't matter when you're storing the information in the client's
cookie.
| def exists(self, session_key=None):
"""
This method makes sense when you're talking to a shared resource, but
it doesn't matter when you're storing the information in the client's
cookie.
"""
return False | [
"def",
"exists",
"(",
"self",
",",
"session_key",
"=",
"None",
")",
":",
"return",
"False"
] | [
42,
4
] | [
48,
20
] | python | en | ['en', 'error', 'th'] | False |
SessionStore.delete | (self, session_key=None) |
To delete, clear the session key and the underlying data structure
and set the modified flag so that the cookie is set on the client for
the current request.
|
To delete, clear the session key and the underlying data structure
and set the modified flag so that the cookie is set on the client for
the current request.
| def delete(self, session_key=None):
"""
To delete, clear the session key and the underlying data structure
and set the modified flag so that the cookie is set on the client for
the current request.
"""
self._session_key = ''
self._session_cache = {}
self.m... | [
"def",
"delete",
"(",
"self",
",",
"session_key",
"=",
"None",
")",
":",
"self",
".",
"_session_key",
"=",
"''",
"self",
".",
"_session_cache",
"=",
"{",
"}",
"self",
".",
"modified",
"=",
"True"
] | [
50,
4
] | [
58,
28
] | python | en | ['en', 'error', 'th'] | False |
SessionStore.cycle_key | (self) |
Keep the same data but with a new key. Call save() and it will
automatically save a cookie with a new key at the end of the request.
|
Keep the same data but with a new key. Call save() and it will
automatically save a cookie with a new key at the end of the request.
| def cycle_key(self):
"""
Keep the same data but with a new key. Call save() and it will
automatically save a cookie with a new key at the end of the request.
"""
self.save() | [
"def",
"cycle_key",
"(",
"self",
")",
":",
"self",
".",
"save",
"(",
")"
] | [
60,
4
] | [
65,
19
] | python | en | ['en', 'error', 'th'] | False |
SessionStore._get_session_key | (self) |
Instead of generating a random string, generate a secure url-safe
base64-encoded string of data as our session key.
|
Instead of generating a random string, generate a secure url-safe
base64-encoded string of data as our session key.
| def _get_session_key(self):
"""
Instead of generating a random string, generate a secure url-safe
base64-encoded string of data as our session key.
"""
return signing.dumps(
self._session, compress=True,
salt='django.contrib.sessions.backends.signed_cookie... | [
"def",
"_get_session_key",
"(",
"self",
")",
":",
"return",
"signing",
".",
"dumps",
"(",
"self",
".",
"_session",
",",
"compress",
"=",
"True",
",",
"salt",
"=",
"'django.contrib.sessions.backends.signed_cookies'",
",",
"serializer",
"=",
"self",
".",
"serializ... | [
67,
4
] | [
76,
9
] | python | en | ['en', 'error', 'th'] | False |
validate_options | (options) | Validates options. | Validates options. | def validate_options(options):
"""Validates options."""
kwcase = options.get('keyword_case')
if kwcase not in [None, 'upper', 'lower', 'capitalize']:
raise SQLParseError('Invalid value for keyword_case: '
'{0!r}'.format(kwcase))
idcase = options.get('identifier_case'... | [
"def",
"validate_options",
"(",
"options",
")",
":",
"kwcase",
"=",
"options",
".",
"get",
"(",
"'keyword_case'",
")",
"if",
"kwcase",
"not",
"in",
"[",
"None",
",",
"'upper'",
",",
"'lower'",
",",
"'capitalize'",
"]",
":",
"raise",
"SQLParseError",
"(",
... | [
14,
0
] | [
129,
18
] | python | en | ['en', 'et', 'en'] | False |
build_filter_stack | (stack, options) | Setup and return a filter stack.
Args:
stack: :class:`~sqlparse.filters.FilterStack` instance
options: Dictionary with options validated by validate_options.
| Setup and return a filter stack. | def build_filter_stack(stack, options):
"""Setup and return a filter stack.
Args:
stack: :class:`~sqlparse.filters.FilterStack` instance
options: Dictionary with options validated by validate_options.
"""
# Token filter
if options.get('keyword_case'):
stack.preprocess.append(
... | [
"def",
"build_filter_stack",
"(",
"stack",
",",
"options",
")",
":",
"# Token filter",
"if",
"options",
".",
"get",
"(",
"'keyword_case'",
")",
":",
"stack",
".",
"preprocess",
".",
"append",
"(",
"filters",
".",
"KeywordCaseFilter",
"(",
"options",
"[",
"'k... | [
132,
0
] | [
198,
16
] | python | en | ['en', 'da', 'en'] | True |
ChangeList.get_filters_params | (self, params=None) |
Return all params except IGNORED_PARAMS.
|
Return all params except IGNORED_PARAMS.
| def get_filters_params(self, params=None):
"""
Return all params except IGNORED_PARAMS.
"""
params = params or self.params
lookup_params = params.copy() # a dictionary of the query string
# Remove all the parameters that are globally and systematically
# ignored.... | [
"def",
"get_filters_params",
"(",
"self",
",",
"params",
"=",
"None",
")",
":",
"params",
"=",
"params",
"or",
"self",
".",
"params",
"lookup_params",
"=",
"params",
".",
"copy",
"(",
")",
"# a dictionary of the query string",
"# Remove all the parameters that are g... | [
107,
4
] | [
118,
28
] | python | en | ['en', 'error', 'th'] | False |
ChangeList.get_ordering_field | (self, field_name) |
Return the proper model field name corresponding to the given
field_name to use for ordering. field_name may either be the name of a
proper model field or the name of a method (on the admin or model) or a
callable with the 'admin_order_field' attribute. Return None if no
proper ... |
Return the proper model field name corresponding to the given
field_name to use for ordering. field_name may either be the name of a
proper model field or the name of a method (on the admin or model) or a
callable with the 'admin_order_field' attribute. Return None if no
proper ... | def get_ordering_field(self, field_name):
"""
Return the proper model field name corresponding to the given
field_name to use for ordering. field_name may either be the name of a
proper model field or the name of a method (on the admin or model) or a
callable with the 'admin_orde... | [
"def",
"get_ordering_field",
"(",
"self",
",",
"field_name",
")",
":",
"try",
":",
"field",
"=",
"self",
".",
"lookup_opts",
".",
"get_field",
"(",
"field_name",
")",
"return",
"field",
".",
"name",
"except",
"FieldDoesNotExist",
":",
"# See whether field_name i... | [
263,
4
] | [
285,
59
] | python | en | ['en', 'error', 'th'] | False |
ChangeList.get_ordering | (self, request, queryset) |
Return the list of ordering fields for the change list.
First check the get_ordering() method in model admin, then check
the object's default ordering. Then, any manually-specified ordering
from the query string overrides anything. Finally, a deterministic
order is guaranteed by... |
Return the list of ordering fields for the change list.
First check the get_ordering() method in model admin, then check
the object's default ordering. Then, any manually-specified ordering
from the query string overrides anything. Finally, a deterministic
order is guaranteed by... | def get_ordering(self, request, queryset):
"""
Return the list of ordering fields for the change list.
First check the get_ordering() method in model admin, then check
the object's default ordering. Then, any manually-specified ordering
from the query string overrides anything. F... | [
"def",
"get_ordering",
"(",
"self",
",",
"request",
",",
"queryset",
")",
":",
"params",
"=",
"self",
".",
"params",
"ordering",
"=",
"list",
"(",
"self",
".",
"model_admin",
".",
"get_ordering",
"(",
"request",
")",
"or",
"self",
".",
"_get_default_orderi... | [
287,
4
] | [
323,
57
] | python | en | ['en', 'error', 'th'] | False |
ChangeList._get_deterministic_ordering | (self, ordering) |
Ensure a deterministic order across all database backends. Search for a
single field or unique together set of fields providing a total
ordering. If these are missing, augment the ordering with a descendant
primary key.
|
Ensure a deterministic order across all database backends. Search for a
single field or unique together set of fields providing a total
ordering. If these are missing, augment the ordering with a descendant
primary key.
| def _get_deterministic_ordering(self, ordering):
"""
Ensure a deterministic order across all database backends. Search for a
single field or unique together set of fields providing a total
ordering. If these are missing, augment the ordering with a descendant
primary key.
... | [
"def",
"_get_deterministic_ordering",
"(",
"self",
",",
"ordering",
")",
":",
"ordering",
"=",
"list",
"(",
"ordering",
")",
"ordering_fields",
"=",
"set",
"(",
")",
"total_ordering_fields",
"=",
"{",
"'pk'",
"}",
"|",
"{",
"field",
".",
"attname",
"for",
... | [
325,
4
] | [
377,
23
] | python | en | ['en', 'error', 'th'] | False |
ChangeList.get_ordering_field_columns | (self) |
Return a dictionary of ordering field column numbers and asc/desc.
|
Return a dictionary of ordering field column numbers and asc/desc.
| def get_ordering_field_columns(self):
"""
Return a dictionary of ordering field column numbers and asc/desc.
"""
# We must cope with more than one column having the same underlying sort
# field, so we base things on column numbers.
ordering = self._get_default_ordering()
... | [
"def",
"get_ordering_field_columns",
"(",
"self",
")",
":",
"# We must cope with more than one column having the same underlying sort",
"# field, so we base things on column numbers.",
"ordering",
"=",
"self",
".",
"_get_default_ordering",
"(",
")",
"ordering_fields",
"=",
"{",
"... | [
379,
4
] | [
417,
30
] | python | en | ['en', 'error', 'th'] | False |
fgm | (
x,
logits,
y=None,
eps=0.3,
ord=np.inf,
loss_fn=softmax_cross_entropy_with_logits,
clip_min=None,
clip_max=None,
clip_grad=False,
targeted=False,
sanity_checks=True,
) |
TensorFlow implementation of the Fast Gradient 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 parameter... |
TensorFlow implementation of the Fast Gradient 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 parameter... | def fgm(
x,
logits,
y=None,
eps=0.3,
ord=np.inf,
loss_fn=softmax_cross_entropy_with_logits,
clip_min=None,
clip_max=None,
clip_grad=False,
targeted=False,
sanity_checks=True,
):
"""
TensorFlow implementation of the Fast Gradient Method.
:param x: the input placeho... | [
"def",
"fgm",
"(",
"x",
",",
"logits",
",",
"y",
"=",
"None",
",",
"eps",
"=",
"0.3",
",",
"ord",
"=",
"np",
".",
"inf",
",",
"loss_fn",
"=",
"softmax_cross_entropy_with_logits",
",",
"clip_min",
"=",
"None",
",",
"clip_max",
"=",
"None",
",",
"clip_... | [
135,
0
] | [
220,
16
] | python | en | ['en', 'error', 'th'] | False |
optimize_linear | (grad, eps, ord=np.inf) |
Solves for the optimal input to a linear function under a norm constraint.
Optimal_perturbation = argmax_{eta, ||eta||_{ord} < eps} dot(eta, grad)
:param grad: tf tensor containing a batch of gradients
:param eps: float scalar specifying size of constraint region
:param ord: int specifying order ... |
Solves for the optimal input to a linear function under a norm constraint. | def optimize_linear(grad, eps, ord=np.inf):
"""
Solves for the optimal input to a linear function under a norm constraint.
Optimal_perturbation = argmax_{eta, ||eta||_{ord} < eps} dot(eta, grad)
:param grad: tf tensor containing a batch of gradients
:param eps: float scalar specifying size of cons... | [
"def",
"optimize_linear",
"(",
"grad",
",",
"eps",
",",
"ord",
"=",
"np",
".",
"inf",
")",
":",
"# In Python 2, the `list` call in the following line is redundant / harmless.",
"# In Python 3, the `list` call is needed to convert the iterator returned by `range` into a list.",
"red_i... | [
223,
0
] | [
270,
30
] | python | en | ['en', 'error', 'th'] | False |
FastGradientMethod.__init__ | (self, model, sess=None, dtypestr="float32", **kwargs) |
Create a FastGradientMethod instance.
Note: the model parameter should be an instance of the
cleverhans.model.Model abstraction provided by CleverHans.
|
Create a FastGradientMethod 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 FastGradientMethod instance.
Note: the model parameter should be an instance of the
cleverhans.model.Model abstraction provided by CleverHans.
"""
super(FastGradientMethod, self).__init__(mo... | [
"def",
"__init__",
"(",
"self",
",",
"model",
",",
"sess",
"=",
"None",
",",
"dtypestr",
"=",
"\"float32\"",
",",
"*",
"*",
"kwargs",
")",
":",
"super",
"(",
"FastGradientMethod",
",",
"self",
")",
".",
"__init__",
"(",
"model",
",",
"sess",
",",
"dt... | [
28,
4
] | [
37,
81
] | python | en | ['en', 'error', 'th'] | False |
FastGradientMethod.generate | (self, x, **kwargs) |
Returns the graph for Fast Gradient Method adversarial examples.
:param x: The model's symbolic inputs.
:param kwargs: See `parse_params`
|
Returns the graph for Fast Gradient Method adversarial examples. | def generate(self, x, **kwargs):
"""
Returns the graph for Fast Gradient Method adversarial examples.
: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",
")",
"labels",
",",
"_nb_classes",
"=",
"self",
".",
"get_or_guess_label... | [
39,
4
] | [
63,
9
] | python | en | ['en', 'error', 'th'] | False |
FastGradientMethod.parse_params | (
self,
eps=0.3,
ord=np.inf,
loss_fn=softmax_cross_entropy_with_logits,
y=None,
y_target=None,
clip_min=None,
clip_max=None,
clip_grad=False,
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) attack step size (input variation)
:param ord: (optional) Order of the norm (mimics NumPy).
Poss... |
Take in a dictionary of parameters and applies attack-specific checks
before saving them as attributes. | def parse_params(
self,
eps=0.3,
ord=np.inf,
loss_fn=softmax_cross_entropy_with_logits,
y=None,
y_target=None,
clip_min=None,
clip_max=None,
clip_grad=False,
sanity_checks=True,
**kwargs
):
"""
Take in a dictiona... | [
"def",
"parse_params",
"(",
"self",
",",
"eps",
"=",
"0.3",
",",
"ord",
"=",
"np",
".",
"inf",
",",
"loss_fn",
"=",
"softmax_cross_entropy_with_logits",
",",
"y",
"=",
"None",
",",
"y_target",
"=",
"None",
",",
"clip_min",
"=",
"None",
",",
"clip_max",
... | [
65,
4
] | [
132,
19
] | python | en | ['en', 'error', 'th'] | False |
RequestEncodingMixin.path_url | (self) | Build the path URL to use. | Build the path URL to use. | def path_url(self):
"""Build the path URL to use."""
url = []
p = urlsplit(self.url)
path = p.path
if not path:
path = '/'
url.append(path)
query = p.query
if query:
url.append('?')
url.append(query)
return... | [
"def",
"path_url",
"(",
"self",
")",
":",
"url",
"=",
"[",
"]",
"p",
"=",
"urlsplit",
"(",
"self",
".",
"url",
")",
"path",
"=",
"p",
".",
"path",
"if",
"not",
"path",
":",
"path",
"=",
"'/'",
"url",
".",
"append",
"(",
"path",
")",
"query",
... | [
61,
4
] | [
79,
27
] | python | en | ['en', 'en', 'en'] | True |
RequestEncodingMixin._encode_params | (data) | Encode parameters in a piece of data.
Will successfully encode parameters when passed as a dict or a list of
2-tuples. Order is retained if data is a list of 2-tuples but arbitrary
if parameters are supplied as a dict.
| Encode parameters in a piece of data. | def _encode_params(data):
"""Encode parameters in a piece of data.
Will successfully encode parameters when passed as a dict or a list of
2-tuples. Order is retained if data is a list of 2-tuples but arbitrary
if parameters are supplied as a dict.
"""
if isinstance(data... | [
"def",
"_encode_params",
"(",
"data",
")",
":",
"if",
"isinstance",
"(",
"data",
",",
"(",
"str",
",",
"bytes",
")",
")",
":",
"return",
"data",
"elif",
"hasattr",
"(",
"data",
",",
"'read'",
")",
":",
"return",
"data",
"elif",
"hasattr",
"(",
"data"... | [
82,
4
] | [
106,
23
] | python | en | ['en', 'en', 'en'] | True |
RequestEncodingMixin._encode_files | (files, data) | Build the body for a multipart/form-data request.
Will successfully encode files when passed as a dict or a list of
tuples. Order is retained if data is a list of tuples but arbitrary
if parameters are supplied as a dict.
The tuples may be 2-tuples (filename, fileobj), 3-tuples (filenam... | Build the body for a multipart/form-data request. | def _encode_files(files, data):
"""Build the body for a multipart/form-data request.
Will successfully encode files when passed as a dict or a list of
tuples. Order is retained if data is a list of tuples but arbitrary
if parameters are supplied as a dict.
The tuples may be 2-tu... | [
"def",
"_encode_files",
"(",
"files",
",",
"data",
")",
":",
"if",
"(",
"not",
"files",
")",
":",
"raise",
"ValueError",
"(",
"\"Files must be provided.\"",
")",
"elif",
"isinstance",
"(",
"data",
",",
"basestring",
")",
":",
"raise",
"ValueError",
"(",
"\... | [
109,
4
] | [
170,
33
] | python | en | ['en', 'en', 'en'] | True |
RequestHooksMixin.register_hook | (self, event, hook) | Properly register a hook. | Properly register a hook. | def register_hook(self, event, hook):
"""Properly register a hook."""
if event not in self.hooks:
raise ValueError('Unsupported event specified, with event name "%s"' % (event))
if isinstance(hook, Callable):
self.hooks[event].append(hook)
elif hasattr(hook, '__... | [
"def",
"register_hook",
"(",
"self",
",",
"event",
",",
"hook",
")",
":",
"if",
"event",
"not",
"in",
"self",
".",
"hooks",
":",
"raise",
"ValueError",
"(",
"'Unsupported event specified, with event name \"%s\"'",
"%",
"(",
"event",
")",
")",
"if",
"isinstance... | [
174,
4
] | [
183,
80
] | python | en | ['en', 'da', 'en'] | True |
RequestHooksMixin.deregister_hook | (self, event, hook) | Deregister a previously registered hook.
Returns True if the hook existed, False if not.
| Deregister a previously registered hook.
Returns True if the hook existed, False if not.
| def deregister_hook(self, event, hook):
"""Deregister a previously registered hook.
Returns True if the hook existed, False if not.
"""
try:
self.hooks[event].remove(hook)
return True
except ValueError:
return False | [
"def",
"deregister_hook",
"(",
"self",
",",
"event",
",",
"hook",
")",
":",
"try",
":",
"self",
".",
"hooks",
"[",
"event",
"]",
".",
"remove",
"(",
"hook",
")",
"return",
"True",
"except",
"ValueError",
":",
"return",
"False"
] | [
185,
4
] | [
194,
24
] | python | en | ['en', 'da', 'en'] | True |
Request.prepare | (self) | Constructs a :class:`PreparedRequest <PreparedRequest>` for transmission and returns it. | Constructs a :class:`PreparedRequest <PreparedRequest>` for transmission and returns it. | def prepare(self):
"""Constructs a :class:`PreparedRequest <PreparedRequest>` for transmission and returns it."""
p = PreparedRequest()
p.prepare(
method=self.method,
url=self.url,
headers=self.headers,
files=self.files,
data=self.data,... | [
"def",
"prepare",
"(",
"self",
")",
":",
"p",
"=",
"PreparedRequest",
"(",
")",
"p",
".",
"prepare",
"(",
"method",
"=",
"self",
".",
"method",
",",
"url",
"=",
"self",
".",
"url",
",",
"headers",
"=",
"self",
".",
"headers",
",",
"files",
"=",
"... | [
253,
4
] | [
268,
16
] | python | en | ['en', 'co', 'en'] | True |
PreparedRequest.prepare | (self,
method=None, url=None, headers=None, files=None, data=None,
params=None, auth=None, cookies=None, hooks=None, json=None) | Prepares the entire request with the given parameters. | Prepares the entire request with the given parameters. | def prepare(self,
method=None, url=None, headers=None, files=None, data=None,
params=None, auth=None, cookies=None, hooks=None, json=None):
"""Prepares the entire request with the given parameters."""
self.prepare_method(method)
self.prepare_url(url, params)
self... | [
"def",
"prepare",
"(",
"self",
",",
"method",
"=",
"None",
",",
"url",
"=",
"None",
",",
"headers",
"=",
"None",
",",
"files",
"=",
"None",
",",
"data",
"=",
"None",
",",
"params",
"=",
"None",
",",
"auth",
"=",
"None",
",",
"cookies",
"=",
"None... | [
307,
4
] | [
323,
33
] | python | en | ['en', 'en', 'en'] | True |
PreparedRequest.prepare_method | (self, method) | Prepares the given HTTP method. | Prepares the given HTTP method. | def prepare_method(self, method):
"""Prepares the given HTTP method."""
self.method = method
if self.method is not None:
self.method = to_native_string(self.method.upper()) | [
"def",
"prepare_method",
"(",
"self",
",",
"method",
")",
":",
"self",
".",
"method",
"=",
"method",
"if",
"self",
".",
"method",
"is",
"not",
"None",
":",
"self",
".",
"method",
"=",
"to_native_string",
"(",
"self",
".",
"method",
".",
"upper",
"(",
... | [
339,
4
] | [
343,
63
] | python | en | ['en', 'en', 'en'] | True |
PreparedRequest.prepare_url | (self, url, params) | Prepares the given HTTP URL. | Prepares the given HTTP URL. | def prepare_url(self, url, params):
"""Prepares the given HTTP URL."""
#: Accept objects that have string representations.
#: We're unable to blindly call unicode/str functions
#: as this will include the bytestring indicator (b'')
#: on python 3.x.
#: https://github.com/... | [
"def",
"prepare_url",
"(",
"self",
",",
"url",
",",
"params",
")",
":",
"#: Accept objects that have string representations.",
"#: We're unable to blindly call unicode/str functions",
"#: as this will include the bytestring indicator (b'')",
"#: on python 3.x.",
"#: https://github.com/ps... | [
355,
4
] | [
439,
22
] | python | en | ['en', 'en', 'en'] | True |
PreparedRequest.prepare_headers | (self, headers) | Prepares the given HTTP headers. | Prepares the given HTTP headers. | def prepare_headers(self, headers):
"""Prepares the given HTTP headers."""
self.headers = CaseInsensitiveDict()
if headers:
for header in headers.items():
# Raise exception on invalid header value.
check_header_validity(header)
name, v... | [
"def",
"prepare_headers",
"(",
"self",
",",
"headers",
")",
":",
"self",
".",
"headers",
"=",
"CaseInsensitiveDict",
"(",
")",
"if",
"headers",
":",
"for",
"header",
"in",
"headers",
".",
"items",
"(",
")",
":",
"# Raise exception on invalid header value.",
"c... | [
441,
4
] | [
450,
60
] | python | en | ['en', 'en', 'en'] | True |
PreparedRequest.prepare_body | (self, data, files, json=None) | Prepares the given HTTP body data. | Prepares the given HTTP body data. | def prepare_body(self, data, files, json=None):
"""Prepares the given HTTP body data."""
# Check if file, fo, generator, iterator.
# If not, run through normal process.
# Nottin' on you.
body = None
content_type = None
if not data and json is not None:
... | [
"def",
"prepare_body",
"(",
"self",
",",
"data",
",",
"files",
",",
"json",
"=",
"None",
")",
":",
"# Check if file, fo, generator, iterator.",
"# If not, run through normal process.",
"# Nottin' on you.",
"body",
"=",
"None",
"content_type",
"=",
"None",
"if",
"not",... | [
452,
4
] | [
519,
24
] | python | en | ['en', 'en', 'en'] | True |
PreparedRequest.prepare_content_length | (self, body) | Prepare Content-Length header based on request method and body | Prepare Content-Length header based on request method and body | def prepare_content_length(self, body):
"""Prepare Content-Length header based on request method and body"""
if body is not None:
length = super_len(body)
if length:
# If length exists, set it. Otherwise, we fallback
# to Transfer-Encoding: chunked... | [
"def",
"prepare_content_length",
"(",
"self",
",",
"body",
")",
":",
"if",
"body",
"is",
"not",
"None",
":",
"length",
"=",
"super_len",
"(",
"body",
")",
"if",
"length",
":",
"# If length exists, set it. Otherwise, we fallback",
"# to Transfer-Encoding: chunked.",
... | [
521,
4
] | [
532,
48
] | python | en | ['en', 'en', 'en'] | True |
PreparedRequest.prepare_auth | (self, auth, url='') | Prepares the given HTTP auth data. | Prepares the given HTTP auth data. | def prepare_auth(self, auth, url=''):
"""Prepares the given HTTP auth data."""
# If no Auth is explicitly provided, extract it from the URL first.
if auth is None:
url_auth = get_auth_from_url(self.url)
auth = url_auth if any(url_auth) else None
if auth:
... | [
"def",
"prepare_auth",
"(",
"self",
",",
"auth",
",",
"url",
"=",
"''",
")",
":",
"# If no Auth is explicitly provided, extract it from the URL first.",
"if",
"auth",
"is",
"None",
":",
"url_auth",
"=",
"get_auth_from_url",
"(",
"self",
".",
"url",
")",
"auth",
... | [
534,
4
] | [
554,
50
] | python | en | ['en', 'en', 'en'] | True |
PreparedRequest.prepare_cookies | (self, cookies) | Prepares the given HTTP cookie data.
This function eventually generates a ``Cookie`` header from the
given cookies using cookielib. Due to cookielib's design, the header
will not be regenerated if it already exists, meaning this function
can only be called once for the life of the
... | Prepares the given HTTP cookie data. | def prepare_cookies(self, cookies):
"""Prepares the given HTTP cookie data.
This function eventually generates a ``Cookie`` header from the
given cookies using cookielib. Due to cookielib's design, the header
will not be regenerated if it already exists, meaning this function
ca... | [
"def",
"prepare_cookies",
"(",
"self",
",",
"cookies",
")",
":",
"if",
"isinstance",
"(",
"cookies",
",",
"cookielib",
".",
"CookieJar",
")",
":",
"self",
".",
"_cookies",
"=",
"cookies",
"else",
":",
"self",
".",
"_cookies",
"=",
"cookiejar_from_dict",
"(... | [
556,
4
] | [
574,
50
] | python | en | ['en', 'en', 'en'] | True |
PreparedRequest.prepare_hooks | (self, hooks) | Prepares the given hooks. | Prepares the given hooks. | def prepare_hooks(self, hooks):
"""Prepares the given hooks."""
# hooks can be passed as None to the prepare method and to this
# method. To prevent iterating over None, simply use an empty list
# if hooks is False-y
hooks = hooks or []
for event in hooks:
sel... | [
"def",
"prepare_hooks",
"(",
"self",
",",
"hooks",
")",
":",
"# hooks can be passed as None to the prepare method and to this",
"# method. To prevent iterating over None, simply use an empty list",
"# if hooks is False-y",
"hooks",
"=",
"hooks",
"or",
"[",
"]",
"for",
"event",
... | [
576,
4
] | [
583,
51
] | python | en | ['en', 'en', 'en'] | True |
Response.__bool__ | (self) | Returns True if :attr:`status_code` is less than 400.
This attribute checks if the status code of the response is between
400 and 600 to see if there was a client error or a server error. If
the status code, is between 200 and 400, this will return True. This
is **not** a check to see i... | Returns True if :attr:`status_code` is less than 400. | def __bool__(self):
"""Returns True if :attr:`status_code` is less than 400.
This attribute checks if the status code of the response is between
400 and 600 to see if there was a client error or a server error. If
the status code, is between 200 and 400, this will return True. This
... | [
"def",
"__bool__",
"(",
"self",
")",
":",
"return",
"self",
".",
"ok"
] | [
668,
4
] | [
676,
22
] | python | en | ['en', 'en', 'en'] | True |
Response.__nonzero__ | (self) | Returns True if :attr:`status_code` is less than 400.
This attribute checks if the status code of the response is between
400 and 600 to see if there was a client error or a server error. If
the status code, is between 200 and 400, this will return True. This
is **not** a check to see i... | Returns True if :attr:`status_code` is less than 400. | def __nonzero__(self):
"""Returns True if :attr:`status_code` is less than 400.
This attribute checks if the status code of the response is between
400 and 600 to see if there was a client error or a server error. If
the status code, is between 200 and 400, this will return True. This
... | [
"def",
"__nonzero__",
"(",
"self",
")",
":",
"return",
"self",
".",
"ok"
] | [
678,
4
] | [
686,
22
] | python | en | ['en', 'en', 'en'] | True |
Response.__iter__ | (self) | Allows you to use a response as an iterator. | Allows you to use a response as an iterator. | def __iter__(self):
"""Allows you to use a response as an iterator."""
return self.iter_content(128) | [
"def",
"__iter__",
"(",
"self",
")",
":",
"return",
"self",
".",
"iter_content",
"(",
"128",
")"
] | [
688,
4
] | [
690,
37
] | python | en | ['en', 'en', 'en'] | True |
Response.ok | (self) | Returns True if :attr:`status_code` is less than 400, False if not.
This attribute checks if the status code of the response is between
400 and 600 to see if there was a client error or a server error. If
the status code is between 200 and 400, this will return True. This
is **not** a c... | Returns True if :attr:`status_code` is less than 400, False if not. | def ok(self):
"""Returns True if :attr:`status_code` is less than 400, False if not.
This attribute checks if the status code of the response is between
400 and 600 to see if there was a client error or a server error. If
the status code is between 200 and 400, this will return True. Th... | [
"def",
"ok",
"(",
"self",
")",
":",
"try",
":",
"self",
".",
"raise_for_status",
"(",
")",
"except",
"HTTPError",
":",
"return",
"False",
"return",
"True"
] | [
693,
4
] | [
705,
19
] | python | en | ['en', 'en', 'en'] | True |
Response.is_redirect | (self) | True if this Response is a well-formed HTTP redirect that could have
been processed automatically (by :meth:`Session.resolve_redirects`).
| True if this Response is a well-formed HTTP redirect that could have
been processed automatically (by :meth:`Session.resolve_redirects`).
| def is_redirect(self):
"""True if this Response is a well-formed HTTP redirect that could have
been processed automatically (by :meth:`Session.resolve_redirects`).
"""
return ('location' in self.headers and self.status_code in REDIRECT_STATI) | [
"def",
"is_redirect",
"(",
"self",
")",
":",
"return",
"(",
"'location'",
"in",
"self",
".",
"headers",
"and",
"self",
".",
"status_code",
"in",
"REDIRECT_STATI",
")"
] | [
708,
4
] | [
712,
82
] | python | en | ['en', 'en', 'en'] | True |
Response.is_permanent_redirect | (self) | True if this Response one of the permanent versions of redirect. | True if this Response one of the permanent versions of redirect. | def is_permanent_redirect(self):
"""True if this Response one of the permanent versions of redirect."""
return ('location' in self.headers and self.status_code in (codes.moved_permanently, codes.permanent_redirect)) | [
"def",
"is_permanent_redirect",
"(",
"self",
")",
":",
"return",
"(",
"'location'",
"in",
"self",
".",
"headers",
"and",
"self",
".",
"status_code",
"in",
"(",
"codes",
".",
"moved_permanently",
",",
"codes",
".",
"permanent_redirect",
")",
")"
] | [
715,
4
] | [
717,
119
] | python | en | ['en', 'en', 'en'] | True |
Response.next | (self) | Returns a PreparedRequest for the next request in a redirect chain, if there is one. | Returns a PreparedRequest for the next request in a redirect chain, if there is one. | def next(self):
"""Returns a PreparedRequest for the next request in a redirect chain, if there is one."""
return self._next | [
"def",
"next",
"(",
"self",
")",
":",
"return",
"self",
".",
"_next"
] | [
720,
4
] | [
722,
25
] | python | en | ['en', 'en', 'en'] | True |
Response.apparent_encoding | (self) | The apparent encoding, provided by the chardet library. | The apparent encoding, provided by the chardet library. | def apparent_encoding(self):
"""The apparent encoding, provided by the chardet library."""
return chardet.detect(self.content)['encoding'] | [
"def",
"apparent_encoding",
"(",
"self",
")",
":",
"return",
"chardet",
".",
"detect",
"(",
"self",
".",
"content",
")",
"[",
"'encoding'",
"]"
] | [
725,
4
] | [
727,
55
] | python | en | ['en', 'en', 'en'] | True |
Response.iter_content | (self, chunk_size=1, decode_unicode=False) | Iterates over the response data. When stream=True is set on the
request, this avoids reading the content at once into memory for
large responses. The chunk size is the number of bytes it should
read into memory. This is not necessarily the length of each item
returned as decoding can ... | Iterates over the response data. When stream=True is set on the
request, this avoids reading the content at once into memory for
large responses. The chunk size is the number of bytes it should
read into memory. This is not necessarily the length of each item
returned as decoding can ... | def iter_content(self, chunk_size=1, decode_unicode=False):
"""Iterates over the response data. When stream=True is set on the
request, this avoids reading the content at once into memory for
large responses. The chunk size is the number of bytes it should
read into memory. This is no... | [
"def",
"iter_content",
"(",
"self",
",",
"chunk_size",
"=",
"1",
",",
"decode_unicode",
"=",
"False",
")",
":",
"def",
"generate",
"(",
")",
":",
"# Special case for urllib3.",
"if",
"hasattr",
"(",
"self",
".",
"raw",
",",
"'stream'",
")",
":",
"try",
"... | [
729,
4
] | [
782,
21
] | python | en | ['en', 'en', 'en'] | True |
Response.iter_lines | (self, chunk_size=ITER_CHUNK_SIZE, decode_unicode=False, delimiter=None) | Iterates over the response data, one line at a time. When
stream=True is set on the request, this avoids reading the
content at once into memory for large responses.
.. note:: This method is not reentrant safe.
| Iterates over the response data, one line at a time. When
stream=True is set on the request, this avoids reading the
content at once into memory for large responses. | def iter_lines(self, chunk_size=ITER_CHUNK_SIZE, decode_unicode=False, delimiter=None):
"""Iterates over the response data, one line at a time. When
stream=True is set on the request, this avoids reading the
content at once into memory for large responses.
.. note:: This method is not ... | [
"def",
"iter_lines",
"(",
"self",
",",
"chunk_size",
"=",
"ITER_CHUNK_SIZE",
",",
"decode_unicode",
"=",
"False",
",",
"delimiter",
"=",
"None",
")",
":",
"pending",
"=",
"None",
"for",
"chunk",
"in",
"self",
".",
"iter_content",
"(",
"chunk_size",
"=",
"c... | [
784,
4
] | [
813,
25
] | python | en | ['en', 'en', 'en'] | True |
Response.content | (self) | Content of the response, in bytes. | Content of the response, in bytes. | def content(self):
"""Content of the response, in bytes."""
if self._content is False:
# Read the contents.
if self._content_consumed:
raise RuntimeError(
'The content for this response was already consumed')
if self.status_code =... | [
"def",
"content",
"(",
"self",
")",
":",
"if",
"self",
".",
"_content",
"is",
"False",
":",
"# Read the contents.",
"if",
"self",
".",
"_content_consumed",
":",
"raise",
"RuntimeError",
"(",
"'The content for this response was already consumed'",
")",
"if",
"self",
... | [
816,
4
] | [
833,
28
] | 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.