Instruction:
Here you have a function in Python 3, explain what it does
def rs_find_error_locator(synd, nsym, erase_loc=None, erase_count=0):
    '''Find error/errata locator and evaluator polynomials with Berlekamp-Massey algorithm'''
    # The idea is that BM will iteratively estimate the error locator polynomial.
    # To do this, it will compute a Discrepancy term called Delta, which will tell us if the error locator polynomial needs an update or not
    # (hence why it's called discrepancy: it tells us when we are getting off board from the correct value).

    # Init the polynomials
    if erase_loc: # if the erasure locator polynomial is supplied, we init with its value, so that we include erasures in the final locator polynomial
        err_loc = bytearray(erase_loc)
        old_loc = bytearray(erase_loc)
    else:
        err_loc = bytearray([1]) # This is the main variable we want to fill, also called Sigma in other notations or more formally the errors/errata locator polynomial.
        old_loc = bytearray([1]) # BM is an iterative algorithm, and we need the errata locator polynomial of the previous iteration in order to update other necessary variables.
    #L = 0 # update flag variable, not needed here because we use an alternative equivalent way of checking if update is needed (but using the flag could potentially be faster depending on if using length(list) is taking linear time in your language, here in Python it's constant so it's as fast.

    # Fix the syndrome shifting: when computing the syndrome, some implementations may prepend a 0 coefficient for the lowest degree term (the constant). This is a case of syndrome shifting, thus the syndrome will be bigger than the number of ecc symbols (I don't know what purpose serves this shifting). If that's the case, then we need to account for the syndrome shifting when we use the syndrome such as inside BM, by skipping those prepended coefficients.
    # Another way to detect the shifting is to detect the 0 coefficients: by definition, a syndrome does not contain any 0 coefficient (except if there are no errors/erasures, in this case they are all 0). This however doesn't work with the modified Forney syndrome, which set to 0 the coefficients corresponding to erasures, leaving only the coefficients corresponding to errors.
    synd_shift = 0
    if len(synd) > nsym: synd_shift = len(synd) - nsym

    for i in xrange(nsym-erase_count): # generally: nsym-erase_count == len(synd), except when you input a partial erase_loc and using the full syndrome instead of the Forney syndrome, in which case nsym-erase_count is more correct (len(synd) will fail badly with IndexError).
        if erase_loc: # if an erasures locator polynomial was provided to init the errors locator polynomial, then we must skip the FIRST erase_count iterations (not the last iterations, this is very important!)
            K = erase_count+i+synd_shift
        else: # if erasures locator is not provided, then either there's no erasures to account or we use the Forney syndromes, so we don't need to use erase_count nor erase_loc (the erasures have been trimmed out of the Forney syndromes).
            K = i+synd_shift

        # Compute the discrepancy Delta
        # Here is the close-to-the-books operation to compute the discrepancy Delta: it's a simple polynomial multiplication of error locator with the syndromes, and then we get the Kth element.
        #delta = gf_poly_mul(err_loc[::-1], synd)[K] # theoretically it should be gf_poly_add(synd[::-1], [1])[::-1] instead of just synd, but it seems it's not absolutely necessary to correctly decode.
        # But this can be optimized: since we only need the Kth element, we don't need to compute the polynomial multiplication for any other element but the Kth. Thus to optimize, we compute the polymul only at the item we need, skipping the rest (avoiding a nested loop, thus we are linear time instead of quadratic).
        # This optimization is actually described in several figures of the book "Algebraic codes for data transmission", Blahut, Richard E., 2003, Cambridge university press.
        delta = synd[K]
        for j in xrange(1, len(err_loc)):
            delta ^= gf_mul(err_loc[-(j+1)], synd[K - j]) # delta is also called discrepancy. Here we do a partial polynomial multiplication (ie, we compute the polynomial multiplication only for the term of degree K). Should be equivalent to brownanrs.polynomial.mul_at().
        #print "delta", K, delta, list(gf_poly_mul(err_loc[::-1], synd)) # debugline

        # Shift polynomials to compute the next degree
        old_loc = old_loc + bytearray([0])

        # Iteratively estimate the errata locator and evaluator polynomials
        if delta != 0: # Update only if there's a discrepancy
            if len(old_loc) > len(err_loc): # Rule B (rule A is implicitly defined because rule A just says that we skip any modification for this iteration)
            #if 2*L <= K+erase_count: # equivalent to len(old_loc) > len(err_loc), as long as L is correctly computed
                # Computing errata locator polynomial Sigma
                new_loc = gf_poly_scale(old_loc, delta)
                old_loc = gf_poly_scale(err_loc, gf_inverse(delta)) # effectively we are doing err_loc * 1/delta = err_loc // delta
                err_loc = new_loc
                # Update the update flag
                #L = K - L # the update flag L is tricky: in Blahut's schema, it's mandatory to use `L = K - L - erase_count` (and indeed in a previous draft of this function, if you forgot to do `- erase_count` it would lead to correcting only 2*(errors+erasures) <= (n-k) instead of 2*errors+erasures <= (n-k)), but in this latest draft, this will lead to a wrong decoding in some cases where it should correctly decode! Thus you should try with and without `- erase_count` to update L on your own implementation and see which one works OK without producing wrong decoding failures.

            # Update with the discrepancy
            err_loc = gf_poly_add(err_loc, gf_poly_scale(old_loc, delta))

    # Check if the result is correct, that there's not too many errors to correct
    err_loc = list(itertools.dropwhile(lambda x: x == 0, err_loc)) # drop leading 0s, else errs will not be of the correct size
    errs = len(err_loc) - 1
    if (errs-erase_count) * 2 + erase_count > nsym:
        raise ReedSolomonError("Too many errors to correct")

    return err_loc

Response: Find error and errata locator polynomials for a syndrometric symbol.


Instruction:
Can you create a Python 3 function that
finds the error locator polynomial from the erasures and errors positions.

Response:
def rs_find_errata_locator(e_pos, generator=2):
    '''Compute the erasures/errors/errata locator polynomial from the erasures/errors/errata positions (the positions must be relative to the x coefficient, eg: "hello worldxxxxxxxxx" is tampered to "h_ll_ worldxxxxxxxxx" with xxxxxxxxx being the ecc of length n-k=9, here the string positions are [1, 4], but the coefficients are reversed since the ecc characters are placed as the first coefficients of the polynomial, thus the coefficients of the erased characters are n-1 - [1, 4] = [18, 15] = erasures_loc to be specified as an argument.'''
    # See: http://ocw.usu.edu/Electrical_and_Computer_Engineering/Error_Control_Coding/lecture7.pdf and Blahut, Richard E. "Transform techniques for error control codes." IBM Journal of Research and development 23.3 (1979): 299-315. http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.92.600&rep=rep1&type=pdf and also a MatLab implementation here: http://www.mathworks.com/matlabcentral/fileexchange/23567-reed-solomon-errors-and-erasures-decoder/content//RS_E_E_DEC.m
    e_loc = [1] # just to init because we will multiply, so it must be 1 so that the multiplication starts correctly without nulling any term
    # erasures_loc is very simple to compute: erasures_loc = prod(1 - x*alpha**i) for i in erasures_pos and where alpha is the alpha chosen to evaluate polynomials (here in this library it's gf(3)). To generate c*x where c is a constant, we simply generate a Polynomial([c, 0]) where 0 is the constant and c is positionned to be the coefficient for x^1.
    for i in e_pos:
        e_loc = gf_poly_mul( e_loc, gf_poly_add([1], [gf_pow(generator, i), 0]) )
    return e_loc


Instruction:
Write a Python 3 function that can
compute the error evaluator polynomial Omega from the syndrome and the error locator polynomial.

Response:
def rs_find_error_evaluator(synd, err_loc, nsym):
    '''Compute the error (or erasures if you supply sigma=erasures locator polynomial, or errata) evaluator polynomial Omega from the syndrome and the error/erasures/errata locator Sigma. Omega is already computed at the same time as Sigma inside the Berlekamp-Massey implemented above, but in case you modify Sigma, you can recompute Omega afterwards using this method, or just ensure that Omega computed by BM is correct given Sigma.'''
    # Omega(x) = [ Synd(x) * Error_loc(x) ] mod x^(n-k+1)
    _, remainder = gf_poly_div( gf_poly_mul(synd, err_loc), ([1] + [0]*(nsym+1)) ) # first multiply syndromes * errata_locator, then do a polynomial division to truncate the polynomial to the required length

    # Faster way that is equivalent
    #remainder = gf_poly_mul(synd, err_loc) # first multiply the syndromes with the errata locator polynomial
    #remainder = remainder[len(remainder)-(nsym+1):] # then divide by a polynomial of the length we want, which is equivalent to slicing the list (which represents the polynomial)

    return remainder


Instruction:
How would you explain what the following Python 3 function does
def rs_find_errors(err_loc, nmess, generator=2):
    '''Find the roots (ie, where evaluation = zero) of error polynomial by bruteforce trial, this is a sort of Chien's search (but less efficient, Chien's search is a way to evaluate the polynomial such that each evaluation only takes constant time).'''
    # nmess = length of whole codeword (message + ecc symbols)
    errs = len(err_loc) - 1
    err_pos = []
    for i in xrange(nmess): # normally we should try all 2^8 possible values, but here we optimize to just check the interesting symbols
        if gf_poly_eval(err_loc, gf_pow(generator, i)) == 0: # It's a 0? Bingo, it's a root of the error locator polynomial, in other terms this is the location of an error
            err_pos.append(nmess - 1 - i)
    # Sanity check: the number of errors/errata positions found should be exactly the same as the length of the errata locator polynomial
    if len(err_pos) != errs:
        # TODO: to decode messages+ecc with length n > 255, we may try to use a bruteforce approach: the correct positions ARE in the final array j, but the problem is because we are above the Galois Field's range, there is a wraparound so that for example if j should be [0, 1, 2, 3], we will also get [255, 256, 257, 258] (because 258 % 255 == 3, same for the other values), so we can't discriminate. The issue is that fixing any errs_nb errors among those will always give a correct output message (in the sense that the syndrome will be all 0), so we may not even be able to check if that's correct or not, so I'm not sure the bruteforce approach may even be possible.
        raise ReedSolomonError("Too many (or few) errors found by Chien Search for the errata locator polynomial!")
    return err_pos

Response: Find the roots of the error locator polynomial by Chien s search.


Instruction:
Can you implement a function in Python 3 that
corrects a message using the Chien Search algorithm.

