id int32 0 252k | 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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
1,200 | TracyWebTech/django-revproxy | revproxy/views.py | ProxyView.get_encoded_query_params | def get_encoded_query_params(self):
"""Return encoded query params to be used in proxied request"""
get_data = encode_items(self.request.GET.lists())
return urlencode(get_data) | python | def get_encoded_query_params(self):
"""Return encoded query params to be used in proxied request"""
get_data = encode_items(self.request.GET.lists())
return urlencode(get_data) | [
"def",
"get_encoded_query_params",
"(",
"self",
")",
":",
"get_data",
"=",
"encode_items",
"(",
"self",
".",
"request",
".",
"GET",
".",
"lists",
"(",
")",
")",
"return",
"urlencode",
"(",
"get_data",
")"
] | Return encoded query params to be used in proxied request | [
"Return",
"encoded",
"query",
"params",
"to",
"be",
"used",
"in",
"proxied",
"request"
] | b8d1d9e44eadbafbd16bc03f04d15560089d4472 | https://github.com/TracyWebTech/django-revproxy/blob/b8d1d9e44eadbafbd16bc03f04d15560089d4472/revproxy/views.py#L140-L143 |
1,201 | jsfenfen/990-xml-reader | irs_reader/file_utils.py | stream_download | def stream_download(url, target_path, verbose=False):
""" Download a large file without loading it into memory. """
response = requests.get(url, stream=True)
handle = open(target_path, "wb")
if verbose:
print("Beginning streaming download of %s" % url)
start = datetime.now()
try:... | python | def stream_download(url, target_path, verbose=False):
""" Download a large file without loading it into memory. """
response = requests.get(url, stream=True)
handle = open(target_path, "wb")
if verbose:
print("Beginning streaming download of %s" % url)
start = datetime.now()
try:... | [
"def",
"stream_download",
"(",
"url",
",",
"target_path",
",",
"verbose",
"=",
"False",
")",
":",
"response",
"=",
"requests",
".",
"get",
"(",
"url",
",",
"stream",
"=",
"True",
")",
"handle",
"=",
"open",
"(",
"target_path",
",",
"\"wb\"",
")",
"if",... | Download a large file without loading it into memory. | [
"Download",
"a",
"large",
"file",
"without",
"loading",
"it",
"into",
"memory",
"."
] | 00020529b789081329a31a2e30b5ee729ce7596a | https://github.com/jsfenfen/990-xml-reader/blob/00020529b789081329a31a2e30b5ee729ce7596a/irs_reader/file_utils.py#L20-L39 |
1,202 | jsfenfen/990-xml-reader | irs_reader/file_utils.py | validate_object_id | def validate_object_id(object_id):
""" It's easy to make a mistake entering these, validate the format """
result = re.match(OBJECT_ID_RE, str(object_id))
if not result:
print("'%s' appears not to be a valid 990 object_id" % object_id)
raise RuntimeError(OBJECT_ID_MSG)
return object_id | python | def validate_object_id(object_id):
""" It's easy to make a mistake entering these, validate the format """
result = re.match(OBJECT_ID_RE, str(object_id))
if not result:
print("'%s' appears not to be a valid 990 object_id" % object_id)
raise RuntimeError(OBJECT_ID_MSG)
return object_id | [
"def",
"validate_object_id",
"(",
"object_id",
")",
":",
"result",
"=",
"re",
".",
"match",
"(",
"OBJECT_ID_RE",
",",
"str",
"(",
"object_id",
")",
")",
"if",
"not",
"result",
":",
"print",
"(",
"\"'%s' appears not to be a valid 990 object_id\"",
"%",
"object_id... | It's easy to make a mistake entering these, validate the format | [
"It",
"s",
"easy",
"to",
"make",
"a",
"mistake",
"entering",
"these",
"validate",
"the",
"format"
] | 00020529b789081329a31a2e30b5ee729ce7596a | https://github.com/jsfenfen/990-xml-reader/blob/00020529b789081329a31a2e30b5ee729ce7596a/irs_reader/file_utils.py#L42-L48 |
1,203 | jsfenfen/990-xml-reader | irs_reader/sked_dict_reader.py | SkedDictReader._get_table_start | def _get_table_start(self):
""" prefill the columns we need for all tables """
if self.documentation:
standardized_table_start = {
'object_id': {
'value': self.object_id,
'ordering': -1,
'line_number': 'NA',
... | python | def _get_table_start(self):
""" prefill the columns we need for all tables """
if self.documentation:
standardized_table_start = {
'object_id': {
'value': self.object_id,
'ordering': -1,
'line_number': 'NA',
... | [
"def",
"_get_table_start",
"(",
"self",
")",
":",
"if",
"self",
".",
"documentation",
":",
"standardized_table_start",
"=",
"{",
"'object_id'",
":",
"{",
"'value'",
":",
"self",
".",
"object_id",
",",
"'ordering'",
":",
"-",
"1",
",",
"'line_number'",
":",
... | prefill the columns we need for all tables | [
"prefill",
"the",
"columns",
"we",
"need",
"for",
"all",
"tables"
] | 00020529b789081329a31a2e30b5ee729ce7596a | https://github.com/jsfenfen/990-xml-reader/blob/00020529b789081329a31a2e30b5ee729ce7596a/irs_reader/sked_dict_reader.py#L45-L78 |
1,204 | jsfenfen/990-xml-reader | irs_reader/text_format_utils.py | debracket | def debracket(string):
""" Eliminate the bracketed var names in doc, line strings """
result = re.sub(BRACKET_RE, ';', str(string))
result = result.lstrip(';')
result = result.lstrip(' ')
result = result.replace('; ;',';')
return result | python | def debracket(string):
""" Eliminate the bracketed var names in doc, line strings """
result = re.sub(BRACKET_RE, ';', str(string))
result = result.lstrip(';')
result = result.lstrip(' ')
result = result.replace('; ;',';')
return result | [
"def",
"debracket",
"(",
"string",
")",
":",
"result",
"=",
"re",
".",
"sub",
"(",
"BRACKET_RE",
",",
"';'",
",",
"str",
"(",
"string",
")",
")",
"result",
"=",
"result",
".",
"lstrip",
"(",
"';'",
")",
"result",
"=",
"result",
".",
"lstrip",
"(",
... | Eliminate the bracketed var names in doc, line strings | [
"Eliminate",
"the",
"bracketed",
"var",
"names",
"in",
"doc",
"line",
"strings"
] | 00020529b789081329a31a2e30b5ee729ce7596a | https://github.com/jsfenfen/990-xml-reader/blob/00020529b789081329a31a2e30b5ee729ce7596a/irs_reader/text_format_utils.py#L15-L21 |
1,205 | jsfenfen/990-xml-reader | irs_reader/filing.py | Filing._set_schedules | def _set_schedules(self):
""" Attach the known and unknown schedules """
self.schedules = ['ReturnHeader990x', ]
self.otherforms = []
for sked in self.raw_irs_dict['Return']['ReturnData'].keys():
if not sked.startswith("@"):
if sked in KNOWN_SCHEDULES:
... | python | def _set_schedules(self):
""" Attach the known and unknown schedules """
self.schedules = ['ReturnHeader990x', ]
self.otherforms = []
for sked in self.raw_irs_dict['Return']['ReturnData'].keys():
if not sked.startswith("@"):
if sked in KNOWN_SCHEDULES:
... | [
"def",
"_set_schedules",
"(",
"self",
")",
":",
"self",
".",
"schedules",
"=",
"[",
"'ReturnHeader990x'",
",",
"]",
"self",
".",
"otherforms",
"=",
"[",
"]",
"for",
"sked",
"in",
"self",
".",
"raw_irs_dict",
"[",
"'Return'",
"]",
"[",
"'ReturnData'",
"]"... | Attach the known and unknown schedules | [
"Attach",
"the",
"known",
"and",
"unknown",
"schedules"
] | 00020529b789081329a31a2e30b5ee729ce7596a | https://github.com/jsfenfen/990-xml-reader/blob/00020529b789081329a31a2e30b5ee729ce7596a/irs_reader/filing.py#L101-L110 |
1,206 | jsfenfen/990-xml-reader | irs_reader/filing.py | Filing.get_parsed_sked | def get_parsed_sked(self, skedname):
""" Returns an array because multiple sked K's are allowed"""
if not self.processed:
raise Exception("Filing must be processed to return parsed sked")
if skedname in self.schedules:
matching_skeds = []
for sked in self.resu... | python | def get_parsed_sked(self, skedname):
""" Returns an array because multiple sked K's are allowed"""
if not self.processed:
raise Exception("Filing must be processed to return parsed sked")
if skedname in self.schedules:
matching_skeds = []
for sked in self.resu... | [
"def",
"get_parsed_sked",
"(",
"self",
",",
"skedname",
")",
":",
"if",
"not",
"self",
".",
"processed",
":",
"raise",
"Exception",
"(",
"\"Filing must be processed to return parsed sked\"",
")",
"if",
"skedname",
"in",
"self",
".",
"schedules",
":",
"matching_ske... | Returns an array because multiple sked K's are allowed | [
"Returns",
"an",
"array",
"because",
"multiple",
"sked",
"K",
"s",
"are",
"allowed"
] | 00020529b789081329a31a2e30b5ee729ce7596a | https://github.com/jsfenfen/990-xml-reader/blob/00020529b789081329a31a2e30b5ee729ce7596a/irs_reader/filing.py#L176-L187 |
1,207 | tus/tus-py-client | tusclient/uploader.py | Uploader.headers | def headers(self):
"""
Return headers of the uploader instance. This would include the headers of the
client instance.
"""
client_headers = getattr(self.client, 'headers', {})
return dict(self.DEFAULT_HEADERS, **client_headers) | python | def headers(self):
"""
Return headers of the uploader instance. This would include the headers of the
client instance.
"""
client_headers = getattr(self.client, 'headers', {})
return dict(self.DEFAULT_HEADERS, **client_headers) | [
"def",
"headers",
"(",
"self",
")",
":",
"client_headers",
"=",
"getattr",
"(",
"self",
".",
"client",
",",
"'headers'",
",",
"{",
"}",
")",
"return",
"dict",
"(",
"self",
".",
"DEFAULT_HEADERS",
",",
"*",
"*",
"client_headers",
")"
] | Return headers of the uploader instance. This would include the headers of the
client instance. | [
"Return",
"headers",
"of",
"the",
"uploader",
"instance",
".",
"This",
"would",
"include",
"the",
"headers",
"of",
"the",
"client",
"instance",
"."
] | 0e5856efcfae6fc281171359ce38488a70468993 | https://github.com/tus/tus-py-client/blob/0e5856efcfae6fc281171359ce38488a70468993/tusclient/uploader.py#L139-L145 |
1,208 | tus/tus-py-client | tusclient/uploader.py | Uploader.headers_as_list | def headers_as_list(self):
"""
Does the same as 'headers' except it is returned as a list.
"""
headers = self.headers
headers_list = ['{}: {}'.format(key, value) for key, value in iteritems(headers)]
return headers_list | python | def headers_as_list(self):
"""
Does the same as 'headers' except it is returned as a list.
"""
headers = self.headers
headers_list = ['{}: {}'.format(key, value) for key, value in iteritems(headers)]
return headers_list | [
"def",
"headers_as_list",
"(",
"self",
")",
":",
"headers",
"=",
"self",
".",
"headers",
"headers_list",
"=",
"[",
"'{}: {}'",
".",
"format",
"(",
"key",
",",
"value",
")",
"for",
"key",
",",
"value",
"in",
"iteritems",
"(",
"headers",
")",
"]",
"retur... | Does the same as 'headers' except it is returned as a list. | [
"Does",
"the",
"same",
"as",
"headers",
"except",
"it",
"is",
"returned",
"as",
"a",
"list",
"."
] | 0e5856efcfae6fc281171359ce38488a70468993 | https://github.com/tus/tus-py-client/blob/0e5856efcfae6fc281171359ce38488a70468993/tusclient/uploader.py#L148-L154 |
1,209 | tus/tus-py-client | tusclient/uploader.py | Uploader.get_offset | def get_offset(self):
"""
Return offset from tus server.
This is different from the instance attribute 'offset' because this makes an
http request to the tus server to retrieve the offset.
"""
resp = requests.head(self.url, headers=self.headers)
offset = resp.hea... | python | def get_offset(self):
"""
Return offset from tus server.
This is different from the instance attribute 'offset' because this makes an
http request to the tus server to retrieve the offset.
"""
resp = requests.head(self.url, headers=self.headers)
offset = resp.hea... | [
"def",
"get_offset",
"(",
"self",
")",
":",
"resp",
"=",
"requests",
".",
"head",
"(",
"self",
".",
"url",
",",
"headers",
"=",
"self",
".",
"headers",
")",
"offset",
"=",
"resp",
".",
"headers",
".",
"get",
"(",
"'upload-offset'",
")",
"if",
"offset... | Return offset from tus server.
This is different from the instance attribute 'offset' because this makes an
http request to the tus server to retrieve the offset. | [
"Return",
"offset",
"from",
"tus",
"server",
"."
] | 0e5856efcfae6fc281171359ce38488a70468993 | https://github.com/tus/tus-py-client/blob/0e5856efcfae6fc281171359ce38488a70468993/tusclient/uploader.py#L170-L182 |
1,210 | tus/tus-py-client | tusclient/uploader.py | Uploader.encode_metadata | def encode_metadata(self):
"""
Return list of encoded metadata as defined by the Tus protocol.
"""
encoded_list = []
for key, value in iteritems(self.metadata):
key_str = str(key) # dict keys may be of any object type.
# confirm that the key does not con... | python | def encode_metadata(self):
"""
Return list of encoded metadata as defined by the Tus protocol.
"""
encoded_list = []
for key, value in iteritems(self.metadata):
key_str = str(key) # dict keys may be of any object type.
# confirm that the key does not con... | [
"def",
"encode_metadata",
"(",
"self",
")",
":",
"encoded_list",
"=",
"[",
"]",
"for",
"key",
",",
"value",
"in",
"iteritems",
"(",
"self",
".",
"metadata",
")",
":",
"key_str",
"=",
"str",
"(",
"key",
")",
"# dict keys may be of any object type.",
"# confir... | Return list of encoded metadata as defined by the Tus protocol. | [
"Return",
"list",
"of",
"encoded",
"metadata",
"as",
"defined",
"by",
"the",
"Tus",
"protocol",
"."
] | 0e5856efcfae6fc281171359ce38488a70468993 | https://github.com/tus/tus-py-client/blob/0e5856efcfae6fc281171359ce38488a70468993/tusclient/uploader.py#L184-L199 |
1,211 | tus/tus-py-client | tusclient/uploader.py | Uploader.get_url | def get_url(self):
"""
Return the tus upload url.
If resumability is enabled, this would try to get the url from storage if available,
otherwise it would request a new upload url from the tus server.
"""
if self.store_url and self.url_storage:
key = self.fing... | python | def get_url(self):
"""
Return the tus upload url.
If resumability is enabled, this would try to get the url from storage if available,
otherwise it would request a new upload url from the tus server.
"""
if self.store_url and self.url_storage:
key = self.fing... | [
"def",
"get_url",
"(",
"self",
")",
":",
"if",
"self",
".",
"store_url",
"and",
"self",
".",
"url_storage",
":",
"key",
"=",
"self",
".",
"fingerprinter",
".",
"get_fingerprint",
"(",
"self",
".",
"get_file_stream",
"(",
")",
")",
"url",
"=",
"self",
"... | Return the tus upload url.
If resumability is enabled, this would try to get the url from storage if available,
otherwise it would request a new upload url from the tus server. | [
"Return",
"the",
"tus",
"upload",
"url",
"."
] | 0e5856efcfae6fc281171359ce38488a70468993 | https://github.com/tus/tus-py-client/blob/0e5856efcfae6fc281171359ce38488a70468993/tusclient/uploader.py#L201-L216 |
1,212 | tus/tus-py-client | tusclient/uploader.py | Uploader.create_url | def create_url(self):
"""
Return upload url.
Makes request to tus server to create a new upload url for the required file upload.
"""
headers = self.headers
headers['upload-length'] = str(self.file_size)
headers['upload-metadata'] = ','.join(self.encode_metadata(... | python | def create_url(self):
"""
Return upload url.
Makes request to tus server to create a new upload url for the required file upload.
"""
headers = self.headers
headers['upload-length'] = str(self.file_size)
headers['upload-metadata'] = ','.join(self.encode_metadata(... | [
"def",
"create_url",
"(",
"self",
")",
":",
"headers",
"=",
"self",
".",
"headers",
"headers",
"[",
"'upload-length'",
"]",
"=",
"str",
"(",
"self",
".",
"file_size",
")",
"headers",
"[",
"'upload-metadata'",
"]",
"=",
"','",
".",
"join",
"(",
"self",
... | Return upload url.
Makes request to tus server to create a new upload url for the required file upload. | [
"Return",
"upload",
"url",
"."
] | 0e5856efcfae6fc281171359ce38488a70468993 | https://github.com/tus/tus-py-client/blob/0e5856efcfae6fc281171359ce38488a70468993/tusclient/uploader.py#L219-L233 |
1,213 | tus/tus-py-client | tusclient/uploader.py | Uploader.request_length | def request_length(self):
"""
Return length of next chunk upload.
"""
remainder = self.stop_at - self.offset
return self.chunk_size if remainder > self.chunk_size else remainder | python | def request_length(self):
"""
Return length of next chunk upload.
"""
remainder = self.stop_at - self.offset
return self.chunk_size if remainder > self.chunk_size else remainder | [
"def",
"request_length",
"(",
"self",
")",
":",
"remainder",
"=",
"self",
".",
"stop_at",
"-",
"self",
".",
"offset",
"return",
"self",
".",
"chunk_size",
"if",
"remainder",
">",
"self",
".",
"chunk_size",
"else",
"remainder"
] | Return length of next chunk upload. | [
"Return",
"length",
"of",
"next",
"chunk",
"upload",
"."
] | 0e5856efcfae6fc281171359ce38488a70468993 | https://github.com/tus/tus-py-client/blob/0e5856efcfae6fc281171359ce38488a70468993/tusclient/uploader.py#L236-L241 |
1,214 | tus/tus-py-client | tusclient/uploader.py | Uploader.verify_upload | def verify_upload(self):
"""
Confirm that the last upload was sucessful.
Raises TusUploadFailed exception if the upload was not sucessful.
"""
if self.request.status_code == 204:
return True
else:
raise TusUploadFailed('', self.request.status_code,... | python | def verify_upload(self):
"""
Confirm that the last upload was sucessful.
Raises TusUploadFailed exception if the upload was not sucessful.
"""
if self.request.status_code == 204:
return True
else:
raise TusUploadFailed('', self.request.status_code,... | [
"def",
"verify_upload",
"(",
"self",
")",
":",
"if",
"self",
".",
"request",
".",
"status_code",
"==",
"204",
":",
"return",
"True",
"else",
":",
"raise",
"TusUploadFailed",
"(",
"''",
",",
"self",
".",
"request",
".",
"status_code",
",",
"self",
".",
... | Confirm that the last upload was sucessful.
Raises TusUploadFailed exception if the upload was not sucessful. | [
"Confirm",
"that",
"the",
"last",
"upload",
"was",
"sucessful",
".",
"Raises",
"TusUploadFailed",
"exception",
"if",
"the",
"upload",
"was",
"not",
"sucessful",
"."
] | 0e5856efcfae6fc281171359ce38488a70468993 | https://github.com/tus/tus-py-client/blob/0e5856efcfae6fc281171359ce38488a70468993/tusclient/uploader.py#L243-L251 |
1,215 | tus/tus-py-client | tusclient/uploader.py | Uploader.get_file_stream | def get_file_stream(self):
"""
Return a file stream instance of the upload.
"""
if self.file_stream:
self.file_stream.seek(0)
return self.file_stream
elif os.path.isfile(self.file_path):
return open(self.file_path, 'rb')
else:
... | python | def get_file_stream(self):
"""
Return a file stream instance of the upload.
"""
if self.file_stream:
self.file_stream.seek(0)
return self.file_stream
elif os.path.isfile(self.file_path):
return open(self.file_path, 'rb')
else:
... | [
"def",
"get_file_stream",
"(",
"self",
")",
":",
"if",
"self",
".",
"file_stream",
":",
"self",
".",
"file_stream",
".",
"seek",
"(",
"0",
")",
"return",
"self",
".",
"file_stream",
"elif",
"os",
".",
"path",
".",
"isfile",
"(",
"self",
".",
"file_path... | Return a file stream instance of the upload. | [
"Return",
"a",
"file",
"stream",
"instance",
"of",
"the",
"upload",
"."
] | 0e5856efcfae6fc281171359ce38488a70468993 | https://github.com/tus/tus-py-client/blob/0e5856efcfae6fc281171359ce38488a70468993/tusclient/uploader.py#L253-L263 |
1,216 | tus/tus-py-client | tusclient/uploader.py | Uploader.file_size | def file_size(self):
"""
Return size of the file.
"""
stream = self.get_file_stream()
stream.seek(0, os.SEEK_END)
return stream.tell() | python | def file_size(self):
"""
Return size of the file.
"""
stream = self.get_file_stream()
stream.seek(0, os.SEEK_END)
return stream.tell() | [
"def",
"file_size",
"(",
"self",
")",
":",
"stream",
"=",
"self",
".",
"get_file_stream",
"(",
")",
"stream",
".",
"seek",
"(",
"0",
",",
"os",
".",
"SEEK_END",
")",
"return",
"stream",
".",
"tell",
"(",
")"
] | Return size of the file. | [
"Return",
"size",
"of",
"the",
"file",
"."
] | 0e5856efcfae6fc281171359ce38488a70468993 | https://github.com/tus/tus-py-client/blob/0e5856efcfae6fc281171359ce38488a70468993/tusclient/uploader.py#L266-L272 |
1,217 | tus/tus-py-client | tusclient/uploader.py | Uploader.upload | def upload(self, stop_at=None):
"""
Perform file upload.
Performs continous upload of chunks of the file. The size uploaded at each cycle is
the value of the attribute 'chunk_size'.
:Args:
- stop_at (Optional[int]):
Determines at what offset value th... | python | def upload(self, stop_at=None):
"""
Perform file upload.
Performs continous upload of chunks of the file. The size uploaded at each cycle is
the value of the attribute 'chunk_size'.
:Args:
- stop_at (Optional[int]):
Determines at what offset value th... | [
"def",
"upload",
"(",
"self",
",",
"stop_at",
"=",
"None",
")",
":",
"self",
".",
"stop_at",
"=",
"stop_at",
"or",
"self",
".",
"file_size",
"while",
"self",
".",
"offset",
"<",
"self",
".",
"stop_at",
":",
"self",
".",
"upload_chunk",
"(",
")",
"els... | Perform file upload.
Performs continous upload of chunks of the file. The size uploaded at each cycle is
the value of the attribute 'chunk_size'.
:Args:
- stop_at (Optional[int]):
Determines at what offset value the upload should stop. If not specified this
... | [
"Perform",
"file",
"upload",
"."
] | 0e5856efcfae6fc281171359ce38488a70468993 | https://github.com/tus/tus-py-client/blob/0e5856efcfae6fc281171359ce38488a70468993/tusclient/uploader.py#L274-L292 |
1,218 | tus/tus-py-client | tusclient/uploader.py | Uploader.upload_chunk | def upload_chunk(self):
"""
Upload chunk of file.
"""
self._retried = 0
self._do_request()
self.offset = int(self.request.response_headers.get('upload-offset'))
if self.log_func:
msg = '{} bytes uploaded ...'.format(self.offset)
self.log_fu... | python | def upload_chunk(self):
"""
Upload chunk of file.
"""
self._retried = 0
self._do_request()
self.offset = int(self.request.response_headers.get('upload-offset'))
if self.log_func:
msg = '{} bytes uploaded ...'.format(self.offset)
self.log_fu... | [
"def",
"upload_chunk",
"(",
"self",
")",
":",
"self",
".",
"_retried",
"=",
"0",
"self",
".",
"_do_request",
"(",
")",
"self",
".",
"offset",
"=",
"int",
"(",
"self",
".",
"request",
".",
"response_headers",
".",
"get",
"(",
"'upload-offset'",
")",
")"... | Upload chunk of file. | [
"Upload",
"chunk",
"of",
"file",
"."
] | 0e5856efcfae6fc281171359ce38488a70468993 | https://github.com/tus/tus-py-client/blob/0e5856efcfae6fc281171359ce38488a70468993/tusclient/uploader.py#L294-L303 |
1,219 | tus/tus-py-client | tusclient/storage/filestorage.py | FileStorage.get_item | def get_item(self, key):
"""
Return the tus url of a file, identified by the key specified.
:Args:
- key[str]: The unique id for the stored item (in this case, url)
:Returns: url[str]
"""
result = self._db.search(self._urls.key == key)
return result[0... | python | def get_item(self, key):
"""
Return the tus url of a file, identified by the key specified.
:Args:
- key[str]: The unique id for the stored item (in this case, url)
:Returns: url[str]
"""
result = self._db.search(self._urls.key == key)
return result[0... | [
"def",
"get_item",
"(",
"self",
",",
"key",
")",
":",
"result",
"=",
"self",
".",
"_db",
".",
"search",
"(",
"self",
".",
"_urls",
".",
"key",
"==",
"key",
")",
"return",
"result",
"[",
"0",
"]",
".",
"get",
"(",
"'url'",
")",
"if",
"result",
"... | Return the tus url of a file, identified by the key specified.
:Args:
- key[str]: The unique id for the stored item (in this case, url)
:Returns: url[str] | [
"Return",
"the",
"tus",
"url",
"of",
"a",
"file",
"identified",
"by",
"the",
"key",
"specified",
"."
] | 0e5856efcfae6fc281171359ce38488a70468993 | https://github.com/tus/tus-py-client/blob/0e5856efcfae6fc281171359ce38488a70468993/tusclient/storage/filestorage.py#L14-L23 |
1,220 | tus/tus-py-client | tusclient/storage/filestorage.py | FileStorage.set_item | def set_item(self, key, url):
"""
Store the url value under the unique key.
:Args:
- key[str]: The unique id to which the item (in this case, url) would be stored.
- value[str]: The actual url value to be stored.
"""
if self._db.search(self._urls.key == k... | python | def set_item(self, key, url):
"""
Store the url value under the unique key.
:Args:
- key[str]: The unique id to which the item (in this case, url) would be stored.
- value[str]: The actual url value to be stored.
"""
if self._db.search(self._urls.key == k... | [
"def",
"set_item",
"(",
"self",
",",
"key",
",",
"url",
")",
":",
"if",
"self",
".",
"_db",
".",
"search",
"(",
"self",
".",
"_urls",
".",
"key",
"==",
"key",
")",
":",
"self",
".",
"_db",
".",
"update",
"(",
"{",
"'url'",
":",
"url",
"}",
",... | Store the url value under the unique key.
:Args:
- key[str]: The unique id to which the item (in this case, url) would be stored.
- value[str]: The actual url value to be stored. | [
"Store",
"the",
"url",
"value",
"under",
"the",
"unique",
"key",
"."
] | 0e5856efcfae6fc281171359ce38488a70468993 | https://github.com/tus/tus-py-client/blob/0e5856efcfae6fc281171359ce38488a70468993/tusclient/storage/filestorage.py#L25-L36 |
1,221 | tus/tus-py-client | tusclient/request.py | TusRequest.perform | def perform(self):
"""
Perform actual request.
"""
try:
host = '{}://{}'.format(self._url.scheme, self._url.netloc)
path = self._url.geturl().replace(host, '', 1)
chunk = self.file.read(self._content_length)
if self._upload_checksum:
... | python | def perform(self):
"""
Perform actual request.
"""
try:
host = '{}://{}'.format(self._url.scheme, self._url.netloc)
path = self._url.geturl().replace(host, '', 1)
chunk = self.file.read(self._content_length)
if self._upload_checksum:
... | [
"def",
"perform",
"(",
"self",
")",
":",
"try",
":",
"host",
"=",
"'{}://{}'",
".",
"format",
"(",
"self",
".",
"_url",
".",
"scheme",
",",
"self",
".",
"_url",
".",
"netloc",
")",
"path",
"=",
"self",
".",
"_url",
".",
"geturl",
"(",
")",
".",
... | Perform actual request. | [
"Perform",
"actual",
"request",
"."
] | 0e5856efcfae6fc281171359ce38488a70468993 | https://github.com/tus/tus-py-client/blob/0e5856efcfae6fc281171359ce38488a70468993/tusclient/request.py#L56-L84 |
1,222 | tus/tus-py-client | tusclient/fingerprint/fingerprint.py | Fingerprint.get_fingerprint | def get_fingerprint(self, fs):
"""
Return a unique fingerprint string value based on the file stream recevied
:Args:
- fs[file]: The file stream instance of the file for which a fingerprint would be generated.
:Returns: fingerprint[str]
"""
hasher = hashlib.m... | python | def get_fingerprint(self, fs):
"""
Return a unique fingerprint string value based on the file stream recevied
:Args:
- fs[file]: The file stream instance of the file for which a fingerprint would be generated.
:Returns: fingerprint[str]
"""
hasher = hashlib.m... | [
"def",
"get_fingerprint",
"(",
"self",
",",
"fs",
")",
":",
"hasher",
"=",
"hashlib",
".",
"md5",
"(",
")",
"# we encode the content to avoid python 3 uncicode errors",
"buf",
"=",
"self",
".",
"_encode_data",
"(",
"fs",
".",
"read",
"(",
"self",
".",
"BLOCK_S... | Return a unique fingerprint string value based on the file stream recevied
:Args:
- fs[file]: The file stream instance of the file for which a fingerprint would be generated.
:Returns: fingerprint[str] | [
"Return",
"a",
"unique",
"fingerprint",
"string",
"value",
"based",
"on",
"the",
"file",
"stream",
"recevied"
] | 0e5856efcfae6fc281171359ce38488a70468993 | https://github.com/tus/tus-py-client/blob/0e5856efcfae6fc281171359ce38488a70468993/tusclient/fingerprint/fingerprint.py#L15-L29 |
1,223 | Yelp/threat_intel | threat_intel/util/http.py | SSLAdapter.init_poolmanager | def init_poolmanager(self, connections, maxsize, block=False, **pool_kwargs):
"""Called to initialize the HTTPAdapter when no proxy is used."""
try:
pool_kwargs['ssl_version'] = ssl.PROTOCOL_TLS
except AttributeError:
pool_kwargs['ssl_version'] = ssl.PROTOCOL_SSLv23
... | python | def init_poolmanager(self, connections, maxsize, block=False, **pool_kwargs):
"""Called to initialize the HTTPAdapter when no proxy is used."""
try:
pool_kwargs['ssl_version'] = ssl.PROTOCOL_TLS
except AttributeError:
pool_kwargs['ssl_version'] = ssl.PROTOCOL_SSLv23
... | [
"def",
"init_poolmanager",
"(",
"self",
",",
"connections",
",",
"maxsize",
",",
"block",
"=",
"False",
",",
"*",
"*",
"pool_kwargs",
")",
":",
"try",
":",
"pool_kwargs",
"[",
"'ssl_version'",
"]",
"=",
"ssl",
".",
"PROTOCOL_TLS",
"except",
"AttributeError",... | Called to initialize the HTTPAdapter when no proxy is used. | [
"Called",
"to",
"initialize",
"the",
"HTTPAdapter",
"when",
"no",
"proxy",
"is",
"used",
"."
] | 60eef841d7cca115ec7857aeb9c553b72b694851 | https://github.com/Yelp/threat_intel/blob/60eef841d7cca115ec7857aeb9c553b72b694851/threat_intel/util/http.py#L51-L57 |
1,224 | Yelp/threat_intel | threat_intel/util/http.py | SSLAdapter.proxy_manager_for | def proxy_manager_for(self, proxy, **proxy_kwargs):
"""Called to initialize the HTTPAdapter when a proxy is used."""
try:
proxy_kwargs['ssl_version'] = ssl.PROTOCOL_TLS
except AttributeError:
proxy_kwargs['ssl_version'] = ssl.PROTOCOL_SSLv23
return super(SSLAdapte... | python | def proxy_manager_for(self, proxy, **proxy_kwargs):
"""Called to initialize the HTTPAdapter when a proxy is used."""
try:
proxy_kwargs['ssl_version'] = ssl.PROTOCOL_TLS
except AttributeError:
proxy_kwargs['ssl_version'] = ssl.PROTOCOL_SSLv23
return super(SSLAdapte... | [
"def",
"proxy_manager_for",
"(",
"self",
",",
"proxy",
",",
"*",
"*",
"proxy_kwargs",
")",
":",
"try",
":",
"proxy_kwargs",
"[",
"'ssl_version'",
"]",
"=",
"ssl",
".",
"PROTOCOL_TLS",
"except",
"AttributeError",
":",
"proxy_kwargs",
"[",
"'ssl_version'",
"]",
... | Called to initialize the HTTPAdapter when a proxy is used. | [
"Called",
"to",
"initialize",
"the",
"HTTPAdapter",
"when",
"a",
"proxy",
"is",
"used",
"."
] | 60eef841d7cca115ec7857aeb9c553b72b694851 | https://github.com/Yelp/threat_intel/blob/60eef841d7cca115ec7857aeb9c553b72b694851/threat_intel/util/http.py#L59-L65 |
1,225 | Yelp/threat_intel | threat_intel/util/http.py | RateLimiter.make_calls | def make_calls(self, num_calls=1):
"""Adds appropriate sleep to avoid making too many calls.
Args:
num_calls: int the number of calls which will be made
"""
self._cull()
while self._outstanding_calls + num_calls > self._max_calls_per_second:
time.sleep(0)... | python | def make_calls(self, num_calls=1):
"""Adds appropriate sleep to avoid making too many calls.
Args:
num_calls: int the number of calls which will be made
"""
self._cull()
while self._outstanding_calls + num_calls > self._max_calls_per_second:
time.sleep(0)... | [
"def",
"make_calls",
"(",
"self",
",",
"num_calls",
"=",
"1",
")",
":",
"self",
".",
"_cull",
"(",
")",
"while",
"self",
".",
"_outstanding_calls",
"+",
"num_calls",
">",
"self",
".",
"_max_calls_per_second",
":",
"time",
".",
"sleep",
"(",
"0",
")",
"... | Adds appropriate sleep to avoid making too many calls.
Args:
num_calls: int the number of calls which will be made | [
"Adds",
"appropriate",
"sleep",
"to",
"avoid",
"making",
"too",
"many",
"calls",
"."
] | 60eef841d7cca115ec7857aeb9c553b72b694851 | https://github.com/Yelp/threat_intel/blob/60eef841d7cca115ec7857aeb9c553b72b694851/threat_intel/util/http.py#L79-L91 |
1,226 | Yelp/threat_intel | threat_intel/util/http.py | RateLimiter._cull | def _cull(self):
"""Remove calls more than 1 second old from the queue."""
right_now = time.time()
cull_from = -1
for index in range(len(self._call_times)):
if right_now - self._call_times[index].time >= 1.0:
cull_from = index
self._outstandin... | python | def _cull(self):
"""Remove calls more than 1 second old from the queue."""
right_now = time.time()
cull_from = -1
for index in range(len(self._call_times)):
if right_now - self._call_times[index].time >= 1.0:
cull_from = index
self._outstandin... | [
"def",
"_cull",
"(",
"self",
")",
":",
"right_now",
"=",
"time",
".",
"time",
"(",
")",
"cull_from",
"=",
"-",
"1",
"for",
"index",
"in",
"range",
"(",
"len",
"(",
"self",
".",
"_call_times",
")",
")",
":",
"if",
"right_now",
"-",
"self",
".",
"_... | Remove calls more than 1 second old from the queue. | [
"Remove",
"calls",
"more",
"than",
"1",
"second",
"old",
"from",
"the",
"queue",
"."
] | 60eef841d7cca115ec7857aeb9c553b72b694851 | https://github.com/Yelp/threat_intel/blob/60eef841d7cca115ec7857aeb9c553b72b694851/threat_intel/util/http.py#L93-L106 |
1,227 | Yelp/threat_intel | threat_intel/util/http.py | AvailabilityLimiter.map_with_retries | def map_with_retries(self, requests, responses_for_requests):
"""Provides session-based retry functionality
:param requests: A collection of Request objects.
:param responses_for_requests: Dictionary mapping of requests to responses
:param max_retries: The maximum number of retries to p... | python | def map_with_retries(self, requests, responses_for_requests):
"""Provides session-based retry functionality
:param requests: A collection of Request objects.
:param responses_for_requests: Dictionary mapping of requests to responses
:param max_retries: The maximum number of retries to p... | [
"def",
"map_with_retries",
"(",
"self",
",",
"requests",
",",
"responses_for_requests",
")",
":",
"retries",
"=",
"[",
"]",
"response_futures",
"=",
"[",
"preq",
".",
"callable",
"(",
")",
"for",
"preq",
"in",
"requests",
"]",
"for",
"request",
",",
"respo... | Provides session-based retry functionality
:param requests: A collection of Request objects.
:param responses_for_requests: Dictionary mapping of requests to responses
:param max_retries: The maximum number of retries to perform per session
:param args: Additional arguments to pass into... | [
"Provides",
"session",
"-",
"based",
"retry",
"functionality"
] | 60eef841d7cca115ec7857aeb9c553b72b694851 | https://github.com/Yelp/threat_intel/blob/60eef841d7cca115ec7857aeb9c553b72b694851/threat_intel/util/http.py#L122-L151 |
1,228 | Yelp/threat_intel | threat_intel/util/http.py | MultiRequest.multi_get | def multi_get(self, urls, query_params=None, to_json=True):
"""Issue multiple GET requests.
Args:
urls - A string URL or list of string URLs
query_params - None, a dict, or a list of dicts representing the query params
to_json - A boolean, should the responses be ret... | python | def multi_get(self, urls, query_params=None, to_json=True):
"""Issue multiple GET requests.
Args:
urls - A string URL or list of string URLs
query_params - None, a dict, or a list of dicts representing the query params
to_json - A boolean, should the responses be ret... | [
"def",
"multi_get",
"(",
"self",
",",
"urls",
",",
"query_params",
"=",
"None",
",",
"to_json",
"=",
"True",
")",
":",
"return",
"self",
".",
"_multi_request",
"(",
"MultiRequest",
".",
"_VERB_GET",
",",
"urls",
",",
"query_params",
",",
"data",
"=",
"No... | Issue multiple GET requests.
Args:
urls - A string URL or list of string URLs
query_params - None, a dict, or a list of dicts representing the query params
to_json - A boolean, should the responses be returned as JSON blobs
Returns:
a list of dicts if to_... | [
"Issue",
"multiple",
"GET",
"requests",
"."
] | 60eef841d7cca115ec7857aeb9c553b72b694851 | https://github.com/Yelp/threat_intel/blob/60eef841d7cca115ec7857aeb9c553b72b694851/threat_intel/util/http.py#L203-L218 |
1,229 | Yelp/threat_intel | threat_intel/util/http.py | MultiRequest.multi_post | def multi_post(self, urls, query_params=None, data=None, to_json=True, send_as_file=False):
"""Issue multiple POST requests.
Args:
urls - A string URL or list of string URLs
query_params - None, a dict, or a list of dicts representing the query params
data - None, a ... | python | def multi_post(self, urls, query_params=None, data=None, to_json=True, send_as_file=False):
"""Issue multiple POST requests.
Args:
urls - A string URL or list of string URLs
query_params - None, a dict, or a list of dicts representing the query params
data - None, a ... | [
"def",
"multi_post",
"(",
"self",
",",
"urls",
",",
"query_params",
"=",
"None",
",",
"data",
"=",
"None",
",",
"to_json",
"=",
"True",
",",
"send_as_file",
"=",
"False",
")",
":",
"return",
"self",
".",
"_multi_request",
"(",
"MultiRequest",
".",
"_VERB... | Issue multiple POST requests.
Args:
urls - A string URL or list of string URLs
query_params - None, a dict, or a list of dicts representing the query params
data - None, a dict or string, or a list of dicts and strings representing the data body.
to_json - A bool... | [
"Issue",
"multiple",
"POST",
"requests",
"."
] | 60eef841d7cca115ec7857aeb9c553b72b694851 | https://github.com/Yelp/threat_intel/blob/60eef841d7cca115ec7857aeb9c553b72b694851/threat_intel/util/http.py#L220-L237 |
1,230 | Yelp/threat_intel | threat_intel/util/http.py | MultiRequest._zip_request_params | def _zip_request_params(self, urls, query_params, data):
"""Massages inputs and returns a list of 3-tuples zipping them up.
This is all the smarts behind deciding how many requests to issue.
It's fine for an input to have 0, 1, or a list of values.
If there are two inputs each with a li... | python | def _zip_request_params(self, urls, query_params, data):
"""Massages inputs and returns a list of 3-tuples zipping them up.
This is all the smarts behind deciding how many requests to issue.
It's fine for an input to have 0, 1, or a list of values.
If there are two inputs each with a li... | [
"def",
"_zip_request_params",
"(",
"self",
",",
"urls",
",",
"query_params",
",",
"data",
")",
":",
"# Everybody gets to be a list",
"if",
"not",
"isinstance",
"(",
"urls",
",",
"list",
")",
":",
"urls",
"=",
"[",
"urls",
"]",
"if",
"not",
"isinstance",
"(... | Massages inputs and returns a list of 3-tuples zipping them up.
This is all the smarts behind deciding how many requests to issue.
It's fine for an input to have 0, 1, or a list of values.
If there are two inputs each with a list of values, the cardinality of those lists much match.
Ar... | [
"Massages",
"inputs",
"and",
"returns",
"a",
"list",
"of",
"3",
"-",
"tuples",
"zipping",
"them",
"up",
"."
] | 60eef841d7cca115ec7857aeb9c553b72b694851 | https://github.com/Yelp/threat_intel/blob/60eef841d7cca115ec7857aeb9c553b72b694851/threat_intel/util/http.py#L272-L322 |
1,231 | Yelp/threat_intel | threat_intel/util/http.py | MultiRequest._wait_for_response | def _wait_for_response(self, requests):
"""Issues a batch of requests and waits for the responses.
If some of the requests fail it will retry the failed ones up to `_max_retry` times.
Args:
requests - A list of requests
Returns:
A list of `requests.models.Respons... | python | def _wait_for_response(self, requests):
"""Issues a batch of requests and waits for the responses.
If some of the requests fail it will retry the failed ones up to `_max_retry` times.
Args:
requests - A list of requests
Returns:
A list of `requests.models.Respons... | [
"def",
"_wait_for_response",
"(",
"self",
",",
"requests",
")",
":",
"failed_requests",
"=",
"[",
"]",
"responses_for_requests",
"=",
"OrderedDict",
".",
"fromkeys",
"(",
"requests",
")",
"for",
"retry",
"in",
"range",
"(",
"self",
".",
"_max_retry",
")",
":... | Issues a batch of requests and waits for the responses.
If some of the requests fail it will retry the failed ones up to `_max_retry` times.
Args:
requests - A list of requests
Returns:
A list of `requests.models.Response` objects
Raises:
InvalidReque... | [
"Issues",
"a",
"batch",
"of",
"requests",
"and",
"waits",
"for",
"the",
"responses",
".",
"If",
"some",
"of",
"the",
"requests",
"fail",
"it",
"will",
"retry",
"the",
"failed",
"ones",
"up",
"to",
"_max_retry",
"times",
"."
] | 60eef841d7cca115ec7857aeb9c553b72b694851 | https://github.com/Yelp/threat_intel/blob/60eef841d7cca115ec7857aeb9c553b72b694851/threat_intel/util/http.py#L324-L380 |
1,232 | Yelp/threat_intel | threat_intel/util/http.py | MultiRequest._convert_to_json | def _convert_to_json(self, response):
"""Converts response to JSON.
If the response cannot be converted to JSON then `None` is returned.
Args:
response - An object of type `requests.models.Response`
Returns:
Response in JSON format if the response can be converte... | python | def _convert_to_json(self, response):
"""Converts response to JSON.
If the response cannot be converted to JSON then `None` is returned.
Args:
response - An object of type `requests.models.Response`
Returns:
Response in JSON format if the response can be converte... | [
"def",
"_convert_to_json",
"(",
"self",
",",
"response",
")",
":",
"try",
":",
"return",
"response",
".",
"json",
"(",
")",
"except",
"ValueError",
":",
"logging",
".",
"warning",
"(",
"'Expected response in JSON format from {0} but the actual response text is: {1}'",
... | Converts response to JSON.
If the response cannot be converted to JSON then `None` is returned.
Args:
response - An object of type `requests.models.Response`
Returns:
Response in JSON format if the response can be converted to JSON. `None` otherwise. | [
"Converts",
"response",
"to",
"JSON",
".",
"If",
"the",
"response",
"cannot",
"be",
"converted",
"to",
"JSON",
"then",
"None",
"is",
"returned",
"."
] | 60eef841d7cca115ec7857aeb9c553b72b694851 | https://github.com/Yelp/threat_intel/blob/60eef841d7cca115ec7857aeb9c553b72b694851/threat_intel/util/http.py#L382-L397 |
1,233 | Yelp/threat_intel | threat_intel/util/http.py | MultiRequest._multi_request | def _multi_request(self, verb, urls, query_params, data, to_json=True, send_as_file=False):
"""Issues multiple batches of simultaneous HTTP requests and waits for responses.
Args:
verb - MultiRequest._VERB_POST or MultiRequest._VERB_GET
urls - A string URL or list of string URLs... | python | def _multi_request(self, verb, urls, query_params, data, to_json=True, send_as_file=False):
"""Issues multiple batches of simultaneous HTTP requests and waits for responses.
Args:
verb - MultiRequest._VERB_POST or MultiRequest._VERB_GET
urls - A string URL or list of string URLs... | [
"def",
"_multi_request",
"(",
"self",
",",
"verb",
",",
"urls",
",",
"query_params",
",",
"data",
",",
"to_json",
"=",
"True",
",",
"send_as_file",
"=",
"False",
")",
":",
"if",
"not",
"urls",
":",
"raise",
"InvalidRequestError",
"(",
"'No URL supplied'",
... | Issues multiple batches of simultaneous HTTP requests and waits for responses.
Args:
verb - MultiRequest._VERB_POST or MultiRequest._VERB_GET
urls - A string URL or list of string URLs
query_params - None, a dict, or a list of dicts representing the query params
... | [
"Issues",
"multiple",
"batches",
"of",
"simultaneous",
"HTTP",
"requests",
"and",
"waits",
"for",
"responses",
"."
] | 60eef841d7cca115ec7857aeb9c553b72b694851 | https://github.com/Yelp/threat_intel/blob/60eef841d7cca115ec7857aeb9c553b72b694851/threat_intel/util/http.py#L399-L443 |
1,234 | Yelp/threat_intel | threat_intel/util/http.py | MultiRequest.error_handling | def error_handling(cls, fn):
"""Decorator to handle errors"""
def wrapper(*args, **kwargs):
try:
result = fn(*args, **kwargs)
return result
except InvalidRequestError as e:
write_exception(e)
if hasattr(e, 'request'... | python | def error_handling(cls, fn):
"""Decorator to handle errors"""
def wrapper(*args, **kwargs):
try:
result = fn(*args, **kwargs)
return result
except InvalidRequestError as e:
write_exception(e)
if hasattr(e, 'request'... | [
"def",
"error_handling",
"(",
"cls",
",",
"fn",
")",
":",
"def",
"wrapper",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"try",
":",
"result",
"=",
"fn",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
"return",
"result",
"except",
"Inval... | Decorator to handle errors | [
"Decorator",
"to",
"handle",
"errors"
] | 60eef841d7cca115ec7857aeb9c553b72b694851 | https://github.com/Yelp/threat_intel/blob/60eef841d7cca115ec7857aeb9c553b72b694851/threat_intel/util/http.py#L450-L465 |
1,235 | glasslion/redlock | redlock/lock.py | RedLock.acquire_node | def acquire_node(self, node):
"""
acquire a single redis node
"""
try:
return node.set(self.resource, self.lock_key, nx=True, px=self.ttl)
except (redis.exceptions.ConnectionError, redis.exceptions.TimeoutError):
return False | python | def acquire_node(self, node):
"""
acquire a single redis node
"""
try:
return node.set(self.resource, self.lock_key, nx=True, px=self.ttl)
except (redis.exceptions.ConnectionError, redis.exceptions.TimeoutError):
return False | [
"def",
"acquire_node",
"(",
"self",
",",
"node",
")",
":",
"try",
":",
"return",
"node",
".",
"set",
"(",
"self",
".",
"resource",
",",
"self",
".",
"lock_key",
",",
"nx",
"=",
"True",
",",
"px",
"=",
"self",
".",
"ttl",
")",
"except",
"(",
"redi... | acquire a single redis node | [
"acquire",
"a",
"single",
"redis",
"node"
] | 7f873cc362eefa7f7adee8d4913e64f87c1fd1c9 | https://github.com/glasslion/redlock/blob/7f873cc362eefa7f7adee8d4913e64f87c1fd1c9/redlock/lock.py#L135-L142 |
1,236 | glasslion/redlock | redlock/lock.py | RedLock.release_node | def release_node(self, node):
"""
release a single redis node
"""
# use the lua script to release the lock in a safe way
try:
node._release_script(keys=[self.resource], args=[self.lock_key])
except (redis.exceptions.ConnectionError, redis.exceptions.TimeoutErr... | python | def release_node(self, node):
"""
release a single redis node
"""
# use the lua script to release the lock in a safe way
try:
node._release_script(keys=[self.resource], args=[self.lock_key])
except (redis.exceptions.ConnectionError, redis.exceptions.TimeoutErr... | [
"def",
"release_node",
"(",
"self",
",",
"node",
")",
":",
"# use the lua script to release the lock in a safe way",
"try",
":",
"node",
".",
"_release_script",
"(",
"keys",
"=",
"[",
"self",
".",
"resource",
"]",
",",
"args",
"=",
"[",
"self",
".",
"lock_key"... | release a single redis node | [
"release",
"a",
"single",
"redis",
"node"
] | 7f873cc362eefa7f7adee8d4913e64f87c1fd1c9 | https://github.com/glasslion/redlock/blob/7f873cc362eefa7f7adee8d4913e64f87c1fd1c9/redlock/lock.py#L144-L152 |
1,237 | Yelp/threat_intel | threat_intel/alexaranking.py | AlexaRankingApi._extract_response_xml | def _extract_response_xml(self, domain, response):
"""Extract XML content of an HTTP response into dictionary format.
Args:
response: HTML Response objects
Returns:
A dictionary: {alexa-ranking key : alexa-ranking value}.
"""
attributes = {}
alexa... | python | def _extract_response_xml(self, domain, response):
"""Extract XML content of an HTTP response into dictionary format.
Args:
response: HTML Response objects
Returns:
A dictionary: {alexa-ranking key : alexa-ranking value}.
"""
attributes = {}
alexa... | [
"def",
"_extract_response_xml",
"(",
"self",
",",
"domain",
",",
"response",
")",
":",
"attributes",
"=",
"{",
"}",
"alexa_keys",
"=",
"{",
"'POPULARITY'",
":",
"'TEXT'",
",",
"'REACH'",
":",
"'RANK'",
",",
"'RANK'",
":",
"'DELTA'",
"}",
"try",
":",
"xml... | Extract XML content of an HTTP response into dictionary format.
Args:
response: HTML Response objects
Returns:
A dictionary: {alexa-ranking key : alexa-ranking value}. | [
"Extract",
"XML",
"content",
"of",
"an",
"HTTP",
"response",
"into",
"dictionary",
"format",
"."
] | 60eef841d7cca115ec7857aeb9c553b72b694851 | https://github.com/Yelp/threat_intel/blob/60eef841d7cca115ec7857aeb9c553b72b694851/threat_intel/alexaranking.py#L74-L95 |
1,238 | Yelp/threat_intel | threat_intel/alexaranking.py | AlexaRankingApi._bulk_cache_lookup | def _bulk_cache_lookup(self, api_name, keys):
"""Performes a bulk cache lookup and returns a tuple with the results
found and the keys missing in the cache. If cached is not configured
it will return an empty dictionary of found results and the initial
list of keys.
Args:
... | python | def _bulk_cache_lookup(self, api_name, keys):
"""Performes a bulk cache lookup and returns a tuple with the results
found and the keys missing in the cache. If cached is not configured
it will return an empty dictionary of found results and the initial
list of keys.
Args:
... | [
"def",
"_bulk_cache_lookup",
"(",
"self",
",",
"api_name",
",",
"keys",
")",
":",
"if",
"self",
".",
"_cache",
":",
"responses",
"=",
"self",
".",
"_cache",
".",
"bulk_lookup",
"(",
"api_name",
",",
"keys",
")",
"missing_keys",
"=",
"[",
"key",
"for",
... | Performes a bulk cache lookup and returns a tuple with the results
found and the keys missing in the cache. If cached is not configured
it will return an empty dictionary of found results and the initial
list of keys.
Args:
api_name: a string name of the API.
key... | [
"Performes",
"a",
"bulk",
"cache",
"lookup",
"and",
"returns",
"a",
"tuple",
"with",
"the",
"results",
"found",
"and",
"the",
"keys",
"missing",
"in",
"the",
"cache",
".",
"If",
"cached",
"is",
"not",
"configured",
"it",
"will",
"return",
"an",
"empty",
... | 60eef841d7cca115ec7857aeb9c553b72b694851 | https://github.com/Yelp/threat_intel/blob/60eef841d7cca115ec7857aeb9c553b72b694851/threat_intel/alexaranking.py#L97-L114 |
1,239 | Yelp/threat_intel | threat_intel/util/api_cache.py | ApiCache._write_cache_to_file | def _write_cache_to_file(self):
"""Write the contents of the cache to a file on disk."""
with(open(self._cache_file_name, 'w')) as fp:
fp.write(simplejson.dumps(self._cache)) | python | def _write_cache_to_file(self):
"""Write the contents of the cache to a file on disk."""
with(open(self._cache_file_name, 'w')) as fp:
fp.write(simplejson.dumps(self._cache)) | [
"def",
"_write_cache_to_file",
"(",
"self",
")",
":",
"with",
"(",
"open",
"(",
"self",
".",
"_cache_file_name",
",",
"'w'",
")",
")",
"as",
"fp",
":",
"fp",
".",
"write",
"(",
"simplejson",
".",
"dumps",
"(",
"self",
".",
"_cache",
")",
")"
] | Write the contents of the cache to a file on disk. | [
"Write",
"the",
"contents",
"of",
"the",
"cache",
"to",
"a",
"file",
"on",
"disk",
"."
] | 60eef841d7cca115ec7857aeb9c553b72b694851 | https://github.com/Yelp/threat_intel/blob/60eef841d7cca115ec7857aeb9c553b72b694851/threat_intel/util/api_cache.py#L42-L45 |
1,240 | Yelp/threat_intel | threat_intel/util/api_cache.py | ApiCache._read_cache_from_file | def _read_cache_from_file(self):
"""Read the contents of the cache from a file on disk."""
cache = {}
try:
with(open(self._cache_file_name, 'r')) as fp:
contents = fp.read()
cache = simplejson.loads(contents)
except (IOError, JSONDecodeError):
... | python | def _read_cache_from_file(self):
"""Read the contents of the cache from a file on disk."""
cache = {}
try:
with(open(self._cache_file_name, 'r')) as fp:
contents = fp.read()
cache = simplejson.loads(contents)
except (IOError, JSONDecodeError):
... | [
"def",
"_read_cache_from_file",
"(",
"self",
")",
":",
"cache",
"=",
"{",
"}",
"try",
":",
"with",
"(",
"open",
"(",
"self",
".",
"_cache_file_name",
",",
"'r'",
")",
")",
"as",
"fp",
":",
"contents",
"=",
"fp",
".",
"read",
"(",
")",
"cache",
"=",... | Read the contents of the cache from a file on disk. | [
"Read",
"the",
"contents",
"of",
"the",
"cache",
"from",
"a",
"file",
"on",
"disk",
"."
] | 60eef841d7cca115ec7857aeb9c553b72b694851 | https://github.com/Yelp/threat_intel/blob/60eef841d7cca115ec7857aeb9c553b72b694851/threat_intel/util/api_cache.py#L47-L58 |
1,241 | Yelp/threat_intel | threat_intel/util/api_cache.py | ApiCache.bulk_lookup | def bulk_lookup(self, api_name, keys):
"""Perform lookup on an enumerable of keys.
Args:
api_name: a string name of the API. Keys and values are segmented by api_name.
keys: an enumerable of string keys.
"""
cached_data = {}
for key in keys:
... | python | def bulk_lookup(self, api_name, keys):
"""Perform lookup on an enumerable of keys.
Args:
api_name: a string name of the API. Keys and values are segmented by api_name.
keys: an enumerable of string keys.
"""
cached_data = {}
for key in keys:
... | [
"def",
"bulk_lookup",
"(",
"self",
",",
"api_name",
",",
"keys",
")",
":",
"cached_data",
"=",
"{",
"}",
"for",
"key",
"in",
"keys",
":",
"value",
"=",
"self",
".",
"lookup_value",
"(",
"api_name",
",",
"key",
")",
"if",
"value",
"is",
"not",
"None",... | Perform lookup on an enumerable of keys.
Args:
api_name: a string name of the API. Keys and values are segmented by api_name.
keys: an enumerable of string keys. | [
"Perform",
"lookup",
"on",
"an",
"enumerable",
"of",
"keys",
"."
] | 60eef841d7cca115ec7857aeb9c553b72b694851 | https://github.com/Yelp/threat_intel/blob/60eef841d7cca115ec7857aeb9c553b72b694851/threat_intel/util/api_cache.py#L82-L95 |
1,242 | 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 |
1,243 | 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 |
1,244 | 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 |
1,245 | 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 |
1,246 | 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 |
1,247 | 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 |
1,248 | 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 |
1,249 | 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 |
1,250 | 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 |
1,251 | 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 |
1,252 | 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 |
1,253 | 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 |
1,254 | 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 |
1,255 | 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 |
1,256 | 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 |
1,257 | 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 |
1,258 | 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 |
1,259 | 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 |
1,260 | 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 |
1,261 | 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 |
1,262 | 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 |
1,263 | 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 |
1,264 | 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 |
1,265 | 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 |
1,266 | 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 |
1,267 | 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",
")",
":",
"\"\"\"\n Returns True if lang is a RTL language\n\n args:\n lang (str): The language to be checked\n\n Returns:\n True if lang is an RTL language... | 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 |
1,268 | 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 |
1,269 | 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 |
1,270 | 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 |
1,271 | 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",
")",
":",
"# 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 package.",
"# FIRS... | 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 |
1,272 | 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 |
1,273 | 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 |
1,274 | 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 |
1,275 | 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 |
1,276 | 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 |
1,277 | 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",
"# List of .po files that are the product of a merge (see gene... | 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 |
1,278 | 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",
"# Use relative paths to make output less noisy.",
"rfile",
"=",
"os",
".",
"path",
".",
"relpath",
"(",
"filename",
",",
"locale_dir",
")",
"out",
",",
"e... | 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 |
1,279 | 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",
")",
":",
"\"\"\"Is this tag one that can change with the language?\"\"\"",
"if",
"tag",
".",
"startswith",
"(",
"\"&\"",
")",
":",
"return",
"True",
"if",
"any",
"(",
"x",
"i... | 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 |
1,280 | 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",
")",
":",
"# 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",
":",
"... | 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 |
1,281 | 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 |
1,282 | 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 |
1,283 | 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 |
1,284 | 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",
")",
":",
"# Reading in the .po file and saving it again fixes redundancies.",
"pomsgs",
"=",
"pofile",
"(",
"pofile_path",
")",
"# The msgcat tool marks the metadata as fuzzy, but it's ok as it is.",
"pomsgs",
".",
"metadata_is_fuzzy",
"=... | 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 |
1,285 | 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 |
1,286 | 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 |
1,287 | 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 |
1,288 | 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 |
1,289 | 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 |
1,290 | 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 |
1,291 | 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 |
1,292 | 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 |
1,293 | 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",
"(",
")",
":",
"# Happens when we have a supported locale that doesn't exist in T... | 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 |
1,294 | 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 |
1,295 | 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 |
1,296 | 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 |
1,297 | 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 |
1,298 | 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 |
1,299 | 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 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.