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
srs_output
(func, argtypes)
Generates a ctypes prototype for the given function with the given C arguments that returns a pointer to an OGR Spatial Reference System.
Generates a ctypes prototype for the given function with the given C arguments that returns a pointer to an OGR Spatial Reference System.
def srs_output(func, argtypes): """ Generates a ctypes prototype for the given function with the given C arguments that returns a pointer to an OGR Spatial Reference System. """ func.argtypes = argtypes func.restype = c_void_p func.errcheck = check_srs return func
[ "def", "srs_output", "(", "func", ",", "argtypes", ")", ":", "func", ".", "argtypes", "=", "argtypes", "func", ".", "restype", "=", "c_void_p", "func", ".", "errcheck", "=", "check_srs", "return", "func" ]
[ 56, 0 ]
[ 65, 15 ]
python
en
['en', 'error', 'th']
False
string_output
(func, argtypes, offset=-1, str_result=False, decoding=None)
Generates a ctypes prototype for the given function with the given argument types that returns a string from a GDAL pointer. The `const` flag indicates whether the allocated pointer should be freed via the GDAL library routine VSIFree -- but only applies only when `str_result` is True.
Generates a ctypes prototype for the given function with the given argument types that returns a string from a GDAL pointer. The `const` flag indicates whether the allocated pointer should be freed via the GDAL library routine VSIFree -- but only applies only when `str_result` is True.
def string_output(func, argtypes, offset=-1, str_result=False, decoding=None): """ Generates a ctypes prototype for the given function with the given argument types that returns a string from a GDAL pointer. The `const` flag indicates whether the allocated pointer should be freed via the GDAL librar...
[ "def", "string_output", "(", "func", ",", "argtypes", ",", "offset", "=", "-", "1", ",", "str_result", "=", "False", ",", "decoding", "=", "None", ")", ":", "func", ".", "argtypes", "=", "argtypes", "if", "str_result", ":", "# Use subclass of c_char_p so the...
[ 85, 0 ]
[ 111, 15 ]
python
en
['en', 'error', 'th']
False
void_output
(func, argtypes, errcheck=True)
For functions that don't only return an error code that needs to be examined.
For functions that don't only return an error code that needs to be examined.
def void_output(func, argtypes, errcheck=True): """ For functions that don't only return an error code that needs to be examined. """ if argtypes: func.argtypes = argtypes if errcheck: # `errcheck` keyword may be set to False for routines that # return void, rather than a...
[ "def", "void_output", "(", "func", ",", "argtypes", ",", "errcheck", "=", "True", ")", ":", "if", "argtypes", ":", "func", ".", "argtypes", "=", "argtypes", "if", "errcheck", ":", "# `errcheck` keyword may be set to False for routines that", "# return void, rather tha...
[ 114, 0 ]
[ 129, 15 ]
python
en
['en', 'error', 'th']
False
voidptr_output
(func, argtypes)
For functions that return c_void_p.
For functions that return c_void_p.
def voidptr_output(func, argtypes): "For functions that return c_void_p." func.argtypes = argtypes func.restype = c_void_p func.errcheck = check_pointer return func
[ "def", "voidptr_output", "(", "func", ",", "argtypes", ")", ":", "func", ".", "argtypes", "=", "argtypes", "func", ".", "restype", "=", "c_void_p", "func", ".", "errcheck", "=", "check_pointer", "return", "func" ]
[ 132, 0 ]
[ 137, 15 ]
python
en
['en', 'en', 'en']
True
TrainManager.__init__
(self, hparams)
:param hparams: An instance of collections.namedtuple specifying the model type and training configs. The parameters are documented in `run_multigpu.py`.
:param hparams: An instance of collections.namedtuple specifying the model type and training configs. The parameters are documented in `run_multigpu.py`.
def __init__(self, hparams): """ :param hparams: An instance of collections.namedtuple specifying the model type and training configs. The parameters are documented in `run_multigpu.py`. """ self.hparams = hparams self.batch_size = ...
[ "def", "__init__", "(", "self", ",", "hparams", ")", ":", "self", ".", "hparams", "=", "hparams", "self", ".", "batch_size", "=", "hparams", ".", "batch_size", "self", ".", "evaluate", "=", "None", "self", ".", "step_num", "=", "0", "self", ".", "repor...
[ 35, 4 ]
[ 52, 26 ]
python
en
['en', 'error', 'th']
False
TrainManager.model_train
(self)
Train a TF graph :param sess: TF session to use when training the graph :param x: input placeholder :param y: output placeholder (for labels) :param predictions: model output predictions :param X_train: numpy array with training inputs :param Y_train: numpy array...
Train a TF graph :param sess: TF session to use when training the graph :param x: input placeholder :param y: output placeholder (for labels) :param predictions: model output predictions :param X_train: numpy array with training inputs :param Y_train: numpy array...
def model_train(self): """ Train a TF graph :param sess: TF session to use when training the graph :param x: input placeholder :param y: output placeholder (for labels) :param predictions: model output predictions :param X_train: numpy array with training inputs ...
[ "def", "model_train", "(", "self", ")", ":", "assert", "(", "self", ".", "runner", "is", "not", "None", ")", ",", "\"\"\"Runner is not initialized. TrainerSingleGPU or TrainerMultiGPU\n instantiate a Runner object at initialization time.\"\"\"", "hparams", "=", "self...
[ 198, 4 ]
[ 279, 49 ]
python
en
['en', 'error', 'th']
False
TrainManager._create_train_graph
(self)
The evaluation graph must be initialized after the train graph is fully initialized, otherwise, some of the variables will be created untrainable.
The evaluation graph must be initialized after the train graph is fully initialized, otherwise, some of the variables will be created untrainable.
def _create_train_graph(self): """ The evaluation graph must be initialized after the train graph is fully initialized, otherwise, some of the variables will be created untrainable. """ assert ( self.evaluate is None ), """Evaluation graph should be in...
[ "def", "_create_train_graph", "(", "self", ")", ":", "assert", "(", "self", ".", "evaluate", "is", "None", ")", ",", "\"\"\"Evaluation graph should be initialzed\n after the train graph\"\"\"" ]
[ 296, 4 ]
[ 305, 63 ]
python
en
['en', 'error', 'th']
False
TrainerMultiGPU.clone_g0_inputs_on_ngpus
(self, inputs, outputs, g0_inputs)
Clone variables unused by the attack on all GPUs. Specifically, the ground-truth label, y, has to be preserved until the training step. :param inputs: A list of dictionaries as the inputs to each step. :param outputs: A list of dictionaries as the outputs of each step. :param g...
Clone variables unused by the attack on all GPUs. Specifically, the ground-truth label, y, has to be preserved until the training step.
def clone_g0_inputs_on_ngpus(self, inputs, outputs, g0_inputs): """ Clone variables unused by the attack on all GPUs. Specifically, the ground-truth label, y, has to be preserved until the training step. :param inputs: A list of dictionaries as the inputs to each step. :param ou...
[ "def", "clone_g0_inputs_on_ngpus", "(", "self", ",", "inputs", ",", "outputs", ",", "g0_inputs", ")", ":", "assert", "len", "(", "inputs", ")", "==", "len", "(", "outputs", ")", ",", "\"Inputs and outputs should have the same number of elements.\"", "inputs", "[", ...
[ 321, 4 ]
[ 350, 30 ]
python
en
['en', 'error', 'th']
False
TrainerSingleGPU._sync_params
(self, forced=False)
Nothing to sync on single GPU.
Nothing to sync on single GPU.
def _sync_params(self, forced=False): """ Nothing to sync on single GPU. """ return True
[ "def", "_sync_params", "(", "self", ",", "forced", "=", "False", ")", ":", "return", "True" ]
[ 492, 4 ]
[ 496, 19 ]
python
en
['en', 'error', 'th']
False
Command.run_from_argv
(self, argv)
Pre-parse the command line to extract the value of the --testrunner option. This allows a test runner to define additional command line arguments.
Pre-parse the command line to extract the value of the --testrunner option. This allows a test runner to define additional command line arguments.
def run_from_argv(self, argv): """ Pre-parse the command line to extract the value of the --testrunner option. This allows a test runner to define additional command line arguments. """ self.test_runner = get_command_line_option(argv, '--testrunner') super().run_f...
[ "def", "run_from_argv", "(", "self", ",", "argv", ")", ":", "self", ".", "test_runner", "=", "get_command_line_option", "(", "argv", ",", "'--testrunner'", ")", "super", "(", ")", ".", "run_from_argv", "(", "argv", ")" ]
[ 15, 4 ]
[ 22, 35 ]
python
en
['en', 'error', 'th']
False
update_test_databases_if_required
(rebuild_test_database: bool = False)
Checks whether the zulip_test_template database template, is consistent with our database migrations; if not, it updates it in the fastest way possible: * If all we need to do is add some migrations, just runs those migrations on the template database. * Otherwise, we rebuild the test template da...
Checks whether the zulip_test_template database template, is consistent with our database migrations; if not, it updates it in the fastest way possible:
def update_test_databases_if_required(rebuild_test_database: bool = False) -> None: """Checks whether the zulip_test_template database template, is consistent with our database migrations; if not, it updates it in the fastest way possible: * If all we need to do is add some migrations, just runs those ...
[ "def", "update_test_databases_if_required", "(", "rebuild_test_database", ":", "bool", "=", "False", ")", "->", "None", ":", "test_template_db_status", "=", "TEST_DATABASE", ".", "template_status", "(", ")", "if", "test_template_db_status", "==", "\"needs_rebuild\"", ":...
[ 254, 0 ]
[ 285, 46 ]
python
en
['en', 'en', 'en']
True
destroy_leaked_test_databases
(expiry_time: int = 60 * 60)
The logic in zerver/lib/test_runner.py tries to delete all the temporary test databases generated by test-backend threads, but it cannot guarantee it handles all race conditions correctly. This is a catch-all function designed to delete any that might have been leaked due to crashes (etc.). The high-l...
The logic in zerver/lib/test_runner.py tries to delete all the temporary test databases generated by test-backend threads, but it cannot guarantee it handles all race conditions correctly. This is a catch-all function designed to delete any that might have been leaked due to crashes (etc.). The high-l...
def destroy_leaked_test_databases(expiry_time: int = 60 * 60) -> int: """The logic in zerver/lib/test_runner.py tries to delete all the temporary test databases generated by test-backend threads, but it cannot guarantee it handles all race conditions correctly. This is a catch-all function designed to ...
[ "def", "destroy_leaked_test_databases", "(", "expiry_time", ":", "int", "=", "60", "*", "60", ")", "->", "int", ":", "files", "=", "glob", ".", "glob", "(", "os", ".", "path", ".", "join", "(", "UUID_VAR_DIR", ",", "TEMPLATE_DATABASE_DIR", ",", "\"*\"", ...
[ 323, 0 ]
[ 374, 33 ]
python
en
['en', 'en', 'en']
True
reset_zulip_test_database
()
This function is used to reset the zulip_test database fastest way possible, i.e. First, it deletes the database and then clones it from zulip_test_template. This function is used with puppeteer tests, so it can quickly reset the test database after each run.
This function is used to reset the zulip_test database fastest way possible, i.e. First, it deletes the database and then clones it from zulip_test_template. This function is used with puppeteer tests, so it can quickly reset the test database after each run.
def reset_zulip_test_database() -> None: """ This function is used to reset the zulip_test database fastest way possible, i.e. First, it deletes the database and then clones it from zulip_test_template. This function is used with puppeteer tests, so it can quickly reset the test database after each ...
[ "def", "reset_zulip_test_database", "(", ")", "->", "None", ":", "from", "zerver", ".", "lib", ".", "test_runner", "import", "destroy_test_databases", "# Make sure default database is 'zulip_test'.", "assert", "connections", "[", "\"default\"", "]", ".", "settings_dict", ...
[ 390, 0 ]
[ 433, 22 ]
python
en
['en', 'error', 'th']
False
Database.template_status
(self)
NOTE: We immediately update the digest, assuming our callers will do what it takes to run the migrations. Ideally our callers would just do it themselves AFTER the migrations actually succeeded, but the caller codepaths are kind of complicated here. ...
NOTE: We immediately update the digest, assuming our callers will do what it takes to run the migrations.
def template_status(self) -> str: # This function returns a status string specifying the type of # state the template db is in and thus the kind of action required. if not self.database_exists(): # TODO: It's possible that `database_exists` will # return `False` eve...
[ "def", "template_status", "(", "self", ")", "->", "str", ":", "# This function returns a status string specifying the type of", "# state the template db is in and thus the kind of action required.", "if", "not", "self", ".", "database_exists", "(", ")", ":", "# TODO: It's possibl...
[ 176, 4 ]
[ 219, 24 ]
python
en
['en', 'error', 'th']
False
get_admin_log
(parser, token)
Populates a template variable with the admin log for the given criteria. Usage:: {% get_admin_log [limit] as [varname] for_user [context_var_containing_user_obj] %} Examples:: {% get_admin_log 10 as admin_log for_user 23 %} {% get_admin_log 10 as admin_log for_user user %} ...
Populates a template variable with the admin log for the given criteria.
def get_admin_log(parser, token): """ Populates a template variable with the admin log for the given criteria. Usage:: {% get_admin_log [limit] as [varname] for_user [context_var_containing_user_obj] %} Examples:: {% get_admin_log 10 as admin_log for_user 23 %} {% get_admin_l...
[ "def", "get_admin_log", "(", "parser", ",", "token", ")", ":", "tokens", "=", "token", ".", "contents", ".", "split", "(", ")", "if", "len", "(", "tokens", ")", "<", "4", ":", "raise", "template", ".", "TemplateSyntaxError", "(", "\"'get_admin_log' stateme...
[ 27, 0 ]
[ 59, 106 ]
python
en
['en', 'error', 'th']
False
instances_and_widgets
(bound_field)
Returns a list of two-tuples of instances and widgets, designed to be used with ModelMultipleChoiceField and CheckboxSelectMultiple widgets. Allows templates to loop over a multiple checkbox field and display the related model instance, such as for a table with checkboxes. Usage: {% for in...
Returns a list of two-tuples of instances and widgets, designed to be used with ModelMultipleChoiceField and CheckboxSelectMultiple widgets.
def instances_and_widgets(bound_field): """ Returns a list of two-tuples of instances and widgets, designed to be used with ModelMultipleChoiceField and CheckboxSelectMultiple widgets. Allows templates to loop over a multiple checkbox field and display the related model instance, such as for a tabl...
[ "def", "instances_and_widgets", "(", "bound_field", ")", ":", "instance_widgets", "=", "[", "]", "for", "index", ",", "instance", "in", "enumerate", "(", "bound_field", ".", "field", ".", "queryset", ".", "all", "(", ")", ")", ":", "widget", "=", "copy", ...
[ 7, 0 ]
[ 28, 27 ]
python
en
['en', 'error', 'th']
False
get_value_from_dict
(dict_data, key)
Usage example {{ your_dict|get_value_from_dict:your_key }}.
Usage example {{ your_dict|get_value_from_dict:your_key }}.
def get_value_from_dict(dict_data, key): """ Usage example {{ your_dict|get_value_from_dict:your_key }}. """ if key: return dict_data.get(key)
[ "def", "get_value_from_dict", "(", "dict_data", ",", "key", ")", ":", "if", "key", ":", "return", "dict_data", ".", "get", "(", "key", ")" ]
[ 32, 0 ]
[ 37, 33 ]
python
en
['en', 'error', 'th']
False
main
(args=None)
This is an internal API only meant for use by pip's own console scripts. For additional details, see https://github.com/pypa/pip/issues/7498.
This is an internal API only meant for use by pip's own console scripts.
def main(args=None): # type: (Optional[List[str]]) -> int """This is an internal API only meant for use by pip's own console scripts. For additional details, see https://github.com/pypa/pip/issues/7498. """ from pip._internal.utils.entrypoints import _wrapper return _wrapper(args)
[ "def", "main", "(", "args", "=", "None", ")", ":", "# type: (Optional[List[str]]) -> int", "from", "pip", ".", "_internal", ".", "utils", ".", "entrypoints", "import", "_wrapper", "return", "_wrapper", "(", "args", ")" ]
[ 9, 0 ]
[ 17, 25 ]
python
en
['en', 'en', 'en']
True
build_clib.check_library_list
(self, libraries)
Ensure that the list of libraries is valid. `library` is presumably provided as a command option 'libraries'. This method checks that it is a list of 2-tuples, where the tuples are (library_name, build_info_dict). Raise DistutilsSetupError if the structure is invalid anywhere; ...
Ensure that the list of libraries is valid.
def check_library_list(self, libraries): """Ensure that the list of libraries is valid. `library` is presumably provided as a command option 'libraries'. This method checks that it is a list of 2-tuples, where the tuples are (library_name, build_info_dict). Raise DistutilsSetup...
[ "def", "check_library_list", "(", "self", ",", "libraries", ")", ":", "if", "not", "isinstance", "(", "libraries", ",", "list", ")", ":", "raise", "DistutilsSetupError", "(", "\"'libraries' option must be a list of tuples\"", ")", "for", "lib", "in", "libraries", ...
[ 117, 4 ]
[ 150, 58 ]
python
en
['en', 'en', 'en']
True
stringfilter
(func)
Decorator for filters which should only receive unicode objects. The object passed as the first positional argument will be converted to a unicode object.
Decorator for filters which should only receive unicode objects. The object passed as the first positional argument will be converted to a unicode object.
def stringfilter(func): """ Decorator for filters which should only receive unicode objects. The object passed as the first positional argument will be converted to a unicode object. """ def _dec(*args, **kwargs): if args: args = list(args) args[0] = force_text(ar...
[ "def", "stringfilter", "(", "func", ")", ":", "def", "_dec", "(", "*", "args", ",", "*", "*", "kwargs", ")", ":", "if", "args", ":", "args", "=", "list", "(", "args", ")", "args", "[", "0", "]", "=", "force_text", "(", "args", "[", "0", "]", ...
[ 34, 0 ]
[ 54, 28 ]
python
en
['en', 'error', 'th']
False
addslashes
(value)
Adds slashes before quotes. Useful for escaping strings in CSV, for example. Less useful for escaping JavaScript; use the ``escapejs`` filter instead.
Adds slashes before quotes. Useful for escaping strings in CSV, for example. Less useful for escaping JavaScript; use the ``escapejs`` filter instead.
def addslashes(value): """ Adds slashes before quotes. Useful for escaping strings in CSV, for example. Less useful for escaping JavaScript; use the ``escapejs`` filter instead. """ return value.replace('\\', '\\\\').replace('"', '\\"').replace("'", "\\'")
[ "def", "addslashes", "(", "value", ")", ":", "return", "value", ".", "replace", "(", "'\\\\'", ",", "'\\\\\\\\'", ")", ".", "replace", "(", "'\"'", ",", "'\\\\\"'", ")", ".", "replace", "(", "\"'\"", ",", "\"\\\\'\"", ")" ]
[ 63, 0 ]
[ 69, 78 ]
python
en
['en', 'error', 'th']
False
capfirst
(value)
Capitalizes the first character of the value.
Capitalizes the first character of the value.
def capfirst(value): """Capitalizes the first character of the value.""" return value and value[0].upper() + value[1:]
[ "def", "capfirst", "(", "value", ")", ":", "return", "value", "and", "value", "[", "0", "]", ".", "upper", "(", ")", "+", "value", "[", "1", ":", "]" ]
[ 74, 0 ]
[ 76, 49 ]
python
en
['en', 'en', 'en']
True
escapejs_filter
(value)
Hex encodes characters for use in JavaScript strings.
Hex encodes characters for use in JavaScript strings.
def escapejs_filter(value): """Hex encodes characters for use in JavaScript strings.""" return escapejs(value)
[ "def", "escapejs_filter", "(", "value", ")", ":", "return", "escapejs", "(", "value", ")" ]
[ 81, 0 ]
[ 83, 26 ]
python
en
['en', 'en', 'en']
True
floatformat
(text, arg=-1)
Displays a float to a specified number of decimal places. If called without an argument, it displays the floating point number with one decimal place -- but only if there's a decimal place to be displayed: * num1 = 34.23234 * num2 = 34.00000 * num3 = 34.26000 * {{ num1|floatformat }} disp...
Displays a float to a specified number of decimal places.
def floatformat(text, arg=-1): """ Displays a float to a specified number of decimal places. If called without an argument, it displays the floating point number with one decimal place -- but only if there's a decimal place to be displayed: * num1 = 34.23234 * num2 = 34.00000 * num3 = 34.2...
[ "def", "floatformat", "(", "text", ",", "arg", "=", "-", "1", ")", ":", "try", ":", "input_val", "=", "force_text", "(", "text", ")", "d", "=", "Decimal", "(", "input_val", ")", "except", "UnicodeEncodeError", ":", "return", "''", "except", "InvalidOpera...
[ 100, 0 ]
[ 180, 24 ]
python
en
['en', 'error', 'th']
False
iriencode
(value)
Escapes an IRI value for use in a URL.
Escapes an IRI value for use in a URL.
def iriencode(value): """Escapes an IRI value for use in a URL.""" return force_text(iri_to_uri(value))
[ "def", "iriencode", "(", "value", ")", ":", "return", "force_text", "(", "iri_to_uri", "(", "value", ")", ")" ]
[ 185, 0 ]
[ 187, 40 ]
python
en
['en', 'en', 'en']
True
linenumbers
(value, autoescape=None)
Displays text with line numbers.
Displays text with line numbers.
def linenumbers(value, autoescape=None): """Displays text with line numbers.""" lines = value.split('\n') # Find the maximum width of the line count, for use with zero padding # string format command width = six.text_type(len(six.text_type(len(lines)))) if not autoescape or isinstance(value, Saf...
[ "def", "linenumbers", "(", "value", ",", "autoescape", "=", "None", ")", ":", "lines", "=", "value", ".", "split", "(", "'\\n'", ")", "# Find the maximum width of the line count, for use with zero padding", "# string format command", "width", "=", "six", ".", "text_ty...
[ 192, 0 ]
[ 204, 38 ]
python
en
['en', 'en', 'en']
True
lower
(value)
Converts a string into all lowercase.
Converts a string into all lowercase.
def lower(value): """Converts a string into all lowercase.""" return value.lower()
[ "def", "lower", "(", "value", ")", ":", "return", "value", ".", "lower", "(", ")" ]
[ 209, 0 ]
[ 211, 24 ]
python
en
['en', 'en', 'en']
True
make_list
(value)
Returns the value turned into a list. For an integer, it's a list of digits. For a string, it's a list of characters.
Returns the value turned into a list.
def make_list(value): """ Returns the value turned into a list. For an integer, it's a list of digits. For a string, it's a list of characters. """ return list(value)
[ "def", "make_list", "(", "value", ")", ":", "return", "list", "(", "value", ")" ]
[ 216, 0 ]
[ 223, 22 ]
python
en
['en', 'error', 'th']
False
slugify
(value)
Converts to lowercase, removes non-word characters (alphanumerics and underscores) and converts spaces to hyphens. Also strips leading and trailing whitespace.
Converts to lowercase, removes non-word characters (alphanumerics and underscores) and converts spaces to hyphens. Also strips leading and trailing whitespace.
def slugify(value): """ Converts to lowercase, removes non-word characters (alphanumerics and underscores) and converts spaces to hyphens. Also strips leading and trailing whitespace. """ return _slugify(value)
[ "def", "slugify", "(", "value", ")", ":", "return", "_slugify", "(", "value", ")" ]
[ 228, 0 ]
[ 234, 26 ]
python
en
['en', 'error', 'th']
False
stringformat
(value, arg)
Formats the variable according to the arg, a string formatting specifier. This specifier uses Python string formating syntax, with the exception that the leading "%" is dropped. See http://docs.python.org/lib/typesseq-strings.html for documentation of Python string formatting
Formats the variable according to the arg, a string formatting specifier.
def stringformat(value, arg): """ Formats the variable according to the arg, a string formatting specifier. This specifier uses Python string formating syntax, with the exception that the leading "%" is dropped. See http://docs.python.org/lib/typesseq-strings.html for documentation of Python s...
[ "def", "stringformat", "(", "value", ",", "arg", ")", ":", "try", ":", "return", "(", "\"%\"", "+", "six", ".", "text_type", "(", "arg", ")", ")", "%", "value", "except", "(", "ValueError", ",", "TypeError", ")", ":", "return", "\"\"" ]
[ 238, 0 ]
[ 251, 17 ]
python
en
['en', 'error', 'th']
False
title
(value)
Converts a string into titlecase.
Converts a string into titlecase.
def title(value): """Converts a string into titlecase.""" t = re.sub("([a-z])'([A-Z])", lambda m: m.group(0).lower(), value.title()) return re.sub("\d([A-Z])", lambda m: m.group(0).lower(), t)
[ "def", "title", "(", "value", ")", ":", "t", "=", "re", ".", "sub", "(", "\"([a-z])'([A-Z])\"", ",", "lambda", "m", ":", "m", ".", "group", "(", "0", ")", ".", "lower", "(", ")", ",", "value", ".", "title", "(", ")", ")", "return", "re", ".", ...
[ 256, 0 ]
[ 259, 63 ]
python
en
['en', 'en', 'en']
True
truncatechars
(value, arg)
Truncates a string after a certain number of characters. Argument: Number of characters to truncate after.
Truncates a string after a certain number of characters.
def truncatechars(value, arg): """ Truncates a string after a certain number of characters. Argument: Number of characters to truncate after. """ try: length = int(arg) except ValueError: # Invalid literal for int(). return value # Fail silently. return Truncator(value).ch...
[ "def", "truncatechars", "(", "value", ",", "arg", ")", ":", "try", ":", "length", "=", "int", "(", "arg", ")", "except", "ValueError", ":", "# Invalid literal for int().", "return", "value", "# Fail silently.", "return", "Truncator", "(", "value", ")", ".", ...
[ 264, 0 ]
[ 274, 41 ]
python
en
['en', 'error', 'th']
False
truncatechars_html
(value, arg)
Truncates HTML after a certain number of chars. Argument: Number of chars to truncate after. Newlines in the HTML are preserved.
Truncates HTML after a certain number of chars.
def truncatechars_html(value, arg): """ Truncates HTML after a certain number of chars. Argument: Number of chars to truncate after. Newlines in the HTML are preserved. """ try: length = int(arg) except ValueError: # invalid literal for int() return value # Fail silently....
[ "def", "truncatechars_html", "(", "value", ",", "arg", ")", ":", "try", ":", "length", "=", "int", "(", "arg", ")", "except", "ValueError", ":", "# invalid literal for int()", "return", "value", "# Fail silently.", "return", "Truncator", "(", "value", ")", "."...
[ 279, 0 ]
[ 291, 52 ]
python
en
['en', 'error', 'th']
False
truncatewords
(value, arg)
Truncates a string after a certain number of words. Argument: Number of words to truncate after. Newlines within the string are removed.
Truncates a string after a certain number of words.
def truncatewords(value, arg): """ Truncates a string after a certain number of words. Argument: Number of words to truncate after. Newlines within the string are removed. """ try: length = int(arg) except ValueError: # Invalid literal for int(). return value # Fail silen...
[ "def", "truncatewords", "(", "value", ",", "arg", ")", ":", "try", ":", "length", "=", "int", "(", "arg", ")", "except", "ValueError", ":", "# Invalid literal for int().", "return", "value", "# Fail silently.", "return", "Truncator", "(", "value", ")", ".", ...
[ 296, 0 ]
[ 308, 58 ]
python
en
['en', 'error', 'th']
False
truncatewords_html
(value, arg)
Truncates HTML after a certain number of words. Argument: Number of words to truncate after. Newlines in the HTML are preserved.
Truncates HTML after a certain number of words.
def truncatewords_html(value, arg): """ Truncates HTML after a certain number of words. Argument: Number of words to truncate after. Newlines in the HTML are preserved. """ try: length = int(arg) except ValueError: # invalid literal for int() return value # Fail silently....
[ "def", "truncatewords_html", "(", "value", ",", "arg", ")", ":", "try", ":", "length", "=", "int", "(", "arg", ")", "except", "ValueError", ":", "# invalid literal for int()", "return", "value", "# Fail silently.", "return", "Truncator", "(", "value", ")", "."...
[ 313, 0 ]
[ 325, 69 ]
python
en
['en', 'error', 'th']
False
upper
(value)
Converts a string into all uppercase.
Converts a string into all uppercase.
def upper(value): """Converts a string into all uppercase.""" return value.upper()
[ "def", "upper", "(", "value", ")", ":", "return", "value", ".", "upper", "(", ")" ]
[ 330, 0 ]
[ 332, 24 ]
python
en
['en', 'en', 'en']
True
urlencode
(value, safe=None)
Escapes a value for use in a URL. Takes an optional ``safe`` parameter used to determine the characters which should not be escaped by Django's ``urlquote`` method. If not provided, the default safe characters will be used (but an empty string can be provided when *all* characters should be escape...
Escapes a value for use in a URL.
def urlencode(value, safe=None): """ Escapes a value for use in a URL. Takes an optional ``safe`` parameter used to determine the characters which should not be escaped by Django's ``urlquote`` method. If not provided, the default safe characters will be used (but an empty string can be provided ...
[ "def", "urlencode", "(", "value", ",", "safe", "=", "None", ")", ":", "kwargs", "=", "{", "}", "if", "safe", "is", "not", "None", ":", "kwargs", "[", "'safe'", "]", "=", "safe", "return", "urlquote", "(", "value", ",", "*", "*", "kwargs", ")" ]
[ 337, 0 ]
[ 349, 36 ]
python
en
['en', 'error', 'th']
False
urlize
(value, autoescape=None)
Converts URLs in plain text into clickable links.
Converts URLs in plain text into clickable links.
def urlize(value, autoescape=None): """Converts URLs in plain text into clickable links.""" return mark_safe(_urlize(value, nofollow=True, autoescape=autoescape))
[ "def", "urlize", "(", "value", ",", "autoescape", "=", "None", ")", ":", "return", "mark_safe", "(", "_urlize", "(", "value", ",", "nofollow", "=", "True", ",", "autoescape", "=", "autoescape", ")", ")" ]
[ 354, 0 ]
[ 356, 74 ]
python
en
['en', 'en', 'en']
True
urlizetrunc
(value, limit, autoescape=None)
Converts URLs into clickable links, truncating URLs to the given character limit, and adding 'rel=nofollow' attribute to discourage spamming. Argument: Length to truncate URLs to.
Converts URLs into clickable links, truncating URLs to the given character limit, and adding 'rel=nofollow' attribute to discourage spamming.
def urlizetrunc(value, limit, autoescape=None): """ Converts URLs into clickable links, truncating URLs to the given character limit, and adding 'rel=nofollow' attribute to discourage spamming. Argument: Length to truncate URLs to. """ return mark_safe(_urlize(value, trim_url_limit=int(limit), ...
[ "def", "urlizetrunc", "(", "value", ",", "limit", ",", "autoescape", "=", "None", ")", ":", "return", "mark_safe", "(", "_urlize", "(", "value", ",", "trim_url_limit", "=", "int", "(", "limit", ")", ",", "nofollow", "=", "True", ",", "autoescape", "=", ...
[ 361, 0 ]
[ 369, 51 ]
python
en
['en', 'error', 'th']
False
wordcount
(value)
Returns the number of words.
Returns the number of words.
def wordcount(value): """Returns the number of words.""" return len(value.split())
[ "def", "wordcount", "(", "value", ")", ":", "return", "len", "(", "value", ".", "split", "(", ")", ")" ]
[ 374, 0 ]
[ 376, 29 ]
python
en
['en', 'en', 'en']
True
wordwrap
(value, arg)
Wraps words at specified line length. Argument: number of characters to wrap the text at.
Wraps words at specified line length.
def wordwrap(value, arg): """ Wraps words at specified line length. Argument: number of characters to wrap the text at. """ return wrap(value, int(arg))
[ "def", "wordwrap", "(", "value", ",", "arg", ")", ":", "return", "wrap", "(", "value", ",", "int", "(", "arg", ")", ")" ]
[ 381, 0 ]
[ 387, 32 ]
python
en
['en', 'error', 'th']
False
ljust
(value, arg)
Left-aligns the value in a field of a given width. Argument: field size.
Left-aligns the value in a field of a given width.
def ljust(value, arg): """ Left-aligns the value in a field of a given width. Argument: field size. """ return value.ljust(int(arg))
[ "def", "ljust", "(", "value", ",", "arg", ")", ":", "return", "value", ".", "ljust", "(", "int", "(", "arg", ")", ")" ]
[ 392, 0 ]
[ 398, 32 ]
python
en
['en', 'error', 'th']
False
rjust
(value, arg)
Right-aligns the value in a field of a given width. Argument: field size.
Right-aligns the value in a field of a given width.
def rjust(value, arg): """ Right-aligns the value in a field of a given width. Argument: field size. """ return value.rjust(int(arg))
[ "def", "rjust", "(", "value", ",", "arg", ")", ":", "return", "value", ".", "rjust", "(", "int", "(", "arg", ")", ")" ]
[ 403, 0 ]
[ 409, 32 ]
python
en
['en', 'error', 'th']
False
center
(value, arg)
Centers the value in a field of a given width.
Centers the value in a field of a given width.
def center(value, arg): """Centers the value in a field of a given width.""" return value.center(int(arg))
[ "def", "center", "(", "value", ",", "arg", ")", ":", "return", "value", ".", "center", "(", "int", "(", "arg", ")", ")" ]
[ 414, 0 ]
[ 416, 33 ]
python
en
['en', 'en', 'en']
True
cut
(value, arg)
Removes all values of arg from the given string.
Removes all values of arg from the given string.
def cut(value, arg): """ Removes all values of arg from the given string. """ safe = isinstance(value, SafeData) value = value.replace(arg, '') if safe and arg != ';': return mark_safe(value) return value
[ "def", "cut", "(", "value", ",", "arg", ")", ":", "safe", "=", "isinstance", "(", "value", ",", "SafeData", ")", "value", "=", "value", ".", "replace", "(", "arg", ",", "''", ")", "if", "safe", "and", "arg", "!=", "';'", ":", "return", "mark_safe",...
[ 421, 0 ]
[ 429, 16 ]
python
en
['en', 'error', 'th']
False
escape_filter
(value)
Marks the value as a string that should not be auto-escaped.
Marks the value as a string that should not be auto-escaped.
def escape_filter(value): """ Marks the value as a string that should not be auto-escaped. """ return mark_for_escaping(value)
[ "def", "escape_filter", "(", "value", ")", ":", "return", "mark_for_escaping", "(", "value", ")" ]
[ 438, 0 ]
[ 442, 35 ]
python
en
['en', 'error', 'th']
False
force_escape
(value)
Escapes a string's HTML. This returns a new string containing the escaped characters (as opposed to "escape", which marks the content for later possible escaping).
Escapes a string's HTML. This returns a new string containing the escaped characters (as opposed to "escape", which marks the content for later possible escaping).
def force_escape(value): """ Escapes a string's HTML. This returns a new string containing the escaped characters (as opposed to "escape", which marks the content for later possible escaping). """ return escape(value)
[ "def", "force_escape", "(", "value", ")", ":", "return", "escape", "(", "value", ")" ]
[ 447, 0 ]
[ 453, 24 ]
python
en
['en', 'error', 'th']
False
linebreaks_filter
(value, autoescape=None)
Replaces line breaks in plain text with appropriate HTML; a single newline becomes an HTML line break (``<br />``) and a new line followed by a blank line becomes a paragraph break (``</p>``).
Replaces line breaks in plain text with appropriate HTML; a single newline becomes an HTML line break (``<br />``) and a new line followed by a blank line becomes a paragraph break (``</p>``).
def linebreaks_filter(value, autoescape=None): """ Replaces line breaks in plain text with appropriate HTML; a single newline becomes an HTML line break (``<br />``) and a new line followed by a blank line becomes a paragraph break (``</p>``). """ autoescape = autoescape and not isinstance(value...
[ "def", "linebreaks_filter", "(", "value", ",", "autoescape", "=", "None", ")", ":", "autoescape", "=", "autoescape", "and", "not", "isinstance", "(", "value", ",", "SafeData", ")", "return", "mark_safe", "(", "linebreaks", "(", "value", ",", "autoescape", ")...
[ 458, 0 ]
[ 465, 51 ]
python
en
['en', 'error', 'th']
False
linebreaksbr
(value, autoescape=None)
Converts all newlines in a piece of plain text to HTML line breaks (``<br />``).
Converts all newlines in a piece of plain text to HTML line breaks (``<br />``).
def linebreaksbr(value, autoescape=None): """ Converts all newlines in a piece of plain text to HTML line breaks (``<br />``). """ autoescape = autoescape and not isinstance(value, SafeData) value = normalize_newlines(value) if autoescape: value = escape(value) return mark_safe(v...
[ "def", "linebreaksbr", "(", "value", ",", "autoescape", "=", "None", ")", ":", "autoescape", "=", "autoescape", "and", "not", "isinstance", "(", "value", ",", "SafeData", ")", "value", "=", "normalize_newlines", "(", "value", ")", "if", "autoescape", ":", ...
[ 470, 0 ]
[ 479, 51 ]
python
en
['en', 'error', 'th']
False
safe
(value)
Marks the value as a string that should not be auto-escaped.
Marks the value as a string that should not be auto-escaped.
def safe(value): """ Marks the value as a string that should not be auto-escaped. """ return mark_safe(value)
[ "def", "safe", "(", "value", ")", ":", "return", "mark_safe", "(", "value", ")" ]
[ 484, 0 ]
[ 488, 27 ]
python
en
['en', 'error', 'th']
False
safeseq
(value)
A "safe" filter for sequences. Marks each element in the sequence, individually, as safe, after converting them to unicode. Returns a list with the results.
A "safe" filter for sequences. Marks each element in the sequence, individually, as safe, after converting them to unicode. Returns a list with the results.
def safeseq(value): """ A "safe" filter for sequences. Marks each element in the sequence, individually, as safe, after converting them to unicode. Returns a list with the results. """ return [mark_safe(force_text(obj)) for obj in value]
[ "def", "safeseq", "(", "value", ")", ":", "return", "[", "mark_safe", "(", "force_text", "(", "obj", ")", ")", "for", "obj", "in", "value", "]" ]
[ 492, 0 ]
[ 498, 56 ]
python
en
['en', 'error', 'th']
False
removetags
(value, tags)
Removes a space separated list of [X]HTML tags from the output.
Removes a space separated list of [X]HTML tags from the output.
def removetags(value, tags): """Removes a space separated list of [X]HTML tags from the output.""" return remove_tags(value, tags)
[ "def", "removetags", "(", "value", ",", "tags", ")", ":", "return", "remove_tags", "(", "value", ",", "tags", ")" ]
[ 503, 0 ]
[ 505, 35 ]
python
en
['en', 'en', 'en']
True
striptags
(value)
Strips all [X]HTML tags.
Strips all [X]HTML tags.
def striptags(value): """Strips all [X]HTML tags.""" return strip_tags(value)
[ "def", "striptags", "(", "value", ")", ":", "return", "strip_tags", "(", "value", ")" ]
[ 510, 0 ]
[ 512, 28 ]
python
en
['en', 'en', 'en']
True
dictsort
(value, arg)
Takes a list of dicts, returns that list sorted by the property given in the argument.
Takes a list of dicts, returns that list sorted by the property given in the argument.
def dictsort(value, arg): """ Takes a list of dicts, returns that list sorted by the property given in the argument. """ try: return sorted(value, key=Variable(arg).resolve) except (TypeError, VariableDoesNotExist): return ''
[ "def", "dictsort", "(", "value", ",", "arg", ")", ":", "try", ":", "return", "sorted", "(", "value", ",", "key", "=", "Variable", "(", "arg", ")", ".", "resolve", ")", "except", "(", "TypeError", ",", "VariableDoesNotExist", ")", ":", "return", "''" ]
[ 520, 0 ]
[ 528, 17 ]
python
en
['en', 'error', 'th']
False
dictsortreversed
(value, arg)
Takes a list of dicts, returns that list sorted in reverse order by the property given in the argument.
Takes a list of dicts, returns that list sorted in reverse order by the property given in the argument.
def dictsortreversed(value, arg): """ Takes a list of dicts, returns that list sorted in reverse order by the property given in the argument. """ try: return sorted(value, key=Variable(arg).resolve, reverse=True) except (TypeError, VariableDoesNotExist): return ''
[ "def", "dictsortreversed", "(", "value", ",", "arg", ")", ":", "try", ":", "return", "sorted", "(", "value", ",", "key", "=", "Variable", "(", "arg", ")", ".", "resolve", ",", "reverse", "=", "True", ")", "except", "(", "TypeError", ",", "VariableDoesN...
[ 532, 0 ]
[ 540, 17 ]
python
en
['en', 'error', 'th']
False
first
(value)
Returns the first item in a list.
Returns the first item in a list.
def first(value): """Returns the first item in a list.""" try: return value[0] except IndexError: return ''
[ "def", "first", "(", "value", ")", ":", "try", ":", "return", "value", "[", "0", "]", "except", "IndexError", ":", "return", "''" ]
[ 544, 0 ]
[ 549, 17 ]
python
en
['en', 'en', 'en']
True
join
(value, arg, autoescape=None)
Joins a list with a string, like Python's ``str.join(list)``.
Joins a list with a string, like Python's ``str.join(list)``.
def join(value, arg, autoescape=None): """ Joins a list with a string, like Python's ``str.join(list)``. """ value = map(force_text, value) if autoescape: value = [conditional_escape(v) for v in value] try: data = conditional_escape(arg).join(value) except AttributeError: # ...
[ "def", "join", "(", "value", ",", "arg", ",", "autoescape", "=", "None", ")", ":", "value", "=", "map", "(", "force_text", ",", "value", ")", "if", "autoescape", ":", "value", "=", "[", "conditional_escape", "(", "v", ")", "for", "v", "in", "value", ...
[ 553, 0 ]
[ 564, 26 ]
python
en
['en', 'error', 'th']
False
last
(value)
Returns the last item in a list
Returns the last item in a list
def last(value): "Returns the last item in a list" try: return value[-1] except IndexError: return ''
[ "def", "last", "(", "value", ")", ":", "try", ":", "return", "value", "[", "-", "1", "]", "except", "IndexError", ":", "return", "''" ]
[ 568, 0 ]
[ 573, 17 ]
python
en
['en', 'en', 'en']
True
length
(value)
Returns the length of the value - useful for lists.
Returns the length of the value - useful for lists.
def length(value): """Returns the length of the value - useful for lists.""" try: return len(value) except (ValueError, TypeError): return 0
[ "def", "length", "(", "value", ")", ":", "try", ":", "return", "len", "(", "value", ")", "except", "(", "ValueError", ",", "TypeError", ")", ":", "return", "0" ]
[ 577, 0 ]
[ 582, 16 ]
python
en
['en', 'en', 'en']
True
length_is
(value, arg)
Returns a boolean of whether the value's length is the argument.
Returns a boolean of whether the value's length is the argument.
def length_is(value, arg): """Returns a boolean of whether the value's length is the argument.""" try: return len(value) == int(arg) except (ValueError, TypeError): return ''
[ "def", "length_is", "(", "value", ",", "arg", ")", ":", "try", ":", "return", "len", "(", "value", ")", "==", "int", "(", "arg", ")", "except", "(", "ValueError", ",", "TypeError", ")", ":", "return", "''" ]
[ 586, 0 ]
[ 591, 17 ]
python
en
['en', 'en', 'en']
True
random
(value)
Returns a random item from the list.
Returns a random item from the list.
def random(value): """Returns a random item from the list.""" return random_module.choice(value)
[ "def", "random", "(", "value", ")", ":", "return", "random_module", ".", "choice", "(", "value", ")" ]
[ 595, 0 ]
[ 597, 38 ]
python
en
['en', 'en', 'en']
True
slice_filter
(value, arg)
Returns a slice of the list. Uses the same syntax as Python's list slicing; see http://www.diveintopython3.net/native-datatypes.html#slicinglists for an introduction.
Returns a slice of the list.
def slice_filter(value, arg): """ Returns a slice of the list. Uses the same syntax as Python's list slicing; see http://www.diveintopython3.net/native-datatypes.html#slicinglists for an introduction. """ try: bits = [] for x in arg.split(':'): if len(x) == 0: ...
[ "def", "slice_filter", "(", "value", ",", "arg", ")", ":", "try", ":", "bits", "=", "[", "]", "for", "x", "in", "arg", ".", "split", "(", "':'", ")", ":", "if", "len", "(", "x", ")", "==", "0", ":", "bits", ".", "append", "(", "None", ")", ...
[ 601, 0 ]
[ 619, 20 ]
python
en
['en', 'error', 'th']
False
unordered_list
(value, autoescape=None)
Recursively takes a self-nested list and returns an HTML unordered list -- WITHOUT opening and closing <ul> tags. The list is assumed to be in the proper format. For example, if ``var`` contains: ``['States', ['Kansas', ['Lawrence', 'Topeka'], 'Illinois']]``, then ``{{ var|unordered_list }}`` woul...
Recursively takes a self-nested list and returns an HTML unordered list -- WITHOUT opening and closing <ul> tags.
def unordered_list(value, autoescape=None): """ Recursively takes a self-nested list and returns an HTML unordered list -- WITHOUT opening and closing <ul> tags. The list is assumed to be in the proper format. For example, if ``var`` contains: ``['States', ['Kansas', ['Lawrence', 'Topeka'], 'Illino...
[ "def", "unordered_list", "(", "value", ",", "autoescape", "=", "None", ")", ":", "if", "autoescape", ":", "escaper", "=", "conditional_escape", "else", ":", "escaper", "=", "lambda", "x", ":", "x", "def", "convert_old_style_list", "(", "list_", ")", ":", "...
[ 623, 0 ]
[ 717, 43 ]
python
en
['en', 'error', 'th']
False
add
(value, arg)
Adds the arg to the value.
Adds the arg to the value.
def add(value, arg): """Adds the arg to the value.""" try: return int(value) + int(arg) except (ValueError, TypeError): try: return value + arg except Exception: return ''
[ "def", "add", "(", "value", ",", "arg", ")", ":", "try", ":", "return", "int", "(", "value", ")", "+", "int", "(", "arg", ")", "except", "(", "ValueError", ",", "TypeError", ")", ":", "try", ":", "return", "value", "+", "arg", "except", "Exception"...
[ 725, 0 ]
[ 733, 21 ]
python
en
['en', 'en', 'en']
True
get_digit
(value, arg)
Given a whole number, returns the requested digit of it, where 1 is the right-most digit, 2 is the second-right-most digit, etc. Returns the original value for invalid input (if input or argument is not an integer, or if argument is less than 1). Otherwise, output is always an integer.
Given a whole number, returns the requested digit of it, where 1 is the right-most digit, 2 is the second-right-most digit, etc. Returns the original value for invalid input (if input or argument is not an integer, or if argument is less than 1). Otherwise, output is always an integer.
def get_digit(value, arg): """ Given a whole number, returns the requested digit of it, where 1 is the right-most digit, 2 is the second-right-most digit, etc. Returns the original value for invalid input (if input or argument is not an integer, or if argument is less than 1). Otherwise, output is a...
[ "def", "get_digit", "(", "value", ",", "arg", ")", ":", "try", ":", "arg", "=", "int", "(", "arg", ")", "value", "=", "int", "(", "value", ")", "except", "ValueError", ":", "return", "value", "# Fail silently for an invalid argument", "if", "arg", "<", "...
[ 737, 0 ]
[ 754, 16 ]
python
en
['en', 'error', 'th']
False
date
(value, arg=None)
Formats a date according to the given format.
Formats a date according to the given format.
def date(value, arg=None): """Formats a date according to the given format.""" if value in (None, ''): return '' if arg is None: arg = settings.DATE_FORMAT try: return formats.date_format(value, arg) except AttributeError: try: return format(value, arg) ...
[ "def", "date", "(", "value", ",", "arg", "=", "None", ")", ":", "if", "value", "in", "(", "None", ",", "''", ")", ":", "return", "''", "if", "arg", "is", "None", ":", "arg", "=", "settings", ".", "DATE_FORMAT", "try", ":", "return", "formats", "....
[ 762, 0 ]
[ 774, 21 ]
python
en
['en', 'en', 'en']
True
time
(value, arg=None)
Formats a time according to the given format.
Formats a time according to the given format.
def time(value, arg=None): """Formats a time according to the given format.""" if value in (None, ''): return '' if arg is None: arg = settings.TIME_FORMAT try: return formats.time_format(value, arg) except AttributeError: try: return time_format(value, ar...
[ "def", "time", "(", "value", ",", "arg", "=", "None", ")", ":", "if", "value", "in", "(", "None", ",", "''", ")", ":", "return", "''", "if", "arg", "is", "None", ":", "arg", "=", "settings", ".", "TIME_FORMAT", "try", ":", "return", "formats", "....
[ 778, 0 ]
[ 790, 21 ]
python
en
['en', 'en', 'en']
True
timesince_filter
(value, arg=None)
Formats a date as the time since that date (i.e. "4 days, 6 hours").
Formats a date as the time since that date (i.e. "4 days, 6 hours").
def timesince_filter(value, arg=None): """Formats a date as the time since that date (i.e. "4 days, 6 hours").""" if not value: return '' try: if arg: return timesince(value, arg) return timesince(value) except (ValueError, TypeError): return ''
[ "def", "timesince_filter", "(", "value", ",", "arg", "=", "None", ")", ":", "if", "not", "value", ":", "return", "''", "try", ":", "if", "arg", ":", "return", "timesince", "(", "value", ",", "arg", ")", "return", "timesince", "(", "value", ")", "exce...
[ 794, 0 ]
[ 803, 17 ]
python
en
['en', 'en', 'en']
True
timeuntil_filter
(value, arg=None)
Formats a date as the time until that date (i.e. "4 days, 6 hours").
Formats a date as the time until that date (i.e. "4 days, 6 hours").
def timeuntil_filter(value, arg=None): """Formats a date as the time until that date (i.e. "4 days, 6 hours").""" if not value: return '' try: return timeuntil(value, arg) except (ValueError, TypeError): return ''
[ "def", "timeuntil_filter", "(", "value", ",", "arg", "=", "None", ")", ":", "if", "not", "value", ":", "return", "''", "try", ":", "return", "timeuntil", "(", "value", ",", "arg", ")", "except", "(", "ValueError", ",", "TypeError", ")", ":", "return", ...
[ 807, 0 ]
[ 814, 17 ]
python
en
['en', 'en', 'en']
True
default
(value, arg)
If value is unavailable, use given default.
If value is unavailable, use given default.
def default(value, arg): """If value is unavailable, use given default.""" return value or arg
[ "def", "default", "(", "value", ",", "arg", ")", ":", "return", "value", "or", "arg" ]
[ 822, 0 ]
[ 824, 23 ]
python
en
['en', 'en', 'en']
True
default_if_none
(value, arg)
If value is None, use given default.
If value is None, use given default.
def default_if_none(value, arg): """If value is None, use given default.""" if value is None: return arg return value
[ "def", "default_if_none", "(", "value", ",", "arg", ")", ":", "if", "value", "is", "None", ":", "return", "arg", "return", "value" ]
[ 828, 0 ]
[ 832, 16 ]
python
en
['en', 'en', 'en']
True
divisibleby
(value, arg)
Returns True if the value is devisible by the argument.
Returns True if the value is devisible by the argument.
def divisibleby(value, arg): """Returns True if the value is devisible by the argument.""" return int(value) % int(arg) == 0
[ "def", "divisibleby", "(", "value", ",", "arg", ")", ":", "return", "int", "(", "value", ")", "%", "int", "(", "arg", ")", "==", "0" ]
[ 836, 0 ]
[ 838, 37 ]
python
en
['en', 'en', 'en']
True
yesno
(value, arg=None)
Given a string mapping values for true, false and (optionally) None, returns one of those strings according to the value: ========== ====================== ================================== Value Argument Outputs ========== ====================== =========================...
Given a string mapping values for true, false and (optionally) None, returns one of those strings according to the value:
def yesno(value, arg=None): """ Given a string mapping values for true, false and (optionally) None, returns one of those strings according to the value: ========== ====================== ================================== Value Argument Outputs ========== ==============...
[ "def", "yesno", "(", "value", ",", "arg", "=", "None", ")", ":", "if", "arg", "is", "None", ":", "arg", "=", "ugettext", "(", "'yes,no,maybe'", ")", "bits", "=", "arg", ".", "split", "(", "','", ")", "if", "len", "(", "bits", ")", "<", "2", ":"...
[ 842, 0 ]
[ 871, 13 ]
python
en
['en', 'error', 'th']
False
filesizeformat
(bytes)
Formats the value like a 'human-readable' file size (i.e. 13 KB, 4.1 MB, 102 bytes, etc).
Formats the value like a 'human-readable' file size (i.e. 13 KB, 4.1 MB, 102 bytes, etc).
def filesizeformat(bytes): """ Formats the value like a 'human-readable' file size (i.e. 13 KB, 4.1 MB, 102 bytes, etc). """ try: bytes = float(bytes) except (TypeError, ValueError, UnicodeDecodeError): value = ungettext("%(size)d byte", "%(size)d bytes", 0) % {'size': 0} ...
[ "def", "filesizeformat", "(", "bytes", ")", ":", "try", ":", "bytes", "=", "float", "(", "bytes", ")", "except", "(", "TypeError", ",", "ValueError", ",", "UnicodeDecodeError", ")", ":", "value", "=", "ungettext", "(", "\"%(size)d byte\"", ",", "\"%(size)d b...
[ 879, 0 ]
[ 911, 32 ]
python
en
['en', 'error', 'th']
False
pluralize
(value, arg='s')
Returns a plural suffix if the value is not 1. By default, 's' is used as the suffix: * If value is 0, vote{{ value|pluralize }} displays "0 votes". * If value is 1, vote{{ value|pluralize }} displays "1 vote". * If value is 2, vote{{ value|pluralize }} displays "2 votes". If an argument is p...
Returns a plural suffix if the value is not 1. By default, 's' is used as the suffix:
def pluralize(value, arg='s'): """ Returns a plural suffix if the value is not 1. By default, 's' is used as the suffix: * If value is 0, vote{{ value|pluralize }} displays "0 votes". * If value is 1, vote{{ value|pluralize }} displays "1 vote". * If value is 2, vote{{ value|pluralize }} displa...
[ "def", "pluralize", "(", "value", ",", "arg", "=", "'s'", ")", ":", "if", "','", "not", "in", "arg", ":", "arg", "=", "','", "+", "arg", "bits", "=", "arg", ".", "split", "(", "','", ")", "if", "len", "(", "bits", ")", ">", "2", ":", "return"...
[ 915, 0 ]
[ 956, 26 ]
python
en
['en', 'error', 'th']
False
phone2numeric_filter
(value)
Takes a phone number and converts it in to its numerical equivalent.
Takes a phone number and converts it in to its numerical equivalent.
def phone2numeric_filter(value): """Takes a phone number and converts it in to its numerical equivalent.""" return phone2numeric(value)
[ "def", "phone2numeric_filter", "(", "value", ")", ":", "return", "phone2numeric", "(", "value", ")" ]
[ 960, 0 ]
[ 962, 31 ]
python
en
['en', 'en', 'en']
True
pprint
(value)
A wrapper around pprint.pprint -- for debugging, really.
A wrapper around pprint.pprint -- for debugging, really.
def pprint(value): """A wrapper around pprint.pprint -- for debugging, really.""" try: return pformat(value) except Exception as e: return "Error in formatting: %s: %s" % (e.__class__.__name__, force_text(e, errors="replace"))
[ "def", "pprint", "(", "value", ")", ":", "try", ":", "return", "pformat", "(", "value", ")", "except", "Exception", "as", "e", ":", "return", "\"Error in formatting: %s: %s\"", "%", "(", "e", ".", "__class__", ".", "__name__", ",", "force_text", "(", "e", ...
[ 966, 0 ]
[ 971, 102 ]
python
en
['en', 'en', 'en']
True
Color3DLUT.generate
(cls, size, callback, channels=3, target_mode=None)
Generates new LUT using provided callback. :param size: Size of the table. Passed to the constructor. :param callback: Function with three parameters which correspond three color channels. Will be called ``size**3`` times with values from 0.0 to 1.0 and...
Generates new LUT using provided callback.
def generate(cls, size, callback, channels=3, target_mode=None): """Generates new LUT using provided callback. :param size: Size of the table. Passed to the constructor. :param callback: Function with three parameters which correspond three color channels. Will be calle...
[ "def", "generate", "(", "cls", ",", "size", ",", "callback", ",", "channels", "=", "3", ",", "target_mode", "=", "None", ")", ":", "size1D", ",", "size2D", ",", "size3D", "=", "cls", ".", "_check_size", "(", "size", ")", "if", "channels", "not", "in"...
[ 426, 4 ]
[ 458, 9 ]
python
en
['en', 'zu', 'en']
True
Color3DLUT.transform
(self, callback, with_normals=False, channels=None, target_mode=None)
Transforms the table values using provided callback and returns a new LUT with altered values. :param callback: A function which takes old lookup table values and returns a new set of values. The number of arguments which function should take is ...
Transforms the table values using provided callback and returns a new LUT with altered values.
def transform(self, callback, with_normals=False, channels=None, target_mode=None): """Transforms the table values using provided callback and returns a new LUT with altered values. :param callback: A function which takes old lookup table values and returns a new set of...
[ "def", "transform", "(", "self", ",", "callback", ",", "with_normals", "=", "False", ",", "channels", "=", "None", ",", "target_mode", "=", "None", ")", ":", "if", "channels", "not", "in", "(", "None", ",", "3", ",", "4", ")", ":", "raise", "ValueErr...
[ 460, 4 ]
[ 511, 9 ]
python
en
['en', 'en', 'en']
True
ip_address
(address)
Take an IP string/int and return an object of the correct type. Args: address: A string or integer, the IP address. Either IPv4 or IPv6 addresses may be supplied; integers less than 2**32 will be considered to be IPv4 by default. Returns: An IPv4Address or IPv6Address obje...
Take an IP string/int and return an object of the correct type.
def ip_address(address): """Take an IP string/int and return an object of the correct type. Args: address: A string or integer, the IP address. Either IPv4 or IPv6 addresses may be supplied; integers less than 2**32 will be considered to be IPv4 by default. Returns: An...
[ "def", "ip_address", "(", "address", ")", ":", "try", ":", "return", "IPv4Address", "(", "address", ")", "except", "(", "AddressValueError", ",", "NetmaskValueError", ")", ":", "pass", "try", ":", "return", "IPv6Address", "(", "address", ")", "except", "(", ...
[ 134, 0 ]
[ 167, 29 ]
python
en
['en', 'en', 'en']
True
ip_network
(address, strict=True)
Take an IP string/int and return an object of the correct type. Args: address: A string or integer, the IP network. Either IPv4 or IPv6 networks may be supplied; integers less than 2**32 will be considered to be IPv4 by default. Returns: An IPv4Network or IPv6Network objec...
Take an IP string/int and return an object of the correct type.
def ip_network(address, strict=True): """Take an IP string/int and return an object of the correct type. Args: address: A string or integer, the IP network. Either IPv4 or IPv6 networks may be supplied; integers less than 2**32 will be considered to be IPv4 by default. Returns...
[ "def", "ip_network", "(", "address", ",", "strict", "=", "True", ")", ":", "try", ":", "return", "IPv4Network", "(", "address", ",", "strict", ")", "except", "(", "AddressValueError", ",", "NetmaskValueError", ")", ":", "pass", "try", ":", "return", "IPv6N...
[ 170, 0 ]
[ 203, 29 ]
python
en
['en', 'en', 'en']
True
ip_interface
(address)
Take an IP string/int and return an object of the correct type. Args: address: A string or integer, the IP address. Either IPv4 or IPv6 addresses may be supplied; integers less than 2**32 will be considered to be IPv4 by default. Returns: An IPv4Interface or IPv6Interface ...
Take an IP string/int and return an object of the correct type.
def ip_interface(address): """Take an IP string/int and return an object of the correct type. Args: address: A string or integer, the IP address. Either IPv4 or IPv6 addresses may be supplied; integers less than 2**32 will be considered to be IPv4 by default. Returns: ...
[ "def", "ip_interface", "(", "address", ")", ":", "try", ":", "return", "IPv4Interface", "(", "address", ")", "except", "(", "AddressValueError", ",", "NetmaskValueError", ")", ":", "pass", "try", ":", "return", "IPv6Interface", "(", "address", ")", "except", ...
[ 206, 0 ]
[ 238, 29 ]
python
en
['en', 'en', 'en']
True
v4_int_to_packed
(address)
Represent an address as 4 packed bytes in network (big-endian) order. Args: address: An integer representation of an IPv4 IP address. Returns: The integer address packed as 4 bytes in network (big-endian) order. Raises: ValueError: If the integer is negative or too large to be an ...
Represent an address as 4 packed bytes in network (big-endian) order.
def v4_int_to_packed(address): """Represent an address as 4 packed bytes in network (big-endian) order. Args: address: An integer representation of an IPv4 IP address. Returns: The integer address packed as 4 bytes in network (big-endian) order. Raises: ValueError: If the inte...
[ "def", "v4_int_to_packed", "(", "address", ")", ":", "try", ":", "return", "_compat_to_bytes", "(", "address", ",", "4", ",", "'big'", ")", "except", "(", "struct", ".", "error", ",", "OverflowError", ")", ":", "raise", "ValueError", "(", "\"Address negative...
[ 241, 0 ]
[ 258, 66 ]
python
en
['en', 'en', 'en']
True
v6_int_to_packed
(address)
Represent an address as 16 packed bytes in network (big-endian) order. Args: address: An integer representation of an IPv6 IP address. Returns: The integer address packed as 16 bytes in network (big-endian) order.
Represent an address as 16 packed bytes in network (big-endian) order.
def v6_int_to_packed(address): """Represent an address as 16 packed bytes in network (big-endian) order. Args: address: An integer representation of an IPv6 IP address. Returns: The integer address packed as 16 bytes in network (big-endian) order. """ try: return _compat_t...
[ "def", "v6_int_to_packed", "(", "address", ")", ":", "try", ":", "return", "_compat_to_bytes", "(", "address", ",", "16", ",", "'big'", ")", "except", "(", "struct", ".", "error", ",", "OverflowError", ")", ":", "raise", "ValueError", "(", "\"Address negativ...
[ 261, 0 ]
[ 274, 66 ]
python
en
['en', 'en', 'en']
True
_split_optional_netmask
(address)
Helper to split the netmask and raise AddressValueError if needed
Helper to split the netmask and raise AddressValueError if needed
def _split_optional_netmask(address): """Helper to split the netmask and raise AddressValueError if needed""" addr = _compat_str(address).split('/') if len(addr) > 2: raise AddressValueError("Only one '/' permitted in %r" % address) return addr
[ "def", "_split_optional_netmask", "(", "address", ")", ":", "addr", "=", "_compat_str", "(", "address", ")", ".", "split", "(", "'/'", ")", "if", "len", "(", "addr", ")", ">", "2", ":", "raise", "AddressValueError", "(", "\"Only one '/' permitted in %r\"", "...
[ 277, 0 ]
[ 282, 15 ]
python
en
['en', 'fi', 'en']
True
_find_address_range
(addresses)
Find a sequence of sorted deduplicated IPv#Address. Args: addresses: a list of IPv#Address objects. Yields: A tuple containing the first and last IP addresses in the sequence.
Find a sequence of sorted deduplicated IPv#Address.
def _find_address_range(addresses): """Find a sequence of sorted deduplicated IPv#Address. Args: addresses: a list of IPv#Address objects. Yields: A tuple containing the first and last IP addresses in the sequence. """ it = iter(addresses) first = last = next(it) for ip in...
[ "def", "_find_address_range", "(", "addresses", ")", ":", "it", "=", "iter", "(", "addresses", ")", "first", "=", "last", "=", "next", "(", "it", ")", "for", "ip", "in", "it", ":", "if", "ip", ".", "_ip", "!=", "last", ".", "_ip", "+", "1", ":", ...
[ 285, 0 ]
[ 302, 21 ]
python
en
['en', 'en', 'en']
True
_count_righthand_zero_bits
(number, bits)
Count the number of zero bits on the right hand side. Args: number: an integer. bits: maximum number of bits to count. Returns: The number of zero bits on the right hand side of the number.
Count the number of zero bits on the right hand side.
def _count_righthand_zero_bits(number, bits): """Count the number of zero bits on the right hand side. Args: number: an integer. bits: maximum number of bits to count. Returns: The number of zero bits on the right hand side of the number. """ if number == 0: return...
[ "def", "_count_righthand_zero_bits", "(", "number", ",", "bits", ")", ":", "if", "number", "==", "0", ":", "return", "bits", "return", "min", "(", "bits", ",", "_compat_bit_length", "(", "~", "number", "&", "(", "number", "-", "1", ")", ")", ")" ]
[ 305, 0 ]
[ 318, 64 ]
python
en
['en', 'en', 'en']
True
summarize_address_range
(first, last)
Summarize a network range given the first and last IP addresses. Example: >>> list(summarize_address_range(IPv4Address('192.0.2.0'), ... IPv4Address('192.0.2.130'))) ... #doctest: +NORMALIZE_WHITESPACE [IPv4Network('192.0.2...
Summarize a network range given the first and last IP addresses.
def summarize_address_range(first, last): """Summarize a network range given the first and last IP addresses. Example: >>> list(summarize_address_range(IPv4Address('192.0.2.0'), ... IPv4Address('192.0.2.130'))) ... #doctest: +N...
[ "def", "summarize_address_range", "(", "first", ",", "last", ")", ":", "if", "(", "not", "(", "isinstance", "(", "first", ",", "_BaseAddress", ")", "and", "isinstance", "(", "last", ",", "_BaseAddress", ")", ")", ")", ":", "raise", "TypeError", "(", "'fi...
[ 321, 0 ]
[ 373, 17 ]
python
en
['en', 'en', 'en']
True
_collapse_addresses_internal
(addresses)
Loops through the addresses, collapsing concurrent netblocks. Example: ip1 = IPv4Network('192.0.2.0/26') ip2 = IPv4Network('192.0.2.64/26') ip3 = IPv4Network('192.0.2.128/26') ip4 = IPv4Network('192.0.2.192/26') _collapse_addresses_internal([ip1, ip2, ip3, ip4]) -> ...
Loops through the addresses, collapsing concurrent netblocks.
def _collapse_addresses_internal(addresses): """Loops through the addresses, collapsing concurrent netblocks. Example: ip1 = IPv4Network('192.0.2.0/26') ip2 = IPv4Network('192.0.2.64/26') ip3 = IPv4Network('192.0.2.128/26') ip4 = IPv4Network('192.0.2.192/26') _collapse...
[ "def", "_collapse_addresses_internal", "(", "addresses", ")", ":", "# First merge", "to_merge", "=", "list", "(", "addresses", ")", "subnets", "=", "{", "}", "while", "to_merge", ":", "net", "=", "to_merge", ".", "pop", "(", ")", "supernet", "=", "net", "....
[ 376, 0 ]
[ 422, 18 ]
python
en
['en', 'en', 'en']
True
collapse_addresses
(addresses)
Collapse a list of IP objects. Example: collapse_addresses([IPv4Network('192.0.2.0/25'), IPv4Network('192.0.2.128/25')]) -> [IPv4Network('192.0.2.0/24')] Args: addresses: An iterator of IPv4Network or IPv6Network objects. Returns: ...
Collapse a list of IP objects.
def collapse_addresses(addresses): """Collapse a list of IP objects. Example: collapse_addresses([IPv4Network('192.0.2.0/25'), IPv4Network('192.0.2.128/25')]) -> [IPv4Network('192.0.2.0/24')] Args: addresses: An iterator of IPv4Network...
[ "def", "collapse_addresses", "(", "addresses", ")", ":", "addrs", "=", "[", "]", "ips", "=", "[", "]", "nets", "=", "[", "]", "# split IP addresses and networks", "for", "ip", "in", "addresses", ":", "if", "isinstance", "(", "ip", ",", "_BaseAddress", ")",...
[ 425, 0 ]
[ 476, 53 ]
python
en
['en', 'en', 'en']
True
get_mixed_type_key
(obj)
Return a key suitable for sorting between networks and addresses. Address and Network objects are not sortable by default; they're fundamentally different so the expression IPv4Address('192.0.2.0') <= IPv4Network('192.0.2.0/24') doesn't make any sense. There are some times however, where you may...
Return a key suitable for sorting between networks and addresses.
def get_mixed_type_key(obj): """Return a key suitable for sorting between networks and addresses. Address and Network objects are not sortable by default; they're fundamentally different so the expression IPv4Address('192.0.2.0') <= IPv4Network('192.0.2.0/24') doesn't make any sense. There a...
[ "def", "get_mixed_type_key", "(", "obj", ")", ":", "if", "isinstance", "(", "obj", ",", "_BaseNetwork", ")", ":", "return", "obj", ".", "_get_networks_key", "(", ")", "elif", "isinstance", "(", "obj", ",", "_BaseAddress", ")", ":", "return", "obj", ".", ...
[ 479, 0 ]
[ 501, 25 ]
python
en
['en', 'en', 'en']
True
_IPAddressBase.exploded
(self)
Return the longhand version of the IP address as a string.
Return the longhand version of the IP address as a string.
def exploded(self): """Return the longhand version of the IP address as a string.""" return self._explode_shorthand_ip_string()
[ "def", "exploded", "(", "self", ")", ":", "return", "self", ".", "_explode_shorthand_ip_string", "(", ")" ]
[ 511, 4 ]
[ 513, 50 ]
python
en
['en', 'en', 'en']
True
_IPAddressBase.compressed
(self)
Return the shorthand version of the IP address as a string.
Return the shorthand version of the IP address as a string.
def compressed(self): """Return the shorthand version of the IP address as a string.""" return _compat_str(self)
[ "def", "compressed", "(", "self", ")", ":", "return", "_compat_str", "(", "self", ")" ]
[ 516, 4 ]
[ 518, 32 ]
python
en
['en', 'en', 'en']
True
_IPAddressBase.reverse_pointer
(self)
The name of the reverse DNS pointer for the IP address, e.g.: >>> ipaddress.ip_address("127.0.0.1").reverse_pointer '1.0.0.127.in-addr.arpa' >>> ipaddress.ip_address("2001:db8::1").reverse_pointer '1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.8.b.d.0.1.0.0.2.ip6.arpa' ...
The name of the reverse DNS pointer for the IP address, e.g.: >>> ipaddress.ip_address("127.0.0.1").reverse_pointer '1.0.0.127.in-addr.arpa' >>> ipaddress.ip_address("2001:db8::1").reverse_pointer '1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.8.b.d.0.1.0.0.2.ip6.arpa'
def reverse_pointer(self): """The name of the reverse DNS pointer for the IP address, e.g.: >>> ipaddress.ip_address("127.0.0.1").reverse_pointer '1.0.0.127.in-addr.arpa' >>> ipaddress.ip_address("2001:db8::1").reverse_pointer '1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0....
[ "def", "reverse_pointer", "(", "self", ")", ":", "return", "self", ".", "_reverse_pointer", "(", ")" ]
[ 521, 4 ]
[ 529, 38 ]
python
en
['en', 'en', 'en']
True
_IPAddressBase._ip_int_from_prefix
(cls, prefixlen)
Turn the prefix length into a bitwise netmask Args: prefixlen: An integer, the prefix length. Returns: An integer.
Turn the prefix length into a bitwise netmask
def _ip_int_from_prefix(cls, prefixlen): """Turn the prefix length into a bitwise netmask Args: prefixlen: An integer, the prefix length. Returns: An integer. """ return cls._ALL_ONES ^ (cls._ALL_ONES >> prefixlen)
[ "def", "_ip_int_from_prefix", "(", "cls", ",", "prefixlen", ")", ":", "return", "cls", ".", "_ALL_ONES", "^", "(", "cls", ".", "_ALL_ONES", ">>", "prefixlen", ")" ]
[ 556, 4 ]
[ 566, 59 ]
python
en
['en', 'haw', 'en']
True
_IPAddressBase._prefix_from_ip_int
(cls, ip_int)
Return prefix length from the bitwise netmask. Args: ip_int: An integer, the netmask in expanded bitwise format Returns: An integer, the prefix length. Raises: ValueError: If the input intermingles zeroes & ones
Return prefix length from the bitwise netmask.
def _prefix_from_ip_int(cls, ip_int): """Return prefix length from the bitwise netmask. Args: ip_int: An integer, the netmask in expanded bitwise format Returns: An integer, the prefix length. Raises: ValueError: If the input intermingles zeroes & o...
[ "def", "_prefix_from_ip_int", "(", "cls", ",", "ip_int", ")", ":", "trailing_zeroes", "=", "_count_righthand_zero_bits", "(", "ip_int", ",", "cls", ".", "_max_prefixlen", ")", "prefixlen", "=", "cls", ".", "_max_prefixlen", "-", "trailing_zeroes", "leading_ones", ...
[ 569, 4 ]
[ 591, 24 ]
python
en
['en', 'en', 'en']
True
_IPAddressBase._prefix_from_prefix_string
(cls, prefixlen_str)
Return prefix length from a numeric string Args: prefixlen_str: The string to be converted Returns: An integer, the prefix length. Raises: NetmaskValueError: If the input is not a valid netmask
Return prefix length from a numeric string
def _prefix_from_prefix_string(cls, prefixlen_str): """Return prefix length from a numeric string Args: prefixlen_str: The string to be converted Returns: An integer, the prefix length. Raises: NetmaskValueError: If the input is not a valid netmask ...
[ "def", "_prefix_from_prefix_string", "(", "cls", ",", "prefixlen_str", ")", ":", "# int allows a leading +/- as well as surrounding whitespace,", "# so we ensure that isn't the case", "if", "not", "_BaseV4", ".", "_DECIMAL_DIGITS", ".", "issuperset", "(", "prefixlen_str", ")", ...
[ 599, 4 ]
[ 621, 24 ]
python
en
['en', 'en', 'en']
True
_IPAddressBase._prefix_from_ip_string
(cls, ip_str)
Turn a netmask/hostmask string into a prefix length Args: ip_str: The netmask/hostmask to be converted Returns: An integer, the prefix length. Raises: NetmaskValueError: If the input is not a valid netmask/hostmask
Turn a netmask/hostmask string into a prefix length
def _prefix_from_ip_string(cls, ip_str): """Turn a netmask/hostmask string into a prefix length Args: ip_str: The netmask/hostmask to be converted Returns: An integer, the prefix length. Raises: NetmaskValueError: If the input is not a valid netmask...
[ "def", "_prefix_from_ip_string", "(", "cls", ",", "ip_str", ")", ":", "# Parse the netmask/hostmask like an IP address.", "try", ":", "ip_int", "=", "cls", ".", "_ip_int_from_string", "(", "ip_str", ")", "except", "AddressValueError", ":", "cls", ".", "_report_invalid...
[ 624, 4 ]
[ 655, 47 ]
python
en
['en', 'haw', 'en']
True
_BaseNetwork.hosts
(self)
Generate Iterator over usable hosts in a network. This is like __iter__ except it doesn't return the network or broadcast addresses.
Generate Iterator over usable hosts in a network.
def hosts(self): """Generate Iterator over usable hosts in a network. This is like __iter__ except it doesn't return the network or broadcast addresses. """ network = int(self.network_address) broadcast = int(self.broadcast_address) for x in _compat_range(networ...
[ "def", "hosts", "(", "self", ")", ":", "network", "=", "int", "(", "self", ".", "network_address", ")", "broadcast", "=", "int", "(", "self", ".", "broadcast_address", ")", "for", "x", "in", "_compat_range", "(", "network", "+", "1", ",", "broadcast", ...
[ 739, 4 ]
[ 749, 40 ]
python
en
['en', 'en', 'en']
True
_BaseNetwork.overlaps
(self, other)
Tell if self is partly contained in other.
Tell if self is partly contained in other.
def overlaps(self, other): """Tell if self is partly contained in other.""" return self.network_address in other or ( self.broadcast_address in other or ( other.network_address in self or ( other.broadcast_address in self)))
[ "def", "overlaps", "(", "self", ",", "other", ")", ":", "return", "self", ".", "network_address", "in", "other", "or", "(", "self", ".", "broadcast_address", "in", "other", "or", "(", "other", ".", "network_address", "in", "self", "or", "(", "other", "."...
[ 809, 4 ]
[ 814, 54 ]
python
en
['en', 'en', 'en']
True