Response:
def rs_correct_msg(msg_in, nsym, fcr=0, generator=2, erase_pos=None, only_erasures=False):
    '''Reed-Solomon main decoding function'''
    global field_charac
    if len(msg_in) > field_charac:
        # Note that it is in fact possible to encode/decode messages that are longer than field_charac, but because this will be above the field, this will generate more error positions during Chien Search than it should, because this will generate duplicate values, which should normally be prevented thank's to the prime polynomial reduction (eg, because it can't discriminate between error at position 1 or 256, both being exactly equal under galois field 2^8). So it's really not advised to do it, but it's possible (but then you're not guaranted to be able to correct any error/erasure on symbols with a position above the length of field_charac -- if you really need a bigger message without chunking, then you should better enlarge c_exp so that you get a bigger field).
        raise ValueError("Message is too long (%i when max is %i)" % (len(msg_in), field_charac))

    msg_out = bytearray(msg_in)     # copy of message
    # erasures: set them to null bytes for easier decoding (but this is not necessary, they will be corrected anyway, but debugging will be easier with null bytes because the error locator polynomial values will only depend on the errors locations, not their values)
    if erase_pos is None:
        erase_pos = []
    else:
        for e_pos in erase_pos:
            msg_out[e_pos] = 0
    # check if there are too many erasures to correct (beyond the Singleton bound)
    if len(erase_pos) > nsym: raise ReedSolomonError("Too many erasures to correct")
    # prepare the syndrome polynomial using only errors (ie: errors = characters that were either replaced by null byte or changed to another character, but we don't know their positions)
    synd = rs_calc_syndromes(msg_out, nsym, fcr, generator)
    # check if there's any error/erasure in the input codeword. If not (all syndromes coefficients are 0), then just return the codeword as-is.
    if max(synd) == 0:
        return msg_out[:-nsym], msg_out[-nsym:]  # no errors

    # Find errors locations
    if only_erasures:
        err_pos = []
    else:
        # compute the Forney syndromes, which hide the erasures from the original syndrome (so that BM will just have to deal with errors, not erasures)
        fsynd = rs_forney_syndromes(synd, erase_pos, len(msg_out), generator)
        # compute the error locator polynomial using Berlekamp-Massey
        err_loc = rs_find_error_locator(fsynd, nsym, erase_count=len(erase_pos))
        # locate the message errors using Chien search (or bruteforce search)
        err_pos = rs_find_errors(err_loc[::-1], len(msg_out), generator)
        if err_pos is None:
            raise ReedSolomonError("Could not locate error")

    # Find errors values and apply them to correct the message
    # compute errata evaluator and errata magnitude polynomials, then correct errors and erasures
    msg_out = rs_correct_errata(msg_out, synd, (erase_pos + err_pos), fcr, generator) # note that we here use the original syndrome, not the forney syndrome (because we will correct both errors and erasures, so we need the full syndrome)
    # check if the final message is fully repaired
    synd = rs_calc_syndromes(msg_out, nsym, fcr, generator)
    if max(synd) > 0:
        raise ReedSolomonError("Could not correct message")
    # return the successfully decoded message
    return msg_out[:-nsym], msg_out[-nsym:]


Instruction:
Explain what the following Python 3 code does
def rs_correct_msg_nofsynd(msg_in, nsym, fcr=0, generator=2, erase_pos=None, only_erasures=False):
    '''Reed-Solomon main decoding function, without using the modified Forney syndromes'''
    global field_charac
    if len(msg_in) > field_charac:
        raise ValueError("Message is too long (%i when max is %i)" % (len(msg_in), field_charac))

    msg_out = bytearray(msg_in)     # copy of message
    # erasures: set them to null bytes for easier decoding (but this is not necessary, they will be corrected anyway, but debugging will be easier with null bytes because the error locator polynomial values will only depend on the errors locations, not their values)
    if erase_pos is None:
        erase_pos = []
    else:
        for e_pos in erase_pos:
            msg_out[e_pos] = 0
    # check if there are too many erasures
    if len(erase_pos) > nsym: raise ReedSolomonError("Too many erasures to correct")
    # prepare the syndrome polynomial using only errors (ie: errors = characters that were either replaced by null byte or changed to another character, but we don't know their positions)
    synd = rs_calc_syndromes(msg_out, nsym, fcr, generator)
    # check if there's any error/erasure in the input codeword. If not (all syndromes coefficients are 0), then just return the codeword as-is.
    if max(synd) == 0:
        return msg_out[:-nsym], msg_out[-nsym:]  # no errors

    # prepare erasures locator and evaluator polynomials
    erase_loc = None
    #erase_eval = None
    erase_count = 0
    if erase_pos:
        erase_count = len(erase_pos)
        erase_pos_reversed = [len(msg_out)-1-eras for eras in erase_pos]
        erase_loc = rs_find_errata_locator(erase_pos_reversed, generator=generator)
        #erase_eval = rs_find_error_evaluator(synd[::-1], erase_loc, len(erase_loc)-1)

    # prepare errors/errata locator polynomial
    if only_erasures:
        err_loc = erase_loc[::-1]
        #err_eval = erase_eval[::-1]
    else:
        err_loc = rs_find_error_locator(synd, nsym, erase_loc=erase_loc, erase_count=erase_count)
        err_loc = err_loc[::-1]
        #err_eval = rs_find_error_evaluator(synd[::-1], err_loc[::-1], len(err_loc)-1)[::-1] # find error/errata evaluator polynomial (not really necessary since we already compute it at the same time as the error locator poly in BM)

    # locate the message errors
    err_pos = rs_find_errors(err_loc, len(msg_out), generator) # find the roots of the errata locator polynomial (ie: the positions of the errors/errata)
    if err_pos is None:
        raise ReedSolomonError("Could not locate error")

    # compute errata evaluator and errata magnitude polynomials, then correct errors and erasures
    msg_out = rs_correct_errata(msg_out, synd, err_pos, fcr=fcr, generator=generator)
    # check if the final message is fully repaired
    synd = rs_calc_syndromes(msg_out, nsym, fcr, generator)
    if max(synd) > 0:
        raise ReedSolomonError("Could not correct message")
    # return the successfully decoded message
    return msg_out[:-nsym], msg_out[-nsym:]

Response: This function is used to correct the message using the modified Forney syndromes.


Instruction:
Can you generate the documentation for the following Python 3 function
def rs_check(msg, nsym, fcr=0, generator=2):
    '''Returns true if the message + ecc has no error of false otherwise (may not always catch a wrong decoding or a wrong message, particularly if there are too many errors -- above the Singleton bound --, but it usually does)'''
    return ( max(rs_calc_syndromes(msg, nsym, fcr, generator)) == 0 )

Response: Returns true if the message + ecc has no error of false otherwise


Instruction:
Can you tell what is the following Python 3 function doing
def encode(self, data):
        '''Encode a message (ie, add the ecc symbols) using Reed-Solomon, whatever the length of the message because we use chunking'''
        if isinstance(data, str):
            data = bytearray(data, "latin-1")
        chunk_size = self.nsize - self.nsym
        enc = bytearray()
        for i in xrange(0, len(data), chunk_size):
            chunk = data[i:i+chunk_size]
            enc.extend(rs_encode_msg(chunk, self.nsym, fcr=self.fcr, generator=self.generator))
        return enc

Response: Encode a message using Reed - Solomon


Instruction:
Can you generate a brief explanation for the following Python 3 code
def decode(self, data, erase_pos=None, only_erasures=False):
        '''Repair a message, whatever its size is, by using chunking'''
        # erase_pos is a list of positions where you know (or greatly suspect at least) there is an erasure (ie, wrong character but you know it's at this position). Just input the list of all positions you know there are errors, and this method will automatically split the erasures positions to attach to the corresponding data chunk.
        if isinstance(data, str):
            data = bytearray(data, "latin-1")
        dec = bytearray()
        for i in xrange(0, len(data), self.nsize):
            # Split the long message in a chunk
            chunk = data[i:i+self.nsize]
            # Extract the erasures for this chunk
            e_pos = []
            if erase_pos:
                # First extract the erasures for this chunk (all erasures below the maximum chunk length)
                e_pos = [x for x in erase_pos if x <= self.nsize]
                # Then remove the extract erasures from the big list and also decrement all subsequent positions values by nsize (the current chunk's size) so as to prepare the correct alignment for the next iteration
                erase_pos = [x - (self.nsize+1) for x in erase_pos if x > self.nsize]
            # Decode/repair this chunk!
            dec.extend(rs_correct_msg(chunk, self.nsym, fcr=self.fcr, generator=self.generator, erase_pos=e_pos, only_erasures=only_erasures)[0])
        return dec

Response: Decode a message from a byte string.


Instruction:
Explain what the following Python 3 code does
def recurse( record, index, stop_types=STOP_TYPES,already_seen=None, type_group=False ):
    if already_seen is None:
        already_seen = set()
    if record['address'] not in already_seen:
        already_seen.add(record['address'])
        if 'refs' in record:
            for child in children( record, index, stop_types=stop_types ):
                if child['address'] not in already_seen:
                    for descendant in recurse(
                        child, index, stop_types,
                        already_seen=already_seen, type_group=type_group,
                    ):
                        yield descendant
        yield record

Response: Recursive generator for the tree traversal of a dictionary record.


Instruction:
Can you write a function in Python 3 where it
finds all loops within the index and replace with loop records

Response:
def find_loops( record, index, stop_types = STOP_TYPES, open=None, seen = None ):
    """Find all loops within the index and replace with loop records"""
    if open is None:
        open = []
    if seen is None:
        seen = set()
    for child in children( record, index, stop_types = stop_types ):
        if child['type'] in stop_types or child['type'] == LOOP_TYPE:
            continue
        if child['address'] in open:
            # loop has been found
            start = open.index( child['address'] )
            new = frozenset( open[start:] )
            if new not in seen:
                seen.add(new)
                yield new
        elif child['address'] in seen:
            continue
        else:
            seen.add( child['address'])
            open.append( child['address'] )
            for loop in find_loops( child, index, stop_types=stop_types, open=open, seen=seen ):
                yield loop
            open.pop( -1 )


Instruction:
Make a summary of the following Python 3 code
def promote_loops( loops, index, shared ):
    for loop in loops:
        loop = list(loop)
        members = [index[addr] for addr in loop]
        external_parents = list(set([
            addr for addr in sum([shared.get(addr,[]) for addr in loop],[])
            if addr not in loop
        ]))
        if external_parents:
            if len(external_parents) == 1:
                # potentially a loop that's been looped...
                parent = index.get( external_parents[0] )
                if parent['type'] == LOOP_TYPE:
                    continue
            # we haven't already been looped...
            loop_addr = new_address( index )
            shared[loop_addr] = external_parents
            loop_record = index[loop_addr] = {
                'address': loop_addr,
                'refs': loop,
                'parents': external_parents,
                'type': LOOP_TYPE,
                'size': 0,
            }
            for member in members:
                # member's references must *not* point to loop...
                member['refs'] = [
                    ref for ref in member['refs']
                    if ref not in loop
                ]
                # member's parents are *just* the loop
                member['parents'][:] = [loop_addr]
            # each referent to loop holds a single reference to the loop rather than many to children
            for parent in external_parents:
                parent = index[parent]
                for member in members:
                    rewrite_references( parent['refs'], member['address'], None )
                parent['refs'].append( loop_addr )

