Python past.builtins.map() Examples

The following are 26 code examples of past.builtins.map(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module past.builtins , or try the search function .
Example #1
Source File: fuzz_logger.py    From boofuzz with GNU General Public License v2.0 6 votes vote down vote up
def failure_summary(self):
        """Return test summary string based on fuzz logger results.

        :return: Test summary string, may be multi-line.
        """
        summary = "Test Summary: {0} tests ran.\n".format(len(self.all_test_cases))
        summary += "PASSED: {0} test cases.\n".format(len(self.passed_test_cases))

        if len(self.failed_test_cases) > 0:
            summary += "FAILED: {0} test cases:\n".format(len(self.failed_test_cases))
            summary += "{0}\n".format("\n".join(map(str, self.failed_test_cases)))

        if len(self.error_test_cases) > 0:
            summary += "Errors on {0} test cases:\n".format(len(self.error_test_cases))
            summary += "{0}".format("\n".join(map(str, self.error_test_cases)))

        return summary 
Example #2
Source File: guide.py    From RAFCON with Eclipse Public License 1.0 6 votes vote down vote up
def find_vertical_guides(self, item_vedges, pdx, height, excluded_items):
        # The root state cannot be aligned
        if not self.item.parent:
            return 0, ()

        states_v = self._get_siblings_and_parent()

        try:
            guides = list(map(Guide, states_v))
        except TypeError:
            guides = []

        vedges = set()
        for g in guides:
            for x in g.vertical():
                vedges.add(self.view.get_matrix_i2v(g.item).transform_point(x, 0)[0])
        dx, edges_x = self.find_closest(item_vedges, vedges)

        return dx, edges_x 
Example #3
Source File: guide.py    From RAFCON with Eclipse Public License 1.0 6 votes vote down vote up
def find_horizontal_guides(self, item_hedges, pdy, width, excluded_items):
        # The root state cannot be aligned
        if not self.item.parent:
            return 0, ()

        states_v = self._get_siblings_and_parent()

        try:
            guides = list(map(Guide, states_v))
        except TypeError:
            guides = []

        hedges = set()
        for g in guides:
            for y in g.horizontal():
                hedges.add(self.view.get_matrix_i2v(g.item).transform_point(0, y)[1])

        dy, edges_y = self.find_closest(item_hedges, hedges)
        return dy, edges_y 
Example #4
Source File: gatt.py    From Adafruit_Python_BluefruitLE with MIT License 6 votes vote down vote up
def start_notify(self, on_change):
        """Enable notification of changes for this characteristic on the
        specified on_change callback.  on_change should be a function that takes
        one parameter which is the value (as a string of bytes) of the changed
        characteristic value.
        """
        # Setup a closure to be the first step in handling the on change callback.
        # This closure will verify the characteristic is changed and pull out the
        # new value to pass to the user's on change callback.
        def characteristic_changed(iface, changed_props, invalidated_props):
            # Check that this change is for a GATT characteristic and it has a
            # new value.
            if iface != _CHARACTERISTIC_INTERFACE:
                return
            if 'Value' not in changed_props:
                return
            # Send the new value to the on_change callback.
            on_change(''.join(map(chr, changed_props['Value'])))
        # Hook up the property changed signal to call the closure above.
        self._props.connect_to_signal('PropertiesChanged', characteristic_changed)
        # Enable notifications for changes on the characteristic.
        self._characteristic.StartNotify() 
Example #5
Source File: helpers.py    From boofuzz with GNU General Public License v2.0 6 votes vote down vote up
def ipv4_checksum(msg):
    """
    Return IPv4 checksum of msg.
    :param msg: Message to compute checksum over.
    :type msg: bytes

    :return: IPv4 checksum of msg.
    :rtype: int
    """
    # Pad with 0 byte if needed
    if len(msg) % 2 == 1:
        msg += b"\x00"

    msg_words = map(_collate_bytes, msg[0::2], msg[1::2])
    total = reduce(_ones_complement_sum_carry_16, msg_words, 0)
    return ~total & 0xFFFF 
Example #6
Source File: helpers.py    From boofuzz with GNU General Public License v2.0 6 votes vote down vote up
def uuid_str_to_bin(uuid):
    """
    Converts a UUID string to binary form.

    Expected string input format is same as uuid_bin_to_str()'s output format.

    Ripped from Core Impacket.

    :param uuid: UUID string to convert to bytes.
    :type uuid: str
    :return: UUID as bytes.
    :rtype: bytes
    """
    uuid_re = r"([\dA-Fa-f]{8})-([\dA-Fa-f]{4})-([\dA-Fa-f]{4})-([\dA-Fa-f]{4})-([\dA-Fa-f]{4})([\dA-Fa-f]{8})"

    matches = re.match(uuid_re, uuid)

    # pytype: disable=attribute-error
    (uuid1, uuid2, uuid3, uuid4, uuid5, uuid6) = map(lambda x: int(x, 16), matches.groups())
    # pytype: enable=attribute-error

    uuid = struct.pack("<LHH", uuid1, uuid2, uuid3)
    uuid += struct.pack(">HHL", uuid4, uuid5, uuid6)

    return uuid 
Example #7
Source File: __init__.py    From boofuzz with GNU General Public License v2.0 6 votes vote down vote up
def s_update(name, value):
    """
    Update the value of the named primitive in the currently open request.

    :type  name:  str
    :param name:  Name of object whose value we wish to update
    :type  value: Mixed
    :param value: Updated value
    """

    if name not in map(lambda o: o.name, blocks.CURRENT.walk()):
        raise exception.SullyRuntimeError("NO OBJECT WITH NAME '%s' FOUND IN CURRENT REQUEST" % name)

    blocks.CURRENT.names[name].value = value


# PRIMITIVES 
Example #8
Source File: toilStatus.py    From toil with Apache License 2.0 6 votes vote down vote up
def print_dot_chart(self):
        """Print a dot output graph representing the workflow."""
        print("digraph toil_graph {")
        print("# This graph was created from job-store: %s" % self.jobStoreName)

        # Make job IDs to node names map
        jobsToNodeNames = dict(enumerate(map(lambda job: job.jobStoreID, self.jobsToReport)))

        # Print the nodes
        for job in set(self.jobsToReport):
            print('%s [label="%s %s"];' % (
                jobsToNodeNames[job.jobStoreID], job.jobName, job.jobStoreID))

        # Print the edges
        for job in set(self.jobsToReport):
            for level, jobList  in enumerate(job.stack):
                for childJob in jobList:
                    # Check, b/c successor may be finished / not in the set of jobs
                    if childJob.jobStoreID in jobsToNodeNames:
                        print('%s -> %s [label="%i"];' % (
                            jobsToNodeNames[job.jobStoreID],
                            jobsToNodeNames[childJob.jobStoreID], level))
        print("}") 
Example #9
Source File: provider.py    From Adafruit_Python_BluefruitLE with MIT License 5 votes vote down vote up
def disconnect_devices(self, service_uuids):
        """Disconnect any connected devices that have any of the specified
        service UUIDs.
        """
        # Get list of connected devices with specified services.
        cbuuids = map(uuid_to_cbuuid, service_uuids)
        for device in self._central_manager.retrieveConnectedPeripheralsWithServices_(cbuuids):
            self._central_manager.cancelPeripheralConnection_(device)


# Stop circular references by importing after classes that use these types. 
Example #10
Source File: process_monitor_pedrpc_server.py    From boofuzz with GNU General Public License v2.0 5 votes vote down vote up
def set_stop_commands(self, new_stop_commands):
        self.log("updating stop commands to: {0}".format(list(new_stop_commands)))
        self.stop_commands = new_stop_commands
        self.stop_commands = map(_split_command_if_str, new_stop_commands) 
Example #11
Source File: process_monitor_pedrpc_server.py    From boofuzz with GNU General Public License v2.0 5 votes vote down vote up
def set_start_commands(self, new_start_commands):
        self.log("updating start commands to: {0}".format(list(new_start_commands)))
        self.start_commands = map(_split_command_if_str, new_start_commands) 
Example #12
Source File: Cell.py    From chemml with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def get_lattice_angles_radians(self, radians=True):
        """Function to get the angles between the lattice vectors.

        Parameters
        ----------
        radians : bool
             (Default value = True)

        Returns
        -------
        output : array-like
            Lattice angles in radians.
        """

        output_radians = []
        col0 = self.simulation_cell[:, 0]
        col1 = self.simulation_cell[:, 1]
        col2 = self.simulation_cell[:, 2]
        nc0 = norm(col0)
        nc1 = norm(col1)
        nc2 = norm(col2)
        # Compute cosines.
        output_radians.append(np.math.acos(col1.dot(col2) / (nc1 * nc2)))
        output_radians.append(np.math.acos(col2.dot(col0) / (nc2 * nc0)))
        output_radians.append(np.math.acos(col0.dot(col1) / (nc0 * nc1)))
        if radians:
            return np.array(output_radians)
        output_degrees = np.array(map(np.math.degrees, output_radians),
                                  dtype=float)
        return output_degrees 
Example #13
Source File: Cell.py    From chemml with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def get_lattice_parameters(self):
        """Function to get the lattice parameters.

        Returns
        -------
        output : array-like
            A numpy array containing the lattice parameters.
        """

        output = np.array(map(norm, [x for x in self.simulation_cell.T]),
                          dtype=float)
        return output 
Example #14
Source File: ec2.py    From toil with Apache License 2.0 5 votes vote down vote up
def wait_instances_running(ec2, instances):
    """
    Wait until no instance in the given iterable is 'pending'. Yield every instance that
    entered the running state as soon as it does.

    :param boto.ec2.connection.EC2Connection ec2: the EC2 connection to use for making requests
    :param Iterator[Instance] instances: the instances to wait on
    :rtype: Iterator[Instance]
    """
    running_ids = set()
    other_ids = set()
    while True:
        pending_ids = set()
        for i in instances:
            if i.state == 'pending':
                pending_ids.add(i.id)
            elif i.state == 'running':
                assert i.id not in running_ids
                running_ids.add(i.id)
                yield i
            else:
                assert i.id not in other_ids
                other_ids.add(i.id)
                yield i
        log.info('%i instance(s) pending, %i running, %i other.',
                 *map(len, (pending_ids, running_ids, other_ids)))
        if not pending_ids:
            break
        seconds = max(a_short_time, min(len(pending_ids), 10 * a_short_time))
        log.info('Sleeping for %is', seconds)
        time.sleep(seconds)
        for attempt in retry_ec2():
            with attempt:
                instances = ec2.get_only_instances(list(pending_ids)) 
Example #15
Source File: test_noniterators.py    From kgsgo-dataset-preprocessor with Mozilla Public License 2.0 5 votes vote down vote up
def test_noniterators_produce_lists(self):
        l = range(10)
        self.assertTrue(isinstance(l, list))

        l2 = zip(l, list('ABCDE')*2)
        self.assertTrue(isinstance(l2, list))

        double = lambda x: x*2
        l3 = map(double, l)
        self.assertTrue(isinstance(l3, list))

        is_odd = lambda x: x % 2 == 1
        l4 = filter(is_odd, range(10))
        self.assertEqual(l4, [1, 3, 5, 7, 9])
        self.assertTrue(isinstance(l4, list)) 
Example #16
Source File: device.py    From Adafruit_Python_BluefruitLE with MIT License 5 votes vote down vote up
def _update_advertised(self, advertised):
        """Called when advertisement data is received."""
        # Advertisement data was received, pull out advertised service UUIDs and
        # name from advertisement data.
        if 'kCBAdvDataServiceUUIDs' in advertised:
            self._advertised = self._advertised + map(cbuuid_to_uuid, advertised['kCBAdvDataServiceUUIDs']) 
Example #17
Source File: provider.py    From Adafruit_Python_BluefruitLE with MIT License 5 votes vote down vote up
def _get_objects_by_path(self, paths):
        """Return a list of all bluez DBus objects from the provided list of paths.
        """
        return map(lambda x: self._bus.get_object('org.bluez', x), paths) 
Example #18
Source File: provider.py    From Adafruit_Python_BluefruitLE with MIT License 5 votes vote down vote up
def list_devices(self):
        """Return a list of BLE devices known to the system."""
        return map(BluezDevice, self._get_objects('org.bluez.Device1')) 
Example #19
Source File: provider.py    From Adafruit_Python_BluefruitLE with MIT License 5 votes vote down vote up
def list_adapters(self):
        """Return a list of BLE adapter objects connected to the system."""
        return map(BluezAdapter, self._get_objects('org.bluez.Adapter1')) 
Example #20
Source File: device.py    From Adafruit_Python_BluefruitLE with MIT License 5 votes vote down vote up
def discover(self, service_uuids, char_uuids, timeout_sec=TIMEOUT_SEC):
        """Wait up to timeout_sec for the specified services and characteristics
        to be discovered on the device.  If the timeout is exceeded without
        discovering the services and characteristics then an exception is thrown.
        """
        # Turn expected values into a counter of each UUID for fast comparison.
        expected_services = set(service_uuids)
        expected_chars = set(char_uuids)
        # Loop trying to find the expected services for the device.
        start = time.time()
        while True:
            # Find actual services discovered for the device.
            actual_services = set(self.advertised)
            # Find actual characteristics discovered for the device.
            chars = map(BluezGattCharacteristic,
                        get_provider()._get_objects(_CHARACTERISTIC_INTERFACE,
                                                    self._device.object_path))
            actual_chars = set(map(lambda x: x.uuid, chars))
            # Compare actual discovered UUIDs with expected and return true if at
            # least the expected UUIDs are available.
            if actual_services >= expected_services and actual_chars >= expected_chars:
                # Found at least the expected services!
                return True
            # Couldn't find the devices so check if timeout has expired and try again.
            if time.time()-start >= timeout_sec:
                return False
            time.sleep(1) 
Example #21
Source File: device.py    From Adafruit_Python_BluefruitLE with MIT License 5 votes vote down vote up
def list_services(self):
        """Return a list of GattService objects that have been discovered for
        this device.
        """
        return map(BluezGattService,
                   get_provider()._get_objects(_SERVICE_INTERFACE,
                                               self._device.object_path)) 
Example #22
Source File: gatt.py    From Adafruit_Python_BluefruitLE with MIT License 5 votes vote down vote up
def list_descriptors(self):
        """Return list of GATT descriptors that have been discovered for this
        characteristic.
        """
        paths = self._props.Get(_CHARACTERISTIC_INTERFACE, 'Descriptors')
        return map(BluezGattDescriptor,
                   get_provider()._get_objects_by_path(paths)) 
Example #23
Source File: gatt.py    From Adafruit_Python_BluefruitLE with MIT License 5 votes vote down vote up
def list_characteristics(self):
        """Return list of GATT characteristics that have been discovered for this
        service.
        """
        paths = self._props.Get(_SERVICE_INTERFACE, 'Characteristics')
        return map(BluezGattCharacteristic,
                   get_provider()._get_objects_by_path(paths)) 
Example #24
Source File: hicFindTADs.py    From HiCExplorer with GNU General Public License v3.0 5 votes vote down vote up
def load_bedgraph_matrix(self, filename, pChromosomes=None):
        # load spectrum matrix:
        matrix = []
        chrom_list = []
        start_list = []
        end_list = []
        with open(filename, 'r') as fh:
            for line in fh:
                # if type(line)
                if line.startswith("#"):
                    # recover the parameters used to generate the spectrum_matrix
                    parameters = json.loads(line[1:].strip())
                    continue
                fields = line.strip().split('\t')
                chrom, start, end = fields[0:3]
                if pChromosomes is not None:
                    if chrom in pChromosomes:
                        chrom_list.append(chrom)
                        start_list.append(int(float(start)))
                        end_list.append(int(float(end)))
                        matrix.append(map(float, fields[3:]))
                else:
                    chrom_list.append(chrom)
                    start_list.append(int(float(start)))
                    end_list.append(int(float(end)))
                    matrix.append(map(float, fields[3:]))
        self.min_depth = parameters['minDepth']
        self.max_depth = parameters['maxDepth']
        self.step = parameters['step']
        self.binsize = parameters['binsize']

        matrix = np.vstack(matrix)
        self.bedgraph_matrix = {'chrom': np.array(chrom_list),
                                'chr_start': np.array(start_list).astype(int),
                                'chr_end': np.array(end_list).astype(int),
                                'matrix': matrix} 
Example #25
Source File: node.py    From toil with Apache License 2.0 4 votes vote down vote up
def coreSSH(self, *args, **kwargs):
        """
        If strict=False, strict host key checking will be temporarily disabled.
        This is provided as a convenience for internal/automated functions and
        ought to be set to True whenever feasible, or whenever the user is directly
        interacting with a resource (e.g. rsync-cluster or ssh-cluster). Assumed
        to be False by default.

        kwargs: input, tty, appliance, collectStdout, sshOptions, strict
        """
        commandTokens = ['ssh', '-tt']
        if not kwargs.pop('strict', False):
            kwargs['sshOptions'] = ['-oUserKnownHostsFile=/dev/null', '-oStrictHostKeyChecking=no'] + kwargs.get(
                'sshOptions', [])
        sshOptions = kwargs.pop('sshOptions', None)
        # Forward ports:
        # 3000 for Grafana dashboard
        # 9090 for Prometheus dashboard
        # 5050 for Mesos dashboard (although to talk to agents you will need a proxy)
        commandTokens.extend(['-L', '3000:localhost:3000', \
                              '-L', '9090:localhost:9090', \
                              '-L', '5050:localhost:5050'])
        if sshOptions:
            # add specified options to ssh command
            assert isinstance(sshOptions, list)
            commandTokens.extend(sshOptions)
        # specify host
        user = kwargs.pop('user', 'core')  # CHANGED: Is this needed?
        commandTokens.append('%s@%s' % (user, str(self.effectiveIP)))

        inputString = kwargs.pop('input', None)
        if inputString is not None:
            kwargs['stdin'] = subprocess.PIPE

        if kwargs.pop('collectStdout', None):
            kwargs['stdout'] = subprocess.PIPE
        kwargs['stderr'] = subprocess.PIPE

        tty = kwargs.pop('tty', None)
        if kwargs.pop('appliance', None):
            ttyFlag = '-t' if tty else ''
            commandTokens += ['docker', 'exec', '-i', ttyFlag, 'toil_leader']

        logger.debug('Node %s: %s', self.effectiveIP, ' '.join(args))
        args = list(map(pipes.quote, args))
        commandTokens += args
        logger.debug('Full command %s', ' '.join(commandTokens))
        process = subprocess.Popen(commandTokens, **kwargs)
        stdout, stderr = process.communicate(input=inputString)
        # at this point the process has already exited, no need for a timeout
        exit_code = process.returncode
        # ssh has been throwing random 255 errors - why?
        if exit_code != 0:
            logger.info('Executing the command "%s" on the appliance returned a non-zero '
                        'exit code %s with stdout %s and stderr %s'
                        % (' '.join(args), exit_code, stdout, stderr))
            raise RuntimeError('Executing the command "%s" on the appliance returned a non-zero '
                               'exit code %s with stdout %s and stderr %s'
                               % (' '.join(args), exit_code, stdout, stderr))
        return stdout 
Example #26
Source File: toilStatus.py    From toil with Apache License 2.0 4 votes vote down vote up
def report_on_jobs(self):
        """
        Gathers information about jobs such as its child jobs and status.

        :returns jobStats: Pairings of a useful category and a list of jobs which fall into it.
        :rtype dict:
        """
        hasChildren = []
        readyToRun = []
        zombies = []
        hasLogFile = []
        hasServices = []
        services = []
        properties = set()

        for job in self.jobsToReport:
            if job.logJobStoreFileID is not None:
                hasLogFile.append(job)

            childNumber = reduce(lambda x, y: x + y, map(len, job.stack) + [0])
            if childNumber > 0:  # Total number of successors > 0
                hasChildren.append(job)
                properties.add("HAS_CHILDREN")
            elif job.command is not None:
                # Job has no children and a command to run. Indicates job could be run.
                readyToRun.append(job)
                properties.add("READY_TO_RUN")
            else:
                # Job has no successors and no command, so is a zombie job.
                zombies.append(job)
                properties.add("IS_ZOMBIE")
            if job.services:
                hasServices.append(job)
                properties.add("HAS_SERVICES")
            if job.startJobStoreID or job.terminateJobStoreID or job.errorJobStoreID:
                # These attributes are only set in service jobs
                services.append(job)
                properties.add("IS_SERVICE")

        jobStats = {'hasChildren': hasChildren,
                    'readyToRun': readyToRun,
                    'zombies': zombies,
                    'hasServices': hasServices,
                    'services': services,
                    'hasLogFile': hasLogFile,
                    'properties': properties,
                    'childNumber': childNumber}
        return jobStats