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
zzUrlconfSubstitutionTests.test_urlconf_was_reverted
(self)
URLconf is reverted to original value after modification in a TestCase This will not find a match as the default ROOT_URLCONF is empty.
URLconf is reverted to original value after modification in a TestCase
def test_urlconf_was_reverted(self): """URLconf is reverted to original value after modification in a TestCase This will not find a match as the default ROOT_URLCONF is empty. """ with self.assertRaises(NoReverseMatch): reverse('arg_view', args=['somename'])
[ "def", "test_urlconf_was_reverted", "(", "self", ")", ":", "with", "self", ".", "assertRaises", "(", "NoReverseMatch", ")", ":", "reverse", "(", "'arg_view'", ",", "args", "=", "[", "'somename'", "]", ")" ]
[ 939, 4 ]
[ 945, 50 ]
python
en
['en', 'en', 'en']
True
transform_hits
(hits)
The list from pypi is really a list of versions. We want a list of packages with the list of versions stored inline. This converts the list from pypi into one we can use.
The list from pypi is really a list of versions. We want a list of packages with the list of versions stored inline. This converts the list from pypi into one we can use.
def transform_hits(hits): """ The list from pypi is really a list of versions. We want a list of packages with the list of versions stored inline. This converts the list from pypi into one we can use. """ packages = OrderedDict() for hit in hits: name = hit['name'] summary = ...
[ "def", "transform_hits", "(", "hits", ")", ":", "packages", "=", "OrderedDict", "(", ")", "for", "hit", "in", "hits", ":", "name", "=", "hit", "[", "'name'", "]", "summary", "=", "hit", "[", "'summary'", "]", "version", "=", "hit", "[", "'version'", ...
[ 74, 0 ]
[ 99, 34 ]
python
en
['en', 'error', 'th']
False
_cf_data_from_bytes
(bytestring)
Given a bytestring, create a CFData object from it. This CFData object must be CFReleased by the caller.
Given a bytestring, create a CFData object from it. This CFData object must be CFReleased by the caller.
def _cf_data_from_bytes(bytestring): """ Given a bytestring, create a CFData object from it. This CFData object must be CFReleased by the caller. """ return CoreFoundation.CFDataCreate( CoreFoundation.kCFAllocatorDefault, bytestring, len(bytestring) )
[ "def", "_cf_data_from_bytes", "(", "bytestring", ")", ":", "return", "CoreFoundation", ".", "CFDataCreate", "(", "CoreFoundation", ".", "kCFAllocatorDefault", ",", "bytestring", ",", "len", "(", "bytestring", ")", ")" ]
[ 26, 0 ]
[ 33, 5 ]
python
en
['en', 'error', 'th']
False
_cf_dictionary_from_tuples
(tuples)
Given a list of Python tuples, create an associated CFDictionary.
Given a list of Python tuples, create an associated CFDictionary.
def _cf_dictionary_from_tuples(tuples): """ Given a list of Python tuples, create an associated CFDictionary. """ dictionary_size = len(tuples) # We need to get the dictionary keys and values out in the same order. keys = (t[0] for t in tuples) values = (t[1] for t in tuples) cf_keys = ...
[ "def", "_cf_dictionary_from_tuples", "(", "tuples", ")", ":", "dictionary_size", "=", "len", "(", "tuples", ")", "# We need to get the dictionary keys and values out in the same order.", "keys", "=", "(", "t", "[", "0", "]", "for", "t", "in", "tuples", ")", "values"...
[ 36, 0 ]
[ 55, 5 ]
python
en
['en', 'error', 'th']
False
_cf_string_to_unicode
(value)
Creates a Unicode string from a CFString object. Used entirely for error reporting. Yes, it annoys me quite a lot that this function is this complex.
Creates a Unicode string from a CFString object. Used entirely for error reporting.
def _cf_string_to_unicode(value): """ Creates a Unicode string from a CFString object. Used entirely for error reporting. Yes, it annoys me quite a lot that this function is this complex. """ value_as_void_p = ctypes.cast(value, ctypes.POINTER(ctypes.c_void_p)) string = CoreFoundation.CFSt...
[ "def", "_cf_string_to_unicode", "(", "value", ")", ":", "value_as_void_p", "=", "ctypes", ".", "cast", "(", "value", ",", "ctypes", ".", "POINTER", "(", "ctypes", ".", "c_void_p", ")", ")", "string", "=", "CoreFoundation", ".", "CFStringGetCStringPtr", "(", ...
[ 58, 0 ]
[ 80, 17 ]
python
en
['en', 'error', 'th']
False
_assert_no_error
(error, exception_class=None)
Checks the return code and throws an exception if there is an error to report
Checks the return code and throws an exception if there is an error to report
def _assert_no_error(error, exception_class=None): """ Checks the return code and throws an exception if there is an error to report """ if error == 0: return cf_error_string = Security.SecCopyErrorMessageString(error, None) output = _cf_string_to_unicode(cf_error_string) CoreFo...
[ "def", "_assert_no_error", "(", "error", ",", "exception_class", "=", "None", ")", ":", "if", "error", "==", "0", ":", "return", "cf_error_string", "=", "Security", ".", "SecCopyErrorMessageString", "(", "error", ",", "None", ")", "output", "=", "_cf_string_to...
[ 83, 0 ]
[ 101, 33 ]
python
en
['en', 'error', 'th']
False
_cert_array_from_pem
(pem_bundle)
Given a bundle of certs in PEM format, turns them into a CFArray of certs that can be used to validate a cert chain.
Given a bundle of certs in PEM format, turns them into a CFArray of certs that can be used to validate a cert chain.
def _cert_array_from_pem(pem_bundle): """ Given a bundle of certs in PEM format, turns them into a CFArray of certs that can be used to validate a cert chain. """ # Normalize the PEM bundle's line endings. pem_bundle = pem_bundle.replace(b"\r\n", b"\n") der_certs = [ base64.b64decod...
[ "def", "_cert_array_from_pem", "(", "pem_bundle", ")", ":", "# Normalize the PEM bundle's line endings.", "pem_bundle", "=", "pem_bundle", ".", "replace", "(", "b\"\\r\\n\"", ",", "b\"\\n\"", ")", "der_certs", "=", "[", "base64", ".", "b64decode", "(", "match", ".",...
[ 104, 0 ]
[ 146, 21 ]
python
en
['en', 'error', 'th']
False
_is_cert
(item)
Returns True if a given CFTypeRef is a certificate.
Returns True if a given CFTypeRef is a certificate.
def _is_cert(item): """ Returns True if a given CFTypeRef is a certificate. """ expected = Security.SecCertificateGetTypeID() return CoreFoundation.CFGetTypeID(item) == expected
[ "def", "_is_cert", "(", "item", ")", ":", "expected", "=", "Security", ".", "SecCertificateGetTypeID", "(", ")", "return", "CoreFoundation", ".", "CFGetTypeID", "(", "item", ")", "==", "expected" ]
[ 149, 0 ]
[ 154, 55 ]
python
en
['en', 'error', 'th']
False
_is_identity
(item)
Returns True if a given CFTypeRef is an identity.
Returns True if a given CFTypeRef is an identity.
def _is_identity(item): """ Returns True if a given CFTypeRef is an identity. """ expected = Security.SecIdentityGetTypeID() return CoreFoundation.CFGetTypeID(item) == expected
[ "def", "_is_identity", "(", "item", ")", ":", "expected", "=", "Security", ".", "SecIdentityGetTypeID", "(", ")", "return", "CoreFoundation", ".", "CFGetTypeID", "(", "item", ")", "==", "expected" ]
[ 157, 0 ]
[ 162, 55 ]
python
en
['en', 'error', 'th']
False
_temporary_keychain
()
This function creates a temporary Mac keychain that we can use to work with credentials. This keychain uses a one-time password and a temporary file to store the data. We expect to have one keychain per socket. The returned SecKeychainRef must be freed by the caller, including calling SecKeychainDe...
This function creates a temporary Mac keychain that we can use to work with credentials. This keychain uses a one-time password and a temporary file to store the data. We expect to have one keychain per socket. The returned SecKeychainRef must be freed by the caller, including calling SecKeychainDe...
def _temporary_keychain(): """ This function creates a temporary Mac keychain that we can use to work with credentials. This keychain uses a one-time password and a temporary file to store the data. We expect to have one keychain per socket. The returned SecKeychainRef must be freed by the caller, i...
[ "def", "_temporary_keychain", "(", ")", ":", "# Unfortunately, SecKeychainCreate requires a path to a keychain. This", "# means we cannot use mkstemp to use a generic temporary file. Instead,", "# we're going to create a temporary directory and a filename to use there.", "# This filename will be 8 r...
[ 165, 0 ]
[ 197, 34 ]
python
en
['en', 'error', 'th']
False
_load_items_from_file
(keychain, path)
Given a single file, loads all the trust objects from it into arrays and the keychain. Returns a tuple of lists: the first list is a list of identities, the second a list of certs.
Given a single file, loads all the trust objects from it into arrays and the keychain. Returns a tuple of lists: the first list is a list of identities, the second a list of certs.
def _load_items_from_file(keychain, path): """ Given a single file, loads all the trust objects from it into arrays and the keychain. Returns a tuple of lists: the first list is a list of identities, the second a list of certs. """ certificates = [] identities = [] result_array = Non...
[ "def", "_load_items_from_file", "(", "keychain", ",", "path", ")", ":", "certificates", "=", "[", "]", "identities", "=", "[", "]", "result_array", "=", "None", "with", "open", "(", "path", ",", "\"rb\"", ")", "as", "f", ":", "raw_filedata", "=", "f", ...
[ 200, 0 ]
[ 252, 37 ]
python
en
['en', 'error', 'th']
False
_load_client_cert_chain
(keychain, *paths)
Load certificates and maybe keys from a number of files. Has the end goal of returning a CFArray containing one SecIdentityRef, and then zero or more SecCertificateRef objects, suitable for use as a client certificate trust chain.
Load certificates and maybe keys from a number of files. Has the end goal of returning a CFArray containing one SecIdentityRef, and then zero or more SecCertificateRef objects, suitable for use as a client certificate trust chain.
def _load_client_cert_chain(keychain, *paths): """ Load certificates and maybe keys from a number of files. Has the end goal of returning a CFArray containing one SecIdentityRef, and then zero or more SecCertificateRef objects, suitable for use as a client certificate trust chain. """ # Ok, ...
[ "def", "_load_client_cert_chain", "(", "keychain", ",", "*", "paths", ")", ":", "# Ok, the strategy.", "#", "# This relies on knowing that macOS will not give you a SecIdentityRef", "# unless you have imported a key into a keychain. This is a somewhat", "# artificial limitation of macOS (f...
[ 255, 0 ]
[ 327, 41 ]
python
en
['en', 'error', 'th']
False
EmailLogBackEnd.log_email
(email: EmailMultiAlternatives)
Used in development to record sent emails in a nice HTML log
Used in development to record sent emails in a nice HTML log
def log_email(email: EmailMultiAlternatives) -> None: """Used in development to record sent emails in a nice HTML log""" html_message = "Missing HTML message" if len(email.alternatives) > 0: html_message = email.alternatives[0][0] context = { "subject": email.sub...
[ "def", "log_email", "(", "email", ":", "EmailMultiAlternatives", ")", "->", "None", ":", "html_message", "=", "\"Missing HTML message\"", "if", "len", "(", "email", ".", "alternatives", ")", ">", "0", ":", "html_message", "=", "email", ".", "alternatives", "["...
[ 33, 4 ]
[ 60, 48 ]
python
en
['en', 'en', 'en']
True
pack
(structure, data)
Pack data into hex string with little endian format.
Pack data into hex string with little endian format.
def pack(structure, data): """ Pack data into hex string with little endian format. """ return struct.pack('<' + structure, *data)
[ "def", "pack", "(", "structure", ",", "data", ")", ":", "return", "struct", ".", "pack", "(", "'<'", "+", "structure", ",", "*", "data", ")" ]
[ 10, 0 ]
[ 14, 46 ]
python
en
['en', 'error', 'th']
False
unpack
(structure, data)
Unpack little endian hexlified binary string into a list.
Unpack little endian hexlified binary string into a list.
def unpack(structure, data): """ Unpack little endian hexlified binary string into a list. """ return struct.unpack('<' + structure, bytes.fromhex(data))
[ "def", "unpack", "(", "structure", ",", "data", ")", ":", "return", "struct", ".", "unpack", "(", "'<'", "+", "structure", ",", "bytes", ".", "fromhex", "(", "data", ")", ")" ]
[ 17, 0 ]
[ 21, 62 ]
python
en
['en', 'error', 'th']
False
chunk
(data, index)
Split a string into two parts at the input index.
Split a string into two parts at the input index.
def chunk(data, index): """ Split a string into two parts at the input index. """ return data[:index], data[index:]
[ "def", "chunk", "(", "data", ",", "index", ")", ":", "return", "data", "[", ":", "index", "]", ",", "data", "[", "index", ":", "]" ]
[ 24, 0 ]
[ 28, 37 ]
python
en
['en', 'error', 'th']
False
from_pgraster
(data)
Convert a PostGIS HEX String into a dictionary.
Convert a PostGIS HEX String into a dictionary.
def from_pgraster(data): """ Convert a PostGIS HEX String into a dictionary. """ if data is None: return # Split raster header from data header, data = chunk(data, 122) header = unpack(POSTGIS_HEADER_STRUCTURE, header) # Parse band data bands = [] pixeltypes = [] wh...
[ "def", "from_pgraster", "(", "data", ")", ":", "if", "data", "is", "None", ":", "return", "# Split raster header from data", "header", ",", "data", "=", "chunk", "(", "data", ",", "122", ")", "header", "=", "unpack", "(", "POSTGIS_HEADER_STRUCTURE", ",", "he...
[ 31, 0 ]
[ 94, 5 ]
python
en
['en', 'error', 'th']
False
to_pgraster
(rast)
Convert a GDALRaster into PostGIS Raster format.
Convert a GDALRaster into PostGIS Raster format.
def to_pgraster(rast): """ Convert a GDALRaster into PostGIS Raster format. """ # Prepare the raster header data as a tuple. The first two numbers are # the endianness and the PostGIS Raster Version, both are fixed by # PostGIS at the moment. rasterheader = ( 1, 0, len(rast.bands), r...
[ "def", "to_pgraster", "(", "rast", ")", ":", "# Prepare the raster header data as a tuple. The first two numbers are", "# the endianness and the PostGIS Raster Version, both are fixed by", "# PostGIS at the moment.", "rasterheader", "=", "(", "1", ",", "0", ",", "len", "(", "rast...
[ 97, 0 ]
[ 140, 23 ]
python
en
['en', 'error', 'th']
False
do_block
(parser, token)
Define a block that can be overridden by child templates.
Define a block that can be overridden by child templates.
def do_block(parser, token): """ Define a block that can be overridden by child templates. """ # token.split_contents() isn't useful here because this tag doesn't accept variable as arguments bits = token.contents.split() if len(bits) != 2: raise TemplateSyntaxError("'%s' tag takes only ...
[ "def", "do_block", "(", "parser", ",", "token", ")", ":", "# token.split_contents() isn't useful here because this tag doesn't accept variable as arguments", "bits", "=", "token", ".", "contents", ".", "split", "(", ")", "if", "len", "(", "bits", ")", "!=", "2", ":"...
[ 162, 0 ]
[ 187, 42 ]
python
en
['en', 'error', 'th']
False
do_extends
(parser, token)
Signal that this template extends a parent template. This tag may be used in two ways: ``{% extends "base" %}`` (with quotes) uses the literal value "base" as the name of the parent template to extend, or ``{% extends variable %}`` uses the value of ``variable`` as either the name of the parent te...
Signal that this template extends a parent template.
def do_extends(parser, token): """ Signal that this template extends a parent template. This tag may be used in two ways: ``{% extends "base" %}`` (with quotes) uses the literal value "base" as the name of the parent template to extend, or ``{% extends variable %}`` uses the value of ``variable`` a...
[ "def", "do_extends", "(", "parser", ",", "token", ")", ":", "bits", "=", "token", ".", "split_contents", "(", ")", "if", "len", "(", "bits", ")", "!=", "2", ":", "raise", "TemplateSyntaxError", "(", "\"'%s' takes one argument\"", "%", "bits", "[", "0", "...
[ 191, 0 ]
[ 208, 45 ]
python
en
['en', 'error', 'th']
False
do_include
(parser, token)
Loads a template and renders it with the current context. You can pass additional context using keyword arguments. Example:: {% include "foo/some_include" %} {% include "foo/some_include" with bar="BAZZ!" baz="BING!" %} Use the ``only`` argument to exclude the current context when re...
Loads a template and renders it with the current context. You can pass additional context using keyword arguments.
def do_include(parser, token): """ Loads a template and renders it with the current context. You can pass additional context using keyword arguments. Example:: {% include "foo/some_include" %} {% include "foo/some_include" with bar="BAZZ!" baz="BING!" %} Use the ``only`` argument ...
[ "def", "do_include", "(", "parser", ",", "token", ")", ":", "bits", "=", "token", ".", "split_contents", "(", ")", "if", "len", "(", "bits", ")", "<", "2", ":", "raise", "TemplateSyntaxError", "(", "\"%r tag takes at least one argument: the name of the template to...
[ 212, 0 ]
[ 255, 57 ]
python
en
['en', 'error', 'th']
False
ModelFormBaseTest.test_empty_fields_to_fields_for_model
(self)
An argument of fields=() to fields_for_model should return an empty dictionary
An argument of fields=() to fields_for_model should return an empty dictionary
def test_empty_fields_to_fields_for_model(self): """ An argument of fields=() to fields_for_model should return an empty dictionary """ field_dict = fields_for_model(Person, fields=()) self.assertEqual(len(field_dict), 0)
[ "def", "test_empty_fields_to_fields_for_model", "(", "self", ")", ":", "field_dict", "=", "fields_for_model", "(", "Person", ",", "fields", "=", "(", ")", ")", "self", ".", "assertEqual", "(", "len", "(", "field_dict", ")", ",", "0", ")" ]
[ 174, 4 ]
[ 179, 44 ]
python
en
['en', 'error', 'th']
False
ModelFormBaseTest.test_empty_fields_on_modelform
(self)
No fields on a ModelForm should actually result in no fields.
No fields on a ModelForm should actually result in no fields.
def test_empty_fields_on_modelform(self): """ No fields on a ModelForm should actually result in no fields. """ class EmptyPersonForm(forms.ModelForm): class Meta: model = Person fields = () form = EmptyPersonForm() self.assert...
[ "def", "test_empty_fields_on_modelform", "(", "self", ")", ":", "class", "EmptyPersonForm", "(", "forms", ".", "ModelForm", ")", ":", "class", "Meta", ":", "model", "=", "Person", "fields", "=", "(", ")", "form", "=", "EmptyPersonForm", "(", ")", "self", "...
[ 181, 4 ]
[ 191, 45 ]
python
en
['en', 'error', 'th']
False
ModelFormBaseTest.test_empty_fields_to_construct_instance
(self)
No fields should be set on a model instance if construct_instance receives fields=().
No fields should be set on a model instance if construct_instance receives fields=().
def test_empty_fields_to_construct_instance(self): """ No fields should be set on a model instance if construct_instance receives fields=(). """ form = modelform_factory(Person, fields="__all__")({'name': 'John Doe'}) self.assertTrue(form.is_valid()) instance = construct_...
[ "def", "test_empty_fields_to_construct_instance", "(", "self", ")", ":", "form", "=", "modelform_factory", "(", "Person", ",", "fields", "=", "\"__all__\"", ")", "(", "{", "'name'", ":", "'John Doe'", "}", ")", "self", ".", "assertTrue", "(", "form", ".", "i...
[ 193, 4 ]
[ 200, 43 ]
python
en
['en', 'error', 'th']
False
ModelFormBaseTest.test_blank_with_null_foreign_key_field
(self)
#13776 -- ModelForm's with models having a FK set to null=False and required=False should be valid.
#13776 -- ModelForm's with models having a FK set to null=False and required=False should be valid.
def test_blank_with_null_foreign_key_field(self): """ #13776 -- ModelForm's with models having a FK set to null=False and required=False should be valid. """ class FormForTestingIsValid(forms.ModelForm): class Meta: model = Student fiel...
[ "def", "test_blank_with_null_foreign_key_field", "(", "self", ")", ":", "class", "FormForTestingIsValid", "(", "forms", ".", "ModelForm", ")", ":", "class", "Meta", ":", "model", "=", "Student", "fields", "=", "'__all__'", "def", "__init__", "(", "self", ",", ...
[ 202, 4 ]
[ 228, 45 ]
python
en
['en', 'error', 'th']
False
UniqueTest.test_unique_together
(self)
ModelForm test of unique_together constraint
ModelForm test of unique_together constraint
def test_unique_together(self): """ModelForm test of unique_together constraint""" form = PriceForm({'price': '6.00', 'quantity': '1'}) self.assertTrue(form.is_valid()) form.save() form = PriceForm({'price': '6.00', 'quantity': '1'}) self.assertFalse(form.is_valid()) ...
[ "def", "test_unique_together", "(", "self", ")", ":", "form", "=", "PriceForm", "(", "{", "'price'", ":", "'6.00'", ",", "'quantity'", ":", "'1'", "}", ")", "self", ".", "assertTrue", "(", "form", ".", "is_valid", "(", ")", ")", "form", ".", "save", ...
[ 651, 4 ]
[ 659, 104 ]
python
en
['en', 'en', 'en']
True
UniqueTest.test_multiple_field_unique_together
(self)
When the same field is involved in multiple unique_together constraints, we need to make sure we don't remove the data for it before doing all the validation checking (not just failing after the first one).
When the same field is involved in multiple unique_together constraints, we need to make sure we don't remove the data for it before doing all the validation checking (not just failing after the first one).
def test_multiple_field_unique_together(self): """ When the same field is involved in multiple unique_together constraints, we need to make sure we don't remove the data for it before doing all the validation checking (not just failing after the first one). """ cl...
[ "def", "test_multiple_field_unique_together", "(", "self", ")", ":", "class", "TripleForm", "(", "forms", ".", "ModelForm", ")", ":", "class", "Meta", ":", "model", "=", "Triple", "fields", "=", "'__all__'", "Triple", ".", "objects", ".", "create", "(", "lef...
[ 661, 4 ]
[ 679, 40 ]
python
en
['en', 'error', 'th']
False
UniqueTest.test_explicitpk_unspecified
(self)
Test for primary_key being in the form and failing validation.
Test for primary_key being in the form and failing validation.
def test_explicitpk_unspecified(self): """Test for primary_key being in the form and failing validation.""" form = ExplicitPKForm({'key': '', 'desc': ''}) self.assertFalse(form.is_valid())
[ "def", "test_explicitpk_unspecified", "(", "self", ")", ":", "form", "=", "ExplicitPKForm", "(", "{", "'key'", ":", "''", ",", "'desc'", ":", "''", "}", ")", "self", ".", "assertFalse", "(", "form", ".", "is_valid", "(", ")", ")" ]
[ 740, 4 ]
[ 743, 41 ]
python
en
['en', 'en', 'en']
True
UniqueTest.test_explicitpk_unique
(self)
Ensure keys and blank character strings are tested for uniqueness.
Ensure keys and blank character strings are tested for uniqueness.
def test_explicitpk_unique(self): """Ensure keys and blank character strings are tested for uniqueness.""" form = ExplicitPKForm({'key': 'key1', 'desc': ''}) self.assertTrue(form.is_valid()) form.save() form = ExplicitPKForm({'key': 'key1', 'desc': ''}) self.assertFalse(f...
[ "def", "test_explicitpk_unique", "(", "self", ")", ":", "form", "=", "ExplicitPKForm", "(", "{", "'key'", ":", "'key1'", ",", "'desc'", ":", "''", "}", ")", "self", ".", "assertTrue", "(", "form", ".", "is_valid", "(", ")", ")", "form", ".", "save", ...
[ 745, 4 ]
[ 755, 91 ]
python
en
['en', 'en', 'en']
True
UniqueTest.test_unique_for_date_in_exclude
(self)
If the date for unique_for_* constraints is excluded from the ModelForm (in this case 'posted' has editable=False, then the constraint should be ignored.
If the date for unique_for_* constraints is excluded from the ModelForm (in this case 'posted' has editable=False, then the constraint should be ignored.
def test_unique_for_date_in_exclude(self): """ If the date for unique_for_* constraints is excluded from the ModelForm (in this case 'posted' has editable=False, then the constraint should be ignored. """ class DateTimePostForm(forms.ModelForm): class Meta: ...
[ "def", "test_unique_for_date_in_exclude", "(", "self", ")", ":", "class", "DateTimePostForm", "(", "forms", ".", "ModelForm", ")", ":", "class", "Meta", ":", "model", "=", "DateTimePost", "fields", "=", "'__all__'", "DateTimePost", ".", "objects", ".", "create",...
[ 783, 4 ]
[ 805, 40 ]
python
en
['en', 'error', 'th']
False
ModelFormBasicTests.test_m2m_initial_callable
(self)
Regression for #10349: A callable can be provided as the initial value for an m2m field
Regression for #10349: A callable can be provided as the initial value for an m2m field
def test_m2m_initial_callable(self): """ Regression for #10349: A callable can be provided as the initial value for an m2m field """ self.maxDiff = 1200 self.create_basic_data() # Set up a callable initial value def formfield_for_dbfield(db_field, **kwargs): ...
[ "def", "test_m2m_initial_callable", "(", "self", ")", ":", "self", ".", "maxDiff", "=", "1200", "self", ".", "create_basic_data", "(", ")", "# Set up a callable initial value", "def", "formfield_for_dbfield", "(", "db_field", ",", "*", "*", "kwargs", ")", ":", "...
[ 1083, 4 ]
[ 1106, 51 ]
python
en
['en', 'error', 'th']
False
ModelChoiceFieldTests.test_modelchoicefield_11183
(self)
Regression test for ticket #11183.
Regression test for ticket #11183.
def test_modelchoicefield_11183(self): """ Regression test for ticket #11183. """ class ModelChoiceForm(forms.Form): category = forms.ModelChoiceField(Category.objects.all()) form1 = ModelChoiceForm() field1 = form1.fields['category'] # To allow the w...
[ "def", "test_modelchoicefield_11183", "(", "self", ")", ":", "class", "ModelChoiceForm", "(", "forms", ".", "Form", ")", ":", "category", "=", "forms", ".", "ModelChoiceField", "(", "Category", ".", "objects", ".", "all", "(", ")", ")", "form1", "=", "Mode...
[ 1455, 4 ]
[ 1467, 62 ]
python
en
['en', 'error', 'th']
False
ModelChoiceFieldTests.test_modelchoicefield_22745
(self)
#22745 -- Make sure that ModelChoiceField with RadioSelect widget doesn't produce unnecessary db queries when accessing its BoundField's attrs.
#22745 -- Make sure that ModelChoiceField with RadioSelect widget doesn't produce unnecessary db queries when accessing its BoundField's attrs.
def test_modelchoicefield_22745(self): """ #22745 -- Make sure that ModelChoiceField with RadioSelect widget doesn't produce unnecessary db queries when accessing its BoundField's attrs. """ class ModelChoiceForm(forms.Form): category = forms.ModelChoiceField(...
[ "def", "test_modelchoicefield_22745", "(", "self", ")", ":", "class", "ModelChoiceForm", "(", "forms", ".", "Form", ")", ":", "category", "=", "forms", ".", "ModelChoiceField", "(", "Category", ".", "objects", ".", "all", "(", ")", ",", "widget", "=", "for...
[ 1469, 4 ]
[ 1482, 54 ]
python
en
['en', 'error', 'th']
False
ModelMultipleChoiceFieldTests.test_model_multiple_choice_number_of_queries
(self)
Test that ModelMultipleChoiceField does O(1) queries instead of O(n) (#10156).
Test that ModelMultipleChoiceField does O(1) queries instead of O(n) (#10156).
def test_model_multiple_choice_number_of_queries(self): """ Test that ModelMultipleChoiceField does O(1) queries instead of O(n) (#10156). """ persons = [Writer.objects.create(name="Person %s" % i) for i in range(30)] f = forms.ModelMultipleChoiceField(queryset=Writer.ob...
[ "def", "test_model_multiple_choice_number_of_queries", "(", "self", ")", ":", "persons", "=", "[", "Writer", ".", "objects", ".", "create", "(", "name", "=", "\"Person %s\"", "%", "i", ")", "for", "i", "in", "range", "(", "30", ")", "]", "f", "=", "forms...
[ 1571, 4 ]
[ 1579, 74 ]
python
en
['en', 'error', 'th']
False
ModelMultipleChoiceFieldTests.test_model_multiple_choice_run_validators
(self)
Test that ModelMultipleChoiceField run given validators (#14144).
Test that ModelMultipleChoiceField run given validators (#14144).
def test_model_multiple_choice_run_validators(self): """ Test that ModelMultipleChoiceField run given validators (#14144). """ for i in range(30): Writer.objects.create(name="Person %s" % i) self._validator_run = False def my_validator(value): se...
[ "def", "test_model_multiple_choice_run_validators", "(", "self", ")", ":", "for", "i", "in", "range", "(", "30", ")", ":", "Writer", ".", "objects", ".", "create", "(", "name", "=", "\"Person %s\"", "%", "i", ")", "self", ".", "_validator_run", "=", "False...
[ 1581, 4 ]
[ 1597, 44 ]
python
en
['en', 'error', 'th']
False
ModelMultipleChoiceFieldTests.test_model_multiple_choice_show_hidden_initial
(self)
Test support of show_hidden_initial by ModelMultipleChoiceField.
Test support of show_hidden_initial by ModelMultipleChoiceField.
def test_model_multiple_choice_show_hidden_initial(self): """ Test support of show_hidden_initial by ModelMultipleChoiceField. """ class WriterForm(forms.Form): persons = forms.ModelMultipleChoiceField(show_hidden_initial=True, ...
[ "def", "test_model_multiple_choice_show_hidden_initial", "(", "self", ")", ":", "class", "WriterForm", "(", "forms", ".", "Form", ")", ":", "persons", "=", "forms", ".", "ModelMultipleChoiceField", "(", "show_hidden_initial", "=", "True", ",", "queryset", "=", "Wr...
[ 1599, 4 ]
[ 1620, 43 ]
python
en
['en', 'error', 'th']
False
ModelMultipleChoiceFieldTests.test_model_multiple_choice_field_22745
(self)
#22745 -- Make sure that ModelMultipleChoiceField with CheckboxSelectMultiple widget doesn't produce unnecessary db queries when accessing its BoundField's attrs.
#22745 -- Make sure that ModelMultipleChoiceField with CheckboxSelectMultiple widget doesn't produce unnecessary db queries when accessing its BoundField's attrs.
def test_model_multiple_choice_field_22745(self): """ #22745 -- Make sure that ModelMultipleChoiceField with CheckboxSelectMultiple widget doesn't produce unnecessary db queries when accessing its BoundField's attrs. """ class ModelMultipleChoiceForm(forms.Form): ...
[ "def", "test_model_multiple_choice_field_22745", "(", "self", ")", ":", "class", "ModelMultipleChoiceForm", "(", "forms", ".", "Form", ")", ":", "categories", "=", "forms", ".", "ModelMultipleChoiceField", "(", "Category", ".", "objects", ".", "all", "(", ")", "...
[ 1622, 4 ]
[ 1635, 54 ]
python
en
['en', 'error', 'th']
False
FileAndImageFieldTests.test_clean_false
(self)
If the ``clean`` method on a non-required FileField receives False as the data (meaning clear the field value), it returns False, regardless of the value of ``initial``.
If the ``clean`` method on a non-required FileField receives False as the data (meaning clear the field value), it returns False, regardless of the value of ``initial``.
def test_clean_false(self): """ If the ``clean`` method on a non-required FileField receives False as the data (meaning clear the field value), it returns False, regardless of the value of ``initial``. """ f = forms.FileField(required=False) self.assertEqual(f.cle...
[ "def", "test_clean_false", "(", "self", ")", ":", "f", "=", "forms", ".", "FileField", "(", "required", "=", "False", ")", "self", ".", "assertEqual", "(", "f", ".", "clean", "(", "False", ")", ",", "False", ")", "self", ".", "assertEqual", "(", "f",...
[ 1735, 4 ]
[ 1743, 58 ]
python
en
['en', 'error', 'th']
False
FileAndImageFieldTests.test_clean_false_required
(self)
If the ``clean`` method on a required FileField receives False as the data, it has the same effect as None: initial is returned if non-empty, otherwise the validation catches the lack of a required value.
If the ``clean`` method on a required FileField receives False as the data, it has the same effect as None: initial is returned if non-empty, otherwise the validation catches the lack of a required value.
def test_clean_false_required(self): """ If the ``clean`` method on a required FileField receives False as the data, it has the same effect as None: initial is returned if non-empty, otherwise the validation catches the lack of a required value. """ f = forms.FileField(re...
[ "def", "test_clean_false_required", "(", "self", ")", ":", "f", "=", "forms", ".", "FileField", "(", "required", "=", "True", ")", "self", ".", "assertEqual", "(", "f", ".", "clean", "(", "False", ",", "'initial'", ")", ",", "'initial'", ")", "self", "...
[ 1745, 4 ]
[ 1753, 58 ]
python
en
['en', 'error', 'th']
False
FileAndImageFieldTests.test_full_clear
(self)
Integration happy-path test that a model FileField can actually be set and cleared via a ModelForm.
Integration happy-path test that a model FileField can actually be set and cleared via a ModelForm.
def test_full_clear(self): """ Integration happy-path test that a model FileField can actually be set and cleared via a ModelForm. """ class DocumentForm(forms.ModelForm): class Meta: model = Document fields = '__all__' form = ...
[ "def", "test_full_clear", "(", "self", ")", ":", "class", "DocumentForm", "(", "forms", ".", "ModelForm", ")", ":", "class", "Meta", ":", "model", "=", "Document", "fields", "=", "'__all__'", "form", "=", "DocumentForm", "(", ")", "self", ".", "assertTrue"...
[ 1755, 4 ]
[ 1776, 49 ]
python
en
['en', 'error', 'th']
False
FileAndImageFieldTests.test_clear_and_file_contradiction
(self)
If the user submits a new file upload AND checks the clear checkbox, they get a validation error, and the bound redisplay of the form still includes the current file and the clear checkbox.
If the user submits a new file upload AND checks the clear checkbox, they get a validation error, and the bound redisplay of the form still includes the current file and the clear checkbox.
def test_clear_and_file_contradiction(self): """ If the user submits a new file upload AND checks the clear checkbox, they get a validation error, and the bound redisplay of the form still includes the current file and the clear checkbox. """ class DocumentForm(forms.Mode...
[ "def", "test_clear_and_file_contradiction", "(", "self", ")", ":", "class", "DocumentForm", "(", "forms", ".", "ModelForm", ")", ":", "class", "Meta", ":", "model", "=", "Document", "fields", "=", "'__all__'", "form", "=", "DocumentForm", "(", "files", "=", ...
[ 1778, 4 ]
[ 1800, 51 ]
python
en
['en', 'error', 'th']
False
FileAndImageFieldTests.test_custom_file_field_save
(self)
Regression for #11149: save_form_data should be called only once
Regression for #11149: save_form_data should be called only once
def test_custom_file_field_save(self): """ Regression for #11149: save_form_data should be called only once """ class CFFForm(forms.ModelForm): class Meta: model = CustomFF fields = '__all__' # It's enough that the form saves without e...
[ "def", "test_custom_file_field_save", "(", "self", ")", ":", "class", "CFFForm", "(", "forms", ".", "ModelForm", ")", ":", "class", "Meta", ":", "model", "=", "CustomFF", "fields", "=", "'__all__'", "# It's enough that the form saves without error -- the custom save rou...
[ 1888, 4 ]
[ 1900, 19 ]
python
en
['en', 'error', 'th']
False
FileAndImageFieldTests.test_file_field_multiple_save
(self)
Simulate a file upload and check how many times Model.save() gets called. Test for bug #639.
Simulate a file upload and check how many times Model.save() gets called. Test for bug #639.
def test_file_field_multiple_save(self): """ Simulate a file upload and check how many times Model.save() gets called. Test for bug #639. """ class PhotoForm(forms.ModelForm): class Meta: model = Photo fields = '__all__' # Grab...
[ "def", "test_file_field_multiple_save", "(", "self", ")", ":", "class", "PhotoForm", "(", "forms", ".", "ModelForm", ")", ":", "class", "Meta", ":", "model", "=", "Photo", "fields", "=", "'__all__'", "# Grab an image for testing.", "filename", "=", "os", ".", ...
[ 1902, 4 ]
[ 1930, 38 ]
python
en
['en', 'error', 'th']
False
FileAndImageFieldTests.test_file_path_field_blank
(self)
Regression test for #8842: FilePathField(blank=True)
Regression test for #8842: FilePathField(blank=True)
def test_file_path_field_blank(self): """ Regression test for #8842: FilePathField(blank=True) """ class FPForm(forms.ModelForm): class Meta: model = FilePathModel fields = '__all__' form = FPForm() names = [p[1] for p in form[...
[ "def", "test_file_path_field_blank", "(", "self", ")", ":", "class", "FPForm", "(", "forms", ".", "ModelForm", ")", ":", "class", "Meta", ":", "model", "=", "FilePathModel", "fields", "=", "'__all__'", "form", "=", "FPForm", "(", ")", "names", "=", "[", ...
[ 1932, 4 ]
[ 1944, 86 ]
python
en
['en', 'error', 'th']
False
ModelOtherFieldTests.test_url_on_modelform
(self)
Check basic URL field validation on model forms
Check basic URL field validation on model forms
def test_url_on_modelform(self): "Check basic URL field validation on model forms" class HomepageForm(forms.ModelForm): class Meta: model = Homepage fields = '__all__' self.assertFalse(HomepageForm({'url': 'foo'}).is_valid()) self.assertFalse(...
[ "def", "test_url_on_modelform", "(", "self", ")", ":", "class", "HomepageForm", "(", "forms", ".", "ModelForm", ")", ":", "class", "Meta", ":", "model", "=", "Homepage", "fields", "=", "'__all__'", "self", ".", "assertFalse", "(", "HomepageForm", "(", "{", ...
[ 2121, 4 ]
[ 2140, 87 ]
python
en
['en', 'en', 'en']
True
ModelOtherFieldTests.test_http_prefixing
(self)
If the http:// prefix is omitted on form input, the field adds it again. (Refs #13613)
If the http:// prefix is omitted on form input, the field adds it again. (Refs #13613)
def test_http_prefixing(self): """ If the http:// prefix is omitted on form input, the field adds it again. (Refs #13613) """ class HomepageForm(forms.ModelForm): class Meta: model = Homepage fields = '__all__' form = HomepageForm({'ur...
[ "def", "test_http_prefixing", "(", "self", ")", ":", "class", "HomepageForm", "(", "forms", ".", "ModelForm", ")", ":", "class", "Meta", ":", "model", "=", "Homepage", "fields", "=", "'__all__'", "form", "=", "HomepageForm", "(", "{", "'url'", ":", "'examp...
[ 2142, 4 ]
[ 2157, 77 ]
python
en
['en', 'error', 'th']
False
CustomCleanTests.test_override_clean
(self)
Regression for #12596: Calling super from ModelForm.clean() should be optional.
Regression for #12596: Calling super from ModelForm.clean() should be optional.
def test_override_clean(self): """ Regression for #12596: Calling super from ModelForm.clean() should be optional. """ class TripleFormWithCleanOverride(forms.ModelForm): class Meta: model = Triple fields = '__all__' def cl...
[ "def", "test_override_clean", "(", "self", ")", ":", "class", "TripleFormWithCleanOverride", "(", "forms", ".", "ModelForm", ")", ":", "class", "Meta", ":", "model", "=", "Triple", "fields", "=", "'__all__'", "def", "clean", "(", "self", ")", ":", "if", "n...
[ 2278, 4 ]
[ 2297, 47 ]
python
en
['en', 'error', 'th']
False
CustomCleanTests.test_model_form_clean_applies_to_model
(self)
Regression test for #12960. Make sure the cleaned_data returned from ModelForm.clean() is applied to the model instance.
Regression test for #12960. Make sure the cleaned_data returned from ModelForm.clean() is applied to the model instance.
def test_model_form_clean_applies_to_model(self): """ Regression test for #12960. Make sure the cleaned_data returned from ModelForm.clean() is applied to the model instance. """ class CategoryForm(forms.ModelForm): class Meta: model = Category ...
[ "def", "test_model_form_clean_applies_to_model", "(", "self", ")", ":", "class", "CategoryForm", "(", "forms", ".", "ModelForm", ")", ":", "class", "Meta", ":", "model", "=", "Category", "fields", "=", "'__all__'", "def", "clean", "(", "self", ")", ":", "sel...
[ 2299, 4 ]
[ 2316, 47 ]
python
en
['en', 'error', 'th']
False
ModelFormInheritanceTests.test_field_removal_name_clashes
(self)
Regression test for https://code.djangoproject.com/ticket/22510.
Regression test for https://code.djangoproject.com/ticket/22510.
def test_field_removal_name_clashes(self): """Regression test for https://code.djangoproject.com/ticket/22510.""" class MyForm(forms.ModelForm): media = forms.CharField() class Meta: model = Writer fields = '__all__' class SubForm(MyForm...
[ "def", "test_field_removal_name_clashes", "(", "self", ")", ":", "class", "MyForm", "(", "forms", ".", "ModelForm", ")", ":", "media", "=", "forms", ".", "CharField", "(", ")", "class", "Meta", ":", "model", "=", "Writer", "fields", "=", "'__all__'", "clas...
[ 2354, 4 ]
[ 2370, 50 ]
python
en
['en', 'da', 'en']
True
LimitChoicesToTest.test_limit_choices_to_callable_for_fk_rel
(self)
A ForeignKey relation can use ``limit_choices_to`` as a callable, re #2554.
A ForeignKey relation can use ``limit_choices_to`` as a callable, re #2554.
def test_limit_choices_to_callable_for_fk_rel(self): """ A ForeignKey relation can use ``limit_choices_to`` as a callable, re #2554. """ stumpjokeform = StumpJokeForm() self.assertIn(self.threepwood, stumpjokeform.fields['most_recently_fooled'].queryset) self.assertNotIn(...
[ "def", "test_limit_choices_to_callable_for_fk_rel", "(", "self", ")", ":", "stumpjokeform", "=", "StumpJokeForm", "(", ")", "self", ".", "assertIn", "(", "self", ".", "threepwood", ",", "stumpjokeform", ".", "fields", "[", "'most_recently_fooled'", "]", ".", "quer...
[ 2393, 4 ]
[ 2399, 92 ]
python
en
['en', 'error', 'th']
False
LimitChoicesToTest.test_limit_choices_to_callable_for_m2m_rel
(self)
A ManyToMany relation can use ``limit_choices_to`` as a callable, re #2554.
A ManyToMany relation can use ``limit_choices_to`` as a callable, re #2554.
def test_limit_choices_to_callable_for_m2m_rel(self): """ A ManyToMany relation can use ``limit_choices_to`` as a callable, re #2554. """ stumpjokeform = StumpJokeForm()
[ "def", "test_limit_choices_to_callable_for_m2m_rel", "(", "self", ")", ":", "stumpjokeform", "=", "StumpJokeForm", "(", ")" ]
[ 2401, 4 ]
[ 2405, 39 ]
python
en
['en', 'error', 'th']
False
SiPassDriver._refresh_objects
(self, object_type)
Loads named objects from SiPass API and saves them in the database
Loads named objects from SiPass API and saves them in the database
def _refresh_objects(self, object_type): """Loads named objects from SiPass API and saves them in the database""" object_get_func = getattr(self, 'get_%s' % object_type) objs = {x['name']: x for x in object_get_func()} with self.system_lock() as system: driver_data = system....
[ "def", "_refresh_objects", "(", "self", ",", "object_type", ")", ":", "object_get_func", "=", "getattr", "(", "self", ",", "'get_%s'", "%", "object_type", ")", "objs", "=", "{", "x", "[", "'name'", "]", ":", "x", "for", "x", "in", "object_get_func", "(",...
[ 398, 4 ]
[ 409, 19 ]
python
en
['en', 'en', 'en']
True
SiPassDriver.get_object_by_id
(self, grant, object_type, setting_name)
Returns the API object corresponding to an object name The object name is taken from either the resource config, or if not found, the system-level config. If the object is not in the system-level object cache, the objects are refreshed from the API.
Returns the API object corresponding to an object name
def get_object_by_id(self, grant, object_type, setting_name): """Returns the API object corresponding to an object name The object name is taken from either the resource config, or if not found, the system-level config. If the object is not in the system-level object cache, the objects ...
[ "def", "get_object_by_id", "(", "self", ",", "grant", ",", "object_type", ",", "setting_name", ")", ":", "obj_name", "=", "grant", ".", "resource", ".", "driver_config", ".", "get", "(", "setting_name", ",", "None", ")", "if", "not", "obj_name", ":", "obj_...
[ 418, 4 ]
[ 435, 18 ]
python
en
['en', 'en', 'en']
True
StaticFilesHandler._should_handle
(self, path)
Checks if the path should be handled. Ignores the path if: * the host is provided as part of the base_url * the request's path isn't under the media path (or equal)
Checks if the path should be handled. Ignores the path if:
def _should_handle(self, path): """ Checks if the path should be handled. Ignores the path if: * the host is provided as part of the base_url * the request's path isn't under the media path (or equal) """ return path.startswith(self.base_url[2]) and not self.base_url[1]
[ "def", "_should_handle", "(", "self", ",", "path", ")", ":", "return", "path", ".", "startswith", "(", "self", ".", "base_url", "[", "2", "]", ")", "and", "not", "self", ".", "base_url", "[", "1", "]" ]
[ 27, 4 ]
[ 34, 73 ]
python
en
['en', 'error', 'th']
False
StaticFilesHandler.file_path
(self, url)
Returns the relative path to the media file on disk for the given URL.
Returns the relative path to the media file on disk for the given URL.
def file_path(self, url): """ Returns the relative path to the media file on disk for the given URL. """ relative_url = url[len(self.base_url[2]):] return url2pathname(relative_url)
[ "def", "file_path", "(", "self", ",", "url", ")", ":", "relative_url", "=", "url", "[", "len", "(", "self", ".", "base_url", "[", "2", "]", ")", ":", "]", "return", "url2pathname", "(", "relative_url", ")" ]
[ 36, 4 ]
[ 41, 41 ]
python
en
['en', 'error', 'th']
False
StaticFilesHandler.serve
(self, request)
Actually serves the request path.
Actually serves the request path.
def serve(self, request): """ Actually serves the request path. """ return serve(request, self.file_path(request.path), insecure=True)
[ "def", "serve", "(", "self", ",", "request", ")", ":", "return", "serve", "(", "request", ",", "self", ".", "file_path", "(", "request", ".", "path", ")", ",", "insecure", "=", "True", ")" ]
[ 43, 4 ]
[ 47, 74 ]
python
en
['en', 'error', 'th']
False
BaseManager.__str__
(self)
Return "app_label.model_label.manager_name".
Return "app_label.model_label.manager_name".
def __str__(self): """Return "app_label.model_label.manager_name".""" return '%s.%s' % (self.model._meta.label, self.name)
[ "def", "__str__", "(", "self", ")", ":", "return", "'%s.%s'", "%", "(", "self", ".", "model", ".", "_meta", ".", "label", ",", "self", ".", "name", ")" ]
[ 33, 4 ]
[ 35, 60 ]
python
en
['en', 'da', 'en']
False
BaseManager.deconstruct
(self)
Return a 5-tuple of the form (as_manager (True), manager_class, queryset_class, args, kwargs). Raise a ValueError if the manager is dynamically generated.
Return a 5-tuple of the form (as_manager (True), manager_class, queryset_class, args, kwargs).
def deconstruct(self): """ Return a 5-tuple of the form (as_manager (True), manager_class, queryset_class, args, kwargs). Raise a ValueError if the manager is dynamically generated. """ qs_class = self._queryset_class if getattr(self, '_built_with_as_manager', Fa...
[ "def", "deconstruct", "(", "self", ")", ":", "qs_class", "=", "self", ".", "_queryset_class", "if", "getattr", "(", "self", ",", "'_built_with_as_manager'", ",", "False", ")", ":", "# using MyQuerySet.as_manager()", "return", "(", "True", ",", "# as_manager", "N...
[ 37, 4 ]
[ 72, 13 ]
python
en
['en', 'error', 'th']
False
BaseManager._set_creation_counter
(self)
Set the creation counter value for this instance and increment the class-level copy.
Set the creation counter value for this instance and increment the class-level copy.
def _set_creation_counter(self): """ Set the creation counter value for this instance and increment the class-level copy. """ self.creation_counter = BaseManager.creation_counter BaseManager.creation_counter += 1
[ "def", "_set_creation_counter", "(", "self", ")", ":", "self", ".", "creation_counter", "=", "BaseManager", ".", "creation_counter", "BaseManager", ".", "creation_counter", "+=", "1" ]
[ 116, 4 ]
[ 122, 41 ]
python
en
['en', 'error', 'th']
False
BaseManager.get_queryset
(self)
Return a new QuerySet object. Subclasses can override this method to customize the behavior of the Manager.
Return a new QuerySet object. Subclasses can override this method to customize the behavior of the Manager.
def get_queryset(self): """ Return a new QuerySet object. Subclasses can override this method to customize the behavior of the Manager. """ return self._queryset_class(model=self.model, using=self._db, hints=self._hints)
[ "def", "get_queryset", "(", "self", ")", ":", "return", "self", ".", "_queryset_class", "(", "model", "=", "self", ".", "model", ",", "using", "=", "self", ".", "_db", ",", "hints", "=", "self", ".", "_hints", ")" ]
[ 138, 4 ]
[ 143, 88 ]
python
en
['en', 'error', 'th']
False
test_get_pretax_price_success
(product_1)
Test the price calculation logic is correct when retrieving product pretax price Includes tax and is rounded to two decimals
Test the price calculation logic is correct when retrieving product pretax price
def test_get_pretax_price_success(product_1): """Test the price calculation logic is correct when retrieving product pretax price Includes tax and is rounded to two decimals""" assert product_1.get_pretax_price() == Decimal('10.33')
[ "def", "test_get_pretax_price_success", "(", "product_1", ")", ":", "assert", "product_1", ".", "get_pretax_price", "(", ")", "==", "Decimal", "(", "'10.33'", ")" ]
[ 73, 0 ]
[ 77, 59 ]
python
en
['en', 'en', 'en']
True
test_get_price_for_time_range_success
(product_1)
Test the price calculation works correctly with timestamps
Test the price calculation works correctly with timestamps
def test_get_price_for_time_range_success(product_1): """Test the price calculation works correctly with timestamps""" start = datetime.datetime(2119, 5, 5, 10, 0, 0, tzinfo=UTC) end = datetime.datetime(2119, 5, 5, 11, 30, 0, tzinfo=UTC) rounded = product_1.get_price_for_time_range(start, end) not_r...
[ "def", "test_get_price_for_time_range_success", "(", "product_1", ")", ":", "start", "=", "datetime", ".", "datetime", "(", "2119", ",", "5", ",", "5", ",", "10", ",", "0", ",", "0", ",", "tzinfo", "=", "UTC", ")", "end", "=", "datetime", ".", "datetim...
[ 80, 0 ]
[ 87, 43 ]
python
en
['en', 'en', 'en']
True
test_get_pretax_price_for_time_range_success
(product_1)
Test the pretax price calculation works correctly with timestamps
Test the pretax price calculation works correctly with timestamps
def test_get_pretax_price_for_time_range_success(product_1): """Test the pretax price calculation works correctly with timestamps""" start = datetime.datetime(2119, 5, 5, 10, 0, 0, tzinfo=UTC) end = datetime.datetime(2119, 5, 5, 13, 0, 0, tzinfo=UTC) rounded = product_1.get_pretax_price_for_time_range(s...
[ "def", "test_get_pretax_price_for_time_range_success", "(", "product_1", ")", ":", "start", "=", "datetime", ".", "datetime", "(", "2119", ",", "5", ",", "5", ",", "10", ",", "0", ",", "0", ",", "tzinfo", "=", "UTC", ")", "end", "=", "datetime", ".", "...
[ 90, 0 ]
[ 97, 74 ]
python
en
['en', 'en', 'en']
True
test_get_price_for_reservation_success
(product_1, two_hour_reservation)
Test the time range is correctly extracted from reservation to use in price calculation with tax
Test the time range is correctly extracted from reservation to use in price calculation with tax
def test_get_price_for_reservation_success(product_1, two_hour_reservation): """Test the time range is correctly extracted from reservation to use in price calculation with tax""" rounded = product_1.get_price_for_reservation(two_hour_reservation) not_rounded = product_1.get_price_for_reservation(two_hour_r...
[ "def", "test_get_price_for_reservation_success", "(", "product_1", ",", "two_hour_reservation", ")", ":", "rounded", "=", "product_1", ".", "get_price_for_reservation", "(", "two_hour_reservation", ")", "not_rounded", "=", "product_1", ".", "get_price_for_reservation", "(",...
[ 100, 0 ]
[ 105, 42 ]
python
en
['en', 'en', 'en']
True
test_get_pretax_price_for_reservation_success
(product_1, two_hour_reservation)
Test the time range is correctly extracted from reservation to use in price calculation without tax
Test the time range is correctly extracted from reservation to use in price calculation without tax
def test_get_pretax_price_for_reservation_success(product_1, two_hour_reservation): """Test the time range is correctly extracted from reservation to use in price calculation without tax""" rounded = product_1.get_pretax_price_for_reservation(two_hour_reservation) not_rounded = product_1.get_pretax_price_fo...
[ "def", "test_get_pretax_price_for_reservation_success", "(", "product_1", ",", "two_hour_reservation", ")", ":", "rounded", "=", "product_1", ".", "get_pretax_price_for_reservation", "(", "two_hour_reservation", ")", "not_rounded", "=", "product_1", ".", "get_pretax_price_for...
[ 108, 0 ]
[ 113, 74 ]
python
en
['en', 'en', 'en']
True
test_get_custom_price_for_reservation_success
(product_1, two_hour_reservation)
Test that price of reservation is calculated right way if custom price for reservation is set
Test that price of reservation is calculated right way if custom price for reservation is set
def test_get_custom_price_for_reservation_success(product_1, two_hour_reservation): """Test that price of reservation is calculated right way if custom price for reservation is set""" ReservationCustomPrice.objects.create(reservation=two_hour_reservation, price=Decimal(1.00), ...
[ "def", "test_get_custom_price_for_reservation_success", "(", "product_1", ",", "two_hour_reservation", ")", ":", "ReservationCustomPrice", ".", "objects", ".", "create", "(", "reservation", "=", "two_hour_reservation", ",", "price", "=", "Decimal", "(", "1.00", ")", "...
[ 116, 0 ]
[ 123, 41 ]
python
en
['en', 'en', 'en']
True
test_get_custom_pretax_price_for_reservation_success
(product_1, two_hour_reservation)
Test that price of reservation is calculated right way if custom price for reservation is set
Test that price of reservation is calculated right way if custom price for reservation is set
def test_get_custom_pretax_price_for_reservation_success(product_1, two_hour_reservation): """Test that price of reservation is calculated right way if custom price for reservation is set""" ReservationCustomPrice.objects.create(reservation=two_hour_reservation, price=Decimal(25.62), ...
[ "def", "test_get_custom_pretax_price_for_reservation_success", "(", "product_1", ",", "two_hour_reservation", ")", ":", "ReservationCustomPrice", ".", "objects", ".", "create", "(", "reservation", "=", "two_hour_reservation", ",", "price", "=", "Decimal", "(", "25.62", ...
[ 126, 0 ]
[ 131, 38 ]
python
en
['en', 'en', 'en']
True
reset_cache
(**kwargs)
Reset global state when LANGUAGES setting has been changed, as some languages should no longer be accepted.
Reset global state when LANGUAGES setting has been changed, as some languages should no longer be accepted.
def reset_cache(**kwargs): """ Reset global state when LANGUAGES setting has been changed, as some languages should no longer be accepted. """ if kwargs['setting'] in ('LANGUAGES', 'LANGUAGE_CODE'): check_for_language.cache_clear() get_languages.cache_clear() get_supported_la...
[ "def", "reset_cache", "(", "*", "*", "kwargs", ")", ":", "if", "kwargs", "[", "'setting'", "]", "in", "(", "'LANGUAGES'", ",", "'LANGUAGE_CODE'", ")", ":", "check_for_language", ".", "cache_clear", "(", ")", "get_languages", ".", "cache_clear", "(", ")", "...
[ 48, 0 ]
[ 56, 52 ]
python
en
['en', 'error', 'th']
False
translation
(language)
Return a translation object in the default 'django' domain.
Return a translation object in the default 'django' domain.
def translation(language): """ Return a translation object in the default 'django' domain. """ global _translations if language not in _translations: _translations[language] = DjangoTranslation(language) return _translations[language]
[ "def", "translation", "(", "language", ")", ":", "global", "_translations", "if", "language", "not", "in", "_translations", ":", "_translations", "[", "language", "]", "=", "DjangoTranslation", "(", "language", ")", "return", "_translations", "[", "language", "]...
[ 260, 0 ]
[ 267, 34 ]
python
en
['en', 'error', 'th']
False
activate
(language)
Fetch the translation object for a given language and install it as the current translation object for the current thread.
Fetch the translation object for a given language and install it as the current translation object for the current thread.
def activate(language): """ Fetch the translation object for a given language and install it as the current translation object for the current thread. """ if not language: return _active.value = translation(language)
[ "def", "activate", "(", "language", ")", ":", "if", "not", "language", ":", "return", "_active", ".", "value", "=", "translation", "(", "language", ")" ]
[ 270, 0 ]
[ 277, 41 ]
python
en
['en', 'error', 'th']
False
deactivate
()
Uninstall the active translation object so that further _() calls resolve to the default translation object.
Uninstall the active translation object so that further _() calls resolve to the default translation object.
def deactivate(): """ Uninstall the active translation object so that further _() calls resolve to the default translation object. """ if hasattr(_active, "value"): del _active.value
[ "def", "deactivate", "(", ")", ":", "if", "hasattr", "(", "_active", ",", "\"value\"", ")", ":", "del", "_active", ".", "value" ]
[ 280, 0 ]
[ 286, 25 ]
python
en
['en', 'error', 'th']
False
deactivate_all
()
Make the active translation object a NullTranslations() instance. This is useful when we want delayed translations to appear as the original string for some reason.
Make the active translation object a NullTranslations() instance. This is useful when we want delayed translations to appear as the original string for some reason.
def deactivate_all(): """ Make the active translation object a NullTranslations() instance. This is useful when we want delayed translations to appear as the original string for some reason. """ _active.value = gettext_module.NullTranslations() _active.value.to_language = lambda *args: None
[ "def", "deactivate_all", "(", ")", ":", "_active", ".", "value", "=", "gettext_module", ".", "NullTranslations", "(", ")", "_active", ".", "value", ".", "to_language", "=", "lambda", "*", "args", ":", "None" ]
[ 289, 0 ]
[ 296, 50 ]
python
en
['en', 'error', 'th']
False
get_language
()
Return the currently selected language.
Return the currently selected language.
def get_language(): """Return the currently selected language.""" t = getattr(_active, "value", None) if t is not None: try: return t.to_language() except AttributeError: pass # If we don't have a real translation object, assume it's the default language. retu...
[ "def", "get_language", "(", ")", ":", "t", "=", "getattr", "(", "_active", ",", "\"value\"", ",", "None", ")", "if", "t", "is", "not", "None", ":", "try", ":", "return", "t", ".", "to_language", "(", ")", "except", "AttributeError", ":", "pass", "# I...
[ 299, 0 ]
[ 308, 33 ]
python
en
['en', 'en', 'en']
True
get_language_bidi
()
Return selected language's BiDi layout. * False = left-to-right layout * True = right-to-left layout
Return selected language's BiDi layout.
def get_language_bidi(): """ Return selected language's BiDi layout. * False = left-to-right layout * True = right-to-left layout """ lang = get_language() if lang is None: return False else: base_lang = get_language().split('-')[0] return base_lang in settings.L...
[ "def", "get_language_bidi", "(", ")", ":", "lang", "=", "get_language", "(", ")", "if", "lang", "is", "None", ":", "return", "False", "else", ":", "base_lang", "=", "get_language", "(", ")", ".", "split", "(", "'-'", ")", "[", "0", "]", "return", "ba...
[ 311, 0 ]
[ 323, 51 ]
python
en
['en', 'error', 'th']
False
catalog
()
Return the current active catalog for further processing. This can be used if you need to modify the catalog or want to access the whole message catalog instead of just translating one string.
Return the current active catalog for further processing. This can be used if you need to modify the catalog or want to access the whole message catalog instead of just translating one string.
def catalog(): """ Return the current active catalog for further processing. This can be used if you need to modify the catalog or want to access the whole message catalog instead of just translating one string. """ global _default t = getattr(_active, "value", None) if t is not None: ...
[ "def", "catalog", "(", ")", ":", "global", "_default", "t", "=", "getattr", "(", "_active", ",", "\"value\"", ",", "None", ")", "if", "t", "is", "not", "None", ":", "return", "t", "if", "_default", "is", "None", ":", "_default", "=", "translation", "...
[ 326, 0 ]
[ 339, 19 ]
python
en
['en', 'error', 'th']
False
gettext
(message)
Translate the 'message' string. It uses the current thread to find the translation object to use. If no current translation is activated, the message will be run through the default translation object.
Translate the 'message' string. It uses the current thread to find the translation object to use. If no current translation is activated, the message will be run through the default translation object.
def gettext(message): """ Translate the 'message' string. It uses the current thread to find the translation object to use. If no current translation is activated, the message will be run through the default translation object. """ global _default eol_message = message.replace('\r\n', '\n')...
[ "def", "gettext", "(", "message", ")", ":", "global", "_default", "eol_message", "=", "message", ".", "replace", "(", "'\\r\\n'", ",", "'\\n'", ")", ".", "replace", "(", "'\\r'", ",", "'\\n'", ")", "if", "eol_message", ":", "_default", "=", "_default", "...
[ 342, 0 ]
[ 365, 17 ]
python
en
['en', 'error', 'th']
False
gettext_noop
(message)
Mark strings for translation but don't translate them now. This can be used to store strings in global variables that should stay in the base language (because they might be used externally) and will be translated later.
Mark strings for translation but don't translate them now. This can be used to store strings in global variables that should stay in the base language (because they might be used externally) and will be translated later.
def gettext_noop(message): """ Mark strings for translation but don't translate them now. This can be used to store strings in global variables that should stay in the base language (because they might be used externally) and will be translated later. """ return message
[ "def", "gettext_noop", "(", "message", ")", ":", "return", "message" ]
[ 379, 0 ]
[ 386, 18 ]
python
en
['en', 'error', 'th']
False
ngettext
(singular, plural, number)
Return a string of the translation of either the singular or plural, based on the number.
Return a string of the translation of either the singular or plural, based on the number.
def ngettext(singular, plural, number): """ Return a string of the translation of either the singular or plural, based on the number. """ return do_ntranslate(singular, plural, number, 'ngettext')
[ "def", "ngettext", "(", "singular", ",", "plural", ",", "number", ")", ":", "return", "do_ntranslate", "(", "singular", ",", "plural", ",", "number", ",", "'ngettext'", ")" ]
[ 400, 0 ]
[ 405, 62 ]
python
en
['en', 'error', 'th']
False
all_locale_paths
()
Return a list of paths to user-provides languages files.
Return a list of paths to user-provides languages files.
def all_locale_paths(): """ Return a list of paths to user-provides languages files. """ globalpath = os.path.join( os.path.dirname(sys.modules[settings.__module__].__file__), 'locale') app_paths = [] for app_config in apps.get_app_configs(): locale_path = os.path.join(app_config...
[ "def", "all_locale_paths", "(", ")", ":", "globalpath", "=", "os", ".", "path", ".", "join", "(", "os", ".", "path", ".", "dirname", "(", "sys", ".", "modules", "[", "settings", ".", "__module__", "]", ".", "__file__", ")", ",", "'locale'", ")", "app...
[ 419, 0 ]
[ 430, 59 ]
python
en
['en', 'error', 'th']
False
check_for_language
(lang_code)
Check whether there is a global language file for the given language code. This is used to decide whether a user-provided language is available. lru_cache should have a maxsize to prevent from memory exhaustion attacks, as the provided language codes are taken from the HTTP request. See also <...
Check whether there is a global language file for the given language code. This is used to decide whether a user-provided language is available.
def check_for_language(lang_code): """ Check whether there is a global language file for the given language code. This is used to decide whether a user-provided language is available. lru_cache should have a maxsize to prevent from memory exhaustion attacks, as the provided language codes are t...
[ "def", "check_for_language", "(", "lang_code", ")", ":", "# First, a quick check to make sure lang_code is well-formed (#21458)", "if", "lang_code", "is", "None", "or", "not", "language_code_re", ".", "search", "(", "lang_code", ")", ":", "return", "False", "return", "a...
[ 434, 0 ]
[ 450, 5 ]
python
en
['en', 'error', 'th']
False
get_languages
()
Cache of settings.LANGUAGES in a dictionary for easy lookups by key.
Cache of settings.LANGUAGES in a dictionary for easy lookups by key.
def get_languages(): """ Cache of settings.LANGUAGES in a dictionary for easy lookups by key. """ return dict(settings.LANGUAGES)
[ "def", "get_languages", "(", ")", ":", "return", "dict", "(", "settings", ".", "LANGUAGES", ")" ]
[ 454, 0 ]
[ 458, 35 ]
python
en
['en', 'error', 'th']
False
get_supported_language_variant
(lang_code, strict=False)
Return the language code that's listed in supported languages, possibly selecting a more generic variant. Raise LookupError if nothing is found. If `strict` is False (the default), look for a country-specific variant when neither the language code nor its generic variant is found. lru_cache shoul...
Return the language code that's listed in supported languages, possibly selecting a more generic variant. Raise LookupError if nothing is found.
def get_supported_language_variant(lang_code, strict=False): """ Return the language code that's listed in supported languages, possibly selecting a more generic variant. Raise LookupError if nothing is found. If `strict` is False (the default), look for a country-specific variant when neither the ...
[ "def", "get_supported_language_variant", "(", "lang_code", ",", "strict", "=", "False", ")", ":", "if", "lang_code", ":", "# If 'fr-ca' is not supported, try special fallback or language-only 'fr'.", "possible_lang_codes", "=", "[", "lang_code", "]", "try", ":", "possible_l...
[ 462, 0 ]
[ 493, 32 ]
python
en
['en', 'error', 'th']
False
get_language_from_path
(path, strict=False)
Return the language code if there's a valid language code found in `path`. If `strict` is False (the default), look for a country-specific variant when neither the language code nor its generic variant is found.
Return the language code if there's a valid language code found in `path`.
def get_language_from_path(path, strict=False): """ Return the language code if there's a valid language code found in `path`. If `strict` is False (the default), look for a country-specific variant when neither the language code nor its generic variant is found. """ regex_match = language_code...
[ "def", "get_language_from_path", "(", "path", ",", "strict", "=", "False", ")", ":", "regex_match", "=", "language_code_prefix_re", ".", "match", "(", "path", ")", "if", "not", "regex_match", ":", "return", "None", "lang_code", "=", "regex_match", ".", "group"...
[ 496, 0 ]
[ 510, 19 ]
python
en
['en', 'error', 'th']
False
get_language_from_request
(request, check_path=False)
Analyze the request to find what language the user wants the system to show. Only languages listed in settings.LANGUAGES are taken into account. If the user requests a sublanguage where we have a main language, we send out the main language. If check_path is True, the URL path prefix will be check...
Analyze the request to find what language the user wants the system to show. Only languages listed in settings.LANGUAGES are taken into account. If the user requests a sublanguage where we have a main language, we send out the main language.
def get_language_from_request(request, check_path=False): """ Analyze the request to find what language the user wants the system to show. Only languages listed in settings.LANGUAGES are taken into account. If the user requests a sublanguage where we have a main language, we send out the main langua...
[ "def", "get_language_from_request", "(", "request", ",", "check_path", "=", "False", ")", ":", "if", "check_path", ":", "lang_code", "=", "get_language_from_path", "(", "request", ".", "path_info", ")", "if", "lang_code", "is", "not", "None", ":", "return", "l...
[ 513, 0 ]
[ 553, 37 ]
python
en
['en', 'error', 'th']
False
parse_accept_lang_header
(lang_string)
Parse the lang_string, which is the body of an HTTP Accept-Language header, and return a tuple of (lang, q-value), ordered by 'q' values. Return an empty tuple if there are any format errors in lang_string.
Parse the lang_string, which is the body of an HTTP Accept-Language header, and return a tuple of (lang, q-value), ordered by 'q' values.
def parse_accept_lang_header(lang_string): """ Parse the lang_string, which is the body of an HTTP Accept-Language header, and return a tuple of (lang, q-value), ordered by 'q' values. Return an empty tuple if there are any format errors in lang_string. """ result = [] pieces = accept_langu...
[ "def", "parse_accept_lang_header", "(", "lang_string", ")", ":", "result", "=", "[", "]", "pieces", "=", "accept_language_re", ".", "split", "(", "lang_string", ".", "lower", "(", ")", ")", "if", "pieces", "[", "-", "1", "]", ":", "return", "(", ")", "...
[ 557, 0 ]
[ 578, 24 ]
python
en
['en', 'error', 'th']
False
DjangoTranslation.__init__
(self, language, domain=None, localedirs=None)
Create a GNUTranslations() using many locale directories
Create a GNUTranslations() using many locale directories
def __init__(self, language, domain=None, localedirs=None): """Create a GNUTranslations() using many locale directories""" gettext_module.GNUTranslations.__init__(self) if domain is not None: self.domain = domain self.__language = language self.__to_language = to_lan...
[ "def", "__init__", "(", "self", ",", "language", ",", "domain", "=", "None", ",", "localedirs", "=", "None", ")", ":", "gettext_module", ".", "GNUTranslations", ".", "__init__", "(", "self", ")", "if", "domain", "is", "not", "None", ":", "self", ".", "...
[ 127, 4 ]
[ 162, 48 ]
python
en
['en', 'en', 'en']
True
DjangoTranslation._new_gnu_trans
(self, localedir, use_null_fallback=True)
Return a mergeable gettext.GNUTranslations instance. A convenience wrapper. By default gettext uses 'fallback=False'. Using param `use_null_fallback` to avoid confusion with any other references to 'fallback'.
Return a mergeable gettext.GNUTranslations instance.
def _new_gnu_trans(self, localedir, use_null_fallback=True): """ Return a mergeable gettext.GNUTranslations instance. A convenience wrapper. By default gettext uses 'fallback=False'. Using param `use_null_fallback` to avoid confusion with any other references to 'fallback'. ...
[ "def", "_new_gnu_trans", "(", "self", ",", "localedir", ",", "use_null_fallback", "=", "True", ")", ":", "return", "gettext_module", ".", "translation", "(", "domain", "=", "self", ".", "domain", ",", "localedir", "=", "localedir", ",", "languages", "=", "["...
[ 167, 4 ]
[ 180, 9 ]
python
en
['en', 'error', 'th']
False
DjangoTranslation._init_translation_catalog
(self)
Create a base catalog using global django translations.
Create a base catalog using global django translations.
def _init_translation_catalog(self): """Create a base catalog using global django translations.""" settingsfile = sys.modules[settings.__module__].__file__ localedir = os.path.join(os.path.dirname(settingsfile), 'locale') translation = self._new_gnu_trans(localedir) self.merge(tr...
[ "def", "_init_translation_catalog", "(", "self", ")", ":", "settingsfile", "=", "sys", ".", "modules", "[", "settings", ".", "__module__", "]", ".", "__file__", "localedir", "=", "os", ".", "path", ".", "join", "(", "os", ".", "path", ".", "dirname", "("...
[ 182, 4 ]
[ 187, 31 ]
python
en
['en', 'bg', 'en']
True
DjangoTranslation._add_installed_apps_translations
(self)
Merge translations from each installed app.
Merge translations from each installed app.
def _add_installed_apps_translations(self): """Merge translations from each installed app.""" try: app_configs = reversed(list(apps.get_app_configs())) except AppRegistryNotReady: raise AppRegistryNotReady( "The translation infrastructure cannot be initial...
[ "def", "_add_installed_apps_translations", "(", "self", ")", ":", "try", ":", "app_configs", "=", "reversed", "(", "list", "(", "apps", ".", "get_app_configs", "(", ")", ")", ")", "except", "AppRegistryNotReady", ":", "raise", "AppRegistryNotReady", "(", "\"The ...
[ 189, 4 ]
[ 202, 39 ]
python
en
['en', 'en', 'en']
True
DjangoTranslation._add_local_translations
(self)
Merge translations defined in LOCALE_PATHS.
Merge translations defined in LOCALE_PATHS.
def _add_local_translations(self): """Merge translations defined in LOCALE_PATHS.""" for localedir in reversed(settings.LOCALE_PATHS): translation = self._new_gnu_trans(localedir) self.merge(translation)
[ "def", "_add_local_translations", "(", "self", ")", ":", "for", "localedir", "in", "reversed", "(", "settings", ".", "LOCALE_PATHS", ")", ":", "translation", "=", "self", ".", "_new_gnu_trans", "(", "localedir", ")", "self", ".", "merge", "(", "translation", ...
[ 204, 4 ]
[ 208, 35 ]
python
en
['en', 'en', 'en']
True
DjangoTranslation._add_fallback
(self, localedirs=None)
Set the GNUTranslations() fallback with the default language.
Set the GNUTranslations() fallback with the default language.
def _add_fallback(self, localedirs=None): """Set the GNUTranslations() fallback with the default language.""" # Don't set a fallback for the default language or any English variant # (as it's empty, so it'll ALWAYS fall back to the default language) if self.__language == settings.LANGUAG...
[ "def", "_add_fallback", "(", "self", ",", "localedirs", "=", "None", ")", ":", "# Don't set a fallback for the default language or any English variant", "# (as it's empty, so it'll ALWAYS fall back to the default language)", "if", "self", ".", "__language", "==", "settings", ".",...
[ 210, 4 ]
[ 223, 46 ]
python
en
['en', 'en', 'en']
True
DjangoTranslation.merge
(self, other)
Merge another translation into this catalog.
Merge another translation into this catalog.
def merge(self, other): """Merge another translation into this catalog.""" if not getattr(other, '_catalog', None): return # NullTranslations() has no _catalog if self._catalog is None: # Take plural and _info from first catalog found (generally Django's). se...
[ "def", "merge", "(", "self", ",", "other", ")", ":", "if", "not", "getattr", "(", "other", ",", "'_catalog'", ",", "None", ")", ":", "return", "# NullTranslations() has no _catalog", "if", "self", ".", "_catalog", "is", "None", ":", "# Take plural and _info fr...
[ 225, 4 ]
[ 237, 46 ]
python
en
['en', 'en', 'en']
True
DjangoTranslation.language
(self)
Return the translation language.
Return the translation language.
def language(self): """Return the translation language.""" return self.__language
[ "def", "language", "(", "self", ")", ":", "return", "self", ".", "__language" ]
[ 239, 4 ]
[ 241, 30 ]
python
en
['en', 'zu', 'en']
True
DjangoTranslation.to_language
(self)
Return the translation language name.
Return the translation language name.
def to_language(self): """Return the translation language name.""" return self.__to_language
[ "def", "to_language", "(", "self", ")", ":", "return", "self", ".", "__to_language" ]
[ 243, 4 ]
[ 245, 33 ]
python
en
['en', 'zu', 'en']
True
gen_filenames
(only_new=False)
Returns a list of filenames referenced in sys.modules and translation files.
Returns a list of filenames referenced in sys.modules and translation files.
def gen_filenames(only_new=False): """ Returns a list of filenames referenced in sys.modules and translation files. """ # N.B. ``list(...)`` is needed, because this runs in parallel with # application code which might be mutating ``sys.modules``, and this will # fail with RuntimeError: canno...
[ "def", "gen_filenames", "(", "only_new", "=", "False", ")", ":", "# N.B. ``list(...)`` is needed, because this runs in parallel with", "# application code which might be mutating ``sys.modules``, and this will", "# fail with RuntimeError: cannot mutate dictionary while iterating", "global", ...
[ 83, 0 ]
[ 128, 60 ]
python
en
['en', 'error', 'th']
False
inotify_code_changed
()
Checks for changed code using inotify. After being called it blocks until a change event has been fired.
Checks for changed code using inotify. After being called it blocks until a change event has been fired.
def inotify_code_changed(): """ Checks for changed code using inotify. After being called it blocks until a change event has been fired. """ class EventHandler(pyinotify.ProcessEvent): modified_code = None def process_default(self, event): if event.path.endswith('.mo'): ...
[ "def", "inotify_code_changed", "(", ")", ":", "class", "EventHandler", "(", "pyinotify", ".", "ProcessEvent", ")", ":", "modified_code", "=", "None", "def", "process_default", "(", "self", ",", "event", ")", ":", "if", "event", ".", "path", ".", "endswith", ...
[ 154, 0 ]
[ 198, 37 ]
python
en
['en', 'error', 'th']
False
develop._resolve_setup_path
(egg_base, install_dir, egg_path)
Generate a path from egg_base back to '.' where the setup script resides and ensure that path points to the setup path from $install_dir/$egg_path.
Generate a path from egg_base back to '.' where the setup script resides and ensure that path points to the setup path from $install_dir/$egg_path.
def _resolve_setup_path(egg_base, install_dir, egg_path): """ Generate a path from egg_base back to '.' where the setup script resides and ensure that path points to the setup path from $install_dir/$egg_path. """ path_to_setup = egg_base.replace(os.sep, '/').rstrip('/') ...
[ "def", "_resolve_setup_path", "(", "egg_base", ",", "install_dir", ",", "egg_path", ")", ":", "path_to_setup", "=", "egg_base", ".", "replace", "(", "os", ".", "sep", ",", "'/'", ")", ".", "rstrip", "(", "'/'", ")", "if", "path_to_setup", "!=", "os", "."...
[ 90, 4 ]
[ 107, 28 ]
python
en
['en', 'error', 'th']
False
GenericRelationsTests.test_generic_update_or_create_when_created
(self)
Should be able to use update_or_create from the generic related manager to create a tag. Refs #23611.
Should be able to use update_or_create from the generic related manager to create a tag. Refs #23611.
def test_generic_update_or_create_when_created(self): """ Should be able to use update_or_create from the generic related manager to create a tag. Refs #23611. """ count = self.bacon.tags.count() tag, created = self.bacon.tags.update_or_create(tag='stinky') self.a...
[ "def", "test_generic_update_or_create_when_created", "(", "self", ")", ":", "count", "=", "self", ".", "bacon", ".", "tags", ".", "count", "(", ")", "tag", ",", "created", "=", "self", ".", "bacon", ".", "tags", ".", "update_or_create", "(", "tag", "=", ...
[ 37, 4 ]
[ 45, 60 ]
python
en
['en', 'error', 'th']
False
GenericRelationsTests.test_generic_update_or_create_when_updated
(self)
Should be able to use update_or_create from the generic related manager to update a tag. Refs #23611.
Should be able to use update_or_create from the generic related manager to update a tag. Refs #23611.
def test_generic_update_or_create_when_updated(self): """ Should be able to use update_or_create from the generic related manager to update a tag. Refs #23611. """ count = self.bacon.tags.count() tag = self.bacon.tags.create(tag='stinky') self.assertEqual(count + ...
[ "def", "test_generic_update_or_create_when_updated", "(", "self", ")", ":", "count", "=", "self", ".", "bacon", ".", "tags", ".", "count", "(", ")", "tag", "=", "self", ".", "bacon", ".", "tags", ".", "create", "(", "tag", "=", "'stinky'", ")", "self", ...
[ 47, 4 ]
[ 58, 42 ]
python
en
['en', 'error', 'th']
False
GenericRelationsTests.test_generic_get_or_create_when_created
(self)
Should be able to use get_or_create from the generic related manager to create a tag. Refs #23611.
Should be able to use get_or_create from the generic related manager to create a tag. Refs #23611.
def test_generic_get_or_create_when_created(self): """ Should be able to use get_or_create from the generic related manager to create a tag. Refs #23611. """ count = self.bacon.tags.count() tag, created = self.bacon.tags.get_or_create(tag='stinky') self.assertTrue...
[ "def", "test_generic_get_or_create_when_created", "(", "self", ")", ":", "count", "=", "self", ".", "bacon", ".", "tags", ".", "count", "(", ")", "tag", ",", "created", "=", "self", ".", "bacon", ".", "tags", ".", "get_or_create", "(", "tag", "=", "'stin...
[ 60, 4 ]
[ 68, 60 ]
python
en
['en', 'error', 'th']
False