Response: Turn loops into objects that can be processed normally


Instruction:
Implement a function in Python 3 to
retrieve children records for given record

Response:
def children( record, index, key='refs', stop_types=STOP_TYPES ):
    """Retrieve children records for given record"""
    result = []
    for ref in record.get( key,[]):
        try:
            record = index[ref]
        except KeyError, err:
            #print 'No record for %s address %s in %s'%(key, ref, record['address'] )
            pass # happens when an unreachable references a reachable that has been compressed out...
        else:
            if record['type'] not in stop_types:
                result.append(  record  )
    return result


Instruction:
Can you tell what is the following Python 3 function doing
def children_types( record, index, key='refs', stop_types=STOP_TYPES ):
    types = {}
    for child in children( record, index, key, stop_types=stop_types ):
        types.setdefault(child['type'],[]).append( child )
    return types

Response: Produce dictionary mapping type - key to instances for all children


Instruction:
Can you create a Python 3 function that
creates a recursive - cost hierarchy based on the overall record and the shared dictionary.

Response:
def recurse_module( overall_record, index, shared, stop_types=STOP_TYPES, already_seen=None, min_size=0 ):
    """Creates a has-a recursive-cost hierarchy

    Mutates objects in-place to produce a hierarchy of memory usage based on
    reference-holding cost assignment
    """
    for record in recurse(
        overall_record, index,
        stop_types=stop_types,
        already_seen=already_seen,
        type_group=True,
    ):
        # anything with a totsize we've already processed...
        if record.get('totsize') is not None:
            continue
        rinfo = record
        rinfo['module'] = overall_record.get('name',NON_MODULE_REFS )
        if not record['refs']:
            rinfo['rsize'] = 0
            rinfo['children'] = []
        else:
            # TODO: provide a flag to coalesce based on e.g. type at each level or throughout...
            rinfo['children'] = rinfo_children = list ( children( record, index, stop_types=stop_types ) )
            rinfo['rsize'] = sum([
                (
                    child.get('totsize',0.0)/float(len(shared.get( child['address'], [])) or 1)
                )
                for child in rinfo_children
            ], 0.0 )
        rinfo['totsize'] = record['size'] + rinfo['rsize']

    return None


Instruction:
Here you have a function in Python 3, explain what it does
def rewrite_refs( targets, old,new, index, key='refs', single_ref=False ):
    for parent in targets:
        if not isinstance( parent, dict ):
            try:
                parent = index[parent]
            except KeyError, err:
                continue
        rewrite_references( parent[key], old, new, single_ref=single_ref )

Response: Rewrite key in all targets to replace old with new


Instruction:
Make a summary of the following Python 3 code
def rewrite_references( sequence, old, new, single_ref=False ):
    old,new = as_id(old),as_id(new)
    to_delete = []
    for i,n in enumerate(sequence):
        if n == old:
            if new is None:
                to_delete.append( i )
            else:
                sequence[i] = new
                if single_ref:
                    new = None
        elif n == new and single_ref:
            new = None
    if to_delete:
        to_delete.reverse()
        for i in to_delete:
            del sequence[i]
    return sequence

Response: Rewrite parents to point to new in old


Instruction:
Implement a Python 3 function for
returning a sub - set of children who are simple in the sense of group_children

Response:
def simple( child, shared, parent ):
    """Return sub-set of children who are "simple" in the sense of group_children"""
    return (
        not child.get('refs',())
        and (
            not shared.get(child['address'])
        or
            shared.get(child['address']) == [parent['address']]
        )
    )


Instruction:
Can you write a function in Python 3 where it
groups children of a single object into a single tree of objects with long children - lists

Response:
def group_children( index, shared, min_kids=10, stop_types=STOP_TYPES, delete_children=True ):
    """Collect like-type children into sub-groups of objects for objects with long children-lists

    Only group if:

        * there are more than X children of type Y
        * children are "simple"
            * individual children have no children themselves
            * individual children have no other parents...
    """
    to_compress = []

    for to_simplify in list(iterindex( index )):
        if not isinstance( to_simplify, dict ):
            continue
        for typ,kids in children_types( to_simplify, index, stop_types=stop_types ).items():
            kids = [k for k in kids if k and simple(k,shared, to_simplify)]
            if len(kids) >= min_kids:
                # we can group and compress out...
                to_compress.append( (to_simplify,typ,kids))

    for to_simplify,typ,kids in to_compress:
        typ_address = new_address(index)
        kid_addresses = [k['address'] for k in kids]
        index[typ_address] = {
            'address': typ_address,
            'type': MANY_TYPE,
            'name': typ,
            'size': sum( [k.get('size',0) for k in kids], 0),
            'parents': [to_simplify['address']],
        }

        shared[typ_address] = index[typ_address]['parents']
        to_simplify['refs'][:] = [typ_address]

        if delete_children:
            for address in kid_addresses:
                try:
                    del index[address]
                except KeyError, err:
                    pass # already compressed out
                try:
                    del shared[address]
                except KeyError, err:
                    pass # already compressed out
            index[typ_address]['refs'] = []
        else:
            index[typ_address]['refs'] = kid_addresses


Instruction:
Make a summary of the following Python 3 code
def simplify_dicts( index, shared, simplify_dicts=SIMPLIFY_DICTS, always_compress=ALWAYS_COMPRESS_DICTS ):

    # things which will have their dictionaries compressed out

    to_delete = set()

    for to_simplify in iterindex(index):
        if to_simplify['address'] in to_delete:
            continue
        if to_simplify['type'] in simplify_dicts and not 'compressed' in to_simplify:
            refs = to_simplify['refs']
            for ref in refs:
                child = index.get( ref )
                if child is not None and child['type'] == 'dict':
                    child_referrers = child['parents'][:]
                    if len(child_referrers) == 1 or to_simplify['type'] in always_compress:

                        to_simplify['compressed'] = True
                        to_simplify['refs'] = child['refs']
                        to_simplify['size'] += child['size']

                        # rewrite anything *else* that was pointing to child to point to us...
                        while to_simplify['address'] in child_referrers:
                            child_referrers.remove( to_simplify['address'] )
                        if child_referrers:
                            rewrite_refs(
                                child_referrers,
                                child['address'],
                                to_simplify['address'],
                                index, single_ref=True
                            )

                        # now rewrite grandchildren to point to root obj instead of dict
                        for grandchild in child['refs']:
                            grandchild = index[grandchild]
                            parent_set = grandchild['parents']
                            if parent_set:
                                rewrite_references(
                                    parent_set,
                                    child,
                                    to_simplify,
                                    single_ref = True,
                                )
                            assert parent_set
                        to_delete.add( child['address'] )
    for item in to_delete:
        del index[item]
        del shared[item]

    return index

Response: Eliminate noise dictionary records from the overall index.


Instruction:
Can you generate a brief explanation for the following Python 3 code
def find_reachable( modules, index, shared, stop_types=STOP_TYPES ):
    reachable = set()
    already_seen = set()
    for module in modules:
        for child in recurse( module, index, stop_types=stop_types, already_seen=already_seen):
            reachable.add( child['address'] )
    return reachable

Response: Find all reachable objects from given root nodes.


Instruction:
Can you generate a brief explanation for the following Python 3 code
def deparent_unreachable( reachable, shared ):
    for id,shares in shared.iteritems():
        if id in reachable: # child is reachable
            filtered = [
                x
                for x in shares
                if x in reachable # only those parents which are reachable
            ]
            if len(filtered) != len(shares):
                shares[:] = filtered

Response: Eliminate all parent - links from unreachable objects from shared


Instruction:
Can you tell what is the following Python 3 function doing
def bind_parents( index, shared ):
    for v in iterindex( index ):
        v['parents'] = shared.get( v['address'], [] )

Response: Bind parents on all items in index


Instruction:
Write a Python 3 function for
finding appropriate root objects from which to recurse the hierarchies

Response:
def find_roots( disconnected, index, shared ):
    """Find appropriate "root" objects from which to recurse the hierarchies

    Will generate a synthetic root for anything which doesn't have any parents...
    """
    log.warn( '%s disconnected objects in %s total objects', len(disconnected), len(index))
    natural_roots = [x for x in disconnected if x.get('refs') and not x.get('parents')]
    log.warn( '%s objects with no parents at all' ,len(natural_roots))
    for natural_root in natural_roots:
        recurse_module(
            natural_root, index, shared
        )
        yield natural_root
    rest = [x for x in disconnected if x.get( 'totsize' ) is None]
    un_found = {
        'type': 'module',
        'name': '<disconnected objects>',
        'children': rest,
        'parents': [ ],
        'size': 0,
        'totsize': sum([x['size'] for x in rest],0),
        'address': new_address( index ),
    }
    index[un_found['address']] = un_found
    yield un_found


Instruction:
Create a Python 3 function for
retrieving the given root by type - key

Response:
def get_root( self, key ):
        """Retrieve the given root by type-key"""
        if key not in self.roots:
            root,self.rows = load( self.filename, include_interpreter = self.include_interpreter )
            self.roots[key] = root
        return self.roots[key]


Instruction:
Explain what the following Python 3 code does
def record_action(self, method_name, *args, **kwargs):
        self.actions.append((method_name, args, kwargs))

Response: Record the method - calling action.


Instruction:
Make a summary of the following Python 3 code
def play_actions(self, target):
        for method_name, args, kwargs in self.actions:
            method = getattr(target, method_name)
            method(*args, **kwargs)

Response: Play record actions on the target object.


Instruction:
Explain what the following Python 3 code does
def route(self, host, rule, **options):
        def decorator(func):
            endpoint = "{func.__module__}:{func.__name__}".format(func=func)
            self.record_action("add_url_rule", host, rule, endpoint, **options)
            return func
        return decorator

Response: The decorator to register wrapped function as the brownant app.


Instruction:
Implement a Python 3 function for
converting the input value into bytes type.

Response:
def to_bytes_safe(text, encoding="utf-8"):
    """Convert the input value into bytes type.

    If the input value is string type and could be encode as UTF-8 bytes, the
    encoded value will be returned. Otherwise, the encoding has failed, the
    origin value will be returned as well.

    :param text: the input value which could be string or bytes.
    :param encoding: the expected encoding be used while converting the string
                     input into bytes.
    :rtype: :class:`~__builtin__.bytes`
    """
    if not isinstance(text, (bytes, text_type)):
        raise TypeError("must be string type")

    if isinstance(text, text_type):
        return text.encode(encoding)

    return text


