Extract tracers data.

    Args:
        tracersfile (:class:`pathlib.Path`): path of the binary tracers file.

    Returns:
        dict of list of numpy.array:
            Tracers data organized by attribute and block.
19472
def tracers(tracersfile):
    
    if not tracersfile.is_file():
        return None
    tra = {}
    with tracersfile.open('rb') as fid:
        readbin = partial(_readbin, fid)
        magic = readbin()
        if magic > 8000:  # 64 bits
            magic -= 8000
            readbin()
            readbin = partial(readbin, file64=True)
        if magic < 100:
            raise ParsingError(tracersfile,
                               'magic > 100 expected to get tracervar info')
        nblk = magic % 100
        readbin('f', 2)  # aspect ratio
        readbin()  # istep
        readbin('f')  # time
        ninfo = readbin()
        ntra = readbin(nwords=nblk, unpack=False)
        readbin('f')  # tracer ideal mass
        curv = readbin()
        if curv:
            readbin('f')  # r_cmb
        infos = []  # list of info names
        for _ in range(ninfo):
            infos.append(b''.join(readbin('b', 16)).strip().decode())
            tra[infos[-1]] = []
        if magic > 200:
            ntrace_elt = readbin()
            if ntrace_elt > 0:
                readbin('f', ntrace_elt)  # outgassed
        for ntrab in ntra:  # blocks
            data = readbin('f', ntrab * ninfo)
            for idx, info in enumerate(infos):
                tra[info].append(data[idx::ninfo])
    return tra
1029971
def get_real_last_traceback(exception):
    
    traceback_blocks = []
    _n, _n, exc_traceback = sys.exc_info()
    tb_list = get_all_tracebacks(exc_traceback)[1:]

    # Remove already captured tracebacks
    # TODO(jmv): This must be a better way of doing this. Need to revisit.
    tb_list = [tb for tb in tb_list if tb not in CAPTURED_TRACEBACKS]
    CAPTURED_TRACEBACKS.extend(tb_list)

    for traceback in tb_list:
        lines, path, line_num = get_source_from_frame(traceback.tb_frame)
        traceback_lines = get_numbered_source(lines, traceback.tb_lineno,
                                              line_num)

        traceback_lines.insert(0, '  - {0}'.format(path))
        traceback_lines.insert(1, '  ------------------')
        traceback_lines.append('  ------------------')
        traceback_blocks.append(traceback_lines)

    traced_lines = ['Error Traceback:']
    traced_lines.extend(itertools.chain.from_iterable(traceback_blocks))
    traced_lines.append('  - Error | {0}: {1}'.format(
        type(exception).__name__, exception))

    return traced_lines
529563
def walkfiles(self, *args, **kwargs):
        
        return (
            item
            for item in self.walk(*args, **kwargs)
            if item.isfile()
        )
1050523
def caller_trace(back=0):
    
    global caller_bases, caller_dicts
    import traceback
    tb = traceback.extract_stack(limit=3+back)
    tb.reverse()
    callee = tb[1][:3]
    caller_bases[callee] = caller_bases.get(callee, 0) + 1
    for caller in tb[2:]:
        caller = callee + caller[:3]
        try:
            entry = caller_dicts[callee]
        except KeyError:
            caller_dicts[callee] = entry = {}
        entry[caller] = entry.get(caller, 0) + 1
        callee = caller
1131472
def get_data_files():
    
    import os

    path = os.path.dirname(__file__)
    path = os.path.join(path, 'data')
    r = dict(
        Alpha_inf_hyrec_file = os.path.join(path, 'hyrec', 'Alpha_inf.dat'),
        R_inf_hyrec_file = os.path.join(path, 'hyrec', 'R_inf.dat'),
        two_photon_tables_hyrec_file = os.path.join(path, 'hyrec', 'two_photon_tables.dat'),
        sBBN_file = os.path.join(path, 'bbn', 'sBBN.dat'),
    )
    return r
1334353
def tcp_traceflow(frame, *, data_link):
    """"""
    if 'TCP' in frame:
        ip = (frame['IPv4'] if 'IPv4' in frame else frame['IPv6']).info
        tcp = frame['TCP'].info
        data = dict(
            protocol=data_link,                     # data link type from global header
            index=frame.info.number,                # frame number
            frame=frame.info,                       # extracted frame info
            syn=tcp.flags.syn,                      # TCP synchronise (SYN) flag
            fin=tcp.flags.fin,                      # TCP finish (FIN) flag
            src=ip.src,                             # source IP
            dst=ip.dst,                             # destination IP
            srcport=tcp.srcport,                    # TCP source port
            dstport=tcp.dstport,                    # TCP destination port
            timestamp=frame.info.time_epoch,        # frame timestamp
        )
        return True, data
    return False, None
