text_prompt
stringlengths
157
13.1k
code_prompt
stringlengths
7
19.8k
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def set (self, id, param, value): """ Sets the value of a configuration parameter. """
assert isinstance(id, basestring) assert isinstance(param, basestring) assert is_iterable_typed(value, basestring) self.params_.setdefault(param, {})[id] = value
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def get_gpus_in_use(max_devices=None): """ Like get_num_gpus_in_use, but returns a list of dictionaries with just queried GPU information. """
from turicreate.util import _get_cuda_gpus gpu_indices = get_gpu_ids_in_use(max_devices=max_devices) gpus = _get_cuda_gpus() return [gpus[index] for index in gpu_indices]
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def make_unity_server_env(): """ Returns the environment for unity_server. The environment is necessary to start the unity_server by setting the proper environme...
env = os.environ.copy() # Add hadoop class path classpath = get_hadoop_class_path() if ("CLASSPATH" in env): env["CLASSPATH"] = env['CLASSPATH'] + (os.path.pathsep + classpath if classpath != '' else '') else: env["CLASSPATH"] = classpath # Add python syspath env['__GL_SYS...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def set_windows_dll_path(): """ Sets the dll load path so that things are resolved correctly. """
lib_path = os.path.dirname(os.path.abspath(_pylambda_worker.__file__)) lib_path = os.path.abspath(os.path.join(lib_path, os.pardir)) def errcheck_bool(result, func, args): if not result: last_error = ctypes.get_last_error() if last_error != 0: raise ctypes....
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def get_library_name(): """ Returns either sframe or turicreate depending on which library this file is bundled with. """
from os.path import split, abspath __lib_name = split(split(abspath(sys.modules[__name__].__file__))[0])[1] assert __lib_name in ["sframe", "turicreate"] return __lib_name
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def get_config_file(): """ Returns the file name of the config file from which the environment variables are written. """
import os from os.path import abspath, expanduser, join, exists __lib_name = get_library_name() assert __lib_name in ["sframe", "turicreate"] __default_config_path = join(expanduser("~"), ".%s" % __lib_name, "config") if "TURI_CONFIG_FILE" in os.environ: __default_config_path = absp...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def setup_environment_from_config_file(): """ Imports the environmental configuration settings from the config file, if present, and sets the environment variabl...
from os.path import exists config_file = get_config_file() if not exists(config_file): return try: config = _ConfigParser.SafeConfigParser() config.read(config_file) __section = "Environment" if config.has_section(__section): items = config.item...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def write_config_file_value(key, value): """ Writes an environment variable configuration to the current config file. This will be read in on the next restart. T...
filename = get_config_file() config = _ConfigParser.SafeConfigParser() config.read(filename) __section = "Environment" if not(config.has_section(__section)): config.add_section(__section) config.set(__section, key, value) with open(filename, 'w') as config_file: config...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def BuildService(self, cls): """Constructs the service class. Args: cls: The class that will be constructed. """
# CallMethod needs to operate with an instance of the Service class. This # internal wrapper function exists only to be able to pass the service # instance to the method that does the real CallMethod work. def _WrapCallMethod(srvc, method_descriptor, rpc_controller, request, ca...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def _CallMethod(self, srvc, method_descriptor, rpc_controller, request, callback): """Calls the method described by a given method descriptor. Args: srvc: Instan...
if method_descriptor.containing_service != self.descriptor: raise RuntimeError( 'CallMethod() given method descriptor for wrong service type.') method = getattr(srvc, method_descriptor.name) return method(rpc_controller, request, callback)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def _GetRequestClass(self, method_descriptor): """Returns the class of the request protocol message. Args: method_descriptor: Descriptor of the method for which ...
if method_descriptor.containing_service != self.descriptor: raise RuntimeError( 'GetRequestClass() given method descriptor for wrong service type.') return method_descriptor.input_type._concrete_class
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def _GetResponseClass(self, method_descriptor): """Returns the class of the response protocol message. Args: method_descriptor: Descriptor of the method for whic...
if method_descriptor.containing_service != self.descriptor: raise RuntimeError( 'GetResponseClass() given method descriptor for wrong service type.') return method_descriptor.output_type._concrete_class
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def _GenerateNonImplementedMethod(self, method): """Generates and returns a method that can be set for a service methods. Args: method: Descriptor of the service...
return lambda inst, rpc_controller, request, callback: ( self._NonImplementedMethod(method.name, rpc_controller, callback))
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def BuildServiceStub(self, cls): """Constructs the stub class. Args: cls: The class that will be constructed. """
def _ServiceStubInit(stub, rpc_channel): stub.rpc_channel = rpc_channel self.cls = cls cls.__init__ = _ServiceStubInit for method in self.descriptor.methods: setattr(cls, method.name, self._GenerateStubMethod(method))
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def _StubMethod(self, stub, method_descriptor, rpc_controller, request, callback): """The body of all service methods in the generated stub class. Args: stub: St...
return stub.rpc_channel.CallMethod( method_descriptor, rpc_controller, request, method_descriptor.output_type._concrete_class, callback)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def _BuildMessageFromTypeName(type_name, descriptor_pool): """Returns a protobuf message instance. Args: type_name: Fully-qualified protobuf message type name st...
# pylint: disable=g-import-not-at-top from google.protobuf import symbol_database database = symbol_database.Default() try: message_descriptor = descriptor_pool.FindMessageTypeByName(type_name) except KeyError: return None message_type = database.GetPrototype(message_descriptor) return message_ty...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def _SkipFieldMessage(tokenizer): """Skips over a field message. Args: tokenizer: A tokenizer to parse the field name and values. """
if tokenizer.TryConsume('<'): delimiter = '>' else: tokenizer.Consume('{') delimiter = '}' while not tokenizer.LookingAt('>') and not tokenizer.LookingAt('}'): _SkipField(tokenizer) tokenizer.Consume(delimiter)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def _SkipFieldValue(tokenizer): """Skips over a field value. Args: tokenizer: A tokenizer to parse the field name and values. Raises: ParseError: In case an inva...
# String/bytes tokens can come in multiple adjacent string literals. # If we can consume one, consume as many as we can. if tokenizer.TryConsumeByteString(): while tokenizer.TryConsumeByteString(): pass return if (not tokenizer.TryConsumeIdentifier() and not _TryConsumeInt64(tokenizer) and...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def _ConsumeInteger(tokenizer, is_signed=False, is_long=False): """Consumes an integer number from tokenizer. Args: tokenizer: A tokenizer used to parse the numb...
try: result = ParseInteger(tokenizer.token, is_signed=is_signed, is_long=is_long) except ValueError as e: raise tokenizer.ParseError(str(e)) tokenizer.NextToken() return result
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def ParseInteger(text, is_signed=False, is_long=False): """Parses an integer. Args: text: The text to parse. is_signed: True if a signed integer must be parsed. ...
# Do the actual parsing. Exception handling is propagated to caller. result = _ParseAbstractInteger(text, is_long=is_long) # Check if the integer is sane. Exceptions handled by callers. checker = _INTEGER_CHECKERS[2 * int(is_long) + int(is_signed)] checker.CheckValue(result) return result
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def ParseFloat(text): """Parse a floating point number. Args: text: Text to parse. Returns: The number parsed. Raises: ValueError: If a floating point number cou...
try: # Assume Python compatible syntax. return float(text) except ValueError: # Check alternative spellings. if _FLOAT_INFINITY.match(text): if text[0] == '-': return float('-inf') else: return float('inf') elif _FLOAT_NAN.match(text): return float('nan') e...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def ParseEnum(field, value): """Parse an enum value. The value can be specified by a number (the enum value), or by a string literal (the enum name). Args: field...
enum_descriptor = field.enum_type try: number = int(value, 0) except ValueError: # Identifier. enum_value = enum_descriptor.values_by_name.get(value, None) if enum_value is None: raise ValueError('Enum type "%s" has no value named %s.' % (enum_descriptor.full_name, va...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def _TryPrintAsAnyMessage(self, message): """Serializes if message is a google.protobuf.Any field."""
packed_message = _BuildMessageFromTypeName(message.TypeName(), self.descriptor_pool) if packed_message: packed_message.MergeFromString(message.value) self.out.write('%s[%s]' % (self.indent * ' ', message.type_url)) self._PrintMessageFieldValue(pa...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def MergeLines(self, lines, message): """Merges a text representation of a protocol message into a message."""
self._allow_multiple_scalars = True self._ParseOrMerge(lines, message) return message
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def _ParseOrMerge(self, lines, message): """Converts a text representation of a protocol message into a message. Args: lines: Lines of a message's text represent...
tokenizer = Tokenizer(lines) while not tokenizer.AtEnd(): self._MergeField(tokenizer, message)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def _ConsumeAnyTypeUrl(self, tokenizer): """Consumes a google.protobuf.Any type URL and returns the type name."""
# Consume "type.googleapis.com/". tokenizer.ConsumeIdentifier() tokenizer.Consume('.') tokenizer.ConsumeIdentifier() tokenizer.Consume('.') tokenizer.ConsumeIdentifier() tokenizer.Consume('/') # Consume the fully-qualified type name. name = [tokenizer.ConsumeIdentifier()] while ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def TryConsume(self, token): """Tries to consume a given piece of text. Args: token: Text to consume. Returns: True iff the text was consumed. """
if self.token == token: self.NextToken() return True return False
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def ConsumeInteger(self, is_long=False): """Consumes an integer number. Args: is_long: True if the value should be returned as a long integer. Returns: The integ...
try: result = _ParseAbstractInteger(self.token, is_long=is_long) except ValueError as e: raise self.ParseError(str(e)) self.NextToken() return result
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def ConsumeString(self): """Consumes a string value. Returns: The string parsed. Raises: ParseError: If a string value couldn't be consumed. """
the_bytes = self.ConsumeByteString() try: return six.text_type(the_bytes, 'utf-8') except UnicodeDecodeError as e: raise self._StringParseError(e)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def ConsumeByteString(self): """Consumes a byte array value. Returns: The array parsed (as a string). Raises: ParseError: If a byte array value couldn't be consu...
the_list = [self._ConsumeSingleByteString()] while self.token and self.token[0] in _QUOTES: the_list.append(self._ConsumeSingleByteString()) return b''.join(the_list)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def NextToken(self): """Reads the next meaningful token."""
self._previous_line = self._line self._previous_column = self._column self._column += len(self.token) self._SkipWhitespace() if not self._more_lines: self.token = '' return match = self._TOKEN.match(self._current_line, self._column) if not match and not self._skip_comments: ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def compute_composite_distance(distance, x, y): """ Compute the value of a composite distance function on two dictionaries, typically SFrame rows. Parameters dis...
## Validate inputs _validate_composite_distance(distance) distance = _convert_distance_names_to_functions(distance) if not isinstance(x, dict) or not isinstance(y, dict): raise TypeError("Inputs 'x' and 'y' must be in dictionary form. " + "Selecting individual rows of ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def _validate_composite_distance(distance): """ Check that composite distance function is in valid form. Don't modify the composite distance in any way. """
if not isinstance(distance, list): raise TypeError("Input 'distance' must be a composite distance.") if len(distance) < 1: raise ValueError("Composite distances must have a least one distance " "component, consisting of a list of feature names, " ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def _scrub_composite_distance_features(distance, feature_blacklist): """ Remove feature names from the feature lists in a composite distance function. """
dist_out = [] for i, d in enumerate(distance): ftrs, dist, weight = d new_ftrs = [x for x in ftrs if x not in feature_blacklist] if len(new_ftrs) > 0: dist_out.append([new_ftrs, dist, weight]) return dist_out
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def _convert_distance_names_to_functions(distance): """ Convert function names in a composite distance function into function handles. """
dist_out = _copy.deepcopy(distance) for i, d in enumerate(distance): _, dist, _ = d if isinstance(dist, str): try: dist_out[i][1] = _tc.distances.__dict__[dist] except: raise ValueError("Distance '{}' not recognized.".format(dist)) r...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def GetMessages(file_protos): """Builds a dictionary of all the messages available in a set of files. Args: file_protos: A sequence of file protos to build messa...
for file_proto in file_protos: _FACTORY.pool.Add(file_proto) return _FACTORY.GetMessages([file_proto.name for file_proto in file_protos])
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def GetPrototype(self, descriptor): """Builds a proto2 message class based on the passed in descriptor. Passing a descriptor with a fully qualified name matching...
if descriptor.full_name not in self._classes: descriptor_name = descriptor.name if str is bytes: # PY2 descriptor_name = descriptor.name.encode('ascii', 'ignore') result_class = reflection.GeneratedProtocolMessageType( descriptor_name, (message.Message,), {'...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def GetMessages(self, files): """Gets all the messages from a specified file. This will find and resolve dependencies, failing if the descriptor pool cannot sati...
result = {} for file_name in files: file_desc = self.pool.FindFileByName(file_name) for desc in file_desc.message_types_by_name.values(): result[desc.full_name] = self.GetPrototype(desc) # While the extension FieldDescriptors are created by the descriptor pool, # the python cla...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description:
def refactor_ifs(stmnt, ifs): ''' for if statements in list comprehension ''' if isinstance(stmnt, _ast.BoolOp): test, right = stmnt.values if isinstance(stmnt.op, _ast.Or): test = _ast.UnaryOp(op=_ast.Not(), operand=test, lineno=0, col_offset=0) ifs.append(test) ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def _get_mps_od_net(input_image_shape, batch_size, output_size, anchors, config, weights={}): """ Initializes an MpsGraphAPI for object detection. """
network = _MpsGraphAPI(network_id=_MpsGraphNetworkType.kODGraphNet) c_in, h_in, w_in = input_image_shape c_out = output_size h_out = h_in // 32 w_out = w_in // 32 c_view = c_in h_view = h_in w_view = w_in network.init(batch_size, c_in, h_in, w_in, c_out, h_out, w_out, ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def predict(self, dataset, confidence_threshold=0.25, iou_threshold=None, verbose=True): """ Predict object instances in an sframe of images. Parameters dataset ...
_numeric_param_check_range('confidence_threshold', confidence_threshold, 0.0, 1.0) dataset, unpack = self._canonize_input(dataset) stacked_pred = self._predict_with_options(dataset, with_ground_truth=False, confidence_threshold=confidence_thresh...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def evaluate(self, dataset, metric='auto', output_type='dict', iou_threshold=None, confidence_threshold=None, verbose=True): """ Evaluate the model by making pre...
if iou_threshold is None: iou_threshold = self.non_maximum_suppression_threshold if confidence_threshold is None: confidence_threshold = 0.001 AP = 'average_precision' MAP = 'mean_average_precision' AP50 = 'average_precision_50' MAP50 = 'mean_average_precision_50' ...
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def _xmlTextReaderErrorFunc(xxx_todo_changeme,msg,severity,locator): """Intermediate callback to wrap the locator"""
(f,arg) = xxx_todo_changeme return f(arg,msg,severity,xmlTextReaderLocator(locator))
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def htmlCreateMemoryParserCtxt(buffer, size): """Create a parser context for an HTML in-memory document. """
ret = libxml2mod.htmlCreateMemoryParserCtxt(buffer, size) if ret is None:raise parserError('htmlCreateMemoryParserCtxt() failed') return parserCtxt(_obj=ret)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def htmlParseDoc(cur, encoding): """parse an HTML in-memory document and build a tree. """
ret = libxml2mod.htmlParseDoc(cur, encoding) if ret is None:raise parserError('htmlParseDoc() failed') return xmlDoc(_obj=ret)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def htmlReadFd(fd, URL, encoding, options): """parse an XML from a file descriptor and build a tree. """
ret = libxml2mod.htmlReadFd(fd, URL, encoding, options) if ret is None:raise treeError('htmlReadFd() failed') return xmlDoc(_obj=ret)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def htmlNewDoc(URI, ExternalID): """Creates a new HTML document """
ret = libxml2mod.htmlNewDoc(URI, ExternalID) if ret is None:raise treeError('htmlNewDoc() failed') return xmlDoc(_obj=ret)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def htmlNewDocNoDtD(URI, ExternalID): """Creates a new HTML document without a DTD node if @URI and @ExternalID are None """
ret = libxml2mod.htmlNewDocNoDtD(URI, ExternalID) if ret is None:raise treeError('htmlNewDocNoDtD() failed') return xmlDoc(_obj=ret)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def loadACatalog(filename): """Load the catalog and build the associated data structures. This can be either an XML Catalog or an SGML Catalog It will recurse in...
ret = libxml2mod.xmlLoadACatalog(filename) if ret is None:raise treeError('xmlLoadACatalog() failed') return catalog(_obj=ret)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def loadSGMLSuperCatalog(filename): """Load an SGML super catalog. It won't expand CATALOG or DELEGATE references. This is only needed for manipulating SGML Supe...
ret = libxml2mod.xmlLoadSGMLSuperCatalog(filename) if ret is None:raise treeError('xmlLoadSGMLSuperCatalog() failed') return catalog(_obj=ret)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def newCatalog(sgml): """create a new Catalog. """
ret = libxml2mod.xmlNewCatalog(sgml) if ret is None:raise treeError('xmlNewCatalog() failed') return catalog(_obj=ret)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def debugDumpString(output, str): """Dumps informations about the string, shorten it if necessary """
if output is not None: output.flush() libxml2mod.xmlDebugDumpString(output, str)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def predefinedEntity(name): """Check whether this name is an predefined entity. """
ret = libxml2mod.xmlGetPredefinedEntity(name) if ret is None:raise treeError('xmlGetPredefinedEntity() failed') return xmlEntity(_obj=ret)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def nanoFTPProxy(host, port, user, passwd, type): """Setup the FTP proxy informations. This can also be done by using ftp_proxy ftp_proxy_user and ftp_proxy_pass...
libxml2mod.xmlNanoFTPProxy(host, port, user, passwd, type)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def createDocParserCtxt(cur): """Creates a parser context for an XML in-memory document. """
ret = libxml2mod.xmlCreateDocParserCtxt(cur) if ret is None:raise parserError('xmlCreateDocParserCtxt() failed') return parserCtxt(_obj=ret)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def parseDTD(ExternalID, SystemID): """Load and parse an external subset. """
ret = libxml2mod.xmlParseDTD(ExternalID, SystemID) if ret is None:raise parserError('xmlParseDTD() failed') return xmlDtd(_obj=ret)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def parseMemory(buffer, size): """parse an XML in-memory block and build a tree. """
ret = libxml2mod.xmlParseMemory(buffer, size) if ret is None:raise parserError('xmlParseMemory() failed') return xmlDoc(_obj=ret)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def readFd(fd, URL, encoding, options): """parse an XML from a file descriptor and build a tree. NOTE that the file descriptor will not be closed when the reader...
ret = libxml2mod.xmlReadFd(fd, URL, encoding, options) if ret is None:raise treeError('xmlReadFd() failed') return xmlDoc(_obj=ret)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def recoverDoc(cur): """parse an XML in-memory document and build a tree. In the case the document is not Well Formed, a attempt to build a tree is tried anyway ...
ret = libxml2mod.xmlRecoverDoc(cur) if ret is None:raise treeError('xmlRecoverDoc() failed') return xmlDoc(_obj=ret)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def recoverMemory(buffer, size): """parse an XML in-memory block and build a tree. In the case the document is not Well Formed, an attempt to build a tree is tri...
ret = libxml2mod.xmlRecoverMemory(buffer, size) if ret is None:raise treeError('xmlRecoverMemory() failed') return xmlDoc(_obj=ret)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def copyChar(len, out, val): """append the char value in the array """
ret = libxml2mod.xmlCopyChar(len, out, val) return ret
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def createMemoryParserCtxt(buffer, size): """Create a parser context for an XML in-memory document. """
ret = libxml2mod.xmlCreateMemoryParserCtxt(buffer, size) if ret is None:raise parserError('xmlCreateMemoryParserCtxt() failed') return parserCtxt(_obj=ret)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def namePop(ctxt): """Pops the top element name from the name stack """
if ctxt is None: ctxt__o = None else: ctxt__o = ctxt._o ret = libxml2mod.namePop(ctxt__o) return ret
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def namePush(ctxt, value): """Pushes a new element name on top of the name stack """
if ctxt is None: ctxt__o = None else: ctxt__o = ctxt._o ret = libxml2mod.namePush(ctxt__o, value) return ret
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def nodePop(ctxt): """Pops the top element node from the node stack """
if ctxt is None: ctxt__o = None else: ctxt__o = ctxt._o ret = libxml2mod.nodePop(ctxt__o) if ret is None:raise treeError('nodePop() failed') return xmlNode(_obj=ret)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def nodePush(ctxt, value): """Pushes a new element node on top of the node stack """
if ctxt is None: ctxt__o = None else: ctxt__o = ctxt._o if value is None: value__o = None else: value__o = value._o ret = libxml2mod.nodePush(ctxt__o, value__o) return ret
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def createInputBuffer(file, encoding): """Create a libxml2 input buffer from a Python file """
ret = libxml2mod.xmlCreateInputBuffer(file, encoding) if ret is None:raise treeError('xmlCreateInputBuffer() failed') return inputBuffer(_obj=ret)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def createOutputBuffer(file, encoding): """Create a libxml2 output buffer from a Python file """
ret = libxml2mod.xmlCreateOutputBuffer(file, encoding) if ret is None:raise treeError('xmlCreateOutputBuffer() failed') return outputBuffer(_obj=ret)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def createPushParser(SAX, chunk, size, URI): """Create a progressive XML parser context to build either an event flow if the SAX object is not None, or a DOM tre...
ret = libxml2mod.xmlCreatePushParser(SAX, chunk, size, URI) if ret is None:raise parserError('xmlCreatePushParser() failed') return parserCtxt(_obj=ret)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def htmlCreatePushParser(SAX, chunk, size, URI): """Create a progressive HTML parser context to build either an event flow if the SAX object is not None, or a DO...
ret = libxml2mod.htmlCreatePushParser(SAX, chunk, size, URI) if ret is None:raise parserError('htmlCreatePushParser() failed') return parserCtxt(_obj=ret)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def newNode(name): """Create a new Node """
ret = libxml2mod.xmlNewNode(name) if ret is None:raise treeError('xmlNewNode() failed') return xmlNode(_obj=ret)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def relaxNGNewMemParserCtxt(buffer, size): """Create an XML RelaxNGs parse context for that memory buffer expected to contain an XML RelaxNGs file. """
ret = libxml2mod.xmlRelaxNGNewMemParserCtxt(buffer, size) if ret is None:raise parserError('xmlRelaxNGNewMemParserCtxt() failed') return relaxNgParserCtxt(_obj=ret)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def buildQName(ncname, prefix, memory, len): """Builds the QName @prefix:@ncname in @memory if there is enough space and prefix is not None nor empty, otherwise ...
ret = libxml2mod.xmlBuildQName(ncname, prefix, memory, len) return ret
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def newComment(content): """Creation of a new node containing a comment. """
ret = libxml2mod.xmlNewComment(content) if ret is None:raise treeError('xmlNewComment() failed') return xmlNode(_obj=ret)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def newDoc(version): """Creates a new XML document """
ret = libxml2mod.xmlNewDoc(version) if ret is None:raise treeError('xmlNewDoc() failed') return xmlDoc(_obj=ret)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def newPI(name, content): """Creation of a processing instruction element. Use xmlDocNewPI preferably to get string interning """
ret = libxml2mod.xmlNewPI(name, content) if ret is None:raise treeError('xmlNewPI() failed') return xmlNode(_obj=ret)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def newText(content): """Creation of a new text node. """
ret = libxml2mod.xmlNewText(content) if ret is None:raise treeError('xmlNewText() failed') return xmlNode(_obj=ret)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def newTextLen(content, len): """Creation of a new text node with an extra parameter for the content's length """
ret = libxml2mod.xmlNewTextLen(content, len) if ret is None:raise treeError('xmlNewTextLen() failed') return xmlNode(_obj=ret)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def newTextReaderFilename(URI): """Create an xmlTextReader structure fed with the resource at @URI """
ret = libxml2mod.xmlNewTextReaderFilename(URI) if ret is None:raise treeError('xmlNewTextReaderFilename() failed') return xmlTextReader(_obj=ret)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def readerForFd(fd, URL, encoding, options): """Create an xmltextReader for an XML from a file descriptor. The parsing flags @options are a combination of xmlPar...
ret = libxml2mod.xmlReaderForFd(fd, URL, encoding, options) if ret is None:raise treeError('xmlReaderForFd() failed') return xmlTextReader(_obj=ret)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def regexpCompile(regexp): """Parses a regular expression conforming to XML Schemas Part 2 Datatype Appendix F and builds an automata suitable for testing string...
ret = libxml2mod.xmlRegexpCompile(regexp) if ret is None:raise treeError('xmlRegexpCompile() failed') return xmlReg(_obj=ret)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def schemaNewMemParserCtxt(buffer, size): """Create an XML Schemas parse context for that memory buffer expected to contain an XML Schemas file. """
ret = libxml2mod.xmlSchemaNewMemParserCtxt(buffer, size) if ret is None:raise parserError('xmlSchemaNewMemParserCtxt() failed') return SchemaParserCtxt(_obj=ret)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def valuePop(ctxt): """Pops the top XPath object from the value stack """
if ctxt is None: ctxt__o = None else: ctxt__o = ctxt._o ret = libxml2mod.valuePop(ctxt__o) return ret
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def removeNsDef(self, href): """ Remove a namespace definition from a node. If href is None, remove all of the ns definitions on that node. The removed namespace...
ret = libxml2mod.xmlNodeRemoveNsDef(self._o, href) if ret is None:return None __tmp = xmlNs(_obj=ret) return __tmp
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def debugDumpNode(self, output, depth): """Dumps debug information for the element node, it is recursive """
libxml2mod.xmlDebugDumpNode(output, self._o, depth)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def debugDumpNodeList(self, output, depth): """Dumps debug information for the list of element node, it is recursive """
libxml2mod.xmlDebugDumpNodeList(output, self._o, depth)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def debugDumpOneNode(self, output, depth): """Dumps debug information for the element node, it is not recursive """
libxml2mod.xmlDebugDumpOneNode(output, self._o, depth)
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def addChild(self, cur): """Add a new node to @parent, at the end of the child (or property) list merging adjacent TEXT nodes (in which case @cur is freed) If th...
if cur is None: cur__o = None else: cur__o = cur._o ret = libxml2mod.xmlAddChild(self._o, cur__o) if ret is None:raise treeError('xmlAddChild() failed') __tmp = xmlNode(_obj=ret) return __tmp
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def addChildList(self, cur): """Add a list of node at the end of the child list of the parent merging adjacent TEXT nodes (@cur may be freed) """
if cur is None: cur__o = None else: cur__o = cur._o ret = libxml2mod.xmlAddChildList(self._o, cur__o) if ret is None:raise treeError('xmlAddChildList() failed') __tmp = xmlNode(_obj=ret) return __tmp
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def addSibling(self, elem): """Add a new element @elem to the list of siblings of @cur merging adjacent TEXT nodes (@elem may be freed) If the new element was al...
if elem is None: elem__o = None else: elem__o = elem._o ret = libxml2mod.xmlAddSibling(self._o, elem__o) if ret is None:raise treeError('xmlAddSibling() failed') __tmp = xmlNode(_obj=ret) return __tmp
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def copyNode(self, extended): """Do a copy of the node. """
ret = libxml2mod.xmlCopyNode(self._o, extended) if ret is None:raise treeError('xmlCopyNode() failed') __tmp = xmlNode(_obj=ret) return __tmp
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def firstElementChild(self): """Finds the first child node of that element which is a Element node Note the handling of entities references is different than in ...
ret = libxml2mod.xmlFirstElementChild(self._o) if ret is None:return None __tmp = xmlNode(_obj=ret) return __tmp
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def lastChild(self): """Search the last child of a node. """
ret = libxml2mod.xmlGetLastChild(self._o) if ret is None:raise treeError('xmlGetLastChild() failed') __tmp = xmlNode(_obj=ret) return __tmp
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def lastElementChild(self): """Finds the last child node of that element which is a Element node Note the handling of entities references is different than in th...
ret = libxml2mod.xmlLastElementChild(self._o) if ret is None:return None __tmp = xmlNode(_obj=ret) return __tmp
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def newNs(self, href, prefix): """Creation of a new Namespace. This function will refuse to create a namespace with a similar prefix than an existing one present...
ret = libxml2mod.xmlNewNs(self._o, href, prefix) if ret is None:raise treeError('xmlNewNs() failed') __tmp = xmlNs(_obj=ret) return __tmp
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def newProp(self, name, value): """Create a new property carried by a node. """
ret = libxml2mod.xmlNewProp(self._o, name, value) if ret is None:raise treeError('xmlNewProp() failed') __tmp = xmlAttr(_obj=ret) return __tmp
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def nextElementSibling(self): """Finds the first closest next sibling of the node which is an element node. Note the handling of entities references is different...
ret = libxml2mod.xmlNextElementSibling(self._o) if ret is None:return None __tmp = xmlNode(_obj=ret) return __tmp
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def previousElementSibling(self): """Finds the first closest previous sibling of the node which is an element node. Note the handling of entities references is d...
ret = libxml2mod.xmlPreviousElementSibling(self._o) if ret is None:return None __tmp = xmlNode(_obj=ret) return __tmp
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def replaceNode(self, cur): """Unlink the old node from its current context, prune the new one at the same place. If @cur was already inserted in a document it i...
if cur is None: cur__o = None else: cur__o = cur._o ret = libxml2mod.xmlReplaceNode(self._o, cur__o) if ret is None:raise treeError('xmlReplaceNode() failed') __tmp = xmlNode(_obj=ret) return __tmp
<SYSTEM_TASK:> Solve the following problem using Python, implementing the functions described below, one line at a time <END_TASK> <USER_TASK:> Description: def textConcat(self, content, len): """Concat the given string at the end of the existing node content """
ret = libxml2mod.xmlTextConcat(self._o, content, len) return ret