repo stringlengths 7 55 | path stringlengths 4 127 | func_name stringlengths 1 88 | original_string stringlengths 75 19.8k | language stringclasses 1
value | code stringlengths 75 19.8k | code_tokens list | docstring stringlengths 3 17.3k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 87 242 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
marshmallow-code/apispec | src/apispec/ext/marshmallow/openapi.py | OpenAPIConverter.field2choices | def field2choices(self, field, **kwargs):
"""Return the dictionary of OpenAPI field attributes for valid choices definition
:param Field field: A marshmallow field.
:rtype: dict
"""
attributes = {}
comparable = [
validator.comparable
for validato... | python | def field2choices(self, field, **kwargs):
"""Return the dictionary of OpenAPI field attributes for valid choices definition
:param Field field: A marshmallow field.
:rtype: dict
"""
attributes = {}
comparable = [
validator.comparable
for validato... | [
"def",
"field2choices",
"(",
"self",
",",
"field",
",",
"**",
"kwargs",
")",
":",
"attributes",
"=",
"{",
"}",
"comparable",
"=",
"[",
"validator",
".",
"comparable",
"for",
"validator",
"in",
"field",
".",
"validators",
"if",
"hasattr",
"(",
"validator",
... | Return the dictionary of OpenAPI field attributes for valid choices definition
:param Field field: A marshmallow field.
:rtype: dict | [
"Return",
"the",
"dictionary",
"of",
"OpenAPI",
"field",
"attributes",
"for",
"valid",
"choices",
"definition"
] | e92ceffd12b2e392b8d199ed314bd2a7e6512dff | https://github.com/marshmallow-code/apispec/blob/e92ceffd12b2e392b8d199ed314bd2a7e6512dff/src/apispec/ext/marshmallow/openapi.py#L208-L232 | train |
marshmallow-code/apispec | src/apispec/ext/marshmallow/openapi.py | OpenAPIConverter.field2read_only | def field2read_only(self, field, **kwargs):
"""Return the dictionary of OpenAPI field attributes for a dump_only field.
:param Field field: A marshmallow field.
:rtype: dict
"""
attributes = {}
if field.dump_only:
attributes["readOnly"] = True
return ... | python | def field2read_only(self, field, **kwargs):
"""Return the dictionary of OpenAPI field attributes for a dump_only field.
:param Field field: A marshmallow field.
:rtype: dict
"""
attributes = {}
if field.dump_only:
attributes["readOnly"] = True
return ... | [
"def",
"field2read_only",
"(",
"self",
",",
"field",
",",
"**",
"kwargs",
")",
":",
"attributes",
"=",
"{",
"}",
"if",
"field",
".",
"dump_only",
":",
"attributes",
"[",
"\"readOnly\"",
"]",
"=",
"True",
"return",
"attributes"
] | Return the dictionary of OpenAPI field attributes for a dump_only field.
:param Field field: A marshmallow field.
:rtype: dict | [
"Return",
"the",
"dictionary",
"of",
"OpenAPI",
"field",
"attributes",
"for",
"a",
"dump_only",
"field",
"."
] | e92ceffd12b2e392b8d199ed314bd2a7e6512dff | https://github.com/marshmallow-code/apispec/blob/e92ceffd12b2e392b8d199ed314bd2a7e6512dff/src/apispec/ext/marshmallow/openapi.py#L234-L243 | train |
marshmallow-code/apispec | src/apispec/ext/marshmallow/openapi.py | OpenAPIConverter.field2write_only | def field2write_only(self, field, **kwargs):
"""Return the dictionary of OpenAPI field attributes for a load_only field.
:param Field field: A marshmallow field.
:rtype: dict
"""
attributes = {}
if field.load_only and self.openapi_version.major >= 3:
attribut... | python | def field2write_only(self, field, **kwargs):
"""Return the dictionary of OpenAPI field attributes for a load_only field.
:param Field field: A marshmallow field.
:rtype: dict
"""
attributes = {}
if field.load_only and self.openapi_version.major >= 3:
attribut... | [
"def",
"field2write_only",
"(",
"self",
",",
"field",
",",
"**",
"kwargs",
")",
":",
"attributes",
"=",
"{",
"}",
"if",
"field",
".",
"load_only",
"and",
"self",
".",
"openapi_version",
".",
"major",
">=",
"3",
":",
"attributes",
"[",
"\"writeOnly\"",
"]... | Return the dictionary of OpenAPI field attributes for a load_only field.
:param Field field: A marshmallow field.
:rtype: dict | [
"Return",
"the",
"dictionary",
"of",
"OpenAPI",
"field",
"attributes",
"for",
"a",
"load_only",
"field",
"."
] | e92ceffd12b2e392b8d199ed314bd2a7e6512dff | https://github.com/marshmallow-code/apispec/blob/e92ceffd12b2e392b8d199ed314bd2a7e6512dff/src/apispec/ext/marshmallow/openapi.py#L245-L254 | train |
marshmallow-code/apispec | src/apispec/ext/marshmallow/openapi.py | OpenAPIConverter.field2nullable | def field2nullable(self, field, **kwargs):
"""Return the dictionary of OpenAPI field attributes for a nullable field.
:param Field field: A marshmallow field.
:rtype: dict
"""
attributes = {}
if field.allow_none:
attributes[
"x-nullable" if se... | python | def field2nullable(self, field, **kwargs):
"""Return the dictionary of OpenAPI field attributes for a nullable field.
:param Field field: A marshmallow field.
:rtype: dict
"""
attributes = {}
if field.allow_none:
attributes[
"x-nullable" if se... | [
"def",
"field2nullable",
"(",
"self",
",",
"field",
",",
"**",
"kwargs",
")",
":",
"attributes",
"=",
"{",
"}",
"if",
"field",
".",
"allow_none",
":",
"attributes",
"[",
"\"x-nullable\"",
"if",
"self",
".",
"openapi_version",
".",
"major",
"<",
"3",
"els... | Return the dictionary of OpenAPI field attributes for a nullable field.
:param Field field: A marshmallow field.
:rtype: dict | [
"Return",
"the",
"dictionary",
"of",
"OpenAPI",
"field",
"attributes",
"for",
"a",
"nullable",
"field",
"."
] | e92ceffd12b2e392b8d199ed314bd2a7e6512dff | https://github.com/marshmallow-code/apispec/blob/e92ceffd12b2e392b8d199ed314bd2a7e6512dff/src/apispec/ext/marshmallow/openapi.py#L256-L267 | train |
marshmallow-code/apispec | src/apispec/ext/marshmallow/openapi.py | OpenAPIConverter.metadata2properties | def metadata2properties(self, field):
"""Return a dictionary of properties extracted from field Metadata
Will include field metadata that are valid properties of `OpenAPI schema
objects
<https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#schemaObject>`_
(... | python | def metadata2properties(self, field):
"""Return a dictionary of properties extracted from field Metadata
Will include field metadata that are valid properties of `OpenAPI schema
objects
<https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#schemaObject>`_
(... | [
"def",
"metadata2properties",
"(",
"self",
",",
"field",
")",
":",
"metadata",
"=",
"{",
"key",
".",
"replace",
"(",
"\"_\"",
",",
"\"-\"",
")",
"if",
"key",
".",
"startswith",
"(",
"\"x_\"",
")",
"else",
"key",
":",
"value",
"for",
"key",
",",
"valu... | Return a dictionary of properties extracted from field Metadata
Will include field metadata that are valid properties of `OpenAPI schema
objects
<https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#schemaObject>`_
(e.g. “description”, “enum”, “example”).
... | [
"Return",
"a",
"dictionary",
"of",
"properties",
"extracted",
"from",
"field",
"Metadata"
] | e92ceffd12b2e392b8d199ed314bd2a7e6512dff | https://github.com/marshmallow-code/apispec/blob/e92ceffd12b2e392b8d199ed314bd2a7e6512dff/src/apispec/ext/marshmallow/openapi.py#L367-L396 | train |
marshmallow-code/apispec | src/apispec/ext/marshmallow/openapi.py | OpenAPIConverter.resolve_nested_schema | def resolve_nested_schema(self, schema):
"""Return the Open API representation of a marshmallow Schema.
Adds the schema to the spec if it isn't already present.
Typically will return a dictionary with the reference to the schema's
path in the spec unless the `schema_name_resolver` retu... | python | def resolve_nested_schema(self, schema):
"""Return the Open API representation of a marshmallow Schema.
Adds the schema to the spec if it isn't already present.
Typically will return a dictionary with the reference to the schema's
path in the spec unless the `schema_name_resolver` retu... | [
"def",
"resolve_nested_schema",
"(",
"self",
",",
"schema",
")",
":",
"schema_instance",
"=",
"resolve_schema_instance",
"(",
"schema",
")",
"schema_key",
"=",
"make_schema_key",
"(",
"schema_instance",
")",
"if",
"schema_key",
"not",
"in",
"self",
".",
"refs",
... | Return the Open API representation of a marshmallow Schema.
Adds the schema to the spec if it isn't already present.
Typically will return a dictionary with the reference to the schema's
path in the spec unless the `schema_name_resolver` returns `None`, in
which case the returned dicto... | [
"Return",
"the",
"Open",
"API",
"representation",
"of",
"a",
"marshmallow",
"Schema",
"."
] | e92ceffd12b2e392b8d199ed314bd2a7e6512dff | https://github.com/marshmallow-code/apispec/blob/e92ceffd12b2e392b8d199ed314bd2a7e6512dff/src/apispec/ext/marshmallow/openapi.py#L444-L477 | train |
marshmallow-code/apispec | src/apispec/ext/marshmallow/openapi.py | OpenAPIConverter.property2parameter | def property2parameter(
self,
prop,
name="body",
required=False,
multiple=False,
location=None,
default_in="body",
):
"""Return the Parameter Object definition for a JSON Schema property.
https://github.com/OAI/OpenAPI-Specification/blob/maste... | python | def property2parameter(
self,
prop,
name="body",
required=False,
multiple=False,
location=None,
default_in="body",
):
"""Return the Parameter Object definition for a JSON Schema property.
https://github.com/OAI/OpenAPI-Specification/blob/maste... | [
"def",
"property2parameter",
"(",
"self",
",",
"prop",
",",
"name",
"=",
"\"body\"",
",",
"required",
"=",
"False",
",",
"multiple",
"=",
"False",
",",
"location",
"=",
"None",
",",
"default_in",
"=",
"\"body\"",
",",
")",
":",
"openapi_default_in",
"=",
... | Return the Parameter Object definition for a JSON Schema property.
https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#parameterObject
:param dict prop: JSON Schema property
:param str name: Field name
:param bool required: Parameter is required
:param bo... | [
"Return",
"the",
"Parameter",
"Object",
"definition",
"for",
"a",
"JSON",
"Schema",
"property",
"."
] | e92ceffd12b2e392b8d199ed314bd2a7e6512dff | https://github.com/marshmallow-code/apispec/blob/e92ceffd12b2e392b8d199ed314bd2a7e6512dff/src/apispec/ext/marshmallow/openapi.py#L571-L619 | train |
marshmallow-code/apispec | src/apispec/ext/marshmallow/openapi.py | OpenAPIConverter.get_ref_dict | def get_ref_dict(self, schema):
"""Method to create a dictionary containing a JSON reference to the
schema in the spec
"""
schema_key = make_schema_key(schema)
ref_schema = build_reference(
"schema", self.openapi_version.major, self.refs[schema_key]
)
... | python | def get_ref_dict(self, schema):
"""Method to create a dictionary containing a JSON reference to the
schema in the spec
"""
schema_key = make_schema_key(schema)
ref_schema = build_reference(
"schema", self.openapi_version.major, self.refs[schema_key]
)
... | [
"def",
"get_ref_dict",
"(",
"self",
",",
"schema",
")",
":",
"schema_key",
"=",
"make_schema_key",
"(",
"schema",
")",
"ref_schema",
"=",
"build_reference",
"(",
"\"schema\"",
",",
"self",
".",
"openapi_version",
".",
"major",
",",
"self",
".",
"refs",
"[",
... | Method to create a dictionary containing a JSON reference to the
schema in the spec | [
"Method",
"to",
"create",
"a",
"dictionary",
"containing",
"a",
"JSON",
"reference",
"to",
"the",
"schema",
"in",
"the",
"spec"
] | e92ceffd12b2e392b8d199ed314bd2a7e6512dff | https://github.com/marshmallow-code/apispec/blob/e92ceffd12b2e392b8d199ed314bd2a7e6512dff/src/apispec/ext/marshmallow/openapi.py#L696-L706 | train |
marshmallow-code/apispec | src/apispec/core.py | clean_operations | def clean_operations(operations, openapi_major_version):
"""Ensure that all parameters with "in" equal to "path" are also required
as required by the OpenAPI specification, as well as normalizing any
references to global parameters. Also checks for invalid HTTP methods.
See https://github.com/OAI/OpenA... | python | def clean_operations(operations, openapi_major_version):
"""Ensure that all parameters with "in" equal to "path" are also required
as required by the OpenAPI specification, as well as normalizing any
references to global parameters. Also checks for invalid HTTP methods.
See https://github.com/OAI/OpenA... | [
"def",
"clean_operations",
"(",
"operations",
",",
"openapi_major_version",
")",
":",
"invalid",
"=",
"{",
"key",
"for",
"key",
"in",
"set",
"(",
"iterkeys",
"(",
"operations",
")",
")",
"-",
"set",
"(",
"VALID_METHODS",
"[",
"openapi_major_version",
"]",
")... | Ensure that all parameters with "in" equal to "path" are also required
as required by the OpenAPI specification, as well as normalizing any
references to global parameters. Also checks for invalid HTTP methods.
See https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#parameterObject.
... | [
"Ensure",
"that",
"all",
"parameters",
"with",
"in",
"equal",
"to",
"path",
"are",
"also",
"required",
"as",
"required",
"by",
"the",
"OpenAPI",
"specification",
"as",
"well",
"as",
"normalizing",
"any",
"references",
"to",
"global",
"parameters",
".",
"Also",... | e92ceffd12b2e392b8d199ed314bd2a7e6512dff | https://github.com/marshmallow-code/apispec/blob/e92ceffd12b2e392b8d199ed314bd2a7e6512dff/src/apispec/core.py#L21-L82 | train |
marshmallow-code/apispec | src/apispec/core.py | Components.schema | def schema(self, name, component=None, **kwargs):
"""Add a new schema to the spec.
:param str name: identifier by which schema may be referenced.
:param dict component: schema definition.
.. note::
If you are using `apispec.ext.marshmallow`, you can pass fields' metadata a... | python | def schema(self, name, component=None, **kwargs):
"""Add a new schema to the spec.
:param str name: identifier by which schema may be referenced.
:param dict component: schema definition.
.. note::
If you are using `apispec.ext.marshmallow`, you can pass fields' metadata a... | [
"def",
"schema",
"(",
"self",
",",
"name",
",",
"component",
"=",
"None",
",",
"**",
"kwargs",
")",
":",
"if",
"name",
"in",
"self",
".",
"_schemas",
":",
"raise",
"DuplicateComponentNameError",
"(",
"'Another schema with name \"{}\" is already registered.'",
".",... | Add a new schema to the spec.
:param str name: identifier by which schema may be referenced.
:param dict component: schema definition.
.. note::
If you are using `apispec.ext.marshmallow`, you can pass fields' metadata as
additional keyword arguments.
For ... | [
"Add",
"a",
"new",
"schema",
"to",
"the",
"spec",
"."
] | e92ceffd12b2e392b8d199ed314bd2a7e6512dff | https://github.com/marshmallow-code/apispec/blob/e92ceffd12b2e392b8d199ed314bd2a7e6512dff/src/apispec/core.py#L113-L147 | train |
marshmallow-code/apispec | src/apispec/core.py | Components.parameter | def parameter(self, component_id, location, component=None, **kwargs):
""" Add a parameter which can be referenced.
:param str param_id: identifier by which parameter may be referenced.
:param str location: location of the parameter.
:param dict component: parameter fields.
:par... | python | def parameter(self, component_id, location, component=None, **kwargs):
""" Add a parameter which can be referenced.
:param str param_id: identifier by which parameter may be referenced.
:param str location: location of the parameter.
:param dict component: parameter fields.
:par... | [
"def",
"parameter",
"(",
"self",
",",
"component_id",
",",
"location",
",",
"component",
"=",
"None",
",",
"**",
"kwargs",
")",
":",
"if",
"component_id",
"in",
"self",
".",
"_parameters",
":",
"raise",
"DuplicateComponentNameError",
"(",
"'Another parameter wit... | Add a parameter which can be referenced.
:param str param_id: identifier by which parameter may be referenced.
:param str location: location of the parameter.
:param dict component: parameter fields.
:param dict kwargs: plugin-specific arguments | [
"Add",
"a",
"parameter",
"which",
"can",
"be",
"referenced",
"."
] | e92ceffd12b2e392b8d199ed314bd2a7e6512dff | https://github.com/marshmallow-code/apispec/blob/e92ceffd12b2e392b8d199ed314bd2a7e6512dff/src/apispec/core.py#L149-L174 | train |
marshmallow-code/apispec | src/apispec/core.py | Components.response | def response(self, component_id, component=None, **kwargs):
"""Add a response which can be referenced.
:param str component_id: ref_id to use as reference
:param dict component: response fields
:param dict kwargs: plugin-specific arguments
"""
if component_id in self._re... | python | def response(self, component_id, component=None, **kwargs):
"""Add a response which can be referenced.
:param str component_id: ref_id to use as reference
:param dict component: response fields
:param dict kwargs: plugin-specific arguments
"""
if component_id in self._re... | [
"def",
"response",
"(",
"self",
",",
"component_id",
",",
"component",
"=",
"None",
",",
"**",
"kwargs",
")",
":",
"if",
"component_id",
"in",
"self",
".",
"_responses",
":",
"raise",
"DuplicateComponentNameError",
"(",
"'Another response with name \"{}\" is already... | Add a response which can be referenced.
:param str component_id: ref_id to use as reference
:param dict component: response fields
:param dict kwargs: plugin-specific arguments | [
"Add",
"a",
"response",
"which",
"can",
"be",
"referenced",
"."
] | e92ceffd12b2e392b8d199ed314bd2a7e6512dff | https://github.com/marshmallow-code/apispec/blob/e92ceffd12b2e392b8d199ed314bd2a7e6512dff/src/apispec/core.py#L176-L198 | train |
marshmallow-code/apispec | src/apispec/core.py | Components.security_scheme | def security_scheme(self, component_id, component):
"""Add a security scheme which can be referenced.
:param str component_id: component_id to use as reference
:param dict kwargs: security scheme fields
"""
if component_id in self._security_schemes:
raise DuplicateCo... | python | def security_scheme(self, component_id, component):
"""Add a security scheme which can be referenced.
:param str component_id: component_id to use as reference
:param dict kwargs: security scheme fields
"""
if component_id in self._security_schemes:
raise DuplicateCo... | [
"def",
"security_scheme",
"(",
"self",
",",
"component_id",
",",
"component",
")",
":",
"if",
"component_id",
"in",
"self",
".",
"_security_schemes",
":",
"raise",
"DuplicateComponentNameError",
"(",
"'Another security scheme with name \"{}\" is already registered.'",
".",
... | Add a security scheme which can be referenced.
:param str component_id: component_id to use as reference
:param dict kwargs: security scheme fields | [
"Add",
"a",
"security",
"scheme",
"which",
"can",
"be",
"referenced",
"."
] | e92ceffd12b2e392b8d199ed314bd2a7e6512dff | https://github.com/marshmallow-code/apispec/blob/e92ceffd12b2e392b8d199ed314bd2a7e6512dff/src/apispec/core.py#L200-L213 | train |
marshmallow-code/apispec | src/apispec/core.py | APISpec.path | def path(
self, path=None, operations=None, summary=None, description=None, **kwargs
):
"""Add a new path object to the spec.
https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#path-item-object
:param str|None path: URL path component
:param dict|Non... | python | def path(
self, path=None, operations=None, summary=None, description=None, **kwargs
):
"""Add a new path object to the spec.
https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#path-item-object
:param str|None path: URL path component
:param dict|Non... | [
"def",
"path",
"(",
"self",
",",
"path",
"=",
"None",
",",
"operations",
"=",
"None",
",",
"summary",
"=",
"None",
",",
"description",
"=",
"None",
",",
"**",
"kwargs",
")",
":",
"operations",
"=",
"operations",
"or",
"OrderedDict",
"(",
")",
"for",
... | Add a new path object to the spec.
https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#path-item-object
:param str|None path: URL path component
:param dict|None operations: describes the http methods and options for `path`
:param str summary: short summary relev... | [
"Add",
"a",
"new",
"path",
"object",
"to",
"the",
"spec",
"."
] | e92ceffd12b2e392b8d199ed314bd2a7e6512dff | https://github.com/marshmallow-code/apispec/blob/e92ceffd12b2e392b8d199ed314bd2a7e6512dff/src/apispec/core.py#L279-L319 | train |
marshmallow-code/apispec | src/apispec/ext/marshmallow/__init__.py | resolver | def resolver(schema):
"""Default implementation of a schema name resolver function
"""
name = schema.__name__
if name.endswith("Schema"):
return name[:-6] or name
return name | python | def resolver(schema):
"""Default implementation of a schema name resolver function
"""
name = schema.__name__
if name.endswith("Schema"):
return name[:-6] or name
return name | [
"def",
"resolver",
"(",
"schema",
")",
":",
"name",
"=",
"schema",
".",
"__name__",
"if",
"name",
".",
"endswith",
"(",
"\"Schema\"",
")",
":",
"return",
"name",
"[",
":",
"-",
"6",
"]",
"or",
"name",
"return",
"name"
] | Default implementation of a schema name resolver function | [
"Default",
"implementation",
"of",
"a",
"schema",
"name",
"resolver",
"function"
] | e92ceffd12b2e392b8d199ed314bd2a7e6512dff | https://github.com/marshmallow-code/apispec/blob/e92ceffd12b2e392b8d199ed314bd2a7e6512dff/src/apispec/ext/marshmallow/__init__.py#L43-L49 | train |
marshmallow-code/apispec | src/apispec/ext/marshmallow/__init__.py | MarshmallowPlugin.resolve_schema_in_request_body | def resolve_schema_in_request_body(self, request_body):
"""Function to resolve a schema in a requestBody object - modifies then
response dict to convert Marshmallow Schema object or class into dict
"""
content = request_body["content"]
for content_type in content:
sch... | python | def resolve_schema_in_request_body(self, request_body):
"""Function to resolve a schema in a requestBody object - modifies then
response dict to convert Marshmallow Schema object or class into dict
"""
content = request_body["content"]
for content_type in content:
sch... | [
"def",
"resolve_schema_in_request_body",
"(",
"self",
",",
"request_body",
")",
":",
"content",
"=",
"request_body",
"[",
"\"content\"",
"]",
"for",
"content_type",
"in",
"content",
":",
"schema",
"=",
"content",
"[",
"content_type",
"]",
"[",
"\"schema\"",
"]",... | Function to resolve a schema in a requestBody object - modifies then
response dict to convert Marshmallow Schema object or class into dict | [
"Function",
"to",
"resolve",
"a",
"schema",
"in",
"a",
"requestBody",
"object",
"-",
"modifies",
"then",
"response",
"dict",
"to",
"convert",
"Marshmallow",
"Schema",
"object",
"or",
"class",
"into",
"dict"
] | e92ceffd12b2e392b8d199ed314bd2a7e6512dff | https://github.com/marshmallow-code/apispec/blob/e92ceffd12b2e392b8d199ed314bd2a7e6512dff/src/apispec/ext/marshmallow/__init__.py#L100-L107 | train |
marshmallow-code/apispec | src/apispec/ext/marshmallow/__init__.py | MarshmallowPlugin.resolve_schema | def resolve_schema(self, data):
"""Function to resolve a schema in a parameter or response - modifies the
corresponding dict to convert Marshmallow Schema object or class into dict
:param APISpec spec: `APISpec` containing refs.
:param dict|str data: either a parameter or response dicti... | python | def resolve_schema(self, data):
"""Function to resolve a schema in a parameter or response - modifies the
corresponding dict to convert Marshmallow Schema object or class into dict
:param APISpec spec: `APISpec` containing refs.
:param dict|str data: either a parameter or response dicti... | [
"def",
"resolve_schema",
"(",
"self",
",",
"data",
")",
":",
"if",
"not",
"isinstance",
"(",
"data",
",",
"dict",
")",
":",
"return",
"if",
"\"schema\"",
"in",
"data",
":",
"data",
"[",
"\"schema\"",
"]",
"=",
"self",
".",
"openapi",
".",
"resolve_sche... | Function to resolve a schema in a parameter or response - modifies the
corresponding dict to convert Marshmallow Schema object or class into dict
:param APISpec spec: `APISpec` containing refs.
:param dict|str data: either a parameter or response dictionary that may
contain a schema... | [
"Function",
"to",
"resolve",
"a",
"schema",
"in",
"a",
"parameter",
"or",
"response",
"-",
"modifies",
"the",
"corresponding",
"dict",
"to",
"convert",
"Marshmallow",
"Schema",
"object",
"or",
"class",
"into",
"dict"
] | e92ceffd12b2e392b8d199ed314bd2a7e6512dff | https://github.com/marshmallow-code/apispec/blob/e92ceffd12b2e392b8d199ed314bd2a7e6512dff/src/apispec/ext/marshmallow/__init__.py#L109-L130 | train |
marshmallow-code/apispec | src/apispec/ext/marshmallow/__init__.py | MarshmallowPlugin.warn_if_schema_already_in_spec | def warn_if_schema_already_in_spec(self, schema_key):
"""Method to warn the user if the schema has already been added to the
spec.
"""
if schema_key in self.openapi.refs:
warnings.warn(
"{} has already been added to the spec. Adding it twice may "
... | python | def warn_if_schema_already_in_spec(self, schema_key):
"""Method to warn the user if the schema has already been added to the
spec.
"""
if schema_key in self.openapi.refs:
warnings.warn(
"{} has already been added to the spec. Adding it twice may "
... | [
"def",
"warn_if_schema_already_in_spec",
"(",
"self",
",",
"schema_key",
")",
":",
"if",
"schema_key",
"in",
"self",
".",
"openapi",
".",
"refs",
":",
"warnings",
".",
"warn",
"(",
"\"{} has already been added to the spec. Adding it twice may \"",
"\"cause references to n... | Method to warn the user if the schema has already been added to the
spec. | [
"Method",
"to",
"warn",
"the",
"user",
"if",
"the",
"schema",
"has",
"already",
"been",
"added",
"to",
"the",
"spec",
"."
] | e92ceffd12b2e392b8d199ed314bd2a7e6512dff | https://github.com/marshmallow-code/apispec/blob/e92ceffd12b2e392b8d199ed314bd2a7e6512dff/src/apispec/ext/marshmallow/__init__.py#L213-L222 | train |
flyingrub/scdl | scdl/utils.py | size_in_bytes | def size_in_bytes(insize):
"""
Returns the size in bytes from strings such as '5 mb' into 5242880.
>>> size_in_bytes('1m')
1048576
>>> size_in_bytes('1.5m')
1572864
>>> size_in_bytes('2g')
2147483648
>>> size_in_bytes(None)
Traceback (most recent call last):
raise ValueE... | python | def size_in_bytes(insize):
"""
Returns the size in bytes from strings such as '5 mb' into 5242880.
>>> size_in_bytes('1m')
1048576
>>> size_in_bytes('1.5m')
1572864
>>> size_in_bytes('2g')
2147483648
>>> size_in_bytes(None)
Traceback (most recent call last):
raise ValueE... | [
"def",
"size_in_bytes",
"(",
"insize",
")",
":",
"if",
"insize",
"is",
"None",
"or",
"insize",
".",
"strip",
"(",
")",
"==",
"''",
":",
"raise",
"ValueError",
"(",
"'no string specified'",
")",
"units",
"=",
"{",
"'k'",
":",
"1024",
",",
"'m'",
":",
... | Returns the size in bytes from strings such as '5 mb' into 5242880.
>>> size_in_bytes('1m')
1048576
>>> size_in_bytes('1.5m')
1572864
>>> size_in_bytes('2g')
2147483648
>>> size_in_bytes(None)
Traceback (most recent call last):
raise ValueError('no string specified')
ValueEr... | [
"Returns",
"the",
"size",
"in",
"bytes",
"from",
"strings",
"such",
"as",
"5",
"mb",
"into",
"5242880",
"."
] | e833a22dd6676311b72fadd8a1c80f4a06acfad9 | https://github.com/flyingrub/scdl/blob/e833a22dd6676311b72fadd8a1c80f4a06acfad9/scdl/utils.py#L31-L73 | train |
flyingrub/scdl | scdl/scdl.py | main | def main():
"""
Main function, parses the URL from command line arguments
"""
signal.signal(signal.SIGINT, signal_handler)
global offset
global arguments
# Parse argument
arguments = docopt(__doc__, version=__version__)
if arguments['--debug']:
logger.level = logging.DEBUG
... | python | def main():
"""
Main function, parses the URL from command line arguments
"""
signal.signal(signal.SIGINT, signal_handler)
global offset
global arguments
# Parse argument
arguments = docopt(__doc__, version=__version__)
if arguments['--debug']:
logger.level = logging.DEBUG
... | [
"def",
"main",
"(",
")",
":",
"signal",
".",
"signal",
"(",
"signal",
".",
"SIGINT",
",",
"signal_handler",
")",
"global",
"offset",
"global",
"arguments",
"arguments",
"=",
"docopt",
"(",
"__doc__",
",",
"version",
"=",
"__version__",
")",
"if",
"argument... | Main function, parses the URL from command line arguments | [
"Main",
"function",
"parses",
"the",
"URL",
"from",
"command",
"line",
"arguments"
] | e833a22dd6676311b72fadd8a1c80f4a06acfad9 | https://github.com/flyingrub/scdl/blob/e833a22dd6676311b72fadd8a1c80f4a06acfad9/scdl/scdl.py#L111-L195 | train |
flyingrub/scdl | scdl/scdl.py | get_config | def get_config():
"""
Reads the music download filepath from scdl.cfg
"""
global token
config = configparser.ConfigParser()
config.read(os.path.join(os.path.expanduser('~'), '.config/scdl/scdl.cfg'))
try:
token = config['scdl']['auth_token']
path = config['scdl']['path']
... | python | def get_config():
"""
Reads the music download filepath from scdl.cfg
"""
global token
config = configparser.ConfigParser()
config.read(os.path.join(os.path.expanduser('~'), '.config/scdl/scdl.cfg'))
try:
token = config['scdl']['auth_token']
path = config['scdl']['path']
... | [
"def",
"get_config",
"(",
")",
":",
"global",
"token",
"config",
"=",
"configparser",
".",
"ConfigParser",
"(",
")",
"config",
".",
"read",
"(",
"os",
".",
"path",
".",
"join",
"(",
"os",
".",
"path",
".",
"expanduser",
"(",
"'~'",
")",
",",
"'.confi... | Reads the music download filepath from scdl.cfg | [
"Reads",
"the",
"music",
"download",
"filepath",
"from",
"scdl",
".",
"cfg"
] | e833a22dd6676311b72fadd8a1c80f4a06acfad9 | https://github.com/flyingrub/scdl/blob/e833a22dd6676311b72fadd8a1c80f4a06acfad9/scdl/scdl.py#L198-L216 | train |
flyingrub/scdl | scdl/scdl.py | get_item | def get_item(track_url, client_id=CLIENT_ID):
"""
Fetches metadata for a track or playlist
"""
try:
item_url = url['resolve'].format(track_url)
r = requests.get(item_url, params={'client_id': client_id})
logger.debug(r.url)
if r.status_code == 403:
return get... | python | def get_item(track_url, client_id=CLIENT_ID):
"""
Fetches metadata for a track or playlist
"""
try:
item_url = url['resolve'].format(track_url)
r = requests.get(item_url, params={'client_id': client_id})
logger.debug(r.url)
if r.status_code == 403:
return get... | [
"def",
"get_item",
"(",
"track_url",
",",
"client_id",
"=",
"CLIENT_ID",
")",
":",
"try",
":",
"item_url",
"=",
"url",
"[",
"'resolve'",
"]",
".",
"format",
"(",
"track_url",
")",
"r",
"=",
"requests",
".",
"get",
"(",
"item_url",
",",
"params",
"=",
... | Fetches metadata for a track or playlist | [
"Fetches",
"metadata",
"for",
"a",
"track",
"or",
"playlist"
] | e833a22dd6676311b72fadd8a1c80f4a06acfad9 | https://github.com/flyingrub/scdl/blob/e833a22dd6676311b72fadd8a1c80f4a06acfad9/scdl/scdl.py#L219-L247 | train |
flyingrub/scdl | scdl/scdl.py | who_am_i | def who_am_i():
"""
Display username from current token and check for validity
"""
me = url['me'].format(token)
r = requests.get(me, params={'client_id': CLIENT_ID})
r.raise_for_status()
current_user = r.json()
logger.debug(me)
logger.info('Hello {0}!'.format(current_user['username'... | python | def who_am_i():
"""
Display username from current token and check for validity
"""
me = url['me'].format(token)
r = requests.get(me, params={'client_id': CLIENT_ID})
r.raise_for_status()
current_user = r.json()
logger.debug(me)
logger.info('Hello {0}!'.format(current_user['username'... | [
"def",
"who_am_i",
"(",
")",
":",
"me",
"=",
"url",
"[",
"'me'",
"]",
".",
"format",
"(",
"token",
")",
"r",
"=",
"requests",
".",
"get",
"(",
"me",
",",
"params",
"=",
"{",
"'client_id'",
":",
"CLIENT_ID",
"}",
")",
"r",
".",
"raise_for_status",
... | Display username from current token and check for validity | [
"Display",
"username",
"from",
"current",
"token",
"and",
"check",
"for",
"validity"
] | e833a22dd6676311b72fadd8a1c80f4a06acfad9 | https://github.com/flyingrub/scdl/blob/e833a22dd6676311b72fadd8a1c80f4a06acfad9/scdl/scdl.py#L286-L297 | train |
flyingrub/scdl | scdl/scdl.py | remove_files | def remove_files():
"""
Removes any pre-existing tracks that were not just downloaded
"""
logger.info("Removing local track files that were not downloaded...")
files = [f for f in os.listdir('.') if os.path.isfile(f)]
for f in files:
if f not in fileToKeep:
os.remove(f) | python | def remove_files():
"""
Removes any pre-existing tracks that were not just downloaded
"""
logger.info("Removing local track files that were not downloaded...")
files = [f for f in os.listdir('.') if os.path.isfile(f)]
for f in files:
if f not in fileToKeep:
os.remove(f) | [
"def",
"remove_files",
"(",
")",
":",
"logger",
".",
"info",
"(",
"\"Removing local track files that were not downloaded...\"",
")",
"files",
"=",
"[",
"f",
"for",
"f",
"in",
"os",
".",
"listdir",
"(",
"'.'",
")",
"if",
"os",
".",
"path",
".",
"isfile",
"(... | Removes any pre-existing tracks that were not just downloaded | [
"Removes",
"any",
"pre",
"-",
"existing",
"tracks",
"that",
"were",
"not",
"just",
"downloaded"
] | e833a22dd6676311b72fadd8a1c80f4a06acfad9 | https://github.com/flyingrub/scdl/blob/e833a22dd6676311b72fadd8a1c80f4a06acfad9/scdl/scdl.py#L300-L308 | train |
flyingrub/scdl | scdl/scdl.py | get_track_info | def get_track_info(track_id):
"""
Fetches track info from Soundcloud, given a track_id
"""
logger.info('Retrieving more info on the track')
info_url = url["trackinfo"].format(track_id)
r = requests.get(info_url, params={'client_id': CLIENT_ID}, stream=True)
item = r.json()
logger.debug(i... | python | def get_track_info(track_id):
"""
Fetches track info from Soundcloud, given a track_id
"""
logger.info('Retrieving more info on the track')
info_url = url["trackinfo"].format(track_id)
r = requests.get(info_url, params={'client_id': CLIENT_ID}, stream=True)
item = r.json()
logger.debug(i... | [
"def",
"get_track_info",
"(",
"track_id",
")",
":",
"logger",
".",
"info",
"(",
"'Retrieving more info on the track'",
")",
"info_url",
"=",
"url",
"[",
"\"trackinfo\"",
"]",
".",
"format",
"(",
"track_id",
")",
"r",
"=",
"requests",
".",
"get",
"(",
"info_u... | Fetches track info from Soundcloud, given a track_id | [
"Fetches",
"track",
"info",
"from",
"Soundcloud",
"given",
"a",
"track_id"
] | e833a22dd6676311b72fadd8a1c80f4a06acfad9 | https://github.com/flyingrub/scdl/blob/e833a22dd6676311b72fadd8a1c80f4a06acfad9/scdl/scdl.py#L311-L320 | train |
flyingrub/scdl | scdl/scdl.py | already_downloaded | def already_downloaded(track, title, filename):
"""
Returns True if the file has already been downloaded
"""
global arguments
already_downloaded = False
if os.path.isfile(filename):
already_downloaded = True
if arguments['--flac'] and can_convert(filename) \
... | python | def already_downloaded(track, title, filename):
"""
Returns True if the file has already been downloaded
"""
global arguments
already_downloaded = False
if os.path.isfile(filename):
already_downloaded = True
if arguments['--flac'] and can_convert(filename) \
... | [
"def",
"already_downloaded",
"(",
"track",
",",
"title",
",",
"filename",
")",
":",
"global",
"arguments",
"already_downloaded",
"=",
"False",
"if",
"os",
".",
"path",
".",
"isfile",
"(",
"filename",
")",
":",
"already_downloaded",
"=",
"True",
"if",
"argume... | Returns True if the file has already been downloaded | [
"Returns",
"True",
"if",
"the",
"file",
"has",
"already",
"been",
"downloaded"
] | e833a22dd6676311b72fadd8a1c80f4a06acfad9 | https://github.com/flyingrub/scdl/blob/e833a22dd6676311b72fadd8a1c80f4a06acfad9/scdl/scdl.py#L562-L588 | train |
flyingrub/scdl | scdl/scdl.py | in_download_archive | def in_download_archive(track):
"""
Returns True if a track_id exists in the download archive
"""
global arguments
if not arguments['--download-archive']:
return
archive_filename = arguments.get('--download-archive')
try:
with open(archive_filename, 'a+', encoding='utf-8') a... | python | def in_download_archive(track):
"""
Returns True if a track_id exists in the download archive
"""
global arguments
if not arguments['--download-archive']:
return
archive_filename = arguments.get('--download-archive')
try:
with open(archive_filename, 'a+', encoding='utf-8') a... | [
"def",
"in_download_archive",
"(",
"track",
")",
":",
"global",
"arguments",
"if",
"not",
"arguments",
"[",
"'--download-archive'",
"]",
":",
"return",
"archive_filename",
"=",
"arguments",
".",
"get",
"(",
"'--download-archive'",
")",
"try",
":",
"with",
"open"... | Returns True if a track_id exists in the download archive | [
"Returns",
"True",
"if",
"a",
"track_id",
"exists",
"in",
"the",
"download",
"archive"
] | e833a22dd6676311b72fadd8a1c80f4a06acfad9 | https://github.com/flyingrub/scdl/blob/e833a22dd6676311b72fadd8a1c80f4a06acfad9/scdl/scdl.py#L591-L613 | train |
flyingrub/scdl | scdl/scdl.py | record_download_archive | def record_download_archive(track):
"""
Write the track_id in the download archive
"""
global arguments
if not arguments['--download-archive']:
return
archive_filename = arguments.get('--download-archive')
try:
with open(archive_filename, 'a', encoding='utf-8') as file:
... | python | def record_download_archive(track):
"""
Write the track_id in the download archive
"""
global arguments
if not arguments['--download-archive']:
return
archive_filename = arguments.get('--download-archive')
try:
with open(archive_filename, 'a', encoding='utf-8') as file:
... | [
"def",
"record_download_archive",
"(",
"track",
")",
":",
"global",
"arguments",
"if",
"not",
"arguments",
"[",
"'--download-archive'",
"]",
":",
"return",
"archive_filename",
"=",
"arguments",
".",
"get",
"(",
"'--download-archive'",
")",
"try",
":",
"with",
"o... | Write the track_id in the download archive | [
"Write",
"the",
"track_id",
"in",
"the",
"download",
"archive"
] | e833a22dd6676311b72fadd8a1c80f4a06acfad9 | https://github.com/flyingrub/scdl/blob/e833a22dd6676311b72fadd8a1c80f4a06acfad9/scdl/scdl.py#L616-L630 | train |
lins05/slackbot | slackbot/dispatcher.py | unicode_compact | def unicode_compact(func):
"""
Make sure the first parameter of the decorated method to be a unicode
object.
"""
@wraps(func)
def wrapped(self, text, *a, **kw):
if not isinstance(text, six.text_type):
text = text.decode('utf-8')
return func(self, text, *a, **kw)
... | python | def unicode_compact(func):
"""
Make sure the first parameter of the decorated method to be a unicode
object.
"""
@wraps(func)
def wrapped(self, text, *a, **kw):
if not isinstance(text, six.text_type):
text = text.decode('utf-8')
return func(self, text, *a, **kw)
... | [
"def",
"unicode_compact",
"(",
"func",
")",
":",
"@",
"wraps",
"(",
"func",
")",
"def",
"wrapped",
"(",
"self",
",",
"text",
",",
"*",
"a",
",",
"**",
"kw",
")",
":",
"if",
"not",
"isinstance",
"(",
"text",
",",
"six",
".",
"text_type",
")",
":",... | Make sure the first parameter of the decorated method to be a unicode
object. | [
"Make",
"sure",
"the",
"first",
"parameter",
"of",
"the",
"decorated",
"method",
"to",
"be",
"a",
"unicode",
"object",
"."
] | 7195d46b9e1dc4ecfae0bdcaa91461202689bfe5 | https://github.com/lins05/slackbot/blob/7195d46b9e1dc4ecfae0bdcaa91461202689bfe5/slackbot/dispatcher.py#L173-L185 | train |
lins05/slackbot | slackbot/dispatcher.py | Message.reply_webapi | def reply_webapi(self, text, attachments=None, as_user=True, in_thread=None):
"""
Send a reply to the sender using Web API
(This function supports formatted message
when using a bot integration)
If the message was send in a thread, answer in a thread per default... | python | def reply_webapi(self, text, attachments=None, as_user=True, in_thread=None):
"""
Send a reply to the sender using Web API
(This function supports formatted message
when using a bot integration)
If the message was send in a thread, answer in a thread per default... | [
"def",
"reply_webapi",
"(",
"self",
",",
"text",
",",
"attachments",
"=",
"None",
",",
"as_user",
"=",
"True",
",",
"in_thread",
"=",
"None",
")",
":",
"if",
"in_thread",
"is",
"None",
":",
"in_thread",
"=",
"'thread_ts'",
"in",
"self",
".",
"body",
"i... | Send a reply to the sender using Web API
(This function supports formatted message
when using a bot integration)
If the message was send in a thread, answer in a thread per default. | [
"Send",
"a",
"reply",
"to",
"the",
"sender",
"using",
"Web",
"API"
] | 7195d46b9e1dc4ecfae0bdcaa91461202689bfe5 | https://github.com/lins05/slackbot/blob/7195d46b9e1dc4ecfae0bdcaa91461202689bfe5/slackbot/dispatcher.py#L214-L230 | train |
lins05/slackbot | slackbot/dispatcher.py | Message.send_webapi | def send_webapi(self, text, attachments=None, as_user=True, thread_ts=None):
"""
Send a reply using Web API
(This function supports formatted message
when using a bot integration)
"""
self._client.send_message(
self._body['channel'],
t... | python | def send_webapi(self, text, attachments=None, as_user=True, thread_ts=None):
"""
Send a reply using Web API
(This function supports formatted message
when using a bot integration)
"""
self._client.send_message(
self._body['channel'],
t... | [
"def",
"send_webapi",
"(",
"self",
",",
"text",
",",
"attachments",
"=",
"None",
",",
"as_user",
"=",
"True",
",",
"thread_ts",
"=",
"None",
")",
":",
"self",
".",
"_client",
".",
"send_message",
"(",
"self",
".",
"_body",
"[",
"'channel'",
"]",
",",
... | Send a reply using Web API
(This function supports formatted message
when using a bot integration) | [
"Send",
"a",
"reply",
"using",
"Web",
"API"
] | 7195d46b9e1dc4ecfae0bdcaa91461202689bfe5 | https://github.com/lins05/slackbot/blob/7195d46b9e1dc4ecfae0bdcaa91461202689bfe5/slackbot/dispatcher.py#L233-L245 | train |
lins05/slackbot | slackbot/dispatcher.py | Message.reply | def reply(self, text, in_thread=None):
"""
Send a reply to the sender using RTM API
(This function doesn't supports formatted message
when using a bot integration)
If the message was send in a thread, answer in a thread per default.
"""
if in_thr... | python | def reply(self, text, in_thread=None):
"""
Send a reply to the sender using RTM API
(This function doesn't supports formatted message
when using a bot integration)
If the message was send in a thread, answer in a thread per default.
"""
if in_thr... | [
"def",
"reply",
"(",
"self",
",",
"text",
",",
"in_thread",
"=",
"None",
")",
":",
"if",
"in_thread",
"is",
"None",
":",
"in_thread",
"=",
"'thread_ts'",
"in",
"self",
".",
"body",
"if",
"in_thread",
":",
"self",
".",
"send",
"(",
"text",
",",
"threa... | Send a reply to the sender using RTM API
(This function doesn't supports formatted message
when using a bot integration)
If the message was send in a thread, answer in a thread per default. | [
"Send",
"a",
"reply",
"to",
"the",
"sender",
"using",
"RTM",
"API"
] | 7195d46b9e1dc4ecfae0bdcaa91461202689bfe5 | https://github.com/lins05/slackbot/blob/7195d46b9e1dc4ecfae0bdcaa91461202689bfe5/slackbot/dispatcher.py#L248-L264 | train |
lins05/slackbot | slackbot/dispatcher.py | Message.direct_reply | def direct_reply(self, text):
"""
Send a reply via direct message using RTM API
"""
channel_id = self._client.open_dm_channel(self._get_user_id())
self._client.rtm_send_message(channel_id, text) | python | def direct_reply(self, text):
"""
Send a reply via direct message using RTM API
"""
channel_id = self._client.open_dm_channel(self._get_user_id())
self._client.rtm_send_message(channel_id, text) | [
"def",
"direct_reply",
"(",
"self",
",",
"text",
")",
":",
"channel_id",
"=",
"self",
".",
"_client",
".",
"open_dm_channel",
"(",
"self",
".",
"_get_user_id",
"(",
")",
")",
"self",
".",
"_client",
".",
"rtm_send_message",
"(",
"channel_id",
",",
"text",
... | Send a reply via direct message using RTM API | [
"Send",
"a",
"reply",
"via",
"direct",
"message",
"using",
"RTM",
"API"
] | 7195d46b9e1dc4ecfae0bdcaa91461202689bfe5 | https://github.com/lins05/slackbot/blob/7195d46b9e1dc4ecfae0bdcaa91461202689bfe5/slackbot/dispatcher.py#L267-L273 | train |
lins05/slackbot | slackbot/dispatcher.py | Message.send | def send(self, text, thread_ts=None):
"""
Send a reply using RTM API
(This function doesn't supports formatted message
when using a bot integration)
"""
self._client.rtm_send_message(self._body['channel'], text, thread_ts=thread_ts) | python | def send(self, text, thread_ts=None):
"""
Send a reply using RTM API
(This function doesn't supports formatted message
when using a bot integration)
"""
self._client.rtm_send_message(self._body['channel'], text, thread_ts=thread_ts) | [
"def",
"send",
"(",
"self",
",",
"text",
",",
"thread_ts",
"=",
"None",
")",
":",
"self",
".",
"_client",
".",
"rtm_send_message",
"(",
"self",
".",
"_body",
"[",
"'channel'",
"]",
",",
"text",
",",
"thread_ts",
"=",
"thread_ts",
")"
] | Send a reply using RTM API
(This function doesn't supports formatted message
when using a bot integration) | [
"Send",
"a",
"reply",
"using",
"RTM",
"API"
] | 7195d46b9e1dc4ecfae0bdcaa91461202689bfe5 | https://github.com/lins05/slackbot/blob/7195d46b9e1dc4ecfae0bdcaa91461202689bfe5/slackbot/dispatcher.py#L277-L284 | train |
lins05/slackbot | slackbot/dispatcher.py | Message.react | def react(self, emojiname):
"""
React to a message using the web api
"""
self._client.react_to_message(
emojiname=emojiname,
channel=self._body['channel'],
timestamp=self._body['ts']) | python | def react(self, emojiname):
"""
React to a message using the web api
"""
self._client.react_to_message(
emojiname=emojiname,
channel=self._body['channel'],
timestamp=self._body['ts']) | [
"def",
"react",
"(",
"self",
",",
"emojiname",
")",
":",
"self",
".",
"_client",
".",
"react_to_message",
"(",
"emojiname",
"=",
"emojiname",
",",
"channel",
"=",
"self",
".",
"_body",
"[",
"'channel'",
"]",
",",
"timestamp",
"=",
"self",
".",
"_body",
... | React to a message using the web api | [
"React",
"to",
"a",
"message",
"using",
"the",
"web",
"api"
] | 7195d46b9e1dc4ecfae0bdcaa91461202689bfe5 | https://github.com/lins05/slackbot/blob/7195d46b9e1dc4ecfae0bdcaa91461202689bfe5/slackbot/dispatcher.py#L286-L293 | train |
lins05/slackbot | slackbot/bot.py | default_reply | def default_reply(*args, **kwargs):
"""
Decorator declaring the wrapped function to the default reply hanlder.
May be invoked as a simple, argument-less decorator (i.e. ``@default_reply``) or
with arguments customizing its behavior (e.g. ``@default_reply(matchstr='pattern')``).
"""
invoked = bo... | python | def default_reply(*args, **kwargs):
"""
Decorator declaring the wrapped function to the default reply hanlder.
May be invoked as a simple, argument-less decorator (i.e. ``@default_reply``) or
with arguments customizing its behavior (e.g. ``@default_reply(matchstr='pattern')``).
"""
invoked = bo... | [
"def",
"default_reply",
"(",
"*",
"args",
",",
"**",
"kwargs",
")",
":",
"invoked",
"=",
"bool",
"(",
"not",
"args",
"or",
"kwargs",
")",
"matchstr",
"=",
"kwargs",
".",
"pop",
"(",
"'matchstr'",
",",
"r'^.*$'",
")",
"flags",
"=",
"kwargs",
".",
"pop... | Decorator declaring the wrapped function to the default reply hanlder.
May be invoked as a simple, argument-less decorator (i.e. ``@default_reply``) or
with arguments customizing its behavior (e.g. ``@default_reply(matchstr='pattern')``). | [
"Decorator",
"declaring",
"the",
"wrapped",
"function",
"to",
"the",
"default",
"reply",
"hanlder",
"."
] | 7195d46b9e1dc4ecfae0bdcaa91461202689bfe5 | https://github.com/lins05/slackbot/blob/7195d46b9e1dc4ecfae0bdcaa91461202689bfe5/slackbot/bot.py#L73-L94 | train |
MicroPyramid/forex-python | forex_python/bitcoin.py | BtcConverter.get_previous_price | def get_previous_price(self, currency, date_obj):
"""
Get Price for one bit coin on given date
"""
start = date_obj.strftime('%Y-%m-%d')
end = date_obj.strftime('%Y-%m-%d')
url = (
'https://api.coindesk.com/v1/bpi/historical/close.json'
'?start={}&... | python | def get_previous_price(self, currency, date_obj):
"""
Get Price for one bit coin on given date
"""
start = date_obj.strftime('%Y-%m-%d')
end = date_obj.strftime('%Y-%m-%d')
url = (
'https://api.coindesk.com/v1/bpi/historical/close.json'
'?start={}&... | [
"def",
"get_previous_price",
"(",
"self",
",",
"currency",
",",
"date_obj",
")",
":",
"start",
"=",
"date_obj",
".",
"strftime",
"(",
"'%Y-%m-%d'",
")",
"end",
"=",
"date_obj",
".",
"strftime",
"(",
"'%Y-%m-%d'",
")",
"url",
"=",
"(",
"'https://api.coindesk.... | Get Price for one bit coin on given date | [
"Get",
"Price",
"for",
"one",
"bit",
"coin",
"on",
"given",
"date"
] | dc34868ec7c7eb49b3b963d6daa3897b7095ba09 | https://github.com/MicroPyramid/forex-python/blob/dc34868ec7c7eb49b3b963d6daa3897b7095ba09/forex_python/bitcoin.py#L35-L54 | train |
MicroPyramid/forex-python | forex_python/bitcoin.py | BtcConverter.get_previous_price_list | def get_previous_price_list(self, currency, start_date, end_date):
"""
Get List of prices between two dates
"""
start = start_date.strftime('%Y-%m-%d')
end = end_date.strftime('%Y-%m-%d')
url = (
'https://api.coindesk.com/v1/bpi/historical/close.json'
... | python | def get_previous_price_list(self, currency, start_date, end_date):
"""
Get List of prices between two dates
"""
start = start_date.strftime('%Y-%m-%d')
end = end_date.strftime('%Y-%m-%d')
url = (
'https://api.coindesk.com/v1/bpi/historical/close.json'
... | [
"def",
"get_previous_price_list",
"(",
"self",
",",
"currency",
",",
"start_date",
",",
"end_date",
")",
":",
"start",
"=",
"start_date",
".",
"strftime",
"(",
"'%Y-%m-%d'",
")",
"end",
"=",
"end_date",
".",
"strftime",
"(",
"'%Y-%m-%d'",
")",
"url",
"=",
... | Get List of prices between two dates | [
"Get",
"List",
"of",
"prices",
"between",
"two",
"dates"
] | dc34868ec7c7eb49b3b963d6daa3897b7095ba09 | https://github.com/MicroPyramid/forex-python/blob/dc34868ec7c7eb49b3b963d6daa3897b7095ba09/forex_python/bitcoin.py#L56-L73 | train |
MicroPyramid/forex-python | forex_python/bitcoin.py | BtcConverter.convert_to_btc | def convert_to_btc(self, amount, currency):
"""
Convert X amount to Bit Coins
"""
if isinstance(amount, Decimal):
use_decimal = True
else:
use_decimal = self._force_decimal
url = 'https://api.coindesk.com/v1/bpi/currentprice/{}.json'.format(curren... | python | def convert_to_btc(self, amount, currency):
"""
Convert X amount to Bit Coins
"""
if isinstance(amount, Decimal):
use_decimal = True
else:
use_decimal = self._force_decimal
url = 'https://api.coindesk.com/v1/bpi/currentprice/{}.json'.format(curren... | [
"def",
"convert_to_btc",
"(",
"self",
",",
"amount",
",",
"currency",
")",
":",
"if",
"isinstance",
"(",
"amount",
",",
"Decimal",
")",
":",
"use_decimal",
"=",
"True",
"else",
":",
"use_decimal",
"=",
"self",
".",
"_force_decimal",
"url",
"=",
"'https://a... | Convert X amount to Bit Coins | [
"Convert",
"X",
"amount",
"to",
"Bit",
"Coins"
] | dc34868ec7c7eb49b3b963d6daa3897b7095ba09 | https://github.com/MicroPyramid/forex-python/blob/dc34868ec7c7eb49b3b963d6daa3897b7095ba09/forex_python/bitcoin.py#L75-L97 | train |
MicroPyramid/forex-python | forex_python/bitcoin.py | BtcConverter.convert_btc_to_cur | def convert_btc_to_cur(self, coins, currency):
"""
Convert X bit coins to valid currency amount
"""
if isinstance(coins, Decimal):
use_decimal = True
else:
use_decimal = self._force_decimal
url = 'https://api.coindesk.com/v1/bpi/currentprice/{}.js... | python | def convert_btc_to_cur(self, coins, currency):
"""
Convert X bit coins to valid currency amount
"""
if isinstance(coins, Decimal):
use_decimal = True
else:
use_decimal = self._force_decimal
url = 'https://api.coindesk.com/v1/bpi/currentprice/{}.js... | [
"def",
"convert_btc_to_cur",
"(",
"self",
",",
"coins",
",",
"currency",
")",
":",
"if",
"isinstance",
"(",
"coins",
",",
"Decimal",
")",
":",
"use_decimal",
"=",
"True",
"else",
":",
"use_decimal",
"=",
"self",
".",
"_force_decimal",
"url",
"=",
"'https:/... | Convert X bit coins to valid currency amount | [
"Convert",
"X",
"bit",
"coins",
"to",
"valid",
"currency",
"amount"
] | dc34868ec7c7eb49b3b963d6daa3897b7095ba09 | https://github.com/MicroPyramid/forex-python/blob/dc34868ec7c7eb49b3b963d6daa3897b7095ba09/forex_python/bitcoin.py#L99-L121 | train |
MicroPyramid/forex-python | forex_python/bitcoin.py | BtcConverter.convert_to_btc_on | def convert_to_btc_on(self, amount, currency, date_obj):
"""
Convert X amount to BTC based on given date rate
"""
if isinstance(amount, Decimal):
use_decimal = True
else:
use_decimal = self._force_decimal
start = date_obj.strftime('%Y-%m-%d')
... | python | def convert_to_btc_on(self, amount, currency, date_obj):
"""
Convert X amount to BTC based on given date rate
"""
if isinstance(amount, Decimal):
use_decimal = True
else:
use_decimal = self._force_decimal
start = date_obj.strftime('%Y-%m-%d')
... | [
"def",
"convert_to_btc_on",
"(",
"self",
",",
"amount",
",",
"currency",
",",
"date_obj",
")",
":",
"if",
"isinstance",
"(",
"amount",
",",
"Decimal",
")",
":",
"use_decimal",
"=",
"True",
"else",
":",
"use_decimal",
"=",
"self",
".",
"_force_decimal",
"st... | Convert X amount to BTC based on given date rate | [
"Convert",
"X",
"amount",
"to",
"BTC",
"based",
"on",
"given",
"date",
"rate"
] | dc34868ec7c7eb49b3b963d6daa3897b7095ba09 | https://github.com/MicroPyramid/forex-python/blob/dc34868ec7c7eb49b3b963d6daa3897b7095ba09/forex_python/bitcoin.py#L123-L152 | train |
DocNow/twarc | twarc/decorators.py | rate_limit | def rate_limit(f):
"""
A decorator to handle rate limiting from the Twitter API. If
a rate limit error is encountered we will sleep until we can
issue the API call again.
"""
def new_f(*args, **kwargs):
errors = 0
while True:
resp = f(*args, **kwargs)
if r... | python | def rate_limit(f):
"""
A decorator to handle rate limiting from the Twitter API. If
a rate limit error is encountered we will sleep until we can
issue the API call again.
"""
def new_f(*args, **kwargs):
errors = 0
while True:
resp = f(*args, **kwargs)
if r... | [
"def",
"rate_limit",
"(",
"f",
")",
":",
"def",
"new_f",
"(",
"*",
"args",
",",
"**",
"kwargs",
")",
":",
"errors",
"=",
"0",
"while",
"True",
":",
"resp",
"=",
"f",
"(",
"*",
"args",
",",
"**",
"kwargs",
")",
"if",
"resp",
".",
"status_code",
... | A decorator to handle rate limiting from the Twitter API. If
a rate limit error is encountered we will sleep until we can
issue the API call again. | [
"A",
"decorator",
"to",
"handle",
"rate",
"limiting",
"from",
"the",
"Twitter",
"API",
".",
"If",
"a",
"rate",
"limit",
"error",
"is",
"encountered",
"we",
"will",
"sleep",
"until",
"we",
"can",
"issue",
"the",
"API",
"call",
"again",
"."
] | 47dd87d0c00592a4d583412c9d660ba574fc6f26 | https://github.com/DocNow/twarc/blob/47dd87d0c00592a4d583412c9d660ba574fc6f26/twarc/decorators.py#L8-L53 | train |
DocNow/twarc | twarc/decorators.py | catch_timeout | def catch_timeout(f):
"""
A decorator to handle read timeouts from Twitter.
"""
def new_f(self, *args, **kwargs):
try:
return f(self, *args, **kwargs)
except (requests.exceptions.ReadTimeout,
requests.packages.urllib3.exceptions.ReadTimeoutError) as e:
... | python | def catch_timeout(f):
"""
A decorator to handle read timeouts from Twitter.
"""
def new_f(self, *args, **kwargs):
try:
return f(self, *args, **kwargs)
except (requests.exceptions.ReadTimeout,
requests.packages.urllib3.exceptions.ReadTimeoutError) as e:
... | [
"def",
"catch_timeout",
"(",
"f",
")",
":",
"def",
"new_f",
"(",
"self",
",",
"*",
"args",
",",
"**",
"kwargs",
")",
":",
"try",
":",
"return",
"f",
"(",
"self",
",",
"*",
"args",
",",
"**",
"kwargs",
")",
"except",
"(",
"requests",
".",
"excepti... | A decorator to handle read timeouts from Twitter. | [
"A",
"decorator",
"to",
"handle",
"read",
"timeouts",
"from",
"Twitter",
"."
] | 47dd87d0c00592a4d583412c9d660ba574fc6f26 | https://github.com/DocNow/twarc/blob/47dd87d0c00592a4d583412c9d660ba574fc6f26/twarc/decorators.py#L81-L93 | train |
DocNow/twarc | twarc/decorators.py | catch_gzip_errors | def catch_gzip_errors(f):
"""
A decorator to handle gzip encoding errors which have been known to
happen during hydration.
"""
def new_f(self, *args, **kwargs):
try:
return f(self, *args, **kwargs)
except requests.exceptions.ContentDecodingError as e:
log.warn... | python | def catch_gzip_errors(f):
"""
A decorator to handle gzip encoding errors which have been known to
happen during hydration.
"""
def new_f(self, *args, **kwargs):
try:
return f(self, *args, **kwargs)
except requests.exceptions.ContentDecodingError as e:
log.warn... | [
"def",
"catch_gzip_errors",
"(",
"f",
")",
":",
"def",
"new_f",
"(",
"self",
",",
"*",
"args",
",",
"**",
"kwargs",
")",
":",
"try",
":",
"return",
"f",
"(",
"self",
",",
"*",
"args",
",",
"**",
"kwargs",
")",
"except",
"requests",
".",
"exceptions... | A decorator to handle gzip encoding errors which have been known to
happen during hydration. | [
"A",
"decorator",
"to",
"handle",
"gzip",
"encoding",
"errors",
"which",
"have",
"been",
"known",
"to",
"happen",
"during",
"hydration",
"."
] | 47dd87d0c00592a4d583412c9d660ba574fc6f26 | https://github.com/DocNow/twarc/blob/47dd87d0c00592a4d583412c9d660ba574fc6f26/twarc/decorators.py#L96-L108 | train |
DocNow/twarc | twarc/decorators.py | interruptible_sleep | def interruptible_sleep(t, event=None):
"""
Sleeps for a specified duration, optionally stopping early for event.
Returns True if interrupted
"""
log.info("sleeping %s", t)
if event is None:
time.sleep(t)
return False
else:
return not event.wait(t) | python | def interruptible_sleep(t, event=None):
"""
Sleeps for a specified duration, optionally stopping early for event.
Returns True if interrupted
"""
log.info("sleeping %s", t)
if event is None:
time.sleep(t)
return False
else:
return not event.wait(t) | [
"def",
"interruptible_sleep",
"(",
"t",
",",
"event",
"=",
"None",
")",
":",
"log",
".",
"info",
"(",
"\"sleeping %s\"",
",",
"t",
")",
"if",
"event",
"is",
"None",
":",
"time",
".",
"sleep",
"(",
"t",
")",
"return",
"False",
"else",
":",
"return",
... | Sleeps for a specified duration, optionally stopping early for event.
Returns True if interrupted | [
"Sleeps",
"for",
"a",
"specified",
"duration",
"optionally",
"stopping",
"early",
"for",
"event",
"."
] | 47dd87d0c00592a4d583412c9d660ba574fc6f26 | https://github.com/DocNow/twarc/blob/47dd87d0c00592a4d583412c9d660ba574fc6f26/twarc/decorators.py#L111-L123 | train |
DocNow/twarc | twarc/decorators.py | filter_protected | def filter_protected(f):
"""
filter_protected will filter out protected tweets and users unless
explicitly requested not to.
"""
def new_f(self, *args, **kwargs):
for obj in f(self, *args, **kwargs):
if self.protected == False:
if 'user' in obj and obj['user']['pr... | python | def filter_protected(f):
"""
filter_protected will filter out protected tweets and users unless
explicitly requested not to.
"""
def new_f(self, *args, **kwargs):
for obj in f(self, *args, **kwargs):
if self.protected == False:
if 'user' in obj and obj['user']['pr... | [
"def",
"filter_protected",
"(",
"f",
")",
":",
"def",
"new_f",
"(",
"self",
",",
"*",
"args",
",",
"**",
"kwargs",
")",
":",
"for",
"obj",
"in",
"f",
"(",
"self",
",",
"*",
"args",
",",
"**",
"kwargs",
")",
":",
"if",
"self",
".",
"protected",
... | filter_protected will filter out protected tweets and users unless
explicitly requested not to. | [
"filter_protected",
"will",
"filter",
"out",
"protected",
"tweets",
"and",
"users",
"unless",
"explicitly",
"requested",
"not",
"to",
"."
] | 47dd87d0c00592a4d583412c9d660ba574fc6f26 | https://github.com/DocNow/twarc/blob/47dd87d0c00592a4d583412c9d660ba574fc6f26/twarc/decorators.py#L125-L139 | train |
DocNow/twarc | utils/extractor.py | tweets_files | def tweets_files(string, path):
"""Iterates over json files in path."""
for filename in os.listdir(path):
if re.match(string, filename) and ".jsonl" in filename:
f = gzip.open if ".gz" in filename else open
yield path + filename, f
Ellipsis | python | def tweets_files(string, path):
"""Iterates over json files in path."""
for filename in os.listdir(path):
if re.match(string, filename) and ".jsonl" in filename:
f = gzip.open if ".gz" in filename else open
yield path + filename, f
Ellipsis | [
"def",
"tweets_files",
"(",
"string",
",",
"path",
")",
":",
"for",
"filename",
"in",
"os",
".",
"listdir",
"(",
"path",
")",
":",
"if",
"re",
".",
"match",
"(",
"string",
",",
"filename",
")",
"and",
"\".jsonl\"",
"in",
"filename",
":",
"f",
"=",
... | Iterates over json files in path. | [
"Iterates",
"over",
"json",
"files",
"in",
"path",
"."
] | 47dd87d0c00592a4d583412c9d660ba574fc6f26 | https://github.com/DocNow/twarc/blob/47dd87d0c00592a4d583412c9d660ba574fc6f26/utils/extractor.py#L38-L45 | train |
DocNow/twarc | utils/extractor.py | extract | def extract(json_object, args, csv_writer):
"""Extract and write found attributes."""
found = [[]]
for attribute in args.attributes:
item = attribute.getElement(json_object)
if len(item) == 0:
for row in found:
row.append("NA")
else:
found1 = [... | python | def extract(json_object, args, csv_writer):
"""Extract and write found attributes."""
found = [[]]
for attribute in args.attributes:
item = attribute.getElement(json_object)
if len(item) == 0:
for row in found:
row.append("NA")
else:
found1 = [... | [
"def",
"extract",
"(",
"json_object",
",",
"args",
",",
"csv_writer",
")",
":",
"found",
"=",
"[",
"[",
"]",
"]",
"for",
"attribute",
"in",
"args",
".",
"attributes",
":",
"item",
"=",
"attribute",
".",
"getElement",
"(",
"json_object",
")",
"if",
"len... | Extract and write found attributes. | [
"Extract",
"and",
"write",
"found",
"attributes",
"."
] | 47dd87d0c00592a4d583412c9d660ba574fc6f26 | https://github.com/DocNow/twarc/blob/47dd87d0c00592a4d583412c9d660ba574fc6f26/utils/extractor.py#L91-L113 | train |
DocNow/twarc | utils/network.py | add | def add(from_user, from_id, to_user, to_id, type):
"adds a relation to the graph"
if options.users and to_user:
G.add_node(from_user, screen_name=from_user)
G.add_node(to_user, screen_name=to_user)
if G.has_edge(from_user, to_user):
weight = G[from_user][to_user]['we... | python | def add(from_user, from_id, to_user, to_id, type):
"adds a relation to the graph"
if options.users and to_user:
G.add_node(from_user, screen_name=from_user)
G.add_node(to_user, screen_name=to_user)
if G.has_edge(from_user, to_user):
weight = G[from_user][to_user]['we... | [
"def",
"add",
"(",
"from_user",
",",
"from_id",
",",
"to_user",
",",
"to_id",
",",
"type",
")",
":",
"\"adds a relation to the graph\"",
"if",
"options",
".",
"users",
"and",
"to_user",
":",
"G",
".",
"add_node",
"(",
"from_user",
",",
"screen_name",
"=",
... | adds a relation to the graph | [
"adds",
"a",
"relation",
"to",
"the",
"graph"
] | 47dd87d0c00592a4d583412c9d660ba574fc6f26 | https://github.com/DocNow/twarc/blob/47dd87d0c00592a4d583412c9d660ba574fc6f26/utils/network.py#L72-L91 | train |
DocNow/twarc | twarc/client.py | Twarc.timeline | def timeline(self, user_id=None, screen_name=None, max_id=None,
since_id=None, max_pages=None):
"""
Returns a collection of the most recent tweets posted
by the user indicated by the user_id or screen_name parameter.
Provide a user_id or screen_name.
"""
... | python | def timeline(self, user_id=None, screen_name=None, max_id=None,
since_id=None, max_pages=None):
"""
Returns a collection of the most recent tweets posted
by the user indicated by the user_id or screen_name parameter.
Provide a user_id or screen_name.
"""
... | [
"def",
"timeline",
"(",
"self",
",",
"user_id",
"=",
"None",
",",
"screen_name",
"=",
"None",
",",
"max_id",
"=",
"None",
",",
"since_id",
"=",
"None",
",",
"max_pages",
"=",
"None",
")",
":",
"if",
"user_id",
"and",
"screen_name",
":",
"raise",
"Value... | Returns a collection of the most recent tweets posted
by the user indicated by the user_id or screen_name parameter.
Provide a user_id or screen_name. | [
"Returns",
"a",
"collection",
"of",
"the",
"most",
"recent",
"tweets",
"posted",
"by",
"the",
"user",
"indicated",
"by",
"the",
"user_id",
"or",
"screen_name",
"parameter",
".",
"Provide",
"a",
"user_id",
"or",
"screen_name",
"."
] | 47dd87d0c00592a4d583412c9d660ba574fc6f26 | https://github.com/DocNow/twarc/blob/47dd87d0c00592a4d583412c9d660ba574fc6f26/twarc/client.py#L138-L211 | train |
DocNow/twarc | twarc/client.py | Twarc.follower_ids | def follower_ids(self, user):
"""
Returns Twitter user id lists for the specified user's followers.
A user can be a specific using their screen_name or user_id
"""
user = str(user)
user = user.lstrip('@')
url = 'https://api.twitter.com/1.1/followers/ids.json'
... | python | def follower_ids(self, user):
"""
Returns Twitter user id lists for the specified user's followers.
A user can be a specific using their screen_name or user_id
"""
user = str(user)
user = user.lstrip('@')
url = 'https://api.twitter.com/1.1/followers/ids.json'
... | [
"def",
"follower_ids",
"(",
"self",
",",
"user",
")",
":",
"user",
"=",
"str",
"(",
"user",
")",
"user",
"=",
"user",
".",
"lstrip",
"(",
"'@'",
")",
"url",
"=",
"'https://api.twitter.com/1.1/followers/ids.json'",
"if",
"re",
".",
"match",
"(",
"r'^\\d+$'"... | Returns Twitter user id lists for the specified user's followers.
A user can be a specific using their screen_name or user_id | [
"Returns",
"Twitter",
"user",
"id",
"lists",
"for",
"the",
"specified",
"user",
"s",
"followers",
".",
"A",
"user",
"can",
"be",
"a",
"specific",
"using",
"their",
"screen_name",
"or",
"user_id"
] | 47dd87d0c00592a4d583412c9d660ba574fc6f26 | https://github.com/DocNow/twarc/blob/47dd87d0c00592a4d583412c9d660ba574fc6f26/twarc/client.py#L254-L278 | train |
DocNow/twarc | twarc/client.py | Twarc.filter | def filter(self, track=None, follow=None, locations=None, event=None,
record_keepalive=False):
"""
Returns an iterator for tweets that match a given filter track from
the livestream of tweets happening right now.
If a threading.Event is provided for event and the event is... | python | def filter(self, track=None, follow=None, locations=None, event=None,
record_keepalive=False):
"""
Returns an iterator for tweets that match a given filter track from
the livestream of tweets happening right now.
If a threading.Event is provided for event and the event is... | [
"def",
"filter",
"(",
"self",
",",
"track",
"=",
"None",
",",
"follow",
"=",
"None",
",",
"locations",
"=",
"None",
",",
"event",
"=",
"None",
",",
"record_keepalive",
"=",
"False",
")",
":",
"if",
"locations",
"is",
"not",
"None",
":",
"if",
"type",... | Returns an iterator for tweets that match a given filter track from
the livestream of tweets happening right now.
If a threading.Event is provided for event and the event is set,
the filter will be interrupted. | [
"Returns",
"an",
"iterator",
"for",
"tweets",
"that",
"match",
"a",
"given",
"filter",
"track",
"from",
"the",
"livestream",
"of",
"tweets",
"happening",
"right",
"now",
"."
] | 47dd87d0c00592a4d583412c9d660ba574fc6f26 | https://github.com/DocNow/twarc/blob/47dd87d0c00592a4d583412c9d660ba574fc6f26/twarc/client.py#L308-L378 | train |
DocNow/twarc | twarc/client.py | Twarc.sample | def sample(self, event=None, record_keepalive=False):
"""
Returns a small random sample of all public statuses. The Tweets
returned by the default access level are the same, so if two different
clients connect to this endpoint, they will see the same Tweets.
If a threading.Event... | python | def sample(self, event=None, record_keepalive=False):
"""
Returns a small random sample of all public statuses. The Tweets
returned by the default access level are the same, so if two different
clients connect to this endpoint, they will see the same Tweets.
If a threading.Event... | [
"def",
"sample",
"(",
"self",
",",
"event",
"=",
"None",
",",
"record_keepalive",
"=",
"False",
")",
":",
"url",
"=",
"'https://stream.twitter.com/1.1/statuses/sample.json'",
"params",
"=",
"{",
"\"stall_warning\"",
":",
"True",
"}",
"headers",
"=",
"{",
"'accep... | Returns a small random sample of all public statuses. The Tweets
returned by the default access level are the same, so if two different
clients connect to this endpoint, they will see the same Tweets.
If a threading.Event is provided for event and the event is set,
the sample will be in... | [
"Returns",
"a",
"small",
"random",
"sample",
"of",
"all",
"public",
"statuses",
".",
"The",
"Tweets",
"returned",
"by",
"the",
"default",
"access",
"level",
"are",
"the",
"same",
"so",
"if",
"two",
"different",
"clients",
"connect",
"to",
"this",
"endpoint",... | 47dd87d0c00592a4d583412c9d660ba574fc6f26 | https://github.com/DocNow/twarc/blob/47dd87d0c00592a4d583412c9d660ba574fc6f26/twarc/client.py#L380-L436 | train |
DocNow/twarc | twarc/client.py | Twarc.dehydrate | def dehydrate(self, iterator):
"""
Pass in an iterator of tweets' JSON and get back an iterator of the
IDs of each tweet.
"""
for line in iterator:
try:
yield json.loads(line)['id_str']
except Exception as e:
log.error("uhoh... | python | def dehydrate(self, iterator):
"""
Pass in an iterator of tweets' JSON and get back an iterator of the
IDs of each tweet.
"""
for line in iterator:
try:
yield json.loads(line)['id_str']
except Exception as e:
log.error("uhoh... | [
"def",
"dehydrate",
"(",
"self",
",",
"iterator",
")",
":",
"for",
"line",
"in",
"iterator",
":",
"try",
":",
"yield",
"json",
".",
"loads",
"(",
"line",
")",
"[",
"'id_str'",
"]",
"except",
"Exception",
"as",
"e",
":",
"log",
".",
"error",
"(",
"\... | Pass in an iterator of tweets' JSON and get back an iterator of the
IDs of each tweet. | [
"Pass",
"in",
"an",
"iterator",
"of",
"tweets",
"JSON",
"and",
"get",
"back",
"an",
"iterator",
"of",
"the",
"IDs",
"of",
"each",
"tweet",
"."
] | 47dd87d0c00592a4d583412c9d660ba574fc6f26 | https://github.com/DocNow/twarc/blob/47dd87d0c00592a4d583412c9d660ba574fc6f26/twarc/client.py#L438-L447 | train |
DocNow/twarc | twarc/client.py | Twarc.hydrate | def hydrate(self, iterator):
"""
Pass in an iterator of tweet ids and get back an iterator for the
decoded JSON for each corresponding tweet.
"""
ids = []
url = "https://api.twitter.com/1.1/statuses/lookup.json"
# lookup 100 tweets at a time
for tweet_id ... | python | def hydrate(self, iterator):
"""
Pass in an iterator of tweet ids and get back an iterator for the
decoded JSON for each corresponding tweet.
"""
ids = []
url = "https://api.twitter.com/1.1/statuses/lookup.json"
# lookup 100 tweets at a time
for tweet_id ... | [
"def",
"hydrate",
"(",
"self",
",",
"iterator",
")",
":",
"ids",
"=",
"[",
"]",
"url",
"=",
"\"https://api.twitter.com/1.1/statuses/lookup.json\"",
"for",
"tweet_id",
"in",
"iterator",
":",
"tweet_id",
"=",
"str",
"(",
"tweet_id",
")",
"tweet_id",
"=",
"tweet_... | Pass in an iterator of tweet ids and get back an iterator for the
decoded JSON for each corresponding tweet. | [
"Pass",
"in",
"an",
"iterator",
"of",
"tweet",
"ids",
"and",
"get",
"back",
"an",
"iterator",
"for",
"the",
"decoded",
"JSON",
"for",
"each",
"corresponding",
"tweet",
"."
] | 47dd87d0c00592a4d583412c9d660ba574fc6f26 | https://github.com/DocNow/twarc/blob/47dd87d0c00592a4d583412c9d660ba574fc6f26/twarc/client.py#L449-L482 | train |
DocNow/twarc | twarc/client.py | Twarc.retweets | def retweets(self, tweet_id):
"""
Retrieves up to the last 100 retweets for the provided
tweet.
"""
log.info("retrieving retweets of %s", tweet_id)
url = "https://api.twitter.com/1.1/statuses/retweets/""{}.json".format(
tweet_id)
resp = self.get(u... | python | def retweets(self, tweet_id):
"""
Retrieves up to the last 100 retweets for the provided
tweet.
"""
log.info("retrieving retweets of %s", tweet_id)
url = "https://api.twitter.com/1.1/statuses/retweets/""{}.json".format(
tweet_id)
resp = self.get(u... | [
"def",
"retweets",
"(",
"self",
",",
"tweet_id",
")",
":",
"log",
".",
"info",
"(",
"\"retrieving retweets of %s\"",
",",
"tweet_id",
")",
"url",
"=",
"\"https://api.twitter.com/1.1/statuses/retweets/\"",
"\"{}.json\"",
".",
"format",
"(",
"tweet_id",
")",
"resp",
... | Retrieves up to the last 100 retweets for the provided
tweet. | [
"Retrieves",
"up",
"to",
"the",
"last",
"100",
"retweets",
"for",
"the",
"provided",
"tweet",
"."
] | 47dd87d0c00592a4d583412c9d660ba574fc6f26 | https://github.com/DocNow/twarc/blob/47dd87d0c00592a4d583412c9d660ba574fc6f26/twarc/client.py#L490-L501 | train |
DocNow/twarc | twarc/client.py | Twarc.trends_available | def trends_available(self):
"""
Returns a list of regions for which Twitter tracks trends.
"""
url = 'https://api.twitter.com/1.1/trends/available.json'
try:
resp = self.get(url)
except requests.exceptions.HTTPError as e:
raise e
return res... | python | def trends_available(self):
"""
Returns a list of regions for which Twitter tracks trends.
"""
url = 'https://api.twitter.com/1.1/trends/available.json'
try:
resp = self.get(url)
except requests.exceptions.HTTPError as e:
raise e
return res... | [
"def",
"trends_available",
"(",
"self",
")",
":",
"url",
"=",
"'https://api.twitter.com/1.1/trends/available.json'",
"try",
":",
"resp",
"=",
"self",
".",
"get",
"(",
"url",
")",
"except",
"requests",
".",
"exceptions",
".",
"HTTPError",
"as",
"e",
":",
"raise... | Returns a list of regions for which Twitter tracks trends. | [
"Returns",
"a",
"list",
"of",
"regions",
"for",
"which",
"Twitter",
"tracks",
"trends",
"."
] | 47dd87d0c00592a4d583412c9d660ba574fc6f26 | https://github.com/DocNow/twarc/blob/47dd87d0c00592a4d583412c9d660ba574fc6f26/twarc/client.py#L503-L512 | train |
DocNow/twarc | twarc/client.py | Twarc.trends_place | def trends_place(self, woeid, exclude=None):
"""
Returns recent Twitter trends for the specified WOEID. If
exclude == 'hashtags', Twitter will remove hashtag trends from the
response.
"""
url = 'https://api.twitter.com/1.1/trends/place.json'
params = {'id': woeid}... | python | def trends_place(self, woeid, exclude=None):
"""
Returns recent Twitter trends for the specified WOEID. If
exclude == 'hashtags', Twitter will remove hashtag trends from the
response.
"""
url = 'https://api.twitter.com/1.1/trends/place.json'
params = {'id': woeid}... | [
"def",
"trends_place",
"(",
"self",
",",
"woeid",
",",
"exclude",
"=",
"None",
")",
":",
"url",
"=",
"'https://api.twitter.com/1.1/trends/place.json'",
"params",
"=",
"{",
"'id'",
":",
"woeid",
"}",
"if",
"exclude",
":",
"params",
"[",
"'exclude'",
"]",
"=",... | Returns recent Twitter trends for the specified WOEID. If
exclude == 'hashtags', Twitter will remove hashtag trends from the
response. | [
"Returns",
"recent",
"Twitter",
"trends",
"for",
"the",
"specified",
"WOEID",
".",
"If",
"exclude",
"==",
"hashtags",
"Twitter",
"will",
"remove",
"hashtag",
"trends",
"from",
"the",
"response",
"."
] | 47dd87d0c00592a4d583412c9d660ba574fc6f26 | https://github.com/DocNow/twarc/blob/47dd87d0c00592a4d583412c9d660ba574fc6f26/twarc/client.py#L514-L530 | train |
DocNow/twarc | twarc/client.py | Twarc.replies | def replies(self, tweet, recursive=False, prune=()):
"""
replies returns a generator of tweets that are replies for a given
tweet. It includes the original tweet. If you would like to fetch the
replies to the replies use recursive=True which will do a depth-first
recursive walk o... | python | def replies(self, tweet, recursive=False, prune=()):
"""
replies returns a generator of tweets that are replies for a given
tweet. It includes the original tweet. If you would like to fetch the
replies to the replies use recursive=True which will do a depth-first
recursive walk o... | [
"def",
"replies",
"(",
"self",
",",
"tweet",
",",
"recursive",
"=",
"False",
",",
"prune",
"=",
"(",
")",
")",
":",
"yield",
"tweet",
"screen_name",
"=",
"tweet",
"[",
"'user'",
"]",
"[",
"'screen_name'",
"]",
"tweet_id",
"=",
"tweet",
"[",
"'id_str'",... | replies returns a generator of tweets that are replies for a given
tweet. It includes the original tweet. If you would like to fetch the
replies to the replies use recursive=True which will do a depth-first
recursive walk of the replies. It also walk up the reply chain if you
supply a tw... | [
"replies",
"returns",
"a",
"generator",
"of",
"tweets",
"that",
"are",
"replies",
"for",
"a",
"given",
"tweet",
".",
"It",
"includes",
"the",
"original",
"tweet",
".",
"If",
"you",
"would",
"like",
"to",
"fetch",
"the",
"replies",
"to",
"the",
"replies",
... | 47dd87d0c00592a4d583412c9d660ba574fc6f26 | https://github.com/DocNow/twarc/blob/47dd87d0c00592a4d583412c9d660ba574fc6f26/twarc/client.py#L544-L603 | train |
DocNow/twarc | twarc/client.py | Twarc.list_members | def list_members(self, list_id=None, slug=None, owner_screen_name=None, owner_id=None):
"""
Returns the members of a list.
List id or (slug and (owner_screen_name or owner_id)) are required
"""
assert list_id or (slug and (owner_screen_name or owner_id))
url = 'https://a... | python | def list_members(self, list_id=None, slug=None, owner_screen_name=None, owner_id=None):
"""
Returns the members of a list.
List id or (slug and (owner_screen_name or owner_id)) are required
"""
assert list_id or (slug and (owner_screen_name or owner_id))
url = 'https://a... | [
"def",
"list_members",
"(",
"self",
",",
"list_id",
"=",
"None",
",",
"slug",
"=",
"None",
",",
"owner_screen_name",
"=",
"None",
",",
"owner_id",
"=",
"None",
")",
":",
"assert",
"list_id",
"or",
"(",
"slug",
"and",
"(",
"owner_screen_name",
"or",
"owne... | Returns the members of a list.
List id or (slug and (owner_screen_name or owner_id)) are required | [
"Returns",
"the",
"members",
"of",
"a",
"list",
"."
] | 47dd87d0c00592a4d583412c9d660ba574fc6f26 | https://github.com/DocNow/twarc/blob/47dd87d0c00592a4d583412c9d660ba574fc6f26/twarc/client.py#L605-L634 | train |
DocNow/twarc | twarc/client.py | Twarc.connect | def connect(self):
"""
Sets up the HTTP session to talk to Twitter. If one is active it is
closed and another one is opened.
"""
if not (self.consumer_key and self.consumer_secret and self.access_token
and self.access_token_secret):
raise RuntimeError(... | python | def connect(self):
"""
Sets up the HTTP session to talk to Twitter. If one is active it is
closed and another one is opened.
"""
if not (self.consumer_key and self.consumer_secret and self.access_token
and self.access_token_secret):
raise RuntimeError(... | [
"def",
"connect",
"(",
"self",
")",
":",
"if",
"not",
"(",
"self",
".",
"consumer_key",
"and",
"self",
".",
"consumer_secret",
"and",
"self",
".",
"access_token",
"and",
"self",
".",
"access_token_secret",
")",
":",
"raise",
"RuntimeError",
"(",
"\"MissingKe... | Sets up the HTTP session to talk to Twitter. If one is active it is
closed and another one is opened. | [
"Sets",
"up",
"the",
"HTTP",
"session",
"to",
"talk",
"to",
"Twitter",
".",
"If",
"one",
"is",
"active",
"it",
"is",
"closed",
"and",
"another",
"one",
"is",
"opened",
"."
] | 47dd87d0c00592a4d583412c9d660ba574fc6f26 | https://github.com/DocNow/twarc/blob/47dd87d0c00592a4d583412c9d660ba574fc6f26/twarc/client.py#L707-L729 | train |
DocNow/twarc | twarc/client.py | Twarc.get_keys | def get_keys(self):
"""
Get the Twitter API keys. Order of precedence is command line,
environment, config file. Return True if all the keys were found
and False if not.
"""
env = os.environ.get
if not self.consumer_key:
self.consumer_key = env('CONSUM... | python | def get_keys(self):
"""
Get the Twitter API keys. Order of precedence is command line,
environment, config file. Return True if all the keys were found
and False if not.
"""
env = os.environ.get
if not self.consumer_key:
self.consumer_key = env('CONSUM... | [
"def",
"get_keys",
"(",
"self",
")",
":",
"env",
"=",
"os",
".",
"environ",
".",
"get",
"if",
"not",
"self",
".",
"consumer_key",
":",
"self",
".",
"consumer_key",
"=",
"env",
"(",
"'CONSUMER_KEY'",
")",
"if",
"not",
"self",
".",
"consumer_secret",
":"... | Get the Twitter API keys. Order of precedence is command line,
environment, config file. Return True if all the keys were found
and False if not. | [
"Get",
"the",
"Twitter",
"API",
"keys",
".",
"Order",
"of",
"precedence",
"is",
"command",
"line",
"environment",
"config",
"file",
".",
"Return",
"True",
"if",
"all",
"the",
"keys",
"were",
"found",
"and",
"False",
"if",
"not",
"."
] | 47dd87d0c00592a4d583412c9d660ba574fc6f26 | https://github.com/DocNow/twarc/blob/47dd87d0c00592a4d583412c9d660ba574fc6f26/twarc/client.py#L731-L751 | train |
DocNow/twarc | twarc/client.py | Twarc.validate_keys | def validate_keys(self):
"""
Validate the keys provided are authentic credentials.
"""
url = 'https://api.twitter.com/1.1/account/verify_credentials.json'
keys_present = self.consumer_key and self.consumer_secret and \
self.access_token and self.access_tok... | python | def validate_keys(self):
"""
Validate the keys provided are authentic credentials.
"""
url = 'https://api.twitter.com/1.1/account/verify_credentials.json'
keys_present = self.consumer_key and self.consumer_secret and \
self.access_token and self.access_tok... | [
"def",
"validate_keys",
"(",
"self",
")",
":",
"url",
"=",
"'https://api.twitter.com/1.1/account/verify_credentials.json'",
"keys_present",
"=",
"self",
".",
"consumer_key",
"and",
"self",
".",
"consumer_secret",
"and",
"self",
".",
"access_token",
"and",
"self",
".",... | Validate the keys provided are authentic credentials. | [
"Validate",
"the",
"keys",
"provided",
"are",
"authentic",
"credentials",
"."
] | 47dd87d0c00592a4d583412c9d660ba574fc6f26 | https://github.com/DocNow/twarc/blob/47dd87d0c00592a4d583412c9d660ba574fc6f26/twarc/client.py#L753-L774 | train |
rochacbruno/dynaconf | dynaconf/contrib/flask_dynaconf.py | FlaskDynaconf.init_app | def init_app(self, app, **kwargs):
"""kwargs holds initial dynaconf configuration"""
self.kwargs.update(kwargs)
self.settings = self.dynaconf_instance or LazySettings(**self.kwargs)
app.config = self.make_config(app)
app.dynaconf = self.settings | python | def init_app(self, app, **kwargs):
"""kwargs holds initial dynaconf configuration"""
self.kwargs.update(kwargs)
self.settings = self.dynaconf_instance or LazySettings(**self.kwargs)
app.config = self.make_config(app)
app.dynaconf = self.settings | [
"def",
"init_app",
"(",
"self",
",",
"app",
",",
"**",
"kwargs",
")",
":",
"self",
".",
"kwargs",
".",
"update",
"(",
"kwargs",
")",
"self",
".",
"settings",
"=",
"self",
".",
"dynaconf_instance",
"or",
"LazySettings",
"(",
"**",
"self",
".",
"kwargs",... | kwargs holds initial dynaconf configuration | [
"kwargs",
"holds",
"initial",
"dynaconf",
"configuration"
] | 5a7cc8f8252251cbdf4f4112965801f9dfe2831d | https://github.com/rochacbruno/dynaconf/blob/5a7cc8f8252251cbdf4f4112965801f9dfe2831d/dynaconf/contrib/flask_dynaconf.py#L102-L107 | train |
rochacbruno/dynaconf | dynaconf/contrib/flask_dynaconf.py | DynaconfConfig.get | def get(self, key, default=None):
"""Gets config from dynaconf variables
if variables does not exists in dynaconf try getting from
`app.config` to support runtime settings."""
return self._settings.get(key, Config.get(self, key, default)) | python | def get(self, key, default=None):
"""Gets config from dynaconf variables
if variables does not exists in dynaconf try getting from
`app.config` to support runtime settings."""
return self._settings.get(key, Config.get(self, key, default)) | [
"def",
"get",
"(",
"self",
",",
"key",
",",
"default",
"=",
"None",
")",
":",
"return",
"self",
".",
"_settings",
".",
"get",
"(",
"key",
",",
"Config",
".",
"get",
"(",
"self",
",",
"key",
",",
"default",
")",
")"
] | Gets config from dynaconf variables
if variables does not exists in dynaconf try getting from
`app.config` to support runtime settings. | [
"Gets",
"config",
"from",
"dynaconf",
"variables",
"if",
"variables",
"does",
"not",
"exists",
"in",
"dynaconf",
"try",
"getting",
"from",
"app",
".",
"config",
"to",
"support",
"runtime",
"settings",
"."
] | 5a7cc8f8252251cbdf4f4112965801f9dfe2831d | https://github.com/rochacbruno/dynaconf/blob/5a7cc8f8252251cbdf4f4112965801f9dfe2831d/dynaconf/contrib/flask_dynaconf.py#L130-L134 | train |
rochacbruno/dynaconf | dynaconf/utils/__init__.py | object_merge | def object_merge(old, new, unique=False):
"""
Recursively merge two data structures.
:param unique: When set to True existing list items are not set.
"""
if isinstance(old, list) and isinstance(new, list):
if old == new:
return
for item in old[::-1]:
if uniqu... | python | def object_merge(old, new, unique=False):
"""
Recursively merge two data structures.
:param unique: When set to True existing list items are not set.
"""
if isinstance(old, list) and isinstance(new, list):
if old == new:
return
for item in old[::-1]:
if uniqu... | [
"def",
"object_merge",
"(",
"old",
",",
"new",
",",
"unique",
"=",
"False",
")",
":",
"if",
"isinstance",
"(",
"old",
",",
"list",
")",
"and",
"isinstance",
"(",
"new",
",",
"list",
")",
":",
"if",
"old",
"==",
"new",
":",
"return",
"for",
"item",
... | Recursively merge two data structures.
:param unique: When set to True existing list items are not set. | [
"Recursively",
"merge",
"two",
"data",
"structures",
"."
] | 5a7cc8f8252251cbdf4f4112965801f9dfe2831d | https://github.com/rochacbruno/dynaconf/blob/5a7cc8f8252251cbdf4f4112965801f9dfe2831d/dynaconf/utils/__init__.py#L20-L38 | train |
rochacbruno/dynaconf | dynaconf/utils/__init__.py | compat_kwargs | def compat_kwargs(kwargs):
"""To keep backwards compat change the kwargs to new names"""
warn_deprecations(kwargs)
for old, new in RENAMED_VARS.items():
if old in kwargs:
kwargs[new] = kwargs[old]
# update cross references
for c_old, c_new in RENAMED_VARS.items():... | python | def compat_kwargs(kwargs):
"""To keep backwards compat change the kwargs to new names"""
warn_deprecations(kwargs)
for old, new in RENAMED_VARS.items():
if old in kwargs:
kwargs[new] = kwargs[old]
# update cross references
for c_old, c_new in RENAMED_VARS.items():... | [
"def",
"compat_kwargs",
"(",
"kwargs",
")",
":",
"warn_deprecations",
"(",
"kwargs",
")",
"for",
"old",
",",
"new",
"in",
"RENAMED_VARS",
".",
"items",
"(",
")",
":",
"if",
"old",
"in",
"kwargs",
":",
"kwargs",
"[",
"new",
"]",
"=",
"kwargs",
"[",
"o... | To keep backwards compat change the kwargs to new names | [
"To",
"keep",
"backwards",
"compat",
"change",
"the",
"kwargs",
"to",
"new",
"names"
] | 5a7cc8f8252251cbdf4f4112965801f9dfe2831d | https://github.com/rochacbruno/dynaconf/blob/5a7cc8f8252251cbdf4f4112965801f9dfe2831d/dynaconf/utils/__init__.py#L107-L116 | train |
rochacbruno/dynaconf | dynaconf/utils/__init__.py | deduplicate | def deduplicate(list_object):
"""Rebuild `list_object` removing duplicated and keeping order"""
new = []
for item in list_object:
if item not in new:
new.append(item)
return new | python | def deduplicate(list_object):
"""Rebuild `list_object` removing duplicated and keeping order"""
new = []
for item in list_object:
if item not in new:
new.append(item)
return new | [
"def",
"deduplicate",
"(",
"list_object",
")",
":",
"new",
"=",
"[",
"]",
"for",
"item",
"in",
"list_object",
":",
"if",
"item",
"not",
"in",
"new",
":",
"new",
".",
"append",
"(",
"item",
")",
"return",
"new"
] | Rebuild `list_object` removing duplicated and keeping order | [
"Rebuild",
"list_object",
"removing",
"duplicated",
"and",
"keeping",
"order"
] | 5a7cc8f8252251cbdf4f4112965801f9dfe2831d | https://github.com/rochacbruno/dynaconf/blob/5a7cc8f8252251cbdf4f4112965801f9dfe2831d/dynaconf/utils/__init__.py#L148-L154 | train |
rochacbruno/dynaconf | dynaconf/utils/__init__.py | trimmed_split | def trimmed_split(s, seps=(";", ",")):
"""Given a string s, split is by one of one of the seps."""
for sep in seps:
if sep not in s:
continue
data = [item.strip() for item in s.strip().split(sep)]
return data
return [s] | python | def trimmed_split(s, seps=(";", ",")):
"""Given a string s, split is by one of one of the seps."""
for sep in seps:
if sep not in s:
continue
data = [item.strip() for item in s.strip().split(sep)]
return data
return [s] | [
"def",
"trimmed_split",
"(",
"s",
",",
"seps",
"=",
"(",
"\";\"",
",",
"\",\"",
")",
")",
":",
"for",
"sep",
"in",
"seps",
":",
"if",
"sep",
"not",
"in",
"s",
":",
"continue",
"data",
"=",
"[",
"item",
".",
"strip",
"(",
")",
"for",
"item",
"in... | Given a string s, split is by one of one of the seps. | [
"Given",
"a",
"string",
"s",
"split",
"is",
"by",
"one",
"of",
"one",
"of",
"the",
"seps",
"."
] | 5a7cc8f8252251cbdf4f4112965801f9dfe2831d | https://github.com/rochacbruno/dynaconf/blob/5a7cc8f8252251cbdf4f4112965801f9dfe2831d/dynaconf/utils/__init__.py#L175-L182 | train |
rochacbruno/dynaconf | dynaconf/utils/__init__.py | ensure_a_list | def ensure_a_list(data):
"""Ensure data is a list or wrap it in a list"""
if not data:
return []
if isinstance(data, (list, tuple, set)):
return list(data)
if isinstance(data, str):
data = trimmed_split(data) # settings.toml,other.yaml
return data
return [data] | python | def ensure_a_list(data):
"""Ensure data is a list or wrap it in a list"""
if not data:
return []
if isinstance(data, (list, tuple, set)):
return list(data)
if isinstance(data, str):
data = trimmed_split(data) # settings.toml,other.yaml
return data
return [data] | [
"def",
"ensure_a_list",
"(",
"data",
")",
":",
"if",
"not",
"data",
":",
"return",
"[",
"]",
"if",
"isinstance",
"(",
"data",
",",
"(",
"list",
",",
"tuple",
",",
"set",
")",
")",
":",
"return",
"list",
"(",
"data",
")",
"if",
"isinstance",
"(",
... | Ensure data is a list or wrap it in a list | [
"Ensure",
"data",
"is",
"a",
"list",
"or",
"wrap",
"it",
"in",
"a",
"list"
] | 5a7cc8f8252251cbdf4f4112965801f9dfe2831d | https://github.com/rochacbruno/dynaconf/blob/5a7cc8f8252251cbdf4f4112965801f9dfe2831d/dynaconf/utils/__init__.py#L185-L194 | train |
rochacbruno/dynaconf | dynaconf/loaders/redis_loader.py | load | def load(obj, env=None, silent=True, key=None):
"""Reads and loads in to "settings" a single key or all keys from redis
:param obj: the settings instance
:param env: settings env default='DYNACONF'
:param silent: if errors should raise
:param key: if defined load a single key, else load all in env
... | python | def load(obj, env=None, silent=True, key=None):
"""Reads and loads in to "settings" a single key or all keys from redis
:param obj: the settings instance
:param env: settings env default='DYNACONF'
:param silent: if errors should raise
:param key: if defined load a single key, else load all in env
... | [
"def",
"load",
"(",
"obj",
",",
"env",
"=",
"None",
",",
"silent",
"=",
"True",
",",
"key",
"=",
"None",
")",
":",
"redis",
"=",
"StrictRedis",
"(",
"**",
"obj",
".",
"get",
"(",
"\"REDIS_FOR_DYNACONF\"",
")",
")",
"holder",
"=",
"obj",
".",
"get",... | Reads and loads in to "settings" a single key or all keys from redis
:param obj: the settings instance
:param env: settings env default='DYNACONF'
:param silent: if errors should raise
:param key: if defined load a single key, else load all in env
:return: None | [
"Reads",
"and",
"loads",
"in",
"to",
"settings",
"a",
"single",
"key",
"or",
"all",
"keys",
"from",
"redis"
] | 5a7cc8f8252251cbdf4f4112965801f9dfe2831d | https://github.com/rochacbruno/dynaconf/blob/5a7cc8f8252251cbdf4f4112965801f9dfe2831d/dynaconf/loaders/redis_loader.py#L16-L60 | train |
rochacbruno/dynaconf | dynaconf/loaders/py_loader.py | load | def load(obj, settings_module, identifier="py", silent=False, key=None):
"""Tries to import a python module"""
mod, loaded_from = get_module(obj, settings_module, silent)
if mod and loaded_from:
obj.logger.debug("py_loader: {}".format(mod))
else:
obj.logger.debug(
"py_loader... | python | def load(obj, settings_module, identifier="py", silent=False, key=None):
"""Tries to import a python module"""
mod, loaded_from = get_module(obj, settings_module, silent)
if mod and loaded_from:
obj.logger.debug("py_loader: {}".format(mod))
else:
obj.logger.debug(
"py_loader... | [
"def",
"load",
"(",
"obj",
",",
"settings_module",
",",
"identifier",
"=",
"\"py\"",
",",
"silent",
"=",
"False",
",",
"key",
"=",
"None",
")",
":",
"mod",
",",
"loaded_from",
"=",
"get_module",
"(",
"obj",
",",
"settings_module",
",",
"silent",
")",
"... | Tries to import a python module | [
"Tries",
"to",
"import",
"a",
"python",
"module"
] | 5a7cc8f8252251cbdf4f4112965801f9dfe2831d | https://github.com/rochacbruno/dynaconf/blob/5a7cc8f8252251cbdf4f4112965801f9dfe2831d/dynaconf/loaders/py_loader.py#L15-L39 | train |
rochacbruno/dynaconf | dynaconf/loaders/py_loader.py | import_from_filename | def import_from_filename(obj, filename, silent=False): # pragma: no cover
"""If settings_module is a filename path import it."""
if filename in [item.filename for item in inspect.stack()]:
raise ImportError(
"Looks like you are loading dynaconf "
"from inside the {} file and the... | python | def import_from_filename(obj, filename, silent=False): # pragma: no cover
"""If settings_module is a filename path import it."""
if filename in [item.filename for item in inspect.stack()]:
raise ImportError(
"Looks like you are loading dynaconf "
"from inside the {} file and the... | [
"def",
"import_from_filename",
"(",
"obj",
",",
"filename",
",",
"silent",
"=",
"False",
")",
":",
"if",
"filename",
"in",
"[",
"item",
".",
"filename",
"for",
"item",
"in",
"inspect",
".",
"stack",
"(",
")",
"]",
":",
"raise",
"ImportError",
"(",
"\"L... | If settings_module is a filename path import it. | [
"If",
"settings_module",
"is",
"a",
"filename",
"path",
"import",
"it",
"."
] | 5a7cc8f8252251cbdf4f4112965801f9dfe2831d | https://github.com/rochacbruno/dynaconf/blob/5a7cc8f8252251cbdf4f4112965801f9dfe2831d/dynaconf/loaders/py_loader.py#L58-L94 | train |
rochacbruno/dynaconf | dynaconf/loaders/vault_loader.py | _get_env_list | def _get_env_list(obj, env):
"""Creates the list of environments to read
:param obj: the settings instance
:param env: settings env default='DYNACONF'
:return: a list of working environments
"""
# add the [default] env
env_list = [obj.get("DEFAULT_ENV_FOR_DYNACONF")]
# compatibility wit... | python | def _get_env_list(obj, env):
"""Creates the list of environments to read
:param obj: the settings instance
:param env: settings env default='DYNACONF'
:return: a list of working environments
"""
# add the [default] env
env_list = [obj.get("DEFAULT_ENV_FOR_DYNACONF")]
# compatibility wit... | [
"def",
"_get_env_list",
"(",
"obj",
",",
"env",
")",
":",
"env_list",
"=",
"[",
"obj",
".",
"get",
"(",
"\"DEFAULT_ENV_FOR_DYNACONF\"",
")",
"]",
"global_env",
"=",
"obj",
".",
"get",
"(",
"\"ENVVAR_PREFIX_FOR_DYNACONF\"",
")",
"or",
"\"DYNACONF\"",
"if",
"g... | Creates the list of environments to read
:param obj: the settings instance
:param env: settings env default='DYNACONF'
:return: a list of working environments | [
"Creates",
"the",
"list",
"of",
"environments",
"to",
"read"
] | 5a7cc8f8252251cbdf4f4112965801f9dfe2831d | https://github.com/rochacbruno/dynaconf/blob/5a7cc8f8252251cbdf4f4112965801f9dfe2831d/dynaconf/loaders/vault_loader.py#L18-L40 | train |
rochacbruno/dynaconf | dynaconf/loaders/vault_loader.py | load | def load(obj, env=None, silent=None, key=None):
"""Reads and loads in to "settings" a single key or all keys from vault
:param obj: the settings instance
:param env: settings env default='DYNACONF'
:param silent: if errors should raise
:param key: if defined load a single key, else load all in env
... | python | def load(obj, env=None, silent=None, key=None):
"""Reads and loads in to "settings" a single key or all keys from vault
:param obj: the settings instance
:param env: settings env default='DYNACONF'
:param silent: if errors should raise
:param key: if defined load a single key, else load all in env
... | [
"def",
"load",
"(",
"obj",
",",
"env",
"=",
"None",
",",
"silent",
"=",
"None",
",",
"key",
"=",
"None",
")",
":",
"client",
"=",
"get_client",
"(",
"obj",
")",
"env_list",
"=",
"_get_env_list",
"(",
"obj",
",",
"env",
")",
"for",
"env",
"in",
"e... | Reads and loads in to "settings" a single key or all keys from vault
:param obj: the settings instance
:param env: settings env default='DYNACONF'
:param silent: if errors should raise
:param key: if defined load a single key, else load all in env
:return: None | [
"Reads",
"and",
"loads",
"in",
"to",
"settings",
"a",
"single",
"key",
"or",
"all",
"keys",
"from",
"vault"
] | 5a7cc8f8252251cbdf4f4112965801f9dfe2831d | https://github.com/rochacbruno/dynaconf/blob/5a7cc8f8252251cbdf4f4112965801f9dfe2831d/dynaconf/loaders/vault_loader.py#L53-L97 | train |
rochacbruno/dynaconf | dynaconf/cli.py | set_settings | def set_settings(instance=None):
"""Pick correct settings instance and set it to a global variable."""
global settings
settings = None
if instance:
settings = import_settings(instance)
elif "INSTANCE_FOR_DYNACONF" in os.environ:
settings = import_settings(os.environ["INSTANCE_FOR... | python | def set_settings(instance=None):
"""Pick correct settings instance and set it to a global variable."""
global settings
settings = None
if instance:
settings = import_settings(instance)
elif "INSTANCE_FOR_DYNACONF" in os.environ:
settings = import_settings(os.environ["INSTANCE_FOR... | [
"def",
"set_settings",
"(",
"instance",
"=",
"None",
")",
":",
"global",
"settings",
"settings",
"=",
"None",
"if",
"instance",
":",
"settings",
"=",
"import_settings",
"(",
"instance",
")",
"elif",
"\"INSTANCE_FOR_DYNACONF\"",
"in",
"os",
".",
"environ",
":",... | Pick correct settings instance and set it to a global variable. | [
"Pick",
"correct",
"settings",
"instance",
"and",
"set",
"it",
"to",
"a",
"global",
"variable",
"."
] | 5a7cc8f8252251cbdf4f4112965801f9dfe2831d | https://github.com/rochacbruno/dynaconf/blob/5a7cc8f8252251cbdf4f4112965801f9dfe2831d/dynaconf/cli.py#L33-L81 | train |
rochacbruno/dynaconf | dynaconf/cli.py | import_settings | def import_settings(dotted_path):
"""Import settings instance from python dotted path.
Last item in dotted path must be settings instace.
Example: import_settings('path.to.settings')
"""
if "." in dotted_path:
module, name = dotted_path.rsplit(".", 1)
else:
raise click.UsageErr... | python | def import_settings(dotted_path):
"""Import settings instance from python dotted path.
Last item in dotted path must be settings instace.
Example: import_settings('path.to.settings')
"""
if "." in dotted_path:
module, name = dotted_path.rsplit(".", 1)
else:
raise click.UsageErr... | [
"def",
"import_settings",
"(",
"dotted_path",
")",
":",
"if",
"\".\"",
"in",
"dotted_path",
":",
"module",
",",
"name",
"=",
"dotted_path",
".",
"rsplit",
"(",
"\".\"",
",",
"1",
")",
"else",
":",
"raise",
"click",
".",
"UsageError",
"(",
"\"invalid path t... | Import settings instance from python dotted path.
Last item in dotted path must be settings instace.
Example: import_settings('path.to.settings') | [
"Import",
"settings",
"instance",
"from",
"python",
"dotted",
"path",
"."
] | 5a7cc8f8252251cbdf4f4112965801f9dfe2831d | https://github.com/rochacbruno/dynaconf/blob/5a7cc8f8252251cbdf4f4112965801f9dfe2831d/dynaconf/cli.py#L84-L104 | train |
rochacbruno/dynaconf | dynaconf/cli.py | read_file_in_root_directory | def read_file_in_root_directory(*names, **kwargs):
"""Read a file on root dir."""
return read_file(
os.path.join(os.path.dirname(__file__), *names),
encoding=kwargs.get("encoding", "utf-8"),
) | python | def read_file_in_root_directory(*names, **kwargs):
"""Read a file on root dir."""
return read_file(
os.path.join(os.path.dirname(__file__), *names),
encoding=kwargs.get("encoding", "utf-8"),
) | [
"def",
"read_file_in_root_directory",
"(",
"*",
"names",
",",
"**",
"kwargs",
")",
":",
"return",
"read_file",
"(",
"os",
".",
"path",
".",
"join",
"(",
"os",
".",
"path",
".",
"dirname",
"(",
"__file__",
")",
",",
"*",
"names",
")",
",",
"encoding",
... | Read a file on root dir. | [
"Read",
"a",
"file",
"on",
"root",
"dir",
"."
] | 5a7cc8f8252251cbdf4f4112965801f9dfe2831d | https://github.com/rochacbruno/dynaconf/blob/5a7cc8f8252251cbdf4f4112965801f9dfe2831d/dynaconf/cli.py#L119-L124 | train |
rochacbruno/dynaconf | dynaconf/cli.py | show_banner | def show_banner(ctx, param, value):
"""Shows dynaconf awesome banner"""
if not value or ctx.resilient_parsing:
return
set_settings()
click.echo(settings.dynaconf_banner)
click.echo("Learn more at: http://github.com/rochacbruno/dynaconf")
ctx.exit() | python | def show_banner(ctx, param, value):
"""Shows dynaconf awesome banner"""
if not value or ctx.resilient_parsing:
return
set_settings()
click.echo(settings.dynaconf_banner)
click.echo("Learn more at: http://github.com/rochacbruno/dynaconf")
ctx.exit() | [
"def",
"show_banner",
"(",
"ctx",
",",
"param",
",",
"value",
")",
":",
"if",
"not",
"value",
"or",
"ctx",
".",
"resilient_parsing",
":",
"return",
"set_settings",
"(",
")",
"click",
".",
"echo",
"(",
"settings",
".",
"dynaconf_banner",
")",
"click",
"."... | Shows dynaconf awesome banner | [
"Shows",
"dynaconf",
"awesome",
"banner"
] | 5a7cc8f8252251cbdf4f4112965801f9dfe2831d | https://github.com/rochacbruno/dynaconf/blob/5a7cc8f8252251cbdf4f4112965801f9dfe2831d/dynaconf/cli.py#L143-L150 | train |
rochacbruno/dynaconf | dynaconf/cli.py | write | def write(to, _vars, _secrets, path, env, y):
"""Writes data to specific source"""
_vars = split_vars(_vars)
_secrets = split_vars(_secrets)
loader = importlib.import_module("dynaconf.loaders.{}_loader".format(to))
if to in EXTS:
# Lets write to a file
path = Path(path)
if... | python | def write(to, _vars, _secrets, path, env, y):
"""Writes data to specific source"""
_vars = split_vars(_vars)
_secrets = split_vars(_secrets)
loader = importlib.import_module("dynaconf.loaders.{}_loader".format(to))
if to in EXTS:
# Lets write to a file
path = Path(path)
if... | [
"def",
"write",
"(",
"to",
",",
"_vars",
",",
"_secrets",
",",
"path",
",",
"env",
",",
"y",
")",
":",
"_vars",
"=",
"split_vars",
"(",
"_vars",
")",
"_secrets",
"=",
"split_vars",
"(",
"_secrets",
")",
"loader",
"=",
"importlib",
".",
"import_module",... | Writes data to specific source | [
"Writes",
"data",
"to",
"specific",
"source"
] | 5a7cc8f8252251cbdf4f4112965801f9dfe2831d | https://github.com/rochacbruno/dynaconf/blob/5a7cc8f8252251cbdf4f4112965801f9dfe2831d/dynaconf/cli.py#L496-L562 | train |
rochacbruno/dynaconf | dynaconf/cli.py | validate | def validate(path): # pragma: no cover
"""Validates Dynaconf settings based on rules defined in
dynaconf_validators.toml"""
# reads the 'dynaconf_validators.toml' from path
# for each section register the validator for specific env
# call validate
path = Path(path)
if not str(path).endswi... | python | def validate(path): # pragma: no cover
"""Validates Dynaconf settings based on rules defined in
dynaconf_validators.toml"""
# reads the 'dynaconf_validators.toml' from path
# for each section register the validator for specific env
# call validate
path = Path(path)
if not str(path).endswi... | [
"def",
"validate",
"(",
"path",
")",
":",
"path",
"=",
"Path",
"(",
"path",
")",
"if",
"not",
"str",
"(",
"path",
")",
".",
"endswith",
"(",
"\".toml\"",
")",
":",
"path",
"=",
"path",
"/",
"\"dynaconf_validators.toml\"",
"if",
"not",
"path",
".",
"e... | Validates Dynaconf settings based on rules defined in
dynaconf_validators.toml | [
"Validates",
"Dynaconf",
"settings",
"based",
"on",
"rules",
"defined",
"in",
"dynaconf_validators",
".",
"toml"
] | 5a7cc8f8252251cbdf4f4112965801f9dfe2831d | https://github.com/rochacbruno/dynaconf/blob/5a7cc8f8252251cbdf4f4112965801f9dfe2831d/dynaconf/cli.py#L569-L620 | train |
rochacbruno/dynaconf | example/common/program.py | connect | def connect(server, port, username, password):
"""This function might be something coming from your ORM"""
print("-" * 79)
print("Connecting to: {}".format(server))
print("At port: {}".format(port))
print("Using username: {}".format(username))
print("Using password: {}".format(password))
pri... | python | def connect(server, port, username, password):
"""This function might be something coming from your ORM"""
print("-" * 79)
print("Connecting to: {}".format(server))
print("At port: {}".format(port))
print("Using username: {}".format(username))
print("Using password: {}".format(password))
pri... | [
"def",
"connect",
"(",
"server",
",",
"port",
",",
"username",
",",
"password",
")",
":",
"print",
"(",
"\"-\"",
"*",
"79",
")",
"print",
"(",
"\"Connecting to: {}\"",
".",
"format",
"(",
"server",
")",
")",
"print",
"(",
"\"At port: {}\"",
".",
"format"... | This function might be something coming from your ORM | [
"This",
"function",
"might",
"be",
"something",
"coming",
"from",
"your",
"ORM"
] | 5a7cc8f8252251cbdf4f4112965801f9dfe2831d | https://github.com/rochacbruno/dynaconf/blob/5a7cc8f8252251cbdf4f4112965801f9dfe2831d/example/common/program.py#L4-L11 | train |
rochacbruno/dynaconf | dynaconf/loaders/env_loader.py | write | def write(settings_path, settings_data, **kwargs):
"""Write data to .env file"""
for key, value in settings_data.items():
dotenv_cli.set_key(str(settings_path), key.upper(), str(value)) | python | def write(settings_path, settings_data, **kwargs):
"""Write data to .env file"""
for key, value in settings_data.items():
dotenv_cli.set_key(str(settings_path), key.upper(), str(value)) | [
"def",
"write",
"(",
"settings_path",
",",
"settings_data",
",",
"**",
"kwargs",
")",
":",
"for",
"key",
",",
"value",
"in",
"settings_data",
".",
"items",
"(",
")",
":",
"dotenv_cli",
".",
"set_key",
"(",
"str",
"(",
"settings_path",
")",
",",
"key",
... | Write data to .env file | [
"Write",
"data",
"to",
".",
"env",
"file"
] | 5a7cc8f8252251cbdf4f4112965801f9dfe2831d | https://github.com/rochacbruno/dynaconf/blob/5a7cc8f8252251cbdf4f4112965801f9dfe2831d/dynaconf/loaders/env_loader.py#L60-L63 | train |
rochacbruno/dynaconf | dynaconf/utils/parse_conf.py | parse_with_toml | def parse_with_toml(data):
"""Uses TOML syntax to parse data"""
try:
return toml.loads("key={}".format(data), DynaBox).key
except toml.TomlDecodeError:
return data | python | def parse_with_toml(data):
"""Uses TOML syntax to parse data"""
try:
return toml.loads("key={}".format(data), DynaBox).key
except toml.TomlDecodeError:
return data | [
"def",
"parse_with_toml",
"(",
"data",
")",
":",
"try",
":",
"return",
"toml",
".",
"loads",
"(",
"\"key={}\"",
".",
"format",
"(",
"data",
")",
",",
"DynaBox",
")",
".",
"key",
"except",
"toml",
".",
"TomlDecodeError",
":",
"return",
"data"
] | Uses TOML syntax to parse data | [
"Uses",
"TOML",
"syntax",
"to",
"parse",
"data"
] | 5a7cc8f8252251cbdf4f4112965801f9dfe2831d | https://github.com/rochacbruno/dynaconf/blob/5a7cc8f8252251cbdf4f4112965801f9dfe2831d/dynaconf/utils/parse_conf.py#L28-L33 | train |
rochacbruno/dynaconf | dynaconf/loaders/base.py | BaseLoader.load | def load(self, filename=None, key=None, silent=True):
"""
Reads and loads in to `self.obj` a single key or all keys from source
:param filename: Optional filename to load
:param key: if provided load a single key
:param silent: if load erros should be silenced
"""
... | python | def load(self, filename=None, key=None, silent=True):
"""
Reads and loads in to `self.obj` a single key or all keys from source
:param filename: Optional filename to load
:param key: if provided load a single key
:param silent: if load erros should be silenced
"""
... | [
"def",
"load",
"(",
"self",
",",
"filename",
"=",
"None",
",",
"key",
"=",
"None",
",",
"silent",
"=",
"True",
")",
":",
"filename",
"=",
"filename",
"or",
"self",
".",
"obj",
".",
"get",
"(",
"self",
".",
"identifier",
".",
"upper",
"(",
")",
")... | Reads and loads in to `self.obj` a single key or all keys from source
:param filename: Optional filename to load
:param key: if provided load a single key
:param silent: if load erros should be silenced | [
"Reads",
"and",
"loads",
"in",
"to",
"self",
".",
"obj",
"a",
"single",
"key",
"or",
"all",
"keys",
"from",
"source"
] | 5a7cc8f8252251cbdf4f4112965801f9dfe2831d | https://github.com/rochacbruno/dynaconf/blob/5a7cc8f8252251cbdf4f4112965801f9dfe2831d/dynaconf/loaders/base.py#L44-L84 | train |
rochacbruno/dynaconf | dynaconf/base.py | LazySettings._setup | def _setup(self):
"""Initial setup, run once."""
default_settings.reload()
environment_variable = self._kwargs.get(
"ENVVAR_FOR_DYNACONF", default_settings.ENVVAR_FOR_DYNACONF
)
settings_module = os.environ.get(environment_variable)
self._wrapped = Settings(
... | python | def _setup(self):
"""Initial setup, run once."""
default_settings.reload()
environment_variable = self._kwargs.get(
"ENVVAR_FOR_DYNACONF", default_settings.ENVVAR_FOR_DYNACONF
)
settings_module = os.environ.get(environment_variable)
self._wrapped = Settings(
... | [
"def",
"_setup",
"(",
"self",
")",
":",
"default_settings",
".",
"reload",
"(",
")",
"environment_variable",
"=",
"self",
".",
"_kwargs",
".",
"get",
"(",
"\"ENVVAR_FOR_DYNACONF\"",
",",
"default_settings",
".",
"ENVVAR_FOR_DYNACONF",
")",
"settings_module",
"=",
... | Initial setup, run once. | [
"Initial",
"setup",
"run",
"once",
"."
] | 5a7cc8f8252251cbdf4f4112965801f9dfe2831d | https://github.com/rochacbruno/dynaconf/blob/5a7cc8f8252251cbdf4f4112965801f9dfe2831d/dynaconf/base.py#L115-L125 | train |
rochacbruno/dynaconf | dynaconf/base.py | LazySettings.configure | def configure(self, settings_module=None, **kwargs):
"""
Allows user to reconfigure settings object passing a new settings
module or separated kwargs
:param settings_module: defines the setttings file
:param kwargs: override default settings
"""
default_settings... | python | def configure(self, settings_module=None, **kwargs):
"""
Allows user to reconfigure settings object passing a new settings
module or separated kwargs
:param settings_module: defines the setttings file
:param kwargs: override default settings
"""
default_settings... | [
"def",
"configure",
"(",
"self",
",",
"settings_module",
"=",
"None",
",",
"**",
"kwargs",
")",
":",
"default_settings",
".",
"reload",
"(",
")",
"environment_var",
"=",
"self",
".",
"_kwargs",
".",
"get",
"(",
"\"ENVVAR_FOR_DYNACONF\"",
",",
"default_settings... | Allows user to reconfigure settings object passing a new settings
module or separated kwargs
:param settings_module: defines the setttings file
:param kwargs: override default settings | [
"Allows",
"user",
"to",
"reconfigure",
"settings",
"object",
"passing",
"a",
"new",
"settings",
"module",
"or",
"separated",
"kwargs"
] | 5a7cc8f8252251cbdf4f4112965801f9dfe2831d | https://github.com/rochacbruno/dynaconf/blob/5a7cc8f8252251cbdf4f4112965801f9dfe2831d/dynaconf/base.py#L127-L143 | train |
rochacbruno/dynaconf | dynaconf/base.py | Settings.as_dict | def as_dict(self, env=None, internal=False):
"""Returns a dictionary with set key and values.
:param env: Str env name, default self.current_env `DEVELOPMENT`
:param internal: bool - should include dynaconf internal vars?
"""
ctx_mgr = suppress() if env is None else self.using_e... | python | def as_dict(self, env=None, internal=False):
"""Returns a dictionary with set key and values.
:param env: Str env name, default self.current_env `DEVELOPMENT`
:param internal: bool - should include dynaconf internal vars?
"""
ctx_mgr = suppress() if env is None else self.using_e... | [
"def",
"as_dict",
"(",
"self",
",",
"env",
"=",
"None",
",",
"internal",
"=",
"False",
")",
":",
"ctx_mgr",
"=",
"suppress",
"(",
")",
"if",
"env",
"is",
"None",
"else",
"self",
".",
"using_env",
"(",
"env",
")",
"with",
"ctx_mgr",
":",
"data",
"="... | Returns a dictionary with set key and values.
:param env: Str env name, default self.current_env `DEVELOPMENT`
:param internal: bool - should include dynaconf internal vars? | [
"Returns",
"a",
"dictionary",
"with",
"set",
"key",
"and",
"values",
"."
] | 5a7cc8f8252251cbdf4f4112965801f9dfe2831d | https://github.com/rochacbruno/dynaconf/blob/5a7cc8f8252251cbdf4f4112965801f9dfe2831d/dynaconf/base.py#L237-L250 | train |
rochacbruno/dynaconf | dynaconf/base.py | Settings._dotted_get | def _dotted_get(self, dotted_key, default=None, **kwargs):
"""
Perform dotted key lookups and keep track of where we are.
"""
split_key = dotted_key.split(".")
name, keys = split_key[0], split_key[1:]
result = self.get(name, default=default, **kwargs)
self._memoiz... | python | def _dotted_get(self, dotted_key, default=None, **kwargs):
"""
Perform dotted key lookups and keep track of where we are.
"""
split_key = dotted_key.split(".")
name, keys = split_key[0], split_key[1:]
result = self.get(name, default=default, **kwargs)
self._memoiz... | [
"def",
"_dotted_get",
"(",
"self",
",",
"dotted_key",
",",
"default",
"=",
"None",
",",
"**",
"kwargs",
")",
":",
"split_key",
"=",
"dotted_key",
".",
"split",
"(",
"\".\"",
")",
"name",
",",
"keys",
"=",
"split_key",
"[",
"0",
"]",
",",
"split_key",
... | Perform dotted key lookups and keep track of where we are. | [
"Perform",
"dotted",
"key",
"lookups",
"and",
"keep",
"track",
"of",
"where",
"we",
"are",
"."
] | 5a7cc8f8252251cbdf4f4112965801f9dfe2831d | https://github.com/rochacbruno/dynaconf/blob/5a7cc8f8252251cbdf4f4112965801f9dfe2831d/dynaconf/base.py#L252-L268 | train |
rochacbruno/dynaconf | dynaconf/base.py | Settings.exists | def exists(self, key, fresh=False):
"""Check if key exists
:param key: the name of setting variable
:param fresh: if key should be taken from source direclty
:return: Boolean
"""
key = key.upper()
if key in self._deleted:
return False
return s... | python | def exists(self, key, fresh=False):
"""Check if key exists
:param key: the name of setting variable
:param fresh: if key should be taken from source direclty
:return: Boolean
"""
key = key.upper()
if key in self._deleted:
return False
return s... | [
"def",
"exists",
"(",
"self",
",",
"key",
",",
"fresh",
"=",
"False",
")",
":",
"key",
"=",
"key",
".",
"upper",
"(",
")",
"if",
"key",
"in",
"self",
".",
"_deleted",
":",
"return",
"False",
"return",
"self",
".",
"get",
"(",
"key",
",",
"fresh",... | Check if key exists
:param key: the name of setting variable
:param fresh: if key should be taken from source direclty
:return: Boolean | [
"Check",
"if",
"key",
"exists"
] | 5a7cc8f8252251cbdf4f4112965801f9dfe2831d | https://github.com/rochacbruno/dynaconf/blob/5a7cc8f8252251cbdf4f4112965801f9dfe2831d/dynaconf/base.py#L310-L320 | train |
rochacbruno/dynaconf | dynaconf/base.py | Settings.get_environ | def get_environ(self, key, default=None, cast=None):
"""Get value from environment variable using os.environ.get
:param key: The name of the setting value, will always be upper case
:param default: In case of not found it will be returned
:param cast: Should cast in to @int, @float, @bo... | python | def get_environ(self, key, default=None, cast=None):
"""Get value from environment variable using os.environ.get
:param key: The name of the setting value, will always be upper case
:param default: In case of not found it will be returned
:param cast: Should cast in to @int, @float, @bo... | [
"def",
"get_environ",
"(",
"self",
",",
"key",
",",
"default",
"=",
"None",
",",
"cast",
"=",
"None",
")",
":",
"key",
"=",
"key",
".",
"upper",
"(",
")",
"data",
"=",
"self",
".",
"environ",
".",
"get",
"(",
"key",
",",
"default",
")",
"if",
"... | Get value from environment variable using os.environ.get
:param key: The name of the setting value, will always be upper case
:param default: In case of not found it will be returned
:param cast: Should cast in to @int, @float, @bool or @json ?
or cast must be true to use cast inferenc... | [
"Get",
"value",
"from",
"environment",
"variable",
"using",
"os",
".",
"environ",
".",
"get"
] | 5a7cc8f8252251cbdf4f4112965801f9dfe2831d | https://github.com/rochacbruno/dynaconf/blob/5a7cc8f8252251cbdf4f4112965801f9dfe2831d/dynaconf/base.py#L333-L349 | train |
rochacbruno/dynaconf | dynaconf/base.py | Settings.settings_module | def settings_module(self):
"""Gets SETTINGS_MODULE variable"""
settings_module = parse_conf_data(
os.environ.get(
self.ENVVAR_FOR_DYNACONF, self.SETTINGS_FILE_FOR_DYNACONF
),
tomlfy=True,
)
if settings_module != getattr(self, "SETTINGS_... | python | def settings_module(self):
"""Gets SETTINGS_MODULE variable"""
settings_module = parse_conf_data(
os.environ.get(
self.ENVVAR_FOR_DYNACONF, self.SETTINGS_FILE_FOR_DYNACONF
),
tomlfy=True,
)
if settings_module != getattr(self, "SETTINGS_... | [
"def",
"settings_module",
"(",
"self",
")",
":",
"settings_module",
"=",
"parse_conf_data",
"(",
"os",
".",
"environ",
".",
"get",
"(",
"self",
".",
"ENVVAR_FOR_DYNACONF",
",",
"self",
".",
"SETTINGS_FILE_FOR_DYNACONF",
")",
",",
"tomlfy",
"=",
"True",
",",
... | Gets SETTINGS_MODULE variable | [
"Gets",
"SETTINGS_MODULE",
"variable"
] | 5a7cc8f8252251cbdf4f4112965801f9dfe2831d | https://github.com/rochacbruno/dynaconf/blob/5a7cc8f8252251cbdf4f4112965801f9dfe2831d/dynaconf/base.py#L472-L482 | train |
rochacbruno/dynaconf | dynaconf/base.py | Settings.clean | def clean(self, *args, **kwargs):
"""Clean all loaded values to reload when switching envs"""
for key in list(self.store.keys()):
self.unset(key) | python | def clean(self, *args, **kwargs):
"""Clean all loaded values to reload when switching envs"""
for key in list(self.store.keys()):
self.unset(key) | [
"def",
"clean",
"(",
"self",
",",
"*",
"args",
",",
"**",
"kwargs",
")",
":",
"for",
"key",
"in",
"list",
"(",
"self",
".",
"store",
".",
"keys",
"(",
")",
")",
":",
"self",
".",
"unset",
"(",
"key",
")"
] | Clean all loaded values to reload when switching envs | [
"Clean",
"all",
"loaded",
"values",
"to",
"reload",
"when",
"switching",
"envs"
] | 5a7cc8f8252251cbdf4f4112965801f9dfe2831d | https://github.com/rochacbruno/dynaconf/blob/5a7cc8f8252251cbdf4f4112965801f9dfe2831d/dynaconf/base.py#L534-L537 | train |
rochacbruno/dynaconf | dynaconf/base.py | Settings.unset | def unset(self, key):
"""Unset on all references
:param key: The key to be unset
"""
key = key.strip().upper()
if key not in dir(default_settings) and key not in self._defaults:
self.logger.debug("Unset %s", key)
delattr(self, key)
self.store.... | python | def unset(self, key):
"""Unset on all references
:param key: The key to be unset
"""
key = key.strip().upper()
if key not in dir(default_settings) and key not in self._defaults:
self.logger.debug("Unset %s", key)
delattr(self, key)
self.store.... | [
"def",
"unset",
"(",
"self",
",",
"key",
")",
":",
"key",
"=",
"key",
".",
"strip",
"(",
")",
".",
"upper",
"(",
")",
"if",
"key",
"not",
"in",
"dir",
"(",
"default_settings",
")",
"and",
"key",
"not",
"in",
"self",
".",
"_defaults",
":",
"self",... | Unset on all references
:param key: The key to be unset | [
"Unset",
"on",
"all",
"references"
] | 5a7cc8f8252251cbdf4f4112965801f9dfe2831d | https://github.com/rochacbruno/dynaconf/blob/5a7cc8f8252251cbdf4f4112965801f9dfe2831d/dynaconf/base.py#L539-L548 | train |
rochacbruno/dynaconf | dynaconf/base.py | Settings.set | def set(
self,
key,
value,
loader_identifier=None,
tomlfy=False,
dotted_lookup=True,
is_secret=False,
):
"""Set a value storing references for the loader
:param key: The key to store
:param value: The value to store
:param load... | python | def set(
self,
key,
value,
loader_identifier=None,
tomlfy=False,
dotted_lookup=True,
is_secret=False,
):
"""Set a value storing references for the loader
:param key: The key to store
:param value: The value to store
:param load... | [
"def",
"set",
"(",
"self",
",",
"key",
",",
"value",
",",
"loader_identifier",
"=",
"None",
",",
"tomlfy",
"=",
"False",
",",
"dotted_lookup",
"=",
"True",
",",
"is_secret",
"=",
"False",
",",
")",
":",
"if",
"\".\"",
"in",
"key",
"and",
"dotted_lookup... | Set a value storing references for the loader
:param key: The key to store
:param value: The value to store
:param loader_identifier: Optional loader name e.g: toml, yaml etc.
:param tomlfy: Bool define if value is parsed by toml (defaults False)
:param is_secret: Bool define if... | [
"Set",
"a",
"value",
"storing",
"references",
"for",
"the",
"loader"
] | 5a7cc8f8252251cbdf4f4112965801f9dfe2831d | https://github.com/rochacbruno/dynaconf/blob/5a7cc8f8252251cbdf4f4112965801f9dfe2831d/dynaconf/base.py#L572-L616 | train |
rochacbruno/dynaconf | dynaconf/base.py | Settings._merge_before_set | def _merge_before_set(self, key, existing, value, is_secret):
"""Merge the new value being set with the existing value before set"""
def _log_before_merging(_value):
self.logger.debug(
"Merging existing %s: %s with new: %s", key, existing, _value
)
def _... | python | def _merge_before_set(self, key, existing, value, is_secret):
"""Merge the new value being set with the existing value before set"""
def _log_before_merging(_value):
self.logger.debug(
"Merging existing %s: %s with new: %s", key, existing, _value
)
def _... | [
"def",
"_merge_before_set",
"(",
"self",
",",
"key",
",",
"existing",
",",
"value",
",",
"is_secret",
")",
":",
"def",
"_log_before_merging",
"(",
"_value",
")",
":",
"self",
".",
"logger",
".",
"debug",
"(",
"\"Merging existing %s: %s with new: %s\"",
",",
"k... | Merge the new value being set with the existing value before set | [
"Merge",
"the",
"new",
"value",
"being",
"set",
"with",
"the",
"existing",
"value",
"before",
"set"
] | 5a7cc8f8252251cbdf4f4112965801f9dfe2831d | https://github.com/rochacbruno/dynaconf/blob/5a7cc8f8252251cbdf4f4112965801f9dfe2831d/dynaconf/base.py#L655-L713 | train |
rochacbruno/dynaconf | dynaconf/base.py | Settings.loaders | def loaders(self): # pragma: no cover
"""Return available loaders"""
if self.LOADERS_FOR_DYNACONF in (None, 0, "0", "false", False):
self.logger.info("No loader defined")
return []
if not self._loaders:
for loader_module_name in self.LOADERS_FOR_DYNACONF:
... | python | def loaders(self): # pragma: no cover
"""Return available loaders"""
if self.LOADERS_FOR_DYNACONF in (None, 0, "0", "false", False):
self.logger.info("No loader defined")
return []
if not self._loaders:
for loader_module_name in self.LOADERS_FOR_DYNACONF:
... | [
"def",
"loaders",
"(",
"self",
")",
":",
"if",
"self",
".",
"LOADERS_FOR_DYNACONF",
"in",
"(",
"None",
",",
"0",
",",
"\"0\"",
",",
"\"false\"",
",",
"False",
")",
":",
"self",
".",
"logger",
".",
"info",
"(",
"\"No loader defined\"",
")",
"return",
"[... | Return available loaders | [
"Return",
"available",
"loaders"
] | 5a7cc8f8252251cbdf4f4112965801f9dfe2831d | https://github.com/rochacbruno/dynaconf/blob/5a7cc8f8252251cbdf4f4112965801f9dfe2831d/dynaconf/base.py#L716-L727 | train |
rochacbruno/dynaconf | dynaconf/base.py | Settings.reload | def reload(self, env=None, silent=None): # pragma: no cover
"""Clean end Execute all loaders"""
self.clean()
self.execute_loaders(env, silent) | python | def reload(self, env=None, silent=None): # pragma: no cover
"""Clean end Execute all loaders"""
self.clean()
self.execute_loaders(env, silent) | [
"def",
"reload",
"(",
"self",
",",
"env",
"=",
"None",
",",
"silent",
"=",
"None",
")",
":",
"self",
".",
"clean",
"(",
")",
"self",
".",
"execute_loaders",
"(",
"env",
",",
"silent",
")"
] | Clean end Execute all loaders | [
"Clean",
"end",
"Execute",
"all",
"loaders"
] | 5a7cc8f8252251cbdf4f4112965801f9dfe2831d | https://github.com/rochacbruno/dynaconf/blob/5a7cc8f8252251cbdf4f4112965801f9dfe2831d/dynaconf/base.py#L729-L732 | train |
rochacbruno/dynaconf | dynaconf/base.py | Settings.execute_loaders | def execute_loaders(self, env=None, silent=None, key=None, filename=None):
"""Execute all internal and registered loaders
:param env: The environment to load
:param silent: If loading erros is silenced
:param key: if provided load a single key
:param filename: optional custom fi... | python | def execute_loaders(self, env=None, silent=None, key=None, filename=None):
"""Execute all internal and registered loaders
:param env: The environment to load
:param silent: If loading erros is silenced
:param key: if provided load a single key
:param filename: optional custom fi... | [
"def",
"execute_loaders",
"(",
"self",
",",
"env",
"=",
"None",
",",
"silent",
"=",
"None",
",",
"key",
"=",
"None",
",",
"filename",
"=",
"None",
")",
":",
"if",
"key",
"is",
"None",
":",
"default_loader",
"(",
"self",
",",
"self",
".",
"_defaults",... | Execute all internal and registered loaders
:param env: The environment to load
:param silent: If loading erros is silenced
:param key: if provided load a single key
:param filename: optional custom filename to load | [
"Execute",
"all",
"internal",
"and",
"registered",
"loaders"
] | 5a7cc8f8252251cbdf4f4112965801f9dfe2831d | https://github.com/rochacbruno/dynaconf/blob/5a7cc8f8252251cbdf4f4112965801f9dfe2831d/dynaconf/base.py#L734-L755 | train |
rochacbruno/dynaconf | dynaconf/base.py | Settings.load_includes | def load_includes(self, env, silent, key):
"""Do we have any nested includes we need to process?"""
includes = self.get("DYNACONF_INCLUDE", [])
includes.extend(ensure_a_list(self.get("INCLUDES_FOR_DYNACONF")))
if includes:
self.logger.debug("Processing includes %s", includes)... | python | def load_includes(self, env, silent, key):
"""Do we have any nested includes we need to process?"""
includes = self.get("DYNACONF_INCLUDE", [])
includes.extend(ensure_a_list(self.get("INCLUDES_FOR_DYNACONF")))
if includes:
self.logger.debug("Processing includes %s", includes)... | [
"def",
"load_includes",
"(",
"self",
",",
"env",
",",
"silent",
",",
"key",
")",
":",
"includes",
"=",
"self",
".",
"get",
"(",
"\"DYNACONF_INCLUDE\"",
",",
"[",
"]",
")",
"includes",
".",
"extend",
"(",
"ensure_a_list",
"(",
"self",
".",
"get",
"(",
... | Do we have any nested includes we need to process? | [
"Do",
"we",
"have",
"any",
"nested",
"includes",
"we",
"need",
"to",
"process?"
] | 5a7cc8f8252251cbdf4f4112965801f9dfe2831d | https://github.com/rochacbruno/dynaconf/blob/5a7cc8f8252251cbdf4f4112965801f9dfe2831d/dynaconf/base.py#L757-L763 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.