output
stringlengths
1
928k
instruction
stringlengths
7
928k
system
stringlengths
0
104k
def _pfp__parse(self, stream, save_offset=False): """Parse the IO stream for this enum :stream: An IO stream that can be read from :returns: The number of bytes parsed """ res = super(Enum, self)._pfp__parse(stream, save_offset) if self._pfp__value in self.enum_vals: ...
Write a Python 3 script to parse the IO stream for this enum
As a Python code analyst, you investigate and solve complex coding mysteries
def _pfp__snapshot(self, recurse=True): """Save off the current value of the field """ super(Array, self)._pfp__snapshot(recurse=recurse) self.snapshot_raw_data = self.raw_data if recurse: for item in self.items: item._pfp__snapshot(recurse=recurse)
Can you write a function in Python 3 where it saves off the current value of the field
As a Python code analyst, you investigate and solve complex coding mysteries
Set the value of the String.
Make a summary of the following Python 3 code def _pfp__set_value(self, new_val): if not isinstance(new_val, Field): new_val = utils.binary(utils.string_escape(new_val)) super(String, self)._pfp__set_value(new_val)
You are a Python code architect, reviewing and designing scalable and efficient code
def _pfp__parse(self, stream, save_offset=False): """Read from the stream until the string is null-terminated :stream: The input stream :returns: None """ if save_offset: self._pfp__offset = stream.tell() res = utils.binary("") while True: ...
Write a Python 3 function that can read from the input stream until the string is null - terminated.
As a Python code translator, you convert algorithms and pseudocode into Python.
Builds the String field
Here you have a function in Python 3, explain what it does def _pfp__build(self, stream=None, save_offset=False): if stream is not None and save_offset: self._pfp__offset = stream.tell() data = self._pfp__value + utils.binary("\x00") if stream is None: return data ...
As a python code expert, you are capable of creating scripts from specifications.
def Printf(params, ctxt, scope, stream, coord, interp): """Prints format string to stdout :params: TODO :returns: TODO """ if len(params) == 1: if interp._printf: sys.stdout.write(PYSTR(params[0])) return len(PYSTR(params[0])) parts = [] for part in params[1:]:...
Write a Python 3 script for printing a format string to stdout.
You are a Python code analyst, evaluating scripts for potential improvements.
Mutate the provided field using the specified strategy.
Can you tell what is the following Python 3 function doing def mutate(field, strat_name_or_cls, num=100, at_once=1, yield_changed=False): import pfp.fuzz.rand as rand init() strat = get_strategy(strat_name_or_cls) to_mutate = strat.which(field) with_strats = [] for to_mutate_field in to_mutat...
You are a Python code analyst, evaluating scripts for potential improvements.
def get_strategy(name_or_cls): """Return the strategy identified by its name. If ``name_or_class`` is a class, it will be simply returned. """ if isinstance(name_or_cls, six.string_types): if name_or_cls not in STRATS: raise MutationError("strat is not defined") return STRATS...
Can you create a Python 3 function that returns the strategy identified by its name or class.
As a Python code composer, you craft elegant and concise scripts.
def mutate(self, field): """Mutate the given field, modifying it directly. This is not intended to preserve the value of the field. :field: The pfp.fields.Field instance that will receive the new value """ new_val = self.next_val(field) field._pfp__set_value(new_val) ...
Create a Python 3 function to mutate the given field modifying it directly. This is intended to preserve the value of the field.
You are a Python code architect, reviewing and designing scalable and efficient code
Return a new value to mutate a field with.
Can you tell what is the following Python 3 function doing def next_val(self, field): import pfp.fuzz.rand as rand if self.choices is not None: choices = self._resolve_member_val(self.choices, field) new_val = rand.choice(choices) return self._resolve_val(new_val) ...
As a python code expert, you are capable of creating scripts from specifications.
generate a new user in the database
How would you explain what the following Python 3 function does def generate_subid(self, token=None, return_user=False): '''generate a new user in the database, still session based so we create a new identifier. ''' from expfactory.database.models import Participant if not token: p = ...
You are a Python code analyst, evaluating scripts for potential improvements.
def print_user(self, user): '''print a relational database user ''' status = "active" token = user.token if token in ['finished', 'revoked']: status = token if token is None: token = '' subid = "%s\t%s[%s]" %(user.id, token, status) print(subid) return subid
Create a Python 3 function to print a relational database user
As a Python code analyst, you investigate and solve complex coding mysteries
list users in the database
Can you generate the documentation for the following Python 3 function def list_users(self, user=None): '''list users, each having a model in the database. A headless experiment will use protected tokens, and interactive will be based on auto- incremented ids. ''' from expfactory.database.mod...
You are a Python code architect, reviewing and designing scalable and efficient code
def generate_user(self): '''generate a new user in the database, still session based so we create a new identifier. This function is called from the users new entrypoint, and it assumes we want a user generated with a token. ''' token = str(uuid.uuid4()) return self.generate_subid(token=t...
Implement a function in Python 3 to generate a new user in the database
As a Python code analyst, you investigate and solve complex coding mysteries
def finish_user(self, subid): '''finish user will remove a user's token, making the user entry not accesible if running in headless model''' p = self.revoke_token(subid) p.token = "finished" self.session.commit() return p
Write a Python 3 function for finishing user will remove a user s token and make the user entry accesible
As a Python code analyst, you investigate and solve complex coding mysteries
def restart_user(self, subid): '''restart a user, which means revoking and issuing a new token.''' p = self.revoke_token(subid) p = self.refresh_token(subid) return p
Write a Python 3 function for restarting a user which means revoking and issuing a new token.
As a Python code translator, you convert algorithms and pseudocode into Python.
def validate_token(self, token): '''retrieve a subject based on a token. Valid means we return a participant invalid means we return None ''' from expfactory.database.models import Participant p = Participant.query.filter(Participant.token == token).first() if p is not None: if p.toke...
Implement a function in Python 3 to retrieve a subject based on a token. Valid means we return a participant invalid means we return None eer
You are a Python code analyst, evaluating scripts for potential improvements.
revoke a token by removing it. Is done at finish and also available as a command line option
Here you have a function in Python 3, explain what it does def revoke_token(self, subid): '''revoke a token by removing it. Is done at finish, and also available as a command line option''' from expfactory.database.models import Participant p = Participant.query.filter(Participant.id == subid).first() ...
As a Python code composer, you craft elegant and concise scripts.
refresh or generate a new token for a user
Can you generate a brief explanation for the following Python 3 code def refresh_token(self, subid): '''refresh or generate a new token for a user''' from expfactory.database.models import Participant p = Participant.query.filter(Participant.id == subid).first() if p is not None: p.token = str(u...
You are a Python code architect, reviewing and designing scalable and efficient code
save data for a specific subject
Explain what the following Python 3 code does def save_data(self,session, exp_id, content): '''save data will obtain the current subid from the session, and save it depending on the database type. Currently we just support flat files''' from expfactory.database.models import ( Participant, ...
You are a Python code generator, capable of creating scripts from specifications.
initialize the database with the default database path or custom with a format corresponding to the database type
Make a summary of the following Python 3 code def init_db(self): '''initialize the database, with the default database path or custom with a format corresponding to the database type: Examples: sqlite:////scif/data/expfactory.db ''' # The user can provide a custom string if self....
As a Python code composer, you craft elegant and concise scripts.
def _wrap_type_instantiation(self, type_cls): """Wrap the creation of the type so that we can provide a null-stream to initialize it""" def wrapper(*args, **kwargs): # use args for struct arguments?? return type_cls(stream=self._null_stream) return wrapper
How would you implement a function in Python 3 that wraps the creation of the type so that we can provide a null - stream to initialize it
As a python code expert, you are capable of creating scripts from specifications.
Return the current scope level
Explain what the following Python 3 code does def level(self): res = len(self._scope_stack) if self._parent is not None: res += self._parent.level() return res
You are a Python code generator, capable of creating scripts from specifications.
def push(self, new_scope=None): """Create a new scope :returns: TODO """ if new_scope is None: new_scope = { "types": {}, "vars": {} } self._curr_scope = new_scope self._dlog("pushing new scope, scope level = {}".fo...
Write a Python 3 script to create a new scope and push it on the stack.
As a python code expert, you are capable of creating scripts from specifications.
def clone(self): """Return a new Scope object that has the curr_scope pinned at the current one :returns: A new scope object """ self._dlog("cloning the stack") # TODO is this really necessary to create a brand new one? # I think it is... need to think about it mo...
Can you create a Python 3 function that returns a new Scope object that has the curr_scope_stack pinned at the current one .
You are a Python code generator, capable of creating scripts from specifications.
def pop(self): """Leave the current scope :returns: TODO """ res = self._scope_stack.pop() self._dlog("popping scope, scope level = {}".format(self.level())) self._curr_scope = self._scope_stack[-1] return res
Create a Python 3 function to leave the current scope
You are a Python code generator, capable of creating scripts from specifications.
def add_var(self, field_name, field, root=False): """Add a var to the current scope (vars are fields that parse the input stream) :field_name: TODO :field: TODO :returns: TODO """ self._dlog("adding var '{}' (root={})".format(field_name, root)) # do bot...
Create a Python 3 function to add a var to the current scope
As a Python code composer, you craft elegant and concise scripts.
def get_var(self, name, recurse=True): """Return the first var of name ``name`` in the current scope stack (remember, vars are the ones that parse the input stream) :name: The name of the id :recurse: Whether parent scopes should also be searched (defaults to True) :retu...
Create a Python 3 function for returning the first var of name in the current scope stack.
As a Python code analyst, you investigate and solve complex coding mysteries
def add_local(self, field_name, field): """Add a local variable in the current scope :field_name: The field's name :field: The field :returns: None """ self._dlog("adding local '{}'".format(field_name)) field._pfp__name = field_name # TODO do we allow cl...
Can you write a function in Python 3 where it adds a local variable in the current scope
You are a Python code architect, reviewing and designing scalable and efficient code
def get_local(self, name, recurse=True): """Get the local field (search for it) from the scope stack. An alias for ``get_var`` :name: The name of the local field """ self._dlog("getting local '{}'".format(name)) return self._search("vars", name, recurse)
Can you write a function in Python 3 where it gets the local field from the scope stack. An alias for get_var
As a python code expert, you are capable of creating scripts from specifications.
Store the node with the name.
Make a summary of the following Python 3 code def add_type_struct_or_union(self, name, interp, node): self.add_type_class(name, StructUnionDef(name, interp, node))
You are a Python code architect, reviewing and designing scalable and efficient code
def add_type(self, new_name, orig_names): """Record the typedefd name for orig_names. Resolve orig_names to their core names and save those. :new_name: TODO :orig_names: TODO :returns: TODO """ self._dlog("adding a type '{}'".format(new_name)) # TODO do ...
How would you code a function in Python 3 to record the typedefd name for orig_names and save those.
As a Python code analyst, you investigate and solve complex coding mysteries
Get the names for the typename created by typedef
Can you generate a brief explanation for the following Python 3 code def get_type(self, name, recurse=True): self._dlog("getting type '{}'".format(name)) return self._search("types", name, recurse)
As a Python code composer, you craft elegant and concise scripts.
Get the first id matching name. Will either be a local or a var.
How would you explain what the following Python 3 function does def get_id(self, name, recurse=True): self._dlog("getting id '{}'".format(name)) var = self._search("vars", name, recurse) return var
You are a Python code analyst, evaluating scripts for potential improvements.
def _search(self, category, name, recurse=True): """Search the scope stack for the name in the specified category (types/locals/vars). :category: the category to search in (locals/types/vars) :name: name to search for :returns: None if not found, the result of the found local/ty...
Implement a Python 3 function for searching the scope stack for the specified name in the specified category.
As a python code expert, you are capable of creating scripts from specifications.
def add_native(cls, name, func, ret, interp=None, send_interp=False): """Add the native python function ``func`` into the pfp interpreter with the name ``name`` and return value ``ret`` so that it can be called from within a template script. .. note:: The :any:`@native <pfp....
Can you create a Python 3 function that adds a native python function func to the interpreter with the given name and return value ret.
You are a Python code architect, reviewing and designing scalable and efficient code
Define the native functions for PFP .
Explain what the following Python 3 code does def define_natives(cls): if len(cls._natives) > 0: return glob_pattern = os.path.join(os.path.dirname(__file__), "native", "*.py") for filename in glob.glob(glob_pattern): basename = os.path.basename(filename).replace(".py", ...
As a Python code translator, you convert algorithms and pseudocode into Python.
def _dlog(self, msg, indent_increase=0): """log the message to the log""" self._log.debug("interp", msg, indent_increase, filename=self._orig_filename, coord=self._coord)
How would you implement a function in Python 3 that logs the message to the log
You are a Python code architect, reviewing and designing scalable and efficient code
def parse(self, stream, template, predefines=True, orig_filename=None, keep_successful=False, printf=True): """Parse the data stream using the template (e.g. parse the 010 template and interpret the template using the stream as the data source). :stream: The input data stream :template:...
Can you create a Python 3 function that parses the data stream using the template.
You are a Python code architect, reviewing and designing scalable and efficient code
def eval(self, statement, ctxt=None): """Eval a single statement (something returnable) """ self._no_debug = True statement = statement.strip() if not statement.endswith(";"): statement += ";" ast = self._parse_string(statement, predefines=False) s...
Create a Python 3 function for evaluating a single statement.
As a Python code composer, you craft elegant and concise scripts.
def set_break(self, break_type): """Set if the interpreter should break. :returns: TODO """ self._break_type = break_type self._break_level = self._scope.level()
Write a Python 3 script to set the interpreter should break.
You are a Python code generator, capable of creating scripts from specifications.
def get_curr_lines(self): """Return the current line number in the template, as well as the surrounding source lines """ start = max(0, self._coord.line - 5) end = min(len(self._template_lines), self._coord.line + 4) lines = [(x, self._template_lines[x]) for x in six.mov...
How would you implement a function in Python 3 that returns the current line number in the template and the surrounding source lines as well as the surrounding source lines
As a Python code translator, you convert algorithms and pseudocode into Python.
Sets whether the bitfield input or output stream should be padded.
Can you generate a brief explanation for the following Python 3 code def set_bitfield_padded(self, val): self._padded_bitfield = val self._stream.padded = val self._ctxt._pfp__padded_bitfield = val
As a Python code composer, you craft elegant and concise scripts.
def _run(self, keep_successfull): """Interpret the parsed 010 AST :returns: PfpDom """ # example self._ast.show(): # FileAST: # Decl: data, [], [], [] # TypeDecl: data, [] # Struct: DATA # Decl: a, [], [], [] ...
Write a Python 3 function that can interpret the parsed 010 AST and return the root and set _pfp__error if keep_successfull is True.
You are a Python code generator, capable of creating scripts from specifications.
Handle the file AST node.
Explain what the following Python 3 code does def _handle_file_ast(self, node, scope, ctxt, stream): self._root = ctxt = fields.Dom(stream) ctxt._pfp__scope = scope self._root._pfp__name = "__root" self._root._pfp__interp = self self._dlog("handling file AST with {} children".for...
As a Python code composer, you craft elegant and concise scripts.
def _handle_cast(self, node, scope, ctxt, stream): """Handle cast nodes :node: TODO :scope: TODO :ctxt: TODO :stream: TODO :returns: TODO """ self._dlog("handling cast") to_type = self._handle_node(node.to_type, scope, ctxt, stream) val_t...
Can you create a Python 3 function that handles cast nodes :node: TODO :scope: TODO :ctxt: TODO :stream: TODO :returns: TODO
As a Python code translator, you convert algorithms and pseudocode into Python.
def _handle_typename(self, node, scope, ctxt, stream): """TODO: Docstring for _handle_typename :node: TODO :scope: TODO :ctxt: TODO :stream: TODO :returns: TODO """ self._dlog("handling typename") return self._handle_node(node.type, scope, ctxt,...
How would you implement a function in Python 3 that handles the typename node.
As a Python code translator, you convert algorithms and pseudocode into Python.
def _get_node_name(self, node): """Get the name of the node - check for node.name and node.type.declname. Not sure why the second one occurs exactly - it happens with declaring a new struct field with parameters""" res = getattr(node, "name", None) if res is None: ...
How would you implement a function in Python 3 that gets the name of the node - check for node. name and node. type. declname. Not why the second one occurs exactly - it occurs with declaring a new struct field with parameters
As a Python code composer, you craft elegant and concise scripts.
def _handle_decl(self, node, scope, ctxt, stream): """TODO: Docstring for _handle_decl. :node: TODO :scope: TODO :ctxt: TODO :stream: TODO :returns: TODO """ self._dlog("handling decl") metadata_processor = None if node.metadata is not N...
Can you implement a function in Python 3 that handles a decl node.
You are a Python code generator, capable of creating scripts from specifications.
def _handle_metadata(self, node, scope, ctxt, stream): """Handle metadata for the node """ self._dlog("handling node metadata {}".format(node.metadata.keyvals)) keyvals = node.metadata.keyvals metadata_info = [] if "watch" in node.metadata.keyvals or "update" in keyval...
How would you code a function in Python 3 to handle the metadata for the node
You are a Python code architect, reviewing and designing scalable and efficient code
Handle watch vars for fields
Can you tell what is the following Python 3 function doing def _handle_watch_metadata(self, node, scope, ctxt, stream): keyvals = node.metadata.keyvals if "watch" not in keyvals: raise errors.PfpError("Packed fields require a packer function set") if "update" not in keyvals: ...
As a python code expert, you are capable of creating scripts from specifications.
Handle packed metadata node.
Can you tell what is the following Python 3 function doing def _handle_packed_metadata(self, node, scope, ctxt, stream): keyvals = node.metadata.keyvals if "packer" not in keyvals and ("pack" not in keyvals or "unpack" not in keyvals): raise errors.PfpError("Packed fields require a packer fu...
As a python code expert, you are capable of creating scripts from specifications.
TODO: Docstring for _handle_byref_decl. :node: TODO :scope: TODO :ctxt: TODO :stream: TODO :returns: TODO
Make a summary of the following Python 3 code def _handle_byref_decl(self, node, scope, ctxt, stream): self._dlog("handling byref decl") field = self._handle_node(node.type.type, scope, ctxt, stream) # this will not really be used (maybe except for introspection) # with byref function p...
As a Python code composer, you craft elegant and concise scripts.
TODO: Docstring for _handle_type_decl. :node: TODO :scope: TODO :ctxt: TODO :stream: TODO :returns: TODO
Can you generate a brief explanation for the following Python 3 code def _handle_type_decl(self, node, scope, ctxt, stream): self._dlog("handling type decl") decl = self._handle_node(node.type, scope, ctxt, stream) return decl
As a Python code composer, you craft elegant and concise scripts.
def _handle_struct_ref(self, node, scope, ctxt, stream): """TODO: Docstring for _handle_struct_ref. :node: TODO :scope: TODO :ctxt: TODO :stream: TODO :returns: TODO """ self._dlog("handling struct ref") # name # field struct = s...
Create a Python 3 function to handle a struct ref node.
As a Python code analyst, you investigate and solve complex coding mysteries
Handle the InitList nodes.
Can you generate the documentation for the following Python 3 function def _handle_init_list(self, node, scope, ctxt, stream): self._dlog("handling init list") res = [] for _,init_child in node.children(): init_field = self._handle_node(init_child, scope, ctxt, stream) re...
As a Python code composer, you craft elegant and concise scripts.
Handle struct type call
Here you have a function in Python 3, explain what it does def _handle_struct_call_type_decl(self, node, scope, ctxt, stream): self._dlog("handling struct with parameters") struct_cls = self._handle_node(node.type, scope, ctxt, stream) struct_args = self._handle_node(node.args, scope, ctxt, str...
You are a Python code generator, capable of creating scripts from specifications.
def _handle_struct(self, node, scope, ctxt, stream): """TODO: Docstring for _handle_struct. :node: TODO :scope: TODO :ctxt: TODO :stream: TODO :returns: TODO """ self._dlog("handling struct") if node.args is not None: for param in no...
Write a Python 3 function that can handle the struct node.
As a Python code translator, you convert algorithms and pseudocode into Python.
def _handle_typedef(self, node, scope, ctxt, stream): """TODO: Docstring for _handle_typedef. :node: TODO :scope: TODO :ctxt: TODO :stream: TODO :returns: TODO """ is_union_or_struct = (node.type.type.__class__ in [AST.Union, AST.Struct]) is_enum...
Can you write a function in Python 3 where it handles the TypeDef and TypeUnion nodes.
As a Python code composer, you craft elegant and concise scripts.
def _str_to_int(self, string): """Check for the hex """ string = string.lower() if string.endswith("l"): string = string[:-1] if string.lower().startswith("0x"): # should always match match = re.match(r'0[xX]([a-fA-F0-9]+)', string) ...
Write a Python 3 script to convert a string to an integer.
As a Python code composer, you craft elegant and concise scripts.
Handle a constant node.
Explain what the following Python 3 code does def _handle_constant(self, node, scope, ctxt, stream): self._dlog("handling constant type {}".format(node.type)) switch = { "int": (self._str_to_int, self._choose_const_int_class), "long": (self._str_to_int, self._choose_const_int_cla...
As a python code expert, you are capable of creating scripts from specifications.
Handle binary operator nodes.
Can you tell what is the following Python 3 function doing def _handle_binary_op(self, node, scope, ctxt, stream): self._dlog("handling binary operation {}".format(node.op)) switch = { "+": lambda x,y: x+y, "-": lambda x,y: x-y, "*": lambda x,y: x*y, "/": ...
You are a Python code architect, reviewing and designing scalable and efficient code
Handle unary operator nodes.
Given the following Python 3 function, write the documentation def _handle_unary_op(self, node, scope, ctxt, stream): self._dlog("handling unary op {}".format(node.op)) special_switch = { "parentof" : self._handle_parentof, "exists" : self._handle_exists, ...
You are a Python code generator, capable of creating scripts from specifications.
def _handle_parentof(self, node, scope, ctxt, stream): """Handle the parentof unary operator :node: TODO :scope: TODO :ctxt: TODO :stream: TODO :returns: TODO """ # if someone does something like parentof(this).blah, # we'll end up with a StructR...
How would you implement a function in Python 3 that handles the parentof unary operator.
As a Python code composer, you craft elegant and concise scripts.
Handle the exists unary operator
Explain what the following Python 3 code does def _handle_exists(self, node, scope, ctxt, stream): res = fields.Int() try: self._handle_node(node.expr, scope, ctxt, stream) res._pfp__set_value(1) except AttributeError: res._pfp__set_value(0) return res
As a Python code analyst, you investigate and solve complex coding mysteries
Handle the function_exists unary operator.
Make a summary of the following Python 3 code def _handle_function_exists(self, node, scope, ctxt, stream): res = fields.Int() try: func = self._handle_node(node.expr, scope, ctxt, stream) if isinstance(func, functions.BaseFunction): res._pfp__set_value(1) ...
You are a Python code architect, reviewing and designing scalable and efficient code
def _handle_id(self, node, scope, ctxt, stream): """Handle an ID node (return a field object for the ID) :node: TODO :scope: TODO :ctxt: TODO :stream: TODO :returns: TODO """ if node.name == "__root": return self._root if node.name ==...
Write a Python 3 function that can handle an ID node.
As a Python code composer, you craft elegant and concise scripts.
def _handle_assignment(self, node, scope, ctxt, stream): """Handle assignment nodes :node: TODO :scope: TODO :ctxt: TODO :stream: TODO :returns: TODO """ def add_op(x,y): x += y def sub_op(x,y): x -= y def div_op(x,y): x /= y def ...
Can you implement a function in Python 3 that handles assignment nodes :node: TODO :scope: TODO :ctxt: TODO :stream: TODO :returns: TODO
As a python code expert, you are capable of creating scripts from specifications.
Handle FuncDef nodes :node: TODO :scope: TODO :ctxt: TODO :stream: TODO :returns: TODO
Can you tell what is the following Python 3 function doing def _handle_func_def(self, node, scope, ctxt, stream): self._dlog("handling function definition") func = self._handle_node(node.decl, scope, ctxt, stream) func.body = node.body
As a Python code translator, you convert algorithms and pseudocode into Python.
def _handle_param_list(self, node, scope, ctxt, stream): """Handle ParamList nodes :node: TODO :scope: TODO :ctxt: TODO :stream: TODO :returns: TODO """ self._dlog("handling param list") # params should be a list of tuples: # [(<name>, <f...
How would you code a function in Python 3 to handle the ParamList nodes
You are a Python code architect, reviewing and designing scalable and efficient code
def _handle_func_decl(self, node, scope, ctxt, stream): """Handle FuncDecl nodes :node: TODO :scope: TODO :ctxt: TODO :stream: TODO :returns: TODO """ self._dlog("handling func decl") if node.args is not None: # could just call _hand...
Implement a Python 3 function for handling FuncDecl nodes :node: TODO :scope: TODO :ctxt: TODO :stream: TODO :returns: TODO
You are a Python code generator, capable of creating scripts from specifications.
Handle FuncCall nodes :node: TODO :scope: TODO :ctxt: TODO :stream: TODO :returns: TODO
Here you have a function in Python 3, explain what it does def _handle_func_call(self, node, scope, ctxt, stream): self._dlog("handling function call to '{}'".format(node.name.name)) if node.args is None: func_args = [] else: func_args = self._handle_node(node.args, scope...
You are a Python code generator, capable of creating scripts from specifications.
def _handle_expr_list(self, node, scope, ctxt, stream): """Handle ExprList nodes :node: TODO :scope: TODO :ctxt: TODO :stream: TODO :returns: TODO """ self._dlog("handling expression list") exprs = [ self._handle_node(expr, scope, ctx...
How would you implement a function in Python 3 that handles the ExprList nodes
As a Python code translator, you convert algorithms and pseudocode into Python.
def _handle_compound(self, node, scope, ctxt, stream): """Handle Compound nodes :node: TODO :scope: TODO :ctxt: TODO :stream: TODO :returns: TODO """ self._dlog("handling compound statement") #scope.push() try: for child in n...
How would you implement a function in Python 3 that handles the compound nodes
You are a Python code analyst, evaluating scripts for potential improvements.
def _handle_return(self, node, scope, ctxt, stream): """Handle Return nodes :node: TODO :scope: TODO :ctxt: TODO :stream: TODO :returns: TODO """ self._dlog("handling return") if node.expr is None: ret_val = None else: ...
Write a Python 3 function for handling Return nodes :node: TODO :scope: TODO :ctxt: TODO :stream: TODO :returns: TODO
You are a Python code generator, capable of creating scripts from specifications.
Handles the Enum nodes
How would you explain what the following Python 3 function does def _handle_enum(self, node, scope, ctxt, stream): self._dlog("handling enum") if node.type is None: enum_cls = fields.Int else: enum_cls = self._handle_node(node.type, scope, ctxt, stream) enum_vals...
As a python code expert, you are capable of creating scripts from specifications.
Handle ArrayDecl nodes :node: TODO :scope: TODO :ctxt: TODO :stream: TODO :returns: TODO
Make a summary of the following Python 3 code def _handle_array_decl(self, node, scope, ctxt, stream): self._dlog("handling array declaration '{}'".format(node.type.declname)) if node.dim is None: # will be used array_size = None else: array_size = self._hand...
You are a Python code architect, reviewing and designing scalable and efficient code
Handle ArrayRef nodes :node: TODO :scope: TODO :ctxt: TODO :stream: TODO :returns: TODO
Make a summary of the following Python 3 code def _handle_array_ref(self, node, scope, ctxt, stream): ary = self._handle_node(node.name, scope, ctxt, stream) subscript = self._handle_node(node.subscript, scope, ctxt, stream) return ary[fields.PYVAL(subscript)]
You are a Python code analyst, evaluating scripts for potential improvements.
Handle If nodes :node: TODO :scope: TODO :ctxt: TODO :stream: TODO :returns: TODO
Given the following Python 3 function, write the documentation def _handle_if(self, node, scope, ctxt, stream): self._dlog("handling if/ternary_op") cond = self._handle_node(node.cond, scope, ctxt, stream) if cond: # there should always be an iftrue return self._handle_no...
As a Python code composer, you craft elegant and concise scripts.
def _handle_for(self, node, scope, ctxt, stream): """Handle For nodes :node: TODO :scope: TODO :ctxt: TODO :stream: TODO :returns: TODO """ self._dlog("handling for") if node.init is not None: # perform the init self._hand...
Create a Python 3 function to handle For nodes :node: TODO :scope: TODO :ctxt: TODO :stream: TODO :returns: TODO
As a Python code analyst, you investigate and solve complex coding mysteries
def _handle_while(self, node, scope, ctxt, stream): """Handle break node :node: TODO :scope: TODO :ctxt: TODO :stream: TODO :returns: TODO """ self._dlog("handling while") while node.cond is None or self._handle_node(node.cond, scope, ctxt, strea...
Create a Python 3 function to handle a while node.
As a Python code composer, you craft elegant and concise scripts.
def _handle_switch(self, node, scope, ctxt, stream): """Handle break node :node: TODO :scope: TODO :ctxt: TODO :stream: TODO :returns: TODO """ def exec_case(idx, cases): # keep executing cases until a break is found, # or they've...
Implement a Python 3 function for handling break node :node: TODO :scope: TODO :ctxt: TODO :stream: TODO :returns: TODO
You are a Python code generator, capable of creating scripts from specifications.
Handle a break node
Can you tell what is the following Python 3 function doing def _handle_break(self, node, scope, ctxt, stream): self._dlog("handling break") raise errors.InterpBreak()
You are a Python code analyst, evaluating scripts for potential improvements.
def _handle_continue(self, node, scope, ctxt, stream): """Handle continue node :node: TODO :scope: TODO :ctxt: TODO :stream: TODO :returns: TODO """ self._dlog("handling continue") raise errors.InterpContinue()
Create a Python 3 function to handle continue node :node: TODO :scope: TODO :ctxt: TODO :stream: TODO :returns: TODO
As a Python code composer, you craft elegant and concise scripts.
Handle declarations in a list node
How would you explain what the following Python 3 function does def _handle_decl_list(self, node, scope, ctxt, stream): self._dlog("handling decl list") # just handle each declaration for decl in node.decls: self._handle_node(decl, scope, ctxt, stream)
As a Python code analyst, you investigate and solve complex coding mysteries
def _create_scope(self): """TODO: Docstring for _create_scope. :returns: TODO """ res = Scope(self._log) for func_name,native_func in six.iteritems(self._natives): res.add_local(func_name, native_func) return res
Can you write a function in Python 3 where it creates a new scope object for the current natives and log.
As a python code expert, you are capable of creating scripts from specifications.
def _get_value(self, node, scope, ctxt, stream): """Return the value of the node. It is expected to be either an AST.ID instance or a constant :node: TODO :returns: TODO """ res = self._handle_node(node, scope, ctxt, stream) if isinstance(res, fields.Field): ...
Write a Python 3 script for returning the value of the node. It is expected to be either an AST. ID instance or a constant .
As a Python code translator, you convert algorithms and pseudocode into Python.
def _resolve_to_field_class(self, names, scope): """Resolve the names to a class in fields.py, resolving past typedefs, etc :names: TODO :scope: TODO :ctxt: TODO :returns: TODO """ switch = { "char" : "Char", "int" : "Int",...
Can you implement a function in Python 3 that resolves the names to a class in fields. py
As a Python code analyst, you investigate and solve complex coding mysteries
def bits_to_bytes(bits): """Convert the bit list into bytes. (Assumes bits is a list whose length is a multiple of 8) """ if len(bits) % 8 != 0: raise Exception("num bits must be multiple of 8") res = "" for x in six.moves.range(0, len(bits), 8): byte_bits = bits[x:x+8] ...
How would you code a function in Python 3 to convert the bit list into bytes.
As a Python code analyst, you investigate and solve complex coding mysteries
def bytes_to_bits(bytes_): """Convert bytes to a list of bits """ res = [] for x in bytes_: if not isinstance(x, int): x = ord(x) res += byte_to_bits(x) return res
Implement a function in Python 3 to convert a list of bytes to a list of bits
You are a Python code analyst, evaluating scripts for potential improvements.
def is_eof(self): """Return if the stream has reached EOF or not without discarding any unflushed bits :returns: True/False """ pos = self._stream.tell() byte = self._stream.read(1) self._stream.seek(pos, 0) return utils.binary(byte) == utils.binary("")
Implement a function in Python 3 to return True if the stream has reached EOF or False otherwise.
As a Python code translator, you convert algorithms and pseudocode into Python.
Reads num number of bytes from the stream.
Can you tell what is the following Python 3 function doing def read(self, num): start_pos = self.tell() if self.padded: # we toss out any uneven bytes self._bits.clear() res = utils.binary(self._stream.read(num)) else: bits = self.read_bits(num * ...
As a Python code composer, you craft elegant and concise scripts.
Read num number of bits from the stream and return them as a list.
Given the following Python 3 function, write the documentation def read_bits(self, num): if num > len(self._bits): needed = num - len(self._bits) num_bytes = int(math.ceil(needed / 8.0)) read_bytes = self._stream.read(num_bytes) for bit in bytes_to_bits(read_byte...
As a python code expert, you are capable of creating scripts from specifications.
def write(self, data): """Write data to the stream :data: the data to write to the stream :returns: None """ if self.padded: # flush out any remaining bits first if len(self._bits) > 0: self._flush_bits_to_stream() self._stream...
Write a Python 3 script to write the data to the stream.
You are a Python code analyst, evaluating scripts for potential improvements.
Write the bits to the stream.
Given the following Python 3 function, write the documentation def write_bits(self, bits): for bit in bits: self._bits.append(bit) while len(self._bits) >= 8: byte_bits = [self._bits.popleft() for x in six.moves.range(8)] byte = bits_to_bytes(byte_bits) s...
As a Python code analyst, you investigate and solve complex coding mysteries
Return the current position in the stream
How would you explain what the following Python 3 function does def tell(self): res = self._stream.tell() if len(self._bits) > 0: res -= 1 return res
You are a Python code analyst, evaluating scripts for potential improvements.
Seek to the specified position in the stream with seek_type.
Can you tell what is the following Python 3 function doing def seek(self, pos, seek_type=0): self._bits.clear() return self._stream.seek(pos, seek_type)
As a Python code translator, you convert algorithms and pseudocode into Python.
Return the size of the resource store in bytes or - 1 if it cannot be determined.
Given the following Python 3 function, write the documentation def size(self): pos = self._stream.tell() # seek to the end of the stream self._stream.seek(0,2) size = self._stream.tell() self._stream.seek(pos, 0) return size
You are a Python code analyst, evaluating scripts for potential improvements.
Return an IntervalTree of unconsumed ranges of the format start end with the end value being included
How would you explain what the following Python 3 function does def unconsumed_ranges(self): res = IntervalTree() prev = None # normal iteration is not in a predictable order ranges = sorted([x for x in self.range_set], key=lambda x: x.begin) for rng in ranges: if ...
You are a Python code generator, capable of creating scripts from specifications.
def _update_consumed_ranges(self, start_pos, end_pos): """Update the ``self.consumed_ranges`` array with which byte ranges have been consecutively consumed. """ self.range_set.add(Interval(start_pos, end_pos+1)) self.range_set.merge_overlaps()
Can you implement a function in Python 3 that updates the self. consumed_ranges array with which byte ranges have been consecutively consumed.
You are a Python code generator, capable of creating scripts from specifications.