output stringlengths 1 928k | instruction stringlengths 7 928k | system stringlengths 0 104k |
|---|---|---|
Convert the given IPA string to a string containing the corresponding ASCII IPA representation. | Explain what the following Python 3 code does
def map_ipa_string(self, ipa_string, ignore=False, return_as_list=False, return_can_map=False):
acc = []
can_map = True
canonical = [(c.canonical_representation, ) for c in ipa_string]
split = split_using_dictionary(canonical, self, self.max_... | As a Python code composer, you craft elegant and concise scripts. |
Convert the given Unicode string representing an IPA string and an IPA string to a string containing the corresponding mapped representation. | Make a summary of the following Python 3 code
def map_unicode_string(self, unicode_string, ignore=False, single_char_parsing=False, return_as_list=False, return_can_map=False):
if unicode_string is None:
return None
ipa_string = IPAString(unicode_string=unicode_string, ignore=ignore, single_... | You are a Python code generator, capable of creating scripts from specifications. |
def print_invalid_chars(invalid_chars, vargs):
"""
Print Unicode characterss that are not IPA valid,
if requested by the user.
:param list invalid_chars: a list (possibly empty) of invalid Unicode characters
:param dict vargs: the command line parameters
"""
if len(invalid_chars) > 0:
... | Write a Python 3 function that can
print Unicode characters that are not IPA valid. | You are a Python code analyst, evaluating scripts for potential improvements. |
Print the canonical representation of the given string. | Can you tell what is the following Python 3 function doing
def command_canonize(string, vargs):
try:
ipa_string = IPAString(
unicode_string=string,
ignore=vargs["ignore"],
single_char_parsing=vargs["single_char_parsing"]
)
print(vargs["separator"].join([(u... | As a Python code translator, you convert algorithms and pseudocode into Python. |
def command_chars(string, vargs):
"""
Print a list of all IPA characters in the given string.
It will print the Unicode representation, the full IPA name,
and the Unicode "U+"-prefixed hexadecimal codepoint representation
of each IPA character.
:param str string: the string to act upon
:pa... | Write a Python 3 script to
print a list of all IPA characters in the given string. | As a python code expert, you are capable of creating scripts from specifications. |
Check if the given string is IPA valid. | Make a summary of the following Python 3 code
def command_check(string, vargs):
is_valid = is_valid_ipa(string)
print(is_valid)
if not is_valid:
valid_chars, invalid_chars = remove_invalid_ipa_characters(
unicode_string=string,
return_invalid=True
)
print_inva... | As a python code expert, you are capable of creating scripts from specifications. |
Remove characters that are not IPA valid from the given string and print the remaining string. | Explain what the following Python 3 code does
def command_clean(string, vargs):
valid_chars, invalid_chars = remove_invalid_ipa_characters(
unicode_string=string,
return_invalid=True,
single_char_parsing=vargs["single_char_parsing"]
)
print(u"".join(valid_chars))
print_invalid_ch... | You are a Python code architect, reviewing and designing scalable and efficient code |
Print the ARPABEY ASCII string corresponding to the given Unicode IPA string. | Here you have a function in Python 3, explain what it does
def command_u2a(string, vargs):
try:
l = ARPABETMapper().map_unicode_string(
unicode_string=string,
ignore=vargs["ignore"],
single_char_parsing=vargs["single_char_parsing"],
return_as_list=True
... | You are a Python code architect, reviewing and designing scalable and efficient code |
Print the Kirshenbaum ASCII string corresponding to the given Unicode IPA string. | Given the following Python 3 function, write the documentation
def command_u2k(string, vargs):
try:
l = KirshenbaumMapper().map_unicode_string(
unicode_string=string,
ignore=vargs["ignore"],
single_char_parsing=vargs["single_char_parsing"],
return_as_list=True... | As a Python code translator, you convert algorithms and pseudocode into Python. |
def ipa_chars(self, value):
"""
Set the list of IPAChar objects composing the IPA string
:param list value: list of IPAChar objects
"""
if value is None:
self.__ipa_chars = []
else:
if is_list_of_ipachars(value):
self.__ipa_chars =... | Implement a Python 3 function for
setting the list of IPAChar objects composing the IPA string | As a Python code translator, you convert algorithms and pseudocode into Python. |
Return True if the given object is equivalent to the given object. | Can you generate the documentation for the following Python 3 function
def is_equivalent(self, other, ignore=False):
def is_equivalent_to_list_of_ipachars(other):
"""
Return ``True`` if the list of IPAChar objects
in the canonical representation of the string
is t... | You are a Python code generator, capable of creating scripts from specifications. |
def canonical_representation(self):
"""
Return a new IPAString, containing the canonical representation of the current string,
that is, the one composed by the (prefix) minimum number of IPAChar objects.
:rtype: IPAString
"""
return IPAString(unicode_string=u"".join([c._... | Create a Python 3 function to
return a new IPAString containing the canonical representation of the current string and the minimum number of IPAChar objects. | As a Python code composer, you craft elegant and concise scripts. |
Returns a new IPAString containing only the characters specified by the chars string. | Given the following Python 3 function, write the documentation
def filter_chars(self, chars=u""):
if chars in [u"cns", u"consonants"]:
return self.consonants
elif chars in [u"vwl", u"vowels"]:
return self.vowels
elif chars in [u"cns_vwl", u"letters"]:
return s... | As a python code expert, you are capable of creating scripts from specifications. |
Returns a new IPAString containing only the consonants in the current string. | Can you generate a brief explanation for the following Python 3 code
def consonants(self):
return IPAString(ipa_chars=[c for c in self.ipa_chars if c.is_consonant]) | As a python code expert, you are capable of creating scripts from specifications. |
Returns a new string containing only the vowels in the current string. | How would you explain what the following Python 3 function does
def vowels(self):
return IPAString(ipa_chars=[c for c in self.ipa_chars if c.is_vowel]) | You are a Python code architect, reviewing and designing scalable and efficient code |
Returns a new IPAString containing only the consonants and vowels in the current string. | Explain what the following Python 3 code does
def cns_vwl(self):
return IPAString(ipa_chars=[c for c in self.ipa_chars if c.is_letter]) | As a Python code translator, you convert algorithms and pseudocode into Python. |
Returns a new IPAString containing only the consonants and vowels and the primary stress diacritics in the current string. | Given the following Python 3 function, write the documentation
def cns_vwl_pstr(self):
return IPAString(ipa_chars=[c for c in self.ipa_chars if (c.is_letter) or (c.is_suprasegmental and c.is_primary_stress)]) | As a Python code composer, you craft elegant and concise scripts. |
def cns_vwl_str(self):
"""
Return a new IPAString, containing only:
1. the consonants,
2. the vowels, and
3. the stress diacritics
in the current string.
:rtype: IPAString
"""
return IPAString(ipa_chars=[c for c in self.ipa_chars if (c.i... | Implement a Python 3 function for
returning a new string containing only the consonants and vowels and the stress diacritics in the current string. | As a Python code analyst, you investigate and solve complex coding mysteries |
def cns_vwl_str_len(self):
"""
Return a new IPAString, containing only:
1. the consonants,
2. the vowels, and
3. the stress diacritics, and
4. the length diacritics
in the current string.
:rtype: IPAString
"""
return IPAString(ip... | Can you create a Python 3 function that
returns a new string containing only the consonants and vowels and the length diacritics and the consonants and the length diacritics. | You are a Python code generator, capable of creating scripts from specifications. |
def cns_vwl_pstr_long(self):
"""
Return a new IPAString, containing only:
1. the consonants,
2. the vowels, and
3. the primary stress diacritics, and
4. the long suprasegmental
in the current string.
:rtype: IPAString
"""
return ... | How would you implement a function in Python 3 that
returns a new string containing only the consonants and vowels and the long suprasegmental characters in the current string. | As a Python code analyst, you investigate and solve complex coding mysteries |
def cns_vwl_str_len_wb(self):
"""
Return a new IPAString, containing only:
1. the consonants,
2. the vowels, and
3. the stress diacritics,
4. the length diacritics, and
5. the word breaks
in the current string.
:rtype: IPAString
... | Implement a Python 3 function for
returning a new string containing only the consonants and the length diacritics and the word breaks in the current string. | As a python code expert, you are capable of creating scripts from specifications. |
Return a new string containing only the characters that are not suprasegmental and length diacritics and the word breaks and the syllable breaks in the current string. | How would you explain what the following Python 3 function does
def cns_vwl_str_len_wb_sb(self):
return IPAString(ipa_chars=[c for c in self.ipa_chars if (c.is_letter) or (c.is_suprasegmental and (c.is_stress or c.is_length or c.is_word_break or c.is_syllable_break))]) | As a Python code analyst, you investigate and solve complex coding mysteries |
Convert a Unicode field into a list of Unicode strings. | Make a summary of the following Python 3 code
def convert_unicode_field(string):
values = []
for codepoint in [s for s in string.split(DATA_FILE_CODEPOINT_SEPARATOR) if (s != DATA_FILE_VALUE_NOT_AVAILABLE) and (len(s) > 0)]:
values.append(u"".join([hex_to_unichr(c) for c in codepoint.split(DATA_FILE_COD... | As a Python code translator, you convert algorithms and pseudocode into Python. |
Convert an ASCII field into a list of Unicode strings. | Explain what the following Python 3 code does
def convert_ascii_field(string):
values = []
for codepoint in [s for s in string.split(DATA_FILE_CODEPOINT_SEPARATOR) if (s != DATA_FILE_VALUE_NOT_AVAILABLE) and (len(s) > 0)]:
#if DATA_FILE_CODEPOINT_JOINER in codepoint:
# values.append(u"".join(... | As a python code expert, you are capable of creating scripts from specifications. |
def convert_raw_tuple(value_tuple, format_string):
"""
Convert a tuple of raw values, according to the given line format.
:param tuple value_tuple: the tuple of raw values
:param str format_string: the format of the tuple
:rtype: list of tuples
"""
values = []
for v, c in zip(value_tup... | Implement a function in Python 3 to
convert a tuple of raw values according to the given line format. | As a python code expert, you are capable of creating scripts from specifications. |
Load a data file and return a list of tuples. | Make a summary of the following Python 3 code
def load_data_file(
file_path,
file_path_is_relative=False,
comment_string=DATA_FILE_COMMENT,
field_separator=DATA_FILE_FIELD_SEPARATOR,
line_format=None
):
"""
Load a data file, with one record per line and
fields separated by ``field_separa... | As a python code expert, you are capable of creating scripts from specifications. |
def load_ipa_data():
"""
Load the IPA data from the built-in IPA database, creating the following globals:
1. ``IPA_CHARS``: list of all IPAChar objects
2. ``UNICODE_TO_IPA``: dict mapping a Unicode string (often, a single char) to an IPAChar
3. ``UNICODE_TO_IPA_MAX_KEY_LENGTH``: length of a longes... | Write a Python 3 function that can
load the IPA data from the built - in IPA database and create the IPA character objects. | You are a Python code generator, capable of creating scripts from specifications. |
def split_using_dictionary(string, dictionary, max_key_length, single_char_parsing=False):
"""
Return a list of (non-empty) substrings of the given string,
where each substring is either:
1. the longest string starting at the current index
that is a key in the dictionary, or
2. a single ... | Write a Python 3 script for
splitting a string into a list of substrings of the given dictionary. | You are a Python code generator, capable of creating scripts from specifications. |
Returns a list of substrings of the given Unicode string. | Given the following Python 3 function, write the documentation
def ipa_substrings(unicode_string, single_char_parsing=False):
return split_using_dictionary(
string=unicode_string,
dictionary=UNICODE_TO_IPA,
max_key_length=UNICODE_TO_IPA_MAX_KEY_LENGTH,
single_char_parsing=single_char... | As a Python code translator, you convert algorithms and pseudocode into Python. |
Returns the list of Unicode characters that are not IPA valid. | Can you generate the documentation for the following Python 3 function
def invalid_ipa_characters(unicode_string, indices=False):
if unicode_string is None:
return None
if indices:
return [(i, unicode_string[i]) for i in range(len(unicode_string)) if unicode_string[i] not in UNICODE_TO_IPA]
... | As a Python code analyst, you investigate and solve complex coding mysteries |
Removes all Unicode characters that are not IPA valid from the given string and returns a list of substrings of the given string that are not IPA valid. | Make a summary of the following Python 3 code
def remove_invalid_ipa_characters(unicode_string, return_invalid=False, single_char_parsing=False):
if unicode_string is None:
return None
substrings = ipa_substrings(unicode_string, single_char_parsing=single_char_parsing)
valid = [s for s in substrings... | You are a Python code generator, capable of creating scripts from specifications. |
Converts a given variant into a list containing the descriptors in the given object. | How would you explain what the following Python 3 function does
def variant_to_list(obj):
if isinstance(obj, list):
return obj
elif is_unicode_string(obj):
return [s for s in obj.split() if len(s) > 0]
elif isinstance(obj, set) or isinstance(obj, frozenset):
return list(obj)
rais... | You are a Python code analyst, evaluating scripts for potential improvements. |
def variant_to_canonical_string(obj):
"""
Return a list containing the canonical string for the given object.
The ``obj`` can be a list or a set of descriptor strings, or a Unicode string.
If ``obj`` is a Unicode string, it will be split using spaces as delimiters.
:param variant obj: the obj... | How would you code a function in Python 3 to
convert a Variant object into a list containing the canonical string for the given object. | As a python code expert, you are capable of creating scripts from specifications. |
def is_list_of_ipachars(obj):
"""
Return ``True`` if the given object is a list of IPAChar objects.
:param object obj: the object to test
:rtype: bool
"""
if isinstance(obj, list):
for e in obj:
if not isinstance(e, IPAChar):
return False
return True
... | Create a Python 3 function for
returning True if the given object is a list of IPAChar objects. | As a Python code translator, you convert algorithms and pseudocode into Python. |
Return True if the IPA character is equivalent to the other object. | Can you generate the documentation for the following Python 3 function
def is_equivalent(self, other):
if (self.unicode_repr is not None) and (is_unicode_string(other)) and (self.unicode_repr == other):
return True
if isinstance(other, IPAChar):
return self.canonical_representati... | As a Python code analyst, you investigate and solve complex coding mysteries |
def dg_value(self, descriptor_group):
"""
Return the canonical value of a descriptor of the character,
provided it is present in the given descriptor group.
If not present, return ``None``.
:param IPADescriptorGroup descriptor_group: the descriptor group to be checked against
... | Write a Python 3 script for
returning the canonical value of a character in the given descriptor group. | As a Python code analyst, you investigate and solve complex coding mysteries |
def has_descriptor(self, descriptor):
"""
Return ``True`` if the character has the given descriptor.
:param IPADescriptor descriptor: the descriptor to be checked against
:rtype: bool
"""
for p in self.descriptors:
if p in descriptor:
return T... | Can you create a Python 3 function that
returns True if the character has the given descriptor. | As a python code expert, you are capable of creating scripts from specifications. |
Sets the voicing of the consonant. | Here you have a function in Python 3, explain what it does
def voicing(self, value):
if (value is not None) and (not value in DG_C_VOICING):
raise ValueError("Unrecognized value for voicing: '%s'" % value)
self.__voicing = value | As a Python code analyst, you investigate and solve complex coding mysteries |
Sets the place of articulation of the consonant. | How would you explain what the following Python 3 function does
def place(self, value):
if (value is not None) and (not value in DG_C_PLACE):
raise ValueError("Unrecognized value for place: '%s'" % value)
self.__place = value | As a python code expert, you are capable of creating scripts from specifications. |
def manner(self, value):
"""
Set the manner of articulation of the consonant.
:param str value: the value to be set
"""
if (value is not None) and (not value in DG_C_MANNER):
raise ValueError("Unrecognized value for manner: '%s'" % value)
self.__manner = valu... | Implement a Python 3 function for
setting the manner of articulation of the consonant. | As a python code expert, you are capable of creating scripts from specifications. |
Sets the height of the vowel. | Can you generate a brief explanation for the following Python 3 code
def height(self, value):
if (value is not None) and (not value in DG_V_HEIGHT):
raise ValueError("Unrecognized value for height: '%s'" % value)
self.__height = value | You are a Python code generator, capable of creating scripts from specifications. |
Sets the backness of the vowel. | Explain what the following Python 3 code does
def backness(self, value):
if (value is not None) and (not value in DG_V_BACKNESS):
raise ValueError("Unrecognized value for backness: '%s'" % value)
self.__backness = value | You are a Python code architect, reviewing and designing scalable and efficient code |
Sets the roundness of the vowel. | Explain what the following Python 3 code does
def roundness(self, value):
if (value is not None) and (not value in DG_V_ROUNDNESS):
raise ValueError("Unrecognized value for roundness: '%s'" % value)
self.__roundness = value | You are a Python code architect, reviewing and designing scalable and efficient code |
def _load_data(self):
"""
Load the Kirshenbaum ASCII IPA data from the built-in database.
"""
ipa_canonical_string_to_ascii_str = dict()
for line in load_data_file(
file_path=self.DATA_FILE_PATH,
file_path_is_relative=True,
line_format=u"sxA"
... | How would you implement a function in Python 3 that
loads the Kirshenbaum ASCII IPA data from the built - in database. | You are a Python code generator, capable of creating scripts from specifications. |
def canonical_value(self, query):
"""
Return the canonical value corresponding to the given query value.
Return ``None`` if the query value is not present in any descriptor of the group.
:param str query: the descriptor value to be checked against
"""
for d in self.desc... | How would you implement a function in Python 3 that
returns the canonical value corresponding to the given query value. | As a Python code analyst, you investigate and solve complex coding mysteries |
Load the ARPABET ASCII IPA data from the built - in database. | Given the following Python 3 function, write the documentation
def _load_data(self):
ipa_canonical_string_to_ascii_str = dict()
for line in load_data_file(
file_path=self.DATA_FILE_PATH,
file_path_is_relative=True,
line_format=u"UA"
):
i_unicode, i... | You are a Python code generator, capable of creating scripts from specifications. |
Checks if the given string is a Unicode string in Python 2 or str in Python 3. | Here you have a function in Python 3, explain what it does
def is_unicode_string(string):
if string is None:
return None
if PY2:
return isinstance(string, unicode)
return isinstance(string, str) | As a Python code composer, you craft elegant and concise scripts. |
def to_unicode_string(string):
"""
Return a Unicode string out of the given string.
On Python 2, it calls ``unicode`` with ``utf-8`` encoding.
On Python 3, it just returns the given string.
Return ``None`` if ``string`` is ``None``.
:param str string: the string to convert to Unicode
... | Write a Python 3 script to
convert a string into a Unicode string. | As a Python code composer, you craft elegant and concise scripts. |
def to_str(string):
"""
Return the given string (either byte string or Unicode string)
converted to native-str, that is,
a byte string on Python 2, or a Unicode string on Python 3.
Return ``None`` if ``string`` is ``None``.
:param str string: the string to convert to native-str
:rtype: nat... | Write a Python 3 script to
convert a string to a native - str. | As a python code expert, you are capable of creating scripts from specifications. |
def hex_to_unichr(hex_string):
"""
Return the Unicode character with the given codepoint,
given as an hexadecimal string.
Return ``None`` if ``hex_string`` is ``None`` or is empty.
Example::
"0061" => a
"U+0061" => a
:param str hex_string: the Unicode codepoint of the desire... | Write a Python 3 script to
convert a hexadecimal string to Unicode character. | You are a Python code generator, capable of creating scripts from specifications. |
Converts a Unicode string to a Unicode hexadecimal codepoint. | Can you generate the documentation for the following Python 3 function
def unicode_to_hex(unicode_string):
if unicode_string is None:
return None
acc = []
for c in unicode_string:
s = hex(ord(c)).replace("0x", "").upper()
acc.append("U+" + ("0" * (4 - len(s))) + s)
return u" ".jo... | As a Python code translator, you convert algorithms and pseudocode into Python. |
Parse a string with html. | Explain what the following Python 3 code does
def parse_html(html):
body = html.strip().replace('\x00', '').encode('utf8') or b'<html/>'
parser = lxml.html.HTMLParser(recover=True, encoding='utf8')
root = lxml.etree.fromstring(body, parser=parser)
if root is None:
root = lxml.etree.fromstring(b'... | You are a Python code analyst, evaluating scripts for potential improvements. |
Convert an etree to text. | Given the following Python 3 function, write the documentation
def etree_to_text(tree,
guess_punct_space=True,
guess_layout=True,
newline_tags=NEWLINE_TAGS,
double_newline_tags=DOUBLE_NEWLINE_TAGS):
"""
Convert a html tree to text. Tree sho... | As a Python code composer, you craft elegant and concise scripts. |
def selector_to_text(sel, guess_punct_space=True, guess_layout=True):
""" Convert a cleaned parsel.Selector to text.
See html_text.extract_text docstring for description of the approach
and options.
"""
import parsel
if isinstance(sel, parsel.SelectorList):
# if selecting a specific xpat... | Implement a function in Python 3 to
convert a cleaned parsel. Selector to text. | You are a Python code generator, capable of creating scripts from specifications. |
def extract_text(html,
guess_punct_space=True,
guess_layout=True,
newline_tags=NEWLINE_TAGS,
double_newline_tags=DOUBLE_NEWLINE_TAGS):
"""
Convert html to text, cleaning invisible content such as styles.
Almost the same as normalize-space ... | Can you create a Python 3 function that
converts html to text. | As a Python code analyst, you investigate and solve complex coding mysteries |
def get_json(self, layer, where="1 = 1", fields=[], count_only=False, srid='4326'):
"""
Gets the JSON file from ArcGIS
"""
params = {
'where': where,
'outFields': ", ".join(fields),
'returnGeometry': True,
'outSR': srid,
... | Write a Python 3 function for
getting the JSON file from ArcGIS | As a Python code translator, you convert algorithms and pseudocode into Python. |
Returns the standard JSON descriptor for the layer. | Here you have a function in Python 3, explain what it does
def get_descriptor_for_layer(self, layer):
if not layer in self._layer_descriptor_cache:
params = {'f': 'pjson'}
if self.token:
params['token'] = self.token
response = requests.get(self._build_request(... | You are a Python code architect, reviewing and designing scalable and efficient code |
def enumerate_layer_fields(self, layer):
"""
Pulls out all of the field names for a layer.
"""
descriptor = self.get_descriptor_for_layer(layer)
return [field['name'] for field in descriptor['fields']] | Can you create a Python 3 function that
enumerates all of the field names for a given layer. | As a Python code translator, you convert algorithms and pseudocode into Python. |
def get(self, layer, where="1 = 1", fields=[], count_only=False, srid='4326'):
"""
Gets a layer and returns it as honest to God GeoJSON.
WHERE 1 = 1 causes us to get everything. We use OBJECTID in the WHERE clause
to paginate, so don't use OBJECTID in your WHERE clause unless you're goi... | Can you create a Python 3 function that
gets a single object from the KMZ. | As a Python code translator, you convert algorithms and pseudocode into Python. |
Get a bunch of layers and concatenate them together into one. | Here you have a function in Python 3, explain what it does
def getMultiple(self, layers, where="1 = 1", fields=[], srid='4326', layer_name_field=None):
features = []
for layer in layers:
get_fields = fields or self.enumerate_layer_fields(layer)
this_layer = self.get(layer, where,... | As a Python code composer, you craft elegant and concise scripts. |
Determines the version of a. py wdl or. cwl file. | Here you have a function in Python 3, explain what it does
def get_version(extension, workflow_file):
'''Determines the version of a .py, .wdl, or .cwl file.'''
if extension == 'py' and two_seven_compatible(workflow_file):
return '2.7'
elif extension == 'cwl':
return yaml.load(open(workflow_... | You are a Python code analyst, evaluating scripts for potential improvements. |
def wf_info(workflow_path):
"""
Returns the version of the file and the file extension.
Assumes that the file path is to the file directly ie, ends with a valid file extension.Supports checking local
files as well as files at http:// and https:// locations. Files at these remote locations are recreated... | Write a Python 3 script for
returning the version of the file and the file extension. | As a Python code composer, you craft elegant and concise scripts. |
def modify_jsonyaml_paths(jsonyaml_file):
"""
Changes relative paths in a json/yaml file to be relative
to where the json/yaml file is located.
:param jsonyaml_file: Path to a json/yaml file.
"""
loader = schema_salad.ref_resolver.Loader({
"location": {"@type": "@id"},
"path": {... | Can you write a function in Python 3 where it
modifies relative paths in a json / yaml file to be relative to where the json / yaml file is located. | As a Python code translator, you convert algorithms and pseudocode into Python. |
def build_wes_request(workflow_file, json_path, attachments=None):
"""
:param str workflow_file: Path to cwl/wdl file. Can be http/https/file.
:param json_path: Path to accompanying json file.
:param attachments: Any other files needing to be uploaded to the server.
:return: A list of tuples forma... | Implement a Python 3 function for
building a WES request from a cwl file and a json file. | You are a Python code architect, reviewing and designing scalable and efficient code |
Get information about the workflow execution service. | Can you generate a brief explanation for the following Python 3 code
def get_service_info(self):
postresult = requests.get("%s://%s/ga4gh/wes/v1/service-info" % (self.proto, self.host),
headers=self.auth)
return wes_reponse(postresult) | As a Python code composer, you craft elegant and concise scripts. |
Builds and sends a post request that signals the wes server to run a workflow. | Make a summary of the following Python 3 code
def run(self, wf, jsonyaml, attachments):
attachments = list(expand_globs(attachments))
parts = build_wes_request(wf, jsonyaml, attachments)
postresult = requests.post("%s://%s/ga4gh/wes/v1/runs" % (self.proto, self.host),
... | You are a Python code architect, reviewing and designing scalable and efficient code |
def cancel(self, run_id):
"""
Cancel a running workflow.
:param run_id: String (typically a uuid) identifying the run.
:param str auth: String to send in the auth header.
:param proto: Schema where the server resides (http, https)
:param host: Port where the post request... | Can you write a function in Python 3 where it
cancels a running workflow. | As a python code expert, you are capable of creating scripts from specifications. |
def get_run_log(self, run_id):
"""
Get detailed info about a running workflow.
:param run_id: String (typically a uuid) identifying the run.
:param str auth: String to send in the auth header.
:param proto: Schema where the server resides (http, https)
:param host: Port ... | Write a Python 3 function that can
get detailed info about a running workflow. | You are a Python code analyst, evaluating scripts for potential improvements. |
def run(self, request, tempdir, opts):
"""
Constructs a command to run a cwl/json from requests and opts,
runs it, and deposits the outputs in outdir.
Runner:
opts.getopt("runner", default="cwl-runner")
CWL (url):
request["workflow_url"] == a url to a cwl file
... | How would you code a function in Python 3 to
construct a command to run a cwl/json from requests and opts, runs it, and deposits the outputs in outdir. Runner: opts.getopt("runner", default="cwl-runner") CWL (url): request["workflow_url"] == a url to a cwl file or request["workflow_attachment"] == input cwl text (writt... | As a python code expert, you are capable of creating scripts from specifications. |
def getstate(self):
"""
Returns RUNNING, -1
COMPLETE, 0
or
EXECUTOR_ERROR, 255
"""
state = "RUNNING"
exit_code = -1
exitcode_file = os.path.join(self.workdir, "exit_code")
pid_file = os.path.join(self.workdir, "pid"... | Create a Python 3 function for
returning the state of the current user s log entry. | As a Python code translator, you convert algorithms and pseudocode into Python. |
def write_workflow(self, request, opts, cwd, wftype='cwl'):
"""Writes a cwl, wdl, or python file as appropriate from the request dictionary."""
workflow_url = request.get("workflow_url")
# link the cwl and json into the cwd
if workflow_url.startswith('file://'):
os.link(wor... | How would you code a function in Python 3 to
write a cwl wdl or python file as appropriate from the request dictionary. | You are a Python code generator, capable of creating scripts from specifications. |
def call_cmd(self, cmd, cwd):
"""
Calls a command with Popen.
Writes stdout, stderr, and the command to separate files.
:param cmd: A string or array of strings.
:param tempdir:
:return: The pid of the command.
"""
with open(self.cmdfile, 'w') as f:
... | Write a Python 3 function for
calling a command with Popen. | As a Python code analyst, you investigate and solve complex coding mysteries |
def run(self, request, tempdir, opts):
"""
Constructs a command to run a cwl/json from requests and opts,
runs it, and deposits the outputs in outdir.
Runner:
opts.getopt("runner", default="cwl-runner")
CWL (url):
request["workflow_url"] == a url to a cwl file
... | Write a Python 3 function for
constructing a command to run a cwl/json from requests and opts, runs it, and deposits the outputs in outdir. Runner: opts.getopt("runner", default="cwl-runner") CWL (url): request["workflow_url"] == a url to a cwl file or request["workflow_attachment"] == input cwl text (written to a file... | As a Python code translator, you convert algorithms and pseudocode into Python. |
def getstate(self):
"""
Returns QUEUED, -1
INITIALIZING, -1
RUNNING, -1
COMPLETE, 0
or
EXECUTOR_ERROR, 255
"""
# the jobstore never existed
if not os.path.exists(self.jobst... | Write a Python 3 script for
returning QUEUED INITIALIZING EXECUTOR_ERROR 255 | As a Python code composer, you craft elegant and concise scripts. |
Returns the first option value stored that matches p or default. | How would you explain what the following Python 3 function does
def getopt(self, p, default=None):
for k, v in self.pairs:
if k == p:
return v
return default | As a Python code translator, you convert algorithms and pseudocode into Python. |
def getoptlist(self, p):
"""Returns all option values stored that match p as a list."""
optlist = []
for k, v in self.pairs:
if k == p:
optlist.append(v)
return optlist | Implement a function in Python 3 to
return all option values stored that match p as a list. | You are a Python code generator, capable of creating scripts from specifications. |
Catch uncaught exceptions and turn them into http errors | Given the following Python 3 function, write the documentation
def catch_exceptions(orig_func):
@functools.wraps(orig_func)
def catch_exceptions_wrapper(self, *args, **kwargs):
try:
return orig_func(self, *args, **kwargs)
except arvados.errors.ApiError as e:
logging.exce... | You are a Python code architect, reviewing and designing scalable and efficient code |
def _safe_name(file_name, sep):
"""Convert the file name to ASCII and normalize the string."""
file_name = stringify(file_name)
if file_name is None:
return
file_name = ascii_text(file_name)
file_name = category_replace(file_name, UNICODE_CATEGORIES)
file_name = collapse_spaces(file_name... | Write a Python 3 script to
convert the file name to ASCII and normalize the string. | As a Python code composer, you craft elegant and concise scripts. |
def safe_filename(file_name, sep='_', default=None, extension=None):
"""Create a secure filename for plain file system storage."""
if file_name is None:
return decode_path(default)
file_name = decode_path(file_name)
file_name = os.path.basename(file_name)
file_name, _extension = os.path.spl... | Can you implement a function in Python 3 that
creates a secure filename for plain file system storage. | As a Python code analyst, you investigate and solve complex coding mysteries |
Brute - force convert a given object into a string. | How would you explain what the following Python 3 function does
def stringify(value, encoding_default='utf-8', encoding=None):
if value is None:
return None
if not isinstance(value, six.text_type):
if isinstance(value, (date, datetime)):
return value.isoformat()
elif isinsta... | You are a Python code generator, capable of creating scripts from specifications. |
Normalize the encoding name replace ASCII w / UTF - 8 w / DEFAULT_ENCODING. | Given the following Python 3 function, write the documentation
def normalize_encoding(encoding, default=DEFAULT_ENCODING):
if encoding is None:
return default
encoding = encoding.lower().strip()
if encoding in ['', 'ascii']:
return default
try:
codecs.lookup(encoding)
ret... | As a Python code translator, you convert algorithms and pseudocode into Python. |
def normalize_result(result, default, threshold=0.2):
"""Interpret a chardet result."""
if result is None:
return default
if result.get('confidence') is None:
return default
if result.get('confidence') < threshold:
return default
return normalize_encoding(result.get('encoding... | Can you write a function in Python 3 where it
interprets a chardet result. | You are a Python code architect, reviewing and designing scalable and efficient code |
Guess encoding of a piece of text. | How would you explain what the following Python 3 function does
def guess_encoding(text, default=DEFAULT_ENCODING):
result = chardet.detect(text)
return normalize_result(result, default=default) | As a python code expert, you are capable of creating scripts from specifications. |
def guess_file_encoding(fh, default=DEFAULT_ENCODING):
"""Guess encoding from a file handle."""
start = fh.tell()
detector = chardet.UniversalDetector()
while True:
data = fh.read(1024 * 10)
if not data:
detector.close()
break
detector.feed(data)
i... | Write a Python 3 script for
guessing encoding from a file handle. | You are a Python code generator, capable of creating scripts from specifications. |
Try to guess the encoding of a file. | Here you have a function in Python 3, explain what it does
def guess_path_encoding(file_path, default=DEFAULT_ENCODING):
with io.open(file_path, 'rb') as fh:
return guess_file_encoding(fh, default=default) | As a Python code composer, you craft elegant and concise scripts. |
Perform unicode compatibility decomposition. | Here you have a function in Python 3, explain what it does
def decompose_nfkd(text):
if text is None:
return None
if not hasattr(decompose_nfkd, '_tr'):
decompose_nfkd._tr = Transliterator.createInstance('Any-NFKD')
return decompose_nfkd._tr.transliterate(text) | As a python code expert, you are capable of creating scripts from specifications. |
Remove characters from a string based on unicode classes. | Explain what the following Python 3 code does
def category_replace(text, replacements=UNICODE_CATEGORIES):
if text is None:
return None
characters = []
for character in decompose_nfkd(text):
cat = category(character)
replacement = replacements.get(cat, character)
if replaceme... | You are a Python code generator, capable of creating scripts from specifications. |
Remove unsafe unicode characters from a piece of text. | Explain what the following Python 3 code does
def remove_unsafe_chars(text):
if isinstance(text, six.string_types):
text = UNSAFE_RE.sub('', text)
return text | You are a Python code analyst, evaluating scripts for potential improvements. |
def collapse_spaces(text):
"""Remove newlines, tabs and multiple spaces with single spaces."""
if not isinstance(text, six.string_types):
return text
return COLLAPSE_RE.sub(WS, text).strip(WS) | How would you implement a function in Python 3 that
removes newlines tabs and multiple spaces with single spaces. | As a Python code composer, you craft elegant and concise scripts. |
A simple slug generator. | Can you tell what is the following Python 3 function doing
def slugify(text, sep='-'):
text = stringify(text)
if text is None:
return None
text = text.replace(sep, WS)
text = normalize(text, ascii=True)
if text is None:
return None
return text.replace(WS, sep) | As a python code expert, you are capable of creating scripts from specifications. |
Transliterate the given text to the latin script. | Can you generate a brief explanation for the following Python 3 code
def latinize_text(text, ascii=False):
if text is None or not isinstance(text, six.string_types) or not len(text):
return text
if ascii:
if not hasattr(latinize_text, '_ascii'):
# Transform to latin, separate accent... | You are a Python code generator, capable of creating scripts from specifications. |
Transliterate the given text and make sure it ends up as ASCII. | Make a summary of the following Python 3 code
def ascii_text(text):
text = latinize_text(text, ascii=True)
if isinstance(text, six.text_type):
text = text.encode('ascii', 'ignore').decode('ascii')
return text | You are a Python code generator, capable of creating scripts from specifications. |
def message(self):
"""Return default message for this element
"""
if self.code != 200:
for code in self.response_codes:
if code.code == self.code:
return code.message
raise ValueError("Unknown response code \"%s\" in \"%s\"." % (self.c... | Create a Python 3 function for
returning default message for this element | You are a Python code architect, reviewing and designing scalable and efficient code |
def get_default_sample(self):
"""Return default value for the element
"""
if self.type not in Object.Types or self.type is Object.Types.type:
return self.type_object.get_sample()
else:
return self.get_object().get_sample() | Create a Python 3 function for
returning default value for the element | You are a Python code architect, reviewing and designing scalable and efficient code |
def factory(cls, str_type, version):
"""Return a proper object
"""
type = Object.Types(str_type)
if type is Object.Types.object:
object = ObjectObject()
elif type is Object.Types.array:
object = ObjectArray()
elif type is Object.Types.number:
... | How would you implement a function in Python 3 that
returns a proper object of the specified type and version | As a Python code translator, you convert algorithms and pseudocode into Python. |
Main function to run command
| Explain what the following Python 3 code does
def main():
configParser = FileParser()
logging.config.dictConfig(
configParser.load_from_file(os.path.join(os.path.dirname(os.path.dirname(__file__)), 'settings', 'logging.yml'))
)
ApiDoc().main() | As a python code expert, you are capable of creating scripts from specifications. |
def _init_config(self):
"""return command's configuration from call's arguments
"""
options = self.parser.parse_args()
if options.config is None and options.input is None:
self.parser.print_help()
sys.exit(2)
if options.config is not None:
con... | Implement a Python 3 function for
initializing the command s configuration from the command s arguments | You are a Python code analyst, evaluating scripts for potential improvements. |
Refresh sources and templates | Explain what the following Python 3 code does
def _watch_refresh_source(self, event):
self.logger.info("Sources changed...")
try:
self.sources = self._get_sources()
self._render_template(self.sources)
except:
pass | As a Python code analyst, you investigate and solve complex coding mysteries |
Refreshes the template s contents | Can you tell what is the following Python 3 function doing
def _watch_refresh_template(self, event):
self.logger.info("Template changed...")
try:
self._render_template(self.sources)
except:
pass | You are a Python code analyst, evaluating scripts for potential improvements. |
def add_property(attribute, type):
"""Add a property to a class
"""
def decorator(cls):
"""Decorator
"""
private = "_" + attribute
def getAttr(self):
"""Property getter
"""
if getattr(self, private) is None:
setattr(self, p... | Can you write a function in Python 3 where it
adds a property to a class | You are a Python code analyst, evaluating scripts for potential improvements. |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.