Instruction:
Explain what the following Python 3 code does
def get_attr(self, obj, name):
        attr_name = self.attr_names[name]
        return getattr(obj, attr_name)

Response:
Get the attribute of the target object with the configured attribute
        name.


Instruction:
Explain what the following Python 3 code does
def add_url_rule(self, host, rule_string, endpoint, **options):
        rule = Rule(rule_string, host=host, endpoint=endpoint, **options)
        self.url_map.add(rule)

Response: Add a url rule to the app instance.


Instruction:
Here you have a function in Python 3, explain what it does
def parse_url(self, url_string):
        url = urllib.parse.urlparse(url_string)
        url = self.validate_url(url)
        url_adapter = self.url_map.bind(server_name=url.hostname,
                                        url_scheme=url.scheme,
                                        path_info=url.path)
        query_args = url_decode(url.query)
        return url, url_adapter, query_args

Response: Parse the URL string with the url_map and return the url adapter and query_args.


Instruction:
Make a summary of the following Python 3 code
def validate_url(self, url):
        # fix up the non-ascii path
        url_path = to_bytes_safe(url.path)
        url_path = urllib.parse.quote(url_path, safe=b"/%")

        # fix up the non-ascii query
        url_query = to_bytes_safe(url.query)
        url_query = urllib.parse.quote(url_query, safe=b"?=&")

        url = urllib.parse.ParseResult(url.scheme, url.netloc, url_path,
                                       url.params, url_query, url.fragment)

        # validate the components of URL
        has_hostname = url.hostname is not None and len(url.hostname) > 0
        has_http_scheme = url.scheme in ("http", "https")
        has_path = not len(url.path) or url.path.startswith("/")

        if not (has_hostname and has_http_scheme and has_path):
            raise NotSupported("invalid url: %s" % repr(url))

        return url

Response:
Validate the :class:`~urllib.parse.ParseResult` object.

        This method will make sure the :meth:`~brownant.app.BrownAnt.parse_url`
        could work as expected even meet a unexpected URL string.

        :param url: the parsed url.
        :type url: :class:`~urllib.parse.ParseResult`


Instruction:
Explain what the following Python 3 code does
def dispatch_url(self, url_string):
        url, url_adapter, query_args = self.parse_url(url_string)

        try:
            endpoint, kwargs = url_adapter.match()
        except NotFound:
            raise NotSupported(url_string)
        except RequestRedirect as e:
            new_url = "{0.new_url}?{1}".format(e, url_encode(query_args))
            return self.dispatch_url(new_url)

        try:
            handler = import_string(endpoint)
            request = Request(url=url, args=query_args)
            return handler(request, **kwargs)
        except RequestRedirect as e:
            return self.dispatch_url(e.new_url)

Response: Dispatch the URL string to the target endpoint function.


Instruction:
How would you code a function in Python 3 to
mount a supported site to this app instance.

Response:
def mount_site(self, site):
        """Mount a supported site to this app instance.

        :param site: the site instance be mounted.
        """
        if isinstance(site, string_types):
            site = import_string(site)
        site.play_actions(target=self)


Instruction:
Given the following Python 3 function, write the documentation
def ping(self, *args, **kwargs):

        return self._makeApiCall(self.funcinfo["ping"], *args, **kwargs)

Response:
Ping Server

        Respond without doing anything.
        This endpoint is used to check that the service is up.

        This method is ``stable``


Instruction:
Can you tell what is the following Python 3 function doing
def githubWebHookConsumer(self, *args, **kwargs):

        return self._makeApiCall(self.funcinfo["githubWebHookConsumer"], *args, **kwargs)

Response: Consume GitHub WebHook events


Instruction:
Can you tell what is the following Python 3 function doing
def badge(self, *args, **kwargs):

        return self._makeApiCall(self.funcinfo["badge"], *args, **kwargs)

Response: Badge is a simple wrapper for the badge method


Instruction:
Write a Python 3 function that can
post a comment on a given GitHub Issue or Pull Request For a given Issue or Pull Request of a repository, this will write a new message. This method takes input: ``v1/create-comment.json#`` This method is ``experimental``

Response:
def createComment(self, *args, **kwargs):
        """
        Post a comment on a given GitHub Issue or Pull Request

        For a given Issue or Pull Request of a repository, this will write a new message.

        This method takes input: ``v1/create-comment.json#``

        This method is ``experimental``
        """

        return self._makeApiCall(self.funcinfo["createComment"], *args, **kwargs)


Instruction:
Can you generate the documentation for the following Python 3 function
def main():
    print()
    print("-~*~--~*~--~*~--~*~--~*~--~*~--~*~--~*~--~*~--~*~-")
    print(lorem_gotham_title().center(50))
    print("-~*~--~*~--~*~--~*~--~*~--~*~--~*~--~*~--~*~--~*~-")
    print()
    poem = lorem_gotham()
    for n in range(16):
        if n in (4, 8, 12):
            print()
        print(next(poem))
    print()

Response: I provide a command - line interface for this module


Instruction:
Can you generate a brief explanation for the following Python 3 code
async def listWorkerTypes(self, *args, **kwargs):

        return await self._makeApiCall(self.funcinfo["listWorkerTypes"], *args, **kwargs)

Response: This method returns a list of worker types known to be managed by this client.


Instruction:
Write a Python 3 script for
running an instance Request an instance of a worker type This method takes input: ``v1/run-instance-request.json#`` This method is ``experimental``

Response:
async def runInstance(self, *args, **kwargs):
        """
        Run an instance

        Request an instance of a worker type

        This method takes input: ``v1/run-instance-request.json#``

        This method is ``experimental``
        """

        return await self._makeApiCall(self.funcinfo["runInstance"], *args, **kwargs)


Instruction:
Can you generate a brief explanation for the following Python 3 code
async def workerTypeStats(self, *args, **kwargs):

        return await self._makeApiCall(self.funcinfo["workerTypeStats"], *args, **kwargs)

Response: This method returns the resource stats for a workerType


Instruction:
Write a Python 3 function that can
look up the resource health for a workerType Return a view of the health of a given worker type This method gives output: ``v1/health.json#`` This method is ``experimental``

Response:
async def workerTypeHealth(self, *args, **kwargs):
        """
        Look up the resource health for a workerType

        Return a view of the health of a given worker type

        This method gives output: ``v1/health.json#``

        This method is ``experimental``
        """

        return await self._makeApiCall(self.funcinfo["workerTypeHealth"], *args, **kwargs)


Instruction:
Create a Python 3 function for
looking up the most recent errors of a workerType Return a list of the most recent errors encountered by a worker type This method gives output: ``v1/errors.json#`` This method is ``experimental``

Response:
async def workerTypeErrors(self, *args, **kwargs):
        """
        Look up the most recent errors of a workerType

        Return a list of the most recent errors encountered by a worker type

        This method gives output: ``v1/errors.json#``

        This method is ``experimental``
        """

        return await self._makeApiCall(self.funcinfo["workerTypeErrors"], *args, **kwargs)


Instruction:
Explain what the following Python 3 code does
async def workerTypeState(self, *args, **kwargs):

        return await self._makeApiCall(self.funcinfo["workerTypeState"], *args, **kwargs)

Response: This method returns the state of a given worker type


Instruction:
Write a Python 3 script for
ensuring a KeyPair for a given worker type exists. Idempotently ensure that a KeyPair for a given worker type exists.

Response:
async def ensureKeyPair(self, *args, **kwargs):
        """
        Ensure a KeyPair for a given worker type exists

        Idempotently ensure that a keypair of a given name exists

        This method takes input: ``v1/create-key-pair.json#``

        This method is ``experimental``
        """

        return await self._makeApiCall(self.funcinfo["ensureKeyPair"], *args, **kwargs)


Instruction:
Write a Python 3 function that can
remove a KeyPair from the cluster

Response:
async def removeKeyPair(self, *args, **kwargs):
        """
        Ensure a KeyPair for a given worker type does not exist

        Ensure that a keypair of a given name does not exist.

        This method is ``experimental``
        """

        return await self._makeApiCall(self.funcinfo["removeKeyPair"], *args, **kwargs)


Instruction:
Can you generate the documentation for the following Python 3 function
async def terminateInstance(self, *args, **kwargs):

        return await self._makeApiCall(self.funcinfo["terminateInstance"], *args, **kwargs)

Response: Terminate an instance in a specified region


Instruction:
Implement a Python 3 function for
requesting prices for EC2 Return a list of possible prices for EC2 This method takes input: ``v1/prices-request.json#`` This method gives output: ``v1/prices.json#`` This method is ``experimental``

Response:
async def getSpecificPrices(self, *args, **kwargs):
        """
        Request prices for EC2

        Return a list of possible prices for EC2

        This method takes input: ``v1/prices-request.json#``

        This method gives output: ``v1/prices.json#``

        This method is ``experimental``
        """

        return await self._makeApiCall(self.funcinfo["getSpecificPrices"], *args, **kwargs)


Instruction:
Can you generate the documentation for the following Python 3 function
async def getHealth(self, *args, **kwargs):

        return await self._makeApiCall(self.funcinfo["getHealth"], *args, **kwargs)

Response: Get health of the EC2 account


Instruction:
Make a summary of the following Python 3 code
async def getRecentErrors(self, *args, **kwargs):

        return await self._makeApiCall(self.funcinfo["getRecentErrors"], *args, **kwargs)

Response: This method returns a list of recent errors encountered in the provisioner across all worker types


Instruction:
Write a Python 3 function for
returning the list of regions managed by this ec2 - manager

Response:
async def regions(self, *args, **kwargs):
        """
        See the list of regions managed by this ec2-manager

        This method is only for debugging the ec2-manager

        This method is ``experimental``
        """

        return await self._makeApiCall(self.funcinfo["regions"], *args, **kwargs)


Instruction:
Can you generate a brief explanation for the following Python 3 code
async def amiUsage(self, *args, **kwargs):

        return await self._makeApiCall(self.funcinfo["amiUsage"], *args, **kwargs)

Response: This method returns the list of AMIs and their usage by returning a list of objects in the form of a list of strings


Instruction:
How would you code a function in Python 3 to
see the current EBS volume usage list Lists current EBS volume usage by returning a list of objects that are uniquely defined by {region, volumetype, state} in the form: { region: string, volumetype: string, state: string, totalcount: integer, totalgb: integer, touched: timestamp (last time that information was updated), } This method is ``experimental``

Response:
async def ebsUsage(self, *args, **kwargs):
        """
        See the current EBS volume usage list

        Lists current EBS volume usage by returning a list of objects
        that are uniquely defined by {region, volumetype, state} in the form:
        {
        region: string,
          volumetype: string,
          state: string,
          totalcount: integer,
          totalgb: integer,
          touched: timestamp (last time that information was updated),
        }

        This method is ``experimental``
        """

        return await self._makeApiCall(self.funcinfo["ebsUsage"], *args, **kwargs)


