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
direct_url_as_pep440_direct_reference
(direct_url: DirectUrl, name: str)
Convert a DirectUrl to a pip requirement string.
Convert a DirectUrl to a pip requirement string.
def direct_url_as_pep440_direct_reference(direct_url: DirectUrl, name: str) -> str: """Convert a DirectUrl to a pip requirement string.""" direct_url.validate() # if invalid, this is a pip bug requirement = name + " @ " fragments = [] if isinstance(direct_url.info, VcsInfo): requirement += ...
[ "def", "direct_url_as_pep440_direct_reference", "(", "direct_url", ":", "DirectUrl", ",", "name", ":", "str", ")", "->", "str", ":", "direct_url", ".", "validate", "(", ")", "# if invalid, this is a pip bug", "requirement", "=", "name", "+", "\" @ \"", "fragments", ...
[ 7, 0 ]
[ 27, 22 ]
python
en
['en', 'en', 'en']
True
colorize
(text='', opts=(), **kwargs)
Return your text, enclosed in ANSI graphics codes. Depends on the keyword arguments 'fg' and 'bg', and the contents of the opts tuple/list. Return the RESET code if no parameters are given. Valid colors: 'black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white' Valid opt...
Return your text, enclosed in ANSI graphics codes.
def colorize(text='', opts=(), **kwargs): """ Return your text, enclosed in ANSI graphics codes. Depends on the keyword arguments 'fg' and 'bg', and the contents of the opts tuple/list. Return the RESET code if no parameters are given. Valid colors: 'black', 'red', 'green', 'yellow', ...
[ "def", "colorize", "(", "text", "=", "''", ",", "opts", "=", "(", ")", ",", "*", "*", "kwargs", ")", ":", "code_list", "=", "[", "]", "if", "text", "==", "''", "and", "len", "(", "opts", ")", "==", "1", "and", "opts", "[", "0", "]", "==", "...
[ 12, 0 ]
[ 54, 68 ]
python
en
['en', 'error', 'th']
False
make_style
(opts=(), **kwargs)
Return a function with default parameters for colorize() Example: bold_red = make_style(opts=('bold',), fg='red') print(bold_red('hello')) KEYWORD = make_style(fg='yellow') COMMENT = make_style(fg='blue', opts=('bold',))
Return a function with default parameters for colorize()
def make_style(opts=(), **kwargs): """ Return a function with default parameters for colorize() Example: bold_red = make_style(opts=('bold',), fg='red') print(bold_red('hello')) KEYWORD = make_style(fg='yellow') COMMENT = make_style(fg='blue', opts=('bold',)) """ ret...
[ "def", "make_style", "(", "opts", "=", "(", ")", ",", "*", "*", "kwargs", ")", ":", "return", "lambda", "text", ":", "colorize", "(", "text", ",", "opts", ",", "*", "*", "kwargs", ")" ]
[ 57, 0 ]
[ 67, 54 ]
python
en
['en', 'error', 'th']
False
parse_color_setting
(config_string)
Parse a DJANGO_COLORS environment variable to produce the system palette The general form of a palette definition is: "palette;role=fg;role=fg/bg;role=fg,option,option;role=fg/bg,option,option" where: palette is a named palette; one of 'light', 'dark', or 'nocolor'. role is a named st...
Parse a DJANGO_COLORS environment variable to produce the system palette
def parse_color_setting(config_string): """Parse a DJANGO_COLORS environment variable to produce the system palette The general form of a palette definition is: "palette;role=fg;role=fg/bg;role=fg,option,option;role=fg/bg,option,option" where: palette is a named palette; one of 'light', '...
[ "def", "parse_color_setting", "(", "config_string", ")", ":", "if", "not", "config_string", ":", "return", "PALETTES", "[", "DEFAULT_PALETTE", "]", "# Split the color configuration into parts", "parts", "=", "config_string", ".", "lower", "(", ")", ".", "split", "("...
[ 136, 0 ]
[ 214, 18 ]
python
en
['en', 'en', 'en']
True
safe_range
(*args)
A range that can't generate ranges with a length of more than MAX_RANGE items.
A range that can't generate ranges with a length of more than MAX_RANGE items.
def safe_range(*args): """A range that can't generate ranges with a length of more than MAX_RANGE items. """ rng = range_type(*args) if len(rng) > MAX_RANGE: raise OverflowError( "Range too big. The sandbox blocks ranges larger than" " MAX_RANGE (%d)." % MAX_RANGE ...
[ "def", "safe_range", "(", "*", "args", ")", ":", "rng", "=", "range_type", "(", "*", "args", ")", "if", "len", "(", "rng", ")", ">", "MAX_RANGE", ":", "raise", "OverflowError", "(", "\"Range too big. The sandbox blocks ranges larger than\"", "\" MAX_RANGE (%d).\""...
[ 144, 0 ]
[ 156, 14 ]
python
en
['en', 'en', 'en']
True
unsafe
(f)
Marks a function or method as unsafe. :: @unsafe def delete(self): pass
Marks a function or method as unsafe.
def unsafe(f): """Marks a function or method as unsafe. :: @unsafe def delete(self): pass """ f.unsafe_callable = True return f
[ "def", "unsafe", "(", "f", ")", ":", "f", ".", "unsafe_callable", "=", "True", "return", "f" ]
[ 159, 0 ]
[ 169, 12 ]
python
en
['en', 'en', 'en']
True
is_internal_attribute
(obj, attr)
Test if the attribute given is an internal python attribute. For example this function returns `True` for the `func_code` attribute of python objects. This is useful if the environment method :meth:`~SandboxedEnvironment.is_safe_attribute` is overridden. >>> from jinja2.sandbox import is_internal_att...
Test if the attribute given is an internal python attribute. For example this function returns `True` for the `func_code` attribute of python objects. This is useful if the environment method :meth:`~SandboxedEnvironment.is_safe_attribute` is overridden.
def is_internal_attribute(obj, attr): """Test if the attribute given is an internal python attribute. For example this function returns `True` for the `func_code` attribute of python objects. This is useful if the environment method :meth:`~SandboxedEnvironment.is_safe_attribute` is overridden. >...
[ "def", "is_internal_attribute", "(", "obj", ",", "attr", ")", ":", "if", "isinstance", "(", "obj", ",", "types", ".", "FunctionType", ")", ":", "if", "attr", "in", "UNSAFE_FUNCTION_ATTRIBUTES", ":", "return", "True", "elif", "isinstance", "(", "obj", ",", ...
[ 172, 0 ]
[ 205, 32 ]
python
en
['en', 'en', 'en']
True
modifies_known_mutable
(obj, attr)
This function checks if an attribute on a builtin mutable object (list, dict, set or deque) would modify it if called. It also supports the "user"-versions of the objects (`sets.Set`, `UserDict.*` etc.) and with Python 2.6 onwards the abstract base classes `MutableSet`, `MutableMapping`, and `MutableSe...
This function checks if an attribute on a builtin mutable object (list, dict, set or deque) would modify it if called. It also supports the "user"-versions of the objects (`sets.Set`, `UserDict.*` etc.) and with Python 2.6 onwards the abstract base classes `MutableSet`, `MutableMapping`, and `MutableSe...
def modifies_known_mutable(obj, attr): """This function checks if an attribute on a builtin mutable object (list, dict, set or deque) would modify it if called. It also supports the "user"-versions of the objects (`sets.Set`, `UserDict.*` etc.) and with Python 2.6 onwards the abstract base classes `Mut...
[ "def", "modifies_known_mutable", "(", "obj", ",", "attr", ")", ":", "for", "typespec", ",", "unsafe", "in", "_mutable_spec", ":", "if", "isinstance", "(", "obj", ",", "typespec", ")", ":", "return", "attr", "in", "unsafe", "return", "False" ]
[ 208, 0 ]
[ 233, 16 ]
python
en
['en', 'en', 'en']
True
SandboxedEnvironment.intercept_unop
(self, operator)
Called during template compilation with the name of a unary operator to check if it should be intercepted at runtime. If this method returns `True`, :meth:`call_unop` is excuted for this unary operator. The default implementation of :meth:`call_unop` will use the :attr:`unop_table` dic...
Called during template compilation with the name of a unary operator to check if it should be intercepted at runtime. If this method returns `True`, :meth:`call_unop` is excuted for this unary operator. The default implementation of :meth:`call_unop` will use the :attr:`unop_table` dic...
def intercept_unop(self, operator): """Called during template compilation with the name of a unary operator to check if it should be intercepted at runtime. If this method returns `True`, :meth:`call_unop` is excuted for this unary operator. The default implementation of :meth:`call_un...
[ "def", "intercept_unop", "(", "self", ",", "operator", ")", ":", "return", "False" ]
[ 300, 4 ]
[ 315, 20 ]
python
en
['en', 'en', 'en']
True
SandboxedEnvironment.is_safe_attribute
(self, obj, attr, value)
The sandboxed environment will call this method to check if the attribute of an object is safe to access. Per default all attributes starting with an underscore are considered private as well as the special attributes of internal python objects as returned by the :func:`is_internal_attr...
The sandboxed environment will call this method to check if the attribute of an object is safe to access. Per default all attributes starting with an underscore are considered private as well as the special attributes of internal python objects as returned by the :func:`is_internal_attr...
def is_safe_attribute(self, obj, attr, value): """The sandboxed environment will call this method to check if the attribute of an object is safe to access. Per default all attributes starting with an underscore are considered private as well as the special attributes of internal python ...
[ "def", "is_safe_attribute", "(", "self", ",", "obj", ",", "attr", ",", "value", ")", ":", "return", "not", "(", "attr", ".", "startswith", "(", "'_'", ")", "or", "is_internal_attribute", "(", "obj", ",", "attr", ")", ")" ]
[ 324, 4 ]
[ 331, 77 ]
python
en
['en', 'en', 'en']
True
SandboxedEnvironment.is_safe_callable
(self, obj)
Check if an object is safely callable. Per default a function is considered safe unless the `unsafe_callable` attribute exists and is True. Override this method to alter the behavior, but this won't affect the `unsafe` decorator from this module.
Check if an object is safely callable. Per default a function is considered safe unless the `unsafe_callable` attribute exists and is True. Override this method to alter the behavior, but this won't affect the `unsafe` decorator from this module.
def is_safe_callable(self, obj): """Check if an object is safely callable. Per default a function is considered safe unless the `unsafe_callable` attribute exists and is True. Override this method to alter the behavior, but this won't affect the `unsafe` decorator from this module. ...
[ "def", "is_safe_callable", "(", "self", ",", "obj", ")", ":", "return", "not", "(", "getattr", "(", "obj", ",", "'unsafe_callable'", ",", "False", ")", "or", "getattr", "(", "obj", ",", "'alters_data'", ",", "False", ")", ")" ]
[ 333, 4 ]
[ 340, 55 ]
python
en
['en', 'en', 'en']
True
SandboxedEnvironment.call_binop
(self, context, operator, left, right)
For intercepted binary operator calls (:meth:`intercepted_binops`) this function is executed instead of the builtin operator. This can be used to fine tune the behavior of certain operators. .. versionadded:: 2.6
For intercepted binary operator calls (:meth:`intercepted_binops`) this function is executed instead of the builtin operator. This can be used to fine tune the behavior of certain operators.
def call_binop(self, context, operator, left, right): """For intercepted binary operator calls (:meth:`intercepted_binops`) this function is executed instead of the builtin operator. This can be used to fine tune the behavior of certain operators. .. versionadded:: 2.6 """ ...
[ "def", "call_binop", "(", "self", ",", "context", ",", "operator", ",", "left", ",", "right", ")", ":", "return", "self", ".", "binop_table", "[", "operator", "]", "(", "left", ",", "right", ")" ]
[ 342, 4 ]
[ 349, 54 ]
python
en
['en', 'ig', 'en']
True
SandboxedEnvironment.call_unop
(self, context, operator, arg)
For intercepted unary operator calls (:meth:`intercepted_unops`) this function is executed instead of the builtin operator. This can be used to fine tune the behavior of certain operators. .. versionadded:: 2.6
For intercepted unary operator calls (:meth:`intercepted_unops`) this function is executed instead of the builtin operator. This can be used to fine tune the behavior of certain operators.
def call_unop(self, context, operator, arg): """For intercepted unary operator calls (:meth:`intercepted_unops`) this function is executed instead of the builtin operator. This can be used to fine tune the behavior of certain operators. .. versionadded:: 2.6 """ return ...
[ "def", "call_unop", "(", "self", ",", "context", ",", "operator", ",", "arg", ")", ":", "return", "self", ".", "unop_table", "[", "operator", "]", "(", "arg", ")" ]
[ 351, 4 ]
[ 358, 45 ]
python
en
['en', 'en', 'it']
True
SandboxedEnvironment.getitem
(self, obj, argument)
Subscribe an object from sandboxed code.
Subscribe an object from sandboxed code.
def getitem(self, obj, argument): """Subscribe an object from sandboxed code.""" try: return obj[argument] except (TypeError, LookupError): if isinstance(argument, string_types): try: attr = str(argument) except Exceptio...
[ "def", "getitem", "(", "self", ",", "obj", ",", "argument", ")", ":", "try", ":", "return", "obj", "[", "argument", "]", "except", "(", "TypeError", ",", "LookupError", ")", ":", "if", "isinstance", "(", "argument", ",", "string_types", ")", ":", "try"...
[ 360, 4 ]
[ 379, 53 ]
python
en
['en', 'en', 'en']
True
SandboxedEnvironment.getattr
(self, obj, attribute)
Subscribe an object from sandboxed code and prefer the attribute. The attribute passed *must* be a bytestring.
Subscribe an object from sandboxed code and prefer the attribute. The attribute passed *must* be a bytestring.
def getattr(self, obj, attribute): """Subscribe an object from sandboxed code and prefer the attribute. The attribute passed *must* be a bytestring. """ try: value = getattr(obj, attribute) except AttributeError: try: return obj[attribute]...
[ "def", "getattr", "(", "self", ",", "obj", ",", "attribute", ")", ":", "try", ":", "value", "=", "getattr", "(", "obj", ",", "attribute", ")", "except", "AttributeError", ":", "try", ":", "return", "obj", "[", "attribute", "]", "except", "(", "TypeErro...
[ 381, 4 ]
[ 396, 54 ]
python
en
['en', 'en', 'en']
True
SandboxedEnvironment.unsafe_undefined
(self, obj, attribute)
Return an undefined object for unsafe attributes.
Return an undefined object for unsafe attributes.
def unsafe_undefined(self, obj, attribute): """Return an undefined object for unsafe attributes.""" return self.undefined('access to attribute %r of %r ' 'object is unsafe.' % ( attribute, obj.__class__.__name__ ), name=attribute, obj=obj, ex...
[ "def", "unsafe_undefined", "(", "self", ",", "obj", ",", "attribute", ")", ":", "return", "self", ".", "undefined", "(", "'access to attribute %r of %r '", "'object is unsafe.'", "%", "(", "attribute", ",", "obj", ".", "__class__", ".", "__name__", ")", ",", "...
[ 398, 4 ]
[ 404, 54 ]
python
en
['en', 'en', 'en']
True
SandboxedEnvironment.format_string
(self, s, args, kwargs, format_func=None)
If a format call is detected, then this is routed through this method so that our safety sandbox can be used for it.
If a format call is detected, then this is routed through this method so that our safety sandbox can be used for it.
def format_string(self, s, args, kwargs, format_func=None): """If a format call is detected, then this is routed through this method so that our safety sandbox can be used for it. """ if isinstance(s, Markup): formatter = SandboxedEscapeFormatter(self, s.escape) else:...
[ "def", "format_string", "(", "self", ",", "s", ",", "args", ",", "kwargs", ",", "format_func", "=", "None", ")", ":", "if", "isinstance", "(", "s", ",", "Markup", ")", ":", "formatter", "=", "SandboxedEscapeFormatter", "(", "self", ",", "s", ".", "esca...
[ 406, 4 ]
[ 427, 26 ]
python
en
['en', 'en', 'en']
True
SandboxedEnvironment.call
(__self, __context, __obj, *args, **kwargs)
Call an object from sandboxed code.
Call an object from sandboxed code.
def call(__self, __context, __obj, *args, **kwargs): """Call an object from sandboxed code.""" fmt = inspect_format_method(__obj) if fmt is not None: return __self.format_string(fmt, args, kwargs, __obj) # the double prefixes are to avoid double keyword argument # er...
[ "def", "call", "(", "__self", ",", "__context", ",", "__obj", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "fmt", "=", "inspect_format_method", "(", "__obj", ")", "if", "fmt", "is", "not", "None", ":", "return", "__self", ".", "format_string", ...
[ 429, 4 ]
[ 439, 53 ]
python
en
['en', 'en', 'en']
True
get_admin_log
(parser, token)
Populate 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 %} ...
Populate a template variable with the admin log for the given criteria.
def get_admin_log(parser, token): """ Populate 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_lo...
[ "def", "get_admin_log", "(", "parser", ",", "token", ")", ":", "tokens", "=", "token", ".", "contents", ".", "split", "(", ")", "if", "len", "(", "tokens", ")", "<", "4", ":", "raise", "template", ".", "TemplateSyntaxError", "(", "\"'get_admin_log' stateme...
[ 26, 0 ]
[ 58, 106 ]
python
en
['en', 'error', 'th']
False
BaseExpression.as_sql
(self, compiler, connection)
Responsible for returning a (sql, [params]) tuple to be included in the current query. Different backends can provide their own implementation, by providing an `as_{vendor}` method and patching the Expression: ``` def override_as_sql(self, compiler, connection): ...
Responsible for returning a (sql, [params]) tuple to be included in the current query.
def as_sql(self, compiler, connection): """ Responsible for returning a (sql, [params]) tuple to be included in the current query. Different backends can provide their own implementation, by providing an `as_{vendor}` method and patching the Expression: ``` def ...
[ "def", "as_sql", "(", "self", ",", "compiler", ",", "connection", ")", ":", "raise", "NotImplementedError", "(", "\"Subclasses must implement as_sql()\"", ")" ]
[ 189, 4 ]
[ 215, 71 ]
python
en
['en', 'error', 'th']
False
BaseExpression.resolve_expression
(self, query=None, allow_joins=True, reuse=None, summarize=False, for_save=False)
Provide the chance to do any preprocessing or validation before being added to the query. Arguments: * query: the backend query implementation * allow_joins: boolean allowing or denying use of joins in this query * reuse: a set of reusable joins for multij...
Provide the chance to do any preprocessing or validation before being added to the query.
def resolve_expression(self, query=None, allow_joins=True, reuse=None, summarize=False, for_save=False): """ Provide the chance to do any preprocessing or validation before being added to the query. Arguments: * query: the backend query implementation * allow_joins: bo...
[ "def", "resolve_expression", "(", "self", ",", "query", "=", "None", ",", "allow_joins", "=", "True", ",", "reuse", "=", "None", ",", "summarize", "=", "False", ",", "for_save", "=", "False", ")", ":", "c", "=", "self", ".", "copy", "(", ")", "c", ...
[ 229, 4 ]
[ 251, 16 ]
python
en
['en', 'error', 'th']
False
BaseExpression.output_field
(self)
Return the output type of this expressions.
Return the output type of this expressions.
def output_field(self): """Return the output type of this expressions.""" output_field = self._resolve_output_field() if output_field is None: self._output_field_resolved_to_none = True raise FieldError('Cannot resolve expression type, unknown output_field') retur...
[ "def", "output_field", "(", "self", ")", ":", "output_field", "=", "self", ".", "_resolve_output_field", "(", ")", "if", "output_field", "is", "None", ":", "self", ".", "_output_field_resolved_to_none", "=", "True", "raise", "FieldError", "(", "'Cannot resolve exp...
[ 262, 4 ]
[ 268, 27 ]
python
en
['en', 'en', 'en']
True
BaseExpression._output_field_or_none
(self)
Return the output field of this expression, or None if _resolve_output_field() didn't return an output type.
Return the output field of this expression, or None if _resolve_output_field() didn't return an output type.
def _output_field_or_none(self): """ Return the output field of this expression, or None if _resolve_output_field() didn't return an output type. """ try: return self.output_field except FieldError: if not self._output_field_resolved_to_none: ...
[ "def", "_output_field_or_none", "(", "self", ")", ":", "try", ":", "return", "self", ".", "output_field", "except", "FieldError", ":", "if", "not", "self", ".", "_output_field_resolved_to_none", ":", "raise" ]
[ 271, 4 ]
[ 280, 21 ]
python
en
['en', 'error', 'th']
False
BaseExpression._resolve_output_field
(self)
Attempt to infer the output type of the expression. If the output fields of all source fields match then, simply infer the same type here. This isn't always correct, but it makes sense most of the time. Consider the difference between `2 + 2` and `2 / 3`. Inferring the type her...
Attempt to infer the output type of the expression. If the output fields of all source fields match then, simply infer the same type here. This isn't always correct, but it makes sense most of the time.
def _resolve_output_field(self): """ Attempt to infer the output type of the expression. If the output fields of all source fields match then, simply infer the same type here. This isn't always correct, but it makes sense most of the time. Consider the difference between `2 + 2`...
[ "def", "_resolve_output_field", "(", "self", ")", ":", "sources_iter", "=", "(", "source", "for", "source", "in", "self", ".", "get_source_fields", "(", ")", "if", "source", "is", "not", "None", ")", "for", "output_field", "in", "sources_iter", ":", "for", ...
[ 282, 4 ]
[ 307, 31 ]
python
en
['en', 'error', 'th']
False
BaseExpression.convert_value
(self)
Expressions provide their own converters because users have the option of manually specifying the output_field which may be a different type from the one the database returns.
Expressions provide their own converters because users have the option of manually specifying the output_field which may be a different type from the one the database returns.
def convert_value(self): """ Expressions provide their own converters because users have the option of manually specifying the output_field which may be a different type from the one the database returns. """ field = self.output_field internal_type = field.get_int...
[ "def", "convert_value", "(", "self", ")", ":", "field", "=", "self", ".", "output_field", "internal_type", "=", "field", ".", "get_internal_type", "(", ")", "if", "internal_type", "==", "'FloatField'", ":", "return", "lambda", "value", ",", "expression", ",", ...
[ 314, 4 ]
[ 328, 39 ]
python
en
['en', 'error', 'th']
False
BaseExpression.get_source_fields
(self)
Return the underlying field types used by this aggregate.
Return the underlying field types used by this aggregate.
def get_source_fields(self): """Return the underlying field types used by this aggregate.""" return [e._output_field_or_none for e in self.get_source_expressions()]
[ "def", "get_source_fields", "(", "self", ")", ":", "return", "[", "e", ".", "_output_field_or_none", "for", "e", "in", "self", ".", "get_source_expressions", "(", ")", "]" ]
[ 355, 4 ]
[ 357, 79 ]
python
en
['en', 'en', 'en']
True
BaseExpression.flatten
(self)
Recursively yield this expression and all subexpressions, in depth-first order.
Recursively yield this expression and all subexpressions, in depth-first order.
def flatten(self): """ Recursively yield this expression and all subexpressions, in depth-first order. """ yield self for expr in self.get_source_expressions(): if expr: if hasattr(expr, 'flatten'): yield from expr.flatten()...
[ "def", "flatten", "(", "self", ")", ":", "yield", "self", "for", "expr", "in", "self", ".", "get_source_expressions", "(", ")", ":", "if", "expr", ":", "if", "hasattr", "(", "expr", ",", "'flatten'", ")", ":", "yield", "from", "expr", ".", "flatten", ...
[ 368, 4 ]
[ 379, 30 ]
python
en
['en', 'error', 'th']
False
BaseExpression.select_format
(self, compiler, sql, params)
Custom format for select clauses. For example, EXISTS expressions need to be wrapped in CASE WHEN on Oracle.
Custom format for select clauses. For example, EXISTS expressions need to be wrapped in CASE WHEN on Oracle.
def select_format(self, compiler, sql, params): """ Custom format for select clauses. For example, EXISTS expressions need to be wrapped in CASE WHEN on Oracle. """ if hasattr(self.output_field, 'select_format'): return self.output_field.select_format(compiler, sql, p...
[ "def", "select_format", "(", "self", ",", "compiler", ",", "sql", ",", "params", ")", ":", "if", "hasattr", "(", "self", ".", "output_field", ",", "'select_format'", ")", ":", "return", "self", ".", "output_field", ".", "select_format", "(", "compiler", ",...
[ 381, 4 ]
[ 388, 26 ]
python
en
['en', 'error', 'th']
False
Func._get_repr_options
(self)
Return a dict of extra __init__() options to include in the repr.
Return a dict of extra __init__() options to include in the repr.
def _get_repr_options(self): """Return a dict of extra __init__() options to include in the repr.""" return {}
[ "def", "_get_repr_options", "(", "self", ")", ":", "return", "{", "}" ]
[ 663, 4 ]
[ 665, 17 ]
python
en
['en', 'en', 'en']
True
Value.__init__
(self, value, output_field=None)
Arguments: * value: the value this expression represents. The value will be added into the sql parameter list and properly quoted. * output_field: an instance of the model field type that this expression will return, such as IntegerField() or CharField().
Arguments: * value: the value this expression represents. The value will be added into the sql parameter list and properly quoted.
def __init__(self, value, output_field=None): """ Arguments: * value: the value this expression represents. The value will be added into the sql parameter list and properly quoted. * output_field: an instance of the model field type that this expression will retu...
[ "def", "__init__", "(", "self", ",", "value", ",", "output_field", "=", "None", ")", ":", "super", "(", ")", ".", "__init__", "(", "output_field", "=", "output_field", ")", "self", ".", "value", "=", "value" ]
[ 714, 4 ]
[ 724, 26 ]
python
en
['en', 'error', 'th']
False
get_normalization_parameters
(traindf, features)
Get the normalization parameters (E.g., mean, std) for traindf for features. We will use these parameters for training, eval, and serving.
Get the normalization parameters (E.g., mean, std) for traindf for features. We will use these parameters for training, eval, and serving.
def get_normalization_parameters(traindf, features): """Get the normalization parameters (E.g., mean, std) for traindf for features. We will use these parameters for training, eval, and serving.""" def _z_score_params(column): mean = traindf[column].mean() std = traindf[column].std() return {'mean...
[ "def", "get_normalization_parameters", "(", "traindf", ",", "features", ")", ":", "def", "_z_score_params", "(", "column", ")", ":", "mean", "=", "traindf", "[", "column", "]", ".", "mean", "(", ")", "std", "=", "traindf", "[", "column", "]", ".", "std",...
[ 29, 0 ]
[ 41, 33 ]
python
en
['en', 'en', 'en']
True
create_feature_cols
(features, use_normalization)
Create our feature columns using tf.feature_column. This function will get executed during training, evaluation, and serving.
Create our feature columns using tf.feature_column. This function will get executed during training, evaluation, and serving.
def create_feature_cols(features, use_normalization): """Create our feature columns using tf.feature_column. This function will get executed during training, evaluation, and serving.""" normalized_feature_columns = [] for column_name in features: if use_normalization: column_params = normalization_pa...
[ "def", "create_feature_cols", "(", "features", ",", "use_normalization", ")", ":", "normalized_feature_columns", "=", "[", "]", "for", "column_name", "in", "features", ":", "if", "use_normalization", ":", "column_params", "=", "normalization_parameters", "[", "column_...
[ 54, 0 ]
[ 70, 35 ]
python
en
['en', 'en', 'en']
True
input_fn
(df, shuffle=True)
For training and evaluation inputs.
For training and evaluation inputs.
def input_fn(df, shuffle=True): """For training and evaluation inputs.""" return tf.estimator.inputs.pandas_input_fn( x = df, y = df["median_house_value"]/100000, # Scale target. shuffle = shuffle)
[ "def", "input_fn", "(", "df", ",", "shuffle", "=", "True", ")", ":", "return", "tf", ".", "estimator", ".", "inputs", ".", "pandas_input_fn", "(", "x", "=", "df", ",", "y", "=", "df", "[", "\"median_house_value\"", "]", "/", "100000", ",", "# Scale tar...
[ 72, 0 ]
[ 77, 22 ]
python
en
['en', 'en', 'en']
True
response_chunks
( response: Response, chunk_size: int = CONTENT_CHUNK_SIZE )
Given a requests Response, provide the data chunks.
Given a requests Response, provide the data chunks.
def response_chunks( response: Response, chunk_size: int = CONTENT_CHUNK_SIZE ) -> Iterator[bytes]: """Given a requests Response, provide the data chunks.""" try: # Special case for urllib3. for chunk in response.raw.stream( chunk_size, # We use decode_content=False h...
[ "def", "response_chunks", "(", "response", ":", "Response", ",", "chunk_size", ":", "int", "=", "CONTENT_CHUNK_SIZE", ")", "->", "Iterator", "[", "bytes", "]", ":", "try", ":", "# Special case for urllib3.", "for", "chunk", "in", "response", ".", "raw", ".", ...
[ 56, 0 ]
[ 95, 23 ]
python
en
['en', 'en', 'en']
True
lovasz_grad
(gt_sorted)
Computes gradient of the Lovasz extension w.r.t sorted errors See Alg. 1 in paper
Computes gradient of the Lovasz extension w.r.t sorted errors See Alg. 1 in paper
def lovasz_grad(gt_sorted): """ Computes gradient of the Lovasz extension w.r.t sorted errors See Alg. 1 in paper """ gts = tf.reduce_sum(gt_sorted) intersection = gts - tf.cumsum(gt_sorted) union = gts + tf.cumsum(1. - gt_sorted) jaccard = 1. - intersection / union jaccard = tf.conc...
[ "def", "lovasz_grad", "(", "gt_sorted", ")", ":", "gts", "=", "tf", ".", "reduce_sum", "(", "gt_sorted", ")", "intersection", "=", "gts", "-", "tf", ".", "cumsum", "(", "gt_sorted", ")", "union", "=", "gts", "+", "tf", ".", "cumsum", "(", "1.", "-", ...
[ 14, 0 ]
[ 24, 18 ]
python
en
['en', 'error', 'th']
False
lovasz_hinge
(logits, labels, per_image=True, ignore=None)
Binary Lovasz hinge loss logits: [B, H, W] Variable, logits at each pixel (between -\infty and +\infty) labels: [B, H, W] Tensor, binary ground truth masks (0 or 1) per_image: compute the loss per image instead of per batch ignore: void class id
Binary Lovasz hinge loss logits: [B, H, W] Variable, logits at each pixel (between -\infty and +\infty) labels: [B, H, W] Tensor, binary ground truth masks (0 or 1) per_image: compute the loss per image instead of per batch ignore: void class id
def lovasz_hinge(logits, labels, per_image=True, ignore=None): """ Binary Lovasz hinge loss logits: [B, H, W] Variable, logits at each pixel (between -\infty and +\infty) labels: [B, H, W] Tensor, binary ground truth masks (0 or 1) per_image: compute the loss per image instead of per batch ...
[ "def", "lovasz_hinge", "(", "logits", ",", "labels", ",", "per_image", "=", "True", ",", "ignore", "=", "None", ")", ":", "if", "per_image", ":", "def", "treat_image", "(", "log_lab", ")", ":", "log", ",", "lab", "=", "log_lab", "log", ",", "lab", "=...
[ 30, 0 ]
[ 48, 15 ]
python
en
['en', 'error', 'th']
False
lovasz_hinge_flat
(logits, labels)
Binary Lovasz hinge loss logits: [P] Variable, logits at each prediction (between -\infty and +\infty) labels: [P] Tensor, binary ground truth labels (0 or 1) ignore: label to ignore
Binary Lovasz hinge loss logits: [P] Variable, logits at each prediction (between -\infty and +\infty) labels: [P] Tensor, binary ground truth labels (0 or 1) ignore: label to ignore
def lovasz_hinge_flat(logits, labels): """ Binary Lovasz hinge loss logits: [P] Variable, logits at each prediction (between -\infty and +\infty) labels: [P] Tensor, binary ground truth labels (0 or 1) ignore: label to ignore """ def compute_loss(): labelsf = tf.cast(labels, l...
[ "def", "lovasz_hinge_flat", "(", "logits", ",", "labels", ")", ":", "def", "compute_loss", "(", ")", ":", "labelsf", "=", "tf", ".", "cast", "(", "labels", ",", "logits", ".", "dtype", ")", "signs", "=", "2.", "*", "labelsf", "-", "1.", "errors", "="...
[ 51, 0 ]
[ 76, 15 ]
python
en
['en', 'error', 'th']
False
flatten_binary_scores
(scores, labels, ignore=None)
Flattens predictions in the batch (binary case) Remove labels equal to 'ignore'
Flattens predictions in the batch (binary case) Remove labels equal to 'ignore'
def flatten_binary_scores(scores, labels, ignore=None): """ Flattens predictions in the batch (binary case) Remove labels equal to 'ignore' """ scores = tf.reshape(scores, (-1,)) labels = tf.reshape(labels, (-1,)) if ignore is None: return scores, labels valid = tf.not_equal(labe...
[ "def", "flatten_binary_scores", "(", "scores", ",", "labels", ",", "ignore", "=", "None", ")", ":", "scores", "=", "tf", ".", "reshape", "(", "scores", ",", "(", "-", "1", ",", ")", ")", "labels", "=", "tf", ".", "reshape", "(", "labels", ",", "(",...
[ 79, 0 ]
[ 91, 27 ]
python
en
['en', 'error', 'th']
False
lovasz_softmax
(probas, labels, classes='present', per_image=False, ignore=None, order='BHWC')
Multi-class Lovasz-Softmax loss probas: [B, H, W, C] or [B, C, H, W] Variable, class probabilities at each prediction (between 0 and 1) Interpreted as binary (sigmoid) output with outputs of size [B, H, W]. labels: [B, H, W] Tensor, ground truth labels (between 0 and C - 1) classes:...
Multi-class Lovasz-Softmax loss probas: [B, H, W, C] or [B, C, H, W] Variable, class probabilities at each prediction (between 0 and 1) Interpreted as binary (sigmoid) output with outputs of size [B, H, W]. labels: [B, H, W] Tensor, ground truth labels (between 0 and C - 1) classes:...
def lovasz_softmax(probas, labels, classes='present', per_image=False, ignore=None, order='BHWC'): """ Multi-class Lovasz-Softmax loss probas: [B, H, W, C] or [B, C, H, W] Variable, class probabilities at each prediction (between 0 and 1) Interpreted as binary (sigmoid) output with outputs o...
[ "def", "lovasz_softmax", "(", "probas", ",", "labels", ",", "classes", "=", "'present'", ",", "per_image", "=", "False", ",", "ignore", "=", "None", ",", "order", "=", "'BHWC'", ")", ":", "if", "per_image", ":", "def", "treat_image", "(", "prob_lab", ")"...
[ 97, 0 ]
[ 118, 15 ]
python
en
['en', 'error', 'th']
False
lovasz_softmax_flat
(probas, labels, classes='present')
Multi-class Lovasz-Softmax loss probas: [P, C] Variable, class probabilities at each prediction (between 0 and 1) labels: [P] Tensor, ground truth labels (between 0 and C - 1) classes: 'all' for all, 'present' for classes present in labels, or a list of classes to average.
Multi-class Lovasz-Softmax loss probas: [P, C] Variable, class probabilities at each prediction (between 0 and 1) labels: [P] Tensor, ground truth labels (between 0 and C - 1) classes: 'all' for all, 'present' for classes present in labels, or a list of classes to average.
def lovasz_softmax_flat(probas, labels, classes='present'): """ Multi-class Lovasz-Softmax loss probas: [P, C] Variable, class probabilities at each prediction (between 0 and 1) labels: [P] Tensor, ground truth labels (between 0 and C - 1) classes: 'all' for all, 'present' for classes present ...
[ "def", "lovasz_softmax_flat", "(", "probas", ",", "labels", ",", "classes", "=", "'present'", ")", ":", "C", "=", "probas", ".", "shape", "[", "1", "]", "losses", "=", "[", "]", "present", "=", "[", "]", "class_to_sum", "=", "list", "(", "range", "("...
[ 121, 0 ]
[ 156, 15 ]
python
en
['en', 'error', 'th']
False
flatten_probas
(probas, labels, ignore=None, order='BHWC')
Flattens predictions in the batch
Flattens predictions in the batch
def flatten_probas(probas, labels, ignore=None, order='BHWC'): """ Flattens predictions in the batch """ if len(probas.shape) == 3: probas, order = tf.expand_dims(probas, 3), 'BHWC' if order == 'BCHW': probas = tf.transpose(probas, (0, 2, 3, 1), name="BCHW_to_BHWC") order = '...
[ "def", "flatten_probas", "(", "probas", ",", "labels", ",", "ignore", "=", "None", ",", "order", "=", "'BHWC'", ")", ":", "if", "len", "(", "probas", ".", "shape", ")", "==", "3", ":", "probas", ",", "order", "=", "tf", ".", "expand_dims", "(", "pr...
[ 159, 0 ]
[ 178, 27 ]
python
en
['en', 'error', 'th']
False
User._encrypt_pw
(self, password)
Encrypt the password with the username and return the sha digest
Encrypt the password with the username and return the sha digest
def _encrypt_pw(self, password): """Encrypt the password with the username and return the sha digest""" hash_str = (self.name + password) hash_str = hash_str.encode("utf8") return hashlib.sha256(hash_str).hexdigest()
[ "def", "_encrypt_pw", "(", "self", ",", "password", ")", ":", "hash_str", "=", "(", "self", ".", "name", "+", "password", ")", "hash_str", "=", "hash_str", ".", "encode", "(", "\"utf8\"", ")", "return", "hashlib", ".", "sha256", "(", "hash_str", ")", "...
[ 47, 4 ]
[ 52, 51 ]
python
en
['en', 'en', 'en']
True
User.check_password
(self, password)
Return True if the password is valid for this user, otherwise false
Return True if the password is valid for this user, otherwise false
def check_password(self, password): """Return True if the password is valid for this user, otherwise false""" encrypted = self._encrypt_pw(password) return encrypted == self.password
[ "def", "check_password", "(", "self", ",", "password", ")", ":", "encrypted", "=", "self", ".", "_encrypt_pw", "(", "password", ")", "return", "encrypted", "==", "self", ".", "password" ]
[ 54, 4 ]
[ 58, 41 ]
python
en
['en', 'en', 'en']
True
Authenticator.__init__
(self)
Construct an authenticator to manage users logging in and out.
Construct an authenticator to manage users logging in and out.
def __init__(self): "Construct an authenticator to manage users logging in and out." self.users = {}
[ "def", "__init__", "(", "self", ")", ":", "self", ".", "users", "=", "{", "}" ]
[ 63, 4 ]
[ 65, 23 ]
python
en
['en', 'en', 'en']
True
Authorizor.add_permission
(self, perm_name)
Create a new permission that users can be added to.
Create a new permission that users can be added to.
def add_permission(self, perm_name): "Create a new permission that users can be added to." try: perm_set = self.permissions[perm_name] except KeyError: self.permissions[perm_name] = set() else: raise PermissionError("Permission Exists")
[ "def", "add_permission", "(", "self", ",", "perm_name", ")", ":", "try", ":", "perm_set", "=", "self", ".", "permissions", "[", "perm_name", "]", "except", "KeyError", ":", "self", ".", "permissions", "[", "perm_name", "]", "=", "set", "(", ")", "else", ...
[ 98, 4 ]
[ 105, 54 ]
python
en
['en', 'en', 'en']
True
Authorizor.permit_user
(self, perm_name, username)
Grant the given permission to the user
Grant the given permission to the user
def permit_user(self, perm_name, username): "Grant the given permission to the user" try: perm_set = self.permissions[perm_name] except KeyError: raise PermissionError("Permission does not exist") else: if username not in self.authenticator.users: ...
[ "def", "permit_user", "(", "self", ",", "perm_name", ",", "username", ")", ":", "try", ":", "perm_set", "=", "self", ".", "permissions", "[", "perm_name", "]", "except", "KeyError", ":", "raise", "PermissionError", "(", "\"Permission does not exist\"", ")", "e...
[ 107, 4 ]
[ 116, 34 ]
python
en
['en', 'en', 'en']
True
GhostNet._make_divisible
(self, v, divisor, min_value=None)
This function is taken from the original tf repo. It ensures that all layers have a channel number that is divisible by 8 It can be seen here: https://github.com/tensorflow/models/blob/master/research/slim/nets/mobilenet/mobilenet.py
This function is taken from the original tf repo. It ensures that all layers have a channel number that is divisible by 8 It can be seen here: https://github.com/tensorflow/models/blob/master/research/slim/nets/mobilenet/mobilenet.py
def _make_divisible(self, v, divisor, min_value=None): """ This function is taken from the original tf repo. It ensures that all layers have a channel number that is divisible by 8 It can be seen here: https://github.com/tensorflow/models/blob/master/research/slim/nets/mobilenet/...
[ "def", "_make_divisible", "(", "self", ",", "v", ",", "divisor", ",", "min_value", "=", "None", ")", ":", "if", "min_value", "is", "None", ":", "min_value", "=", "divisor", "new_v", "=", "max", "(", "min_value", ",", "int", "(", "v", "+", "divisor", ...
[ 302, 4 ]
[ 315, 20 ]
python
en
['en', 'error', 'th']
False
cloudinary_direct_upload
(callback_url, **options)
Deprecated - please use cloudinary_direct_upload_field, or a proper form
Deprecated - please use cloudinary_direct_upload_field, or a proper form
def cloudinary_direct_upload(callback_url, **options): """Deprecated - please use cloudinary_direct_upload_field, or a proper form""" params = utils.build_upload_params(callback=callback_url, **options) params = utils.sign_request(params, options) api_url = utils.cloudinary_api_url("upload", resource_t...
[ "def", "cloudinary_direct_upload", "(", "callback_url", ",", "*", "*", "options", ")", ":", "params", "=", "utils", ".", "build_upload_params", "(", "callback", "=", "callback_url", ",", "*", "*", "options", ")", "params", "=", "utils", ".", "sign_request", ...
[ 59, 0 ]
[ 67, 45 ]
python
en
['en', 'en', 'en']
True
make_graph
(dists, scheme='default')
Makes a dependency graph from the given distributions. :parameter dists: a list of distributions :type dists: list of :class:`distutils2.database.InstalledDistribution` and :class:`distutils2.database.EggInfoDistribution` instances :rtype: a :class:`DependencyGraph` instance
Makes a dependency graph from the given distributions.
def make_graph(dists, scheme='default'): """Makes a dependency graph from the given distributions. :parameter dists: a list of distributions :type dists: list of :class:`distutils2.database.InstalledDistribution` and :class:`distutils2.database.EggInfoDistribution` instances :rtype: a ...
[ "def", "make_graph", "(", "dists", ",", "scheme", "=", "'default'", ")", ":", "scheme", "=", "get_scheme", "(", "scheme", ")", "graph", "=", "DependencyGraph", "(", ")", "provided", "=", "{", "}", "# maps names to lists of (version, dist) tuples", "# first, build ...
[ 1224, 0 ]
[ 1275, 16 ]
python
en
['en', 'en', 'en']
True
get_dependent_dists
(dists, dist)
Recursively generate a list of distributions from *dists* that are dependent on *dist*. :param dists: a list of distributions :param dist: a distribution, member of *dists* for which we are interested
Recursively generate a list of distributions from *dists* that are dependent on *dist*.
def get_dependent_dists(dists, dist): """Recursively generate a list of distributions from *dists* that are dependent on *dist*. :param dists: a list of distributions :param dist: a distribution, member of *dists* for which we are interested """ if dist not in dists: raise DistlibExcept...
[ "def", "get_dependent_dists", "(", "dists", ",", "dist", ")", ":", "if", "dist", "not", "in", "dists", ":", "raise", "DistlibException", "(", "'given distribution %r is not a member '", "'of the list'", "%", "dist", ".", "name", ")", "graph", "=", "make_graph", ...
[ 1278, 0 ]
[ 1301, 14 ]
python
en
['en', 'en', 'en']
True
get_required_dists
(dists, dist)
Recursively generate a list of distributions from *dists* that are required by *dist*. :param dists: a list of distributions :param dist: a distribution, member of *dists* for which we are interested
Recursively generate a list of distributions from *dists* that are required by *dist*.
def get_required_dists(dists, dist): """Recursively generate a list of distributions from *dists* that are required by *dist*. :param dists: a list of distributions :param dist: a distribution, member of *dists* for which we are interested """ if dist not in dists: raise DistlibExceptio...
[ "def", "get_required_dists", "(", "dists", ",", "dist", ")", ":", "if", "dist", "not", "in", "dists", ":", "raise", "DistlibException", "(", "'given distribution %r is not a member '", "'of the list'", "%", "dist", ".", "name", ")", "graph", "=", "make_graph", "...
[ 1304, 0 ]
[ 1326, 14 ]
python
en
['en', 'en', 'en']
True
make_dist
(name, version, **kwargs)
A convenience method for making a dist given just a name and version.
A convenience method for making a dist given just a name and version.
def make_dist(name, version, **kwargs): """ A convenience method for making a dist given just a name and version. """ summary = kwargs.pop('summary', 'Placeholder for summary') md = Metadata(**kwargs) md.name = name md.version = version md.summary = summary or 'Placeholder for summary' ...
[ "def", "make_dist", "(", "name", ",", "version", ",", "*", "*", "kwargs", ")", ":", "summary", "=", "kwargs", ".", "pop", "(", "'summary'", ",", "'Placeholder for summary'", ")", "md", "=", "Metadata", "(", "*", "*", "kwargs", ")", "md", ".", "name", ...
[ 1329, 0 ]
[ 1338, 27 ]
python
en
['en', 'error', 'th']
False
_Cache.__init__
(self)
Initialise an instance. There is normally one for each DistributionPath.
Initialise an instance. There is normally one for each DistributionPath.
def __init__(self): """ Initialise an instance. There is normally one for each DistributionPath. """ self.name = {} self.path = {} self.generated = False
[ "def", "__init__", "(", "self", ")", ":", "self", ".", "name", "=", "{", "}", "self", ".", "path", "=", "{", "}", "self", ".", "generated", "=", "False" ]
[ 48, 4 ]
[ 54, 30 ]
python
en
['en', 'error', 'th']
False
_Cache.clear
(self)
Clear the cache, setting it to its initial state.
Clear the cache, setting it to its initial state.
def clear(self): """ Clear the cache, setting it to its initial state. """ self.name.clear() self.path.clear() self.generated = False
[ "def", "clear", "(", "self", ")", ":", "self", ".", "name", ".", "clear", "(", ")", "self", ".", "path", ".", "clear", "(", ")", "self", ".", "generated", "=", "False" ]
[ 56, 4 ]
[ 62, 30 ]
python
en
['en', 'error', 'th']
False
_Cache.add
(self, dist)
Add a distribution to the cache. :param dist: The distribution to add.
Add a distribution to the cache. :param dist: The distribution to add.
def add(self, dist): """ Add a distribution to the cache. :param dist: The distribution to add. """ if dist.path not in self.path: self.path[dist.path] = dist self.name.setdefault(dist.key, []).append(dist)
[ "def", "add", "(", "self", ",", "dist", ")", ":", "if", "dist", ".", "path", "not", "in", "self", ".", "path", ":", "self", ".", "path", "[", "dist", ".", "path", "]", "=", "dist", "self", ".", "name", ".", "setdefault", "(", "dist", ".", "key"...
[ 64, 4 ]
[ 71, 59 ]
python
en
['en', 'error', 'th']
False
DistributionPath.__init__
(self, path=None, include_egg=False)
Create an instance from a path, optionally including legacy (distutils/ setuptools/distribute) distributions. :param path: The path to use, as a list of directories. If not specified, sys.path is used. :param include_egg: If True, this instance will look for and ret...
Create an instance from a path, optionally including legacy (distutils/ setuptools/distribute) distributions. :param path: The path to use, as a list of directories. If not specified, sys.path is used. :param include_egg: If True, this instance will look for and ret...
def __init__(self, path=None, include_egg=False): """ Create an instance from a path, optionally including legacy (distutils/ setuptools/distribute) distributions. :param path: The path to use, as a list of directories. If not specified, sys.path is used. :pa...
[ "def", "__init__", "(", "self", ",", "path", "=", "None", ",", "include_egg", "=", "False", ")", ":", "if", "path", "is", "None", ":", "path", "=", "sys", ".", "path", "self", ".", "path", "=", "path", "self", ".", "_include_dist", "=", "True", "se...
[ 78, 4 ]
[ 96, 44 ]
python
en
['en', 'error', 'th']
False
DistributionPath.clear_cache
(self)
Clears the internal cache.
Clears the internal cache.
def clear_cache(self): """ Clears the internal cache. """ self._cache.clear() self._cache_egg.clear()
[ "def", "clear_cache", "(", "self", ")", ":", "self", ".", "_cache", ".", "clear", "(", ")", "self", ".", "_cache_egg", ".", "clear", "(", ")" ]
[ 106, 4 ]
[ 111, 31 ]
python
en
['en', 'error', 'th']
False
DistributionPath._yield_distributions
(self)
Yield .dist-info and/or .egg(-info) distributions.
Yield .dist-info and/or .egg(-info) distributions.
def _yield_distributions(self): """ Yield .dist-info and/or .egg(-info) distributions. """ # We need to check if we've seen some resources already, because on # some Linux systems (e.g. some Debian/Ubuntu variants) there are # symlinks which alias other files in the envir...
[ "def", "_yield_distributions", "(", "self", ")", ":", "# We need to check if we've seen some resources already, because on", "# some Linux systems (e.g. some Debian/Ubuntu variants) there are", "# symlinks which alias other files in the environment.", "seen", "=", "set", "(", ")", "for",...
[ 114, 4 ]
[ 156, 54 ]
python
en
['en', 'error', 'th']
False
DistributionPath._generate_cache
(self)
Scan the path for distributions and populate the cache with those that are found.
Scan the path for distributions and populate the cache with those that are found.
def _generate_cache(self): """ Scan the path for distributions and populate the cache with those that are found. """ gen_dist = not self._cache.generated gen_egg = self._include_egg and not self._cache_egg.generated if gen_dist or gen_egg: for dist in ...
[ "def", "_generate_cache", "(", "self", ")", ":", "gen_dist", "=", "not", "self", ".", "_cache", ".", "generated", "gen_egg", "=", "self", ".", "_include_egg", "and", "not", "self", ".", "_cache_egg", ".", "generated", "if", "gen_dist", "or", "gen_egg", ":"...
[ 158, 4 ]
[ 175, 48 ]
python
en
['en', 'error', 'th']
False
DistributionPath.distinfo_dirname
(cls, name, version)
The *name* and *version* parameters are converted into their filename-escaped form, i.e. any ``'-'`` characters are replaced with ``'_'`` other than the one in ``'dist-info'`` and the one separating the name from the version number. :parameter name: is converted to a standard d...
The *name* and *version* parameters are converted into their filename-escaped form, i.e. any ``'-'`` characters are replaced with ``'_'`` other than the one in ``'dist-info'`` and the one separating the name from the version number.
def distinfo_dirname(cls, name, version): """ The *name* and *version* parameters are converted into their filename-escaped form, i.e. any ``'-'`` characters are replaced with ``'_'`` other than the one in ``'dist-info'`` and the one separating the name from the version number. ...
[ "def", "distinfo_dirname", "(", "cls", ",", "name", ",", "version", ")", ":", "name", "=", "name", ".", "replace", "(", "'-'", ",", "'_'", ")", "return", "'-'", ".", "join", "(", "[", "name", ",", "version", "]", ")", "+", "DISTINFO_EXT" ]
[ 178, 4 ]
[ 197, 55 ]
python
en
['en', 'error', 'th']
False
DistributionPath.get_distributions
(self)
Provides an iterator that looks for distributions and returns :class:`InstalledDistribution` or :class:`EggInfoDistribution` instances for each one of them. :rtype: iterator of :class:`InstalledDistribution` and :class:`EggInfoDistribution` instances
Provides an iterator that looks for distributions and returns :class:`InstalledDistribution` or :class:`EggInfoDistribution` instances for each one of them.
def get_distributions(self): """ Provides an iterator that looks for distributions and returns :class:`InstalledDistribution` or :class:`EggInfoDistribution` instances for each one of them. :rtype: iterator of :class:`InstalledDistribution` and :class:`EggInfoDis...
[ "def", "get_distributions", "(", "self", ")", ":", "if", "not", "self", ".", "_cache_enabled", ":", "for", "dist", "in", "self", ".", "_yield_distributions", "(", ")", ":", "yield", "dist", "else", ":", "self", ".", "_generate_cache", "(", ")", "for", "d...
[ 199, 4 ]
[ 219, 30 ]
python
en
['en', 'error', 'th']
False
DistributionPath.get_distribution
(self, name)
Looks for a named distribution on the path. This function only returns the first result found, as no more than one value is expected. If nothing is found, ``None`` is returned. :rtype: :class:`InstalledDistribution`, :class:`EggInfoDistribution` or ``None``
Looks for a named distribution on the path.
def get_distribution(self, name): """ Looks for a named distribution on the path. This function only returns the first result found, as no more than one value is expected. If nothing is found, ``None`` is returned. :rtype: :class:`InstalledDistribution`, :class:`EggInfoDistribu...
[ "def", "get_distribution", "(", "self", ",", "name", ")", ":", "result", "=", "None", "name", "=", "name", ".", "lower", "(", ")", "if", "not", "self", ".", "_cache_enabled", ":", "for", "dist", "in", "self", ".", "_yield_distributions", "(", ")", ":",...
[ 221, 4 ]
[ 245, 21 ]
python
en
['en', 'error', 'th']
False
DistributionPath.provides_distribution
(self, name, version=None)
Iterates over all distributions to find which distributions provide *name*. If a *version* is provided, it will be used to filter the results. This function only returns the first result found, since no more than one values are expected. If the directory is not found, returns ``None``....
Iterates over all distributions to find which distributions provide *name*. If a *version* is provided, it will be used to filter the results.
def provides_distribution(self, name, version=None): """ Iterates over all distributions to find which distributions provide *name*. If a *version* is provided, it will be used to filter the results. This function only returns the first result found, since no more than one value...
[ "def", "provides_distribution", "(", "self", ",", "name", ",", "version", "=", "None", ")", ":", "matcher", "=", "None", "if", "version", "is", "not", "None", ":", "try", ":", "matcher", "=", "self", ".", "_scheme", ".", "matcher", "(", "'%s (%s)'", "%...
[ 247, 4 ]
[ 286, 33 ]
python
en
['en', 'error', 'th']
False
DistributionPath.get_file_path
(self, name, relative_path)
Return the path to a resource file.
Return the path to a resource file.
def get_file_path(self, name, relative_path): """ Return the path to a resource file. """ dist = self.get_distribution(name) if dist is None: raise LookupError('no distribution named %r found' % name) return dist.get_resource_path(relative_path)
[ "def", "get_file_path", "(", "self", ",", "name", ",", "relative_path", ")", ":", "dist", "=", "self", ".", "get_distribution", "(", "name", ")", "if", "dist", "is", "None", ":", "raise", "LookupError", "(", "'no distribution named %r found'", "%", "name", "...
[ 288, 4 ]
[ 295, 52 ]
python
en
['en', 'error', 'th']
False
DistributionPath.get_exported_entries
(self, category, name=None)
Return all of the exported entries in a particular category. :param category: The category to search for entries. :param name: If specified, only entries with that name are returned.
Return all of the exported entries in a particular category.
def get_exported_entries(self, category, name=None): """ Return all of the exported entries in a particular category. :param category: The category to search for entries. :param name: If specified, only entries with that name are returned. """ for dist in self.get_distri...
[ "def", "get_exported_entries", "(", "self", ",", "category", ",", "name", "=", "None", ")", ":", "for", "dist", "in", "self", ".", "get_distributions", "(", ")", ":", "r", "=", "dist", ".", "exports", "if", "category", "in", "r", ":", "d", "=", "r", ...
[ 297, 4 ]
[ 313, 31 ]
python
en
['en', 'error', 'th']
False
Distribution.__init__
(self, metadata)
Initialise an instance. :param metadata: The instance of :class:`Metadata` describing this distribution.
Initialise an instance. :param metadata: The instance of :class:`Metadata` describing this distribution.
def __init__(self, metadata): """ Initialise an instance. :param metadata: The instance of :class:`Metadata` describing this distribution. """ self.metadata = metadata self.name = metadata.name self.key = self.name.lower() # for case-insensitive compari...
[ "def", "__init__", "(", "self", ",", "metadata", ")", ":", "self", ".", "metadata", "=", "metadata", "self", ".", "name", "=", "metadata", ".", "name", "self", ".", "key", "=", "self", ".", "name", ".", "lower", "(", ")", "# for case-insensitive comparis...
[ 334, 4 ]
[ 349, 25 ]
python
en
['en', 'error', 'th']
False
Distribution.source_url
(self)
The source archive download URL for this distribution.
The source archive download URL for this distribution.
def source_url(self): """ The source archive download URL for this distribution. """ return self.metadata.source_url
[ "def", "source_url", "(", "self", ")", ":", "return", "self", ".", "metadata", ".", "source_url" ]
[ 352, 4 ]
[ 356, 39 ]
python
en
['en', 'error', 'th']
False
Distribution.name_and_version
(self)
A utility property which displays the name and version in parentheses.
A utility property which displays the name and version in parentheses.
def name_and_version(self): """ A utility property which displays the name and version in parentheses. """ return '%s (%s)' % (self.name, self.version)
[ "def", "name_and_version", "(", "self", ")", ":", "return", "'%s (%s)'", "%", "(", "self", ".", "name", ",", "self", ".", "version", ")" ]
[ 361, 4 ]
[ 365, 52 ]
python
en
['en', 'error', 'th']
False
Distribution.provides
(self)
A set of distribution names and versions provided by this distribution. :return: A set of "name (version)" strings.
A set of distribution names and versions provided by this distribution. :return: A set of "name (version)" strings.
def provides(self): """ A set of distribution names and versions provided by this distribution. :return: A set of "name (version)" strings. """ plist = self.metadata.provides s = '%s (%s)' % (self.name, self.version) if s not in plist: plist.append(s) ...
[ "def", "provides", "(", "self", ")", ":", "plist", "=", "self", ".", "metadata", ".", "provides", "s", "=", "'%s (%s)'", "%", "(", "self", ".", "name", ",", "self", ".", "version", ")", "if", "s", "not", "in", "plist", ":", "plist", ".", "append", ...
[ 368, 4 ]
[ 377, 20 ]
python
en
['en', 'error', 'th']
False
Distribution.matches_requirement
(self, req)
Say if this instance matches (fulfills) a requirement. :param req: The requirement to match. :rtype req: str :return: True if it matches, else False.
Say if this instance matches (fulfills) a requirement. :param req: The requirement to match. :rtype req: str :return: True if it matches, else False.
def matches_requirement(self, req): """ Say if this instance matches (fulfills) a requirement. :param req: The requirement to match. :rtype req: str :return: True if it matches, else False. """ # Requirement may contain extras - parse to lose those # from ...
[ "def", "matches_requirement", "(", "self", ",", "req", ")", ":", "# Requirement may contain extras - parse to lose those", "# from what's passed to the matcher", "r", "=", "parse_requirement", "(", "req", ")", "scheme", "=", "get_scheme", "(", "self", ".", "metadata", "...
[ 406, 4 ]
[ 438, 21 ]
python
en
['en', 'error', 'th']
False
Distribution.__repr__
(self)
Return a textual representation of this instance,
Return a textual representation of this instance,
def __repr__(self): """ Return a textual representation of this instance, """ if self.source_url: suffix = ' [%s]' % self.source_url else: suffix = '' return '<Distribution %s (%s)%s>' % (self.name, self.version, suffix)
[ "def", "__repr__", "(", "self", ")", ":", "if", "self", ".", "source_url", ":", "suffix", "=", "' [%s]'", "%", "self", ".", "source_url", "else", ":", "suffix", "=", "''", "return", "'<Distribution %s (%s)%s>'", "%", "(", "self", ".", "name", ",", "self"...
[ 440, 4 ]
[ 448, 77 ]
python
en
['en', 'error', 'th']
False
Distribution.__eq__
(self, other)
See if this distribution is the same as another. :param other: The distribution to compare with. To be equal to one another. distributions must have the same type, name, version and source_url. :return: True if it is the same, else False.
See if this distribution is the same as another. :param other: The distribution to compare with. To be equal to one another. distributions must have the same type, name, version and source_url. :return: True if it is the same, else False.
def __eq__(self, other): """ See if this distribution is the same as another. :param other: The distribution to compare with. To be equal to one another. distributions must have the same type, name, version and source_url. :return: True if it i...
[ "def", "__eq__", "(", "self", ",", "other", ")", ":", "if", "type", "(", "other", ")", "is", "not", "type", "(", "self", ")", ":", "result", "=", "False", "else", ":", "result", "=", "(", "self", ".", "name", "==", "other", ".", "name", "and", ...
[ 450, 4 ]
[ 464, 21 ]
python
en
['en', 'error', 'th']
False
Distribution.__hash__
(self)
Compute hash in a way which matches the equality test.
Compute hash in a way which matches the equality test.
def __hash__(self): """ Compute hash in a way which matches the equality test. """ return hash(self.name) + hash(self.version) + hash(self.source_url)
[ "def", "__hash__", "(", "self", ")", ":", "return", "hash", "(", "self", ".", "name", ")", "+", "hash", "(", "self", ".", "version", ")", "+", "hash", "(", "self", ".", "source_url", ")" ]
[ 466, 4 ]
[ 470, 75 ]
python
en
['en', 'error', 'th']
False
BaseInstalledDistribution.__init__
(self, metadata, path, env=None)
Initialise an instance. :param metadata: An instance of :class:`Metadata` which describes the distribution. This will normally have been initialised from a metadata file in the ``path``. :param path: The path of the ``.dist-info`` or ``.egg-...
Initialise an instance. :param metadata: An instance of :class:`Metadata` which describes the distribution. This will normally have been initialised from a metadata file in the ``path``. :param path: The path of the ``.dist-info`` or ``.egg-...
def __init__(self, metadata, path, env=None): """ Initialise an instance. :param metadata: An instance of :class:`Metadata` which describes the distribution. This will normally have been initialised from a metadata file in the ``path``. :...
[ "def", "__init__", "(", "self", ",", "metadata", ",", "path", ",", "env", "=", "None", ")", ":", "super", "(", "BaseInstalledDistribution", ",", "self", ")", ".", "__init__", "(", "metadata", ")", "self", ".", "path", "=", "path", "self", ".", "dist_pa...
[ 481, 4 ]
[ 494, 28 ]
python
en
['en', 'error', 'th']
False
BaseInstalledDistribution.get_hash
(self, data, hasher=None)
Get the hash of some data, using a particular hash algorithm, if specified. :param data: The data to be hashed. :type data: bytes :param hasher: The name of a hash implementation, supported by hashlib, or ``None``. Examples of valid values are ``'sha1'``,...
Get the hash of some data, using a particular hash algorithm, if specified.
def get_hash(self, data, hasher=None): """ Get the hash of some data, using a particular hash algorithm, if specified. :param data: The data to be hashed. :type data: bytes :param hasher: The name of a hash implementation, supported by hashlib, or ...
[ "def", "get_hash", "(", "self", ",", "data", ",", "hasher", "=", "None", ")", ":", "if", "hasher", "is", "None", ":", "hasher", "=", "self", ".", "hasher", "if", "hasher", "is", "None", ":", "hasher", "=", "hashlib", ".", "md5", "prefix", "=", "''"...
[ 496, 4 ]
[ 525, 40 ]
python
en
['en', 'error', 'th']
False
InstalledDistribution._get_records
(self)
Get the list of installed files for the distribution :return: A list of tuples of path, hash and size. Note that hash and size might be ``None`` for some entries. The path is exactly as stored in the file (which is as in PEP 376).
Get the list of installed files for the distribution :return: A list of tuples of path, hash and size. Note that hash and size might be ``None`` for some entries. The path is exactly as stored in the file (which is as in PEP 376).
def _get_records(self): """ Get the list of installed files for the distribution :return: A list of tuples of path, hash and size. Note that hash and size might be ``None`` for some entries. The path is exactly as stored in the file (which is as in PEP 376). ...
[ "def", "_get_records", "(", "self", ")", ":", "results", "=", "[", "]", "r", "=", "self", ".", "get_distinfo_resource", "(", "'RECORD'", ")", "with", "contextlib", ".", "closing", "(", "r", ".", "as_stream", "(", ")", ")", "as", "stream", ":", "with", ...
[ 579, 4 ]
[ 600, 22 ]
python
en
['en', 'error', 'th']
False
InstalledDistribution.exports
(self)
Return the information exported by this distribution. :return: A dictionary of exports, mapping an export category to a dict of :class:`ExportEntry` instances describing the individual export entries, and keyed by name.
Return the information exported by this distribution. :return: A dictionary of exports, mapping an export category to a dict of :class:`ExportEntry` instances describing the individual export entries, and keyed by name.
def exports(self): """ Return the information exported by this distribution. :return: A dictionary of exports, mapping an export category to a dict of :class:`ExportEntry` instances describing the individual export entries, and keyed by name. """ ...
[ "def", "exports", "(", "self", ")", ":", "result", "=", "{", "}", "r", "=", "self", ".", "get_distinfo_resource", "(", "EXPORTS_FILENAME", ")", "if", "r", ":", "result", "=", "self", ".", "read_exports", "(", ")", "return", "result" ]
[ 603, 4 ]
[ 614, 21 ]
python
en
['en', 'error', 'th']
False
InstalledDistribution.read_exports
(self)
Read exports data from a file in .ini format. :return: A dictionary of exports, mapping an export category to a list of :class:`ExportEntry` instances describing the individual export entries.
Read exports data from a file in .ini format.
def read_exports(self): """ Read exports data from a file in .ini format. :return: A dictionary of exports, mapping an export category to a list of :class:`ExportEntry` instances describing the individual export entries. """ result = {} ...
[ "def", "read_exports", "(", "self", ")", ":", "result", "=", "{", "}", "r", "=", "self", ".", "get_distinfo_resource", "(", "EXPORTS_FILENAME", ")", "if", "r", ":", "with", "contextlib", ".", "closing", "(", "r", ".", "as_stream", "(", ")", ")", "as", ...
[ 616, 4 ]
[ 629, 21 ]
python
en
['en', 'error', 'th']
False
InstalledDistribution.write_exports
(self, exports)
Write a dictionary of exports to a file in .ini format. :param exports: A dictionary of exports, mapping an export category to a list of :class:`ExportEntry` instances describing the individual export entries.
Write a dictionary of exports to a file in .ini format. :param exports: A dictionary of exports, mapping an export category to a list of :class:`ExportEntry` instances describing the individual export entries.
def write_exports(self, exports): """ Write a dictionary of exports to a file in .ini format. :param exports: A dictionary of exports, mapping an export category to a list of :class:`ExportEntry` instances describing the individual export entries. ...
[ "def", "write_exports", "(", "self", ",", "exports", ")", ":", "rf", "=", "self", ".", "get_distinfo_file", "(", "EXPORTS_FILENAME", ")", "with", "open", "(", "rf", ",", "'w'", ")", "as", "f", ":", "write_exports", "(", "exports", ",", "f", ")" ]
[ 631, 4 ]
[ 640, 37 ]
python
en
['en', 'error', 'th']
False
InstalledDistribution.get_resource_path
(self, relative_path)
NOTE: This API may change in the future. Return the absolute path to a resource file with the given relative path. :param relative_path: The path, relative to .dist-info, of the resource of interest. :return: The absolute path where the resource i...
NOTE: This API may change in the future.
def get_resource_path(self, relative_path): """ NOTE: This API may change in the future. Return the absolute path to a resource file with the given relative path. :param relative_path: The path, relative to .dist-info, of the resource of interest. ...
[ "def", "get_resource_path", "(", "self", ",", "relative_path", ")", ":", "r", "=", "self", ".", "get_distinfo_resource", "(", "'RESOURCES'", ")", "with", "contextlib", ".", "closing", "(", "r", ".", "as_stream", "(", ")", ")", "as", "stream", ":", "with", ...
[ 642, 4 ]
[ 660, 54 ]
python
en
['en', 'error', 'th']
False
InstalledDistribution.list_installed_files
(self)
Iterates over the ``RECORD`` entries and returns a tuple ``(path, hash, size)`` for each line. :returns: iterator of (path, hash, size)
Iterates over the ``RECORD`` entries and returns a tuple ``(path, hash, size)`` for each line.
def list_installed_files(self): """ Iterates over the ``RECORD`` entries and returns a tuple ``(path, hash, size)`` for each line. :returns: iterator of (path, hash, size) """ for result in self._get_records(): yield result
[ "def", "list_installed_files", "(", "self", ")", ":", "for", "result", "in", "self", ".", "_get_records", "(", ")", ":", "yield", "result" ]
[ 662, 4 ]
[ 670, 24 ]
python
en
['en', 'error', 'th']
False
InstalledDistribution.write_installed_files
(self, paths, prefix, dry_run=False)
Writes the ``RECORD`` file, using the ``paths`` iterable passed in. Any existing ``RECORD`` file is silently overwritten. prefix is used to determine when to write absolute paths.
Writes the ``RECORD`` file, using the ``paths`` iterable passed in. Any existing ``RECORD`` file is silently overwritten.
def write_installed_files(self, paths, prefix, dry_run=False): """ Writes the ``RECORD`` file, using the ``paths`` iterable passed in. Any existing ``RECORD`` file is silently overwritten. prefix is used to determine when to write absolute paths. """ prefix = os.path.joi...
[ "def", "write_installed_files", "(", "self", ",", "paths", ",", "prefix", ",", "dry_run", "=", "False", ")", ":", "prefix", "=", "os", ".", "path", ".", "join", "(", "prefix", ",", "''", ")", "base", "=", "os", ".", "path", ".", "dirname", "(", "se...
[ 672, 4 ]
[ 705, 26 ]
python
en
['en', 'error', 'th']
False
InstalledDistribution.check_installed_files
(self)
Checks that the hashes and sizes of the files in ``RECORD`` are matched by the files themselves. Returns a (possibly empty) list of mismatches. Each entry in the mismatch list will be a tuple consisting of the path, 'exists', 'size' or 'hash' according to what didn't match (exis...
Checks that the hashes and sizes of the files in ``RECORD`` are matched by the files themselves. Returns a (possibly empty) list of mismatches. Each entry in the mismatch list will be a tuple consisting of the path, 'exists', 'size' or 'hash' according to what didn't match (exis...
def check_installed_files(self): """ Checks that the hashes and sizes of the files in ``RECORD`` are matched by the files themselves. Returns a (possibly empty) list of mismatches. Each entry in the mismatch list will be a tuple consisting of the path, 'exists', 'size' or 'hash' ...
[ "def", "check_installed_files", "(", "self", ")", ":", "mismatches", "=", "[", "]", "base", "=", "os", ".", "path", ".", "dirname", "(", "self", ".", "path", ")", "record_path", "=", "self", ".", "get_distinfo_file", "(", "'RECORD'", ")", "for", "path", ...
[ 707, 4 ]
[ 740, 25 ]
python
en
['en', 'error', 'th']
False
InstalledDistribution.shared_locations
(self)
A dictionary of shared locations whose keys are in the set 'prefix', 'purelib', 'platlib', 'scripts', 'headers', 'data' and 'namespace'. The corresponding value is the absolute path of that category for this distribution, and takes into account any paths selected by the user at ...
A dictionary of shared locations whose keys are in the set 'prefix', 'purelib', 'platlib', 'scripts', 'headers', 'data' and 'namespace'. The corresponding value is the absolute path of that category for this distribution, and takes into account any paths selected by the user at ...
def shared_locations(self): """ A dictionary of shared locations whose keys are in the set 'prefix', 'purelib', 'platlib', 'scripts', 'headers', 'data' and 'namespace'. The corresponding value is the absolute path of that category for this distribution, and takes into account any...
[ "def", "shared_locations", "(", "self", ")", ":", "result", "=", "{", "}", "shared_path", "=", "os", ".", "path", ".", "join", "(", "self", ".", "path", ",", "'SHARED'", ")", "if", "os", ".", "path", ".", "isfile", "(", "shared_path", ")", ":", "wi...
[ 743, 4 ]
[ 767, 21 ]
python
en
['en', 'error', 'th']
False
InstalledDistribution.write_shared_locations
(self, paths, dry_run=False)
Write shared location information to the SHARED file in .dist-info. :param paths: A dictionary as described in the documentation for :meth:`shared_locations`. :param dry_run: If True, the action is logged but no file is actually written. :return: The path...
Write shared location information to the SHARED file in .dist-info. :param paths: A dictionary as described in the documentation for :meth:`shared_locations`. :param dry_run: If True, the action is logged but no file is actually written. :return: The path...
def write_shared_locations(self, paths, dry_run=False): """ Write shared location information to the SHARED file in .dist-info. :param paths: A dictionary as described in the documentation for :meth:`shared_locations`. :param dry_run: If True, the action is logged but no file is ...
[ "def", "write_shared_locations", "(", "self", ",", "paths", ",", "dry_run", "=", "False", ")", ":", "shared_path", "=", "os", ".", "path", ".", "join", "(", "self", ".", "path", ",", "'SHARED'", ")", "logger", ".", "info", "(", "'creating %s'", ",", "s...
[ 769, 4 ]
[ 792, 26 ]
python
en
['en', 'error', 'th']
False
InstalledDistribution.get_distinfo_file
(self, path)
Returns a path located under the ``.dist-info`` directory. Returns a string representing the path. :parameter path: a ``'/'``-separated path relative to the ``.dist-info`` directory or an absolute path; If *path* is an absolute path and doesn't...
Returns a path located under the ``.dist-info`` directory. Returns a string representing the path.
def get_distinfo_file(self, path): """ Returns a path located under the ``.dist-info`` directory. Returns a string representing the path. :parameter path: a ``'/'``-separated path relative to the ``.dist-info`` directory or an absolute path; ...
[ "def", "get_distinfo_file", "(", "self", ",", "path", ")", ":", "# Check if it is an absolute path # XXX use relpath, add tests", "if", "path", ".", "find", "(", "os", ".", "sep", ")", ">=", "0", ":", "# it's an absolute path?", "distinfo_dirname", ",", "path", "="...
[ 803, 4 ]
[ 830, 44 ]
python
en
['en', 'error', 'th']
False
InstalledDistribution.list_distinfo_files
(self)
Iterates over the ``RECORD`` entries and returns paths for each line if the path is pointing to a file located in the ``.dist-info`` directory or one of its subdirectories. :returns: iterator of paths
Iterates over the ``RECORD`` entries and returns paths for each line if the path is pointing to a file located in the ``.dist-info`` directory or one of its subdirectories.
def list_distinfo_files(self): """ Iterates over the ``RECORD`` entries and returns paths for each line if the path is pointing to a file located in the ``.dist-info`` directory or one of its subdirectories. :returns: iterator of paths """ base = os.path.dirname(...
[ "def", "list_distinfo_files", "(", "self", ")", ":", "base", "=", "os", ".", "path", ".", "dirname", "(", "self", ".", "path", ")", "for", "path", ",", "checksum", ",", "size", "in", "self", ".", "_get_records", "(", ")", ":", "# XXX add separator or use...
[ 832, 4 ]
[ 846, 26 ]
python
en
['en', 'error', 'th']
False
EggInfoDistribution.check_installed_files
(self)
Checks that the hashes and sizes of the files in ``RECORD`` are matched by the files themselves. Returns a (possibly empty) list of mismatches. Each entry in the mismatch list will be a tuple consisting of the path, 'exists', 'size' or 'hash' according to what didn't match (exis...
Checks that the hashes and sizes of the files in ``RECORD`` are matched by the files themselves. Returns a (possibly empty) list of mismatches. Each entry in the mismatch list will be a tuple consisting of the path, 'exists', 'size' or 'hash' according to what didn't match (exis...
def check_installed_files(self): """ Checks that the hashes and sizes of the files in ``RECORD`` are matched by the files themselves. Returns a (possibly empty) list of mismatches. Each entry in the mismatch list will be a tuple consisting of the path, 'exists', 'size' or 'hash' ...
[ "def", "check_installed_files", "(", "self", ")", ":", "mismatches", "=", "[", "]", "record_path", "=", "os", ".", "path", ".", "join", "(", "self", ".", "path", ",", "'installed-files.txt'", ")", "if", "os", ".", "path", ".", "exists", "(", "record_path...
[ 983, 4 ]
[ 1000, 25 ]
python
en
['en', 'error', 'th']
False
EggInfoDistribution.list_installed_files
(self)
Iterates over the ``installed-files.txt`` entries and returns a tuple ``(path, hash, size)`` for each line. :returns: a list of (path, hash, size)
Iterates over the ``installed-files.txt`` entries and returns a tuple ``(path, hash, size)`` for each line.
def list_installed_files(self): """ Iterates over the ``installed-files.txt`` entries and returns a tuple ``(path, hash, size)`` for each line. :returns: a list of (path, hash, size) """ def _md5(path): f = open(path, 'rb') try: c...
[ "def", "list_installed_files", "(", "self", ")", ":", "def", "_md5", "(", "path", ")", ":", "f", "=", "open", "(", "path", ",", "'rb'", ")", "try", ":", "content", "=", "f", ".", "read", "(", ")", "finally", ":", "f", ".", "close", "(", ")", "r...
[ 1002, 4 ]
[ 1038, 21 ]
python
en
['en', 'error', 'th']
False
EggInfoDistribution.list_distinfo_files
(self, absolute=False)
Iterates over the ``installed-files.txt`` entries and returns paths for each line if the path is pointing to a file located in the ``.egg-info`` directory or one of its subdirectories. :parameter absolute: If *absolute* is ``True``, each returned path is trans...
Iterates over the ``installed-files.txt`` entries and returns paths for each line if the path is pointing to a file located in the ``.egg-info`` directory or one of its subdirectories.
def list_distinfo_files(self, absolute=False): """ Iterates over the ``installed-files.txt`` entries and returns paths for each line if the path is pointing to a file located in the ``.egg-info`` directory or one of its subdirectories. :parameter absolute: If *absolute* is ``Tru...
[ "def", "list_distinfo_files", "(", "self", ",", "absolute", "=", "False", ")", ":", "record_path", "=", "os", ".", "path", ".", "join", "(", "self", ".", "path", ",", "'installed-files.txt'", ")", "if", "os", ".", "path", ".", "exists", "(", "record_path...
[ 1040, 4 ]
[ 1067, 42 ]
python
en
['en', 'error', 'th']
False
DependencyGraph.add_distribution
(self, distribution)
Add the *distribution* to the graph. :type distribution: :class:`distutils2.database.InstalledDistribution` or :class:`distutils2.database.EggInfoDistribution`
Add the *distribution* to the graph.
def add_distribution(self, distribution): """Add the *distribution* to the graph. :type distribution: :class:`distutils2.database.InstalledDistribution` or :class:`distutils2.database.EggInfoDistribution` """ self.adjacency_list[distribution] = [] sel...
[ "def", "add_distribution", "(", "self", ",", "distribution", ")", ":", "self", ".", "adjacency_list", "[", "distribution", "]", "=", "[", "]", "self", ".", "reverse_list", "[", "distribution", "]", "=", "[", "]" ]
[ 1101, 4 ]
[ 1108, 44 ]
python
en
['en', 'en', 'en']
True
DependencyGraph.add_edge
(self, x, y, label=None)
Add an edge from distribution *x* to distribution *y* with the given *label*. :type x: :class:`distutils2.database.InstalledDistribution` or :class:`distutils2.database.EggInfoDistribution` :type y: :class:`distutils2.database.InstalledDistribution` or :class:`...
Add an edge from distribution *x* to distribution *y* with the given *label*.
def add_edge(self, x, y, label=None): """Add an edge from distribution *x* to distribution *y* with the given *label*. :type x: :class:`distutils2.database.InstalledDistribution` or :class:`distutils2.database.EggInfoDistribution` :type y: :class:`distutils2.database.In...
[ "def", "add_edge", "(", "self", ",", "x", ",", "y", ",", "label", "=", "None", ")", ":", "self", ".", "adjacency_list", "[", "x", "]", ".", "append", "(", "(", "y", ",", "label", ")", ")", "# multiple edges are allowed, so be careful", "if", "x", "not"...
[ 1111, 4 ]
[ 1124, 42 ]
python
en
['en', 'en', 'en']
True
DependencyGraph.add_missing
(self, distribution, requirement)
Add a missing *requirement* for the given *distribution*. :type distribution: :class:`distutils2.database.InstalledDistribution` or :class:`distutils2.database.EggInfoDistribution` :type requirement: ``str``
Add a missing *requirement* for the given *distribution*.
def add_missing(self, distribution, requirement): """ Add a missing *requirement* for the given *distribution*. :type distribution: :class:`distutils2.database.InstalledDistribution` or :class:`distutils2.database.EggInfoDistribution` :type requirement: ``str...
[ "def", "add_missing", "(", "self", ",", "distribution", ",", "requirement", ")", ":", "logger", ".", "debug", "(", "'%s missing %r'", ",", "distribution", ",", "requirement", ")", "self", ".", "missing", ".", "setdefault", "(", "distribution", ",", "[", "]",...
[ 1126, 4 ]
[ 1135, 69 ]
python
en
['en', 'error', 'th']
False
DependencyGraph.repr_node
(self, dist, level=1)
Prints only a subgraph
Prints only a subgraph
def repr_node(self, dist, level=1): """Prints only a subgraph""" output = [self._repr_dist(dist)] for other, label in self.adjacency_list[dist]: dist = self._repr_dist(other) if label is not None: dist = '%s [%s]' % (dist, label) output.append(...
[ "def", "repr_node", "(", "self", ",", "dist", ",", "level", "=", "1", ")", ":", "output", "=", "[", "self", ".", "_repr_dist", "(", "dist", ")", "]", "for", "other", ",", "label", "in", "self", ".", "adjacency_list", "[", "dist", "]", ":", "dist", ...
[ 1140, 4 ]
[ 1151, 32 ]
python
en
['en', 'en', 'en']
True
DependencyGraph.to_dot
(self, f, skip_disconnected=True)
Writes a DOT output for the graph to the provided file *f*. If *skip_disconnected* is set to ``True``, then all distributions that are not dependent on any other distribution are skipped. :type f: has to support ``file``-like operations :type skip_disconnected: ``bool``
Writes a DOT output for the graph to the provided file *f*.
def to_dot(self, f, skip_disconnected=True): """Writes a DOT output for the graph to the provided file *f*. If *skip_disconnected* is set to ``True``, then all distributions that are not dependent on any other distribution are skipped. :type f: has to support ``file``-like operations ...
[ "def", "to_dot", "(", "self", ",", "f", ",", "skip_disconnected", "=", "True", ")", ":", "disconnected", "=", "[", "]", "f", ".", "write", "(", "\"digraph dependencies {\\n\"", ")", "for", "dist", ",", "adjs", "in", "self", ".", "adjacency_list", ".", "i...
[ 1153, 4 ]
[ 1183, 22 ]
python
en
['en', 'en', 'en']
True
DependencyGraph.topological_sort
(self)
Perform a topological sort of the graph. :return: A tuple, the first element of which is a topologically sorted list of distributions, and the second element of which is a list of distributions that cannot be sorted because they have circular dependenc...
Perform a topological sort of the graph. :return: A tuple, the first element of which is a topologically sorted list of distributions, and the second element of which is a list of distributions that cannot be sorted because they have circular dependenc...
def topological_sort(self): """ Perform a topological sort of the graph. :return: A tuple, the first element of which is a topologically sorted list of distributions, and the second element of which is a list of distributions that cannot be sorted because they h...
[ "def", "topological_sort", "(", "self", ")", ":", "result", "=", "[", "]", "# Make a shallow copy of the adjacency list", "alist", "=", "{", "}", "for", "k", ",", "v", "in", "self", ".", "adjacency_list", ".", "items", "(", ")", ":", "alist", "[", "k", "...
[ 1185, 4 ]
[ 1214, 41 ]
python
en
['en', 'error', 'th']
False
DependencyGraph.__repr__
(self)
Representation of the graph
Representation of the graph
def __repr__(self): """Representation of the graph""" output = [] for dist, adjs in self.adjacency_list.items(): output.append(self.repr_node(dist)) return '\n'.join(output)
[ "def", "__repr__", "(", "self", ")", ":", "output", "=", "[", "]", "for", "dist", ",", "adjs", "in", "self", ".", "adjacency_list", ".", "items", "(", ")", ":", "output", ".", "append", "(", "self", ".", "repr_node", "(", "dist", ")", ")", "return"...
[ 1216, 4 ]
[ 1221, 32 ]
python
en
['en', 'en', 'en']
True
iri2uri
(uri)
Convert an IRI to a URI. Note that IRIs must be passed in a unicode strings. That is, do not utf-8 encode the IRI before passing it into the function.
Convert an IRI to a URI. Note that IRIs must be passed in a unicode strings. That is, do not utf-8 encode the IRI before passing it into the function.
def iri2uri(uri): """Convert an IRI to a URI. Note that IRIs must be passed in a unicode strings. That is, do not utf-8 encode the IRI before passing it into the function.""" if isinstance(uri, unicode): (scheme, authority, path, query, fragment) = urlparse.urlsplit(uri) authority = auth...
[ "def", "iri2uri", "(", "uri", ")", ":", "if", "isinstance", "(", "uri", ",", "unicode", ")", ":", "(", "scheme", ",", "authority", ",", "path", ",", "query", ",", "fragment", ")", "=", "urlparse", ".", "urlsplit", "(", "uri", ")", "authority", "=", ...
[ 58, 0 ]
[ 70, 14 ]
python
en
['en', 'lb', 'en']
True
setup_module_logger
(name)
Set up module level logging with formatting
Set up module level logging with formatting
def setup_module_logger(name): """Set up module level logging with formatting""" logger = logging.getLogger(name) ch = logging.StreamHandler() # Really should not be configuring formats in a library, see # https://docs.python.org/3/howto/logging.html#configuring-logging-for-a-library formatter =...
[ "def", "setup_module_logger", "(", "name", ")", ":", "logger", "=", "logging", ".", "getLogger", "(", "name", ")", "ch", "=", "logging", ".", "StreamHandler", "(", ")", "# Really should not be configuring formats in a library, see", "# https://docs.python.org/3/howto/logg...
[ 19, 0 ]
[ 29, 25 ]
python
en
['en', 'en', 'en']
True
get_mx_ip
(hostname)
Get MX record by hostname.
Get MX record by hostname.
async def get_mx_ip(hostname): '''Get MX record by hostname. ''' if hostname not in MX_DNS_CACHE: try: resolver = aiodns.DNSResolver() MX_DNS_CACHE[hostname] = await resolver.query(hostname, 'MX') except aiodns.error.DNSError as e: MX_DNS_CACHE[hostname] ...
[ "async", "def", "get_mx_ip", "(", "hostname", ")", ":", "if", "hostname", "not", "in", "MX_DNS_CACHE", ":", "try", ":", "resolver", "=", "aiodns", ".", "DNSResolver", "(", ")", "MX_DNS_CACHE", "[", "hostname", "]", "=", "await", "resolver", ".", "query", ...
[ 38, 0 ]
[ 47, 33 ]
python
en
['en', 'en', 'en']
True