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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
Yelp/threat_intel | threat_intel/opendns.py | _cached_by_domain | def _cached_by_domain(api_name):
"""A caching wrapper for functions that take a list of domains as
parameters.
Raises:
ResponseError - if the response received from the endpoint is
not valid.
"""
def wrapped(func):
def decorated(self, domains):
if not self._cach... | python | def _cached_by_domain(api_name):
"""A caching wrapper for functions that take a list of domains as
parameters.
Raises:
ResponseError - if the response received from the endpoint is
not valid.
"""
def wrapped(func):
def decorated(self, domains):
if not self._cach... | [
"def",
"_cached_by_domain",
"(",
"api_name",
")",
":",
"def",
"wrapped",
"(",
"func",
")",
":",
"def",
"decorated",
"(",
"self",
",",
"domains",
")",
":",
"if",
"not",
"self",
".",
"_cache",
":",
"return",
"func",
"(",
"self",
",",
"domains",
")",
"a... | A caching wrapper for functions that take a list of domains as
parameters.
Raises:
ResponseError - if the response received from the endpoint is
not valid. | [
"A",
"caching",
"wrapper",
"for",
"functions",
"that",
"take",
"a",
"list",
"of",
"domains",
"as",
"parameters",
"."
] | 60eef841d7cca115ec7857aeb9c553b72b694851 | https://github.com/Yelp/threat_intel/blob/60eef841d7cca115ec7857aeb9c553b72b694851/threat_intel/opendns.py#L16-L45 | train |
Yelp/threat_intel | threat_intel/opendns.py | InvestigateApi.domain_score | def domain_score(self, domains):
"""Calls domain scores endpoint.
This method is deprecated since OpenDNS Investigate API
endpoint is also deprecated.
"""
warn(
'OpenDNS Domain Scores endpoint is deprecated. Use '
'InvestigateApi.categorization() instead'... | python | def domain_score(self, domains):
"""Calls domain scores endpoint.
This method is deprecated since OpenDNS Investigate API
endpoint is also deprecated.
"""
warn(
'OpenDNS Domain Scores endpoint is deprecated. Use '
'InvestigateApi.categorization() instead'... | [
"def",
"domain_score",
"(",
"self",
",",
"domains",
")",
":",
"warn",
"(",
"'OpenDNS Domain Scores endpoint is deprecated. Use '",
"'InvestigateApi.categorization() instead'",
",",
"DeprecationWarning",
",",
")",
"url_path",
"=",
"'domains/score/'",
"return",
"self",
".",
... | Calls domain scores endpoint.
This method is deprecated since OpenDNS Investigate API
endpoint is also deprecated. | [
"Calls",
"domain",
"scores",
"endpoint",
"."
] | 60eef841d7cca115ec7857aeb9c553b72b694851 | https://github.com/Yelp/threat_intel/blob/60eef841d7cca115ec7857aeb9c553b72b694851/threat_intel/opendns.py#L115-L126 | train |
Yelp/threat_intel | threat_intel/opendns.py | InvestigateApi._multi_get | def _multi_get(self, cache_api_name, fmt_url_path, url_params, query_params=None):
"""Makes multiple GETs to an OpenDNS endpoint.
Args:
cache_api_name: string api_name for caching
fmt_url_path: format string for building URL paths
url_params: An enumerable of strings... | python | def _multi_get(self, cache_api_name, fmt_url_path, url_params, query_params=None):
"""Makes multiple GETs to an OpenDNS endpoint.
Args:
cache_api_name: string api_name for caching
fmt_url_path: format string for building URL paths
url_params: An enumerable of strings... | [
"def",
"_multi_get",
"(",
"self",
",",
"cache_api_name",
",",
"fmt_url_path",
",",
"url_params",
",",
"query_params",
"=",
"None",
")",
":",
"all_responses",
"=",
"{",
"}",
"if",
"self",
".",
"_cache",
":",
"all_responses",
"=",
"self",
".",
"_cache",
".",... | Makes multiple GETs to an OpenDNS endpoint.
Args:
cache_api_name: string api_name for caching
fmt_url_path: format string for building URL paths
url_params: An enumerable of strings used in building URLs
query_params - None / dict / list of dicts containing query... | [
"Makes",
"multiple",
"GETs",
"to",
"an",
"OpenDNS",
"endpoint",
"."
] | 60eef841d7cca115ec7857aeb9c553b72b694851 | https://github.com/Yelp/threat_intel/blob/60eef841d7cca115ec7857aeb9c553b72b694851/threat_intel/opendns.py#L129-L154 | train |
Yelp/threat_intel | threat_intel/opendns.py | InvestigateApi.security | def security(self, domains):
"""Calls security end point and adds an 'is_suspicious' key to each response.
Args:
domains: An enumerable of strings
Returns:
A dict of {domain: security_result}
"""
api_name = 'opendns-security'
fmt_url_path = u'secu... | python | def security(self, domains):
"""Calls security end point and adds an 'is_suspicious' key to each response.
Args:
domains: An enumerable of strings
Returns:
A dict of {domain: security_result}
"""
api_name = 'opendns-security'
fmt_url_path = u'secu... | [
"def",
"security",
"(",
"self",
",",
"domains",
")",
":",
"api_name",
"=",
"'opendns-security'",
"fmt_url_path",
"=",
"u'security/name/{0}.json'",
"return",
"self",
".",
"_multi_get",
"(",
"api_name",
",",
"fmt_url_path",
",",
"domains",
")"
] | Calls security end point and adds an 'is_suspicious' key to each response.
Args:
domains: An enumerable of strings
Returns:
A dict of {domain: security_result} | [
"Calls",
"security",
"end",
"point",
"and",
"adds",
"an",
"is_suspicious",
"key",
"to",
"each",
"response",
"."
] | 60eef841d7cca115ec7857aeb9c553b72b694851 | https://github.com/Yelp/threat_intel/blob/60eef841d7cca115ec7857aeb9c553b72b694851/threat_intel/opendns.py#L156-L166 | train |
Yelp/threat_intel | threat_intel/opendns.py | InvestigateApi.whois_emails | def whois_emails(self, emails):
"""Calls WHOIS Email end point
Args:
emails: An enumerable of string Emails
Returns:
A dict of {email: domain_result}
"""
api_name = 'opendns-whois-emails'
fmt_url_path = u'whois/emails/{0}'
return self._mul... | python | def whois_emails(self, emails):
"""Calls WHOIS Email end point
Args:
emails: An enumerable of string Emails
Returns:
A dict of {email: domain_result}
"""
api_name = 'opendns-whois-emails'
fmt_url_path = u'whois/emails/{0}'
return self._mul... | [
"def",
"whois_emails",
"(",
"self",
",",
"emails",
")",
":",
"api_name",
"=",
"'opendns-whois-emails'",
"fmt_url_path",
"=",
"u'whois/emails/{0}'",
"return",
"self",
".",
"_multi_get",
"(",
"api_name",
",",
"fmt_url_path",
",",
"emails",
")"
] | Calls WHOIS Email end point
Args:
emails: An enumerable of string Emails
Returns:
A dict of {email: domain_result} | [
"Calls",
"WHOIS",
"Email",
"end",
"point"
] | 60eef841d7cca115ec7857aeb9c553b72b694851 | https://github.com/Yelp/threat_intel/blob/60eef841d7cca115ec7857aeb9c553b72b694851/threat_intel/opendns.py#L168-L178 | train |
Yelp/threat_intel | threat_intel/opendns.py | InvestigateApi.whois_nameservers | def whois_nameservers(self, nameservers):
"""Calls WHOIS Nameserver end point
Args:
emails: An enumerable of nameservers
Returns:
A dict of {nameserver: domain_result}
"""
api_name = 'opendns-whois-nameservers'
fmt_url_path = u'whois/nameservers/{... | python | def whois_nameservers(self, nameservers):
"""Calls WHOIS Nameserver end point
Args:
emails: An enumerable of nameservers
Returns:
A dict of {nameserver: domain_result}
"""
api_name = 'opendns-whois-nameservers'
fmt_url_path = u'whois/nameservers/{... | [
"def",
"whois_nameservers",
"(",
"self",
",",
"nameservers",
")",
":",
"api_name",
"=",
"'opendns-whois-nameservers'",
"fmt_url_path",
"=",
"u'whois/nameservers/{0}'",
"return",
"self",
".",
"_multi_get",
"(",
"api_name",
",",
"fmt_url_path",
",",
"nameservers",
")"
] | Calls WHOIS Nameserver end point
Args:
emails: An enumerable of nameservers
Returns:
A dict of {nameserver: domain_result} | [
"Calls",
"WHOIS",
"Nameserver",
"end",
"point"
] | 60eef841d7cca115ec7857aeb9c553b72b694851 | https://github.com/Yelp/threat_intel/blob/60eef841d7cca115ec7857aeb9c553b72b694851/threat_intel/opendns.py#L180-L190 | train |
Yelp/threat_intel | threat_intel/opendns.py | InvestigateApi.whois_domains | def whois_domains(self, domains):
"""Calls WHOIS domain end point
Args:
domains: An enumerable of domains
Returns:
A dict of {domain: domain_result}
"""
api_name = 'opendns-whois-domain'
fmt_url_path = u'whois/{0}'
return self._multi_get(a... | python | def whois_domains(self, domains):
"""Calls WHOIS domain end point
Args:
domains: An enumerable of domains
Returns:
A dict of {domain: domain_result}
"""
api_name = 'opendns-whois-domain'
fmt_url_path = u'whois/{0}'
return self._multi_get(a... | [
"def",
"whois_domains",
"(",
"self",
",",
"domains",
")",
":",
"api_name",
"=",
"'opendns-whois-domain'",
"fmt_url_path",
"=",
"u'whois/{0}'",
"return",
"self",
".",
"_multi_get",
"(",
"api_name",
",",
"fmt_url_path",
",",
"domains",
")"
] | Calls WHOIS domain end point
Args:
domains: An enumerable of domains
Returns:
A dict of {domain: domain_result} | [
"Calls",
"WHOIS",
"domain",
"end",
"point"
] | 60eef841d7cca115ec7857aeb9c553b72b694851 | https://github.com/Yelp/threat_intel/blob/60eef841d7cca115ec7857aeb9c553b72b694851/threat_intel/opendns.py#L192-L202 | train |
Yelp/threat_intel | threat_intel/opendns.py | InvestigateApi.whois_domains_history | def whois_domains_history(self, domains):
"""Calls WHOIS domain history end point
Args:
domains: An enumerable of domains
Returns:
A dict of {domain: domain_history_result}
"""
api_name = 'opendns-whois-domain-history'
fmt_url_path = u'whois/{0}/h... | python | def whois_domains_history(self, domains):
"""Calls WHOIS domain history end point
Args:
domains: An enumerable of domains
Returns:
A dict of {domain: domain_history_result}
"""
api_name = 'opendns-whois-domain-history'
fmt_url_path = u'whois/{0}/h... | [
"def",
"whois_domains_history",
"(",
"self",
",",
"domains",
")",
":",
"api_name",
"=",
"'opendns-whois-domain-history'",
"fmt_url_path",
"=",
"u'whois/{0}/history'",
"return",
"self",
".",
"_multi_get",
"(",
"api_name",
",",
"fmt_url_path",
",",
"domains",
")"
] | Calls WHOIS domain history end point
Args:
domains: An enumerable of domains
Returns:
A dict of {domain: domain_history_result} | [
"Calls",
"WHOIS",
"domain",
"history",
"end",
"point"
] | 60eef841d7cca115ec7857aeb9c553b72b694851 | https://github.com/Yelp/threat_intel/blob/60eef841d7cca115ec7857aeb9c553b72b694851/threat_intel/opendns.py#L204-L214 | train |
Yelp/threat_intel | threat_intel/opendns.py | InvestigateApi.domain_tag | def domain_tag(self, domains):
"""Get the data range when a domain is part of OpenDNS block list.
Args:
domains: an enumerable of strings domain names
Returns:
An enumerable of string with period, category, and url
"""
api_name = 'opendns-domain_tag'
... | python | def domain_tag(self, domains):
"""Get the data range when a domain is part of OpenDNS block list.
Args:
domains: an enumerable of strings domain names
Returns:
An enumerable of string with period, category, and url
"""
api_name = 'opendns-domain_tag'
... | [
"def",
"domain_tag",
"(",
"self",
",",
"domains",
")",
":",
"api_name",
"=",
"'opendns-domain_tag'",
"fmt_url_path",
"=",
"u'domains/{0}/latest_tags'",
"return",
"self",
".",
"_multi_get",
"(",
"api_name",
",",
"fmt_url_path",
",",
"domains",
")"
] | Get the data range when a domain is part of OpenDNS block list.
Args:
domains: an enumerable of strings domain names
Returns:
An enumerable of string with period, category, and url | [
"Get",
"the",
"data",
"range",
"when",
"a",
"domain",
"is",
"part",
"of",
"OpenDNS",
"block",
"list",
"."
] | 60eef841d7cca115ec7857aeb9c553b72b694851 | https://github.com/Yelp/threat_intel/blob/60eef841d7cca115ec7857aeb9c553b72b694851/threat_intel/opendns.py#L228-L238 | train |
Yelp/threat_intel | threat_intel/opendns.py | InvestigateApi.rr_history | def rr_history(self, ips):
"""Get the domains related to input ips.
Args:
ips: an enumerable of strings as ips
Returns:
An enumerable of resource records and features
"""
api_name = 'opendns-rr_history'
fmt_url_path = u'dnsdb/ip/a/{0}.json'
... | python | def rr_history(self, ips):
"""Get the domains related to input ips.
Args:
ips: an enumerable of strings as ips
Returns:
An enumerable of resource records and features
"""
api_name = 'opendns-rr_history'
fmt_url_path = u'dnsdb/ip/a/{0}.json'
... | [
"def",
"rr_history",
"(",
"self",
",",
"ips",
")",
":",
"api_name",
"=",
"'opendns-rr_history'",
"fmt_url_path",
"=",
"u'dnsdb/ip/a/{0}.json'",
"return",
"self",
".",
"_multi_get",
"(",
"api_name",
",",
"fmt_url_path",
",",
"ips",
")"
] | Get the domains related to input ips.
Args:
ips: an enumerable of strings as ips
Returns:
An enumerable of resource records and features | [
"Get",
"the",
"domains",
"related",
"to",
"input",
"ips",
"."
] | 60eef841d7cca115ec7857aeb9c553b72b694851 | https://github.com/Yelp/threat_intel/blob/60eef841d7cca115ec7857aeb9c553b72b694851/threat_intel/opendns.py#L253-L263 | train |
Yelp/threat_intel | threat_intel/opendns.py | InvestigateApi.sample | def sample(self, hashes):
"""Get the information about a sample based on its hash.
Args:
hashes: an enumerable of strings as hashes
Returns:
An enumerable of arrays which contains the information
about the original samples
"""
api_name = 'open... | python | def sample(self, hashes):
"""Get the information about a sample based on its hash.
Args:
hashes: an enumerable of strings as hashes
Returns:
An enumerable of arrays which contains the information
about the original samples
"""
api_name = 'open... | [
"def",
"sample",
"(",
"self",
",",
"hashes",
")",
":",
"api_name",
"=",
"'opendns-sample'",
"fmt_url_path",
"=",
"u'sample/{0}'",
"return",
"self",
".",
"_multi_get",
"(",
"api_name",
",",
"fmt_url_path",
",",
"hashes",
")"
] | Get the information about a sample based on its hash.
Args:
hashes: an enumerable of strings as hashes
Returns:
An enumerable of arrays which contains the information
about the original samples | [
"Get",
"the",
"information",
"about",
"a",
"sample",
"based",
"on",
"its",
"hash",
"."
] | 60eef841d7cca115ec7857aeb9c553b72b694851 | https://github.com/Yelp/threat_intel/blob/60eef841d7cca115ec7857aeb9c553b72b694851/threat_intel/opendns.py#L289-L300 | train |
Yelp/threat_intel | threat_intel/opendns.py | InvestigateApi.search | def search(self, patterns, start=30, limit=1000, include_category=False):
"""Performs pattern searches against the Investigate database.
Args:
patterns: An enumerable of RegEx domain patterns to search for
start: How far back results extend from in days (max is 30)
... | python | def search(self, patterns, start=30, limit=1000, include_category=False):
"""Performs pattern searches against the Investigate database.
Args:
patterns: An enumerable of RegEx domain patterns to search for
start: How far back results extend from in days (max is 30)
... | [
"def",
"search",
"(",
"self",
",",
"patterns",
",",
"start",
"=",
"30",
",",
"limit",
"=",
"1000",
",",
"include_category",
"=",
"False",
")",
":",
"api_name",
"=",
"'opendns-patterns'",
"fmt_url_path",
"=",
"u'search/{0}'",
"start",
"=",
"'-{0}days'",
".",
... | Performs pattern searches against the Investigate database.
Args:
patterns: An enumerable of RegEx domain patterns to search for
start: How far back results extend from in days (max is 30)
limit: Number of results to show (max is 1000)
include_category: Inclu... | [
"Performs",
"pattern",
"searches",
"against",
"the",
"Investigate",
"database",
"."
] | 60eef841d7cca115ec7857aeb9c553b72b694851 | https://github.com/Yelp/threat_intel/blob/60eef841d7cca115ec7857aeb9c553b72b694851/threat_intel/opendns.py#L302-L322 | train |
Yelp/threat_intel | threat_intel/opendns.py | InvestigateApi.risk_score | def risk_score(self, domains):
"""Performs Umbrella risk score analysis on the input domains
Args:
domains: an enumerable of domains
Returns:
An enumerable of associated domain risk scores
"""
api_name = 'opendns-risk_score'
fmt_url_path = u'domai... | python | def risk_score(self, domains):
"""Performs Umbrella risk score analysis on the input domains
Args:
domains: an enumerable of domains
Returns:
An enumerable of associated domain risk scores
"""
api_name = 'opendns-risk_score'
fmt_url_path = u'domai... | [
"def",
"risk_score",
"(",
"self",
",",
"domains",
")",
":",
"api_name",
"=",
"'opendns-risk_score'",
"fmt_url_path",
"=",
"u'domains/risk-score/{0}'",
"return",
"self",
".",
"_multi_get",
"(",
"api_name",
",",
"fmt_url_path",
",",
"domains",
")"
] | Performs Umbrella risk score analysis on the input domains
Args:
domains: an enumerable of domains
Returns:
An enumerable of associated domain risk scores | [
"Performs",
"Umbrella",
"risk",
"score",
"analysis",
"on",
"the",
"input",
"domains"
] | 60eef841d7cca115ec7857aeb9c553b72b694851 | https://github.com/Yelp/threat_intel/blob/60eef841d7cca115ec7857aeb9c553b72b694851/threat_intel/opendns.py#L324-L334 | train |
Yelp/threat_intel | threat_intel/virustotal.py | VirusTotalApi._extract_all_responses | def _extract_all_responses(self, resources, api_endpoint, api_name):
""" Aux function to extract all the API endpoint responses.
Args:
resources: list of string hashes.
api_endpoint: endpoint path
api_name: endpoint name
Returns:
A dict with the h... | python | def _extract_all_responses(self, resources, api_endpoint, api_name):
""" Aux function to extract all the API endpoint responses.
Args:
resources: list of string hashes.
api_endpoint: endpoint path
api_name: endpoint name
Returns:
A dict with the h... | [
"def",
"_extract_all_responses",
"(",
"self",
",",
"resources",
",",
"api_endpoint",
",",
"api_name",
")",
":",
"all_responses",
",",
"resources",
"=",
"self",
".",
"_bulk_cache_lookup",
"(",
"api_name",
",",
"resources",
")",
"resource_chunks",
"=",
"self",
"."... | Aux function to extract all the API endpoint responses.
Args:
resources: list of string hashes.
api_endpoint: endpoint path
api_name: endpoint name
Returns:
A dict with the hash as key and the VT report as value. | [
"Aux",
"function",
"to",
"extract",
"all",
"the",
"API",
"endpoint",
"responses",
"."
] | 60eef841d7cca115ec7857aeb9c553b72b694851 | https://github.com/Yelp/threat_intel/blob/60eef841d7cca115ec7857aeb9c553b72b694851/threat_intel/virustotal.py#L52-L67 | train |
Yelp/threat_intel | threat_intel/virustotal.py | VirusTotalApi.get_url_distribution | def get_url_distribution(self, params=None):
"""Retrieves a live feed with the latest URLs submitted to VT.
Args:
resources: a dictionary with name and value for optional arguments
Returns:
A dict with the VT report.
"""
params = params or {}
all_... | python | def get_url_distribution(self, params=None):
"""Retrieves a live feed with the latest URLs submitted to VT.
Args:
resources: a dictionary with name and value for optional arguments
Returns:
A dict with the VT report.
"""
params = params or {}
all_... | [
"def",
"get_url_distribution",
"(",
"self",
",",
"params",
"=",
"None",
")",
":",
"params",
"=",
"params",
"or",
"{",
"}",
"all_responses",
"=",
"{",
"}",
"api_name",
"=",
"'virustotal-url-distribution'",
"response_chunks",
"=",
"self",
".",
"_request_reports",
... | Retrieves a live feed with the latest URLs submitted to VT.
Args:
resources: a dictionary with name and value for optional arguments
Returns:
A dict with the VT report. | [
"Retrieves",
"a",
"live",
"feed",
"with",
"the",
"latest",
"URLs",
"submitted",
"to",
"VT",
"."
] | 60eef841d7cca115ec7857aeb9c553b72b694851 | https://github.com/Yelp/threat_intel/blob/60eef841d7cca115ec7857aeb9c553b72b694851/threat_intel/virustotal.py#L128-L143 | train |
Yelp/threat_intel | threat_intel/virustotal.py | VirusTotalApi.get_url_reports | def get_url_reports(self, resources):
"""Retrieves a scan report on a given URL.
Args:
resources: list of URLs.
Returns:
A dict with the URL as key and the VT report as value.
"""
api_name = 'virustotal-url-reports'
(all_responses, resources) = s... | python | def get_url_reports(self, resources):
"""Retrieves a scan report on a given URL.
Args:
resources: list of URLs.
Returns:
A dict with the URL as key and the VT report as value.
"""
api_name = 'virustotal-url-reports'
(all_responses, resources) = s... | [
"def",
"get_url_reports",
"(",
"self",
",",
"resources",
")",
":",
"api_name",
"=",
"'virustotal-url-reports'",
"(",
"all_responses",
",",
"resources",
")",
"=",
"self",
".",
"_bulk_cache_lookup",
"(",
"api_name",
",",
"resources",
")",
"resource_chunks",
"=",
"... | Retrieves a scan report on a given URL.
Args:
resources: list of URLs.
Returns:
A dict with the URL as key and the VT report as value. | [
"Retrieves",
"a",
"scan",
"report",
"on",
"a",
"given",
"URL",
"."
] | 60eef841d7cca115ec7857aeb9c553b72b694851 | https://github.com/Yelp/threat_intel/blob/60eef841d7cca115ec7857aeb9c553b72b694851/threat_intel/virustotal.py#L167-L182 | train |
Yelp/threat_intel | threat_intel/virustotal.py | VirusTotalApi.get_ip_reports | def get_ip_reports(self, ips):
"""Retrieves the most recent VT info for a set of ips.
Args:
ips: list of IPs.
Returns:
A dict with the IP as key and the VT report as value.
"""
api_name = 'virustotal-ip-address-reports'
(all_responses, ips) = sel... | python | def get_ip_reports(self, ips):
"""Retrieves the most recent VT info for a set of ips.
Args:
ips: list of IPs.
Returns:
A dict with the IP as key and the VT report as value.
"""
api_name = 'virustotal-ip-address-reports'
(all_responses, ips) = sel... | [
"def",
"get_ip_reports",
"(",
"self",
",",
"ips",
")",
":",
"api_name",
"=",
"'virustotal-ip-address-reports'",
"(",
"all_responses",
",",
"ips",
")",
"=",
"self",
".",
"_bulk_cache_lookup",
"(",
"api_name",
",",
"ips",
")",
"responses",
"=",
"self",
".",
"_... | Retrieves the most recent VT info for a set of ips.
Args:
ips: list of IPs.
Returns:
A dict with the IP as key and the VT report as value. | [
"Retrieves",
"the",
"most",
"recent",
"VT",
"info",
"for",
"a",
"set",
"of",
"ips",
"."
] | 60eef841d7cca115ec7857aeb9c553b72b694851 | https://github.com/Yelp/threat_intel/blob/60eef841d7cca115ec7857aeb9c553b72b694851/threat_intel/virustotal.py#L185-L203 | train |
Yelp/threat_intel | threat_intel/virustotal.py | VirusTotalApi.get_file_clusters | def get_file_clusters(self, date):
"""Retrieves file similarity clusters for a given time frame.
Args:
date: the specific date for which we want the clustering details.
Example: 'date': '2013-09-10'
Returns:
A dict with the VT report.
"""
api_... | python | def get_file_clusters(self, date):
"""Retrieves file similarity clusters for a given time frame.
Args:
date: the specific date for which we want the clustering details.
Example: 'date': '2013-09-10'
Returns:
A dict with the VT report.
"""
api_... | [
"def",
"get_file_clusters",
"(",
"self",
",",
"date",
")",
":",
"api_name",
"=",
"'virustotal-file-clusters'",
"(",
"all_responses",
",",
"resources",
")",
"=",
"self",
".",
"_bulk_cache_lookup",
"(",
"api_name",
",",
"date",
")",
"response",
"=",
"self",
".",... | Retrieves file similarity clusters for a given time frame.
Args:
date: the specific date for which we want the clustering details.
Example: 'date': '2013-09-10'
Returns:
A dict with the VT report. | [
"Retrieves",
"file",
"similarity",
"clusters",
"for",
"a",
"given",
"time",
"frame",
"."
] | 60eef841d7cca115ec7857aeb9c553b72b694851 | https://github.com/Yelp/threat_intel/blob/60eef841d7cca115ec7857aeb9c553b72b694851/threat_intel/virustotal.py#L227-L242 | train |
Yelp/threat_intel | threat_intel/virustotal.py | VirusTotalApi._prepare_resource_chunks | def _prepare_resource_chunks(self, resources, resource_delim=','):
"""As in some VirusTotal API methods the call can be made for multiple
resources at once this method prepares a list of concatenated resources
according to the maximum number of resources per requests.
Args:
... | python | def _prepare_resource_chunks(self, resources, resource_delim=','):
"""As in some VirusTotal API methods the call can be made for multiple
resources at once this method prepares a list of concatenated resources
according to the maximum number of resources per requests.
Args:
... | [
"def",
"_prepare_resource_chunks",
"(",
"self",
",",
"resources",
",",
"resource_delim",
"=",
"','",
")",
":",
"return",
"[",
"self",
".",
"_prepare_resource_chunk",
"(",
"resources",
",",
"resource_delim",
",",
"pos",
")",
"for",
"pos",
"in",
"range",
"(",
... | As in some VirusTotal API methods the call can be made for multiple
resources at once this method prepares a list of concatenated resources
according to the maximum number of resources per requests.
Args:
resources: a list of the resources.
resource_delim: a string used ... | [
"As",
"in",
"some",
"VirusTotal",
"API",
"methods",
"the",
"call",
"can",
"be",
"made",
"for",
"multiple",
"resources",
"at",
"once",
"this",
"method",
"prepares",
"a",
"list",
"of",
"concatenated",
"resources",
"according",
"to",
"the",
"maximum",
"number",
... | 60eef841d7cca115ec7857aeb9c553b72b694851 | https://github.com/Yelp/threat_intel/blob/60eef841d7cca115ec7857aeb9c553b72b694851/threat_intel/virustotal.py#L263-L276 | train |
Yelp/threat_intel | threat_intel/virustotal.py | VirusTotalApi._extract_response_chunks | def _extract_response_chunks(self, all_responses, response_chunks, api_name):
"""Extracts and caches the responses from the response chunks in case
of the responses for the requests containing multiple concatenated
resources. Extracted responses are added to the already cached
responses ... | python | def _extract_response_chunks(self, all_responses, response_chunks, api_name):
"""Extracts and caches the responses from the response chunks in case
of the responses for the requests containing multiple concatenated
resources. Extracted responses are added to the already cached
responses ... | [
"def",
"_extract_response_chunks",
"(",
"self",
",",
"all_responses",
",",
"response_chunks",
",",
"api_name",
")",
":",
"for",
"response_chunk",
"in",
"response_chunks",
":",
"if",
"not",
"isinstance",
"(",
"response_chunk",
",",
"list",
")",
":",
"response_chunk... | Extracts and caches the responses from the response chunks in case
of the responses for the requests containing multiple concatenated
resources. Extracted responses are added to the already cached
responses passed in the all_responses parameter.
Args:
all_responses: a list c... | [
"Extracts",
"and",
"caches",
"the",
"responses",
"from",
"the",
"response",
"chunks",
"in",
"case",
"of",
"the",
"responses",
"for",
"the",
"requests",
"containing",
"multiple",
"concatenated",
"resources",
".",
"Extracted",
"responses",
"are",
"added",
"to",
"t... | 60eef841d7cca115ec7857aeb9c553b72b694851 | https://github.com/Yelp/threat_intel/blob/60eef841d7cca115ec7857aeb9c553b72b694851/threat_intel/virustotal.py#L295-L315 | train |
divio/djangocms-text-ckeditor | djangocms_text_ckeditor/cms_plugins.py | TextPlugin.get_editor_widget | def get_editor_widget(self, request, plugins, plugin):
"""
Returns the Django form Widget to be used for
the text area
"""
cancel_url_name = self.get_admin_url_name('delete_on_cancel')
cancel_url = reverse('admin:%s' % cancel_url_name)
render_plugin_url_name = se... | python | def get_editor_widget(self, request, plugins, plugin):
"""
Returns the Django form Widget to be used for
the text area
"""
cancel_url_name = self.get_admin_url_name('delete_on_cancel')
cancel_url = reverse('admin:%s' % cancel_url_name)
render_plugin_url_name = se... | [
"def",
"get_editor_widget",
"(",
"self",
",",
"request",
",",
"plugins",
",",
"plugin",
")",
":",
"cancel_url_name",
"=",
"self",
".",
"get_admin_url_name",
"(",
"'delete_on_cancel'",
")",
"cancel_url",
"=",
"reverse",
"(",
"'admin:%s'",
"%",
"cancel_url_name",
... | Returns the Django form Widget to be used for
the text area | [
"Returns",
"the",
"Django",
"form",
"Widget",
"to",
"be",
"used",
"for",
"the",
"text",
"area"
] | a6069096fdac80931fd328055d1d615d168c33df | https://github.com/divio/djangocms-text-ckeditor/blob/a6069096fdac80931fd328055d1d615d168c33df/djangocms_text_ckeditor/cms_plugins.py#L227-L257 | train |
divio/djangocms-text-ckeditor | djangocms_text_ckeditor/cms_plugins.py | TextPlugin.get_form_class | def get_form_class(self, request, plugins, plugin):
"""
Returns a subclass of Form to be used by this plugin
"""
widget = self.get_editor_widget(
request=request,
plugins=plugins,
plugin=plugin,
)
instance = plugin.get_plugin_instance(... | python | def get_form_class(self, request, plugins, plugin):
"""
Returns a subclass of Form to be used by this plugin
"""
widget = self.get_editor_widget(
request=request,
plugins=plugins,
plugin=plugin,
)
instance = plugin.get_plugin_instance(... | [
"def",
"get_form_class",
"(",
"self",
",",
"request",
",",
"plugins",
",",
"plugin",
")",
":",
"widget",
"=",
"self",
".",
"get_editor_widget",
"(",
"request",
"=",
"request",
",",
"plugins",
"=",
"plugins",
",",
"plugin",
"=",
"plugin",
",",
")",
"insta... | Returns a subclass of Form to be used by this plugin | [
"Returns",
"a",
"subclass",
"of",
"Form",
"to",
"be",
"used",
"by",
"this",
"plugin"
] | a6069096fdac80931fd328055d1d615d168c33df | https://github.com/divio/djangocms-text-ckeditor/blob/a6069096fdac80931fd328055d1d615d168c33df/djangocms_text_ckeditor/cms_plugins.py#L259-L291 | train |
divio/djangocms-text-ckeditor | djangocms_text_ckeditor/utils.py | _plugin_tags_to_html | def _plugin_tags_to_html(text, output_func):
"""
Convert plugin object 'tags' into the form for public site.
context is the template context to use, placeholder is the placeholder name
"""
plugins_by_id = get_plugins_from_text(text)
def _render_tag(m):
try:
plugin_id = int(... | python | def _plugin_tags_to_html(text, output_func):
"""
Convert plugin object 'tags' into the form for public site.
context is the template context to use, placeholder is the placeholder name
"""
plugins_by_id = get_plugins_from_text(text)
def _render_tag(m):
try:
plugin_id = int(... | [
"def",
"_plugin_tags_to_html",
"(",
"text",
",",
"output_func",
")",
":",
"plugins_by_id",
"=",
"get_plugins_from_text",
"(",
"text",
")",
"def",
"_render_tag",
"(",
"m",
")",
":",
"try",
":",
"plugin_id",
"=",
"int",
"(",
"m",
".",
"groupdict",
"(",
")",
... | Convert plugin object 'tags' into the form for public site.
context is the template context to use, placeholder is the placeholder name | [
"Convert",
"plugin",
"object",
"tags",
"into",
"the",
"form",
"for",
"public",
"site",
"."
] | a6069096fdac80931fd328055d1d615d168c33df | https://github.com/divio/djangocms-text-ckeditor/blob/a6069096fdac80931fd328055d1d615d168c33df/djangocms_text_ckeditor/utils.py#L91-L110 | train |
divio/djangocms-text-ckeditor | djangocms_text_ckeditor/html.py | extract_images | def extract_images(data, plugin):
"""
extracts base64 encoded images from drag and drop actions in browser and saves
those images as plugins
"""
if not settings.TEXT_SAVE_IMAGE_FUNCTION:
return data
tree_builder = html5lib.treebuilders.getTreeBuilder('dom')
parser = html5lib.html5par... | python | def extract_images(data, plugin):
"""
extracts base64 encoded images from drag and drop actions in browser and saves
those images as plugins
"""
if not settings.TEXT_SAVE_IMAGE_FUNCTION:
return data
tree_builder = html5lib.treebuilders.getTreeBuilder('dom')
parser = html5lib.html5par... | [
"def",
"extract_images",
"(",
"data",
",",
"plugin",
")",
":",
"if",
"not",
"settings",
".",
"TEXT_SAVE_IMAGE_FUNCTION",
":",
"return",
"data",
"tree_builder",
"=",
"html5lib",
".",
"treebuilders",
".",
"getTreeBuilder",
"(",
"'dom'",
")",
"parser",
"=",
"html... | extracts base64 encoded images from drag and drop actions in browser and saves
those images as plugins | [
"extracts",
"base64",
"encoded",
"images",
"from",
"drag",
"and",
"drop",
"actions",
"in",
"browser",
"and",
"saves",
"those",
"images",
"as",
"plugins"
] | a6069096fdac80931fd328055d1d615d168c33df | https://github.com/divio/djangocms-text-ckeditor/blob/a6069096fdac80931fd328055d1d615d168c33df/djangocms_text_ckeditor/html.py#L76-L140 | train |
edx/i18n-tools | i18n/config.py | Configuration.default_config_filename | def default_config_filename(root_dir=None):
"""
Returns the default name of the configuration file.
"""
root_dir = Path(root_dir) if root_dir else Path('.').abspath()
locale_dir = root_dir / 'locale'
if not os.path.exists(locale_dir):
locale_dir = root_dir / '... | python | def default_config_filename(root_dir=None):
"""
Returns the default name of the configuration file.
"""
root_dir = Path(root_dir) if root_dir else Path('.').abspath()
locale_dir = root_dir / 'locale'
if not os.path.exists(locale_dir):
locale_dir = root_dir / '... | [
"def",
"default_config_filename",
"(",
"root_dir",
"=",
"None",
")",
":",
"root_dir",
"=",
"Path",
"(",
"root_dir",
")",
"if",
"root_dir",
"else",
"Path",
"(",
"'.'",
")",
".",
"abspath",
"(",
")",
"locale_dir",
"=",
"root_dir",
"/",
"'locale'",
"if",
"n... | Returns the default name of the configuration file. | [
"Returns",
"the",
"default",
"name",
"of",
"the",
"configuration",
"file",
"."
] | 99b20c17d1a0ca07a8839f33e0e9068248a581e5 | https://github.com/edx/i18n-tools/blob/99b20c17d1a0ca07a8839f33e0e9068248a581e5/i18n/config.py#L47-L55 | train |
edx/i18n-tools | i18n/config.py | Configuration.rtl_langs | def rtl_langs(self):
"""
Returns the set of translated RTL language codes present in self.locales.
Ignores source locale.
"""
def is_rtl(lang):
"""
Returns True if lang is a RTL language
args:
lang (str): The language to be che... | python | def rtl_langs(self):
"""
Returns the set of translated RTL language codes present in self.locales.
Ignores source locale.
"""
def is_rtl(lang):
"""
Returns True if lang is a RTL language
args:
lang (str): The language to be che... | [
"def",
"rtl_langs",
"(",
"self",
")",
":",
"def",
"is_rtl",
"(",
"lang",
")",
":",
"base_rtl",
"=",
"[",
"'ar'",
",",
"'fa'",
",",
"'he'",
",",
"'ur'",
"]",
"return",
"any",
"(",
"[",
"lang",
".",
"startswith",
"(",
"base_code",
")",
"for",
"base_c... | Returns the set of translated RTL language codes present in self.locales.
Ignores source locale. | [
"Returns",
"the",
"set",
"of",
"translated",
"RTL",
"language",
"codes",
"present",
"in",
"self",
".",
"locales",
".",
"Ignores",
"source",
"locale",
"."
] | 99b20c17d1a0ca07a8839f33e0e9068248a581e5 | https://github.com/edx/i18n-tools/blob/99b20c17d1a0ca07a8839f33e0e9068248a581e5/i18n/config.py#L94-L115 | train |
edx/i18n-tools | i18n/branch_cleanup.py | BranchCleanup.clean_conf_folder | def clean_conf_folder(self, locale):
"""Remove the configuration directory for `locale`"""
dirname = self.configuration.get_messages_dir(locale)
dirname.removedirs_p() | python | def clean_conf_folder(self, locale):
"""Remove the configuration directory for `locale`"""
dirname = self.configuration.get_messages_dir(locale)
dirname.removedirs_p() | [
"def",
"clean_conf_folder",
"(",
"self",
",",
"locale",
")",
":",
"dirname",
"=",
"self",
".",
"configuration",
".",
"get_messages_dir",
"(",
"locale",
")",
"dirname",
".",
"removedirs_p",
"(",
")"
] | Remove the configuration directory for `locale` | [
"Remove",
"the",
"configuration",
"directory",
"for",
"locale"
] | 99b20c17d1a0ca07a8839f33e0e9068248a581e5 | https://github.com/edx/i18n-tools/blob/99b20c17d1a0ca07a8839f33e0e9068248a581e5/i18n/branch_cleanup.py#L27-L30 | train |
edx/i18n-tools | i18n/segment.py | segment_pofiles | def segment_pofiles(configuration, locale):
"""Segment all the pofiles for `locale`.
Returns a set of filenames, all the segment files written.
"""
files_written = set()
for filename, segments in configuration.segment.items():
filename = configuration.get_messages_dir(locale) / filename
... | python | def segment_pofiles(configuration, locale):
"""Segment all the pofiles for `locale`.
Returns a set of filenames, all the segment files written.
"""
files_written = set()
for filename, segments in configuration.segment.items():
filename = configuration.get_messages_dir(locale) / filename
... | [
"def",
"segment_pofiles",
"(",
"configuration",
",",
"locale",
")",
":",
"files_written",
"=",
"set",
"(",
")",
"for",
"filename",
",",
"segments",
"in",
"configuration",
".",
"segment",
".",
"items",
"(",
")",
":",
"filename",
"=",
"configuration",
".",
"... | Segment all the pofiles for `locale`.
Returns a set of filenames, all the segment files written. | [
"Segment",
"all",
"the",
"pofiles",
"for",
"locale",
"."
] | 99b20c17d1a0ca07a8839f33e0e9068248a581e5 | https://github.com/edx/i18n-tools/blob/99b20c17d1a0ca07a8839f33e0e9068248a581e5/i18n/segment.py#L20-L30 | train |
edx/i18n-tools | i18n/segment.py | segment_pofile | def segment_pofile(filename, segments):
"""Segment a .po file using patterns in `segments`.
The .po file at `filename` is read, and the occurrence locations of its
messages are examined. `segments` is a dictionary: the keys are segment
.po filenames, the values are lists of patterns::
{
... | python | def segment_pofile(filename, segments):
"""Segment a .po file using patterns in `segments`.
The .po file at `filename` is read, and the occurrence locations of its
messages are examined. `segments` is a dictionary: the keys are segment
.po filenames, the values are lists of patterns::
{
... | [
"def",
"segment_pofile",
"(",
"filename",
",",
"segments",
")",
":",
"reading_msg",
"=",
"\"Reading {num} entries from {file}\"",
"writing_msg",
"=",
"\"Writing {num} entries to {file}\"",
"source_po",
"=",
"polib",
".",
"pofile",
"(",
"filename",
")",
"LOG",
".",
"in... | Segment a .po file using patterns in `segments`.
The .po file at `filename` is read, and the occurrence locations of its
messages are examined. `segments` is a dictionary: the keys are segment
.po filenames, the values are lists of patterns::
{
'django-studio.po': [
'c... | [
"Segment",
"a",
".",
"po",
"file",
"using",
"patterns",
"in",
"segments",
"."
] | 99b20c17d1a0ca07a8839f33e0e9068248a581e5 | https://github.com/edx/i18n-tools/blob/99b20c17d1a0ca07a8839f33e0e9068248a581e5/i18n/segment.py#L33-L116 | train |
edx/i18n-tools | i18n/extract.py | fix_header | def fix_header(pofile):
"""
Replace default headers with edX headers
"""
# By default, django-admin.py makemessages creates this header:
#
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE... | python | def fix_header(pofile):
"""
Replace default headers with edX headers
"""
# By default, django-admin.py makemessages creates this header:
#
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE... | [
"def",
"fix_header",
"(",
"pofile",
")",
":",
"pofile",
".",
"metadata_is_fuzzy",
"=",
"[",
"]",
"header",
"=",
"pofile",
".",
"header",
"fixes",
"=",
"(",
"(",
"'SOME DESCRIPTIVE TITLE'",
",",
"EDX_MARKER",
")",
",",
"(",
"'Translations template for PROJECT.'",... | Replace default headers with edX headers | [
"Replace",
"default",
"headers",
"with",
"edX",
"headers"
] | 99b20c17d1a0ca07a8839f33e0e9068248a581e5 | https://github.com/edx/i18n-tools/blob/99b20c17d1a0ca07a8839f33e0e9068248a581e5/i18n/extract.py#L184-L216 | train |
edx/i18n-tools | i18n/extract.py | strip_key_strings | def strip_key_strings(pofile):
"""
Removes all entries in PO which are key strings.
These entries should appear only in messages.po, not in any other po files.
"""
newlist = [entry for entry in pofile if not is_key_string(entry.msgid)]
del pofile[:]
pofile += newlist | python | def strip_key_strings(pofile):
"""
Removes all entries in PO which are key strings.
These entries should appear only in messages.po, not in any other po files.
"""
newlist = [entry for entry in pofile if not is_key_string(entry.msgid)]
del pofile[:]
pofile += newlist | [
"def",
"strip_key_strings",
"(",
"pofile",
")",
":",
"newlist",
"=",
"[",
"entry",
"for",
"entry",
"in",
"pofile",
"if",
"not",
"is_key_string",
"(",
"entry",
".",
"msgid",
")",
"]",
"del",
"pofile",
"[",
":",
"]",
"pofile",
"+=",
"newlist"
] | Removes all entries in PO which are key strings.
These entries should appear only in messages.po, not in any other po files. | [
"Removes",
"all",
"entries",
"in",
"PO",
"which",
"are",
"key",
"strings",
".",
"These",
"entries",
"should",
"appear",
"only",
"in",
"messages",
".",
"po",
"not",
"in",
"any",
"other",
"po",
"files",
"."
] | 99b20c17d1a0ca07a8839f33e0e9068248a581e5 | https://github.com/edx/i18n-tools/blob/99b20c17d1a0ca07a8839f33e0e9068248a581e5/i18n/extract.py#L249-L256 | train |
edx/i18n-tools | i18n/extract.py | Extract.rename_source_file | def rename_source_file(self, src, dst):
"""
Rename a file in the source directory.
"""
try:
os.rename(self.source_msgs_dir.joinpath(src), self.source_msgs_dir.joinpath(dst))
except OSError:
pass | python | def rename_source_file(self, src, dst):
"""
Rename a file in the source directory.
"""
try:
os.rename(self.source_msgs_dir.joinpath(src), self.source_msgs_dir.joinpath(dst))
except OSError:
pass | [
"def",
"rename_source_file",
"(",
"self",
",",
"src",
",",
"dst",
")",
":",
"try",
":",
"os",
".",
"rename",
"(",
"self",
".",
"source_msgs_dir",
".",
"joinpath",
"(",
"src",
")",
",",
"self",
".",
"source_msgs_dir",
".",
"joinpath",
"(",
"dst",
")",
... | Rename a file in the source directory. | [
"Rename",
"a",
"file",
"in",
"the",
"source",
"directory",
"."
] | 99b20c17d1a0ca07a8839f33e0e9068248a581e5 | https://github.com/edx/i18n-tools/blob/99b20c17d1a0ca07a8839f33e0e9068248a581e5/i18n/extract.py#L55-L62 | train |
edx/i18n-tools | i18n/main.py | get_valid_commands | def get_valid_commands():
"""
Returns valid commands.
Returns:
commands (list): List of valid commands
"""
modules = [m.basename().split('.')[0] for m in Path(__file__).dirname().files('*.py')]
commands = []
for modname in modules:
if modname == 'main':
continue
... | python | def get_valid_commands():
"""
Returns valid commands.
Returns:
commands (list): List of valid commands
"""
modules = [m.basename().split('.')[0] for m in Path(__file__).dirname().files('*.py')]
commands = []
for modname in modules:
if modname == 'main':
continue
... | [
"def",
"get_valid_commands",
"(",
")",
":",
"modules",
"=",
"[",
"m",
".",
"basename",
"(",
")",
".",
"split",
"(",
"'.'",
")",
"[",
"0",
"]",
"for",
"m",
"in",
"Path",
"(",
"__file__",
")",
".",
"dirname",
"(",
")",
".",
"files",
"(",
"'*.py'",
... | Returns valid commands.
Returns:
commands (list): List of valid commands | [
"Returns",
"valid",
"commands",
"."
] | 99b20c17d1a0ca07a8839f33e0e9068248a581e5 | https://github.com/edx/i18n-tools/blob/99b20c17d1a0ca07a8839f33e0e9068248a581e5/i18n/main.py#L11-L26 | train |
edx/i18n-tools | i18n/main.py | error_message | def error_message():
"""
Writes out error message specifying the valid commands.
Returns:
Failure code for system exit
"""
sys.stderr.write('valid commands:\n')
for cmd in get_valid_commands():
sys.stderr.write('\t%s\n' % cmd)
return -1 | python | def error_message():
"""
Writes out error message specifying the valid commands.
Returns:
Failure code for system exit
"""
sys.stderr.write('valid commands:\n')
for cmd in get_valid_commands():
sys.stderr.write('\t%s\n' % cmd)
return -1 | [
"def",
"error_message",
"(",
")",
":",
"sys",
".",
"stderr",
".",
"write",
"(",
"'valid commands:\\n'",
")",
"for",
"cmd",
"in",
"get_valid_commands",
"(",
")",
":",
"sys",
".",
"stderr",
".",
"write",
"(",
"'\\t%s\\n'",
"%",
"cmd",
")",
"return",
"-",
... | Writes out error message specifying the valid commands.
Returns:
Failure code for system exit | [
"Writes",
"out",
"error",
"message",
"specifying",
"the",
"valid",
"commands",
"."
] | 99b20c17d1a0ca07a8839f33e0e9068248a581e5 | https://github.com/edx/i18n-tools/blob/99b20c17d1a0ca07a8839f33e0e9068248a581e5/i18n/main.py#L29-L39 | train |
edx/i18n-tools | i18n/main.py | main | def main():
"""
Executes the given command. Returns error_message if command is not valid.
Returns:
Output of the given command or error message if command is not valid.
"""
try:
command = sys.argv[1]
except IndexError:
return error_message()
try:
module = i... | python | def main():
"""
Executes the given command. Returns error_message if command is not valid.
Returns:
Output of the given command or error message if command is not valid.
"""
try:
command = sys.argv[1]
except IndexError:
return error_message()
try:
module = i... | [
"def",
"main",
"(",
")",
":",
"try",
":",
"command",
"=",
"sys",
".",
"argv",
"[",
"1",
"]",
"except",
"IndexError",
":",
"return",
"error_message",
"(",
")",
"try",
":",
"module",
"=",
"importlib",
".",
"import_module",
"(",
"'i18n.%s'",
"%",
"command... | Executes the given command. Returns error_message if command is not valid.
Returns:
Output of the given command or error message if command is not valid. | [
"Executes",
"the",
"given",
"command",
".",
"Returns",
"error_message",
"if",
"command",
"is",
"not",
"valid",
"."
] | 99b20c17d1a0ca07a8839f33e0e9068248a581e5 | https://github.com/edx/i18n-tools/blob/99b20c17d1a0ca07a8839f33e0e9068248a581e5/i18n/main.py#L42-L60 | train |
edx/i18n-tools | i18n/validate.py | validate_po_files | def validate_po_files(configuration, locale_dir, root_dir=None, report_empty=False, check_all=False):
"""
Validate all of the po files found in the root directory that are not product of a merge.
Returns a boolean indicating whether or not problems were found.
"""
found_problems = False
# List... | python | def validate_po_files(configuration, locale_dir, root_dir=None, report_empty=False, check_all=False):
"""
Validate all of the po files found in the root directory that are not product of a merge.
Returns a boolean indicating whether or not problems were found.
"""
found_problems = False
# List... | [
"def",
"validate_po_files",
"(",
"configuration",
",",
"locale_dir",
",",
"root_dir",
"=",
"None",
",",
"report_empty",
"=",
"False",
",",
"check_all",
"=",
"False",
")",
":",
"found_problems",
"=",
"False",
"merged_files",
"=",
"configuration",
".",
"generate_m... | Validate all of the po files found in the root directory that are not product of a merge.
Returns a boolean indicating whether or not problems were found. | [
"Validate",
"all",
"of",
"the",
"po",
"files",
"found",
"in",
"the",
"root",
"directory",
"that",
"are",
"not",
"product",
"of",
"a",
"merge",
"."
] | 99b20c17d1a0ca07a8839f33e0e9068248a581e5 | https://github.com/edx/i18n-tools/blob/99b20c17d1a0ca07a8839f33e0e9068248a581e5/i18n/validate.py#L22-L63 | train |
edx/i18n-tools | i18n/validate.py | msgfmt_check_po_file | def msgfmt_check_po_file(locale_dir, filename):
"""
Call GNU msgfmt -c on each .po file to validate its format.
Any errors caught by msgfmt are logged to log.
Returns a boolean indicating whether or not problems were found.
"""
found_problems = False
# Use relative paths to make output les... | python | def msgfmt_check_po_file(locale_dir, filename):
"""
Call GNU msgfmt -c on each .po file to validate its format.
Any errors caught by msgfmt are logged to log.
Returns a boolean indicating whether or not problems were found.
"""
found_problems = False
# Use relative paths to make output les... | [
"def",
"msgfmt_check_po_file",
"(",
"locale_dir",
",",
"filename",
")",
":",
"found_problems",
"=",
"False",
"rfile",
"=",
"os",
".",
"path",
".",
"relpath",
"(",
"filename",
",",
"locale_dir",
")",
"out",
",",
"err",
"=",
"call",
"(",
"'msgfmt -c -o /dev/nu... | Call GNU msgfmt -c on each .po file to validate its format.
Any errors caught by msgfmt are logged to log.
Returns a boolean indicating whether or not problems were found. | [
"Call",
"GNU",
"msgfmt",
"-",
"c",
"on",
"each",
".",
"po",
"file",
"to",
"validate",
"its",
"format",
".",
"Any",
"errors",
"caught",
"by",
"msgfmt",
"are",
"logged",
"to",
"log",
"."
] | 99b20c17d1a0ca07a8839f33e0e9068248a581e5 | https://github.com/edx/i18n-tools/blob/99b20c17d1a0ca07a8839f33e0e9068248a581e5/i18n/validate.py#L66-L83 | train |
edx/i18n-tools | i18n/validate.py | tags_in_string | def tags_in_string(msg):
"""
Return the set of tags in a message string.
Tags includes HTML tags, data placeholders, etc.
Skips tags that might change due to translations: HTML entities, <abbr>,
and so on.
"""
def is_linguistic_tag(tag):
"""Is this tag one that can change with the... | python | def tags_in_string(msg):
"""
Return the set of tags in a message string.
Tags includes HTML tags, data placeholders, etc.
Skips tags that might change due to translations: HTML entities, <abbr>,
and so on.
"""
def is_linguistic_tag(tag):
"""Is this tag one that can change with the... | [
"def",
"tags_in_string",
"(",
"msg",
")",
":",
"def",
"is_linguistic_tag",
"(",
"tag",
")",
":",
"if",
"tag",
".",
"startswith",
"(",
"\"&\"",
")",
":",
"return",
"True",
"if",
"any",
"(",
"x",
"in",
"tag",
"for",
"x",
"in",
"[",
"\"<abbr>\"",
",",
... | Return the set of tags in a message string.
Tags includes HTML tags, data placeholders, etc.
Skips tags that might change due to translations: HTML entities, <abbr>,
and so on. | [
"Return",
"the",
"set",
"of",
"tags",
"in",
"a",
"message",
"string",
"."
] | 99b20c17d1a0ca07a8839f33e0e9068248a581e5 | https://github.com/edx/i18n-tools/blob/99b20c17d1a0ca07a8839f33e0e9068248a581e5/i18n/validate.py#L86-L105 | train |
edx/i18n-tools | i18n/validate.py | astral | def astral(msg):
"""Does `msg` have characters outside the Basic Multilingual Plane?"""
# Python2 narrow builds present astral characters as surrogate pairs.
# By encoding as utf32, and decoding DWORDS, we can get at the real code
# points.
utf32 = msg.encode("utf32")[4:] # [4:] to drop the ... | python | def astral(msg):
"""Does `msg` have characters outside the Basic Multilingual Plane?"""
# Python2 narrow builds present astral characters as surrogate pairs.
# By encoding as utf32, and decoding DWORDS, we can get at the real code
# points.
utf32 = msg.encode("utf32")[4:] # [4:] to drop the ... | [
"def",
"astral",
"(",
"msg",
")",
":",
"utf32",
"=",
"msg",
".",
"encode",
"(",
"\"utf32\"",
")",
"[",
"4",
":",
"]",
"code_points",
"=",
"struct",
".",
"unpack",
"(",
"\"%dI\"",
"%",
"(",
"len",
"(",
"utf32",
")",
"/",
"4",
")",
",",
"utf32",
... | Does `msg` have characters outside the Basic Multilingual Plane? | [
"Does",
"msg",
"have",
"characters",
"outside",
"the",
"Basic",
"Multilingual",
"Plane?"
] | 99b20c17d1a0ca07a8839f33e0e9068248a581e5 | https://github.com/edx/i18n-tools/blob/99b20c17d1a0ca07a8839f33e0e9068248a581e5/i18n/validate.py#L108-L115 | train |
edx/i18n-tools | i18n/validate.py | report_problems | def report_problems(filename, problems):
"""
Report on the problems found in `filename`.
`problems` is a list of tuples as returned by `check_messages`.
"""
problem_file = filename.replace(".po", ".prob")
id_filler = textwrap.TextWrapper(width=79, initial_indent=" msgid: ", subsequent_indent=... | python | def report_problems(filename, problems):
"""
Report on the problems found in `filename`.
`problems` is a list of tuples as returned by `check_messages`.
"""
problem_file = filename.replace(".po", ".prob")
id_filler = textwrap.TextWrapper(width=79, initial_indent=" msgid: ", subsequent_indent=... | [
"def",
"report_problems",
"(",
"filename",
",",
"problems",
")",
":",
"problem_file",
"=",
"filename",
".",
"replace",
"(",
"\".po\"",
",",
"\".prob\"",
")",
"id_filler",
"=",
"textwrap",
".",
"TextWrapper",
"(",
"width",
"=",
"79",
",",
"initial_indent",
"=... | Report on the problems found in `filename`.
`problems` is a list of tuples as returned by `check_messages`. | [
"Report",
"on",
"the",
"problems",
"found",
"in",
"filename",
"."
] | 99b20c17d1a0ca07a8839f33e0e9068248a581e5 | https://github.com/edx/i18n-tools/blob/99b20c17d1a0ca07a8839f33e0e9068248a581e5/i18n/validate.py#L182-L203 | train |
edx/i18n-tools | i18n/generate.py | merge | def merge(configuration, locale, target='django.po', sources=('django-partial.po',), fail_if_missing=True):
"""
For the given locale, merge the `sources` files to become the `target`
file. Note that the target file might also be one of the sources.
If fail_if_missing is true, and the files to be merge... | python | def merge(configuration, locale, target='django.po', sources=('django-partial.po',), fail_if_missing=True):
"""
For the given locale, merge the `sources` files to become the `target`
file. Note that the target file might also be one of the sources.
If fail_if_missing is true, and the files to be merge... | [
"def",
"merge",
"(",
"configuration",
",",
"locale",
",",
"target",
"=",
"'django.po'",
",",
"sources",
"=",
"(",
"'django-partial.po'",
",",
")",
",",
"fail_if_missing",
"=",
"True",
")",
":",
"LOG",
".",
"info",
"(",
"'Merging %s locale %s'",
",",
"target"... | For the given locale, merge the `sources` files to become the `target`
file. Note that the target file might also be one of the sources.
If fail_if_missing is true, and the files to be merged are missing,
throw an Exception, otherwise return silently.
If fail_if_missing is false, and the files to be ... | [
"For",
"the",
"given",
"locale",
"merge",
"the",
"sources",
"files",
"to",
"become",
"the",
"target",
"file",
".",
"Note",
"that",
"the",
"target",
"file",
"might",
"also",
"be",
"one",
"of",
"the",
"sources",
"."
] | 99b20c17d1a0ca07a8839f33e0e9068248a581e5 | https://github.com/edx/i18n-tools/blob/99b20c17d1a0ca07a8839f33e0e9068248a581e5/i18n/generate.py#L32-L72 | train |
edx/i18n-tools | i18n/generate.py | merge_files | def merge_files(configuration, locale, fail_if_missing=True):
"""
Merge all the files in `locale`, as specified in config.yaml.
"""
for target, sources in configuration.generate_merge.items():
merge(configuration, locale, target, sources, fail_if_missing) | python | def merge_files(configuration, locale, fail_if_missing=True):
"""
Merge all the files in `locale`, as specified in config.yaml.
"""
for target, sources in configuration.generate_merge.items():
merge(configuration, locale, target, sources, fail_if_missing) | [
"def",
"merge_files",
"(",
"configuration",
",",
"locale",
",",
"fail_if_missing",
"=",
"True",
")",
":",
"for",
"target",
",",
"sources",
"in",
"configuration",
".",
"generate_merge",
".",
"items",
"(",
")",
":",
"merge",
"(",
"configuration",
",",
"locale"... | Merge all the files in `locale`, as specified in config.yaml. | [
"Merge",
"all",
"the",
"files",
"in",
"locale",
"as",
"specified",
"in",
"config",
".",
"yaml",
"."
] | 99b20c17d1a0ca07a8839f33e0e9068248a581e5 | https://github.com/edx/i18n-tools/blob/99b20c17d1a0ca07a8839f33e0e9068248a581e5/i18n/generate.py#L75-L80 | train |
edx/i18n-tools | i18n/generate.py | clean_pofile | def clean_pofile(pofile_path):
"""
Clean various aspect of a .po file.
Fixes:
- Removes the fuzzy flag on metadata.
- Removes occurrence line numbers so that the generated files don't
generate a lot of line noise when they're committed.
Returns a list of any duplicate entri... | python | def clean_pofile(pofile_path):
"""
Clean various aspect of a .po file.
Fixes:
- Removes the fuzzy flag on metadata.
- Removes occurrence line numbers so that the generated files don't
generate a lot of line noise when they're committed.
Returns a list of any duplicate entri... | [
"def",
"clean_pofile",
"(",
"pofile_path",
")",
":",
"pomsgs",
"=",
"pofile",
"(",
"pofile_path",
")",
"pomsgs",
".",
"metadata_is_fuzzy",
"=",
"False",
"duplicate_entries",
"=",
"[",
"]",
"for",
"entry",
"in",
"pomsgs",
":",
"entry",
".",
"occurrences",
"="... | Clean various aspect of a .po file.
Fixes:
- Removes the fuzzy flag on metadata.
- Removes occurrence line numbers so that the generated files don't
generate a lot of line noise when they're committed.
Returns a list of any duplicate entries found. | [
"Clean",
"various",
"aspect",
"of",
"a",
".",
"po",
"file",
"."
] | 99b20c17d1a0ca07a8839f33e0e9068248a581e5 | https://github.com/edx/i18n-tools/blob/99b20c17d1a0ca07a8839f33e0e9068248a581e5/i18n/generate.py#L83-L135 | train |
edx/i18n-tools | i18n/dummy.py | new_filename | def new_filename(original_filename, new_locale):
"""Returns a filename derived from original_filename, using new_locale as the locale"""
orig_file = Path(original_filename)
new_file = orig_file.parent.parent.parent / new_locale / orig_file.parent.name / orig_file.name
return new_file.abspath() | python | def new_filename(original_filename, new_locale):
"""Returns a filename derived from original_filename, using new_locale as the locale"""
orig_file = Path(original_filename)
new_file = orig_file.parent.parent.parent / new_locale / orig_file.parent.name / orig_file.name
return new_file.abspath() | [
"def",
"new_filename",
"(",
"original_filename",
",",
"new_locale",
")",
":",
"orig_file",
"=",
"Path",
"(",
"original_filename",
")",
"new_file",
"=",
"orig_file",
".",
"parent",
".",
"parent",
".",
"parent",
"/",
"new_locale",
"/",
"orig_file",
".",
"parent"... | Returns a filename derived from original_filename, using new_locale as the locale | [
"Returns",
"a",
"filename",
"derived",
"from",
"original_filename",
"using",
"new_locale",
"as",
"the",
"locale"
] | 99b20c17d1a0ca07a8839f33e0e9068248a581e5 | https://github.com/edx/i18n-tools/blob/99b20c17d1a0ca07a8839f33e0e9068248a581e5/i18n/dummy.py#L217-L221 | train |
edx/i18n-tools | i18n/dummy.py | DummyCommand.run | def run(self, args):
"""
Generate dummy strings for all source po files.
"""
configuration = self.configuration
source_messages_dir = configuration.source_messages_dir
for locale, converter in zip(configuration.dummy_locales, [Dummy(), Dummy2(), ArabicDummy()]):
... | python | def run(self, args):
"""
Generate dummy strings for all source po files.
"""
configuration = self.configuration
source_messages_dir = configuration.source_messages_dir
for locale, converter in zip(configuration.dummy_locales, [Dummy(), Dummy2(), ArabicDummy()]):
... | [
"def",
"run",
"(",
"self",
",",
"args",
")",
":",
"configuration",
"=",
"self",
".",
"configuration",
"source_messages_dir",
"=",
"configuration",
".",
"source_messages_dir",
"for",
"locale",
",",
"converter",
"in",
"zip",
"(",
"configuration",
".",
"dummy_local... | Generate dummy strings for all source po files. | [
"Generate",
"dummy",
"strings",
"for",
"all",
"source",
"po",
"files",
"."
] | 99b20c17d1a0ca07a8839f33e0e9068248a581e5 | https://github.com/edx/i18n-tools/blob/99b20c17d1a0ca07a8839f33e0e9068248a581e5/i18n/dummy.py#L235-L248 | train |
edx/i18n-tools | i18n/execute.py | execute | def execute(command, working_directory=config.BASE_DIR, stderr=sp.STDOUT):
"""
Executes shell command in a given working_directory.
Command is a string to pass to the shell.
Output is ignored.
"""
LOG.info("Executing in %s ...", working_directory)
LOG.info(command)
sp.check_call(command,... | python | def execute(command, working_directory=config.BASE_DIR, stderr=sp.STDOUT):
"""
Executes shell command in a given working_directory.
Command is a string to pass to the shell.
Output is ignored.
"""
LOG.info("Executing in %s ...", working_directory)
LOG.info(command)
sp.check_call(command,... | [
"def",
"execute",
"(",
"command",
",",
"working_directory",
"=",
"config",
".",
"BASE_DIR",
",",
"stderr",
"=",
"sp",
".",
"STDOUT",
")",
":",
"LOG",
".",
"info",
"(",
"\"Executing in %s ...\"",
",",
"working_directory",
")",
"LOG",
".",
"info",
"(",
"comm... | Executes shell command in a given working_directory.
Command is a string to pass to the shell.
Output is ignored. | [
"Executes",
"shell",
"command",
"in",
"a",
"given",
"working_directory",
".",
"Command",
"is",
"a",
"string",
"to",
"pass",
"to",
"the",
"shell",
".",
"Output",
"is",
"ignored",
"."
] | 99b20c17d1a0ca07a8839f33e0e9068248a581e5 | https://github.com/edx/i18n-tools/blob/99b20c17d1a0ca07a8839f33e0e9068248a581e5/i18n/execute.py#L13-L21 | train |
edx/i18n-tools | i18n/execute.py | remove_file | def remove_file(filename, verbose=True):
"""
Attempt to delete filename.
log is boolean. If true, removal is logged.
Log a warning if file does not exist.
Logging filenames are relative to config.BASE_DIR to cut down on noise in output.
"""
if verbose:
LOG.info('Deleting file %s', os... | python | def remove_file(filename, verbose=True):
"""
Attempt to delete filename.
log is boolean. If true, removal is logged.
Log a warning if file does not exist.
Logging filenames are relative to config.BASE_DIR to cut down on noise in output.
"""
if verbose:
LOG.info('Deleting file %s', os... | [
"def",
"remove_file",
"(",
"filename",
",",
"verbose",
"=",
"True",
")",
":",
"if",
"verbose",
":",
"LOG",
".",
"info",
"(",
"'Deleting file %s'",
",",
"os",
".",
"path",
".",
"relpath",
"(",
"filename",
",",
"config",
".",
"BASE_DIR",
")",
")",
"if",
... | Attempt to delete filename.
log is boolean. If true, removal is logged.
Log a warning if file does not exist.
Logging filenames are relative to config.BASE_DIR to cut down on noise in output. | [
"Attempt",
"to",
"delete",
"filename",
".",
"log",
"is",
"boolean",
".",
"If",
"true",
"removal",
"is",
"logged",
".",
"Log",
"a",
"warning",
"if",
"file",
"does",
"not",
"exist",
".",
"Logging",
"filenames",
"are",
"relative",
"to",
"config",
".",
"BASE... | 99b20c17d1a0ca07a8839f33e0e9068248a581e5 | https://github.com/edx/i18n-tools/blob/99b20c17d1a0ca07a8839f33e0e9068248a581e5/i18n/execute.py#L37-L49 | train |
edx/i18n-tools | i18n/transifex.py | push | def push(*resources):
"""
Push translation source English files to Transifex.
Arguments name specific resources to push. Otherwise, push all the source
files.
"""
cmd = 'tx push -s'
if resources:
for resource in resources:
execute(cmd + ' -r {resource}'.format(resource=r... | python | def push(*resources):
"""
Push translation source English files to Transifex.
Arguments name specific resources to push. Otherwise, push all the source
files.
"""
cmd = 'tx push -s'
if resources:
for resource in resources:
execute(cmd + ' -r {resource}'.format(resource=r... | [
"def",
"push",
"(",
"*",
"resources",
")",
":",
"cmd",
"=",
"'tx push -s'",
"if",
"resources",
":",
"for",
"resource",
"in",
"resources",
":",
"execute",
"(",
"cmd",
"+",
"' -r {resource}'",
".",
"format",
"(",
"resource",
"=",
"resource",
")",
")",
"els... | Push translation source English files to Transifex.
Arguments name specific resources to push. Otherwise, push all the source
files. | [
"Push",
"translation",
"source",
"English",
"files",
"to",
"Transifex",
"."
] | 99b20c17d1a0ca07a8839f33e0e9068248a581e5 | https://github.com/edx/i18n-tools/blob/99b20c17d1a0ca07a8839f33e0e9068248a581e5/i18n/transifex.py#L17-L29 | train |
edx/i18n-tools | i18n/transifex.py | pull_all_ltr | def pull_all_ltr(configuration):
"""
Pulls all translations - reviewed or not - for LTR languages
"""
print("Pulling all translated LTR languages from transifex...")
for lang in configuration.ltr_langs:
print('rm -rf conf/locale/' + lang)
execute('rm -rf conf/locale/' + lang)
... | python | def pull_all_ltr(configuration):
"""
Pulls all translations - reviewed or not - for LTR languages
"""
print("Pulling all translated LTR languages from transifex...")
for lang in configuration.ltr_langs:
print('rm -rf conf/locale/' + lang)
execute('rm -rf conf/locale/' + lang)
... | [
"def",
"pull_all_ltr",
"(",
"configuration",
")",
":",
"print",
"(",
"\"Pulling all translated LTR languages from transifex...\"",
")",
"for",
"lang",
"in",
"configuration",
".",
"ltr_langs",
":",
"print",
"(",
"'rm -rf conf/locale/'",
"+",
"lang",
")",
"execute",
"("... | Pulls all translations - reviewed or not - for LTR languages | [
"Pulls",
"all",
"translations",
"-",
"reviewed",
"or",
"not",
"-",
"for",
"LTR",
"languages"
] | 99b20c17d1a0ca07a8839f33e0e9068248a581e5 | https://github.com/edx/i18n-tools/blob/99b20c17d1a0ca07a8839f33e0e9068248a581e5/i18n/transifex.py#L79-L88 | train |
edx/i18n-tools | i18n/transifex.py | pull_all_rtl | def pull_all_rtl(configuration):
"""
Pulls all translations - reviewed or not - for RTL languages
"""
print("Pulling all translated RTL languages from transifex...")
for lang in configuration.rtl_langs:
print('rm -rf conf/locale/' + lang)
execute('rm -rf conf/locale/' + lang)
... | python | def pull_all_rtl(configuration):
"""
Pulls all translations - reviewed or not - for RTL languages
"""
print("Pulling all translated RTL languages from transifex...")
for lang in configuration.rtl_langs:
print('rm -rf conf/locale/' + lang)
execute('rm -rf conf/locale/' + lang)
... | [
"def",
"pull_all_rtl",
"(",
"configuration",
")",
":",
"print",
"(",
"\"Pulling all translated RTL languages from transifex...\"",
")",
"for",
"lang",
"in",
"configuration",
".",
"rtl_langs",
":",
"print",
"(",
"'rm -rf conf/locale/'",
"+",
"lang",
")",
"execute",
"("... | Pulls all translations - reviewed or not - for RTL languages | [
"Pulls",
"all",
"translations",
"-",
"reviewed",
"or",
"not",
"-",
"for",
"RTL",
"languages"
] | 99b20c17d1a0ca07a8839f33e0e9068248a581e5 | https://github.com/edx/i18n-tools/blob/99b20c17d1a0ca07a8839f33e0e9068248a581e5/i18n/transifex.py#L91-L100 | train |
edx/i18n-tools | i18n/transifex.py | clean_translated_locales | def clean_translated_locales(configuration, langs=None):
"""
Strips out the warning from all translated po files
about being an English source file.
"""
if not langs:
langs = configuration.translated_locales
for locale in langs:
clean_locale(configuration, locale) | python | def clean_translated_locales(configuration, langs=None):
"""
Strips out the warning from all translated po files
about being an English source file.
"""
if not langs:
langs = configuration.translated_locales
for locale in langs:
clean_locale(configuration, locale) | [
"def",
"clean_translated_locales",
"(",
"configuration",
",",
"langs",
"=",
"None",
")",
":",
"if",
"not",
"langs",
":",
"langs",
"=",
"configuration",
".",
"translated_locales",
"for",
"locale",
"in",
"langs",
":",
"clean_locale",
"(",
"configuration",
",",
"... | Strips out the warning from all translated po files
about being an English source file. | [
"Strips",
"out",
"the",
"warning",
"from",
"all",
"translated",
"po",
"files",
"about",
"being",
"an",
"English",
"source",
"file",
"."
] | 99b20c17d1a0ca07a8839f33e0e9068248a581e5 | https://github.com/edx/i18n-tools/blob/99b20c17d1a0ca07a8839f33e0e9068248a581e5/i18n/transifex.py#L103-L111 | train |
edx/i18n-tools | i18n/transifex.py | clean_locale | def clean_locale(configuration, locale):
"""
Strips out the warning from all of a locale's translated po files
about being an English source file.
Iterates over machine-generated files.
"""
dirname = configuration.get_messages_dir(locale)
if not dirname.exists():
# Happens when we ha... | python | def clean_locale(configuration, locale):
"""
Strips out the warning from all of a locale's translated po files
about being an English source file.
Iterates over machine-generated files.
"""
dirname = configuration.get_messages_dir(locale)
if not dirname.exists():
# Happens when we ha... | [
"def",
"clean_locale",
"(",
"configuration",
",",
"locale",
")",
":",
"dirname",
"=",
"configuration",
".",
"get_messages_dir",
"(",
"locale",
")",
"if",
"not",
"dirname",
".",
"exists",
"(",
")",
":",
"return",
"for",
"filename",
"in",
"dirname",
".",
"fi... | Strips out the warning from all of a locale's translated po files
about being an English source file.
Iterates over machine-generated files. | [
"Strips",
"out",
"the",
"warning",
"from",
"all",
"of",
"a",
"locale",
"s",
"translated",
"po",
"files",
"about",
"being",
"an",
"English",
"source",
"file",
".",
"Iterates",
"over",
"machine",
"-",
"generated",
"files",
"."
] | 99b20c17d1a0ca07a8839f33e0e9068248a581e5 | https://github.com/edx/i18n-tools/blob/99b20c17d1a0ca07a8839f33e0e9068248a581e5/i18n/transifex.py#L114-L125 | train |
edx/i18n-tools | i18n/transifex.py | clean_file | def clean_file(configuration, filename):
"""
Strips out the warning from a translated po file about being an English source file.
Replaces warning with a note about coming from Transifex.
"""
pofile = polib.pofile(filename)
if pofile.header.find(EDX_MARKER) != -1:
new_header = get_new_h... | python | def clean_file(configuration, filename):
"""
Strips out the warning from a translated po file about being an English source file.
Replaces warning with a note about coming from Transifex.
"""
pofile = polib.pofile(filename)
if pofile.header.find(EDX_MARKER) != -1:
new_header = get_new_h... | [
"def",
"clean_file",
"(",
"configuration",
",",
"filename",
")",
":",
"pofile",
"=",
"polib",
".",
"pofile",
"(",
"filename",
")",
"if",
"pofile",
".",
"header",
".",
"find",
"(",
"EDX_MARKER",
")",
"!=",
"-",
"1",
":",
"new_header",
"=",
"get_new_header... | Strips out the warning from a translated po file about being an English source file.
Replaces warning with a note about coming from Transifex. | [
"Strips",
"out",
"the",
"warning",
"from",
"a",
"translated",
"po",
"file",
"about",
"being",
"an",
"English",
"source",
"file",
".",
"Replaces",
"warning",
"with",
"a",
"note",
"about",
"coming",
"from",
"Transifex",
"."
] | 99b20c17d1a0ca07a8839f33e0e9068248a581e5 | https://github.com/edx/i18n-tools/blob/99b20c17d1a0ca07a8839f33e0e9068248a581e5/i18n/transifex.py#L128-L139 | train |
edx/i18n-tools | i18n/transifex.py | get_new_header | def get_new_header(configuration, pofile):
"""
Insert info about edX into the po file headers
"""
team = pofile.metadata.get('Language-Team', None)
if not team:
return TRANSIFEX_HEADER.format(configuration.TRANSIFEX_URL)
return TRANSIFEX_HEADER.format(team) | python | def get_new_header(configuration, pofile):
"""
Insert info about edX into the po file headers
"""
team = pofile.metadata.get('Language-Team', None)
if not team:
return TRANSIFEX_HEADER.format(configuration.TRANSIFEX_URL)
return TRANSIFEX_HEADER.format(team) | [
"def",
"get_new_header",
"(",
"configuration",
",",
"pofile",
")",
":",
"team",
"=",
"pofile",
".",
"metadata",
".",
"get",
"(",
"'Language-Team'",
",",
"None",
")",
"if",
"not",
"team",
":",
"return",
"TRANSIFEX_HEADER",
".",
"format",
"(",
"configuration",... | Insert info about edX into the po file headers | [
"Insert",
"info",
"about",
"edX",
"into",
"the",
"po",
"file",
"headers"
] | 99b20c17d1a0ca07a8839f33e0e9068248a581e5 | https://github.com/edx/i18n-tools/blob/99b20c17d1a0ca07a8839f33e0e9068248a581e5/i18n/transifex.py#L142-L149 | train |
edx/i18n-tools | i18n/converter.py | Converter.detag_string | def detag_string(self, string):
"""Extracts tags from string.
returns (string, list) where
string: string has tags replaced by indices (<BR>... => <0>, <1>, <2>, etc.)
list: list of the removed tags ('<BR>', '<I>', '</I>')
"""
counter = itertools.count(0)
... | python | def detag_string(self, string):
"""Extracts tags from string.
returns (string, list) where
string: string has tags replaced by indices (<BR>... => <0>, <1>, <2>, etc.)
list: list of the removed tags ('<BR>', '<I>', '</I>')
"""
counter = itertools.count(0)
... | [
"def",
"detag_string",
"(",
"self",
",",
"string",
")",
":",
"counter",
"=",
"itertools",
".",
"count",
"(",
"0",
")",
"count",
"=",
"lambda",
"m",
":",
"'<%s>'",
"%",
"next",
"(",
"counter",
")",
"tags",
"=",
"self",
".",
"tag_pattern",
".",
"findal... | Extracts tags from string.
returns (string, list) where
string: string has tags replaced by indices (<BR>... => <0>, <1>, <2>, etc.)
list: list of the removed tags ('<BR>', '<I>', '</I>') | [
"Extracts",
"tags",
"from",
"string",
"."
] | 99b20c17d1a0ca07a8839f33e0e9068248a581e5 | https://github.com/edx/i18n-tools/blob/99b20c17d1a0ca07a8839f33e0e9068248a581e5/i18n/converter.py#L51-L65 | train |
protream/iquery | iquery/utils.py | Args.options | def options(self):
"""Train tickets query options."""
arg = self.get(0)
if arg.startswith('-') and not self.is_asking_for_help:
return arg[1:]
return ''.join(x for x in arg if x in 'dgktz') | python | def options(self):
"""Train tickets query options."""
arg = self.get(0)
if arg.startswith('-') and not self.is_asking_for_help:
return arg[1:]
return ''.join(x for x in arg if x in 'dgktz') | [
"def",
"options",
"(",
"self",
")",
":",
"arg",
"=",
"self",
".",
"get",
"(",
"0",
")",
"if",
"arg",
".",
"startswith",
"(",
"'-'",
")",
"and",
"not",
"self",
".",
"is_asking_for_help",
":",
"return",
"arg",
"[",
"1",
":",
"]",
"return",
"''",
".... | Train tickets query options. | [
"Train",
"tickets",
"query",
"options",
"."
] | 7272e68af610f1dd63cf695209cfa44b75adc0e6 | https://github.com/protream/iquery/blob/7272e68af610f1dd63cf695209cfa44b75adc0e6/iquery/utils.py#L79-L84 | train |
protream/iquery | iquery/trains.py | TrainsCollection.trains | def trains(self):
"""Filter rows according to `headers`"""
for row in self._rows:
train_no = row.get('station_train_code')
initial = train_no[0].lower()
if not self._opts or initial in self._opts:
train = [
# Column: '车次'
... | python | def trains(self):
"""Filter rows according to `headers`"""
for row in self._rows:
train_no = row.get('station_train_code')
initial = train_no[0].lower()
if not self._opts or initial in self._opts:
train = [
# Column: '车次'
... | [
"def",
"trains",
"(",
"self",
")",
":",
"for",
"row",
"in",
"self",
".",
"_rows",
":",
"train_no",
"=",
"row",
".",
"get",
"(",
"'station_train_code'",
")",
"initial",
"=",
"train_no",
"[",
"0",
"]",
".",
"lower",
"(",
")",
"if",
"not",
"self",
"."... | Filter rows according to `headers` | [
"Filter",
"rows",
"according",
"to",
"headers"
] | 7272e68af610f1dd63cf695209cfa44b75adc0e6 | https://github.com/protream/iquery/blob/7272e68af610f1dd63cf695209cfa44b75adc0e6/iquery/trains.py#L63-L101 | train |
protream/iquery | iquery/trains.py | TrainsCollection.pretty_print | def pretty_print(self):
"""Use `PrettyTable` to perform formatted outprint."""
pt = PrettyTable()
if len(self) == 0:
pt._set_field_names(['Sorry,'])
pt.add_row([TRAIN_NOT_FOUND])
else:
pt._set_field_names(self.headers)
for train in self.tra... | python | def pretty_print(self):
"""Use `PrettyTable` to perform formatted outprint."""
pt = PrettyTable()
if len(self) == 0:
pt._set_field_names(['Sorry,'])
pt.add_row([TRAIN_NOT_FOUND])
else:
pt._set_field_names(self.headers)
for train in self.tra... | [
"def",
"pretty_print",
"(",
"self",
")",
":",
"pt",
"=",
"PrettyTable",
"(",
")",
"if",
"len",
"(",
"self",
")",
"==",
"0",
":",
"pt",
".",
"_set_field_names",
"(",
"[",
"'Sorry,'",
"]",
")",
"pt",
".",
"add_row",
"(",
"[",
"TRAIN_NOT_FOUND",
"]",
... | Use `PrettyTable` to perform formatted outprint. | [
"Use",
"PrettyTable",
"to",
"perform",
"formatted",
"outprint",
"."
] | 7272e68af610f1dd63cf695209cfa44b75adc0e6 | https://github.com/protream/iquery/blob/7272e68af610f1dd63cf695209cfa44b75adc0e6/iquery/trains.py#L103-L113 | train |
protream/iquery | iquery/trains.py | TrainTicketsQuery._valid_date | def _valid_date(self):
"""Check and return a valid query date."""
date = self._parse_date(self.date)
if not date:
exit_after_echo(INVALID_DATE)
try:
date = datetime.strptime(date, '%Y%m%d')
except ValueError:
exit_after_echo(INVALID_DATE)
... | python | def _valid_date(self):
"""Check and return a valid query date."""
date = self._parse_date(self.date)
if not date:
exit_after_echo(INVALID_DATE)
try:
date = datetime.strptime(date, '%Y%m%d')
except ValueError:
exit_after_echo(INVALID_DATE)
... | [
"def",
"_valid_date",
"(",
"self",
")",
":",
"date",
"=",
"self",
".",
"_parse_date",
"(",
"self",
".",
"date",
")",
"if",
"not",
"date",
":",
"exit_after_echo",
"(",
"INVALID_DATE",
")",
"try",
":",
"date",
"=",
"datetime",
".",
"strptime",
"(",
"date... | Check and return a valid query date. | [
"Check",
"and",
"return",
"a",
"valid",
"query",
"date",
"."
] | 7272e68af610f1dd63cf695209cfa44b75adc0e6 | https://github.com/protream/iquery/blob/7272e68af610f1dd63cf695209cfa44b75adc0e6/iquery/trains.py#L177-L194 | train |
protream/iquery | iquery/trains.py | TrainTicketsQuery._parse_date | def _parse_date(date):
"""Parse from the user input `date`.
e.g. current year 2016:
input 6-26, 626, ... return 2016626
input 2016-6-26, 2016/6/26, ... retrun 2016626
This fn wouldn't check the date, it only gather the number as a string.
"""
result = ''.j... | python | def _parse_date(date):
"""Parse from the user input `date`.
e.g. current year 2016:
input 6-26, 626, ... return 2016626
input 2016-6-26, 2016/6/26, ... retrun 2016626
This fn wouldn't check the date, it only gather the number as a string.
"""
result = ''.j... | [
"def",
"_parse_date",
"(",
"date",
")",
":",
"result",
"=",
"''",
".",
"join",
"(",
"re",
".",
"findall",
"(",
"'\\d'",
",",
"date",
")",
")",
"l",
"=",
"len",
"(",
"result",
")",
"if",
"l",
"in",
"(",
"2",
",",
"3",
",",
"4",
")",
":",
"ye... | Parse from the user input `date`.
e.g. current year 2016:
input 6-26, 626, ... return 2016626
input 2016-6-26, 2016/6/26, ... retrun 2016626
This fn wouldn't check the date, it only gather the number as a string. | [
"Parse",
"from",
"the",
"user",
"input",
"date",
"."
] | 7272e68af610f1dd63cf695209cfa44b75adc0e6 | https://github.com/protream/iquery/blob/7272e68af610f1dd63cf695209cfa44b75adc0e6/iquery/trains.py#L197-L218 | train |
protream/iquery | iquery/trains.py | TrainTicketsQuery._build_params | def _build_params(self):
"""Have no idea why wrong params order can't get data.
So, use `OrderedDict` here.
"""
d = OrderedDict()
d['purpose_codes'] = 'ADULT'
d['queryDate'] = self._valid_date
d['from_station'] = self._from_station_telecode
d['to_station']... | python | def _build_params(self):
"""Have no idea why wrong params order can't get data.
So, use `OrderedDict` here.
"""
d = OrderedDict()
d['purpose_codes'] = 'ADULT'
d['queryDate'] = self._valid_date
d['from_station'] = self._from_station_telecode
d['to_station']... | [
"def",
"_build_params",
"(",
"self",
")",
":",
"d",
"=",
"OrderedDict",
"(",
")",
"d",
"[",
"'purpose_codes'",
"]",
"=",
"'ADULT'",
"d",
"[",
"'queryDate'",
"]",
"=",
"self",
".",
"_valid_date",
"d",
"[",
"'from_station'",
"]",
"=",
"self",
".",
"_from... | Have no idea why wrong params order can't get data.
So, use `OrderedDict` here. | [
"Have",
"no",
"idea",
"why",
"wrong",
"params",
"order",
"can",
"t",
"get",
"data",
".",
"So",
"use",
"OrderedDict",
"here",
"."
] | 7272e68af610f1dd63cf695209cfa44b75adc0e6 | https://github.com/protream/iquery/blob/7272e68af610f1dd63cf695209cfa44b75adc0e6/iquery/trains.py#L220-L229 | train |
protream/iquery | iquery/showes.py | ShowTicketsQuery.date_range | def date_range(self):
"""Generate date range according to the `days` user input."""
try:
days = int(self.days)
except ValueError:
exit_after_echo(QUERY_DAYS_INVALID)
if days < 1:
exit_after_echo(QUERY_DAYS_INVALID)
start = datetime.today()
... | python | def date_range(self):
"""Generate date range according to the `days` user input."""
try:
days = int(self.days)
except ValueError:
exit_after_echo(QUERY_DAYS_INVALID)
if days < 1:
exit_after_echo(QUERY_DAYS_INVALID)
start = datetime.today()
... | [
"def",
"date_range",
"(",
"self",
")",
":",
"try",
":",
"days",
"=",
"int",
"(",
"self",
".",
"days",
")",
"except",
"ValueError",
":",
"exit_after_echo",
"(",
"QUERY_DAYS_INVALID",
")",
"if",
"days",
"<",
"1",
":",
"exit_after_echo",
"(",
"QUERY_DAYS_INVA... | Generate date range according to the `days` user input. | [
"Generate",
"date",
"range",
"according",
"to",
"the",
"days",
"user",
"input",
"."
] | 7272e68af610f1dd63cf695209cfa44b75adc0e6 | https://github.com/protream/iquery/blob/7272e68af610f1dd63cf695209cfa44b75adc0e6/iquery/showes.py#L121-L135 | train |
protream/iquery | iquery/hospitals.py | query | def query(params):
"""`params` is a city name or a city name + hospital name.
CLI:
1. query all putian hospitals in a city:
$ iquery -p 南京
+------+
| 南京 |
+------+
|... |
+------+
|... |
+------+
...
2. query if the... | python | def query(params):
"""`params` is a city name or a city name + hospital name.
CLI:
1. query all putian hospitals in a city:
$ iquery -p 南京
+------+
| 南京 |
+------+
|... |
+------+
|... |
+------+
...
2. query if the... | [
"def",
"query",
"(",
"params",
")",
":",
"r",
"=",
"requests_get",
"(",
"QUERY_URL",
",",
"verify",
"=",
"True",
")",
"return",
"HospitalCollection",
"(",
"r",
".",
"json",
"(",
")",
",",
"params",
")"
] | `params` is a city name or a city name + hospital name.
CLI:
1. query all putian hospitals in a city:
$ iquery -p 南京
+------+
| 南京 |
+------+
|... |
+------+
|... |
+------+
...
2. query if the hospital in the city is p... | [
"params",
"is",
"a",
"city",
"name",
"or",
"a",
"city",
"name",
"+",
"hospital",
"name",
"."
] | 7272e68af610f1dd63cf695209cfa44b75adc0e6 | https://github.com/protream/iquery/blob/7272e68af610f1dd63cf695209cfa44b75adc0e6/iquery/hospitals.py#L67-L99 | train |
protream/iquery | iquery/core.py | cli | def cli():
"""Various information query via command line.
Usage:
iquery -l <song> [singer]
iquery (-m|电影)
iquery (-c|彩票)
iquery -p <city>
iquery -p <city> <hospital>
iquery <city> <show> [days]
iquery [-dgktz] <from> <to> <date>
Arguments:
from 出发站
to ... | python | def cli():
"""Various information query via command line.
Usage:
iquery -l <song> [singer]
iquery (-m|电影)
iquery (-c|彩票)
iquery -p <city>
iquery -p <city> <hospital>
iquery <city> <show> [days]
iquery [-dgktz] <from> <to> <date>
Arguments:
from 出发站
to ... | [
"def",
"cli",
"(",
")",
":",
"if",
"args",
".",
"is_asking_for_help",
":",
"exit_after_echo",
"(",
"cli",
".",
"__doc__",
",",
"color",
"=",
"None",
")",
"elif",
"args",
".",
"is_querying_lottery",
":",
"from",
".",
"lottery",
"import",
"query",
"result",
... | Various information query via command line.
Usage:
iquery -l <song> [singer]
iquery (-m|电影)
iquery (-c|彩票)
iquery -p <city>
iquery -p <city> <hospital>
iquery <city> <show> [days]
iquery [-dgktz] <from> <to> <date>
Arguments:
from 出发站
to 到达站
date ... | [
"Various",
"information",
"query",
"via",
"command",
"line",
"."
] | 7272e68af610f1dd63cf695209cfa44b75adc0e6 | https://github.com/protream/iquery/blob/7272e68af610f1dd63cf695209cfa44b75adc0e6/iquery/core.py#L44-L117 | train |
protream/iquery | iquery/movies.py | query | def query():
"""Query hot movies infomation from douban."""
r = requests_get(QUERY_URL)
try:
rows = r.json()['subject_collection_items']
except (IndexError, TypeError):
rows = []
return MoviesCollection(rows) | python | def query():
"""Query hot movies infomation from douban."""
r = requests_get(QUERY_URL)
try:
rows = r.json()['subject_collection_items']
except (IndexError, TypeError):
rows = []
return MoviesCollection(rows) | [
"def",
"query",
"(",
")",
":",
"r",
"=",
"requests_get",
"(",
"QUERY_URL",
")",
"try",
":",
"rows",
"=",
"r",
".",
"json",
"(",
")",
"[",
"'subject_collection_items'",
"]",
"except",
"(",
"IndexError",
",",
"TypeError",
")",
":",
"rows",
"=",
"[",
"]... | Query hot movies infomation from douban. | [
"Query",
"hot",
"movies",
"infomation",
"from",
"douban",
"."
] | 7272e68af610f1dd63cf695209cfa44b75adc0e6 | https://github.com/protream/iquery/blob/7272e68af610f1dd63cf695209cfa44b75adc0e6/iquery/movies.py#L93-L103 | train |
OCA/knowledge | document_page_approval/models/document_page_history.py | DocumentPageHistory.action_draft | def action_draft(self):
"""Set a change request as draft"""
for rec in self:
if not rec.state == 'cancelled':
raise UserError(
_('You need to cancel it before reopening.'))
if not (rec.am_i_owner or rec.am_i_approver):
raise Use... | python | def action_draft(self):
"""Set a change request as draft"""
for rec in self:
if not rec.state == 'cancelled':
raise UserError(
_('You need to cancel it before reopening.'))
if not (rec.am_i_owner or rec.am_i_approver):
raise Use... | [
"def",
"action_draft",
"(",
"self",
")",
":",
"for",
"rec",
"in",
"self",
":",
"if",
"not",
"rec",
".",
"state",
"==",
"'cancelled'",
":",
"raise",
"UserError",
"(",
"_",
"(",
"'You need to cancel it before reopening.'",
")",
")",
"if",
"not",
"(",
"rec",
... | Set a change request as draft | [
"Set",
"a",
"change",
"request",
"as",
"draft"
] | 77fa06019c989b56ce34839e9f6343577184223a | https://github.com/OCA/knowledge/blob/77fa06019c989b56ce34839e9f6343577184223a/document_page_approval/models/document_page_history.py#L54-L64 | train |
OCA/knowledge | document_page_approval/models/document_page_history.py | DocumentPageHistory.action_to_approve | def action_to_approve(self):
"""Set a change request as to approve"""
template = self.env.ref(
'document_page_approval.email_template_new_draft_need_approval')
approver_gid = self.env.ref(
'document_page_approval.group_document_approver_user')
for rec in self:
... | python | def action_to_approve(self):
"""Set a change request as to approve"""
template = self.env.ref(
'document_page_approval.email_template_new_draft_need_approval')
approver_gid = self.env.ref(
'document_page_approval.group_document_approver_user')
for rec in self:
... | [
"def",
"action_to_approve",
"(",
"self",
")",
":",
"template",
"=",
"self",
".",
"env",
".",
"ref",
"(",
"'document_page_approval.email_template_new_draft_need_approval'",
")",
"approver_gid",
"=",
"self",
".",
"env",
".",
"ref",
"(",
"'document_page_approval.group_do... | Set a change request as to approve | [
"Set",
"a",
"change",
"request",
"as",
"to",
"approve"
] | 77fa06019c989b56ce34839e9f6343577184223a | https://github.com/OCA/knowledge/blob/77fa06019c989b56ce34839e9f6343577184223a/document_page_approval/models/document_page_history.py#L67-L92 | train |
OCA/knowledge | document_page_approval/models/document_page_history.py | DocumentPageHistory.action_approve | def action_approve(self):
"""Set a change request as approved."""
for rec in self:
if rec.state not in ['draft', 'to approve']:
raise UserError(
_("Can't approve page in '%s' state.") % rec.state)
if not rec.am_i_approver:
raise... | python | def action_approve(self):
"""Set a change request as approved."""
for rec in self:
if rec.state not in ['draft', 'to approve']:
raise UserError(
_("Can't approve page in '%s' state.") % rec.state)
if not rec.am_i_approver:
raise... | [
"def",
"action_approve",
"(",
"self",
")",
":",
"for",
"rec",
"in",
"self",
":",
"if",
"rec",
".",
"state",
"not",
"in",
"[",
"'draft'",
",",
"'to approve'",
"]",
":",
"raise",
"UserError",
"(",
"_",
"(",
"\"Can't approve page in '%s' state.\"",
")",
"%",
... | Set a change request as approved. | [
"Set",
"a",
"change",
"request",
"as",
"approved",
"."
] | 77fa06019c989b56ce34839e9f6343577184223a | https://github.com/OCA/knowledge/blob/77fa06019c989b56ce34839e9f6343577184223a/document_page_approval/models/document_page_history.py#L95-L129 | train |
OCA/knowledge | document_page_approval/models/document_page_history.py | DocumentPageHistory.action_cancel | def action_cancel(self):
"""Set a change request as cancelled."""
self.write({'state': 'cancelled'})
for rec in self:
rec.message_post(
subtype='mt_comment',
body=_(
'Change request <b>%s</b> has been cancelled by %s.'
... | python | def action_cancel(self):
"""Set a change request as cancelled."""
self.write({'state': 'cancelled'})
for rec in self:
rec.message_post(
subtype='mt_comment',
body=_(
'Change request <b>%s</b> has been cancelled by %s.'
... | [
"def",
"action_cancel",
"(",
"self",
")",
":",
"self",
".",
"write",
"(",
"{",
"'state'",
":",
"'cancelled'",
"}",
")",
"for",
"rec",
"in",
"self",
":",
"rec",
".",
"message_post",
"(",
"subtype",
"=",
"'mt_comment'",
",",
"body",
"=",
"_",
"(",
"'Ch... | Set a change request as cancelled. | [
"Set",
"a",
"change",
"request",
"as",
"cancelled",
"."
] | 77fa06019c989b56ce34839e9f6343577184223a | https://github.com/OCA/knowledge/blob/77fa06019c989b56ce34839e9f6343577184223a/document_page_approval/models/document_page_history.py#L132-L141 | train |
OCA/knowledge | document_page_approval/models/document_page_history.py | DocumentPageHistory._compute_am_i_owner | def _compute_am_i_owner(self):
"""Check if current user is the owner"""
for rec in self:
rec.am_i_owner = (rec.create_uid == self.env.user) | python | def _compute_am_i_owner(self):
"""Check if current user is the owner"""
for rec in self:
rec.am_i_owner = (rec.create_uid == self.env.user) | [
"def",
"_compute_am_i_owner",
"(",
"self",
")",
":",
"for",
"rec",
"in",
"self",
":",
"rec",
".",
"am_i_owner",
"=",
"(",
"rec",
".",
"create_uid",
"==",
"self",
".",
"env",
".",
"user",
")"
] | Check if current user is the owner | [
"Check",
"if",
"current",
"user",
"is",
"the",
"owner"
] | 77fa06019c989b56ce34839e9f6343577184223a | https://github.com/OCA/knowledge/blob/77fa06019c989b56ce34839e9f6343577184223a/document_page_approval/models/document_page_history.py#L150-L153 | train |
OCA/knowledge | document_page_approval/models/document_page_history.py | DocumentPageHistory._compute_page_url | def _compute_page_url(self):
"""Compute the page url."""
for page in self:
base_url = self.env['ir.config_parameter'].sudo().get_param(
'web.base.url',
default='http://localhost:8069'
)
page.page_url = (
'{}/web#db={}&i... | python | def _compute_page_url(self):
"""Compute the page url."""
for page in self:
base_url = self.env['ir.config_parameter'].sudo().get_param(
'web.base.url',
default='http://localhost:8069'
)
page.page_url = (
'{}/web#db={}&i... | [
"def",
"_compute_page_url",
"(",
"self",
")",
":",
"for",
"page",
"in",
"self",
":",
"base_url",
"=",
"self",
".",
"env",
"[",
"'ir.config_parameter'",
"]",
".",
"sudo",
"(",
")",
".",
"get_param",
"(",
"'web.base.url'",
",",
"default",
"=",
"'http://local... | Compute the page url. | [
"Compute",
"the",
"page",
"url",
"."
] | 77fa06019c989b56ce34839e9f6343577184223a | https://github.com/OCA/knowledge/blob/77fa06019c989b56ce34839e9f6343577184223a/document_page_approval/models/document_page_history.py#L156-L170 | train |
OCA/knowledge | document_page_approval/models/document_page_history.py | DocumentPageHistory._compute_diff | def _compute_diff(self):
"""Shows a diff between this version and the previous version"""
history = self.env['document.page.history']
for rec in self:
domain = [
('page_id', '=', rec.page_id.id),
('state', '=', 'approved')]
if rec.approved_... | python | def _compute_diff(self):
"""Shows a diff between this version and the previous version"""
history = self.env['document.page.history']
for rec in self:
domain = [
('page_id', '=', rec.page_id.id),
('state', '=', 'approved')]
if rec.approved_... | [
"def",
"_compute_diff",
"(",
"self",
")",
":",
"history",
"=",
"self",
".",
"env",
"[",
"'document.page.history'",
"]",
"for",
"rec",
"in",
"self",
":",
"domain",
"=",
"[",
"(",
"'page_id'",
",",
"'='",
",",
"rec",
".",
"page_id",
".",
"id",
")",
","... | Shows a diff between this version and the previous version | [
"Shows",
"a",
"diff",
"between",
"this",
"version",
"and",
"the",
"previous",
"version"
] | 77fa06019c989b56ce34839e9f6343577184223a | https://github.com/OCA/knowledge/blob/77fa06019c989b56ce34839e9f6343577184223a/document_page_approval/models/document_page_history.py#L173-L186 | train |
OCA/knowledge | document_url/wizard/document_url.py | AddUrlWizard.action_add_url | def action_add_url(self):
"""Adds the URL with the given name as an ir.attachment record."""
if not self.env.context.get('active_model'):
return
attachment_obj = self.env['ir.attachment']
for form in self:
url = parse.urlparse(form.url)
if not url.sche... | python | def action_add_url(self):
"""Adds the URL with the given name as an ir.attachment record."""
if not self.env.context.get('active_model'):
return
attachment_obj = self.env['ir.attachment']
for form in self:
url = parse.urlparse(form.url)
if not url.sche... | [
"def",
"action_add_url",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"env",
".",
"context",
".",
"get",
"(",
"'active_model'",
")",
":",
"return",
"attachment_obj",
"=",
"self",
".",
"env",
"[",
"'ir.attachment'",
"]",
"for",
"form",
"in",
"self",
... | Adds the URL with the given name as an ir.attachment record. | [
"Adds",
"the",
"URL",
"with",
"the",
"given",
"name",
"as",
"an",
"ir",
".",
"attachment",
"record",
"."
] | 77fa06019c989b56ce34839e9f6343577184223a | https://github.com/OCA/knowledge/blob/77fa06019c989b56ce34839e9f6343577184223a/document_url/wizard/document_url.py#L14-L32 | train |
OCA/knowledge | document_page_approval/models/document_page.py | DocumentPage._compute_is_approval_required | def _compute_is_approval_required(self):
"""Check if the document required approval based on his parents."""
for page in self:
res = page.approval_required
if page.parent_id:
res = res or page.parent_id.is_approval_required
page.is_approval_required = ... | python | def _compute_is_approval_required(self):
"""Check if the document required approval based on his parents."""
for page in self:
res = page.approval_required
if page.parent_id:
res = res or page.parent_id.is_approval_required
page.is_approval_required = ... | [
"def",
"_compute_is_approval_required",
"(",
"self",
")",
":",
"for",
"page",
"in",
"self",
":",
"res",
"=",
"page",
".",
"approval_required",
"if",
"page",
".",
"parent_id",
":",
"res",
"=",
"res",
"or",
"page",
".",
"parent_id",
".",
"is_approval_required"... | Check if the document required approval based on his parents. | [
"Check",
"if",
"the",
"document",
"required",
"approval",
"based",
"on",
"his",
"parents",
"."
] | 77fa06019c989b56ce34839e9f6343577184223a | https://github.com/OCA/knowledge/blob/77fa06019c989b56ce34839e9f6343577184223a/document_page_approval/models/document_page.py#L76-L82 | train |
OCA/knowledge | document_page_approval/models/document_page.py | DocumentPage._compute_approver_group_ids | def _compute_approver_group_ids(self):
"""Compute the approver groups based on his parents."""
for page in self:
res = page.approver_gid
if page.parent_id:
res = res | page.parent_id.approver_group_ids
page.approver_group_ids = res | python | def _compute_approver_group_ids(self):
"""Compute the approver groups based on his parents."""
for page in self:
res = page.approver_gid
if page.parent_id:
res = res | page.parent_id.approver_group_ids
page.approver_group_ids = res | [
"def",
"_compute_approver_group_ids",
"(",
"self",
")",
":",
"for",
"page",
"in",
"self",
":",
"res",
"=",
"page",
".",
"approver_gid",
"if",
"page",
".",
"parent_id",
":",
"res",
"=",
"res",
"|",
"page",
".",
"parent_id",
".",
"approver_group_ids",
"page"... | Compute the approver groups based on his parents. | [
"Compute",
"the",
"approver",
"groups",
"based",
"on",
"his",
"parents",
"."
] | 77fa06019c989b56ce34839e9f6343577184223a | https://github.com/OCA/knowledge/blob/77fa06019c989b56ce34839e9f6343577184223a/document_page_approval/models/document_page.py#L86-L92 | train |
OCA/knowledge | document_page_approval/models/document_page.py | DocumentPage._compute_am_i_approver | def _compute_am_i_approver(self):
"""Check if the current user can approve changes to this page."""
for rec in self:
rec.am_i_approver = rec.can_user_approve_this_page(self.env.user) | python | def _compute_am_i_approver(self):
"""Check if the current user can approve changes to this page."""
for rec in self:
rec.am_i_approver = rec.can_user_approve_this_page(self.env.user) | [
"def",
"_compute_am_i_approver",
"(",
"self",
")",
":",
"for",
"rec",
"in",
"self",
":",
"rec",
".",
"am_i_approver",
"=",
"rec",
".",
"can_user_approve_this_page",
"(",
"self",
".",
"env",
".",
"user",
")"
] | Check if the current user can approve changes to this page. | [
"Check",
"if",
"the",
"current",
"user",
"can",
"approve",
"changes",
"to",
"this",
"page",
"."
] | 77fa06019c989b56ce34839e9f6343577184223a | https://github.com/OCA/knowledge/blob/77fa06019c989b56ce34839e9f6343577184223a/document_page_approval/models/document_page.py#L96-L99 | train |
OCA/knowledge | document_page_approval/models/document_page.py | DocumentPage.can_user_approve_this_page | def can_user_approve_this_page(self, user):
"""Check if a user can approve this page."""
self.ensure_one()
# if it's not required, anyone can approve
if not self.is_approval_required:
return True
# if user belongs to 'Knowledge / Manager', he can approve anything
... | python | def can_user_approve_this_page(self, user):
"""Check if a user can approve this page."""
self.ensure_one()
# if it's not required, anyone can approve
if not self.is_approval_required:
return True
# if user belongs to 'Knowledge / Manager', he can approve anything
... | [
"def",
"can_user_approve_this_page",
"(",
"self",
",",
"user",
")",
":",
"self",
".",
"ensure_one",
"(",
")",
"if",
"not",
"self",
".",
"is_approval_required",
":",
"return",
"True",
"if",
"user",
".",
"has_group",
"(",
"'document_page.group_document_manager'",
... | Check if a user can approve this page. | [
"Check",
"if",
"a",
"user",
"can",
"approve",
"this",
"page",
"."
] | 77fa06019c989b56ce34839e9f6343577184223a | https://github.com/OCA/knowledge/blob/77fa06019c989b56ce34839e9f6343577184223a/document_page_approval/models/document_page.py#L102-L119 | train |
watchforstock/evohome-client | evohomeclient2/location.py | Location.status | def status(self):
"""Retrieves the location status."""
response = requests.get(
"https://tccna.honeywell.com/WebAPI/emea/api/v1/"
"location/%s/status?includeTemperatureControlSystems=True" %
self.locationId,
headers=self.client._headers() ... | python | def status(self):
"""Retrieves the location status."""
response = requests.get(
"https://tccna.honeywell.com/WebAPI/emea/api/v1/"
"location/%s/status?includeTemperatureControlSystems=True" %
self.locationId,
headers=self.client._headers() ... | [
"def",
"status",
"(",
"self",
")",
":",
"response",
"=",
"requests",
".",
"get",
"(",
"\"https://tccna.honeywell.com/WebAPI/emea/api/v1/\"",
"\"location/%s/status?includeTemperatureControlSystems=True\"",
"%",
"self",
".",
"locationId",
",",
"headers",
"=",
"self",
".",
... | Retrieves the location status. | [
"Retrieves",
"the",
"location",
"status",
"."
] | f1cb9273e97946d79c0651f00a218abbf7ada53a | https://github.com/watchforstock/evohome-client/blob/f1cb9273e97946d79c0651f00a218abbf7ada53a/evohomeclient2/location.py#L26-L55 | train |
watchforstock/evohome-client | evohomeclient2/hotwater.py | HotWater.set_dhw_on | def set_dhw_on(self, until=None):
"""Sets the DHW on until a given time, or permanently."""
if until is None:
data = {"Mode": "PermanentOverride",
"State": "On",
"UntilTime": None}
else:
data = {"Mode": "TemporaryOverride",
... | python | def set_dhw_on(self, until=None):
"""Sets the DHW on until a given time, or permanently."""
if until is None:
data = {"Mode": "PermanentOverride",
"State": "On",
"UntilTime": None}
else:
data = {"Mode": "TemporaryOverride",
... | [
"def",
"set_dhw_on",
"(",
"self",
",",
"until",
"=",
"None",
")",
":",
"if",
"until",
"is",
"None",
":",
"data",
"=",
"{",
"\"Mode\"",
":",
"\"PermanentOverride\"",
",",
"\"State\"",
":",
"\"On\"",
",",
"\"UntilTime\"",
":",
"None",
"}",
"else",
":",
"... | Sets the DHW on until a given time, or permanently. | [
"Sets",
"the",
"DHW",
"on",
"until",
"a",
"given",
"time",
"or",
"permanently",
"."
] | f1cb9273e97946d79c0651f00a218abbf7ada53a | https://github.com/watchforstock/evohome-client/blob/f1cb9273e97946d79c0651f00a218abbf7ada53a/evohomeclient2/hotwater.py#L34-L45 | train |
watchforstock/evohome-client | evohomeclient2/hotwater.py | HotWater.set_dhw_off | def set_dhw_off(self, until=None):
"""Sets the DHW off until a given time, or permanently."""
if until is None:
data = {"Mode": "PermanentOverride",
"State": "Off",
"UntilTime": None}
else:
data = {"Mode": "TemporaryOverride",
... | python | def set_dhw_off(self, until=None):
"""Sets the DHW off until a given time, or permanently."""
if until is None:
data = {"Mode": "PermanentOverride",
"State": "Off",
"UntilTime": None}
else:
data = {"Mode": "TemporaryOverride",
... | [
"def",
"set_dhw_off",
"(",
"self",
",",
"until",
"=",
"None",
")",
":",
"if",
"until",
"is",
"None",
":",
"data",
"=",
"{",
"\"Mode\"",
":",
"\"PermanentOverride\"",
",",
"\"State\"",
":",
"\"Off\"",
",",
"\"UntilTime\"",
":",
"None",
"}",
"else",
":",
... | Sets the DHW off until a given time, or permanently. | [
"Sets",
"the",
"DHW",
"off",
"until",
"a",
"given",
"time",
"or",
"permanently",
"."
] | f1cb9273e97946d79c0651f00a218abbf7ada53a | https://github.com/watchforstock/evohome-client/blob/f1cb9273e97946d79c0651f00a218abbf7ada53a/evohomeclient2/hotwater.py#L47-L58 | train |
watchforstock/evohome-client | evohomeclient2/zone.py | ZoneBase.schedule | def schedule(self):
"""Gets the schedule for the given zone"""
response = requests.get(
"https://tccna.honeywell.com/WebAPI/emea/api/v1"
"/%s/%s/schedule" % (self.zone_type, self.zoneId),
headers=self.client._headers() # pylint: d... | python | def schedule(self):
"""Gets the schedule for the given zone"""
response = requests.get(
"https://tccna.honeywell.com/WebAPI/emea/api/v1"
"/%s/%s/schedule" % (self.zone_type, self.zoneId),
headers=self.client._headers() # pylint: d... | [
"def",
"schedule",
"(",
"self",
")",
":",
"response",
"=",
"requests",
".",
"get",
"(",
"\"https://tccna.honeywell.com/WebAPI/emea/api/v1\"",
"\"/%s/%s/schedule\"",
"%",
"(",
"self",
".",
"zone_type",
",",
"self",
".",
"zoneId",
")",
",",
"headers",
"=",
"self",... | Gets the schedule for the given zone | [
"Gets",
"the",
"schedule",
"for",
"the",
"given",
"zone"
] | f1cb9273e97946d79c0651f00a218abbf7ada53a | https://github.com/watchforstock/evohome-client/blob/f1cb9273e97946d79c0651f00a218abbf7ada53a/evohomeclient2/zone.py#L16-L42 | train |
watchforstock/evohome-client | evohomeclient2/zone.py | ZoneBase.set_schedule | def set_schedule(self, zone_info):
"""Sets the schedule for this zone"""
# must only POST json, otherwise server API handler raises exceptions
try:
json.loads(zone_info)
except ValueError as error:
raise ValueError("zone_info must be valid JSON: ", error)
... | python | def set_schedule(self, zone_info):
"""Sets the schedule for this zone"""
# must only POST json, otherwise server API handler raises exceptions
try:
json.loads(zone_info)
except ValueError as error:
raise ValueError("zone_info must be valid JSON: ", error)
... | [
"def",
"set_schedule",
"(",
"self",
",",
"zone_info",
")",
":",
"try",
":",
"json",
".",
"loads",
"(",
"zone_info",
")",
"except",
"ValueError",
"as",
"error",
":",
"raise",
"ValueError",
"(",
"\"zone_info must be valid JSON: \"",
",",
"error",
")",
"headers",... | Sets the schedule for this zone | [
"Sets",
"the",
"schedule",
"for",
"this",
"zone"
] | f1cb9273e97946d79c0651f00a218abbf7ada53a | https://github.com/watchforstock/evohome-client/blob/f1cb9273e97946d79c0651f00a218abbf7ada53a/evohomeclient2/zone.py#L44-L63 | train |
watchforstock/evohome-client | evohomeclient/__init__.py | EvohomeClient.temperatures | def temperatures(self, force_refresh=False):
"""Retrieve the current details for each zone. Returns a generator."""
self._populate_full_data(force_refresh)
for device in self.full_data['devices']:
set_point = 0
status = ""
if 'heatSetpoint' in device['thermost... | python | def temperatures(self, force_refresh=False):
"""Retrieve the current details for each zone. Returns a generator."""
self._populate_full_data(force_refresh)
for device in self.full_data['devices']:
set_point = 0
status = ""
if 'heatSetpoint' in device['thermost... | [
"def",
"temperatures",
"(",
"self",
",",
"force_refresh",
"=",
"False",
")",
":",
"self",
".",
"_populate_full_data",
"(",
"force_refresh",
")",
"for",
"device",
"in",
"self",
".",
"full_data",
"[",
"'devices'",
"]",
":",
"set_point",
"=",
"0",
"status",
"... | Retrieve the current details for each zone. Returns a generator. | [
"Retrieve",
"the",
"current",
"details",
"for",
"each",
"zone",
".",
"Returns",
"a",
"generator",
"."
] | f1cb9273e97946d79c0651f00a218abbf7ada53a | https://github.com/watchforstock/evohome-client/blob/f1cb9273e97946d79c0651f00a218abbf7ada53a/evohomeclient/__init__.py#L115-L133 | train |
watchforstock/evohome-client | evohomeclient/__init__.py | EvohomeClient.get_modes | def get_modes(self, zone):
"""Returns the set of modes the device can be assigned."""
self._populate_full_data()
device = self._get_device(zone)
return device['thermostat']['allowedModes'] | python | def get_modes(self, zone):
"""Returns the set of modes the device can be assigned."""
self._populate_full_data()
device = self._get_device(zone)
return device['thermostat']['allowedModes'] | [
"def",
"get_modes",
"(",
"self",
",",
"zone",
")",
":",
"self",
".",
"_populate_full_data",
"(",
")",
"device",
"=",
"self",
".",
"_get_device",
"(",
"zone",
")",
"return",
"device",
"[",
"'thermostat'",
"]",
"[",
"'allowedModes'",
"]"
] | Returns the set of modes the device can be assigned. | [
"Returns",
"the",
"set",
"of",
"modes",
"the",
"device",
"can",
"be",
"assigned",
"."
] | f1cb9273e97946d79c0651f00a218abbf7ada53a | https://github.com/watchforstock/evohome-client/blob/f1cb9273e97946d79c0651f00a218abbf7ada53a/evohomeclient/__init__.py#L135-L139 | train |
watchforstock/evohome-client | evohomeclient/__init__.py | EvohomeClient.set_temperature | def set_temperature(self, zone, temperature, until=None):
"""Sets the temperature of the given zone."""
if until is None:
data = {"Value": temperature, "Status": "Hold", "NextTime": None}
else:
data = {"Value": temperature,
"Status": "Temporary",
... | python | def set_temperature(self, zone, temperature, until=None):
"""Sets the temperature of the given zone."""
if until is None:
data = {"Value": temperature, "Status": "Hold", "NextTime": None}
else:
data = {"Value": temperature,
"Status": "Temporary",
... | [
"def",
"set_temperature",
"(",
"self",
",",
"zone",
",",
"temperature",
",",
"until",
"=",
"None",
")",
":",
"if",
"until",
"is",
"None",
":",
"data",
"=",
"{",
"\"Value\"",
":",
"temperature",
",",
"\"Status\"",
":",
"\"Hold\"",
",",
"\"NextTime\"",
":"... | Sets the temperature of the given zone. | [
"Sets",
"the",
"temperature",
"of",
"the",
"given",
"zone",
"."
] | f1cb9273e97946d79c0651f00a218abbf7ada53a | https://github.com/watchforstock/evohome-client/blob/f1cb9273e97946d79c0651f00a218abbf7ada53a/evohomeclient/__init__.py#L266-L275 | train |
watchforstock/evohome-client | evohomeclient/__init__.py | EvohomeClient._set_dhw | def _set_dhw(self, status="Scheduled", mode=None, next_time=None):
"""Set DHW to On, Off or Auto, either indefinitely, or until a
specified time.
"""
data = {"Status": status,
"Mode": mode,
"NextTime": next_time,
"SpecialModes": None,
... | python | def _set_dhw(self, status="Scheduled", mode=None, next_time=None):
"""Set DHW to On, Off or Auto, either indefinitely, or until a
specified time.
"""
data = {"Status": status,
"Mode": mode,
"NextTime": next_time,
"SpecialModes": None,
... | [
"def",
"_set_dhw",
"(",
"self",
",",
"status",
"=",
"\"Scheduled\"",
",",
"mode",
"=",
"None",
",",
"next_time",
"=",
"None",
")",
":",
"data",
"=",
"{",
"\"Status\"",
":",
"status",
",",
"\"Mode\"",
":",
"mode",
",",
"\"NextTime\"",
":",
"next_time",
... | Set DHW to On, Off or Auto, either indefinitely, or until a
specified time. | [
"Set",
"DHW",
"to",
"On",
"Off",
"or",
"Auto",
"either",
"indefinitely",
"or",
"until",
"a",
"specified",
"time",
"."
] | f1cb9273e97946d79c0651f00a218abbf7ada53a | https://github.com/watchforstock/evohome-client/blob/f1cb9273e97946d79c0651f00a218abbf7ada53a/evohomeclient/__init__.py#L288-L311 | train |
watchforstock/evohome-client | evohomeclient/__init__.py | EvohomeClient.set_dhw_on | def set_dhw_on(self, until=None):
"""Set DHW to on, either indefinitely, or until a specified time.
When On, the DHW controller will work to keep its target temperature
at/above its target temperature. After the specified time, it will
revert to its scheduled behaviour.
"""
... | python | def set_dhw_on(self, until=None):
"""Set DHW to on, either indefinitely, or until a specified time.
When On, the DHW controller will work to keep its target temperature
at/above its target temperature. After the specified time, it will
revert to its scheduled behaviour.
"""
... | [
"def",
"set_dhw_on",
"(",
"self",
",",
"until",
"=",
"None",
")",
":",
"time_until",
"=",
"None",
"if",
"until",
"is",
"None",
"else",
"until",
".",
"strftime",
"(",
"'%Y-%m-%dT%H:%M:%SZ'",
")",
"self",
".",
"_set_dhw",
"(",
"status",
"=",
"\"Hold\"",
",... | Set DHW to on, either indefinitely, or until a specified time.
When On, the DHW controller will work to keep its target temperature
at/above its target temperature. After the specified time, it will
revert to its scheduled behaviour. | [
"Set",
"DHW",
"to",
"on",
"either",
"indefinitely",
"or",
"until",
"a",
"specified",
"time",
"."
] | f1cb9273e97946d79c0651f00a218abbf7ada53a | https://github.com/watchforstock/evohome-client/blob/f1cb9273e97946d79c0651f00a218abbf7ada53a/evohomeclient/__init__.py#L313-L324 | train |
watchforstock/evohome-client | evohomeclient2/__init__.py | EvohomeClient._headers | def _headers(self):
"""Ensure the Authorization Header has a valid Access Token."""
if not self.access_token or not self.access_token_expires:
self._basic_login()
elif datetime.now() > self.access_token_expires - timedelta(seconds=30):
self._basic_login()
return... | python | def _headers(self):
"""Ensure the Authorization Header has a valid Access Token."""
if not self.access_token or not self.access_token_expires:
self._basic_login()
elif datetime.now() > self.access_token_expires - timedelta(seconds=30):
self._basic_login()
return... | [
"def",
"_headers",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"access_token",
"or",
"not",
"self",
".",
"access_token_expires",
":",
"self",
".",
"_basic_login",
"(",
")",
"elif",
"datetime",
".",
"now",
"(",
")",
">",
"self",
".",
"access_token_ex... | Ensure the Authorization Header has a valid Access Token. | [
"Ensure",
"the",
"Authorization",
"Header",
"has",
"a",
"valid",
"Access",
"Token",
"."
] | f1cb9273e97946d79c0651f00a218abbf7ada53a | https://github.com/watchforstock/evohome-client/blob/f1cb9273e97946d79c0651f00a218abbf7ada53a/evohomeclient2/__init__.py#L84-L93 | train |
watchforstock/evohome-client | evohomeclient2/__init__.py | EvohomeClient._basic_login | def _basic_login(self):
"""Obtain a new access token from the vendor.
First, try using the refresh_token, if one is available, otherwise
authenticate using the user credentials.
"""
_LOGGER.debug("No/Expired/Invalid access_token, re-authenticating...")
self.access_token ... | python | def _basic_login(self):
"""Obtain a new access token from the vendor.
First, try using the refresh_token, if one is available, otherwise
authenticate using the user credentials.
"""
_LOGGER.debug("No/Expired/Invalid access_token, re-authenticating...")
self.access_token ... | [
"def",
"_basic_login",
"(",
"self",
")",
":",
"_LOGGER",
".",
"debug",
"(",
"\"No/Expired/Invalid access_token, re-authenticating...\"",
")",
"self",
".",
"access_token",
"=",
"self",
".",
"access_token_expires",
"=",
"None",
"if",
"self",
".",
"refresh_token",
":",... | Obtain a new access token from the vendor.
First, try using the refresh_token, if one is available, otherwise
authenticate using the user credentials. | [
"Obtain",
"a",
"new",
"access",
"token",
"from",
"the",
"vendor",
"."
] | f1cb9273e97946d79c0651f00a218abbf7ada53a | https://github.com/watchforstock/evohome-client/blob/f1cb9273e97946d79c0651f00a218abbf7ada53a/evohomeclient2/__init__.py#L95-L130 | train |
watchforstock/evohome-client | evohomeclient2/__init__.py | EvohomeClient.user_account | def user_account(self):
"""Return the user account information."""
self.account_info = None
url = 'https://tccna.honeywell.com/WebAPI/emea/api/v1/userAccount'
response = requests.get(url, headers=self._headers())
response.raise_for_status()
self.account_info = response... | python | def user_account(self):
"""Return the user account information."""
self.account_info = None
url = 'https://tccna.honeywell.com/WebAPI/emea/api/v1/userAccount'
response = requests.get(url, headers=self._headers())
response.raise_for_status()
self.account_info = response... | [
"def",
"user_account",
"(",
"self",
")",
":",
"self",
".",
"account_info",
"=",
"None",
"url",
"=",
"'https://tccna.honeywell.com/WebAPI/emea/api/v1/userAccount'",
"response",
"=",
"requests",
".",
"get",
"(",
"url",
",",
"headers",
"=",
"self",
".",
"_headers",
... | Return the user account information. | [
"Return",
"the",
"user",
"account",
"information",
"."
] | f1cb9273e97946d79c0651f00a218abbf7ada53a | https://github.com/watchforstock/evohome-client/blob/f1cb9273e97946d79c0651f00a218abbf7ada53a/evohomeclient2/__init__.py#L192-L202 | train |
watchforstock/evohome-client | evohomeclient2/__init__.py | EvohomeClient.installation | def installation(self):
"""Return the details of the installation."""
self.locations = []
url = ("https://tccna.honeywell.com/WebAPI/emea/api/v1/location"
"/installationInfo?userId=%s"
"&includeTemperatureControlSystems=True"
% self.account_info['use... | python | def installation(self):
"""Return the details of the installation."""
self.locations = []
url = ("https://tccna.honeywell.com/WebAPI/emea/api/v1/location"
"/installationInfo?userId=%s"
"&includeTemperatureControlSystems=True"
% self.account_info['use... | [
"def",
"installation",
"(",
"self",
")",
":",
"self",
".",
"locations",
"=",
"[",
"]",
"url",
"=",
"(",
"\"https://tccna.honeywell.com/WebAPI/emea/api/v1/location\"",
"\"/installationInfo?userId=%s\"",
"\"&includeTemperatureControlSystems=True\"",
"%",
"self",
".",
"account... | Return the details of the installation. | [
"Return",
"the",
"details",
"of",
"the",
"installation",
"."
] | f1cb9273e97946d79c0651f00a218abbf7ada53a | https://github.com/watchforstock/evohome-client/blob/f1cb9273e97946d79c0651f00a218abbf7ada53a/evohomeclient2/__init__.py#L204-L223 | train |
watchforstock/evohome-client | evohomeclient2/__init__.py | EvohomeClient.full_installation | def full_installation(self, location=None):
"""Return the full details of the installation."""
url = ("https://tccna.honeywell.com/WebAPI/emea/api/v1/location"
"/%s/installationInfo?includeTemperatureControlSystems=True"
% self._get_location(location))
response = r... | python | def full_installation(self, location=None):
"""Return the full details of the installation."""
url = ("https://tccna.honeywell.com/WebAPI/emea/api/v1/location"
"/%s/installationInfo?includeTemperatureControlSystems=True"
% self._get_location(location))
response = r... | [
"def",
"full_installation",
"(",
"self",
",",
"location",
"=",
"None",
")",
":",
"url",
"=",
"(",
"\"https://tccna.honeywell.com/WebAPI/emea/api/v1/location\"",
"\"/%s/installationInfo?includeTemperatureControlSystems=True\"",
"%",
"self",
".",
"_get_location",
"(",
"location... | Return the full details of the installation. | [
"Return",
"the",
"full",
"details",
"of",
"the",
"installation",
"."
] | f1cb9273e97946d79c0651f00a218abbf7ada53a | https://github.com/watchforstock/evohome-client/blob/f1cb9273e97946d79c0651f00a218abbf7ada53a/evohomeclient2/__init__.py#L225-L234 | train |
watchforstock/evohome-client | evohomeclient2/__init__.py | EvohomeClient.gateway | def gateway(self):
"""Return the detail of the gateway."""
url = 'https://tccna.honeywell.com/WebAPI/emea/api/v1/gateway'
response = requests.get(url, headers=self._headers())
response.raise_for_status()
return response.json() | python | def gateway(self):
"""Return the detail of the gateway."""
url = 'https://tccna.honeywell.com/WebAPI/emea/api/v1/gateway'
response = requests.get(url, headers=self._headers())
response.raise_for_status()
return response.json() | [
"def",
"gateway",
"(",
"self",
")",
":",
"url",
"=",
"'https://tccna.honeywell.com/WebAPI/emea/api/v1/gateway'",
"response",
"=",
"requests",
".",
"get",
"(",
"url",
",",
"headers",
"=",
"self",
".",
"_headers",
"(",
")",
")",
"response",
".",
"raise_for_status"... | Return the detail of the gateway. | [
"Return",
"the",
"detail",
"of",
"the",
"gateway",
"."
] | f1cb9273e97946d79c0651f00a218abbf7ada53a | https://github.com/watchforstock/evohome-client/blob/f1cb9273e97946d79c0651f00a218abbf7ada53a/evohomeclient2/__init__.py#L236-L243 | train |
watchforstock/evohome-client | evohomeclient2/controlsystem.py | ControlSystem.temperatures | def temperatures(self):
"""Return a generator with the details of each zone."""
self.location.status()
if self.hotwater:
yield {
'thermostat': 'DOMESTIC_HOT_WATER',
'id': self.hotwater.dhwId,
'name': '',
'temp': self.ho... | python | def temperatures(self):
"""Return a generator with the details of each zone."""
self.location.status()
if self.hotwater:
yield {
'thermostat': 'DOMESTIC_HOT_WATER',
'id': self.hotwater.dhwId,
'name': '',
'temp': self.ho... | [
"def",
"temperatures",
"(",
"self",
")",
":",
"self",
".",
"location",
".",
"status",
"(",
")",
"if",
"self",
".",
"hotwater",
":",
"yield",
"{",
"'thermostat'",
":",
"'DOMESTIC_HOT_WATER'",
",",
"'id'",
":",
"self",
".",
"hotwater",
".",
"dhwId",
",",
... | Return a generator with the details of each zone. | [
"Return",
"a",
"generator",
"with",
"the",
"details",
"of",
"each",
"zone",
"."
] | f1cb9273e97946d79c0651f00a218abbf7ada53a | https://github.com/watchforstock/evohome-client/blob/f1cb9273e97946d79c0651f00a218abbf7ada53a/evohomeclient2/controlsystem.py#L92-L116 | train |
watchforstock/evohome-client | evohomeclient2/controlsystem.py | ControlSystem.zone_schedules_backup | def zone_schedules_backup(self, filename):
"""Backup all zones on control system to the given file."""
_LOGGER.info("Backing up schedules from ControlSystem: %s (%s)...",
self.systemId, self.location.name)
schedules = {}
if self.hotwater:
_LOGGER.info("... | python | def zone_schedules_backup(self, filename):
"""Backup all zones on control system to the given file."""
_LOGGER.info("Backing up schedules from ControlSystem: %s (%s)...",
self.systemId, self.location.name)
schedules = {}
if self.hotwater:
_LOGGER.info("... | [
"def",
"zone_schedules_backup",
"(",
"self",
",",
"filename",
")",
":",
"_LOGGER",
".",
"info",
"(",
"\"Backing up schedules from ControlSystem: %s (%s)...\"",
",",
"self",
".",
"systemId",
",",
"self",
".",
"location",
".",
"name",
")",
"schedules",
"=",
"{",
"... | Backup all zones on control system to the given file. | [
"Backup",
"all",
"zones",
"on",
"control",
"system",
"to",
"the",
"given",
"file",
"."
] | f1cb9273e97946d79c0651f00a218abbf7ada53a | https://github.com/watchforstock/evohome-client/blob/f1cb9273e97946d79c0651f00a218abbf7ada53a/evohomeclient2/controlsystem.py#L118-L149 | train |
watchforstock/evohome-client | evohomeclient2/controlsystem.py | ControlSystem.zone_schedules_restore | def zone_schedules_restore(self, filename):
"""Restore all zones on control system from the given file."""
_LOGGER.info("Restoring schedules to ControlSystem %s (%s)...",
self.systemId, self.location)
_LOGGER.info("Reading from backup file: %s...", filename)
with op... | python | def zone_schedules_restore(self, filename):
"""Restore all zones on control system from the given file."""
_LOGGER.info("Restoring schedules to ControlSystem %s (%s)...",
self.systemId, self.location)
_LOGGER.info("Reading from backup file: %s...", filename)
with op... | [
"def",
"zone_schedules_restore",
"(",
"self",
",",
"filename",
")",
":",
"_LOGGER",
".",
"info",
"(",
"\"Restoring schedules to ControlSystem %s (%s)...\"",
",",
"self",
".",
"systemId",
",",
"self",
".",
"location",
")",
"_LOGGER",
".",
"info",
"(",
"\"Reading fr... | Restore all zones on control system from the given file. | [
"Restore",
"all",
"zones",
"on",
"control",
"system",
"from",
"the",
"given",
"file",
"."
] | f1cb9273e97946d79c0651f00a218abbf7ada53a | https://github.com/watchforstock/evohome-client/blob/f1cb9273e97946d79c0651f00a218abbf7ada53a/evohomeclient2/controlsystem.py#L151-L174 | train |
softlayer/softlayer-python | SoftLayer/CLI/order/item_list.py | cli | def cli(env, package_keyname, keyword, category):
"""List package items used for ordering.
The item keyNames listed can be used with `slcli order place` to specify
the items that are being ordered in the package.
.. Note::
Items with a numbered category, like disk0 or gpu0, can be included
... | python | def cli(env, package_keyname, keyword, category):
"""List package items used for ordering.
The item keyNames listed can be used with `slcli order place` to specify
the items that are being ordered in the package.
.. Note::
Items with a numbered category, like disk0 or gpu0, can be included
... | [
"def",
"cli",
"(",
"env",
",",
"package_keyname",
",",
"keyword",
",",
"category",
")",
":",
"table",
"=",
"formatting",
".",
"Table",
"(",
"COLUMNS",
")",
"manager",
"=",
"ordering",
".",
"OrderingManager",
"(",
"env",
".",
"client",
")",
"_filter",
"="... | List package items used for ordering.
The item keyNames listed can be used with `slcli order place` to specify
the items that are being ordered in the package.
.. Note::
Items with a numbered category, like disk0 or gpu0, can be included
multiple times in an order to match how many of the ... | [
"List",
"package",
"items",
"used",
"for",
"ordering",
"."
] | 9f181be08cc3668353b05a6de0cb324f52cff6fa | https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/CLI/order/item_list.py#L18-L53 | train |
softlayer/softlayer-python | SoftLayer/CLI/order/item_list.py | sort_items | def sort_items(items):
"""sorts the items into a dictionary of categories, with a list of items"""
sorted_items = {}
for item in items:
category = lookup(item, 'itemCategory', 'categoryCode')
if sorted_items.get(category) is None:
sorted_items[category] = []
sorted_items... | python | def sort_items(items):
"""sorts the items into a dictionary of categories, with a list of items"""
sorted_items = {}
for item in items:
category = lookup(item, 'itemCategory', 'categoryCode')
if sorted_items.get(category) is None:
sorted_items[category] = []
sorted_items... | [
"def",
"sort_items",
"(",
"items",
")",
":",
"sorted_items",
"=",
"{",
"}",
"for",
"item",
"in",
"items",
":",
"category",
"=",
"lookup",
"(",
"item",
",",
"'itemCategory'",
",",
"'categoryCode'",
")",
"if",
"sorted_items",
".",
"get",
"(",
"category",
"... | sorts the items into a dictionary of categories, with a list of items | [
"sorts",
"the",
"items",
"into",
"a",
"dictionary",
"of",
"categories",
"with",
"a",
"list",
"of",
"items"
] | 9f181be08cc3668353b05a6de0cb324f52cff6fa | https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/CLI/order/item_list.py#L56-L66 | train |
softlayer/softlayer-python | SoftLayer/CLI/vlan/list.py | cli | def cli(env, sortby, datacenter, number, name, limit):
"""List VLANs."""
mgr = SoftLayer.NetworkManager(env.client)
table = formatting.Table(COLUMNS)
table.sortby = sortby
vlans = mgr.list_vlans(datacenter=datacenter,
vlan_number=number,
name=... | python | def cli(env, sortby, datacenter, number, name, limit):
"""List VLANs."""
mgr = SoftLayer.NetworkManager(env.client)
table = formatting.Table(COLUMNS)
table.sortby = sortby
vlans = mgr.list_vlans(datacenter=datacenter,
vlan_number=number,
name=... | [
"def",
"cli",
"(",
"env",
",",
"sortby",
",",
"datacenter",
",",
"number",
",",
"name",
",",
"limit",
")",
":",
"mgr",
"=",
"SoftLayer",
".",
"NetworkManager",
"(",
"env",
".",
"client",
")",
"table",
"=",
"formatting",
".",
"Table",
"(",
"COLUMNS",
... | List VLANs. | [
"List",
"VLANs",
"."
] | 9f181be08cc3668353b05a6de0cb324f52cff6fa | https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/CLI/vlan/list.py#L34-L58 | train |
softlayer/softlayer-python | SoftLayer/CLI/nas/list.py | cli | def cli(env):
"""List NAS accounts."""
account = env.client['Account']
nas_accounts = account.getNasNetworkStorage(
mask='eventCount,serviceResource[datacenter.name]')
table = formatting.Table(['id', 'datacenter', 'size', 'server'])
for nas_account in nas_accounts:
table.add_row(... | python | def cli(env):
"""List NAS accounts."""
account = env.client['Account']
nas_accounts = account.getNasNetworkStorage(
mask='eventCount,serviceResource[datacenter.name]')
table = formatting.Table(['id', 'datacenter', 'size', 'server'])
for nas_account in nas_accounts:
table.add_row(... | [
"def",
"cli",
"(",
"env",
")",
":",
"account",
"=",
"env",
".",
"client",
"[",
"'Account'",
"]",
"nas_accounts",
"=",
"account",
".",
"getNasNetworkStorage",
"(",
"mask",
"=",
"'eventCount,serviceResource[datacenter.name]'",
")",
"table",
"=",
"formatting",
".",... | List NAS accounts. | [
"List",
"NAS",
"accounts",
"."
] | 9f181be08cc3668353b05a6de0cb324f52cff6fa | https://github.com/softlayer/softlayer-python/blob/9f181be08cc3668353b05a6de0cb324f52cff6fa/SoftLayer/CLI/nas/list.py#L13-L36 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.