Instruction:
Can you tell what is the following Python 3 function doing
async def sqsStats(self, *args, **kwargs):

        return await self._makeApiCall(self.funcinfo["sqsStats"], *args, **kwargs)

Response: This method returns statistics on the sqs queues


Instruction:
Write a Python 3 function that can
purge the SQS queues

Response:
async def purgeQueues(self, *args, **kwargs):
        """
        Purge the SQS queues

        This method is only for debugging the ec2-manager

        This method is ``experimental``
        """

        return await self._makeApiCall(self.funcinfo["purgeQueues"], *args, **kwargs)


Instruction:
Make a summary of the following Python 3 code
def rotating_cube(degree_change=3, frame_rate=3):
    degrees = 0
    while True:
        t1 = time.time()

        with Frame() as frame:
            oval_width = frame.width
            oval_height = frame.height / 3.0
            cube_height = int(oval_height * 2)

            (p1_x, p1_y) = ellipse_point(degrees, oval_width, oval_height)
            (p2_x, p2_y) = ellipse_point(degrees + 90, oval_width, oval_height)
            (p3_x, p3_y) = ellipse_point(degrees + 180, oval_width, oval_height)
            (p4_x, p4_y) = ellipse_point(degrees + 270, oval_width, oval_height)
            degrees = (degrees + degree_change) % 360

            # connect square thing at top
            frame.line(p1_x, p1_y, p2_x, p2_y)
            frame.line(p2_x, p2_y, p3_x, p3_y)
            frame.line(p3_x, p3_y, p4_x, p4_y)
            frame.line(p4_x, p4_y, p1_x, p1_y)

            # connect top to bottom
            frame.line(p1_x, p1_y, p1_x, p1_y + cube_height)
            frame.line(p2_x, p2_y, p2_x, p2_y + cube_height)
            frame.line(p3_x, p3_y, p3_x, p3_y + cube_height)
            frame.line(p4_x, p4_y, p4_x, p4_y + cube_height)

            # connect square thing at bottom
            frame.line(p1_x, p1_y + cube_height, p2_x, p2_y + cube_height)
            frame.line(p2_x, p2_y + cube_height, p3_x, p3_y + cube_height)
            frame.line(p3_x, p3_y + cube_height, p4_x, p4_y + cube_height)
            frame.line(p4_x, p4_y + cube_height, p1_x, p1_y + cube_height)

        elapsed = (time.time() - t1)
        time.sleep(abs(1.0 / frame_rate - elapsed))

Response: Rotating a single cube program.


Instruction:
Can you generate the documentation for the following Python 3 function
def line(self, x0, y0, x1, y1, c='*'):
        steep = abs(y1 - y0) > abs(x1 - x0)
        if steep:
            (x0, y0) = (y0, x0)
            (x1, y1) = (y1, x1)
        if x0 > x1:
            (x0, x1) = (x1, x0)
            (y0, y1) = (y1, y0)
        deltax = x1 - x0
        deltay = abs(y1 - y0)
        error = deltax / 2
        y = y0
        if y0 < y1:
            ystep = 1
        else:
            ystep = -1
        for x in range(x0, x1 - 1):
            if steep:
                self[y, x] = c
            else:
                self[x, y] = c
            error = error - deltay
            if error < 0:
                y = y + ystep
                error = error + deltax

Response: r Draws a line in the region of the area defined by x0 y0 x1 y1.


Instruction:
Here you have a function in Python 3, explain what it does
def terminateWorkerType(self, *args, **kwargs):

        return self._makeApiCall(self.funcinfo["terminateWorkerType"], *args, **kwargs)

Response: Terminate all resources from a worker type


Instruction:
Implement a function in Python 3 to
request prices for EC2 Return a list of possible prices for EC2 This method gives output: ``v1/prices.json#`` This method is ``experimental``

Response:
def getPrices(self, *args, **kwargs):
        """
        Request prices for EC2

        Return a list of possible prices for EC2

        This method gives output: ``v1/prices.json#``

        This method is ``experimental``
        """

        return self._makeApiCall(self.funcinfo["getPrices"], *args, **kwargs)


Instruction:
Here you have a function in Python 3, explain what it does
def allState(self, *args, **kwargs):

        return self._makeApiCall(self.funcinfo["allState"], *args, **kwargs)

Response: This method returns the entire internal state of the ec2 - manager


Instruction:
How would you implement a function in Python 3 that
gets Task Definition This end - point will return the task - definition.

Response:
def task(self, *args, **kwargs):
        """
        Get Task Definition

        This end-point will return the task-definition. Notice that the task
        definition may have been modified by queue, if an optional property is
        not specified the queue may provide a default value.

        This method gives output: ``v1/task.json#``

        This method is ``stable``
        """

        return self._makeApiCall(self.funcinfo["task"], *args, **kwargs)


Instruction:
Make a summary of the following Python 3 code
def defineTask(self, *args, **kwargs):

        return self._makeApiCall(self.funcinfo["defineTask"], *args, **kwargs)

Response: This is only present for legacy use.


Instruction:
Can you create a Python 3 function that
schedules a task for execution.

Response:
def scheduleTask(self, *args, **kwargs):
        """
        Schedule Defined Task

        scheduleTask will schedule a task to be executed, even if it has
        unresolved dependencies. A task would otherwise only be scheduled if
        its dependencies were resolved.

        This is useful if you have defined a task that depends on itself or on
        some other task that has not been resolved, but you wish the task to be
        scheduled immediately.

        This will announce the task as pending and workers will be allowed to
        claim it and resolve the task.

        **Note** this operation is **idempotent** and will not fail or complain
        if called with a `taskId` that is already scheduled, or even resolved.
        To reschedule a task previously resolved, use `rerunTask`.

        This method gives output: ``v1/task-status-response.json#``

        This method is ``stable``
        """

        return self._makeApiCall(self.funcinfo["scheduleTask"], *args, **kwargs)


Instruction:
How would you code a function in Python 3 to
rerun a previously resolved task

Response:
def rerunTask(self, *args, **kwargs):
        """
        Rerun a Resolved Task

        This method _reruns_ a previously resolved task, even if it was
        _completed_. This is useful if your task completes unsuccessfully, and
        you just want to run it from scratch again. This will also reset the
        number of `retries` allowed.

        This method is deprecated in favour of creating a new task with the same
        task definition (but with a new taskId).

        Remember that `retries` in the task status counts the number of runs that
        the queue have started because the worker stopped responding, for example
        because a spot node died.

        **Remark** this operation is idempotent, if you try to rerun a task that
        is not either `failed` or `completed`, this operation will just return
        the current task status.

        This method gives output: ``v1/task-status-response.json#``

        This method is ``deprecated``
        """

        return self._makeApiCall(self.funcinfo["rerunTask"], *args, **kwargs)


Instruction:
Can you implement a function in Python 3 that
cancels a scheduled task

Response:
def cancelTask(self, *args, **kwargs):
        """
        Cancel Task

        This method will cancel a task that is either `unscheduled`, `pending` or
        `running`. It will resolve the current run as `exception` with
        `reasonResolved` set to `canceled`. If the task isn't scheduled yet, ie.
        it doesn't have any runs, an initial run will be added and resolved as
        described above. Hence, after canceling a task, it cannot be scheduled
        with `queue.scheduleTask`, but a new run can be created with
        `queue.rerun`. These semantics is equivalent to calling
        `queue.scheduleTask` immediately followed by `queue.cancelTask`.

        **Remark** this operation is idempotent, if you try to cancel a task that
        isn't `unscheduled`, `pending` or `running`, this operation will just
        return the current task status.

        This method gives output: ``v1/task-status-response.json#``

        This method is ``stable``
        """

        return self._makeApiCall(self.funcinfo["cancelTask"], *args, **kwargs)


Instruction:
Create a Python 3 function for
reporting Run Failed Report Run Failed Report Run Failed Report Run Failed Report Run Failed Report Run Failed Report Run Failed Report Run Failed Report Run Failed Report Run Failed Report Run Failed Report Run Failed Report Run Failed

Response:
def reportFailed(self, *args, **kwargs):
        """
        Report Run Failed

        Report a run failed, resolving the run as `failed`. Use this to resolve
        a run that failed because the task specific code behaved unexpectedly.
        For example the task exited non-zero, or didn't produce expected output.

        Do not use this if the task couldn't be run because if malformed
        payload, or other unexpected condition. In these cases we have a task
        exception, which should be reported with `reportException`.

        This method gives output: ``v1/task-status-response.json#``

        This method is ``stable``
        """

        return self._makeApiCall(self.funcinfo["reportFailed"], *args, **kwargs)


Instruction:
Explain what the following Python 3 code does
def reportException(self, *args, **kwargs):

        return self._makeApiCall(self.funcinfo["reportException"], *args, **kwargs)

Response: Report a run as an exception.


Instruction:
Given the following Python 3 function, write the documentation
def createArtifact(self, *args, **kwargs):

        return self._makeApiCall(self.funcinfo["createArtifact"], *args, **kwargs)

Response: This method creates an artifact for a specific run of a task. This method is used by the Task s createArtifact method.


Instruction:
Explain what the following Python 3 code does
def completeArtifact(self, *args, **kwargs):

        return self._makeApiCall(self.funcinfo["completeArtifact"], *args, **kwargs)

Response: This endpoint finalises an artifact upload and returns the response.


Instruction:
Create a Python 3 function to
get a list of all active provisioners Get all active provisioners. The term "provisioner" is taken broadly to mean anything with a provisionerId. This does not necessarily mean there is an associated service performing any provisioning activity. The response is paged. If this end-point returns a `continuationToken`, you should call the end-point again with the `continuationToken` as a query-string option. By default this end-point will list up to 1000 provisioners in a single page. You may limit this with the query-string parameter `limit`. This method gives output: ``v1/list-provisioners-response.json#`` This method is ``experimental``

Response:
def listProvisioners(self, *args, **kwargs):
        """
        Get a list of all active provisioners

        Get all active provisioners.

        The term "provisioner" is taken broadly to mean anything with a provisionerId.
        This does not necessarily mean there is an associated service performing any
        provisioning activity.

        The response is paged. If this end-point returns a `continuationToken`, you
        should call the end-point again with the `continuationToken` as a query-string
        option. By default this end-point will list up to 1000 provisioners in a single
        page. You may limit this with the query-string parameter `limit`.

        This method gives output: ``v1/list-provisioners-response.json#``

        This method is ``experimental``
        """

        return self._makeApiCall(self.funcinfo["listProvisioners"], *args, **kwargs)