772703
def tcp_traceflow(packet, timestamp, *, data_link, count=NotImplemented):
    """"""
    if getattr(packet, 'ip', None):
        ip = packet['ip']
    elif getattr(packet, 'ip6', None):
        ip = packet['ip6']
    else:
        return False, None
    tcp = getattr(ip, 'tcp', None)
    if tcp is not None:
        flags = bin(tcp.flags)[2:].zfill(8)
        data = dict(
            protocol=data_link,                                         # data link type from global header
            index=count,                                                # frame number
            frame=packet2dict(packet, timestamp, data_link=data_link),  # extracted packet
            syn=bool(int(flags[6])),                                    # TCP synchronise (SYN) flag
            fin=bool(int(flags[7])),                                    # TCP finish (FIN) flag
            src=ipaddress.ip_address(ip.src),                           # source IP
            dst=ipaddress.ip_address(ip.dst),                           # destination IP
            srcport=tcp.sport,                                          # TCP source port
            dstport=tcp.dport,                                          # TCP destination port
            timestamp=timestamp,                                        # timestamp
        )
        return True, data
    return False, None
600487
def get_traceback_data(self):
        """"""
        default_template_engine = None

        if default_template_engine is None:
            template_loaders = []

        frames = self.get_traceback_frames()
        for i, frame in enumerate(frames):
            if 'vars' in frame:
                frame_vars = []
                for k, v in frame['vars']:
                    v = pformat(v)
                    # The escape filter assume unicode, make sure that works
                    if isinstance(v, six.binary_type):
                        v = v.decode('utf-8', 'replace')  # don't choke on non-utf-8 input
                    # Trim large blobs of data
                    if v and len(v) > 4096:
                        v = '%s... <trimmed %d bytes string>' % (v[0:4096], len(v))
                    frame_vars.append((k, v))
                frame['vars'] = frame_vars
            frames[i] = frame

        unicode_hint = ''
        if self.exc_type and issubclass(self.exc_type, UnicodeError):
            start = getattr(self.exc_value, 'start', None)
            end = getattr(self.exc_value, 'end', None)
            if start is not None and end is not None:
                unicode_str = self.exc_value.args[1]

        c = {
            'is_email': False,
            'frames': frames,
            'sys_executable': sys.executable,
            'sys_version_info': '%d.%d.%d' % sys.version_info[0:3],
            'sys_path': sys.path,
        }

        # Check whether exception info is available
        if self.exc_type:
            c['exception_type'] = self.exc_type.__name__
        if self.exc_value:
            c['exception_value'] = self.exc_value
        if frames:
            c['lastframe'] = frames[-1]
        return c
1143873
def find(cls, paths):
    
    pythons = []
    for path in paths:
      for fn in cls.expand_path(path):
        basefile = os.path.basename(fn)
        if cls._matches_binary_name(basefile):
          try:
            pythons.append(cls.from_binary(fn))
          except Exception as e:
            TRACER.log('Could not identify %s: %s' % (fn, e))
            continue
    return pythons
770463
def _map_trajectory(self):
        
        self.trajectory_map = {}
        with open(self.filepath, 'r') as trajectory_file:
            with closing(
                    mmap(
                        trajectory_file.fileno(), 0,
                        access=ACCESS_READ)) as mapped_file:
                progress = 0
                line = 0
                frame = -1
                frame_start = 0
                while progress <= len(mapped_file):
                    line = line + 1
                    # We read a binary data from a mapped file.
                    bline = mapped_file.readline()
                    # If the bline length equals zero we terminate.
                    # We reached end of the file but still add the last frame!
                    if len(bline) == 0:
                        frame = frame + 1
                        if progress - frame_start > 10:
                            self.trajectory_map[frame] = [
                                frame_start, progress
                            ]
                        break
                    # We need to decode byte line into an utf-8 string.
                    sline = bline.decode("utf-8").strip('\n').split()
                    # We extract map's byte coordinates for each frame
                    if len(sline) == 1 and sline[0] == 'END':
                        frame = frame + 1
                        self.trajectory_map[frame] = [frame_start, progress]
                        frame_start = progress
                    # Here we extract the map's byte coordinates for the header
                    # And also the periodic system type needed for later.
                    progress = progress + len(bline)
            self.no_of_frames = frame
205297
def get_trace_name(object):
    

    global TRACE_NAMES_CACHE
    global TRACE_WALKER_CACHE

    trace_name = TRACE_NAMES_CACHE.get(object)
    if trace_name is None:

        TRACE_NAMES_CACHE[object] = trace_name = get_object_name(object)

        if type(object) is property:
            object = object.fget

        module = inspect.getmodule(object)
        if module is None:
            return

        members = TRACE_WALKER_CACHE.get(module)
        if members is None:
            TRACE_WALKER_CACHE[module] = members = tuple(trace_walker(module))

        for (cls, member) in members:
            if object in (cls, untracer(member)):
                TRACE_NAMES_CACHE[object] = trace_name = \
                    ".".join(map(get_object_name, filter(lambda x: x is not None, (module, cls, member))))
                break

    return trace_name
