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
nitmir/django-cas-server
cas_server/views.py
FederateAuth.get_cas_client
def get_cas_client(self, request, provider, renew=False): """ return a CAS client object matching provider :param django.http.HttpRequest request: The current request object :param cas_server.models.FederatedIendityProvider provider: the user identity provider :r...
python
def get_cas_client(self, request, provider, renew=False): """ return a CAS client object matching provider :param django.http.HttpRequest request: The current request object :param cas_server.models.FederatedIendityProvider provider: the user identity provider :r...
[ "def", "get_cas_client", "(", "self", ",", "request", ",", "provider", ",", "renew", "=", "False", ")", ":", "service_url", "=", "utils", ".", "get_current_url", "(", "request", ",", "{", "\"ticket\"", ",", "\"provider\"", "}", ")", "self", ".", "service_u...
return a CAS client object matching provider :param django.http.HttpRequest request: The current request object :param cas_server.models.FederatedIendityProvider provider: the user identity provider :return: The user CAS client object :rtype: :class:`federate.CASFederate...
[ "return", "a", "CAS", "client", "object", "matching", "provider" ]
d106181b94c444f1946269da5c20f6c904840ad3
https://github.com/nitmir/django-cas-server/blob/d106181b94c444f1946269da5c20f6c904840ad3/cas_server/views.py#L244-L257
train
nitmir/django-cas-server
cas_server/views.py
FederateAuth.post
def post(self, request, provider=None): """ method called on POST request :param django.http.HttpRequest request: The current request object :param unicode provider: Optional parameter. The user provider suffix. """ # if settings.CAS_FEDERATE is not True redi...
python
def post(self, request, provider=None): """ method called on POST request :param django.http.HttpRequest request: The current request object :param unicode provider: Optional parameter. The user provider suffix. """ # if settings.CAS_FEDERATE is not True redi...
[ "def", "post", "(", "self", ",", "request", ",", "provider", "=", "None", ")", ":", "if", "not", "settings", ".", "CAS_FEDERATE", ":", "logger", ".", "warning", "(", "\"CAS_FEDERATE is False, set it to True to use federation\"", ")", "return", "redirect", "(", "...
method called on POST request :param django.http.HttpRequest request: The current request object :param unicode provider: Optional parameter. The user provider suffix.
[ "method", "called", "on", "POST", "request" ]
d106181b94c444f1946269da5c20f6c904840ad3
https://github.com/nitmir/django-cas-server/blob/d106181b94c444f1946269da5c20f6c904840ad3/cas_server/views.py#L259-L301
train
nitmir/django-cas-server
cas_server/views.py
FederateAuth.get
def get(self, request, provider=None): """ method called on GET request :param django.http.HttpRequestself. request: The current request object :param unicode provider: Optional parameter. The user provider suffix. """ # if settings.CAS_FEDERATE is not True r...
python
def get(self, request, provider=None): """ method called on GET request :param django.http.HttpRequestself. request: The current request object :param unicode provider: Optional parameter. The user provider suffix. """ # if settings.CAS_FEDERATE is not True r...
[ "def", "get", "(", "self", ",", "request", ",", "provider", "=", "None", ")", ":", "if", "not", "settings", ".", "CAS_FEDERATE", ":", "logger", ".", "warning", "(", "\"CAS_FEDERATE is False, set it to True to use federation\"", ")", "return", "redirect", "(", "\...
method called on GET request :param django.http.HttpRequestself. request: The current request object :param unicode provider: Optional parameter. The user provider suffix.
[ "method", "called", "on", "GET", "request" ]
d106181b94c444f1946269da5c20f6c904840ad3
https://github.com/nitmir/django-cas-server/blob/d106181b94c444f1946269da5c20f6c904840ad3/cas_server/views.py#L303-L392
train
nitmir/django-cas-server
cas_server/views.py
LoginView.init_post
def init_post(self, request): """ Initialize POST received parameters :param django.http.HttpRequest request: The current request object """ self.request = request self.service = request.POST.get('service') self.renew = bool(request.POST.get('renew') and ...
python
def init_post(self, request): """ Initialize POST received parameters :param django.http.HttpRequest request: The current request object """ self.request = request self.service = request.POST.get('service') self.renew = bool(request.POST.get('renew') and ...
[ "def", "init_post", "(", "self", ",", "request", ")", ":", "self", ".", "request", "=", "request", "self", ".", "service", "=", "request", ".", "POST", ".", "get", "(", "'service'", ")", "self", ".", "renew", "=", "bool", "(", "request", ".", "POST",...
Initialize POST received parameters :param django.http.HttpRequest request: The current request object
[ "Initialize", "POST", "received", "parameters" ]
d106181b94c444f1946269da5c20f6c904840ad3
https://github.com/nitmir/django-cas-server/blob/d106181b94c444f1946269da5c20f6c904840ad3/cas_server/views.py#L442-L460
train
nitmir/django-cas-server
cas_server/views.py
LoginView.gen_lt
def gen_lt(self): """Generate a new LoginTicket and add it to the list of valid LT for the user""" self.request.session['lt'] = self.request.session.get('lt', []) + [utils.gen_lt()] if len(self.request.session['lt']) > 100: self.request.session['lt'] = self.request.session['lt'][-100...
python
def gen_lt(self): """Generate a new LoginTicket and add it to the list of valid LT for the user""" self.request.session['lt'] = self.request.session.get('lt', []) + [utils.gen_lt()] if len(self.request.session['lt']) > 100: self.request.session['lt'] = self.request.session['lt'][-100...
[ "def", "gen_lt", "(", "self", ")", ":", "self", ".", "request", ".", "session", "[", "'lt'", "]", "=", "self", ".", "request", ".", "session", ".", "get", "(", "'lt'", ",", "[", "]", ")", "+", "[", "utils", ".", "gen_lt", "(", ")", "]", "if", ...
Generate a new LoginTicket and add it to the list of valid LT for the user
[ "Generate", "a", "new", "LoginTicket", "and", "add", "it", "to", "the", "list", "of", "valid", "LT", "for", "the", "user" ]
d106181b94c444f1946269da5c20f6c904840ad3
https://github.com/nitmir/django-cas-server/blob/d106181b94c444f1946269da5c20f6c904840ad3/cas_server/views.py#L462-L466
train
nitmir/django-cas-server
cas_server/views.py
LoginView.check_lt
def check_lt(self): """ Check is the POSTed LoginTicket is valid, if yes invalide it :return: ``True`` if the LoginTicket is valid, ``False`` otherwise :rtype: bool """ # save LT for later check lt_valid = self.request.session.get('lt', []) lt...
python
def check_lt(self): """ Check is the POSTed LoginTicket is valid, if yes invalide it :return: ``True`` if the LoginTicket is valid, ``False`` otherwise :rtype: bool """ # save LT for later check lt_valid = self.request.session.get('lt', []) lt...
[ "def", "check_lt", "(", "self", ")", ":", "lt_valid", "=", "self", ".", "request", ".", "session", ".", "get", "(", "'lt'", ",", "[", "]", ")", "lt_send", "=", "self", ".", "request", ".", "POST", ".", "get", "(", "'lt'", ")", "self", ".", "gen_l...
Check is the POSTed LoginTicket is valid, if yes invalide it :return: ``True`` if the LoginTicket is valid, ``False`` otherwise :rtype: bool
[ "Check", "is", "the", "POSTed", "LoginTicket", "is", "valid", "if", "yes", "invalide", "it" ]
d106181b94c444f1946269da5c20f6c904840ad3
https://github.com/nitmir/django-cas-server/blob/d106181b94c444f1946269da5c20f6c904840ad3/cas_server/views.py#L468-L488
train
nitmir/django-cas-server
cas_server/views.py
LoginView.init_get
def init_get(self, request): """ Initialize GET received parameters :param django.http.HttpRequest request: The current request object """ self.request = request self.service = request.GET.get('service') self.renew = bool(request.GET.get('renew') and requ...
python
def init_get(self, request): """ Initialize GET received parameters :param django.http.HttpRequest request: The current request object """ self.request = request self.service = request.GET.get('service') self.renew = bool(request.GET.get('renew') and requ...
[ "def", "init_get", "(", "self", ",", "request", ")", ":", "self", ".", "request", "=", "request", "self", ".", "service", "=", "request", ".", "GET", ".", "get", "(", "'service'", ")", "self", ".", "renew", "=", "bool", "(", "request", ".", "GET", ...
Initialize GET received parameters :param django.http.HttpRequest request: The current request object
[ "Initialize", "GET", "received", "parameters" ]
d106181b94c444f1946269da5c20f6c904840ad3
https://github.com/nitmir/django-cas-server/blob/d106181b94c444f1946269da5c20f6c904840ad3/cas_server/views.py#L583-L604
train
nitmir/django-cas-server
cas_server/views.py
LoginView.process_get
def process_get(self): """ Analyse the GET request :return: * :attr:`USER_NOT_AUTHENTICATED` if the user is not authenticated or is requesting for authentication renewal * :attr:`USER_AUTHENTICATED` if the user is authenticated and is no...
python
def process_get(self): """ Analyse the GET request :return: * :attr:`USER_NOT_AUTHENTICATED` if the user is not authenticated or is requesting for authentication renewal * :attr:`USER_AUTHENTICATED` if the user is authenticated and is no...
[ "def", "process_get", "(", "self", ")", ":", "self", ".", "gen_lt", "(", ")", "if", "not", "self", ".", "request", ".", "session", ".", "get", "(", "\"authenticated\"", ")", "or", "self", ".", "renew", ":", "self", ".", "init_form", "(", ")", "return...
Analyse the GET request :return: * :attr:`USER_NOT_AUTHENTICATED` if the user is not authenticated or is requesting for authentication renewal * :attr:`USER_AUTHENTICATED` if the user is authenticated and is not requesting for authenticati...
[ "Analyse", "the", "GET", "request" ]
d106181b94c444f1946269da5c20f6c904840ad3
https://github.com/nitmir/django-cas-server/blob/d106181b94c444f1946269da5c20f6c904840ad3/cas_server/views.py#L619-L636
train
nitmir/django-cas-server
cas_server/views.py
LoginView.init_form
def init_form(self, values=None): """ Initialization of the good form depending of POST and GET parameters :param django.http.QueryDict values: A POST or GET QueryDict """ if values: values = values.copy() values['lt'] = self.request.session['lt']...
python
def init_form(self, values=None): """ Initialization of the good form depending of POST and GET parameters :param django.http.QueryDict values: A POST or GET QueryDict """ if values: values = values.copy() values['lt'] = self.request.session['lt']...
[ "def", "init_form", "(", "self", ",", "values", "=", "None", ")", ":", "if", "values", ":", "values", "=", "values", ".", "copy", "(", ")", "values", "[", "'lt'", "]", "=", "self", ".", "request", ".", "session", "[", "'lt'", "]", "[", "-", "1", ...
Initialization of the good form depending of POST and GET parameters :param django.http.QueryDict values: A POST or GET QueryDict
[ "Initialization", "of", "the", "good", "form", "depending", "of", "POST", "and", "GET", "parameters" ]
d106181b94c444f1946269da5c20f6c904840ad3
https://github.com/nitmir/django-cas-server/blob/d106181b94c444f1946269da5c20f6c904840ad3/cas_server/views.py#L638-L671
train
nitmir/django-cas-server
cas_server/views.py
LoginView.service_login
def service_login(self): """ Perform login against a service :return: * The rendering of the ``settings.CAS_WARN_TEMPLATE`` if the user asked to be warned before ticket emission and has not yep been warned. * The redirection to the servi...
python
def service_login(self): """ Perform login against a service :return: * The rendering of the ``settings.CAS_WARN_TEMPLATE`` if the user asked to be warned before ticket emission and has not yep been warned. * The redirection to the servi...
[ "def", "service_login", "(", "self", ")", ":", "try", ":", "service_pattern", "=", "ServicePattern", ".", "validate", "(", "self", ".", "service", ")", "service_pattern", ".", "check_user", "(", "self", ".", "user", ")", "if", "self", ".", "request", ".", ...
Perform login against a service :return: * The rendering of the ``settings.CAS_WARN_TEMPLATE`` if the user asked to be warned before ticket emission and has not yep been warned. * The redirection to the service URL with a ticket GET parameter ...
[ "Perform", "login", "against", "a", "service" ]
d106181b94c444f1946269da5c20f6c904840ad3
https://github.com/nitmir/django-cas-server/blob/d106181b94c444f1946269da5c20f6c904840ad3/cas_server/views.py#L673-L773
train
nitmir/django-cas-server
cas_server/views.py
LoginView.authenticated
def authenticated(self): """ Processing authenticated users :return: * The returned value of :meth:`service_login` if :attr:`service` is defined * The rendering of ``settings.CAS_LOGGED_TEMPLATE`` otherwise :rtype: django.http.HttpResponse ...
python
def authenticated(self): """ Processing authenticated users :return: * The returned value of :meth:`service_login` if :attr:`service` is defined * The rendering of ``settings.CAS_LOGGED_TEMPLATE`` otherwise :rtype: django.http.HttpResponse ...
[ "def", "authenticated", "(", "self", ")", ":", "try", ":", "self", ".", "user", "=", "models", ".", "User", ".", "objects", ".", "get", "(", "username", "=", "self", ".", "request", ".", "session", ".", "get", "(", "\"username\"", ")", ",", "session_...
Processing authenticated users :return: * The returned value of :meth:`service_login` if :attr:`service` is defined * The rendering of ``settings.CAS_LOGGED_TEMPLATE`` otherwise :rtype: django.http.HttpResponse
[ "Processing", "authenticated", "users" ]
d106181b94c444f1946269da5c20f6c904840ad3
https://github.com/nitmir/django-cas-server/blob/d106181b94c444f1946269da5c20f6c904840ad3/cas_server/views.py#L775-L822
train
nitmir/django-cas-server
cas_server/views.py
LoginView.not_authenticated
def not_authenticated(self): """ Processing non authenticated users :return: * The rendering of ``settings.CAS_LOGIN_TEMPLATE`` with various messages depending of GET/POST parameters * The redirection to :class:`FederateAuth` if ``settin...
python
def not_authenticated(self): """ Processing non authenticated users :return: * The rendering of ``settings.CAS_LOGIN_TEMPLATE`` with various messages depending of GET/POST parameters * The redirection to :class:`FederateAuth` if ``settin...
[ "def", "not_authenticated", "(", "self", ")", ":", "if", "self", ".", "service", ":", "try", ":", "service_pattern", "=", "ServicePattern", ".", "validate", "(", "self", ".", "service", ")", "if", "self", ".", "gateway", "and", "not", "self", ".", "ajax"...
Processing non authenticated users :return: * The rendering of ``settings.CAS_LOGIN_TEMPLATE`` with various messages depending of GET/POST parameters * The redirection to :class:`FederateAuth` if ``settings.CAS_FEDERATE`` is ``True`` and t...
[ "Processing", "non", "authenticated", "users" ]
d106181b94c444f1946269da5c20f6c904840ad3
https://github.com/nitmir/django-cas-server/blob/d106181b94c444f1946269da5c20f6c904840ad3/cas_server/views.py#L824-L930
train
nitmir/django-cas-server
cas_server/views.py
LoginView.common
def common(self): """ Common part execute uppon GET and POST request :return: * The returned value of :meth:`authenticated` if the user is authenticated and not requesting for authentication or if the authentication has just been renewed ...
python
def common(self): """ Common part execute uppon GET and POST request :return: * The returned value of :meth:`authenticated` if the user is authenticated and not requesting for authentication or if the authentication has just been renewed ...
[ "def", "common", "(", "self", ")", ":", "if", "self", ".", "request", ".", "session", ".", "get", "(", "\"authenticated\"", ")", "and", "(", "not", "self", ".", "renew", "or", "self", ".", "renewed", ")", ":", "return", "self", ".", "authenticated", ...
Common part execute uppon GET and POST request :return: * The returned value of :meth:`authenticated` if the user is authenticated and not requesting for authentication or if the authentication has just been renewed * The returned value of :meth:`not_authen...
[ "Common", "part", "execute", "uppon", "GET", "and", "POST", "request" ]
d106181b94c444f1946269da5c20f6c904840ad3
https://github.com/nitmir/django-cas-server/blob/d106181b94c444f1946269da5c20f6c904840ad3/cas_server/views.py#L932-L946
train
nitmir/django-cas-server
cas_server/views.py
ValidateService.process_ticket
def process_ticket(self): """ fetch the ticket against the database and check its validity :raises ValidateError: if the ticket is not found or not valid, potentially for that service :returns: A couple (ticket, proxies list) :rtype: :obj:`tuple` ...
python
def process_ticket(self): """ fetch the ticket against the database and check its validity :raises ValidateError: if the ticket is not found or not valid, potentially for that service :returns: A couple (ticket, proxies list) :rtype: :obj:`tuple` ...
[ "def", "process_ticket", "(", "self", ")", ":", "try", ":", "proxies", "=", "[", "]", "if", "self", ".", "allow_proxy_ticket", ":", "ticket", "=", "models", ".", "Ticket", ".", "get", "(", "self", ".", "ticket", ",", "self", ".", "renew", ")", "else"...
fetch the ticket against the database and check its validity :raises ValidateError: if the ticket is not found or not valid, potentially for that service :returns: A couple (ticket, proxies list) :rtype: :obj:`tuple`
[ "fetch", "the", "ticket", "against", "the", "database", "and", "check", "its", "validity" ]
d106181b94c444f1946269da5c20f6c904840ad3
https://github.com/nitmir/django-cas-server/blob/d106181b94c444f1946269da5c20f6c904840ad3/cas_server/views.py#L1191-L1217
train
nitmir/django-cas-server
cas_server/views.py
ValidateService.process_pgturl
def process_pgturl(self, params): """ Handle PGT request :param dict params: A template context dict :raises ValidateError: if pgtUrl is invalid or if TLS validation of the pgtUrl fails :return: The rendering of ``cas_server/serviceValidate.xml``, using ``params`...
python
def process_pgturl(self, params): """ Handle PGT request :param dict params: A template context dict :raises ValidateError: if pgtUrl is invalid or if TLS validation of the pgtUrl fails :return: The rendering of ``cas_server/serviceValidate.xml``, using ``params`...
[ "def", "process_pgturl", "(", "self", ",", "params", ")", ":", "try", ":", "pattern", "=", "ServicePattern", ".", "validate", "(", "self", ".", "pgt_url", ")", "if", "pattern", ".", "proxy_callback", ":", "proxyid", "=", "utils", ".", "gen_pgtiou", "(", ...
Handle PGT request :param dict params: A template context dict :raises ValidateError: if pgtUrl is invalid or if TLS validation of the pgtUrl fails :return: The rendering of ``cas_server/serviceValidate.xml``, using ``params`` :rtype: django.http.HttpResponse
[ "Handle", "PGT", "request" ]
d106181b94c444f1946269da5c20f6c904840ad3
https://github.com/nitmir/django-cas-server/blob/d106181b94c444f1946269da5c20f6c904840ad3/cas_server/views.py#L1219-L1282
train
nitmir/django-cas-server
cas_server/views.py
Proxy.process_proxy
def process_proxy(self): """ handle PT request :raises ValidateError: if the PGT is not found, or the target service not allowed or the user not allowed on the tardet service. :return: The rendering of ``cas_server/proxy.xml`` :rtype: django.http....
python
def process_proxy(self): """ handle PT request :raises ValidateError: if the PGT is not found, or the target service not allowed or the user not allowed on the tardet service. :return: The rendering of ``cas_server/proxy.xml`` :rtype: django.http....
[ "def", "process_proxy", "(", "self", ")", ":", "try", ":", "pattern", "=", "ServicePattern", ".", "validate", "(", "self", ".", "target_service", ")", "if", "not", "pattern", ".", "proxy", ":", "raise", "ValidateError", "(", "u'UNAUTHORIZED_SERVICE'", ",", "...
handle PT request :raises ValidateError: if the PGT is not found, or the target service not allowed or the user not allowed on the tardet service. :return: The rendering of ``cas_server/proxy.xml`` :rtype: django.http.HttpResponse
[ "handle", "PT", "request" ]
d106181b94c444f1946269da5c20f6c904840ad3
https://github.com/nitmir/django-cas-server/blob/d106181b94c444f1946269da5c20f6c904840ad3/cas_server/views.py#L1320-L1369
train
nitmir/django-cas-server
cas_server/views.py
SamlValidate.process_ticket
def process_ticket(self): """ validate ticket from SAML XML body :raises: SamlValidateError: if the ticket is not found or not valid, or if we fail to parse the posted XML. :return: a ticket object :rtype: :class:`models.Ticket<cas_server.models.T...
python
def process_ticket(self): """ validate ticket from SAML XML body :raises: SamlValidateError: if the ticket is not found or not valid, or if we fail to parse the posted XML. :return: a ticket object :rtype: :class:`models.Ticket<cas_server.models.T...
[ "def", "process_ticket", "(", "self", ")", ":", "try", ":", "auth_req", "=", "self", ".", "root", ".", "getchildren", "(", ")", "[", "1", "]", ".", "getchildren", "(", ")", "[", "0", "]", "ticket", "=", "auth_req", ".", "getchildren", "(", ")", "["...
validate ticket from SAML XML body :raises: SamlValidateError: if the ticket is not found or not valid, or if we fail to parse the posted XML. :return: a ticket object :rtype: :class:`models.Ticket<cas_server.models.Ticket>`
[ "validate", "ticket", "from", "SAML", "XML", "body" ]
d106181b94c444f1946269da5c20f6c904840ad3
https://github.com/nitmir/django-cas-server/blob/d106181b94c444f1946269da5c20f6c904840ad3/cas_server/views.py#L1446-L1473
train
pipermerriam/flex
flex/cli.py
main
def main(source): """ For a given command line supplied argument, negotiate the content, parse the schema and then return any issues to stdout or if no schema issues, return success exit code. """ if source is None: click.echo( "You need to supply a file or url to a schema to...
python
def main(source): """ For a given command line supplied argument, negotiate the content, parse the schema and then return any issues to stdout or if no schema issues, return success exit code. """ if source is None: click.echo( "You need to supply a file or url to a schema to...
[ "def", "main", "(", "source", ")", ":", "if", "source", "is", "None", ":", "click", ".", "echo", "(", "\"You need to supply a file or url to a schema to a swagger schema, for\"", "\"the validator to work.\"", ")", "return", "1", "try", ":", "load", "(", "source", ")...
For a given command line supplied argument, negotiate the content, parse the schema and then return any issues to stdout or if no schema issues, return success exit code.
[ "For", "a", "given", "command", "line", "supplied", "argument", "negotiate", "the", "content", "parse", "the", "schema", "and", "then", "return", "any", "issues", "to", "stdout", "or", "if", "no", "schema", "issues", "return", "success", "exit", "code", "." ...
233f8149fb851a6255753bcec948cb6fefb2723b
https://github.com/pipermerriam/flex/blob/233f8149fb851a6255753bcec948cb6fefb2723b/flex/cli.py#L12-L29
train
pipermerriam/flex
flex/core.py
load_source
def load_source(source): """ Common entry point for loading some form of raw swagger schema. Supports: - python object (dictionary-like) - path to yaml file - path to json file - file object (json or yaml). - json string. - yaml string. """ if isinsta...
python
def load_source(source): """ Common entry point for loading some form of raw swagger schema. Supports: - python object (dictionary-like) - path to yaml file - path to json file - file object (json or yaml). - json string. - yaml string. """ if isinsta...
[ "def", "load_source", "(", "source", ")", ":", "if", "isinstance", "(", "source", ",", "collections", ".", "Mapping", ")", ":", "return", "deepcopy", "(", "source", ")", "elif", "hasattr", "(", "source", ",", "'read'", ")", "and", "callable", "(", "sourc...
Common entry point for loading some form of raw swagger schema. Supports: - python object (dictionary-like) - path to yaml file - path to json file - file object (json or yaml). - json string. - yaml string.
[ "Common", "entry", "point", "for", "loading", "some", "form", "of", "raw", "swagger", "schema", "." ]
233f8149fb851a6255753bcec948cb6fefb2723b
https://github.com/pipermerriam/flex/blob/233f8149fb851a6255753bcec948cb6fefb2723b/flex/core.py#L33-L78
train
pipermerriam/flex
flex/core.py
validate
def validate(raw_schema, target=None, **kwargs): """ Given the python representation of a JSONschema as defined in the swagger spec, validate that the schema complies to spec. If `target` is provided, that target will be validated against the provided schema. """ schema = schema_validator(raw_s...
python
def validate(raw_schema, target=None, **kwargs): """ Given the python representation of a JSONschema as defined in the swagger spec, validate that the schema complies to spec. If `target` is provided, that target will be validated against the provided schema. """ schema = schema_validator(raw_s...
[ "def", "validate", "(", "raw_schema", ",", "target", "=", "None", ",", "**", "kwargs", ")", ":", "schema", "=", "schema_validator", "(", "raw_schema", ",", "**", "kwargs", ")", "if", "target", "is", "not", "None", ":", "validate_object", "(", "target", "...
Given the python representation of a JSONschema as defined in the swagger spec, validate that the schema complies to spec. If `target` is provided, that target will be validated against the provided schema.
[ "Given", "the", "python", "representation", "of", "a", "JSONschema", "as", "defined", "in", "the", "swagger", "spec", "validate", "that", "the", "schema", "complies", "to", "spec", ".", "If", "target", "is", "provided", "that", "target", "will", "be", "valid...
233f8149fb851a6255753bcec948cb6fefb2723b
https://github.com/pipermerriam/flex/blob/233f8149fb851a6255753bcec948cb6fefb2723b/flex/core.py#L103-L111
train
pipermerriam/flex
flex/core.py
validate_api_response
def validate_api_response(schema, raw_response, request_method='get', raw_request=None): """ Validate the response of an api call against a swagger schema. """ request = None if raw_request is not None: request = normalize_request(raw_request) response = None if raw_response is not ...
python
def validate_api_response(schema, raw_response, request_method='get', raw_request=None): """ Validate the response of an api call against a swagger schema. """ request = None if raw_request is not None: request = normalize_request(raw_request) response = None if raw_response is not ...
[ "def", "validate_api_response", "(", "schema", ",", "raw_response", ",", "request_method", "=", "'get'", ",", "raw_request", "=", "None", ")", ":", "request", "=", "None", "if", "raw_request", "is", "not", "None", ":", "request", "=", "normalize_request", "(",...
Validate the response of an api call against a swagger schema.
[ "Validate", "the", "response", "of", "an", "api", "call", "against", "a", "swagger", "schema", "." ]
233f8149fb851a6255753bcec948cb6fefb2723b
https://github.com/pipermerriam/flex/blob/233f8149fb851a6255753bcec948cb6fefb2723b/flex/core.py#L121-L138
train
pipermerriam/flex
flex/parameters.py
find_parameter
def find_parameter(parameters, **kwargs): """ Given a list of parameters, find the one with the given name. """ matching_parameters = filter_parameters(parameters, **kwargs) if len(matching_parameters) == 1: return matching_parameters[0] elif len(matching_parameters) > 1: raise M...
python
def find_parameter(parameters, **kwargs): """ Given a list of parameters, find the one with the given name. """ matching_parameters = filter_parameters(parameters, **kwargs) if len(matching_parameters) == 1: return matching_parameters[0] elif len(matching_parameters) > 1: raise M...
[ "def", "find_parameter", "(", "parameters", ",", "**", "kwargs", ")", ":", "matching_parameters", "=", "filter_parameters", "(", "parameters", ",", "**", "kwargs", ")", "if", "len", "(", "matching_parameters", ")", "==", "1", ":", "return", "matching_parameters"...
Given a list of parameters, find the one with the given name.
[ "Given", "a", "list", "of", "parameters", "find", "the", "one", "with", "the", "given", "name", "." ]
233f8149fb851a6255753bcec948cb6fefb2723b
https://github.com/pipermerriam/flex/blob/233f8149fb851a6255753bcec948cb6fefb2723b/flex/parameters.py#L25-L34
train
pipermerriam/flex
flex/parameters.py
merge_parameter_lists
def merge_parameter_lists(*parameter_definitions): """ Merge multiple lists of parameters into a single list. If there are any duplicate definitions, the last write wins. """ merged_parameters = {} for parameter_list in parameter_definitions: for parameter in parameter_list: ...
python
def merge_parameter_lists(*parameter_definitions): """ Merge multiple lists of parameters into a single list. If there are any duplicate definitions, the last write wins. """ merged_parameters = {} for parameter_list in parameter_definitions: for parameter in parameter_list: ...
[ "def", "merge_parameter_lists", "(", "*", "parameter_definitions", ")", ":", "merged_parameters", "=", "{", "}", "for", "parameter_list", "in", "parameter_definitions", ":", "for", "parameter", "in", "parameter_list", ":", "key", "=", "(", "parameter", "[", "'name...
Merge multiple lists of parameters into a single list. If there are any duplicate definitions, the last write wins.
[ "Merge", "multiple", "lists", "of", "parameters", "into", "a", "single", "list", ".", "If", "there", "are", "any", "duplicate", "definitions", "the", "last", "write", "wins", "." ]
233f8149fb851a6255753bcec948cb6fefb2723b
https://github.com/pipermerriam/flex/blob/233f8149fb851a6255753bcec948cb6fefb2723b/flex/parameters.py#L37-L47
train
pipermerriam/flex
flex/validation/response.py
validate_status_code_to_response_definition
def validate_status_code_to_response_definition(response, operation_definition): """ Given a response, validate that the response status code is in the accepted status codes defined by this endpoint. If so, return the response definition that corresponds to the status code. """ status_code = re...
python
def validate_status_code_to_response_definition(response, operation_definition): """ Given a response, validate that the response status code is in the accepted status codes defined by this endpoint. If so, return the response definition that corresponds to the status code. """ status_code = re...
[ "def", "validate_status_code_to_response_definition", "(", "response", ",", "operation_definition", ")", ":", "status_code", "=", "response", ".", "status_code", "operation_responses", "=", "{", "str", "(", "code", ")", ":", "val", "for", "code", ",", "val", "in",...
Given a response, validate that the response status code is in the accepted status codes defined by this endpoint. If so, return the response definition that corresponds to the status code.
[ "Given", "a", "response", "validate", "that", "the", "response", "status", "code", "is", "in", "the", "accepted", "status", "codes", "defined", "by", "this", "endpoint", "." ]
233f8149fb851a6255753bcec948cb6fefb2723b
https://github.com/pipermerriam/flex/blob/233f8149fb851a6255753bcec948cb6fefb2723b/flex/validation/response.py#L37-L60
train
pipermerriam/flex
flex/validation/response.py
generate_path_validator
def generate_path_validator(api_path, path_definition, parameters, context, **kwargs): """ Generates a callable for validating the parameters in a response object. """ path_level_parameters = dereference_parameter_list( path_definition.get('parameters', []), c...
python
def generate_path_validator(api_path, path_definition, parameters, context, **kwargs): """ Generates a callable for validating the parameters in a response object. """ path_level_parameters = dereference_parameter_list( path_definition.get('parameters', []), c...
[ "def", "generate_path_validator", "(", "api_path", ",", "path_definition", ",", "parameters", ",", "context", ",", "**", "kwargs", ")", ":", "path_level_parameters", "=", "dereference_parameter_list", "(", "path_definition", ".", "get", "(", "'parameters'", ",", "["...
Generates a callable for validating the parameters in a response object.
[ "Generates", "a", "callable", "for", "validating", "the", "parameters", "in", "a", "response", "object", "." ]
233f8149fb851a6255753bcec948cb6fefb2723b
https://github.com/pipermerriam/flex/blob/233f8149fb851a6255753bcec948cb6fefb2723b/flex/validation/response.py#L115-L139
train
pipermerriam/flex
flex/validation/response.py
validate_response
def validate_response(response, request_method, schema): """ Response validation involves the following steps. 4. validate that the response status_code is in the allowed responses for the request method. 5. validate that the response content validates against any provided sche...
python
def validate_response(response, request_method, schema): """ Response validation involves the following steps. 4. validate that the response status_code is in the allowed responses for the request method. 5. validate that the response content validates against any provided sche...
[ "def", "validate_response", "(", "response", ",", "request_method", ",", "schema", ")", ":", "with", "ErrorDict", "(", ")", "as", "errors", ":", "try", ":", "api_path", "=", "validate_path_to_api_path", "(", "path", "=", "response", ".", "path", ",", "contex...
Response validation involves the following steps. 4. validate that the response status_code is in the allowed responses for the request method. 5. validate that the response content validates against any provided schemas for the responses. 6. headers, content-types, etc..., ???
[ "Response", "validation", "involves", "the", "following", "steps", ".", "4", ".", "validate", "that", "the", "response", "status_code", "is", "in", "the", "allowed", "responses", "for", "the", "request", "method", ".", "5", ".", "validate", "that", "the", "r...
233f8149fb851a6255753bcec948cb6fefb2723b
https://github.com/pipermerriam/flex/blob/233f8149fb851a6255753bcec948cb6fefb2723b/flex/validation/response.py#L194-L248
train
pipermerriam/flex
flex/validation/schema.py
construct_schema_validators
def construct_schema_validators(schema, context): """ Given a schema object, construct a dictionary of validators needed to validate a response matching the given schema. Special Cases: - $ref: These validators need to be Lazily evaluating so that circular validation dep...
python
def construct_schema_validators(schema, context): """ Given a schema object, construct a dictionary of validators needed to validate a response matching the given schema. Special Cases: - $ref: These validators need to be Lazily evaluating so that circular validation dep...
[ "def", "construct_schema_validators", "(", "schema", ",", "context", ")", ":", "validators", "=", "ValidationDict", "(", ")", "if", "'$ref'", "in", "schema", ":", "validators", ".", "add_validator", "(", "'$ref'", ",", "SchemaReferenceValidator", "(", "schema", ...
Given a schema object, construct a dictionary of validators needed to validate a response matching the given schema. Special Cases: - $ref: These validators need to be Lazily evaluating so that circular validation dependencies do not result in an infinitely deep vali...
[ "Given", "a", "schema", "object", "construct", "a", "dictionary", "of", "validators", "needed", "to", "validate", "a", "response", "matching", "the", "given", "schema", "." ]
233f8149fb851a6255753bcec948cb6fefb2723b
https://github.com/pipermerriam/flex/blob/233f8149fb851a6255753bcec948cb6fefb2723b/flex/validation/schema.py#L199-L236
train
pipermerriam/flex
flex/validation/common.py
validate_type
def validate_type(value, types, **kwargs): """ Validate that the value is one of the provided primative types. """ if not is_value_of_any_type(value, types): raise ValidationError(MESSAGES['type']['invalid'].format( repr(value), get_type_for_value(value), types, ))
python
def validate_type(value, types, **kwargs): """ Validate that the value is one of the provided primative types. """ if not is_value_of_any_type(value, types): raise ValidationError(MESSAGES['type']['invalid'].format( repr(value), get_type_for_value(value), types, ))
[ "def", "validate_type", "(", "value", ",", "types", ",", "**", "kwargs", ")", ":", "if", "not", "is_value_of_any_type", "(", "value", ",", "types", ")", ":", "raise", "ValidationError", "(", "MESSAGES", "[", "'type'", "]", "[", "'invalid'", "]", ".", "fo...
Validate that the value is one of the provided primative types.
[ "Validate", "that", "the", "value", "is", "one", "of", "the", "provided", "primative", "types", "." ]
233f8149fb851a6255753bcec948cb6fefb2723b
https://github.com/pipermerriam/flex/blob/233f8149fb851a6255753bcec948cb6fefb2723b/flex/validation/common.py#L56-L63
train
pipermerriam/flex
flex/validation/common.py
generate_type_validator
def generate_type_validator(type_, **kwargs): """ Generates a callable validator for the given type or iterable of types. """ if is_non_string_iterable(type_): types = tuple(type_) else: types = (type_,) # support x-nullable since Swagger 2.0 doesn't support null type # (see ...
python
def generate_type_validator(type_, **kwargs): """ Generates a callable validator for the given type or iterable of types. """ if is_non_string_iterable(type_): types = tuple(type_) else: types = (type_,) # support x-nullable since Swagger 2.0 doesn't support null type # (see ...
[ "def", "generate_type_validator", "(", "type_", ",", "**", "kwargs", ")", ":", "if", "is_non_string_iterable", "(", "type_", ")", ":", "types", "=", "tuple", "(", "type_", ")", "else", ":", "types", "=", "(", "type_", ",", ")", "if", "kwargs", ".", "ge...
Generates a callable validator for the given type or iterable of types.
[ "Generates", "a", "callable", "validator", "for", "the", "given", "type", "or", "iterable", "of", "types", "." ]
233f8149fb851a6255753bcec948cb6fefb2723b
https://github.com/pipermerriam/flex/blob/233f8149fb851a6255753bcec948cb6fefb2723b/flex/validation/common.py#L67-L79
train
pipermerriam/flex
flex/validation/common.py
validate_multiple_of
def validate_multiple_of(value, divisor, **kwargs): """ Given a value and a divisor, validate that the value is divisible by the divisor. """ if not decimal.Decimal(str(value)) % decimal.Decimal(str(divisor)) == 0: raise ValidationError( MESSAGES['multiple_of']['invalid'].format(...
python
def validate_multiple_of(value, divisor, **kwargs): """ Given a value and a divisor, validate that the value is divisible by the divisor. """ if not decimal.Decimal(str(value)) % decimal.Decimal(str(divisor)) == 0: raise ValidationError( MESSAGES['multiple_of']['invalid'].format(...
[ "def", "validate_multiple_of", "(", "value", ",", "divisor", ",", "**", "kwargs", ")", ":", "if", "not", "decimal", ".", "Decimal", "(", "str", "(", "value", ")", ")", "%", "decimal", ".", "Decimal", "(", "str", "(", "divisor", ")", ")", "==", "0", ...
Given a value and a divisor, validate that the value is divisible by the divisor.
[ "Given", "a", "value", "and", "a", "divisor", "validate", "that", "the", "value", "is", "divisible", "by", "the", "divisor", "." ]
233f8149fb851a6255753bcec948cb6fefb2723b
https://github.com/pipermerriam/flex/blob/233f8149fb851a6255753bcec948cb6fefb2723b/flex/validation/common.py#L103-L111
train
pipermerriam/flex
flex/validation/common.py
validate_minimum
def validate_minimum(value, minimum, is_exclusive, **kwargs): """ Validator function for validating that a value does not violate it's minimum allowed value. This validation can be inclusive, or exclusive of the minimum depending on the value of `is_exclusive`. """ if is_exclusive: comp...
python
def validate_minimum(value, minimum, is_exclusive, **kwargs): """ Validator function for validating that a value does not violate it's minimum allowed value. This validation can be inclusive, or exclusive of the minimum depending on the value of `is_exclusive`. """ if is_exclusive: comp...
[ "def", "validate_minimum", "(", "value", ",", "minimum", ",", "is_exclusive", ",", "**", "kwargs", ")", ":", "if", "is_exclusive", ":", "comparison_text", "=", "\"greater than\"", "compare_fn", "=", "operator", ".", "gt", "else", ":", "comparison_text", "=", "...
Validator function for validating that a value does not violate it's minimum allowed value. This validation can be inclusive, or exclusive of the minimum depending on the value of `is_exclusive`.
[ "Validator", "function", "for", "validating", "that", "a", "value", "does", "not", "violate", "it", "s", "minimum", "allowed", "value", ".", "This", "validation", "can", "be", "inclusive", "or", "exclusive", "of", "the", "minimum", "depending", "on", "the", ...
233f8149fb851a6255753bcec948cb6fefb2723b
https://github.com/pipermerriam/flex/blob/233f8149fb851a6255753bcec948cb6fefb2723b/flex/validation/common.py#L120-L136
train
pipermerriam/flex
flex/validation/common.py
generate_minimum_validator
def generate_minimum_validator(minimum, exclusiveMinimum=False, **kwargs): """ Generator function returning a callable for minimum value validation. """ return functools.partial(validate_minimum, minimum=minimum, is_exclusive=exclusiveMinimum)
python
def generate_minimum_validator(minimum, exclusiveMinimum=False, **kwargs): """ Generator function returning a callable for minimum value validation. """ return functools.partial(validate_minimum, minimum=minimum, is_exclusive=exclusiveMinimum)
[ "def", "generate_minimum_validator", "(", "minimum", ",", "exclusiveMinimum", "=", "False", ",", "**", "kwargs", ")", ":", "return", "functools", ".", "partial", "(", "validate_minimum", ",", "minimum", "=", "minimum", ",", "is_exclusive", "=", "exclusiveMinimum",...
Generator function returning a callable for minimum value validation.
[ "Generator", "function", "returning", "a", "callable", "for", "minimum", "value", "validation", "." ]
233f8149fb851a6255753bcec948cb6fefb2723b
https://github.com/pipermerriam/flex/blob/233f8149fb851a6255753bcec948cb6fefb2723b/flex/validation/common.py#L139-L143
train
pipermerriam/flex
flex/validation/common.py
validate_maximum
def validate_maximum(value, maximum, is_exclusive, **kwargs): """ Validator function for validating that a value does not violate it's maximum allowed value. This validation can be inclusive, or exclusive of the maximum depending on the value of `is_exclusive`. """ if is_exclusive: comp...
python
def validate_maximum(value, maximum, is_exclusive, **kwargs): """ Validator function for validating that a value does not violate it's maximum allowed value. This validation can be inclusive, or exclusive of the maximum depending on the value of `is_exclusive`. """ if is_exclusive: comp...
[ "def", "validate_maximum", "(", "value", ",", "maximum", ",", "is_exclusive", ",", "**", "kwargs", ")", ":", "if", "is_exclusive", ":", "comparison_text", "=", "\"less than\"", "compare_fn", "=", "operator", ".", "lt", "else", ":", "comparison_text", "=", "\"l...
Validator function for validating that a value does not violate it's maximum allowed value. This validation can be inclusive, or exclusive of the maximum depending on the value of `is_exclusive`.
[ "Validator", "function", "for", "validating", "that", "a", "value", "does", "not", "violate", "it", "s", "maximum", "allowed", "value", ".", "This", "validation", "can", "be", "inclusive", "or", "exclusive", "of", "the", "maximum", "depending", "on", "the", ...
233f8149fb851a6255753bcec948cb6fefb2723b
https://github.com/pipermerriam/flex/blob/233f8149fb851a6255753bcec948cb6fefb2723b/flex/validation/common.py#L148-L164
train
pipermerriam/flex
flex/validation/common.py
generate_maximum_validator
def generate_maximum_validator(maximum, exclusiveMaximum=False, **kwargs): """ Generator function returning a callable for maximum value validation. """ return functools.partial(validate_maximum, maximum=maximum, is_exclusive=exclusiveMaximum)
python
def generate_maximum_validator(maximum, exclusiveMaximum=False, **kwargs): """ Generator function returning a callable for maximum value validation. """ return functools.partial(validate_maximum, maximum=maximum, is_exclusive=exclusiveMaximum)
[ "def", "generate_maximum_validator", "(", "maximum", ",", "exclusiveMaximum", "=", "False", ",", "**", "kwargs", ")", ":", "return", "functools", ".", "partial", "(", "validate_maximum", ",", "maximum", "=", "maximum", ",", "is_exclusive", "=", "exclusiveMaximum",...
Generator function returning a callable for maximum value validation.
[ "Generator", "function", "returning", "a", "callable", "for", "maximum", "value", "validation", "." ]
233f8149fb851a6255753bcec948cb6fefb2723b
https://github.com/pipermerriam/flex/blob/233f8149fb851a6255753bcec948cb6fefb2723b/flex/validation/common.py#L167-L171
train
pipermerriam/flex
flex/validation/common.py
validate_min_items
def validate_min_items(value, minimum, **kwargs): """ Validator for ARRAY types to enforce a minimum number of items allowed for the ARRAY to be valid. """ if len(value) < minimum: raise ValidationError( MESSAGES['min_items']['invalid'].format( minimum, len(value)...
python
def validate_min_items(value, minimum, **kwargs): """ Validator for ARRAY types to enforce a minimum number of items allowed for the ARRAY to be valid. """ if len(value) < minimum: raise ValidationError( MESSAGES['min_items']['invalid'].format( minimum, len(value)...
[ "def", "validate_min_items", "(", "value", ",", "minimum", ",", "**", "kwargs", ")", ":", "if", "len", "(", "value", ")", "<", "minimum", ":", "raise", "ValidationError", "(", "MESSAGES", "[", "'min_items'", "]", "[", "'invalid'", "]", ".", "format", "("...
Validator for ARRAY types to enforce a minimum number of items allowed for the ARRAY to be valid.
[ "Validator", "for", "ARRAY", "types", "to", "enforce", "a", "minimum", "number", "of", "items", "allowed", "for", "the", "ARRAY", "to", "be", "valid", "." ]
233f8149fb851a6255753bcec948cb6fefb2723b
https://github.com/pipermerriam/flex/blob/233f8149fb851a6255753bcec948cb6fefb2723b/flex/validation/common.py#L204-L214
train
pipermerriam/flex
flex/validation/common.py
validate_max_items
def validate_max_items(value, maximum, **kwargs): """ Validator for ARRAY types to enforce a maximum number of items allowed for the ARRAY to be valid. """ if len(value) > maximum: raise ValidationError( MESSAGES['max_items']['invalid'].format( maximum, len(value)...
python
def validate_max_items(value, maximum, **kwargs): """ Validator for ARRAY types to enforce a maximum number of items allowed for the ARRAY to be valid. """ if len(value) > maximum: raise ValidationError( MESSAGES['max_items']['invalid'].format( maximum, len(value)...
[ "def", "validate_max_items", "(", "value", ",", "maximum", ",", "**", "kwargs", ")", ":", "if", "len", "(", "value", ")", ">", "maximum", ":", "raise", "ValidationError", "(", "MESSAGES", "[", "'max_items'", "]", "[", "'invalid'", "]", ".", "format", "("...
Validator for ARRAY types to enforce a maximum number of items allowed for the ARRAY to be valid.
[ "Validator", "for", "ARRAY", "types", "to", "enforce", "a", "maximum", "number", "of", "items", "allowed", "for", "the", "ARRAY", "to", "be", "valid", "." ]
233f8149fb851a6255753bcec948cb6fefb2723b
https://github.com/pipermerriam/flex/blob/233f8149fb851a6255753bcec948cb6fefb2723b/flex/validation/common.py#L226-L236
train
pipermerriam/flex
flex/validation/common.py
validate_unique_items
def validate_unique_items(value, **kwargs): """ Validator for ARRAY types to enforce that all array items must be unique. """ # we can't just look at the items themselves since 0 and False are treated # the same as dictionary keys, and objects aren't hashable. counter = collections.Counter(( ...
python
def validate_unique_items(value, **kwargs): """ Validator for ARRAY types to enforce that all array items must be unique. """ # we can't just look at the items themselves since 0 and False are treated # the same as dictionary keys, and objects aren't hashable. counter = collections.Counter(( ...
[ "def", "validate_unique_items", "(", "value", ",", "**", "kwargs", ")", ":", "counter", "=", "collections", ".", "Counter", "(", "(", "json", ".", "dumps", "(", "v", ",", "sort_keys", "=", "True", ")", "for", "v", "in", "value", ")", ")", "dupes", "=...
Validator for ARRAY types to enforce that all array items must be unique.
[ "Validator", "for", "ARRAY", "types", "to", "enforce", "that", "all", "array", "items", "must", "be", "unique", "." ]
233f8149fb851a6255753bcec948cb6fefb2723b
https://github.com/pipermerriam/flex/blob/233f8149fb851a6255753bcec948cb6fefb2723b/flex/validation/common.py#L248-L264
train
pipermerriam/flex
flex/validation/common.py
validate_object
def validate_object(obj, field_validators=None, non_field_validators=None, schema=None, context=None): """ Takes a mapping and applies a mapping of validator functions to it collecting and reraising any validation errors that occur. """ if schema is None: schema = {} ...
python
def validate_object(obj, field_validators=None, non_field_validators=None, schema=None, context=None): """ Takes a mapping and applies a mapping of validator functions to it collecting and reraising any validation errors that occur. """ if schema is None: schema = {} ...
[ "def", "validate_object", "(", "obj", ",", "field_validators", "=", "None", ",", "non_field_validators", "=", "None", ",", "schema", "=", "None", ",", "context", "=", "None", ")", ":", "if", "schema", "is", "None", ":", "schema", "=", "{", "}", "if", "...
Takes a mapping and applies a mapping of validator functions to it collecting and reraising any validation errors that occur.
[ "Takes", "a", "mapping", "and", "applies", "a", "mapping", "of", "validator", "functions", "to", "it", "collecting", "and", "reraising", "any", "validation", "errors", "that", "occur", "." ]
233f8149fb851a6255753bcec948cb6fefb2723b
https://github.com/pipermerriam/flex/blob/233f8149fb851a6255753bcec948cb6fefb2723b/flex/validation/common.py#L365-L398
train
pipermerriam/flex
flex/validation/common.py
validate_request_method_to_operation
def validate_request_method_to_operation(request_method, path_definition): """ Given a request method, validate that the request method is valid for the api path. If so, return the operation definition related to this request method. """ try: operation_definition = path_definition[reque...
python
def validate_request_method_to_operation(request_method, path_definition): """ Given a request method, validate that the request method is valid for the api path. If so, return the operation definition related to this request method. """ try: operation_definition = path_definition[reque...
[ "def", "validate_request_method_to_operation", "(", "request_method", ",", "path_definition", ")", ":", "try", ":", "operation_definition", "=", "path_definition", "[", "request_method", "]", "except", "KeyError", ":", "allowed_methods", "=", "set", "(", "REQUEST_METHOD...
Given a request method, validate that the request method is valid for the api path. If so, return the operation definition related to this request method.
[ "Given", "a", "request", "method", "validate", "that", "the", "request", "method", "is", "valid", "for", "the", "api", "path", "." ]
233f8149fb851a6255753bcec948cb6fefb2723b
https://github.com/pipermerriam/flex/blob/233f8149fb851a6255753bcec948cb6fefb2723b/flex/validation/common.py#L498-L514
train
pipermerriam/flex
flex/validation/common.py
validate_path_to_api_path
def validate_path_to_api_path(path, paths, basePath='', context=None, **kwargs): """ Given a path, find the api_path it matches. """ if context is None: context = {} try: api_path = match_path_to_api_path( path_definitions=paths, target_path=path, ...
python
def validate_path_to_api_path(path, paths, basePath='', context=None, **kwargs): """ Given a path, find the api_path it matches. """ if context is None: context = {} try: api_path = match_path_to_api_path( path_definitions=paths, target_path=path, ...
[ "def", "validate_path_to_api_path", "(", "path", ",", "paths", ",", "basePath", "=", "''", ",", "context", "=", "None", ",", "**", "kwargs", ")", ":", "if", "context", "is", "None", ":", "context", "=", "{", "}", "try", ":", "api_path", "=", "match_pat...
Given a path, find the api_path it matches.
[ "Given", "a", "path", "find", "the", "api_path", "it", "matches", "." ]
233f8149fb851a6255753bcec948cb6fefb2723b
https://github.com/pipermerriam/flex/blob/233f8149fb851a6255753bcec948cb6fefb2723b/flex/validation/common.py#L517-L535
train
pipermerriam/flex
flex/validation/parameter.py
validate_path_parameters
def validate_path_parameters(target_path, api_path, path_parameters, context): """ Helper function for validating a request path """ base_path = context.get('basePath', '') full_api_path = re.sub(NORMALIZE_SLASH_REGEX, '/', base_path + api_path) parameter_values = get_path_parameter_values( ...
python
def validate_path_parameters(target_path, api_path, path_parameters, context): """ Helper function for validating a request path """ base_path = context.get('basePath', '') full_api_path = re.sub(NORMALIZE_SLASH_REGEX, '/', base_path + api_path) parameter_values = get_path_parameter_values( ...
[ "def", "validate_path_parameters", "(", "target_path", ",", "api_path", ",", "path_parameters", ",", "context", ")", ":", "base_path", "=", "context", ".", "get", "(", "'basePath'", ",", "''", ")", "full_api_path", "=", "re", ".", "sub", "(", "NORMALIZE_SLASH_...
Helper function for validating a request path
[ "Helper", "function", "for", "validating", "a", "request", "path" ]
233f8149fb851a6255753bcec948cb6fefb2723b
https://github.com/pipermerriam/flex/blob/233f8149fb851a6255753bcec948cb6fefb2723b/flex/validation/parameter.py#L75-L84
train
pipermerriam/flex
flex/validation/parameter.py
construct_parameter_validators
def construct_parameter_validators(parameter, context): """ Constructs a dictionary of validator functions for the provided parameter definition. """ validators = ValidationDict() if '$ref' in parameter: validators.add_validator( '$ref', ParameterReferenceValidator(parameter[...
python
def construct_parameter_validators(parameter, context): """ Constructs a dictionary of validator functions for the provided parameter definition. """ validators = ValidationDict() if '$ref' in parameter: validators.add_validator( '$ref', ParameterReferenceValidator(parameter[...
[ "def", "construct_parameter_validators", "(", "parameter", ",", "context", ")", ":", "validators", "=", "ValidationDict", "(", ")", "if", "'$ref'", "in", "parameter", ":", "validators", ".", "add_validator", "(", "'$ref'", ",", "ParameterReferenceValidator", "(", ...
Constructs a dictionary of validator functions for the provided parameter definition.
[ "Constructs", "a", "dictionary", "of", "validator", "functions", "for", "the", "provided", "parameter", "definition", "." ]
233f8149fb851a6255753bcec948cb6fefb2723b
https://github.com/pipermerriam/flex/blob/233f8149fb851a6255753bcec948cb6fefb2723b/flex/validation/parameter.py#L109-L129
train
pipermerriam/flex
flex/validation/parameter.py
construct_multi_parameter_validators
def construct_multi_parameter_validators(parameters, context): """ Given an iterable of parameters, returns a dictionary of validator functions for each parameter. Note that this expects the parameters to be unique in their name value, and throws an error if this is not the case. """ validators...
python
def construct_multi_parameter_validators(parameters, context): """ Given an iterable of parameters, returns a dictionary of validator functions for each parameter. Note that this expects the parameters to be unique in their name value, and throws an error if this is not the case. """ validators...
[ "def", "construct_multi_parameter_validators", "(", "parameters", ",", "context", ")", ":", "validators", "=", "ValidationDict", "(", ")", "for", "parameter", "in", "parameters", ":", "key", "=", "parameter", "[", "'name'", "]", "if", "key", "in", "validators", ...
Given an iterable of parameters, returns a dictionary of validator functions for each parameter. Note that this expects the parameters to be unique in their name value, and throws an error if this is not the case.
[ "Given", "an", "iterable", "of", "parameters", "returns", "a", "dictionary", "of", "validator", "functions", "for", "each", "parameter", ".", "Note", "that", "this", "expects", "the", "parameters", "to", "be", "unique", "in", "their", "name", "value", "and", ...
233f8149fb851a6255753bcec948cb6fefb2723b
https://github.com/pipermerriam/flex/blob/233f8149fb851a6255753bcec948cb6fefb2723b/flex/validation/parameter.py#L150-L167
train
pipermerriam/flex
flex/validation/path.py
generate_path_parameters_validator
def generate_path_parameters_validator(api_path, path_parameters, context): """ Generates a validator function that given a path, validates that it against the path parameters """ path_parameter_validator = functools.partial( validate_path_parameters, api_path=api_path, path_...
python
def generate_path_parameters_validator(api_path, path_parameters, context): """ Generates a validator function that given a path, validates that it against the path parameters """ path_parameter_validator = functools.partial( validate_path_parameters, api_path=api_path, path_...
[ "def", "generate_path_parameters_validator", "(", "api_path", ",", "path_parameters", ",", "context", ")", ":", "path_parameter_validator", "=", "functools", ".", "partial", "(", "validate_path_parameters", ",", "api_path", "=", "api_path", ",", "path_parameters", "=", ...
Generates a validator function that given a path, validates that it against the path parameters
[ "Generates", "a", "validator", "function", "that", "given", "a", "path", "validates", "that", "it", "against", "the", "path", "parameters" ]
233f8149fb851a6255753bcec948cb6fefb2723b
https://github.com/pipermerriam/flex/blob/233f8149fb851a6255753bcec948cb6fefb2723b/flex/validation/path.py#L8-L19
train
pipermerriam/flex
flex/paths.py
escape_regex_special_chars
def escape_regex_special_chars(api_path): """ Turns the non prametrized path components into strings subtable for using as a regex pattern. This primarily involves escaping special characters so that the actual character is matched in the regex. """ def substitute(string, replacements): ...
python
def escape_regex_special_chars(api_path): """ Turns the non prametrized path components into strings subtable for using as a regex pattern. This primarily involves escaping special characters so that the actual character is matched in the regex. """ def substitute(string, replacements): ...
[ "def", "escape_regex_special_chars", "(", "api_path", ")", ":", "def", "substitute", "(", "string", ",", "replacements", ")", ":", "pattern", ",", "repl", "=", "replacements", "return", "re", ".", "sub", "(", "pattern", ",", "repl", ",", "string", ")", "re...
Turns the non prametrized path components into strings subtable for using as a regex pattern. This primarily involves escaping special characters so that the actual character is matched in the regex.
[ "Turns", "the", "non", "prametrized", "path", "components", "into", "strings", "subtable", "for", "using", "as", "a", "regex", "pattern", ".", "This", "primarily", "involves", "escaping", "special", "characters", "so", "that", "the", "actual", "character", "is",...
233f8149fb851a6255753bcec948cb6fefb2723b
https://github.com/pipermerriam/flex/blob/233f8149fb851a6255753bcec948cb6fefb2723b/flex/paths.py#L26-L36
train
pipermerriam/flex
flex/paths.py
construct_parameter_pattern
def construct_parameter_pattern(parameter): """ Given a parameter definition returns a regex pattern that will match that part of the path. """ name = parameter['name'] type = parameter['type'] repeated = '[^/]' if type == 'integer': repeated = '\d' return "(?P<{name}>{rep...
python
def construct_parameter_pattern(parameter): """ Given a parameter definition returns a regex pattern that will match that part of the path. """ name = parameter['name'] type = parameter['type'] repeated = '[^/]' if type == 'integer': repeated = '\d' return "(?P<{name}>{rep...
[ "def", "construct_parameter_pattern", "(", "parameter", ")", ":", "name", "=", "parameter", "[", "'name'", "]", "type", "=", "parameter", "[", "'type'", "]", "repeated", "=", "'[^/]'", "if", "type", "==", "'integer'", ":", "repeated", "=", "'\\d'", "return",...
Given a parameter definition returns a regex pattern that will match that part of the path.
[ "Given", "a", "parameter", "definition", "returns", "a", "regex", "pattern", "that", "will", "match", "that", "part", "of", "the", "path", "." ]
233f8149fb851a6255753bcec948cb6fefb2723b
https://github.com/pipermerriam/flex/blob/233f8149fb851a6255753bcec948cb6fefb2723b/flex/paths.py#L44-L57
train
pipermerriam/flex
flex/paths.py
path_to_pattern
def path_to_pattern(api_path, parameters): """ Given an api path, possibly with parameter notation, return a pattern suitable for turing into a regular expression which will match request paths that conform to the parameter definitions and the api path. """ parts = re.split(PARAMETER_REGEX, api_...
python
def path_to_pattern(api_path, parameters): """ Given an api path, possibly with parameter notation, return a pattern suitable for turing into a regular expression which will match request paths that conform to the parameter definitions and the api path. """ parts = re.split(PARAMETER_REGEX, api_...
[ "def", "path_to_pattern", "(", "api_path", ",", "parameters", ")", ":", "parts", "=", "re", ".", "split", "(", "PARAMETER_REGEX", ",", "api_path", ")", "pattern", "=", "''", ".", "join", "(", "(", "process_path_part", "(", "part", ",", "parameters", ")", ...
Given an api path, possibly with parameter notation, return a pattern suitable for turing into a regular expression which will match request paths that conform to the parameter definitions and the api path.
[ "Given", "an", "api", "path", "possibly", "with", "parameter", "notation", "return", "a", "pattern", "suitable", "for", "turing", "into", "a", "regular", "expression", "which", "will", "match", "request", "paths", "that", "conform", "to", "the", "parameter", "...
233f8149fb851a6255753bcec948cb6fefb2723b
https://github.com/pipermerriam/flex/blob/233f8149fb851a6255753bcec948cb6fefb2723b/flex/paths.py#L87-L101
train
pipermerriam/flex
flex/paths.py
match_path_to_api_path
def match_path_to_api_path(path_definitions, target_path, base_path='', context=None): """ Match a request or response path to one of the api paths. Anything other than exactly one match is an error condition. """ if context is None: context = {} assert isinst...
python
def match_path_to_api_path(path_definitions, target_path, base_path='', context=None): """ Match a request or response path to one of the api paths. Anything other than exactly one match is an error condition. """ if context is None: context = {} assert isinst...
[ "def", "match_path_to_api_path", "(", "path_definitions", ",", "target_path", ",", "base_path", "=", "''", ",", "context", "=", "None", ")", ":", "if", "context", "is", "None", ":", "context", "=", "{", "}", "assert", "isinstance", "(", "context", ",", "co...
Match a request or response path to one of the api paths. Anything other than exactly one match is an error condition.
[ "Match", "a", "request", "or", "response", "path", "to", "one", "of", "the", "api", "paths", "." ]
233f8149fb851a6255753bcec948cb6fefb2723b
https://github.com/pipermerriam/flex/blob/233f8149fb851a6255753bcec948cb6fefb2723b/flex/paths.py#L140-L209
train
pipermerriam/flex
flex/validation/request.py
validate_request
def validate_request(request, schema): """ Request validation does the following steps. 1. validate that the path matches one of the defined paths in the schema. 2. validate that the request method conforms to a supported methods for the given path. 3. validate that the request parameters ...
python
def validate_request(request, schema): """ Request validation does the following steps. 1. validate that the path matches one of the defined paths in the schema. 2. validate that the request method conforms to a supported methods for the given path. 3. validate that the request parameters ...
[ "def", "validate_request", "(", "request", ",", "schema", ")", ":", "with", "ErrorDict", "(", ")", "as", "errors", ":", "try", ":", "api_path", "=", "validate_path_to_api_path", "(", "path", "=", "request", ".", "path", ",", "context", "=", "schema", ",", ...
Request validation does the following steps. 1. validate that the path matches one of the defined paths in the schema. 2. validate that the request method conforms to a supported methods for the given path. 3. validate that the request parameters conform to the parameter definitions for ...
[ "Request", "validation", "does", "the", "following", "steps", "." ]
233f8149fb851a6255753bcec948cb6fefb2723b
https://github.com/pipermerriam/flex/blob/233f8149fb851a6255753bcec948cb6fefb2723b/flex/validation/request.py#L13-L65
train
pipermerriam/flex
flex/http.py
normalize_request
def normalize_request(request): """ Given a request, normalize it to the internal Request class. """ if isinstance(request, Request): return request for normalizer in REQUEST_NORMALIZERS: try: return normalizer(request) except TypeError: continue ...
python
def normalize_request(request): """ Given a request, normalize it to the internal Request class. """ if isinstance(request, Request): return request for normalizer in REQUEST_NORMALIZERS: try: return normalizer(request) except TypeError: continue ...
[ "def", "normalize_request", "(", "request", ")", ":", "if", "isinstance", "(", "request", ",", "Request", ")", ":", "return", "request", "for", "normalizer", "in", "REQUEST_NORMALIZERS", ":", "try", ":", "return", "normalizer", "(", "request", ")", "except", ...
Given a request, normalize it to the internal Request class.
[ "Given", "a", "request", "normalize", "it", "to", "the", "internal", "Request", "class", "." ]
233f8149fb851a6255753bcec948cb6fefb2723b
https://github.com/pipermerriam/flex/blob/233f8149fb851a6255753bcec948cb6fefb2723b/flex/http.py#L279-L292
train
pipermerriam/flex
flex/http.py
normalize_response
def normalize_response(response, request=None): """ Given a response, normalize it to the internal Response class. This also involves normalizing the associated request object. """ if isinstance(response, Response): return response if request is not None and not isinstance(request, Requ...
python
def normalize_response(response, request=None): """ Given a response, normalize it to the internal Response class. This also involves normalizing the associated request object. """ if isinstance(response, Response): return response if request is not None and not isinstance(request, Requ...
[ "def", "normalize_response", "(", "response", ",", "request", "=", "None", ")", ":", "if", "isinstance", "(", "response", ",", "Response", ")", ":", "return", "response", "if", "request", "is", "not", "None", "and", "not", "isinstance", "(", "request", ","...
Given a response, normalize it to the internal Response class. This also involves normalizing the associated request object.
[ "Given", "a", "response", "normalize", "it", "to", "the", "internal", "Response", "class", ".", "This", "also", "involves", "normalizing", "the", "associated", "request", "object", "." ]
233f8149fb851a6255753bcec948cb6fefb2723b
https://github.com/pipermerriam/flex/blob/233f8149fb851a6255753bcec948cb6fefb2723b/flex/http.py#L474-L490
train
pipermerriam/flex
flex/validation/operation.py
generate_header_validator
def generate_header_validator(headers, context, **kwargs): """ Generates a validation function that will validate a dictionary of headers. """ validators = ValidationDict() for header_definition in headers: header_processor = generate_value_processor( context=context, ...
python
def generate_header_validator(headers, context, **kwargs): """ Generates a validation function that will validate a dictionary of headers. """ validators = ValidationDict() for header_definition in headers: header_processor = generate_value_processor( context=context, ...
[ "def", "generate_header_validator", "(", "headers", ",", "context", ",", "**", "kwargs", ")", ":", "validators", "=", "ValidationDict", "(", ")", "for", "header_definition", "in", "headers", ":", "header_processor", "=", "generate_value_processor", "(", "context", ...
Generates a validation function that will validate a dictionary of headers.
[ "Generates", "a", "validation", "function", "that", "will", "validate", "a", "dictionary", "of", "headers", "." ]
233f8149fb851a6255753bcec948cb6fefb2723b
https://github.com/pipermerriam/flex/blob/233f8149fb851a6255753bcec948cb6fefb2723b/flex/validation/operation.py#L62-L82
train
pipermerriam/flex
flex/validation/operation.py
generate_parameters_validator
def generate_parameters_validator(api_path, path_definition, parameters, context, **kwargs): """ Generates a validator function to validate. - request.path against the path parameters. - request.query against the query parameters. - request.headers against the head...
python
def generate_parameters_validator(api_path, path_definition, parameters, context, **kwargs): """ Generates a validator function to validate. - request.path against the path parameters. - request.query against the query parameters. - request.headers against the head...
[ "def", "generate_parameters_validator", "(", "api_path", ",", "path_definition", ",", "parameters", ",", "context", ",", "**", "kwargs", ")", ":", "validators", "=", "ValidationDict", "(", ")", "path_level_parameters", "=", "dereference_parameter_list", "(", "path_def...
Generates a validator function to validate. - request.path against the path parameters. - request.query against the query parameters. - request.headers against the header parameters. - TODO: request.body against the body parameters. - TODO: request.formData against any form data.
[ "Generates", "a", "validator", "function", "to", "validate", "." ]
233f8149fb851a6255753bcec948cb6fefb2723b
https://github.com/pipermerriam/flex/blob/233f8149fb851a6255753bcec948cb6fefb2723b/flex/validation/operation.py#L100-L182
train
pipermerriam/flex
flex/decorators.py
partial_safe_wraps
def partial_safe_wraps(wrapped_func, *args, **kwargs): """ A version of `functools.wraps` that is safe to wrap a partial in. """ if isinstance(wrapped_func, functools.partial): return partial_safe_wraps(wrapped_func.func) else: return functools.wraps(wrapped_func)
python
def partial_safe_wraps(wrapped_func, *args, **kwargs): """ A version of `functools.wraps` that is safe to wrap a partial in. """ if isinstance(wrapped_func, functools.partial): return partial_safe_wraps(wrapped_func.func) else: return functools.wraps(wrapped_func)
[ "def", "partial_safe_wraps", "(", "wrapped_func", ",", "*", "args", ",", "**", "kwargs", ")", ":", "if", "isinstance", "(", "wrapped_func", ",", "functools", ".", "partial", ")", ":", "return", "partial_safe_wraps", "(", "wrapped_func", ".", "func", ")", "el...
A version of `functools.wraps` that is safe to wrap a partial in.
[ "A", "version", "of", "functools", ".", "wraps", "that", "is", "safe", "to", "wrap", "a", "partial", "in", "." ]
233f8149fb851a6255753bcec948cb6fefb2723b
https://github.com/pipermerriam/flex/blob/233f8149fb851a6255753bcec948cb6fefb2723b/flex/decorators.py#L10-L17
train
pipermerriam/flex
flex/decorators.py
skip_if_empty
def skip_if_empty(func): """ Decorator for validation functions which makes them pass if the value passed in is the EMPTY sentinal value. """ @partial_safe_wraps(func) def inner(value, *args, **kwargs): if value is EMPTY: return else: return func(value, *a...
python
def skip_if_empty(func): """ Decorator for validation functions which makes them pass if the value passed in is the EMPTY sentinal value. """ @partial_safe_wraps(func) def inner(value, *args, **kwargs): if value is EMPTY: return else: return func(value, *a...
[ "def", "skip_if_empty", "(", "func", ")", ":", "@", "partial_safe_wraps", "(", "func", ")", "def", "inner", "(", "value", ",", "*", "args", ",", "**", "kwargs", ")", ":", "if", "value", "is", "EMPTY", ":", "return", "else", ":", "return", "func", "("...
Decorator for validation functions which makes them pass if the value passed in is the EMPTY sentinal value.
[ "Decorator", "for", "validation", "functions", "which", "makes", "them", "pass", "if", "the", "value", "passed", "in", "is", "the", "EMPTY", "sentinal", "value", "." ]
233f8149fb851a6255753bcec948cb6fefb2723b
https://github.com/pipermerriam/flex/blob/233f8149fb851a6255753bcec948cb6fefb2723b/flex/decorators.py#L42-L53
train
pipermerriam/flex
flex/decorators.py
rewrite_reserved_words
def rewrite_reserved_words(func): """ Given a function whos kwargs need to contain a reserved word such as `in`, allow calling that function with the keyword as `in_`, such that function kwargs are rewritten to use the reserved word. """ @partial_safe_wraps(func) def inner(*args, **kwargs): ...
python
def rewrite_reserved_words(func): """ Given a function whos kwargs need to contain a reserved word such as `in`, allow calling that function with the keyword as `in_`, such that function kwargs are rewritten to use the reserved word. """ @partial_safe_wraps(func) def inner(*args, **kwargs): ...
[ "def", "rewrite_reserved_words", "(", "func", ")", ":", "@", "partial_safe_wraps", "(", "func", ")", "def", "inner", "(", "*", "args", ",", "**", "kwargs", ")", ":", "for", "word", "in", "RESERVED_WORDS", ":", "key", "=", "\"{0}_\"", ".", "format", "(", ...
Given a function whos kwargs need to contain a reserved word such as `in`, allow calling that function with the keyword as `in_`, such that function kwargs are rewritten to use the reserved word.
[ "Given", "a", "function", "whos", "kwargs", "need", "to", "contain", "a", "reserved", "word", "such", "as", "in", "allow", "calling", "that", "function", "with", "the", "keyword", "as", "in_", "such", "that", "function", "kwargs", "are", "rewritten", "to", ...
233f8149fb851a6255753bcec948cb6fefb2723b
https://github.com/pipermerriam/flex/blob/233f8149fb851a6255753bcec948cb6fefb2723b/flex/decorators.py#L74-L87
train
pipermerriam/flex
flex/validation/utils.py
any_validator
def any_validator(obj, validators, **kwargs): """ Attempt multiple validators on an object. - If any pass, then all validation passes. - Otherwise, raise all of the errors. """ if not len(validators) > 1: raise ValueError( "any_validator requires at least 2 validator. Only ...
python
def any_validator(obj, validators, **kwargs): """ Attempt multiple validators on an object. - If any pass, then all validation passes. - Otherwise, raise all of the errors. """ if not len(validators) > 1: raise ValueError( "any_validator requires at least 2 validator. Only ...
[ "def", "any_validator", "(", "obj", ",", "validators", ",", "**", "kwargs", ")", ":", "if", "not", "len", "(", "validators", ")", ">", "1", ":", "raise", "ValueError", "(", "\"any_validator requires at least 2 validator. Only got \"", "\"{0}\"", ".", "format", ...
Attempt multiple validators on an object. - If any pass, then all validation passes. - Otherwise, raise all of the errors.
[ "Attempt", "multiple", "validators", "on", "an", "object", "." ]
233f8149fb851a6255753bcec948cb6fefb2723b
https://github.com/pipermerriam/flex/blob/233f8149fb851a6255753bcec948cb6fefb2723b/flex/validation/utils.py#L9-L37
train
toabctl/metaextract
metaextract/utils.py
_extract_to_tempdir
def _extract_to_tempdir(archive_filename): """extract the given tarball or zipfile to a tempdir and change the cwd to the new tempdir. Delete the tempdir at the end""" if not os.path.exists(archive_filename): raise Exception("Archive '%s' does not exist" % (archive_filename)) tempdir = tempfile...
python
def _extract_to_tempdir(archive_filename): """extract the given tarball or zipfile to a tempdir and change the cwd to the new tempdir. Delete the tempdir at the end""" if not os.path.exists(archive_filename): raise Exception("Archive '%s' does not exist" % (archive_filename)) tempdir = tempfile...
[ "def", "_extract_to_tempdir", "(", "archive_filename", ")", ":", "if", "not", "os", ".", "path", ".", "exists", "(", "archive_filename", ")", ":", "raise", "Exception", "(", "\"Archive '%s' does not exist\"", "%", "(", "archive_filename", ")", ")", "tempdir", "=...
extract the given tarball or zipfile to a tempdir and change the cwd to the new tempdir. Delete the tempdir at the end
[ "extract", "the", "given", "tarball", "or", "zipfile", "to", "a", "tempdir", "and", "change", "the", "cwd", "to", "the", "new", "tempdir", ".", "Delete", "the", "tempdir", "at", "the", "end" ]
0515490b5983d888bbbaec5fdb5a0a4214743335
https://github.com/toabctl/metaextract/blob/0515490b5983d888bbbaec5fdb5a0a4214743335/metaextract/utils.py#L37-L59
train
toabctl/metaextract
metaextract/utils.py
_enter_single_subdir
def _enter_single_subdir(root_dir): """if the given directory has just a single subdir, enter that""" current_cwd = os.getcwd() try: dest_dir = root_dir dir_list = os.listdir(root_dir) if len(dir_list) == 1: first = os.path.join(root_dir, dir_list[0]) if os.pa...
python
def _enter_single_subdir(root_dir): """if the given directory has just a single subdir, enter that""" current_cwd = os.getcwd() try: dest_dir = root_dir dir_list = os.listdir(root_dir) if len(dir_list) == 1: first = os.path.join(root_dir, dir_list[0]) if os.pa...
[ "def", "_enter_single_subdir", "(", "root_dir", ")", ":", "current_cwd", "=", "os", ".", "getcwd", "(", ")", "try", ":", "dest_dir", "=", "root_dir", "dir_list", "=", "os", ".", "listdir", "(", "root_dir", ")", "if", "len", "(", "dir_list", ")", "==", ...
if the given directory has just a single subdir, enter that
[ "if", "the", "given", "directory", "has", "just", "a", "single", "subdir", "enter", "that" ]
0515490b5983d888bbbaec5fdb5a0a4214743335
https://github.com/toabctl/metaextract/blob/0515490b5983d888bbbaec5fdb5a0a4214743335/metaextract/utils.py#L63-L78
train
toabctl/metaextract
metaextract/utils.py
_set_file_encoding_utf8
def _set_file_encoding_utf8(filename): """set a encoding header as suggested in PEP-0263. This is not entirely correct because we don't know the encoding of the given file but it's at least a chance to get metadata from the setup.py""" with open(filename, 'r+') as f: content = f.read() f...
python
def _set_file_encoding_utf8(filename): """set a encoding header as suggested in PEP-0263. This is not entirely correct because we don't know the encoding of the given file but it's at least a chance to get metadata from the setup.py""" with open(filename, 'r+') as f: content = f.read() f...
[ "def", "_set_file_encoding_utf8", "(", "filename", ")", ":", "with", "open", "(", "filename", ",", "'r+'", ")", "as", "f", ":", "content", "=", "f", ".", "read", "(", ")", "f", ".", "seek", "(", "0", ",", "0", ")", "f", ".", "write", "(", "\"# -*...
set a encoding header as suggested in PEP-0263. This is not entirely correct because we don't know the encoding of the given file but it's at least a chance to get metadata from the setup.py
[ "set", "a", "encoding", "header", "as", "suggested", "in", "PEP", "-", "0263", ".", "This", "is", "not", "entirely", "correct", "because", "we", "don", "t", "know", "the", "encoding", "of", "the", "given", "file", "but", "it", "s", "at", "least", "a", ...
0515490b5983d888bbbaec5fdb5a0a4214743335
https://github.com/toabctl/metaextract/blob/0515490b5983d888bbbaec5fdb5a0a4214743335/metaextract/utils.py#L81-L88
train
toabctl/metaextract
metaextract/utils.py
_setup_py_run_from_dir
def _setup_py_run_from_dir(root_dir, py_interpreter): """run the extractmeta command via the setup.py in the given root_dir. the output of extractmeta is json and is stored in a tempfile which is then read in and returned as data""" data = {} with _enter_single_subdir(root_dir) as single_subdir: ...
python
def _setup_py_run_from_dir(root_dir, py_interpreter): """run the extractmeta command via the setup.py in the given root_dir. the output of extractmeta is json and is stored in a tempfile which is then read in and returned as data""" data = {} with _enter_single_subdir(root_dir) as single_subdir: ...
[ "def", "_setup_py_run_from_dir", "(", "root_dir", ",", "py_interpreter", ")", ":", "data", "=", "{", "}", "with", "_enter_single_subdir", "(", "root_dir", ")", "as", "single_subdir", ":", "if", "not", "os", ".", "path", ".", "exists", "(", "\"setup.py\"", ")...
run the extractmeta command via the setup.py in the given root_dir. the output of extractmeta is json and is stored in a tempfile which is then read in and returned as data
[ "run", "the", "extractmeta", "command", "via", "the", "setup", ".", "py", "in", "the", "given", "root_dir", ".", "the", "output", "of", "extractmeta", "is", "json", "and", "is", "stored", "in", "a", "tempfile", "which", "is", "then", "read", "in", "and",...
0515490b5983d888bbbaec5fdb5a0a4214743335
https://github.com/toabctl/metaextract/blob/0515490b5983d888bbbaec5fdb5a0a4214743335/metaextract/utils.py#L91-L121
train
toabctl/metaextract
metaextract/utils.py
from_archive
def from_archive(archive_filename, py_interpreter=sys.executable): """extract metadata from a given sdist archive file :param archive_filename: a sdist archive file :param py_interpreter: The full path to the used python interpreter :returns: a json blob with metadata """ with _extract_to_tempdir(...
python
def from_archive(archive_filename, py_interpreter=sys.executable): """extract metadata from a given sdist archive file :param archive_filename: a sdist archive file :param py_interpreter: The full path to the used python interpreter :returns: a json blob with metadata """ with _extract_to_tempdir(...
[ "def", "from_archive", "(", "archive_filename", ",", "py_interpreter", "=", "sys", ".", "executable", ")", ":", "with", "_extract_to_tempdir", "(", "archive_filename", ")", "as", "root_dir", ":", "data", "=", "_setup_py_run_from_dir", "(", "root_dir", ",", "py_int...
extract metadata from a given sdist archive file :param archive_filename: a sdist archive file :param py_interpreter: The full path to the used python interpreter :returns: a json blob with metadata
[ "extract", "metadata", "from", "a", "given", "sdist", "archive", "file" ]
0515490b5983d888bbbaec5fdb5a0a4214743335
https://github.com/toabctl/metaextract/blob/0515490b5983d888bbbaec5fdb5a0a4214743335/metaextract/utils.py#L125-L135
train
rwl/PyCIM
PyCIM/RDFXMLReader.py
xmlns
def xmlns(source): """ Returns a map of prefix to namespace for the given XML file. """ namespaces = {} events=("end", "start-ns", "end-ns") for (event, elem) in iterparse(source, events): if event == "start-ns": prefix, ns = elem namespaces[prefix] = ns ...
python
def xmlns(source): """ Returns a map of prefix to namespace for the given XML file. """ namespaces = {} events=("end", "start-ns", "end-ns") for (event, elem) in iterparse(source, events): if event == "start-ns": prefix, ns = elem namespaces[prefix] = ns ...
[ "def", "xmlns", "(", "source", ")", ":", "namespaces", "=", "{", "}", "events", "=", "(", "\"end\"", ",", "\"start-ns\"", ",", "\"end-ns\"", ")", "for", "(", "event", ",", "elem", ")", "in", "iterparse", "(", "source", ",", "events", ")", ":", "if", ...
Returns a map of prefix to namespace for the given XML file.
[ "Returns", "a", "map", "of", "prefix", "to", "namespace", "for", "the", "given", "XML", "file", "." ]
4a12ebb5a7fb03c7790d396910daef9b97c4ef99
https://github.com/rwl/PyCIM/blob/4a12ebb5a7fb03c7790d396910daef9b97c4ef99/PyCIM/RDFXMLReader.py#L226-L244
train
adafruit/Adafruit_Python_PN532
examples/mcpi_listen.py
create_block
def create_block(mc, block_id, subtype=None): """Build a block with the specified id and subtype under the player in the Minecraft world. Subtype is optional and can be specified as None to use the default subtype for the block. """ # Get player tile position and real position. ptx, pty, ptz = ...
python
def create_block(mc, block_id, subtype=None): """Build a block with the specified id and subtype under the player in the Minecraft world. Subtype is optional and can be specified as None to use the default subtype for the block. """ # Get player tile position and real position. ptx, pty, ptz = ...
[ "def", "create_block", "(", "mc", ",", "block_id", ",", "subtype", "=", "None", ")", ":", "ptx", ",", "pty", ",", "ptz", "=", "mc", ".", "player", ".", "getTilePos", "(", ")", "px", ",", "py", ",", "pz", "=", "mc", ".", "player", ".", "getPos", ...
Build a block with the specified id and subtype under the player in the Minecraft world. Subtype is optional and can be specified as None to use the default subtype for the block.
[ "Build", "a", "block", "with", "the", "specified", "id", "and", "subtype", "under", "the", "player", "in", "the", "Minecraft", "world", ".", "Subtype", "is", "optional", "and", "can", "be", "specified", "as", "None", "to", "use", "the", "default", "subtype...
343521a8ec842ea82f680a5ed868fee16e9609bd
https://github.com/adafruit/Adafruit_Python_PN532/blob/343521a8ec842ea82f680a5ed868fee16e9609bd/examples/mcpi_listen.py#L48-L62
train
adafruit/Adafruit_Python_PN532
Adafruit_PN532/PN532.py
PN532._busy_wait_ms
def _busy_wait_ms(self, ms): """Busy wait for the specified number of milliseconds.""" start = time.time() delta = ms/1000.0 while (time.time() - start) <= delta: pass
python
def _busy_wait_ms(self, ms): """Busy wait for the specified number of milliseconds.""" start = time.time() delta = ms/1000.0 while (time.time() - start) <= delta: pass
[ "def", "_busy_wait_ms", "(", "self", ",", "ms", ")", ":", "start", "=", "time", ".", "time", "(", ")", "delta", "=", "ms", "/", "1000.0", "while", "(", "time", ".", "time", "(", ")", "-", "start", ")", "<=", "delta", ":", "pass" ]
Busy wait for the specified number of milliseconds.
[ "Busy", "wait", "for", "the", "specified", "number", "of", "milliseconds", "." ]
343521a8ec842ea82f680a5ed868fee16e9609bd
https://github.com/adafruit/Adafruit_Python_PN532/blob/343521a8ec842ea82f680a5ed868fee16e9609bd/Adafruit_PN532/PN532.py#L191-L196
train
adafruit/Adafruit_Python_PN532
Adafruit_PN532/PN532.py
PN532._write_frame
def _write_frame(self, data): """Write a frame to the PN532 with the specified data bytearray.""" assert data is not None and 0 < len(data) < 255, 'Data must be array of 1 to 255 bytes.' # Build frame to send as: # - SPI data write (0x01) # - Preamble (0x00) # - Start cod...
python
def _write_frame(self, data): """Write a frame to the PN532 with the specified data bytearray.""" assert data is not None and 0 < len(data) < 255, 'Data must be array of 1 to 255 bytes.' # Build frame to send as: # - SPI data write (0x01) # - Preamble (0x00) # - Start cod...
[ "def", "_write_frame", "(", "self", ",", "data", ")", ":", "assert", "data", "is", "not", "None", "and", "0", "<", "len", "(", "data", ")", "<", "255", ",", "'Data must be array of 1 to 255 bytes.'", "length", "=", "len", "(", "data", ")", "frame", "=", ...
Write a frame to the PN532 with the specified data bytearray.
[ "Write", "a", "frame", "to", "the", "PN532", "with", "the", "specified", "data", "bytearray", "." ]
343521a8ec842ea82f680a5ed868fee16e9609bd
https://github.com/adafruit/Adafruit_Python_PN532/blob/343521a8ec842ea82f680a5ed868fee16e9609bd/Adafruit_PN532/PN532.py#L198-L227
train
adafruit/Adafruit_Python_PN532
Adafruit_PN532/PN532.py
PN532._read_data
def _read_data(self, count): """Read a specified count of bytes from the PN532.""" # Build a read request frame. frame = bytearray(count) frame[0] = PN532_SPI_DATAREAD # Send the frame and return the response, ignoring the SPI header byte. self._gpio.set_low(self._cs) ...
python
def _read_data(self, count): """Read a specified count of bytes from the PN532.""" # Build a read request frame. frame = bytearray(count) frame[0] = PN532_SPI_DATAREAD # Send the frame and return the response, ignoring the SPI header byte. self._gpio.set_low(self._cs) ...
[ "def", "_read_data", "(", "self", ",", "count", ")", ":", "frame", "=", "bytearray", "(", "count", ")", "frame", "[", "0", "]", "=", "PN532_SPI_DATAREAD", "self", ".", "_gpio", ".", "set_low", "(", "self", ".", "_cs", ")", "self", ".", "_busy_wait_ms",...
Read a specified count of bytes from the PN532.
[ "Read", "a", "specified", "count", "of", "bytes", "from", "the", "PN532", "." ]
343521a8ec842ea82f680a5ed868fee16e9609bd
https://github.com/adafruit/Adafruit_Python_PN532/blob/343521a8ec842ea82f680a5ed868fee16e9609bd/Adafruit_PN532/PN532.py#L229-L239
train
adafruit/Adafruit_Python_PN532
Adafruit_PN532/PN532.py
PN532._read_frame
def _read_frame(self, length): """Read a response frame from the PN532 of at most length bytes in size. Returns the data inside the frame if found, otherwise raises an exception if there is an error parsing the frame. Note that less than length bytes might be returned! """ ...
python
def _read_frame(self, length): """Read a response frame from the PN532 of at most length bytes in size. Returns the data inside the frame if found, otherwise raises an exception if there is an error parsing the frame. Note that less than length bytes might be returned! """ ...
[ "def", "_read_frame", "(", "self", ",", "length", ")", ":", "response", "=", "self", ".", "_read_data", "(", "length", "+", "8", ")", "logger", ".", "debug", "(", "'Read frame: 0x{0}'", ".", "format", "(", "binascii", ".", "hexlify", "(", "response", ")"...
Read a response frame from the PN532 of at most length bytes in size. Returns the data inside the frame if found, otherwise raises an exception if there is an error parsing the frame. Note that less than length bytes might be returned!
[ "Read", "a", "response", "frame", "from", "the", "PN532", "of", "at", "most", "length", "bytes", "in", "size", ".", "Returns", "the", "data", "inside", "the", "frame", "if", "found", "otherwise", "raises", "an", "exception", "if", "there", "is", "an", "e...
343521a8ec842ea82f680a5ed868fee16e9609bd
https://github.com/adafruit/Adafruit_Python_PN532/blob/343521a8ec842ea82f680a5ed868fee16e9609bd/Adafruit_PN532/PN532.py#L241-L274
train
adafruit/Adafruit_Python_PN532
Adafruit_PN532/PN532.py
PN532._wait_ready
def _wait_ready(self, timeout_sec=1): """Wait until the PN532 is ready to receive commands. At most wait timeout_sec seconds for the PN532 to be ready. If the PN532 is ready before the timeout is exceeded then True will be returned, otherwise False is returned when the timeout is excee...
python
def _wait_ready(self, timeout_sec=1): """Wait until the PN532 is ready to receive commands. At most wait timeout_sec seconds for the PN532 to be ready. If the PN532 is ready before the timeout is exceeded then True will be returned, otherwise False is returned when the timeout is excee...
[ "def", "_wait_ready", "(", "self", ",", "timeout_sec", "=", "1", ")", ":", "start", "=", "time", ".", "time", "(", ")", "self", ".", "_gpio", ".", "set_low", "(", "self", ".", "_cs", ")", "self", ".", "_busy_wait_ms", "(", "2", ")", "response", "="...
Wait until the PN532 is ready to receive commands. At most wait timeout_sec seconds for the PN532 to be ready. If the PN532 is ready before the timeout is exceeded then True will be returned, otherwise False is returned when the timeout is exceeded.
[ "Wait", "until", "the", "PN532", "is", "ready", "to", "receive", "commands", ".", "At", "most", "wait", "timeout_sec", "seconds", "for", "the", "PN532", "to", "be", "ready", ".", "If", "the", "PN532", "is", "ready", "before", "the", "timeout", "is", "exc...
343521a8ec842ea82f680a5ed868fee16e9609bd
https://github.com/adafruit/Adafruit_Python_PN532/blob/343521a8ec842ea82f680a5ed868fee16e9609bd/Adafruit_PN532/PN532.py#L276-L299
train
adafruit/Adafruit_Python_PN532
Adafruit_PN532/PN532.py
PN532.call_function
def call_function(self, command, response_length=0, params=[], timeout_sec=1): """Send specified command to the PN532 and expect up to response_length bytes back in a response. Note that less than the expected bytes might be returned! Params can optionally specify an array of bytes to send as ...
python
def call_function(self, command, response_length=0, params=[], timeout_sec=1): """Send specified command to the PN532 and expect up to response_length bytes back in a response. Note that less than the expected bytes might be returned! Params can optionally specify an array of bytes to send as ...
[ "def", "call_function", "(", "self", ",", "command", ",", "response_length", "=", "0", ",", "params", "=", "[", "]", ",", "timeout_sec", "=", "1", ")", ":", "data", "=", "bytearray", "(", "2", "+", "len", "(", "params", ")", ")", "data", "[", "0", ...
Send specified command to the PN532 and expect up to response_length bytes back in a response. Note that less than the expected bytes might be returned! Params can optionally specify an array of bytes to send as parameters to the function call. Will wait up to timeout_secs seconds for...
[ "Send", "specified", "command", "to", "the", "PN532", "and", "expect", "up", "to", "response_length", "bytes", "back", "in", "a", "response", ".", "Note", "that", "less", "than", "the", "expected", "bytes", "might", "be", "returned!", "Params", "can", "optio...
343521a8ec842ea82f680a5ed868fee16e9609bd
https://github.com/adafruit/Adafruit_Python_PN532/blob/343521a8ec842ea82f680a5ed868fee16e9609bd/Adafruit_PN532/PN532.py#L301-L330
train
adafruit/Adafruit_Python_PN532
Adafruit_PN532/PN532.py
PN532.begin
def begin(self): """Initialize communication with the PN532. Must be called before any other calls are made against the PN532. """ # Assert CS pin low for a second for PN532 to be ready. self._gpio.set_low(self._cs) time.sleep(1.0) # Call GetFirmwareVersion to sy...
python
def begin(self): """Initialize communication with the PN532. Must be called before any other calls are made against the PN532. """ # Assert CS pin low for a second for PN532 to be ready. self._gpio.set_low(self._cs) time.sleep(1.0) # Call GetFirmwareVersion to sy...
[ "def", "begin", "(", "self", ")", ":", "self", ".", "_gpio", ".", "set_low", "(", "self", ".", "_cs", ")", "time", ".", "sleep", "(", "1.0", ")", "self", ".", "get_firmware_version", "(", ")", "self", ".", "_gpio", ".", "set_high", "(", "self", "."...
Initialize communication with the PN532. Must be called before any other calls are made against the PN532.
[ "Initialize", "communication", "with", "the", "PN532", ".", "Must", "be", "called", "before", "any", "other", "calls", "are", "made", "against", "the", "PN532", "." ]
343521a8ec842ea82f680a5ed868fee16e9609bd
https://github.com/adafruit/Adafruit_Python_PN532/blob/343521a8ec842ea82f680a5ed868fee16e9609bd/Adafruit_PN532/PN532.py#L332-L342
train
adafruit/Adafruit_Python_PN532
Adafruit_PN532/PN532.py
PN532.get_firmware_version
def get_firmware_version(self): """Call PN532 GetFirmwareVersion function and return a tuple with the IC, Ver, Rev, and Support values. """ response = self.call_function(PN532_COMMAND_GETFIRMWAREVERSION, 4) if response is None: raise RuntimeError('Failed to detect the...
python
def get_firmware_version(self): """Call PN532 GetFirmwareVersion function and return a tuple with the IC, Ver, Rev, and Support values. """ response = self.call_function(PN532_COMMAND_GETFIRMWAREVERSION, 4) if response is None: raise RuntimeError('Failed to detect the...
[ "def", "get_firmware_version", "(", "self", ")", ":", "response", "=", "self", ".", "call_function", "(", "PN532_COMMAND_GETFIRMWAREVERSION", ",", "4", ")", "if", "response", "is", "None", ":", "raise", "RuntimeError", "(", "'Failed to detect the PN532! Make sure the...
Call PN532 GetFirmwareVersion function and return a tuple with the IC, Ver, Rev, and Support values.
[ "Call", "PN532", "GetFirmwareVersion", "function", "and", "return", "a", "tuple", "with", "the", "IC", "Ver", "Rev", "and", "Support", "values", "." ]
343521a8ec842ea82f680a5ed868fee16e9609bd
https://github.com/adafruit/Adafruit_Python_PN532/blob/343521a8ec842ea82f680a5ed868fee16e9609bd/Adafruit_PN532/PN532.py#L344-L351
train
adafruit/Adafruit_Python_PN532
Adafruit_PN532/PN532.py
PN532.read_passive_target
def read_passive_target(self, card_baud=PN532_MIFARE_ISO14443A, timeout_sec=1): """Wait for a MiFare card to be available and return its UID when found. Will wait up to timeout_sec seconds and return None if no card is found, otherwise a bytearray with the UID of the found card is returned. ...
python
def read_passive_target(self, card_baud=PN532_MIFARE_ISO14443A, timeout_sec=1): """Wait for a MiFare card to be available and return its UID when found. Will wait up to timeout_sec seconds and return None if no card is found, otherwise a bytearray with the UID of the found card is returned. ...
[ "def", "read_passive_target", "(", "self", ",", "card_baud", "=", "PN532_MIFARE_ISO14443A", ",", "timeout_sec", "=", "1", ")", ":", "response", "=", "self", ".", "call_function", "(", "PN532_COMMAND_INLISTPASSIVETARGET", ",", "params", "=", "[", "0x01", ",", "ca...
Wait for a MiFare card to be available and return its UID when found. Will wait up to timeout_sec seconds and return None if no card is found, otherwise a bytearray with the UID of the found card is returned.
[ "Wait", "for", "a", "MiFare", "card", "to", "be", "available", "and", "return", "its", "UID", "when", "found", ".", "Will", "wait", "up", "to", "timeout_sec", "seconds", "and", "return", "None", "if", "no", "card", "is", "found", "otherwise", "a", "bytea...
343521a8ec842ea82f680a5ed868fee16e9609bd
https://github.com/adafruit/Adafruit_Python_PN532/blob/343521a8ec842ea82f680a5ed868fee16e9609bd/Adafruit_PN532/PN532.py#L363-L381
train
adafruit/Adafruit_Python_PN532
Adafruit_PN532/PN532.py
PN532.mifare_classic_read_block
def mifare_classic_read_block(self, block_number): """Read a block of data from the card. Block number should be the block to read. If the block is successfully read a bytearray of length 16 with data starting at the specified block will be returned. If the block is not read then None...
python
def mifare_classic_read_block(self, block_number): """Read a block of data from the card. Block number should be the block to read. If the block is successfully read a bytearray of length 16 with data starting at the specified block will be returned. If the block is not read then None...
[ "def", "mifare_classic_read_block", "(", "self", ",", "block_number", ")", ":", "response", "=", "self", ".", "call_function", "(", "PN532_COMMAND_INDATAEXCHANGE", ",", "params", "=", "[", "0x01", ",", "MIFARE_CMD_READ", ",", "block_number", "&", "0xFF", "]", ",...
Read a block of data from the card. Block number should be the block to read. If the block is successfully read a bytearray of length 16 with data starting at the specified block will be returned. If the block is not read then None will be returned.
[ "Read", "a", "block", "of", "data", "from", "the", "card", ".", "Block", "number", "should", "be", "the", "block", "to", "read", ".", "If", "the", "block", "is", "successfully", "read", "a", "bytearray", "of", "length", "16", "with", "data", "starting", ...
343521a8ec842ea82f680a5ed868fee16e9609bd
https://github.com/adafruit/Adafruit_Python_PN532/blob/343521a8ec842ea82f680a5ed868fee16e9609bd/Adafruit_PN532/PN532.py#L406-L420
train
adafruit/Adafruit_Python_PN532
Adafruit_PN532/PN532.py
PN532.mifare_classic_write_block
def mifare_classic_write_block(self, block_number, data): """Write a block of data to the card. Block number should be the block to write and data should be a byte array of length 16 with the data to write. If the data is successfully written then True is returned, otherwise False is r...
python
def mifare_classic_write_block(self, block_number, data): """Write a block of data to the card. Block number should be the block to write and data should be a byte array of length 16 with the data to write. If the data is successfully written then True is returned, otherwise False is r...
[ "def", "mifare_classic_write_block", "(", "self", ",", "block_number", ",", "data", ")", ":", "assert", "data", "is", "not", "None", "and", "len", "(", "data", ")", "==", "16", ",", "'Data must be an array of 16 bytes!'", "params", "=", "bytearray", "(", "19",...
Write a block of data to the card. Block number should be the block to write and data should be a byte array of length 16 with the data to write. If the data is successfully written then True is returned, otherwise False is returned.
[ "Write", "a", "block", "of", "data", "to", "the", "card", ".", "Block", "number", "should", "be", "the", "block", "to", "write", "and", "data", "should", "be", "a", "byte", "array", "of", "length", "16", "with", "the", "data", "to", "write", ".", "If...
343521a8ec842ea82f680a5ed868fee16e9609bd
https://github.com/adafruit/Adafruit_Python_PN532/blob/343521a8ec842ea82f680a5ed868fee16e9609bd/Adafruit_PN532/PN532.py#L422-L439
train
edwardgeorge/virtualenv-clone
clonevirtualenv.py
_dirmatch
def _dirmatch(path, matchwith): """Check if path is within matchwith's tree. >>> _dirmatch('/home/foo/bar', '/home/foo/bar') True >>> _dirmatch('/home/foo/bar/', '/home/foo/bar') True >>> _dirmatch('/home/foo/bar/etc', '/home/foo/bar') True >>> _dirmatch('/home/foo/bar2', '/home/foo/bar...
python
def _dirmatch(path, matchwith): """Check if path is within matchwith's tree. >>> _dirmatch('/home/foo/bar', '/home/foo/bar') True >>> _dirmatch('/home/foo/bar/', '/home/foo/bar') True >>> _dirmatch('/home/foo/bar/etc', '/home/foo/bar') True >>> _dirmatch('/home/foo/bar2', '/home/foo/bar...
[ "def", "_dirmatch", "(", "path", ",", "matchwith", ")", ":", "matchlen", "=", "len", "(", "matchwith", ")", "if", "(", "path", ".", "startswith", "(", "matchwith", ")", "and", "path", "[", "matchlen", ":", "matchlen", "+", "1", "]", "in", "[", "os", ...
Check if path is within matchwith's tree. >>> _dirmatch('/home/foo/bar', '/home/foo/bar') True >>> _dirmatch('/home/foo/bar/', '/home/foo/bar') True >>> _dirmatch('/home/foo/bar/etc', '/home/foo/bar') True >>> _dirmatch('/home/foo/bar2', '/home/foo/bar') False >>> _dirmatch('/home/f...
[ "Check", "if", "path", "is", "within", "matchwith", "s", "tree", "." ]
434b12eb725ac1850b60f2bad8e848540e5596de
https://github.com/edwardgeorge/virtualenv-clone/blob/434b12eb725ac1850b60f2bad8e848540e5596de/clonevirtualenv.py#L29-L47
train
edwardgeorge/virtualenv-clone
clonevirtualenv.py
_virtualenv_sys
def _virtualenv_sys(venv_path): "obtain version and path info from a virtualenv." executable = os.path.join(venv_path, env_bin_dir, 'python') # Must use "executable" as the first argument rather than as the # keyword argument "executable" to get correct value from sys.path p = subprocess.Popen([exec...
python
def _virtualenv_sys(venv_path): "obtain version and path info from a virtualenv." executable = os.path.join(venv_path, env_bin_dir, 'python') # Must use "executable" as the first argument rather than as the # keyword argument "executable" to get correct value from sys.path p = subprocess.Popen([exec...
[ "def", "_virtualenv_sys", "(", "venv_path", ")", ":", "\"obtain version and path info from a virtualenv.\"", "executable", "=", "os", ".", "path", ".", "join", "(", "venv_path", ",", "env_bin_dir", ",", "'python'", ")", "p", "=", "subprocess", ".", "Popen", "(", ...
obtain version and path info from a virtualenv.
[ "obtain", "version", "and", "path", "info", "from", "a", "virtualenv", "." ]
434b12eb725ac1850b60f2bad8e848540e5596de
https://github.com/edwardgeorge/virtualenv-clone/blob/434b12eb725ac1850b60f2bad8e848540e5596de/clonevirtualenv.py#L50-L64
train
dsoprea/PyEasyArchive
libarchive/types/archive_entry.py
int_to_ef
def int_to_ef(n): """This is here for testing support but, in practice, this isn't very useful as many of the flags are just combinations of other flags. The relationships are defined by the OS in ways that aren't semantically intuitive to this project. """ flags = {} for name, value in lib...
python
def int_to_ef(n): """This is here for testing support but, in practice, this isn't very useful as many of the flags are just combinations of other flags. The relationships are defined by the OS in ways that aren't semantically intuitive to this project. """ flags = {} for name, value in lib...
[ "def", "int_to_ef", "(", "n", ")", ":", "flags", "=", "{", "}", "for", "name", ",", "value", "in", "libarchive", ".", "constants", ".", "archive_entry", ".", "FILETYPES", ".", "items", "(", ")", ":", "flags", "[", "name", "]", "=", "(", "n", "&", ...
This is here for testing support but, in practice, this isn't very useful as many of the flags are just combinations of other flags. The relationships are defined by the OS in ways that aren't semantically intuitive to this project.
[ "This", "is", "here", "for", "testing", "support", "but", "in", "practice", "this", "isn", "t", "very", "useful", "as", "many", "of", "the", "flags", "are", "just", "combinations", "of", "other", "flags", ".", "The", "relationships", "are", "defined", "by"...
50414b9fa9a1055435499b5b2e4b2a336a40dff6
https://github.com/dsoprea/PyEasyArchive/blob/50414b9fa9a1055435499b5b2e4b2a336a40dff6/libarchive/types/archive_entry.py#L24-L35
train
dsoprea/PyEasyArchive
libarchive/adapters/archive_read.py
_enumerator
def _enumerator(opener, entry_cls, format_code=None, filter_code=None): """Return an archive enumerator from a user-defined source, using a user- defined entry type. """ archive_res = _archive_read_new() try: r = _set_read_context(archive_res, format_code, filter_code) opener(archi...
python
def _enumerator(opener, entry_cls, format_code=None, filter_code=None): """Return an archive enumerator from a user-defined source, using a user- defined entry type. """ archive_res = _archive_read_new() try: r = _set_read_context(archive_res, format_code, filter_code) opener(archi...
[ "def", "_enumerator", "(", "opener", ",", "entry_cls", ",", "format_code", "=", "None", ",", "filter_code", "=", "None", ")", ":", "archive_res", "=", "_archive_read_new", "(", ")", "try", ":", "r", "=", "_set_read_context", "(", "archive_res", ",", "format_...
Return an archive enumerator from a user-defined source, using a user- defined entry type.
[ "Return", "an", "archive", "enumerator", "from", "a", "user", "-", "defined", "source", "using", "a", "user", "-", "defined", "entry", "type", "." ]
50414b9fa9a1055435499b5b2e4b2a336a40dff6
https://github.com/dsoprea/PyEasyArchive/blob/50414b9fa9a1055435499b5b2e4b2a336a40dff6/libarchive/adapters/archive_read.py#L270-L293
train
dsoprea/PyEasyArchive
libarchive/adapters/archive_read.py
file_enumerator
def file_enumerator(filepath, block_size=10240, *args, **kwargs): """Return an enumerator that knows how to read a physical file.""" _LOGGER.debug("Enumerating through archive file: %s", filepath) def opener(archive_res): _LOGGER.debug("Opening from file (file_enumerator): %s", filepath) _...
python
def file_enumerator(filepath, block_size=10240, *args, **kwargs): """Return an enumerator that knows how to read a physical file.""" _LOGGER.debug("Enumerating through archive file: %s", filepath) def opener(archive_res): _LOGGER.debug("Opening from file (file_enumerator): %s", filepath) _...
[ "def", "file_enumerator", "(", "filepath", ",", "block_size", "=", "10240", ",", "*", "args", ",", "**", "kwargs", ")", ":", "_LOGGER", ".", "debug", "(", "\"Enumerating through archive file: %s\"", ",", "filepath", ")", "def", "opener", "(", "archive_res", ")...
Return an enumerator that knows how to read a physical file.
[ "Return", "an", "enumerator", "that", "knows", "how", "to", "read", "a", "physical", "file", "." ]
50414b9fa9a1055435499b5b2e4b2a336a40dff6
https://github.com/dsoprea/PyEasyArchive/blob/50414b9fa9a1055435499b5b2e4b2a336a40dff6/libarchive/adapters/archive_read.py#L295-L309
train
dsoprea/PyEasyArchive
libarchive/adapters/archive_read.py
memory_enumerator
def memory_enumerator(buffer_, *args, **kwargs): """Return an enumerator that knows how to read raw memory.""" _LOGGER.debug("Enumerating through (%d) bytes of archive data.", len(buffer_)) def opener(archive_res): _LOGGER.debug("Opening from (%d) bytes (memory_enumerator).", ...
python
def memory_enumerator(buffer_, *args, **kwargs): """Return an enumerator that knows how to read raw memory.""" _LOGGER.debug("Enumerating through (%d) bytes of archive data.", len(buffer_)) def opener(archive_res): _LOGGER.debug("Opening from (%d) bytes (memory_enumerator).", ...
[ "def", "memory_enumerator", "(", "buffer_", ",", "*", "args", ",", "**", "kwargs", ")", ":", "_LOGGER", ".", "debug", "(", "\"Enumerating through (%d) bytes of archive data.\"", ",", "len", "(", "buffer_", ")", ")", "def", "opener", "(", "archive_res", ")", ":...
Return an enumerator that knows how to read raw memory.
[ "Return", "an", "enumerator", "that", "knows", "how", "to", "read", "raw", "memory", "." ]
50414b9fa9a1055435499b5b2e4b2a336a40dff6
https://github.com/dsoprea/PyEasyArchive/blob/50414b9fa9a1055435499b5b2e4b2a336a40dff6/libarchive/adapters/archive_read.py#L311-L328
train
dsoprea/PyEasyArchive
libarchive/adapters/archive_read.py
_pour
def _pour(opener, flags=0, *args, **kwargs): """A flexible pouring facility that knows how to enumerate entry data.""" with _enumerator(opener, *args, entry_cls=_ArchiveEntryItState, **kwargs) as r: ext = libarchive.calls.archive_write.c_ar...
python
def _pour(opener, flags=0, *args, **kwargs): """A flexible pouring facility that knows how to enumerate entry data.""" with _enumerator(opener, *args, entry_cls=_ArchiveEntryItState, **kwargs) as r: ext = libarchive.calls.archive_write.c_ar...
[ "def", "_pour", "(", "opener", ",", "flags", "=", "0", ",", "*", "args", ",", "**", "kwargs", ")", ":", "with", "_enumerator", "(", "opener", ",", "*", "args", ",", "entry_cls", "=", "_ArchiveEntryItState", ",", "**", "kwargs", ")", "as", "r", ":", ...
A flexible pouring facility that knows how to enumerate entry data.
[ "A", "flexible", "pouring", "facility", "that", "knows", "how", "to", "enumerate", "entry", "data", "." ]
50414b9fa9a1055435499b5b2e4b2a336a40dff6
https://github.com/dsoprea/PyEasyArchive/blob/50414b9fa9a1055435499b5b2e4b2a336a40dff6/libarchive/adapters/archive_read.py#L348-L397
train
dsoprea/PyEasyArchive
libarchive/adapters/archive_read.py
file_pour
def file_pour(filepath, block_size=10240, *args, **kwargs): """Write physical files from entries.""" def opener(archive_res): _LOGGER.debug("Opening from file (file_pour): %s", filepath) _archive_read_open_filename(archive_res, filepath, block_size) return _pour(opener, *args, flags=0, **k...
python
def file_pour(filepath, block_size=10240, *args, **kwargs): """Write physical files from entries.""" def opener(archive_res): _LOGGER.debug("Opening from file (file_pour): %s", filepath) _archive_read_open_filename(archive_res, filepath, block_size) return _pour(opener, *args, flags=0, **k...
[ "def", "file_pour", "(", "filepath", ",", "block_size", "=", "10240", ",", "*", "args", ",", "**", "kwargs", ")", ":", "def", "opener", "(", "archive_res", ")", ":", "_LOGGER", ".", "debug", "(", "\"Opening from file (file_pour): %s\"", ",", "filepath", ")",...
Write physical files from entries.
[ "Write", "physical", "files", "from", "entries", "." ]
50414b9fa9a1055435499b5b2e4b2a336a40dff6
https://github.com/dsoprea/PyEasyArchive/blob/50414b9fa9a1055435499b5b2e4b2a336a40dff6/libarchive/adapters/archive_read.py#L399-L406
train
dsoprea/PyEasyArchive
libarchive/adapters/archive_read.py
memory_pour
def memory_pour(buffer_, *args, **kwargs): """Yield data from entries.""" def opener(archive_res): _LOGGER.debug("Opening from (%d) bytes (memory_pour).", len(buffer_)) _archive_read_open_memory(archive_res, buffer_) return _pour(opener, *args, flags=0, **kwargs)
python
def memory_pour(buffer_, *args, **kwargs): """Yield data from entries.""" def opener(archive_res): _LOGGER.debug("Opening from (%d) bytes (memory_pour).", len(buffer_)) _archive_read_open_memory(archive_res, buffer_) return _pour(opener, *args, flags=0, **kwargs)
[ "def", "memory_pour", "(", "buffer_", ",", "*", "args", ",", "**", "kwargs", ")", ":", "def", "opener", "(", "archive_res", ")", ":", "_LOGGER", ".", "debug", "(", "\"Opening from (%d) bytes (memory_pour).\"", ",", "len", "(", "buffer_", ")", ")", "_archive_...
Yield data from entries.
[ "Yield", "data", "from", "entries", "." ]
50414b9fa9a1055435499b5b2e4b2a336a40dff6
https://github.com/dsoprea/PyEasyArchive/blob/50414b9fa9a1055435499b5b2e4b2a336a40dff6/libarchive/adapters/archive_read.py#L408-L415
train
dsoprea/PyEasyArchive
libarchive/adapters/archive_write.py
_archive_write_data
def _archive_write_data(archive, data): """Write data to archive. This will only be called with a non-empty string. """ n = libarchive.calls.archive_write.c_archive_write_data( archive, ctypes.cast(ctypes.c_char_p(data), ctypes.c_void_p), len(data)) if n == 0: ...
python
def _archive_write_data(archive, data): """Write data to archive. This will only be called with a non-empty string. """ n = libarchive.calls.archive_write.c_archive_write_data( archive, ctypes.cast(ctypes.c_char_p(data), ctypes.c_void_p), len(data)) if n == 0: ...
[ "def", "_archive_write_data", "(", "archive", ",", "data", ")", ":", "n", "=", "libarchive", ".", "calls", ".", "archive_write", ".", "c_archive_write_data", "(", "archive", ",", "ctypes", ".", "cast", "(", "ctypes", ".", "c_char_p", "(", "data", ")", ",",...
Write data to archive. This will only be called with a non-empty string.
[ "Write", "data", "to", "archive", ".", "This", "will", "only", "be", "called", "with", "a", "non", "-", "empty", "string", "." ]
50414b9fa9a1055435499b5b2e4b2a336a40dff6
https://github.com/dsoprea/PyEasyArchive/blob/50414b9fa9a1055435499b5b2e4b2a336a40dff6/libarchive/adapters/archive_write.py#L71-L82
train
adafruit/Adafruit_CircuitPython_BME280
adafruit_bme280.py
Adafruit_BME280._write_ctrl_meas
def _write_ctrl_meas(self): """ Write the values to the ctrl_meas and ctrl_hum registers in the device ctrl_meas sets the pressure and temperature data acquistion options ctrl_hum sets the humidty oversampling and must be written to first """ self._write_register_byte(_BM...
python
def _write_ctrl_meas(self): """ Write the values to the ctrl_meas and ctrl_hum registers in the device ctrl_meas sets the pressure and temperature data acquistion options ctrl_hum sets the humidty oversampling and must be written to first """ self._write_register_byte(_BM...
[ "def", "_write_ctrl_meas", "(", "self", ")", ":", "self", ".", "_write_register_byte", "(", "_BME280_REGISTER_CTRL_HUM", ",", "self", ".", "overscan_humidity", ")", "self", ".", "_write_register_byte", "(", "_BME280_REGISTER_CTRL_MEAS", ",", "self", ".", "_ctrl_meas",...
Write the values to the ctrl_meas and ctrl_hum registers in the device ctrl_meas sets the pressure and temperature data acquistion options ctrl_hum sets the humidty oversampling and must be written to first
[ "Write", "the", "values", "to", "the", "ctrl_meas", "and", "ctrl_hum", "registers", "in", "the", "device", "ctrl_meas", "sets", "the", "pressure", "and", "temperature", "data", "acquistion", "options", "ctrl_hum", "sets", "the", "humidty", "oversampling", "and", ...
febcd51983dc2bc3cd006bacaada505251c39af1
https://github.com/adafruit/Adafruit_CircuitPython_BME280/blob/febcd51983dc2bc3cd006bacaada505251c39af1/adafruit_bme280.py#L161-L168
train
adafruit/Adafruit_CircuitPython_BME280
adafruit_bme280.py
Adafruit_BME280._write_config
def _write_config(self): """Write the value to the config register in the device """ normal_flag = False if self._mode == MODE_NORMAL: #Writes to the config register may be ignored while in Normal mode normal_flag = True self.mode = MODE_SLEEP #So we switch to...
python
def _write_config(self): """Write the value to the config register in the device """ normal_flag = False if self._mode == MODE_NORMAL: #Writes to the config register may be ignored while in Normal mode normal_flag = True self.mode = MODE_SLEEP #So we switch to...
[ "def", "_write_config", "(", "self", ")", ":", "normal_flag", "=", "False", "if", "self", ".", "_mode", "==", "MODE_NORMAL", ":", "normal_flag", "=", "True", "self", ".", "mode", "=", "MODE_SLEEP", "self", ".", "_write_register_byte", "(", "_BME280_REGISTER_CO...
Write the value to the config register in the device
[ "Write", "the", "value", "to", "the", "config", "register", "in", "the", "device" ]
febcd51983dc2bc3cd006bacaada505251c39af1
https://github.com/adafruit/Adafruit_CircuitPython_BME280/blob/febcd51983dc2bc3cd006bacaada505251c39af1/adafruit_bme280.py#L178-L187
train
adafruit/Adafruit_CircuitPython_BME280
adafruit_bme280.py
Adafruit_BME280._config
def _config(self): """Value to be written to the device's config register """ config = 0 if self.mode == MODE_NORMAL: config += (self._t_standby << 5) if self._iir_filter: config += (self._iir_filter << 2) return config
python
def _config(self): """Value to be written to the device's config register """ config = 0 if self.mode == MODE_NORMAL: config += (self._t_standby << 5) if self._iir_filter: config += (self._iir_filter << 2) return config
[ "def", "_config", "(", "self", ")", ":", "config", "=", "0", "if", "self", ".", "mode", "==", "MODE_NORMAL", ":", "config", "+=", "(", "self", ".", "_t_standby", "<<", "5", ")", "if", "self", ".", "_iir_filter", ":", "config", "+=", "(", "self", "....
Value to be written to the device's config register
[ "Value", "to", "be", "written", "to", "the", "device", "s", "config", "register" ]
febcd51983dc2bc3cd006bacaada505251c39af1
https://github.com/adafruit/Adafruit_CircuitPython_BME280/blob/febcd51983dc2bc3cd006bacaada505251c39af1/adafruit_bme280.py#L282-L289
train
adafruit/Adafruit_CircuitPython_BME280
adafruit_bme280.py
Adafruit_BME280._ctrl_meas
def _ctrl_meas(self): """Value to be written to the device's ctrl_meas register """ ctrl_meas = (self.overscan_temperature << 5) ctrl_meas += (self.overscan_pressure << 2) ctrl_meas += self.mode return ctrl_meas
python
def _ctrl_meas(self): """Value to be written to the device's ctrl_meas register """ ctrl_meas = (self.overscan_temperature << 5) ctrl_meas += (self.overscan_pressure << 2) ctrl_meas += self.mode return ctrl_meas
[ "def", "_ctrl_meas", "(", "self", ")", ":", "ctrl_meas", "=", "(", "self", ".", "overscan_temperature", "<<", "5", ")", "ctrl_meas", "+=", "(", "self", ".", "overscan_pressure", "<<", "2", ")", "ctrl_meas", "+=", "self", ".", "mode", "return", "ctrl_meas" ...
Value to be written to the device's ctrl_meas register
[ "Value", "to", "be", "written", "to", "the", "device", "s", "ctrl_meas", "register" ]
febcd51983dc2bc3cd006bacaada505251c39af1
https://github.com/adafruit/Adafruit_CircuitPython_BME280/blob/febcd51983dc2bc3cd006bacaada505251c39af1/adafruit_bme280.py#L292-L297
train
adafruit/Adafruit_CircuitPython_BME280
adafruit_bme280.py
Adafruit_BME280.measurement_time_typical
def measurement_time_typical(self): """Typical time in milliseconds required to complete a measurement in normal mode""" meas_time_ms = 1.0 if self.overscan_temperature != OVERSCAN_DISABLE: meas_time_ms += (2 * _BME280_OVERSCANS.get(self.overscan_temperature)) if self.oversca...
python
def measurement_time_typical(self): """Typical time in milliseconds required to complete a measurement in normal mode""" meas_time_ms = 1.0 if self.overscan_temperature != OVERSCAN_DISABLE: meas_time_ms += (2 * _BME280_OVERSCANS.get(self.overscan_temperature)) if self.oversca...
[ "def", "measurement_time_typical", "(", "self", ")", ":", "meas_time_ms", "=", "1.0", "if", "self", ".", "overscan_temperature", "!=", "OVERSCAN_DISABLE", ":", "meas_time_ms", "+=", "(", "2", "*", "_BME280_OVERSCANS", ".", "get", "(", "self", ".", "overscan_temp...
Typical time in milliseconds required to complete a measurement in normal mode
[ "Typical", "time", "in", "milliseconds", "required", "to", "complete", "a", "measurement", "in", "normal", "mode" ]
febcd51983dc2bc3cd006bacaada505251c39af1
https://github.com/adafruit/Adafruit_CircuitPython_BME280/blob/febcd51983dc2bc3cd006bacaada505251c39af1/adafruit_bme280.py#L300-L309
train
adafruit/Adafruit_CircuitPython_BME280
adafruit_bme280.py
Adafruit_BME280.pressure
def pressure(self): """ The compensated pressure in hectoPascals. returns None if pressure measurement is disabled """ self._read_temperature() # Algorithm from the BME280 driver # https://github.com/BoschSensortec/BME280_driver/blob/master/bme280.c adc =...
python
def pressure(self): """ The compensated pressure in hectoPascals. returns None if pressure measurement is disabled """ self._read_temperature() # Algorithm from the BME280 driver # https://github.com/BoschSensortec/BME280_driver/blob/master/bme280.c adc =...
[ "def", "pressure", "(", "self", ")", ":", "self", ".", "_read_temperature", "(", ")", "adc", "=", "self", ".", "_read24", "(", "_BME280_REGISTER_PRESSUREDATA", ")", "/", "16", "var1", "=", "float", "(", "self", ".", "_t_fine", ")", "/", "2.0", "-", "64...
The compensated pressure in hectoPascals. returns None if pressure measurement is disabled
[ "The", "compensated", "pressure", "in", "hectoPascals", ".", "returns", "None", "if", "pressure", "measurement", "is", "disabled" ]
febcd51983dc2bc3cd006bacaada505251c39af1
https://github.com/adafruit/Adafruit_CircuitPython_BME280/blob/febcd51983dc2bc3cd006bacaada505251c39af1/adafruit_bme280.py#L330-L363
train
adafruit/Adafruit_CircuitPython_BME280
adafruit_bme280.py
Adafruit_BME280.humidity
def humidity(self): """ The relative humidity in RH % returns None if humidity measurement is disabled """ self._read_temperature() hum = self._read_register(_BME280_REGISTER_HUMIDDATA, 2) #print("Humidity data: ", hum) adc = float(hum[0] << 8 | hum[1]) ...
python
def humidity(self): """ The relative humidity in RH % returns None if humidity measurement is disabled """ self._read_temperature() hum = self._read_register(_BME280_REGISTER_HUMIDDATA, 2) #print("Humidity data: ", hum) adc = float(hum[0] << 8 | hum[1]) ...
[ "def", "humidity", "(", "self", ")", ":", "self", ".", "_read_temperature", "(", ")", "hum", "=", "self", ".", "_read_register", "(", "_BME280_REGISTER_HUMIDDATA", ",", "2", ")", "adc", "=", "float", "(", "hum", "[", "0", "]", "<<", "8", "|", "hum", ...
The relative humidity in RH % returns None if humidity measurement is disabled
[ "The", "relative", "humidity", "in", "RH", "%", "returns", "None", "if", "humidity", "measurement", "is", "disabled" ]
febcd51983dc2bc3cd006bacaada505251c39af1
https://github.com/adafruit/Adafruit_CircuitPython_BME280/blob/febcd51983dc2bc3cd006bacaada505251c39af1/adafruit_bme280.py#L366-L399
train
adafruit/Adafruit_CircuitPython_BME280
adafruit_bme280.py
Adafruit_BME280._read_coefficients
def _read_coefficients(self): """Read & save the calibration coefficients""" coeff = self._read_register(_BME280_REGISTER_DIG_T1, 24) coeff = list(struct.unpack('<HhhHhhhhhhhh', bytes(coeff))) coeff = [float(i) for i in coeff] self._temp_calib = coeff[:3] self._pressure_c...
python
def _read_coefficients(self): """Read & save the calibration coefficients""" coeff = self._read_register(_BME280_REGISTER_DIG_T1, 24) coeff = list(struct.unpack('<HhhHhhhhhhhh', bytes(coeff))) coeff = [float(i) for i in coeff] self._temp_calib = coeff[:3] self._pressure_c...
[ "def", "_read_coefficients", "(", "self", ")", ":", "coeff", "=", "self", ".", "_read_register", "(", "_BME280_REGISTER_DIG_T1", ",", "24", ")", "coeff", "=", "list", "(", "struct", ".", "unpack", "(", "'<HhhHhhhhhhhh'", ",", "bytes", "(", "coeff", ")", ")...
Read & save the calibration coefficients
[ "Read", "&", "save", "the", "calibration", "coefficients" ]
febcd51983dc2bc3cd006bacaada505251c39af1
https://github.com/adafruit/Adafruit_CircuitPython_BME280/blob/febcd51983dc2bc3cd006bacaada505251c39af1/adafruit_bme280.py#L408-L424
train
adafruit/Adafruit_CircuitPython_BME280
adafruit_bme280.py
Adafruit_BME280._read24
def _read24(self, register): """Read an unsigned 24-bit value as a floating point and return it.""" ret = 0.0 for b in self._read_register(register, 3): ret *= 256.0 ret += float(b & 0xFF) return ret
python
def _read24(self, register): """Read an unsigned 24-bit value as a floating point and return it.""" ret = 0.0 for b in self._read_register(register, 3): ret *= 256.0 ret += float(b & 0xFF) return ret
[ "def", "_read24", "(", "self", ",", "register", ")", ":", "ret", "=", "0.0", "for", "b", "in", "self", ".", "_read_register", "(", "register", ",", "3", ")", ":", "ret", "*=", "256.0", "ret", "+=", "float", "(", "b", "&", "0xFF", ")", "return", "...
Read an unsigned 24-bit value as a floating point and return it.
[ "Read", "an", "unsigned", "24", "-", "bit", "value", "as", "a", "floating", "point", "and", "return", "it", "." ]
febcd51983dc2bc3cd006bacaada505251c39af1
https://github.com/adafruit/Adafruit_CircuitPython_BME280/blob/febcd51983dc2bc3cd006bacaada505251c39af1/adafruit_bme280.py#L430-L436
train
ArangoDB-Community/pyArango
pyArango/index.py
Index._create
def _create(self, postData) : """Creates an index of any type according to postData""" if self.infos is None : r = self.connection.session.post(self.indexesURL, params = {"collection" : self.collection.name}, data = json.dumps(postData, default=str)) data = r.json() i...
python
def _create(self, postData) : """Creates an index of any type according to postData""" if self.infos is None : r = self.connection.session.post(self.indexesURL, params = {"collection" : self.collection.name}, data = json.dumps(postData, default=str)) data = r.json() i...
[ "def", "_create", "(", "self", ",", "postData", ")", ":", "if", "self", ".", "infos", "is", "None", ":", "r", "=", "self", ".", "connection", ".", "session", ".", "post", "(", "self", ".", "indexesURL", ",", "params", "=", "{", "\"collection\"", ":",...
Creates an index of any type according to postData
[ "Creates", "an", "index", "of", "any", "type", "according", "to", "postData" ]
dd72e5f6c540e5e148943d615ddf7553bb78ce0b
https://github.com/ArangoDB-Community/pyArango/blob/dd72e5f6c540e5e148943d615ddf7553bb78ce0b/pyArango/index.py#L22-L29
train
ArangoDB-Community/pyArango
pyArango/graph.py
Graph.createVertex
def createVertex(self, collectionName, docAttributes, waitForSync = False) : """adds a vertex to the graph and returns it""" url = "%s/vertex/%s" % (self.URL, collectionName) store = DOC.DocumentStore(self.database[collectionName], validators=self.database[collectionName]._fields, initDct=docAt...
python
def createVertex(self, collectionName, docAttributes, waitForSync = False) : """adds a vertex to the graph and returns it""" url = "%s/vertex/%s" % (self.URL, collectionName) store = DOC.DocumentStore(self.database[collectionName], validators=self.database[collectionName]._fields, initDct=docAt...
[ "def", "createVertex", "(", "self", ",", "collectionName", ",", "docAttributes", ",", "waitForSync", "=", "False", ")", ":", "url", "=", "\"%s/vertex/%s\"", "%", "(", "self", ".", "URL", ",", "collectionName", ")", "store", "=", "DOC", ".", "DocumentStore", ...
adds a vertex to the graph and returns it
[ "adds", "a", "vertex", "to", "the", "graph", "and", "returns", "it" ]
dd72e5f6c540e5e148943d615ddf7553bb78ce0b
https://github.com/ArangoDB-Community/pyArango/blob/dd72e5f6c540e5e148943d615ddf7553bb78ce0b/pyArango/graph.py#L115-L129
train
ArangoDB-Community/pyArango
pyArango/graph.py
Graph.deleteVertex
def deleteVertex(self, document, waitForSync = False) : """deletes a vertex from the graph as well as al linked edges""" url = "%s/vertex/%s" % (self.URL, document._id) r = self.connection.session.delete(url, params = {'waitForSync' : waitForSync}) data = r.json() if r.status_co...
python
def deleteVertex(self, document, waitForSync = False) : """deletes a vertex from the graph as well as al linked edges""" url = "%s/vertex/%s" % (self.URL, document._id) r = self.connection.session.delete(url, params = {'waitForSync' : waitForSync}) data = r.json() if r.status_co...
[ "def", "deleteVertex", "(", "self", ",", "document", ",", "waitForSync", "=", "False", ")", ":", "url", "=", "\"%s/vertex/%s\"", "%", "(", "self", ".", "URL", ",", "document", ".", "_id", ")", "r", "=", "self", ".", "connection", ".", "session", ".", ...
deletes a vertex from the graph as well as al linked edges
[ "deletes", "a", "vertex", "from", "the", "graph", "as", "well", "as", "al", "linked", "edges" ]
dd72e5f6c540e5e148943d615ddf7553bb78ce0b
https://github.com/ArangoDB-Community/pyArango/blob/dd72e5f6c540e5e148943d615ddf7553bb78ce0b/pyArango/graph.py#L131-L140
train
ArangoDB-Community/pyArango
pyArango/graph.py
Graph.createEdge
def createEdge(self, collectionName, _fromId, _toId, edgeAttributes, waitForSync = False) : """creates an edge between two documents""" if not _fromId : raise ValueError("Invalid _fromId: %s" % _fromId) if not _toId : raise ValueError("Invalid _toId: %s" % _toId) ...
python
def createEdge(self, collectionName, _fromId, _toId, edgeAttributes, waitForSync = False) : """creates an edge between two documents""" if not _fromId : raise ValueError("Invalid _fromId: %s" % _fromId) if not _toId : raise ValueError("Invalid _toId: %s" % _toId) ...
[ "def", "createEdge", "(", "self", ",", "collectionName", ",", "_fromId", ",", "_toId", ",", "edgeAttributes", ",", "waitForSync", "=", "False", ")", ":", "if", "not", "_fromId", ":", "raise", "ValueError", "(", "\"Invalid _fromId: %s\"", "%", "_fromId", ")", ...
creates an edge between two documents
[ "creates", "an", "edge", "between", "two", "documents" ]
dd72e5f6c540e5e148943d615ddf7553bb78ce0b
https://github.com/ArangoDB-Community/pyArango/blob/dd72e5f6c540e5e148943d615ddf7553bb78ce0b/pyArango/graph.py#L142-L170
train
ArangoDB-Community/pyArango
pyArango/graph.py
Graph.link
def link(self, definition, doc1, doc2, edgeAttributes, waitForSync = False) : "A shorthand for createEdge that takes two documents as input" if type(doc1) is DOC.Document : if not doc1._id : doc1.save() doc1_id = doc1._id else : doc1_id = doc1 ...
python
def link(self, definition, doc1, doc2, edgeAttributes, waitForSync = False) : "A shorthand for createEdge that takes two documents as input" if type(doc1) is DOC.Document : if not doc1._id : doc1.save() doc1_id = doc1._id else : doc1_id = doc1 ...
[ "def", "link", "(", "self", ",", "definition", ",", "doc1", ",", "doc2", ",", "edgeAttributes", ",", "waitForSync", "=", "False", ")", ":", "\"A shorthand for createEdge that takes two documents as input\"", "if", "type", "(", "doc1", ")", "is", "DOC", ".", "Doc...
A shorthand for createEdge that takes two documents as input
[ "A", "shorthand", "for", "createEdge", "that", "takes", "two", "documents", "as", "input" ]
dd72e5f6c540e5e148943d615ddf7553bb78ce0b
https://github.com/ArangoDB-Community/pyArango/blob/dd72e5f6c540e5e148943d615ddf7553bb78ce0b/pyArango/graph.py#L172-L188
train
ArangoDB-Community/pyArango
pyArango/graph.py
Graph.unlink
def unlink(self, definition, doc1, doc2) : "deletes all links between doc1 and doc2" links = self.database[definition].fetchByExample( {"_from": doc1._id,"_to" : doc2._id}, batchSize = 100) for l in links : self.deleteEdge(l)
python
def unlink(self, definition, doc1, doc2) : "deletes all links between doc1 and doc2" links = self.database[definition].fetchByExample( {"_from": doc1._id,"_to" : doc2._id}, batchSize = 100) for l in links : self.deleteEdge(l)
[ "def", "unlink", "(", "self", ",", "definition", ",", "doc1", ",", "doc2", ")", ":", "\"deletes all links between doc1 and doc2\"", "links", "=", "self", ".", "database", "[", "definition", "]", ".", "fetchByExample", "(", "{", "\"_from\"", ":", "doc1", ".", ...
deletes all links between doc1 and doc2
[ "deletes", "all", "links", "between", "doc1", "and", "doc2" ]
dd72e5f6c540e5e148943d615ddf7553bb78ce0b
https://github.com/ArangoDB-Community/pyArango/blob/dd72e5f6c540e5e148943d615ddf7553bb78ce0b/pyArango/graph.py#L190-L194
train