Instruction:
Can you generate the documentation for the following Python 3 function
def getProvisioner(self, *args, **kwargs):

        return self._makeApiCall(self.funcinfo["getProvisioner"], *args, **kwargs)

Response: Get an active provisioning


Instruction:
Create a Python 3 function for
declaring a provisioner. This is a simple API call to update a provisioner with some details about it.

Response:
def declareProvisioner(self, *args, **kwargs):
        """
        Update a provisioner

        Declare a provisioner, supplying some details about it.

        `declareProvisioner` allows updating one or more properties of a provisioner as long as the required scopes are
        possessed. For example, a request to update the `aws-provisioner-v1`
        provisioner with a body `{description: 'This provisioner is great'}` would require you to have the scope
        `queue:declare-provisioner:aws-provisioner-v1#description`.

        The term "provisioner" is taken broadly to mean anything with a provisionerId.
        This does not necessarily mean there is an associated service performing any
        provisioning activity.

        This method takes input: ``v1/update-provisioner-request.json#``

        This method gives output: ``v1/provisioner-response.json#``

        This method is ``experimental``
        """

        return self._makeApiCall(self.funcinfo["declareProvisioner"], *args, **kwargs)


Instruction:
Write a Python 3 script to
get Number of Pending Tasks

Response:
def pendingTasks(self, *args, **kwargs):
        """
        Get Number of Pending Tasks

        Get an approximate number of pending tasks for the given `provisionerId`
        and `workerType`.

        The underlying Azure Storage Queues only promises to give us an estimate.
        Furthermore, we cache the result in memory for 20 seconds. So consumers
        should be no means expect this to be an accurate number.
        It is, however, a solid estimate of the number of pending tasks.

        This method gives output: ``v1/pending-tasks-response.json#``

        This method is ``stable``
        """

        return self._makeApiCall(self.funcinfo["pendingTasks"], *args, **kwargs)


Instruction:
How would you implement a function in Python 3 that
quarantines a worker Quarantine a worker This method takes input: ``v1/quarantine-worker-request.json#`` This method gives output: ``v1/worker-response.json#`` This method is ``experimental``

Response:
def quarantineWorker(self, *args, **kwargs):
        """
        Quarantine a worker

        Quarantine a worker

        This method takes input: ``v1/quarantine-worker-request.json#``

        This method gives output: ``v1/worker-response.json#``

        This method is ``experimental``
        """

        return self._makeApiCall(self.funcinfo["quarantineWorker"], *args, **kwargs)


Instruction:
Can you generate the documentation for the following Python 3 function
def declareWorker(self, *args, **kwargs):

        return self._makeApiCall(self.funcinfo["declareWorker"], *args, **kwargs)

Response: This method allows you to declare a worker in the worker manager. It is intended to be used by the worker manager to update one or more properties of a worker.


Instruction:
Here you have a function in Python 3, explain what it does
async def findTask(self, *args, **kwargs):

        return await self._makeApiCall(self.funcinfo["findTask"], *args, **kwargs)

Response:
Find Indexed Task
        Find Indexed Task
        Find Indexed Task
        Find Indexed Task
        Find Indexed Task
        Find Indexed Task
TTtl Find Indexed Task
TTtl Find Indexed Task


Instruction:
How would you explain what the following Python 3 function does
async def listNamespaces(self, *args, **kwargs):

        return await self._makeApiCall(self.funcinfo["listNamespaces"], *args, **kwargs)

Response: This method returns the list of namespaces immediately under a given namespace.


Instruction:
Write a Python 3 function for
listing Tasks List the tasks immediately under a given namespace. This endpoint lists up to 1000 tasks. If more tasks are present, a `continuationToken` will be returned, which can be given in the next request. For the initial request, the payload should be an empty JSON object. **Remark**, this end-point is designed for humans browsing for tasks, not services, as that makes little sense. This method gives output: ``v1/list-tasks-response.json#`` This method is ``stable``

Response:
async def listTasks(self, *args, **kwargs):
        """
        List Tasks

        List the tasks immediately under a given namespace.

        This endpoint
        lists up to 1000 tasks. If more tasks are present, a
        `continuationToken` will be returned, which can be given in the next
        request. For the initial request, the payload should be an empty JSON
        object.

        **Remark**, this end-point is designed for humans browsing for tasks, not
        services, as that makes little sense.

        This method gives output: ``v1/list-tasks-response.json#``

        This method is ``stable``
        """

        return await self._makeApiCall(self.funcinfo["listTasks"], *args, **kwargs)


Instruction:
Given the following Python 3 function, write the documentation
async def insertTask(self, *args, **kwargs):

        return await self._makeApiCall(self.funcinfo["insertTask"], *args, **kwargs)

Response: Insert a task into the index.


Instruction:
Can you tell what is the following Python 3 function doing
async def findArtifactFromTask(self, *args, **kwargs):

        return await self._makeApiCall(self.funcinfo["findArtifactFromTask"], *args, **kwargs)

Response: Find an artifact from a task by its index path and redirect to the artifact on the most recent run with the given name.


Instruction:
Here you have a function in Python 3, explain what it does
async def allPurgeRequests(self, *args, **kwargs):

        return await self._makeApiCall(self.funcinfo["allPurgeRequests"], *args, **kwargs)

Response: All Purge Requests This endpoint returns a list of all open purge requests for the specified master and provisioner.


Instruction:
Create a Python 3 function for
purging Requests for a particular workerType

Response:
async def purgeRequests(self, *args, **kwargs):
        """
        Open Purge Requests for a provisionerId/workerType pair

        List of caches that need to be purged if they are from before
        a certain time. This is safe to be used in automation from
        workers.

        This method gives output: ``v1/purge-cache-request-list.json#``

        This method is ``stable``
        """

        return await self._makeApiCall(self.funcinfo["purgeRequests"], *args, **kwargs)


Instruction:
Can you generate the documentation for the following Python 3 function
def write(self, text):
        escape_parts = re.compile('\x01?\x1b\\[([0-9;]*)m\x02?')
        chunks = escape_parts.split(text)
        i = 0
        for chunk in chunks:
            if chunk != '':
                if i % 2 == 0:
                    self.stream.write(chunk)
                else:
                    c = chunk.split(';')
                    r = Magic.rdisplay(c)
                    self.display(**r) #see caveat 0
                self.flush()
            i += 1

Response: Parses the text and prints proper output to the terminal


Instruction:
Explain what the following Python 3 code does
def getch(self):
        return NotImplemented
        fno = stdout.fileno()
        mode = self.termios.tcgetattr(fno)
        try:
            self.tty.setraw(fno, self.termios.TCSANOW)
            ch = self.read(1)
        finally:
            self.termios.tcsetattr(fno, self.termios.TCSANOW, mode)
        return ch

Response: Return a single character from the terminal.


Instruction:
How would you implement a function in Python 3 that
displays the codes using ANSI escapes

Response:
def display(self, codes=[], fg=None, bg=None):
        """Displays the codes using ANSI escapes
        """
        codes, fg, bg = Magic.displayformat(codes, fg, bg)
        self.stream.write(Magic.display(codes, fg, bg))
        self.flush()


Instruction:
How would you implement a function in Python 3 that
moves the term to a new location

Response:
def move(self, place, distance = 1):
        """see doc in Term class"""
        for d in range(distance):
            self.stream.write(self._get_cap('move '+place))
        self.flush()


Instruction:
Make a summary of the following Python 3 code
def clear(self, scope = 'screen'):
        if scope == 'line':
            self.clear('beginning of line')
            self.clear('end of line')
        else: self.stream.write(self._get_cap('clear '+scope))
        self.flush()

Response: see doc in Term class


Instruction:
Here you have a function in Python 3, explain what it does
def get_size(self):
        self.curses.setupterm()
        return self.curses.tigetnum('cols'), self.curses.tigetnum('lines')

Response: return the number of columns and lines