1070579
def _group_trace_frames(
        self, trace_frames: Iterable[TraceFrameQueryResult], limit: int
    ) -> Dict[Tuple[str, str], List[TraceFrameQueryResult]]:
        
        # pyre-fixme[9]: caller_buckets has type `DefaultDict[Tuple[str, str], List[T...
        caller_buckets: DefaultDict[
            Tuple[str, str], List[TraceFrameQueryResult]
        ] = defaultdict(list)
        for trace_frame in itertools.islice(trace_frames, limit):
            caller_buckets[(trace_frame.caller, trace_frame.caller_port)].append(
                trace_frame
            )
        return caller_buckets
784543
def _get_result_paths(self, data):
        

        result = {}

        result['Output'] = ResultPath(
            Path=self.Parameters['--output'].Value,
            IsWritten=self.Parameters['--output'].isOn())

        result['ClusterFile'] = ResultPath(
            Path=self.Parameters['--uc'].Value,
            IsWritten=self.Parameters['--uc'].isOn())

        # uchime 3-way global alignments
        result['Output_aln'] = ResultPath(
            Path=self.Parameters['--uchimealns'].Value,
            IsWritten=self.Parameters['--uchimealns'].isOn())

        # uchime tab-separated format
        result['Output_tabular'] = ResultPath(
            Path=self.Parameters['--uchimeout'].Value,
            IsWritten=self.Parameters['--uchimeout'].isOn())

        # chimeras fasta file output
        result['Output_chimeras'] = ResultPath(
            Path=self.Parameters['--chimeras'].Value,
            IsWritten=self.Parameters['--chimeras'].isOn())

        # nonchimeras fasta file output
        result['Output_nonchimeras'] = ResultPath(
            Path=self.Parameters['--nonchimeras'].Value,
            IsWritten=self.Parameters['--nonchimeras'].isOn())

        # log file
        result['LogFile'] = ResultPath(
            Path=self.Parameters['--log'].Value,
            IsWritten=self.Parameters['--log'].isOn())

        return result
1137084
def get_log_attrs():
    
    try:
        tracer = execution_context.get_opencensus_tracer()
        if tracer is None:
            raise RuntimeError
    except Exception:  # noqa
        _meta_logger.error("Failed to get opencensus tracer")
        return ATTR_DEFAULTS

    try:
        trace_id = tracer.span_context.trace_id
        if trace_id is None:
            trace_id = ATTR_DEFAULTS.trace_id
    except Exception:  # noqa
        _meta_logger.error("Failed to get opencensus trace ID")
        trace_id = ATTR_DEFAULTS.trace_id

    try:
        span_id = tracer.span_context.span_id
        if span_id is None:
            span_id = ATTR_DEFAULTS.span_id
    except Exception:  # noqa
        _meta_logger.error("Failed to get opencensus span ID")
        span_id = ATTR_DEFAULTS.span_id

    try:
        sampling_decision = tracer.span_context.trace_options.get_enabled
        if sampling_decision is None:
            sampling_decision = ATTR_DEFAULTS.sampling_decision
    except AttributeError:
        sampling_decision = ATTR_DEFAULTS.sampling_decision
    except Exception:  # noqa
        _meta_logger.error("Failed to get opencensus sampling decision")
        sampling_decision = ATTR_DEFAULTS.sampling_decision

    return LogAttrs(trace_id, span_id, sampling_decision)
513878
def traces(self):
        
        traces = []
        for v, c in zip(self.values.T, self.columns):
            traces.append(Trace(v, self.index, name=c))
        return traces
373587
def _open_file(filename):
        
        if filename is None:
            raise DataSourceError("Trace filename is not defined")

        try:
            trace_file = open(filename, "r")
        except IOError as e:
            raise DataSourceError("Unable to open trace file %s" % filename, e)
        else:
            LOG.debug("Opened trace file %s", filename)
            return trace_file
614457
def _GetDelayImportTimestamps(self, pefile_object):
    
    delay_import_timestamps = []
    if not hasattr(pefile_object, 'DIRECTORY_ENTRY_DELAY_IMPORT'):
      return delay_import_timestamps
    for importdata in pefile_object.DIRECTORY_ENTRY_DELAY_IMPORT:
      dll_name = importdata.dll
      try:
        dll_name = dll_name.decode('ascii')
      except UnicodeDecodeError:
        dll_name = dll_name.decode('ascii', errors='replace')

      timestamp = getattr(importdata.struct, 'dwTimeStamp', 0)
      delay_import_timestamps.append([dll_name, timestamp])
    return delay_import_timestamps