Instruction:
How would you explain what the following Python 3 function does
def display(self, codes=[], fg=None, bg=None):
        codes, fg, bg = Magic.displayformat(codes, fg, bg)
        color = 0
        for c in codes:
            try:
                f = getattr(self, '_display_' + c)
                out = f()
                if out: color |= out
            except AttributeError:
                pass
        cfg, cfgi, cbg, cbgi = self._split_attributes(
                          self._get_console_info()['attributes'])
        if self.reverse_input:
            cfg, cbg = (cbg // 0x10), (cfg * 0x10)
            cfgi, cbgi = (cbgi // 0x10), (cfgi * 0x10)
        if fg != None:
            color |= self.FG[fg]
            self.real_fg = self.FG[fg]
        else: color |= cfg
        if bg != None:
            color |= self.BG[bg]
        else: color |= cbg
        color |= (cfgi | cbgi)
        fg, fgi, bg, bgi = self._split_attributes(color)
        if self.dim_output:
            # intense black
            fg = 0
            fgi = self.FG_INTENSITY
        if self.reverse_output:
            fg, bg = (bg // 0x10), (fg * 0x10)
            fgi, bgi = (bgi // 0x10), (fgi * 0x10)
            self.reverse_input = True
        if self.hidden_output:
            fg = (bg // 0x10)
            fgi = (bgi // 0x10)
        self._set_attributes(fg | fgi | bg | bgi)

Response: Displays the codes using Windows kernel calls.


Instruction:
Can you write a function in Python 3 where it
sees doc in Term class

Response:
def get_size(self):
        """see doc in Term class"""
        attr = self._get_console_info()
        cols = attr['window']['right'] - attr['window']['left'] + 1
        lines = attr['window']['bottom'] - attr['window']['top'] + 1
        return cols, lines


Instruction:
Can you implement a function in Python 3 that
splits the attributes into foreground background and background intensity.

Response:
def _split_attributes(self, attrs):
        """Spilt attribute code

        Takes an attribute code and returns a tuple containing
        foreground (fg), foreground intensity (fgi), background (bg), and
        background intensity (bgi)

        Attributes can be joined using ``fg | fgi | bg | bgi``
        """
        fg = attrs & self.FG_ALL
        fgi = attrs & self.FG_INTENSITY
        bg = attrs & self.BG_ALL
        bgi = attrs & self.BG_INTENSITY
        return fg, fgi, bg, bgi


Instruction:
Can you create a Python 3 function that
moves the term to a specific location

Response:
def move(self, place, distance = 1):
        """see doc in Term class"""
        x, y = self._get_position()
        if place == 'up':
            y -= distance
        elif place == 'down':
            for i in range(distance): print
            nx, ny = self._get_position()
            y = ny
            self.move('beginning of line')
        elif place == 'left':
            x -= distance
        elif place == 'right':
            x += distance
        elif place == 'beginning of line':
            x = 0
        elif place == 'beginning of screen':
            x = 0
            y = self._get_console_info()['window']['top']
        else:
            raise ValueError("invalid place to move")
        self._set_position((x, y))


Instruction:
How would you implement a function in Python 3 that
sees doc in Term class According to http://support.microsoft.com/kb/99261 the best way to clear the console is to write out empty spaces

Response:
def clear(self, scope = 'screen'):
        """see doc in Term class

        According to http://support.microsoft.com/kb/99261 the best way
        to clear the console is to write out empty spaces
        """
        #TODO: clear attributes too
        if scope == 'screen':
            bos = (0, self._get_console_info()['window']['top'])
            cols, lines = self.get_size()
            length = cols * lines
            self._clear_console(length, bos)
            self.move('beginning of screen')
        elif scope == ' beginning of line':
            pass
        elif scope == 'end of line':
            curx, cury = self._get_position()
            cols, lines = self.get_size()
            coord = (curx, cury)
            length = cols - curx
            self._clear_console(length, coord)
        elif scope == 'end of screen':
            curx, cury = self._get_position()
            coord = (curx, cury)
            cols, lines = self.get_size()
            length = (lines - cury) * cols - curx
            self._clear_console(length, coord)
        elif scope == 'line':
            curx, cury = self._get_position()
            coord = (0, cury)
            cols, lines = self.get_size()
            self._clear_console(cols, coord)
            self._set_position((curx, cury))
        elif scope == 'left':
            self.move('left')
            self.write(' ')
        elif scope == 'right':
            self.write(' ')
            self.move('left')
        else:
            raise ValueError("invalid scope to clear")


Instruction:
Explain what the following Python 3 code does
def _get_title(self):
        #TODO: unicode support
        strbuffer = self.ctypes.create_string_buffer(1024)
        size = self.ctypes.c_short(1024)
        #unicode versions are (Get|Set)ConsolTitleW
        self.ctypes.windll.kernel32.GetConsoleTitleA(strbuffer, size)
        return strbuffer.value

Response: Get the title of the current console entry.


Instruction:
Can you implement a function in Python 3 that
gets the coord of the current log entry.

Response:
def _get_coord(self, coord):
        """ It's a hack, see fixcoord in pyreadline's console.py (revision
        1289)
        """
        x, y = coord
        return self.ctypes.c_int(y << 16 | x)


Instruction:
Implement a function in Python 3 to
make sure all arguments are valid

Response:
def displayformat(codes=[], fg=None, bg=None):
        """Makes sure all arguments are valid"""
        if isinstance(codes, basestring):
            codes = [codes]
        else:
            codes = list(codes)
        for code in codes:
            if code not in Magic.DISPLAY.keys():
                raise ValueError("'%s' not a valid display value" % code)
        for color in (fg, bg):
            if color != None:
                if color not in Magic.COLORS.keys():
                    raise ValueError("'%s' not a valid color" % color)
        return [codes, fg, bg]


Instruction:
Write a Python 3 script to
read a list of codes and generates dict

Response:
def rdisplay(codes):
        """Reads a list of codes and generates dict

        >>> Magic.rdisplay([])
        {}
        >>> result = Magic.rdisplay([1,2,34,46])
        >>> sorted(result.keys())
        ['bg', 'codes', 'fg']
        >>> sorted(result['codes'])
        ['bright', 'dim']
        >>> result['bg']
        'cyan'
        >>> result['fg']
        'blue'
        """
        dcodes = []
        fg = bg = None
        for code in codes:
            code = int(code)
            offset = code // 10
            decimal = code % 10
            if offset == 3 and decimal in Magic.COLORS.values(): fg = decimal
            elif offset == 4 and decimal in Magic.COLORS.values(): bg = decimal
            elif code in Magic.DISPLAY.values(): dcodes.append(code)
            else: pass # drop unhandled values
        r = {}
        if len(codes): r['codes'] = [Magic.rDISPLAY[c] for c in dcodes]
        if fg != None: r['fg'] = Magic.rCOLORS[fg]
        if bg != None: r['bg'] = Magic.rCOLORS[bg]
        return r


Instruction:
Can you implement a function in Python 3 that
lists Clients with the same prefix

Response:
def listClients(self, *args, **kwargs):
        """
        List Clients

        Get a list of all clients.  With `prefix`, only clients for which
        it is a prefix of the clientId are returned.

        By default this end-point will try to return up to 1000 clients in one
        request. But it **may return less, even none**.
        It may also return a `continuationToken` even though there are no more
        results. However, you can only be sure to have seen all results if you
        keep calling `listClients` with the last `continuationToken` until you
        get a result without a `continuationToken`.

        This method gives output: ``v1/list-clients-response.json#``

        This method is ``stable``
        """

        return self._makeApiCall(self.funcinfo["listClients"], *args, **kwargs)


Instruction:
Can you create a Python 3 function that
gets information about a single client

Response:
def client(self, *args, **kwargs):
        """
        Get Client

        Get information about a single client.

        This method gives output: ``v1/get-client-response.json#``

        This method is ``stable``
        """

        return self._makeApiCall(self.funcinfo["client"], *args, **kwargs)


Instruction:
Write a Python 3 function that can
create Client Create a new client and get the `accessToken` for this client. You should store the `accessToken` from this API call as there is no other way to retrieve it. If you loose the `accessToken` you can call `resetAccessToken` to reset it, and a new `accessToken` will be returned, but you cannot retrieve the current `accessToken`. If a client with the same `clientId` already exists this operation will fail. Use `updateClient` if you wish to update an existing client. The caller's scopes must satisfy `scopes`. This method takes input: ``v1/create-client-request.json#`` This method gives output: ``v1/create-client-response.json#`` This method is ``stable``

Response:
def createClient(self, *args, **kwargs):
        """
        Create Client

        Create a new client and get the `accessToken` for this client.
        You should store the `accessToken` from this API call as there is no
        other way to retrieve it.

        If you loose the `accessToken` you can call `resetAccessToken` to reset
        it, and a new `accessToken` will be returned, but you cannot retrieve the
        current `accessToken`.

        If a client with the same `clientId` already exists this operation will
        fail. Use `updateClient` if you wish to update an existing client.

        The caller's scopes must satisfy `scopes`.

        This method takes input: ``v1/create-client-request.json#``

        This method gives output: ``v1/create-client-response.json#``

        This method is ``stable``
        """

        return self._makeApiCall(self.funcinfo["createClient"], *args, **kwargs)


Instruction:
Implement a Python 3 function for
updating Client Update an exisiting client. The `clientId` and `accessToken` cannot be updated, but `scopes` can be modified. The caller's scopes must satisfy all scopes being added to the client in the update operation. If no scopes are given in the request, the client's scopes remain unchanged This method takes input: ``v1/create-client-request.json#`` This method gives output: ``v1/get-client-response.json#`` This method is ``stable``

Response:
def updateClient(self, *args, **kwargs):
        """
        Update Client

        Update an exisiting client. The `clientId` and `accessToken` cannot be
        updated, but `scopes` can be modified.  The caller's scopes must
        satisfy all scopes being added to the client in the update operation.
        If no scopes are given in the request, the client's scopes remain
        unchanged

        This method takes input: ``v1/create-client-request.json#``

        This method gives output: ``v1/get-client-response.json#``

        This method is ``stable``
        """

        return self._makeApiCall(self.funcinfo["updateClient"], *args, **kwargs)


Instruction:
Write a Python 3 script for
enabling a client that was disabled with disableClient.

Response:
def enableClient(self, *args, **kwargs):
        """
        Enable Client

        Enable a client that was disabled with `disableClient`.  If the client
        is already enabled, this does nothing.

        This is typically used by identity providers to re-enable clients that
        had been disabled when the corresponding identity's scopes changed.

        This method gives output: ``v1/get-client-response.json#``

        This method is ``stable``
        """

        return self._makeApiCall(self.funcinfo["enableClient"], *args, **kwargs)


Instruction:
Can you generate the documentation for the following Python 3 function
def disableClient(self, *args, **kwargs):

        return self._makeApiCall(self.funcinfo["disableClient"], *args, **kwargs)

Response:
Disable Client

        Disable a client.  If the client is already disabled, this does nothing.

        This is typically used by identity providers to disable clients when the
        corresponding identity's scopes no longer satisfy the client's scopes.

        This method gives output: ``v1/get-client-response.json#``

        This method is ``stable``


Instruction:
Can you generate the documentation for the following Python 3 function
def deleteClient(self, *args, **kwargs):

        return self._makeApiCall(self.funcinfo["deleteClient"], *args, **kwargs)

Response:
Delete Client

        Delete a client, please note that any roles related to this client must
        be deleted independently.

        This method is ``stable``


Instruction:
Given the following Python 3 function, write the documentation
def listRoles(self, *args, **kwargs):

        return self._makeApiCall(self.funcinfo["listRoles"], *args, **kwargs)

Response: This method returns a list of all roles in the system


Instruction:
Create a Python 3 function for
listing Role IDs If no limit is given, the roleIds of all roles are returned. Since this list may become long, callers can use the `limit` and `continuationToken` query arguments to page through the responses. This method gives output: ``v1/list-role-ids-response.json#`` This method is ``stable``

Response:
def listRoleIds(self, *args, **kwargs):
        """
        List Role IDs

        If no limit is given, the roleIds of all roles are returned. Since this
        list may become long, callers can use the `limit` and `continuationToken`
        query arguments to page through the responses.

        This method gives output: ``v1/list-role-ids-response.json#``

        This method is ``stable``
        """

        return self._makeApiCall(self.funcinfo["listRoleIds"], *args, **kwargs)


Instruction:
How would you explain what the following Python 3 function does
def listRoles2(self, *args, **kwargs):

        return self._makeApiCall(self.funcinfo["listRoles2"], *args, **kwargs)

Response: This is the base API endpoint for listing the roles in the second level of the user.


Instruction:
Write a Python 3 script to
create a new role

Response:
def createRole(self, *args, **kwargs):
        """
        Create Role

        Create a new role.

        The caller's scopes must satisfy the new role's scopes.

        If there already exists a role with the same `roleId` this operation
        will fail. Use `updateRole` to modify an existing role.

        Creation of a role that will generate an infinite expansion will result
        in an error response.

        This method takes input: ``v1/create-role-request.json#``

        This method gives output: ``v1/get-role-response.json#``

        This method is ``stable``
        """

        return self._makeApiCall(self.funcinfo["createRole"], *args, **kwargs)


Instruction:
Explain what the following Python 3 code does
def updateRole(self, *args, **kwargs):

        return self._makeApiCall(self.funcinfo["updateRole"], *args, **kwargs)

Response: This is a private API call to update a role. This is a private API call.


Instruction:
Can you generate a brief explanation for the following Python 3 code
def deleteRole(self, *args, **kwargs):

        return self._makeApiCall(self.funcinfo["deleteRole"], *args, **kwargs)

Response:
Delete Role

        Delete a role. This operation will succeed regardless of whether or not
        the role exists.

        This method is ``stable``


Instruction:
How would you explain what the following Python 3 function does
def expandScopesGet(self, *args, **kwargs):

        return self._makeApiCall(self.funcinfo["expandScopesGet"], *args, **kwargs)

Response:
This is a convenience method that returns an expanded copy of the given scopeset with implied by any
        roles included.


Instruction:
Write a Python 3 function for
expanding Scopes Return an expanded copy of the given scopeset, with scopes implied by any roles included. This method takes input: ``v1/scopeset.json#`` This method gives output: ``v1/scopeset.json#`` This method is ``stable``

Response:
def expandScopes(self, *args, **kwargs):
        """
        Expand Scopes

        Return an expanded copy of the given scopeset, with scopes implied by any
        roles included.

        This method takes input: ``v1/scopeset.json#``

        This method gives output: ``v1/scopeset.json#``

        This method is ``stable``
        """

        return self._makeApiCall(self.funcinfo["expandScopes"], *args, **kwargs)


Instruction:
Make a summary of the following Python 3 code
def currentScopes(self, *args, **kwargs):

        return self._makeApiCall(self.funcinfo["currentScopes"], *args, **kwargs)

Response: Get the expanded scopes available in the request


Instruction:
How would you implement a function in Python 3 that
gets Temporary Read/Write Credentials S3 Get temporary AWS credentials for `read-write` or `read-only` access to a given `bucket` and `prefix` within that bucket. The `level` parameter can be `read-write` or `read-only` and determines which type of credentials are returned. Please note that the `level` parameter is required in the scope guarding access. The bucket name must not contain `.`, as recommended by Amazon. This method can only allow access to a whitelisted set of buckets. To add a bucket to that whitelist, contact the Taskcluster team, who will add it to the appropriate IAM policy. If the bucket is in a different AWS account, you will also need to add a bucket policy allowing access from the Taskcluster account. That policy should look like this: ``` { "Version": "2012-10-17", "Statement": [ { "Sid": "allow-taskcluster-auth-to-delegate-access", "Effect": "Allow", "Principal": { "AWS": "arn:aws:iam::692406183521:root" }, "Action": [ "s3:ListBucket", "s3:GetObject", "s3:PutObject", "s3:DeleteObject", "s3:GetBucketLocation" ], "Resource": [ "arn:aws:s3:::<bucket>", "arn:aws:s3:::<bucket>/*" ] } ] } ``` The credentials are set to expire after an hour, but this behavior is subject to change. Hence, you should always read the `expires` property from the response, if you intend to maintain active credentials in your application. Please note that your `prefix` may not start with slash `/`. Such a prefix is allowed on S3, but we forbid it here to discourage bad behavior. Also note that if your `prefix` doesn't end in a slash `/`, the STS credentials may allow access to unexpected keys, as S3 does not treat slashes specially. For example, a prefix of `my-folder` will allow access to `my-folder/file.txt` as expected, but also to `my-folder.txt`, which may not be intended. Finally, note that the `PutObjectAcl` call is not allowed. Passing a canned ACL other than `private` to `PutObject` is treated as a `PutObjectAcl` call, and will result in an access-denied error from AWS. This limitation is due to a security flaw in Amazon S3 which might otherwise allow indefinite access to uploaded objects. **EC2 metadata compatibility**, if the querystring parameter `?format=iam-role-compat` is given, the response will be compatible with the JSON exposed by the EC2 metadata service. This aims to ease compatibility for libraries and tools built to auto-refresh credentials. For details on the format returned by EC2 metadata service see: [EC2 User Guide](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html#instance-metadata-security-credentials). This method gives output: ``v1/aws-s3-credentials-response.json#`` This method is ``stable``

Response:
def awsS3Credentials(self, *args, **kwargs):
        """
        Get Temporary Read/Write Credentials S3

        Get temporary AWS credentials for `read-write` or `read-only` access to
        a given `bucket` and `prefix` within that bucket.
        The `level` parameter can be `read-write` or `read-only` and determines
        which type of credentials are returned. Please note that the `level`
        parameter is required in the scope guarding access.  The bucket name must
        not contain `.`, as recommended by Amazon.

        This method can only allow access to a whitelisted set of buckets.  To add
        a bucket to that whitelist, contact the Taskcluster team, who will add it to
        the appropriate IAM policy.  If the bucket is in a different AWS account, you
        will also need to add a bucket policy allowing access from the Taskcluster
        account.  That policy should look like this:

        ```
        {
          "Version": "2012-10-17",
          "Statement": [
            {
              "Sid": "allow-taskcluster-auth-to-delegate-access",
              "Effect": "Allow",
              "Principal": {
                "AWS": "arn:aws:iam::692406183521:root"
              },
              "Action": [
                "s3:ListBucket",
                "s3:GetObject",
                "s3:PutObject",
                "s3:DeleteObject",
                "s3:GetBucketLocation"
              ],
              "Resource": [
                "arn:aws:s3:::<bucket>",
                "arn:aws:s3:::<bucket>/*"
              ]
            }
          ]
        }
        ```

        The credentials are set to expire after an hour, but this behavior is
        subject to change. Hence, you should always read the `expires` property
        from the response, if you intend to maintain active credentials in your
        application.

        Please note that your `prefix` may not start with slash `/`. Such a prefix
        is allowed on S3, but we forbid it here to discourage bad behavior.

        Also note that if your `prefix` doesn't end in a slash `/`, the STS
        credentials may allow access to unexpected keys, as S3 does not treat
        slashes specially.  For example, a prefix of `my-folder` will allow
        access to `my-folder/file.txt` as expected, but also to `my-folder.txt`,
        which may not be intended.

        Finally, note that the `PutObjectAcl` call is not allowed.  Passing a canned
        ACL other than `private` to `PutObject` is treated as a `PutObjectAcl` call, and
        will result in an access-denied error from AWS.  This limitation is due to a
        security flaw in Amazon S3 which might otherwise allow indefinite access to
        uploaded objects.

        **EC2 metadata compatibility**, if the querystring parameter
        `?format=iam-role-compat` is given, the response will be compatible
        with the JSON exposed by the EC2 metadata service. This aims to ease
        compatibility for libraries and tools built to auto-refresh credentials.
        For details on the format returned by EC2 metadata service see:
        [EC2 User Guide](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html#instance-metadata-security-credentials).

        This method gives output: ``v1/aws-s3-credentials-response.json#``

        This method is ``stable``
        """

        return self._makeApiCall(self.funcinfo["awsS3Credentials"], *args, **kwargs)


Instruction:
Can you tell what is the following Python 3 function doing
def azureTables(self, *args, **kwargs):

        return self._makeApiCall(self.funcinfo["azureTables"], *args, **kwargs)

Response: This method returns a list of all tables in an Account managed by Auth


Instruction:
Can you write a function in Python 3 where it
gets Shared-Access-Signature for Azure Table Get a shared access signature (SAS) string for use with a specific Azure Table Storage table. The `level` parameter can be `read-write` or `read-only` and determines which type of credentials are returned. If level is read-write, it will create the table if it doesn't already exist. This method gives output: ``v1/azure-table-access-response.json#`` This method is ``stable``

Response:
def azureTableSAS(self, *args, **kwargs):
        """
        Get Shared-Access-Signature for Azure Table

        Get a shared access signature (SAS) string for use with a specific Azure
        Table Storage table.

        The `level` parameter can be `read-write` or `read-only` and determines
        which type of credentials are returned.  If level is read-write, it will create the
        table if it doesn't already exist.

        This method gives output: ``v1/azure-table-access-response.json#``

        This method is ``stable``
        """

        return self._makeApiCall(self.funcinfo["azureTableSAS"], *args, **kwargs)


Instruction:
Explain what the following Python 3 code does
def azureContainers(self, *args, **kwargs):

        return self._makeApiCall(self.funcinfo["azureContainers"], *args, **kwargs)

Response: This method returns a list of all containers in an Account managed by Auth


Instruction:
How would you implement a function in Python 3 that
gets Shared-Access-Signature for Azure Container Get a shared access signature (SAS) string for use with a specific Azure Blob Storage container. The `level` parameter can be `read-write` or `read-only` and determines which type of credentials are returned. If level is read-write, it will create the container if it doesn't already exist. This method gives output: ``v1/azure-container-response.json#`` This method is ``stable``

Response:
def azureContainerSAS(self, *args, **kwargs):
        """
        Get Shared-Access-Signature for Azure Container

        Get a shared access signature (SAS) string for use with a specific Azure
        Blob Storage container.

        The `level` parameter can be `read-write` or `read-only` and determines
        which type of credentials are returned.  If level is read-write, it will create the
        container if it doesn't already exist.

        This method gives output: ``v1/azure-container-response.json#``

        This method is ``stable``
        """

        return self._makeApiCall(self.funcinfo["azureContainerSAS"], *args, **kwargs)


Instruction:
Can you tell what is the following Python 3 function doing
def sentryDSN(self, *args, **kwargs):

        return self._makeApiCall(self.funcinfo["sentryDSN"], *args, **kwargs)

Response: Sentry DSN for a Sentry Project


Instruction:
Can you generate a brief explanation for the following Python 3 code
def statsumToken(self, *args, **kwargs):

        return self._makeApiCall(self.funcinfo["statsumToken"], *args, **kwargs)

Response: This method returns a Statsum Token for Statsum Project


Instruction:
Write a Python 3 function for
getting a client token for the Websocktunnel service Get a temporary token suitable for use connecting to a [websocktunnel](https://github.com/taskcluster/websocktunnel) server. The resulting token will only be accepted by servers with a matching audience value. Reaching such a server is the callers responsibility. In general, a server URL or set of URLs should be provided to the caller as configuration along with the audience value. The token is valid for a limited time (on the scale of hours). Callers should refresh it before expiration. This method gives output: ``v1/websocktunnel-token-response.json#`` This method is ``stable``

Response:
def websocktunnelToken(self, *args, **kwargs):
        """
        Get a client token for the Websocktunnel service

        Get a temporary token suitable for use connecting to a
        [websocktunnel](https://github.com/taskcluster/websocktunnel) server.

        The resulting token will only be accepted by servers with a matching audience
        value.  Reaching such a server is the callers responsibility.  In general,
        a server URL or set of URLs should be provided to the caller as configuration
        along with the audience value.

        The token is valid for a limited time (on the scale of hours). Callers should
        refresh it before expiration.

        This method gives output: ``v1/websocktunnel-token-response.json#``

        This method is ``stable``
        """

        return self._makeApiCall(self.funcinfo["websocktunnelToken"], *args, **kwargs)