text:
import os
import os.path
import time
import math
import logging
import re
import struct

log = logging.getLogger(__name__)

try:
    import pymoku.li_capnp as schema
except ImportError:
    log.info("No Capnp, won't be able to convert binary files")

class InvalidFormatException(Exception):
    pass

class InvalidFileException(Exception):
    pass

class DataIntegrityException(Exception):
    pass

class LIDataFileReader(object):
    """
    Reads LI format data files.

    Data is read from this object in the form of Records.
    The form of a record depends on the instrument with which the data was
    captured and is decribed by the :any:`headers` field.
    A record may be a scalar in the case of, say, a datalogger; or may be a
    tuple of elements. The Phasemeter for example has records defined as tuples
    of (frequency, phase, amplitude).

    If multiple channels of data have been recorded, all read methods return
    time-aligned samples from all channels at once. A single channel capture
    will return single-element lists of records.

    Presents the iterator interface and the context manager interface.
    For example:

    with LIDataFileReader('input.li') as f:
        for record in f:
            do_something(record)

    :autoinstanceattribute:: pymoku.dataparser.LIDataFileReader.headers

    :autoinstanceattribute:: pymoku.dataparser.LIDataFileReader.nch

    :autoinstanceattribute:: pymoku.dataparser.LIDataFileReader.instr

    :autoinstanceattribute:: pymoku.dataparser.LIDataFileReader.instrv

    :autoinstanceattribute:: pymoku.dataparser.LIDataFileReader.deltat

    :autoinstanceattribute:: pymoku.dataparser.LIDataFileReader.starttime

    :autoinstanceattribute:: pymoku.dataparser.LIDataFileReader.startoffset

    """

    def __init__(self, filename):
        """

        :raises :any:`InvalidFileException`: when file is corrupted or of the
        wrong version.
        :type filename: str
        :param filename: Input filename
        """
        self.records = []
        self.cal = []
        self.proc = []
        self.filename = filename
        self.file = open(filename, 'r+b')

        # Pre-define instance fields so we can attach docstrings.

        #: Column headers describing the contents of the datafile records
        self.headers = []

        #: Number of (valid) channels in input file
        self.nch = 0

        #: Numeric Instrument identifier
        self.instr = 0

        #: Instrument version
        self.instrv = 0

        #: Time step with which the data was captured
        self.deltat = 0

        #: Time at which the recording was started (seconds since Jan 1 1970)
        self.starttime = 0

        #: Time at which the first sample occured, relative to the start time
        # (valid in V2+ files only)
        self.startoffset = 0

        if self.file.read(2) != b'LI':
            raise InvalidFileException("Bad Magic")

        self.version = int(self.file.read(1))
        if self.version == 1:
            self._parse_v1_header()
        elif self.version == 2:
            if 'capnp' not in globals():
                raise Exception("Can't parse LI files on this platform."
                                " Ensure 'capnp' is installed.")
            self._parse_v2_header()
        else:
            raise InvalidFileException("Unknown File Version %s"
                                       % self.version)

        # Assume the last line of the CSV header block is the column headers
        try:
            self.headers = [s.strip() for s in self.hdr.split('\r\n')
                            if len(s)][-1].split(',')
        except IndexError:
            self.headers = []

        self.records = [[] for _ in range(self.nch)]

        self.parser = LIDataParser(self.ch1,
                                   self.ch2,
                                   self.rec,
                                   self.proc,
                                   self.fmt,
                                   self.hdr,
                                   self.deltat,
                                   self.starttime,
                                   self.cal,
                                   self.startoffset
                                   )

    def _parse_v1_header(self):
        pkthdr_len = struct.unpack("<H", self.file.read(2))[0]
        self.chs, self.instr, self.instrv, self.deltat, self.starttime \
            = struct.unpack("<BBHdQ", self.file.read(20))

        # Extract the selected channels
        self.nch = 0
        self.ch1 = bool(self.chs & 0x01)
        self.ch2 = bool(self.chs & 0x02)
        if (self.ch1):
            self.nch += 1
        if (self.ch2):
            self.nch += 1

        for i in range(self.nch):
            self.cal.append(struct.unpack("<d", self.file.read(8))[0])

        reclen = struct.unpack("<H", self.file.read(2))[0]
        self.rec = self.file.read(reclen).decode('ascii')

        for i in range(self.nch):
            proclen = struct.unpack("<H", self.file.read(2))[0]
            self.proc.append(self.file.read(proclen).decode('ascii'))

        fmtlen = struct.unpack("<H", self.file.read(2))[0]
        self.fmt = self.file.read(fmtlen).decode('ascii')
        hdrlen = struct.unpack("<H", self.file.read(2))[0]
        self.hdr = self.file.read(hdrlen).decode('ascii')

        if self.file.tell() != pkthdr_len + 5:
            raise InvalidFileException("Incorrect File Header Length "
                                       "(expected %d got %d)"
                                       % (pkthdr_len + 5, self.file.tell())
                                       )

    def _parse_v2_header(self):
        # The capnp parser uses the underlying fileno and does its own
        # buffering which renders it incompatible with Python's internal
        # buffering (triggered when ever you call read()).
        # TL;DR the Python file object used by capnp can't have been read()
        # from, re-open it and seek past the header
        self.file.close()
        self.file = open(self.filename, 'r+b')
        self.file.seek(3)
        self.element_iterator = schema.LIFileElement.read_multiple(self.file)

        element = self.element_iterator.__next__()
        if element.which() != 'header':
            raise InvalidFileException('First Element is not a Header: %s',
                                       element.which()
                                       )

        header = element.header

        self.instr = header.instrumentId
        self.instrv = header.instrumentVer
        self.deltat = header.timeStep
        self.starttime = header.startTime
        self.startoffset = header.startOffset

        # The definition of these fields is heavily influenced by the V1 header
        # format and should be
        # refactored if/when we put that out to pasture.
        self.nch = len(header.channels)

        self.ch1 = 1 in [c.number for c in header.channels]
        self.ch2 = 2 in [c.number for c in header.channels]

        # This file format allows for different records per channel but we
        # don't currently use that.
        self.rec = header.channels[0].recordFmt
        self.proc = [c.procFmt for c in header.channels]
        self.cal = [c.calibration for c in header.channels]

        self.fmt = header.csvFmt
        self.hdr = header.csvHeader

    def _parse_chunk(self):
        if self.version == 1:
            ch, d = self._parse_chunk_v1()
        elif self.version == 2:
            ch, d = self._parse_chunk_v2()

        if ch is None:
            return None

        self.parser.parse(d, ch)

        return ch

    def _parse_chunk_v1(self):
        dhdr = self.file.read(3)
        if len(dhdr) != 3:
            return None, None

        ch, _len = struct.unpack("<BH", dhdr)

        d = self.file.read(_len)

        if len(d) != _len:
            raise InvalidFileException("Unexpected EOF while reading data")

        return ch, d

    def _parse_chunk_v2(self):
        try:
            element = self.element_iterator.__next__()
        except Exception:
            return None, None

        if element.which() != 'data':
            raise InvalidFileException("Unexpected element type %s",
                                       element.which()
                                       )

        ch = element.data.channel - 1
        d = element.data.data

        return ch, d

    def _process_chunk(self):
        ch = self._parse_chunk()

        if ch is None:
            return False

        self.records[ch].extend(self.parser.processed[ch])

        # Now that we've copied the records in to our own storage, free them
        # from the parser.
        self.parser.clear_processed()

        return True

    def read(self):
        """ Read a single record from the file
        :returns: [ch1_record, ...]
        """
        while not all([len(r) >= 1 for r in self.records]):
            if not self._process_chunk():
                break

        # Make sure we have matched samples for all channels
        if not all([len(r) for r in self.records]):
            return None

        rec = []
        for r in self.records:
            rec.append(r.pop(0))

        return rec

    def readall(self):
        """ Returns an array containing all the data from the file.

        Be aware that this can be very big in the case of long or high-rate
        captures. """
        ret = []

        for rec in self:
            ret.append(rec)

        return ret

    def close(self):
        """ Safely close the file"""
        self.file.close()

    def to_csv(self, fname):
        """ Dump the contents of this data file as a CSV.

        :param fname: Output CSV filename.
        """
        try:
            os.remove(fname)
        except OSError:
            pass
        # Don't actually care about the chunk contents, just that it's been
        # loaded
        while self._parse_chunk() is not None:
            self.parser.dump_csv(fname)

    def __iter__(self):
        return self

    def __next__(self):
        d = self.read()

        if d is None or not len(d):
            raise StopIteration
        else:
            return d

    next = __next__  # Python 2/3 translation

    def __enter__(self):
        pass

    def __exit__(self):
        self.close()

class LIDataFileWriterV1(object):
    """ Eases the creation of LI format data files."""
    def __init__(self, file, instr, instrv, chs, binstr, procstr, fmtstr,
                 hdrstr, calcoeffs, timestep, starttime):
        """ Create file and write the header information.
        Not designed for general use, is likely to only be of utility in the
        Moku:Lab firmware.

        :param file: String filename or file-like object for data output
        :param instr: Numeric instrument identifier
        :param instrv: Numberic instrument version
        :param chs: Channel selection flags
        :param binstr: Format string representing the binary data from the
         instrument
        :param procstr: String array representing the record processing to
         apply to the data of each channel
        :param fmtstr: Format string describing the transformation from data
         records to CSV output
        :param hdrstr: Format string describing the header lines on a CSV
         output
        :param calcoeffs: Array of calibration coefficients for the data being
         acquired
        :param timestep: Time between records being captured
        :param starttime: Time at which the record was started, seconds since
         Jan 1 1970
        """
        try:
            self.file = open(file, 'wb')
        except TypeError:
            # Assume a file object has been passed
            self.file = file

        nch = 0
        if (chs & 0x01):
            nch += 1
        if (chs & 0x02):
            nch += 1

        self.file.write(b'LI1')
        hdr = struct.pack("<BBHdQ", chs, instr, instrv, timestep, starttime)

        for i in range(nch):
            hdr += struct.pack('<d', calcoeffs[i])

        hdr += struct.pack("<H", len(binstr)) + binstr.encode()

        for i in range(nch):
            hdr += struct.pack("<H", len(procstr[i])) + procstr[i].encode()

        hdr += struct.pack("<H", len(fmtstr)) + fmtstr.encode()
        hdr += struct.pack("<H", len(hdrstr)) + hdrstr.encode()

        self.file.write(struct.pack("<H", len(hdr)))
        self.file.write(hdr)

    def add_data(self, data, ch, flush=False):
        """ Append a data chunk to the open file.

        :param data: Bytestring of new data
        :param ch: Channel number to which the data belongs (0-indexed)
        """
        self.file.write(struct.pack("<BH", ch, len(data)))
        self.file.write(data)

        if flush:
            self.file.flush()

    def finalize(self):
        """
        Save and close the file.
        """
        self.file.close()

    def __enter__(self):
        pass

    def __exit__(self):
        self.finalize()

class LIDataFileWriterV2(object):
    """ Eases the creation of LIv2 format data files."""
    def __init__(self, file, instr, instrv, chs, binstr, procstr, fmtstr,
                 hdrstr, calcoeffs, timestep, starttime, startoffset):
        """ Create file and write the header information.
        Not designed for general use, is likely to only be of utility in the
        Moku:Lab firmware.

        :param file: String filename or file-like object for data output
        :param instr: Numeric instrument identifier
        :param instrv: Numberic instrument version
        :param chs: Channel selection flags
        :param binstr: Format string representing the binary data from the
         instrument
        :param procstr: String array representing the record processing to
         apply to the data of each channel
        :param fmtstr: Format string describing the transformation from data
         records to CSV output
        :param hdrstr: Format string describing the header lines on a CSV
         output
        :param calcoeffs: Array of calibration coefficients for the data
         being acquired
        :param timestep: Time between records being captured
        :param starttime: Time at which the record was started, seconds
         since Jan 1 1970
        :param startoffset: Time delta, fractional seconds, between starttime
         and the time of the first sample (e.g. because of triggered start with
         offset)
        """

        if 'capnp' not in globals():
            raise Exception("Can't write LI files on this platform. "
                            "Ensure 'capnp' is installed.")

        try:
            self.file = open(file, 'wb')
        except TypeError:
            # Assume a file object has been passed
            self.file = file

        self.file.write(b'LI2')

        element = schema.LIFileElement.new_message()
        element.header.instrumentId = instr
        element.header.instrumentVer = instrv
        element.header.timeStep = timestep
        element.header.startTime = starttime
        element.header.startOffset = startoffset

        chnums = []
        if chs & 0x01:
            chnums.append(1)
        if chs & 0x02:
            chnums.append(2)

        channels = element.header.init('channels', len(chnums))
        for i, ch in enumerate(chnums):
            channels[i].number = ch
            channels[i].calibration = calcoeffs[i]
            channels[i].recordFmt = binstr
            channels[i].procFmt = procstr[i]

        element.header.csvFmt = fmtstr
        element.header.csvHeader = hdrstr
        self.file.write(element.to_bytes())

    def add_data(self, data, ch, flush=False):
        """ Append a data chunk to the open file.

        :param data: Bytestring of new data
        :param ch: Channel number to which the data belongs (0-indexed)
        """
        element = schema.LIFileElement.new_message()
        element.init('data')
        element.data.channel = ch + 1
        element.data.data = data

        self.file.write(element.to_bytes())

        if flush:
            self.file.flush()

    def finalize(self):
        """
        Save and close the file.
        """
        self.file.close()

    def __enter__(self):
        pass

    def __exit__(self):
        self.finalize()

class SlowDataParser(object):
    """ Backend class that parses raw bytestrings from the instruments
    according to given format strings.

    Unlikely to be of utility outside the Moku:Lab firmware, an end-user
    probably wants to instantiate an :any:`LIDataFileReader` instead."""

    @staticmethod
    def record_length(binstr):
        """ Returns the bit length of the records decribed by the given binary
        description string """
        b = LIDataParser._parse_binstr(binstr)
        return sum(list(zip(*b))[1])

    @staticmethod
    def _parse_binstr(binstr):
        fmt = []

        if binstr[0] == '>':
            raise InvalidFormatException("Big-endian data order currently "
                                         "not supported.")

        for clause in binstr.split(':'):
            try:
                typ, bitlen, literal = re.findall(r'([usfbrp])([0-9]+),'
                                                  '*([0-9a-zA-Z]+)*',
                                                  clause)[0]
                fmt.append((typ, int(bitlen), int(literal, 0) if len(literal)
                            else None))
            except IndexError:
                raise InvalidFormatException("Can't parse binary specifier %s"
                                             % clause)

        return fmt

    @staticmethod
    def _parse_procstr(procstr, calcoeff):
        def _eval_lit(lit):
            if lit == '':
                return None
            elif lit == 'C':
                return calcoeff

            try:
                return int(lit, 0)
            except Exception:
                pass

            try:
                return float(lit)
            except Exception:
                raise InvalidFormatException("Can't parse literal %s" % lit)

        fmt = []

        for clause in procstr.split(':'):
            ops = re.findall(
                r'([*/\+\-&s\^fc])(\-?[0-9\.xA-F]+(e\-?[0-9]+)?)?', clause)

            ops = [(op, _eval_lit(lit)) for op, lit, _ in ops]

            fmt.append(ops)

        return fmt

    def __init__(self, ch1, ch2, binstr, procstr, fmtstr, hdrstr, deltat,
                 starttime, calcoeffs, startoffset):

        if not len(binstr):
            raise InvalidFormatException("Can't use empty "
                                         "binary record string")

        self.binfmt = LIDataParser._parse_binstr(binstr)
        self.recordlen = sum(list(zip(*self.binfmt))[1])
        self.procstr = procstr

        self.nch = 0
        self.ch1 = bool(ch1)
        self.ch2 = bool(ch2)

        if self.ch1:
            self.nch += 1
        if self.ch2:
            self.nch += 1

        self.procfmt = []
        for ch in range(self.nch):
            self.procfmt.append(LIDataParser._parse_procstr(procstr[ch],
                                calcoeffs[ch]))

        self.fmtdict = {
            # Standard repr plus explicit timezone
            'T': time.strftime('%c %Z', time.localtime(starttime)),
            't': startoffset,
            'd': deltat,
            'n': 0,
        }
        self.fmt = fmtstr
        self.dout = hdrstr.format(**self.fmtdict)

        self.dcache = ['' for _ in range(self.nch)]
        self.records = [[] for _ in range(self.nch)]
        self.processed = [[] for _ in range(self.nch)]
        self._currecord = [[] for _ in range(self.nch)]
        self._currfmt = [[] for _ in range(self.nch)]

        self._byteidx = [0 for _ in range(self.nch)]

    def _process_records(self):
        for ch in range(self.nch):
            for record in self.records[ch]:
                rec = []
                for field, ops in zip(record, self.procfmt[ch]):
                    val = field
                    for op, lit in ops:
                        if op == '*':
                            val *= lit
                        elif op == '/':
                            val /= lit
                        elif op == '+':
                            val += lit
                        elif op == '-':
                            val -= lit
                        elif op == '&':
                            val &= lit
                        elif op == 's':
                            val = math.sqrt(val)
                        elif op == 'f':
                            val = int(math.floor(val))
                        elif op == 'c':
                            val = int(math.ceil(val))
                        elif op == '^':
                            val = val**lit
                        else:
                            raise InvalidFormatException("Don't recognize "
                                                         "operation %s", op)

                    rec.append(val)

                if len(rec) > 1:
                    self.processed[ch].append(tuple(rec))
                else:
                    self.processed[ch].append(rec[0])

        # Remove all processed records
        self.records = [[] for x in range(self.nch)]

    def _format_records(self):
        new_data = []

        # Single channel logging
        if self.nch == 1:
            for rec in self.processed[0]:
                self.fmtdict['n'] += 1
                self.fmtdict['t'] = (self.fmtdict['n'] - 1) * self.fmtdict['d']
                if self.ch1:
                    new_data.append(self.fmt.format(ch1=rec, **self.fmtdict))
                else:
                    new_data.append(self.fmt.format(ch2=rec, **self.fmtdict))

            self.dout += ''.join(new_data)

            return len(self.processed[0])
        else:
            i = 0
            for rec1, rec2 in zip(*self.processed):
                self.fmtdict['n'] += 1
                self.fmtdict['t'] = (self.fmtdict['n'] - 1) * self.fmtdict['d']
                new_data.append(self.fmt.format(ch1=rec1,
                                                ch2=rec2,
                                                **self.fmtdict))
                i += 1

            self.dout += ''.join(new_data)

            return i

    def set_coeff(self, ch, coeff):
        self.procfmt[ch] = LIDataParser._parse_procstr(self.procstr[ch], coeff)

    def dump_csv(self, fname=None):
        """ Write out incremental CSV output from new data"""
        n_formatted = self._format_records()
        self.clear_processed(n_formatted)

        if not fname:
            d = self.dout
            self.dout = ''
            return d

        with open(fname, 'ab') as f:
            f.write(self.dout.encode())

        self.dout = ''

    def clear_processed(self, _len=None):
        """ Flush processed data.

        Called by the data consumer to indicate that it's no longer of use
        (e.g. has been written to a file or otherwise processed)."""
        if _len is None:
            self.processed = [[] for x in range(self.nch)]
        else:
            # Clear out the raw and processed records so we can stream
            # chunk at a time
            for i in range(len(self.processed)):
                self.processed[i] = self.processed[i][_len:]

    def _parse(self, data, ch):
        # Manipulation is done on a string of ASCII '0' and '1'. Tried using
        # the bitarray package but that's ~3x slower than the string version
        # and the bitstring package is around 7x slower.

        # Convert channel number to processing array index
        if ch == 0 or self.nch == 1:
            chidx = 0
        elif ch == 1:
            chidx = 1

        # This is all hard-coded little-endian; we reverse the bitstrings at
        # the byte level here, then reverse them again at the field level below
        # to correctly parse the fields LE.
        self.dcache[chidx] += ''.join(["{:08b}".format(d)[::-1]
                                      for d in bytearray(data)])

        while True:
            if not len(self._currfmt[chidx]):
                self._currfmt[chidx] = self.binfmt[:]

                if len(self._currecord[chidx]):
                    self.records[chidx].append(self._currecord[chidx])
                self._currecord[chidx] = []

            _type, _len, lit = self._currfmt[chidx][0]

            if len(self.dcache[chidx]) < _len:
                break

            # TODO: This is hard-coded little endian. Need to correctly handle
            # the endianness specifier in the binary format string.
            candidate = self.dcache[chidx][:_len][::-1]

            if _type in 'up':
                val = int(candidate, 2)
            elif _type == 's':
                val = int(candidate, 2)

                if candidate[0] == '1':
                    val -= (1 << _len)
            elif _type == 'f':
                if _len == 32:
                    fmtstr = 'If'
                elif _len == 64:
                    fmtstr = 'Qd'
                else:
                    raise InvalidFormatException("Can't have a floating point "
                                                 "spec with bit length other "
                                                 "than 32/64 bits")

                bitpattern = struct.pack(fmtstr[0], int(candidate, 2))
                val = struct.unpack(fmtstr[1], bitpattern)[0]
            elif _type == 'b':
                val = candidate == '1'
            else:
                raise InvalidFormatException("Don't know how to handle '%s' "
                                             "types" % _type)

            if not lit or val == lit:
                if _type != 'p':
                    self._currecord[chidx].append(val)
                self._currfmt[chidx] = self._currfmt[chidx][1:]

                # Drop off the whole successfully-matched field.
                self.dcache[chidx] = self.dcache[chidx][_len:]
            else:
                # If we fail a literal match, drop the entire pattern and start
                # again
                log.debug("Literal mismatch (%d != %d), "
                          "dropped partial record %s",
                          val, lit, str(self._currecord[chidx]))
                self._currecord[chidx] = []
                self._currfmt[chidx] = []

                # Drop off a byte, assuming that that is the base granulatity
                # at which the data has been captured
                self.dcache[chidx] = self.dcache[chidx][8:]

        if len(self._currecord[chidx]) and not len(self._currfmt[chidx]):
            self.records[chidx].append(self._currecord[chidx])

    def parse(self, data, ch, start_idx=None):
        """ Parse a chunk of data.

        :param data: bytestring of new data
        :param ch: Channel to which the data belongs"""

        self._parse(data, ch)
        self._process_records()

        # The sample index isn't the same as the total length of the processed
        # array as the user can empty the processed array themselves
        if start_idx is not None:
            if self._byteidx[ch] == start_idx:
                self._byteidx[ch] += len(data)
            else:
                raise DataIntegrityException("Data loss detected on "
                                             "stream interface")

try:
    import liquidreader as lr
    log.debug("liquidreader imported successfully")

    class FastDataParser(SlowDataParser):
        # This class does the binary parsing and processing in the external
        # liquidreader C module for about a 10x increase in speed compared to
        # binary. The CSV processing is currently still done in Python,
        # inherited from the SlowDataParser above.
        def __init__(self, ch1, ch2, binstr, procstr, fmtstr, hdrstr, deltat,
                     starttime, calcoeffs, startoffset):
            self.ch1, self.ch2 = ch1, ch2
            self.binstr, self.procstr, self.fmtstr, self.hdrstr \
                = binstr, procstr, fmtstr, hdrstr
            self.deltat, self.starttime, self.startoffset \
                = deltat, starttime, startoffset
            self.calcoeffs = calcoeffs
            self.nch = 2 if self.ch1 and self.ch2 else 1
            self.ready = False

            self.backlog = []

            super(FastDataParser, self).__init__(ch1, ch2,
                                                 binstr, procstr,
                                                 fmtstr, hdrstr,
                                                 deltat, starttime,
                                                 calcoeffs, startoffset)

            if all(self.calcoeffs):
                self.init_liquidreader()

        def init_liquidreader(self):
            # This writes out effectively a version-1 LI file header so the
            # underlying LI Reader doesn't need any modification (so long as
            # it doesn't drop v1 support!)
            chs = (int(self.ch2) << 1) | int(self.ch1)

            hdr = struct.pack("<BBHdQ", chs, 0, 0, self.deltat, self.starttime)

            for i in range(self.nch):
                hdr += struct.pack('<d', self.calcoeffs[i])

            hdr += struct.pack("<H", len(self.binstr)) + self.binstr.encode()

            for i in range(self.nch):
                hdr += struct.pack("<H", len(self.procstr[i]))
                + self.procstr[i].encode()

            hdr += struct.pack("<H", len(self.fmtstr)) + self.fmtstr.encode()
            hdr += struct.pack("<H", len(self.hdrstr)) + self.hdrstr.encode()

            d = b'LI1' + struct.pack("<H", len(hdr)) + hdr
            lr.restart()
            lr.put(d)

            self.ready = True

            for data, ch, start_idx in self.backlog:
                self.parse(data, ch, start_idx)

            self.backlog = []

        def set_coeff(self, ch, coeff):
            # Some users, notably stream-to-network, don't know the particular
            # unit's calibration coefficients until some data arrives,
            # so this needs to be separately settable. However
            # the Liquidreader can't be initialised twice, just do it the once
            # when we have all info.
            self.calcoeffs[ch] = coeff

            if all(self.calcoeffs) and not self.ready:
                self.init_liquidreader()

        def parse(self, data, ch, start_idx=None):
            if not self.ready:
                self.backlog.append((data, ch, start_idx))
                return

            lr.put(struct.pack("<BH", ch, len(data)) + data)

            d = lr.get()
            while d is not None:
                if self.nch == 2:
                    ch1, ch2 = d
                    self.processed[0].append(ch1)
                    self.processed[1].append(ch2)
                else:
                    self.processed[0].append(d)

                d = lr.get()

    LIDataParser = FastDataParser

except ImportError:
    log.debug("liquidreader module unable to be imported. "
              "Falling back to default data parser.")
    LIDataParser = SlowDataParser


text:
<component name="libraryTable">
  <library name="KotlinTest">
    <CLASSES>
      <root url="jar://$KOTLIN_BUNDLED$/lib/kotlin-test.jar!/" />
    </CLASSES>
    <JAVADOC />
    <SOURCES />
  </library>
</component>

redpajama_set_name: RedPajamaGithub


text:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">

<TITLE>The CMD user interface</TITLE>
<META NAME="description" CONTENT="The CMD user interface">
<META NAME="keywords" CONTENT="pdtrav">
<META NAME="resource-type" CONTENT="document">
<META NAME="distribution" CONTENT="global">

<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Generator" CONTENT="LaTeX2HTML v99.1 release">
<META HTTP-EQUIV="Content-Style-Type" CONTENT="text/css">

<LINK REL="STYLESHEET" HREF="pdtrav.css">

<LINK REL="next" HREF="node14.html">
<LINK REL="previous" HREF="node12.html">
<LINK REL="up" HREF="node5.html">
<LINK REL="next" HREF="node14.html">

 Next: Setting Parameters
 Up: User's Manual
 Previous: Traversals
 &nbsp   Contents

The CMD user interface

PdTRAV is equipped with an interactive textual user interface.
It is intended for users who plan not to link PdTRAV packages as an object
library.
Commands are issued on a line by line basis.

If the first character of a command is the exclamation mark "!", a system
call is issued instead.
This allows to execute basic system commands such as "more", "ls", etc.

If the first character of a command is "#" the command is ignored, i.e., it
is supposed to be a comment.
This is especially useful to write script files.
In fact, the command "source" gives the possibility to read from a
source-script file instead that from standard input.

If the first character of the command is "@" this indicates that a script
file with parameter is used.
For example

@script1.cmd a b c

runs the script file script1.cmd (containing some $1, $2 and $3) with
parameters a, b and c.

For more information on the commands see the documentation in the  cmd

doc
directory and the on-line documentation (command  help).

 Next: Setting Parameters
 Up: User's Manual
 Previous: Traversals
 &nbsp   Contents

<ADDRESS>
Gianpiero Cabodi

2001-03-25
</ADDRESS>


text:
package com.microsoft.azure.management.automation.v2015_10_31.implementation;

import retrofit2.Retrofit;
import com.google.common.reflect.TypeToken;
import com.microsoft.azure.AzureServiceFuture;
import com.microsoft.azure.ListOperationCallback;
import com.microsoft.azure.management.automation.v2015_10_31.ErrorResponseException;
import com.microsoft.azure.Page;
import com.microsoft.azure.PagedList;
import com.microsoft.rest.ServiceCallback;
import com.microsoft.rest.ServiceFuture;
import com.microsoft.rest.ServiceResponse;
import java.io.IOException;
import java.util.List;
import okhttp3.ResponseBody;
import retrofit2.http.GET;
import retrofit2.http.Header;
import retrofit2.http.Headers;
import retrofit2.http.Path;
import retrofit2.http.Query;
import retrofit2.http.Url;
import retrofit2.Response;
import rx.functions.Func1;
import rx.Observable;

/**
 * An instance of this class provides access to all the operations defined
 * in JobStreams.
 */
public class JobStreamsInner {
    /** The Retrofit service to perform REST calls. */
    private JobStreamsService service;
    /** The service client containing this operation class. */
    private AutomationClientImpl client;

    /**
     * Initializes an instance of JobStreamsInner.
     *
     * @param retrofit the Retrofit instance built from a Retrofit Builder.
     * @param client the instance of the service client containing this operation class.
     */
    public JobStreamsInner(Retrofit retrofit, AutomationClientImpl client) {
        this.service = retrofit.create(JobStreamsService.class);
        this.client = client;
    }

    /**
     * The interface defining all the services for JobStreams to be
     * used by Retrofit to perform actually REST calls.
     */
    interface JobStreamsService {
        @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.automation.v2015_10_31.JobStreams get" })
        @GET("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automation/automationAccounts/{automationAccountName}/jobs/{jobId}/streams/{jobStreamId}")
        Observable<Response<ResponseBody>> get(@Path("resourceGroupName") String resourceGroupName, @Path("automationAccountName") String automationAccountName, @Path("jobId") String jobId, @Path("jobStreamId") String jobStreamId, @Path("subscriptionId") String subscriptionId, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent);

        @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.automation.v2015_10_31.JobStreams listByJob" })
        @GET("subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automation/automationAccounts/{automationAccountName}/jobs/{jobId}/streams")
        Observable<Response<ResponseBody>> listByJob(@Path("resourceGroupName") String resourceGroupName, @Path("automationAccountName") String automationAccountName, @Path("jobId") String jobId, @Path("subscriptionId") String subscriptionId, @Query("$filter") String filter, @Query("api-version") String apiVersion, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent);

        @Headers({ "Content-Type: application/json; charset=utf-8", "x-ms-logging-context: com.microsoft.azure.management.automation.v2015_10_31.JobStreams listByJobNext" })
        @GET
        Observable<Response<ResponseBody>> listByJobNext(@Url String nextUrl, @Header("accept-language") String acceptLanguage, @Header("User-Agent") String userAgent);

    }

    /**
     * Retrieve the job stream identified by job stream id.
     *
     * @param resourceGroupName Name of an Azure Resource group.
     * @param automationAccountName The name of the automation account.
     * @param jobId The job id.
     * @param jobStreamId The job stream id.
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @throws ErrorResponseException thrown if the request is rejected by server
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent
     * @return the JobStreamInner object if successful.
     */
    public JobStreamInner get(String resourceGroupName, String automationAccountName, String jobId, String jobStreamId) {
        return getWithServiceResponseAsync(resourceGroupName, automationAccountName, jobId, jobStreamId).toBlocking().single().body();
    }

    /**
     * Retrieve the job stream identified by job stream id.
     *
     * @param resourceGroupName Name of an Azure Resource group.
     * @param automationAccountName The name of the automation account.
     * @param jobId The job id.
     * @param jobStreamId The job stream id.
     * @param serviceCallback the async ServiceCallback to handle successful and failed responses.
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @return the {@link ServiceFuture} object
     */
    public ServiceFuture<JobStreamInner> getAsync(String resourceGroupName, String automationAccountName, String jobId, String jobStreamId, final ServiceCallback<JobStreamInner> serviceCallback) {
        return ServiceFuture.fromResponse(getWithServiceResponseAsync(resourceGroupName, automationAccountName, jobId, jobStreamId), serviceCallback);
    }

    /**
     * Retrieve the job stream identified by job stream id.
     *
     * @param resourceGroupName Name of an Azure Resource group.
     * @param automationAccountName The name of the automation account.
     * @param jobId The job id.
     * @param jobStreamId The job stream id.
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @return the observable to the JobStreamInner object
     */
    public Observable<JobStreamInner> getAsync(String resourceGroupName, String automationAccountName, String jobId, String jobStreamId) {
        return getWithServiceResponseAsync(resourceGroupName, automationAccountName, jobId, jobStreamId).map(new Func1<ServiceResponse<JobStreamInner>, JobStreamInner>() {
            @Override
            public JobStreamInner call(ServiceResponse<JobStreamInner> response) {
                return response.body();
            }
        });
    }

    /**
     * Retrieve the job stream identified by job stream id.
     *
     * @param resourceGroupName Name of an Azure Resource group.
     * @param automationAccountName The name of the automation account.
     * @param jobId The job id.
     * @param jobStreamId The job stream id.
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @return the observable to the JobStreamInner object
     */
    public Observable<ServiceResponse<JobStreamInner>> getWithServiceResponseAsync(String resourceGroupName, String automationAccountName, String jobId, String jobStreamId) {
        if (resourceGroupName == null) {
            throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null.");
        }
        if (automationAccountName == null) {
            throw new IllegalArgumentException("Parameter automationAccountName is required and cannot be null.");
        }
        if (jobId == null) {
            throw new IllegalArgumentException("Parameter jobId is required and cannot be null.");
        }
        if (jobStreamId == null) {
            throw new IllegalArgumentException("Parameter jobStreamId is required and cannot be null.");
        }
        if (this.client.subscriptionId() == null) {
            throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null.");
        }
        final String apiVersion = "2015-10-31";
        return service.get(resourceGroupName, automationAccountName, jobId, jobStreamId, this.client.subscriptionId(), apiVersion, this.client.acceptLanguage(), this.client.userAgent())
            .flatMap(new Func1<Response<ResponseBody>, Observable<ServiceResponse<JobStreamInner>>>() {
                @Override
                public Observable<ServiceResponse<JobStreamInner>> call(Response<ResponseBody> response) {
                    try {
                        ServiceResponse<JobStreamInner> clientResponse = getDelegate(response);
                        return Observable.just(clientResponse);
                    } catch (Throwable t) {
                        return Observable.error(t);
                    }
                }
            });
    }

    private ServiceResponse<JobStreamInner> getDelegate(Response<ResponseBody> response) throws ErrorResponseException, IOException, IllegalArgumentException {
        return this.client.restClient().responseBuilderFactory().<JobStreamInner, ErrorResponseException>newInstance(this.client.serializerAdapter())
                .register(200, new TypeToken<JobStreamInner>() { }.getType())
                .registerError(ErrorResponseException.class)
                .build(response);
    }

    /**
     * Retrieve a list of jobs streams identified by job id.
     *
     * @param resourceGroupName Name of an Azure Resource group.
     * @param automationAccountName The name of the automation account.
     * @param jobId The job Id.
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @throws ErrorResponseException thrown if the request is rejected by server
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent
     * @return the PagedList<JobStreamInner> object if successful.
     */
    public PagedList<JobStreamInner> listByJob(final String resourceGroupName, final String automationAccountName, final String jobId) {
        ServiceResponse<Page<JobStreamInner>> response = listByJobSinglePageAsync(resourceGroupName, automationAccountName, jobId).toBlocking().single();
        return new PagedList<JobStreamInner>(response.body()) {
            @Override
            public Page<JobStreamInner> nextPage(String nextPageLink) {
                return listByJobNextSinglePageAsync(nextPageLink).toBlocking().single().body();
            }
        };
    }

    /**
     * Retrieve a list of jobs streams identified by job id.
     *
     * @param resourceGroupName Name of an Azure Resource group.
     * @param automationAccountName The name of the automation account.
     * @param jobId The job Id.
     * @param serviceCallback the async ServiceCallback to handle successful and failed responses.
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @return the {@link ServiceFuture} object
     */
    public ServiceFuture<List<JobStreamInner>> listByJobAsync(final String resourceGroupName, final String automationAccountName, final String jobId, final ListOperationCallback<JobStreamInner> serviceCallback) {
        return AzureServiceFuture.fromPageResponse(
            listByJobSinglePageAsync(resourceGroupName, automationAccountName, jobId),
            new Func1<String, Observable<ServiceResponse<Page<JobStreamInner>>>>() {
                @Override
                public Observable<ServiceResponse<Page<JobStreamInner>>> call(String nextPageLink) {
                    return listByJobNextSinglePageAsync(nextPageLink);
                }
            },
            serviceCallback);
    }

    /**
     * Retrieve a list of jobs streams identified by job id.
     *
     * @param resourceGroupName Name of an Azure Resource group.
     * @param automationAccountName The name of the automation account.
     * @param jobId The job Id.
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @return the observable to the PagedList<JobStreamInner> object
     */
    public Observable<Page<JobStreamInner>> listByJobAsync(final String resourceGroupName, final String automationAccountName, final String jobId) {
        return listByJobWithServiceResponseAsync(resourceGroupName, automationAccountName, jobId)
            .map(new Func1<ServiceResponse<Page<JobStreamInner>>, Page<JobStreamInner>>() {
                @Override
                public Page<JobStreamInner> call(ServiceResponse<Page<JobStreamInner>> response) {
                    return response.body();
                }
            });
    }

    /**
     * Retrieve a list of jobs streams identified by job id.
     *
     * @param resourceGroupName Name of an Azure Resource group.
     * @param automationAccountName The name of the automation account.
     * @param jobId The job Id.
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @return the observable to the PagedList<JobStreamInner> object
     */
    public Observable<ServiceResponse<Page<JobStreamInner>>> listByJobWithServiceResponseAsync(final String resourceGroupName, final String automationAccountName, final String jobId) {
        return listByJobSinglePageAsync(resourceGroupName, automationAccountName, jobId)
            .concatMap(new Func1<ServiceResponse<Page<JobStreamInner>>, Observable<ServiceResponse<Page<JobStreamInner>>>>() {
                @Override
                public Observable<ServiceResponse<Page<JobStreamInner>>> call(ServiceResponse<Page<JobStreamInner>> page) {
                    String nextPageLink = page.body().nextPageLink();
                    if (nextPageLink == null) {
                        return Observable.just(page);
                    }
                    return Observable.just(page).concatWith(listByJobNextWithServiceResponseAsync(nextPageLink));
                }
            });
    }

    /**
     * Retrieve a list of jobs streams identified by job id.
     *
     * @param resourceGroupName Name of an Azure Resource group.
     * @param automationAccountName The name of the automation account.
     * @param jobId The job Id.
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @return the PagedList<JobStreamInner> object wrapped in {@link ServiceResponse} if successful.
     */
    public Observable<ServiceResponse<Page<JobStreamInner>>> listByJobSinglePageAsync(final String resourceGroupName, final String automationAccountName, final String jobId) {
        if (resourceGroupName == null) {
            throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null.");
        }
        if (automationAccountName == null) {
            throw new IllegalArgumentException("Parameter automationAccountName is required and cannot be null.");
        }
        if (jobId == null) {
            throw new IllegalArgumentException("Parameter jobId is required and cannot be null.");
        }
        if (this.client.subscriptionId() == null) {
            throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null.");
        }
        final String apiVersion = "2015-10-31";
        final String filter = null;
        return service.listByJob(resourceGroupName, automationAccountName, jobId, this.client.subscriptionId(), filter, apiVersion, this.client.acceptLanguage(), this.client.userAgent())
            .flatMap(new Func1<Response<ResponseBody>, Observable<ServiceResponse<Page<JobStreamInner>>>>() {
                @Override
                public Observable<ServiceResponse<Page<JobStreamInner>>> call(Response<ResponseBody> response) {
                    try {
                        ServiceResponse<PageImpl<JobStreamInner>> result = listByJobDelegate(response);
                        return Observable.just(new ServiceResponse<Page<JobStreamInner>>(result.body(), result.response()));
                    } catch (Throwable t) {
                        return Observable.error(t);
                    }
                }
            });
    }

    /**
     * Retrieve a list of jobs streams identified by job id.
     *
     * @param resourceGroupName Name of an Azure Resource group.
     * @param automationAccountName The name of the automation account.
     * @param jobId The job Id.
     * @param filter The filter to apply on the operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @throws ErrorResponseException thrown if the request is rejected by server
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent
     * @return the PagedList<JobStreamInner> object if successful.
     */
    public PagedList<JobStreamInner> listByJob(final String resourceGroupName, final String automationAccountName, final String jobId, final String filter) {
        ServiceResponse<Page<JobStreamInner>> response = listByJobSinglePageAsync(resourceGroupName, automationAccountName, jobId, filter).toBlocking().single();
        return new PagedList<JobStreamInner>(response.body()) {
            @Override
            public Page<JobStreamInner> nextPage(String nextPageLink) {
                return listByJobNextSinglePageAsync(nextPageLink).toBlocking().single().body();
            }
        };
    }

    /**
     * Retrieve a list of jobs streams identified by job id.
     *
     * @param resourceGroupName Name of an Azure Resource group.
     * @param automationAccountName The name of the automation account.
     * @param jobId The job Id.
     * @param filter The filter to apply on the operation.
     * @param serviceCallback the async ServiceCallback to handle successful and failed responses.
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @return the {@link ServiceFuture} object
     */
    public ServiceFuture<List<JobStreamInner>> listByJobAsync(final String resourceGroupName, final String automationAccountName, final String jobId, final String filter, final ListOperationCallback<JobStreamInner> serviceCallback) {
        return AzureServiceFuture.fromPageResponse(
            listByJobSinglePageAsync(resourceGroupName, automationAccountName, jobId, filter),
            new Func1<String, Observable<ServiceResponse<Page<JobStreamInner>>>>() {
                @Override
                public Observable<ServiceResponse<Page<JobStreamInner>>> call(String nextPageLink) {
                    return listByJobNextSinglePageAsync(nextPageLink);
                }
            },
            serviceCallback);
    }

    /**
     * Retrieve a list of jobs streams identified by job id.
     *
     * @param resourceGroupName Name of an Azure Resource group.
     * @param automationAccountName The name of the automation account.
     * @param jobId The job Id.
     * @param filter The filter to apply on the operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @return the observable to the PagedList<JobStreamInner> object
     */
    public Observable<Page<JobStreamInner>> listByJobAsync(final String resourceGroupName, final String automationAccountName, final String jobId, final String filter) {
        return listByJobWithServiceResponseAsync(resourceGroupName, automationAccountName, jobId, filter)
            .map(new Func1<ServiceResponse<Page<JobStreamInner>>, Page<JobStreamInner>>() {
                @Override
                public Page<JobStreamInner> call(ServiceResponse<Page<JobStreamInner>> response) {
                    return response.body();
                }
            });
    }

    /**
     * Retrieve a list of jobs streams identified by job id.
     *
     * @param resourceGroupName Name of an Azure Resource group.
     * @param automationAccountName The name of the automation account.
     * @param jobId The job Id.
     * @param filter The filter to apply on the operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @return the observable to the PagedList<JobStreamInner> object
     */
    public Observable<ServiceResponse<Page<JobStreamInner>>> listByJobWithServiceResponseAsync(final String resourceGroupName, final String automationAccountName, final String jobId, final String filter) {
        return listByJobSinglePageAsync(resourceGroupName, automationAccountName, jobId, filter)
            .concatMap(new Func1<ServiceResponse<Page<JobStreamInner>>, Observable<ServiceResponse<Page<JobStreamInner>>>>() {
                @Override
                public Observable<ServiceResponse<Page<JobStreamInner>>> call(ServiceResponse<Page<JobStreamInner>> page) {
                    String nextPageLink = page.body().nextPageLink();
                    if (nextPageLink == null) {
                        return Observable.just(page);
                    }
                    return Observable.just(page).concatWith(listByJobNextWithServiceResponseAsync(nextPageLink));
                }
            });
    }

    /**
     * Retrieve a list of jobs streams identified by job id.
     *
    ServiceResponse<PageImpl<JobStreamInner>> * @param resourceGroupName Name of an Azure Resource group.
    ServiceResponse<PageImpl<JobStreamInner>> * @param automationAccountName The name of the automation account.
    ServiceResponse<PageImpl<JobStreamInner>> * @param jobId The job Id.
    ServiceResponse<PageImpl<JobStreamInner>> * @param filter The filter to apply on the operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @return the PagedList<JobStreamInner> object wrapped in {@link ServiceResponse} if successful.
     */
    public Observable<ServiceResponse<Page<JobStreamInner>>> listByJobSinglePageAsync(final String resourceGroupName, final String automationAccountName, final String jobId, final String filter) {
        if (resourceGroupName == null) {
            throw new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null.");
        }
        if (automationAccountName == null) {
            throw new IllegalArgumentException("Parameter automationAccountName is required and cannot be null.");
        }
        if (jobId == null) {
            throw new IllegalArgumentException("Parameter jobId is required and cannot be null.");
        }
        if (this.client.subscriptionId() == null) {
            throw new IllegalArgumentException("Parameter this.client.subscriptionId() is required and cannot be null.");
        }
        final String apiVersion = "2015-10-31";
        return service.listByJob(resourceGroupName, automationAccountName, jobId, this.client.subscriptionId(), filter, apiVersion, this.client.acceptLanguage(), this.client.userAgent())
            .flatMap(new Func1<Response<ResponseBody>, Observable<ServiceResponse<Page<JobStreamInner>>>>() {
                @Override
                public Observable<ServiceResponse<Page<JobStreamInner>>> call(Response<ResponseBody> response) {
                    try {
                        ServiceResponse<PageImpl<JobStreamInner>> result = listByJobDelegate(response);
                        return Observable.just(new ServiceResponse<Page<JobStreamInner>>(result.body(), result.response()));
                    } catch (Throwable t) {
                        return Observable.error(t);
                    }
                }
            });
    }

    private ServiceResponse<PageImpl<JobStreamInner>> listByJobDelegate(Response<ResponseBody> response) throws ErrorResponseException, IOException, IllegalArgumentException {
        return this.client.restClient().responseBuilderFactory().<PageImpl<JobStreamInner>, ErrorResponseException>newInstance(this.client.serializerAdapter())
                .register(200, new TypeToken<PageImpl<JobStreamInner>>() { }.getType())
                .registerError(ErrorResponseException.class)
                .build(response);
    }

    /**
     * Retrieve a list of jobs streams identified by job id.
     *
     * @param nextPageLink The NextLink from the previous successful call to List operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @throws ErrorResponseException thrown if the request is rejected by server
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent
     * @return the PagedList<JobStreamInner> object if successful.
     */
    public PagedList<JobStreamInner> listByJobNext(final String nextPageLink) {
        ServiceResponse<Page<JobStreamInner>> response = listByJobNextSinglePageAsync(nextPageLink).toBlocking().single();
        return new PagedList<JobStreamInner>(response.body()) {
            @Override
            public Page<JobStreamInner> nextPage(String nextPageLink) {
                return listByJobNextSinglePageAsync(nextPageLink).toBlocking().single().body();
            }
        };
    }

    /**
     * Retrieve a list of jobs streams identified by job id.
     *
     * @param nextPageLink The NextLink from the previous successful call to List operation.
     * @param serviceFuture the ServiceFuture object tracking the Retrofit calls
     * @param serviceCallback the async ServiceCallback to handle successful and failed responses.
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @return the {@link ServiceFuture} object
     */
    public ServiceFuture<List<JobStreamInner>> listByJobNextAsync(final String nextPageLink, final ServiceFuture<List<JobStreamInner>> serviceFuture, final ListOperationCallback<JobStreamInner> serviceCallback) {
        return AzureServiceFuture.fromPageResponse(
            listByJobNextSinglePageAsync(nextPageLink),
            new Func1<String, Observable<ServiceResponse<Page<JobStreamInner>>>>() {
                @Override
                public Observable<ServiceResponse<Page<JobStreamInner>>> call(String nextPageLink) {
                    return listByJobNextSinglePageAsync(nextPageLink);
                }
            },
            serviceCallback);
    }

    /**
     * Retrieve a list of jobs streams identified by job id.
     *
     * @param nextPageLink The NextLink from the previous successful call to List operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @return the observable to the PagedList<JobStreamInner> object
     */
    public Observable<Page<JobStreamInner>> listByJobNextAsync(final String nextPageLink) {
        return listByJobNextWithServiceResponseAsync(nextPageLink)
            .map(new Func1<ServiceResponse<Page<JobStreamInner>>, Page<JobStreamInner>>() {
                @Override
                public Page<JobStreamInner> call(ServiceResponse<Page<JobStreamInner>> response) {
                    return response.body();
                }
            });
    }

    /**
     * Retrieve a list of jobs streams identified by job id.
     *
     * @param nextPageLink The NextLink from the previous successful call to List operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @return the observable to the PagedList<JobStreamInner> object
     */
    public Observable<ServiceResponse<Page<JobStreamInner>>> listByJobNextWithServiceResponseAsync(final String nextPageLink) {
        return listByJobNextSinglePageAsync(nextPageLink)
            .concatMap(new Func1<ServiceResponse<Page<JobStreamInner>>, Observable<ServiceResponse<Page<JobStreamInner>>>>() {
                @Override
                public Observable<ServiceResponse<Page<JobStreamInner>>> call(ServiceResponse<Page<JobStreamInner>> page) {
                    String nextPageLink = page.body().nextPageLink();
                    if (nextPageLink == null) {
                        return Observable.just(page);
                    }
                    return Observable.just(page).concatWith(listByJobNextWithServiceResponseAsync(nextPageLink));
                }
            });
    }

    /**
     * Retrieve a list of jobs streams identified by job id.
     *
    ServiceResponse<PageImpl<JobStreamInner>> * @param nextPageLink The NextLink from the previous successful call to List operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation
     * @return the PagedList<JobStreamInner> object wrapped in {@link ServiceResponse} if successful.
     */
    public Observable<ServiceResponse<Page<JobStreamInner>>> listByJobNextSinglePageAsync(final String nextPageLink) {
        if (nextPageLink == null) {
            throw new IllegalArgumentException("Parameter nextPageLink is required and cannot be null.");
        }
        String nextUrl = String.format("%s", nextPageLink);
        return service.listByJobNext(nextUrl, this.client.acceptLanguage(), this.client.userAgent())
            .flatMap(new Func1<Response<ResponseBody>, Observable<ServiceResponse<Page<JobStreamInner>>>>() {
                @Override
                public Observable<ServiceResponse<Page<JobStreamInner>>> call(Response<ResponseBody> response) {
                    try {
                        ServiceResponse<PageImpl<JobStreamInner>> result = listByJobNextDelegate(response);
                        return Observable.just(new ServiceResponse<Page<JobStreamInner>>(result.body(), result.response()));
                    } catch (Throwable t) {
                        return Observable.error(t);
                    }
                }
            });
    }

    private ServiceResponse<PageImpl<JobStreamInner>> listByJobNextDelegate(Response<ResponseBody> response) throws ErrorResponseException, IOException, IllegalArgumentException {
        return this.client.restClient().responseBuilderFactory().<PageImpl<JobStreamInner>, ErrorResponseException>newInstance(this.client.serializerAdapter())
                .register(200, new TypeToken<PageImpl<JobStreamInner>>() { }.getType())
                .registerError(ErrorResponseException.class)
                .build(response);
    }

}


text:
package net.giovannibotta.antlr.example.arith1;
import org.antlr.v4.runtime.atn.*;
import org.antlr.v4.runtime.dfa.DFA;
import org.antlr.v4.runtime.*;
import org.antlr.v4.runtime.misc.*;
import org.antlr.v4.runtime.tree.*;
import java.util.List;
import java.util.Iterator;
import java.util.ArrayList;

@SuppressWarnings({"all", "warnings", "unchecked", "unused", "cast"})
public class Expressions1Parser extends Parser {
	protected static final DFA[] _decisionToDFA;
	protected static final PredictionContextCache _sharedContextCache =
		new PredictionContextCache();
	public static final int
		T__3=1, T__2=2, T__1=3, T__0=4, INT=5, WS=6;
	public static final String[] tokenNames = {
		"<INVALID>", "'+'", "'*'", "'-'", "'/'", "INT", "WS"
	};
	public static final int
		RULE_start = 0, RULE_expr = 1;
	public static final String[] ruleNames = {
		"start", "expr"
	};

	@Override
	public String getGrammarFileName() { return "Expressions1.g4"; }

	@Override
	public String[] getTokenNames() { return tokenNames; }

	@Override
	public String[] getRuleNames() { return ruleNames; }

	@Override
	public String getSerializedATN() { return _serializedATN; }

	@Override
	public ATN getATN() { return _ATN; }

	public Expressions1Parser(TokenStream input) {
		super(input);
		_interp = new ParserATNSimulator(this,_ATN,_decisionToDFA,_sharedContextCache);
	}
	public static class StartContext extends ParserRuleContext {
		public ExprContext expr() {
			return getRuleContext(ExprContext.class,0);
		}
		public StartContext(ParserRuleContext parent, int invokingState) {
			super(parent, invokingState);
		}
		@Override public int getRuleIndex() { return RULE_start; }
		@Override
		public <T> T accept(ParseTreeVisitor<? extends T> visitor) {
			if ( visitor instanceof Expressions1Visitor ) return ((Expressions1Visitor<? extends T>)visitor).visitStart(this);
			else return visitor.visitChildren(this);
		}
	}

	public final StartContext start() throws RecognitionException {
		StartContext _localctx = new StartContext(_ctx, getState());
		enterRule(_localctx, 0, RULE_start);
		try {
			enterOuterAlt(_localctx, 1);
			{
			setState(4); expr(0);
			}
		}
		catch (RecognitionException re) {
			_localctx.exception = re;
			_errHandler.reportError(this, re);
			_errHandler.recover(this, re);
		}
		finally {
			exitRule();
		}
		return _localctx;
	}

	public static class ExprContext extends ParserRuleContext {
		public ExprContext(ParserRuleContext parent, int invokingState) {
			super(parent, invokingState);
		}
		@Override public int getRuleIndex() { return RULE_expr; }

		public ExprContext() { }
		public void copyFrom(ExprContext ctx) {
			super.copyFrom(ctx);
		}
	}
	public static class OpExprContext extends ExprContext {
		public ExprContext left;
		public Token op;
		public ExprContext right;
		public List<ExprContext> expr() {
			return getRuleContexts(ExprContext.class);
		}
		public ExprContext expr(int i) {
			return getRuleContext(ExprContext.class,i);
		}
		public OpExprContext(ExprContext ctx) { copyFrom(ctx); }
		@Override
		public <T> T accept(ParseTreeVisitor<? extends T> visitor) {
			if ( visitor instanceof Expressions1Visitor ) return ((Expressions1Visitor<? extends T>)visitor).visitOpExpr(this);
			else return visitor.visitChildren(this);
		}
	}
	public static class AtomExprContext extends ExprContext {
		public Token atom;
		public TerminalNode INT() { return getToken(Expressions1Parser.INT, 0); }
		public AtomExprContext(ExprContext ctx) { copyFrom(ctx); }
		@Override
		public <T> T accept(ParseTreeVisitor<? extends T> visitor) {
			if ( visitor instanceof Expressions1Visitor ) return ((Expressions1Visitor<? extends T>)visitor).visitAtomExpr(this);
			else return visitor.visitChildren(this);
		}
	}

	public final ExprContext expr() throws RecognitionException {
		return expr(0);
	}

	private ExprContext expr(int _p) throws RecognitionException {
		ParserRuleContext _parentctx = _ctx;
		int _parentState = getState();
		ExprContext _localctx = new ExprContext(_ctx, _parentState);
		ExprContext _prevctx = _localctx;
		int _startState = 2;
		enterRecursionRule(_localctx, 2, RULE_expr, _p);
		int _la;
		try {
			int _alt;
			enterOuterAlt(_localctx, 1);
			{
			{
			_localctx = new AtomExprContext(_localctx);
			_ctx = _localctx;
			_prevctx = _localctx;

			setState(7); ((AtomExprContext)_localctx).atom = match(INT);
			}
			_ctx.stop = _input.LT(-1);
			setState(17);
			_errHandler.sync(this);
			_alt = getInterpreter().adaptivePredict(_input,1,_ctx);
			while ( _alt!=2 && _alt!=-1 ) {
				if ( _alt==1 ) {
					if ( _parseListeners!=null ) triggerExitRuleEvent();
					_prevctx = _localctx;
					{
					setState(15);
					switch ( getInterpreter().adaptivePredict(_input,0,_ctx) ) {
					case 1:
						{
						_localctx = new OpExprContext(new ExprContext(_parentctx, _parentState));
						((OpExprContext)_localctx).left = _prevctx;
						pushNewRecursionContext(_localctx, _startState, RULE_expr);
						setState(9);
						if (!(precpred(_ctx, 3))) throw new FailedPredicateException(this, "precpred(_ctx, 3)");
						setState(10);
						((OpExprContext)_localctx).op = _input.LT(1);
						_la = _input.LA(1);
						if ( !(_la==2 || _la==4) ) {
							((OpExprContext)_localctx).op = (Token)_errHandler.recoverInline(this);
						}
						consume();
						setState(11); ((OpExprContext)_localctx).right = expr(4);
						}
						break;

					case 2:
						{
						_localctx = new OpExprContext(new ExprContext(_parentctx, _parentState));
						((OpExprContext)_localctx).left = _prevctx;
						pushNewRecursionContext(_localctx, _startState, RULE_expr);
						setState(12);
						if (!(precpred(_ctx, 2))) throw new FailedPredicateException(this, "precpred(_ctx, 2)");
						setState(13);
						((OpExprContext)_localctx).op = _input.LT(1);
						_la = _input.LA(1);
						if ( !(_la==1 || _la==3) ) {
							((OpExprContext)_localctx).op = (Token)_errHandler.recoverInline(this);
						}
						consume();
						setState(14); ((OpExprContext)_localctx).right = expr(3);
						}
						break;
					}
					}
				}
				setState(19);
				_errHandler.sync(this);
				_alt = getInterpreter().adaptivePredict(_input,1,_ctx);
			}
			}
		}
		catch (RecognitionException re) {
			_localctx.exception = re;
			_errHandler.reportError(this, re);
			_errHandler.recover(this, re);
		}
		finally {
			unrollRecursionContexts(_parentctx);
		}
		return _localctx;
	}

	public boolean sempred(RuleContext _localctx, int ruleIndex, int predIndex) {
		switch (ruleIndex) {
		case 1: return expr_sempred((ExprContext)_localctx, predIndex);
		}
		return true;
	}
	private boolean expr_sempred(ExprContext _localctx, int predIndex) {
		switch (predIndex) {
		case 0: return precpred(_ctx, 3);

		case 1: return precpred(_ctx, 2);
		}
		return true;
	}

	public static final String _serializedATN =
		"\3\u0430\ud6d1\u8206\uad2d\u4417\uaef1\u8d80\uaadd\3\b\27\4\2\t\2\4\3"+
		"\t\3\3\2\3\2\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\3\7\3\22\n\3\f\3\16\3\25"+
		"\13\3\3\3\2\3\4\4\2\4\2\4\4\2\4\4\6\6\4\2\3\3\5\5\26\2\6\3\2\2\2\4\b\3"+
		"\2\2\2\6\7\5\4\3\2\7\3\3\2\2\2\b\t\b\3\1\2\t\n\7\7\2\2\n\23\3\2\2\2\13"+
		"\f\f\5\2\2\f\r\t\2\2\2\r\22\5\4\3\6\16\17\f\4\2\2\17\20\t\3\2\2\20\22"+
		"\5\4\3\5\21\13\3\2\2\2\21\16\3\2\2\2\22\25\3\2\2\2\23\21\3\2\2\2\23\24"+
		"\3\2\2\2\24\5\3\2\2\2\25\23\3\2\2\2\4\21\23";
	public static final ATN _ATN =
		new ATNDeserializer().deserialize(_serializedATN.toCharArray());
	static {
		_decisionToDFA = new DFA[_ATN.getNumberOfDecisions()];
		for (int i = 0; i < _ATN.getNumberOfDecisions(); i++) {
			_decisionToDFA[i] = new DFA(_ATN.getDecisionState(i), i);
		}
	}
}


text:
FROM golang:1.7.4

# virtualenv is necessary to run acceptance tests
RUN apt-get update && \
    apt-get install -y iptables build-essential --no-install-recommends && \
    apt-get install -y python-setuptools && \
    easy_install pip && pip install virtualenv

# Install build dependencies
RUN go get github.com/aktau/github-release && \
    go get golang.org/x/tools/cmd/cover && \
    go get github.com/golang/lint/golint

# Which docker version to test on and what default one to use
ENV DOCKER_VERSIONS 1.9.1 1.10.3 1.11.2 1.12.1
ENV DEFAULT_DOCKER_VERSION 1.10.3

# Download docker
RUN set -e; \
    for v in $(echo ${DOCKER_VERSIONS} | cut -f1); do \
        if test "${v}" = "1.9.1" || test "${v}" = "1.10.3"; then \
           mkdir -p /usr/local/bin/docker-${v}/; \
           curl https://get.docker.com/builds/Linux/x86_64/docker-${v} -o /usr/local/bin/docker-${v}/docker; \
           chmod +x /usr/local/bin/docker-${v}/docker; \
        else \
             curl https://get.docker.com/builds/Linux/x86_64/docker-${v}.tgz -o docker-${v}.tgz; \
             tar xzf docker-${v}.tgz -C /usr/local/bin/; \
             mv /usr/local/bin/docker /usr/local/bin/docker-${v}; \
             rm docker-${v}.tgz; \
        fi \
    done

# Set the default Docker to be run
RUN ln -s /usr/local/bin/docker-${DEFAULT_DOCKER_VERSION} /usr/local/bin/docker

WORKDIR /go/src/github.com/docker/libcompose

# Compose COMMIT for acceptance test version, update that commit when
# you want to update the acceptance test version to support.
ENV COMPOSE_COMMIT 1.8.0
RUN virtualenv venv && \
    git clone https://github.com/docker/compose.git venv/compose && \
    cd venv/compose && \
    git checkout -q "$COMPOSE_COMMIT" && \
    ../bin/pip install \
               -r requirements.txt \
               -r requirements-dev.txt

ENV COMPOSE_BINARY /go/src/github.com/docker/libcompose/libcompose-cli
ENV USER root

# Compile Go for cross compilation
# FIXME(vdemeester) This is mainly for the vendor script, should be shared somewhere else
ENV DOCKER_CROSSPLATFORMS \
	linux/386 linux/arm \
	darwin/amd64 darwin/386 \
	freebsd/amd64 freebsd/386 freebsd/arm \
	windows/amd64 windows/386

# Wrap all commands in the "docker-in-docker" script to allow nested containers
ENTRYPOINT ["hack/dind"]

COPY . /go/src/github.com/docker/libcompose


text:
layout: post
title:  "First Blog Post"
date:   2016-09-23
categories: ""
author: "Brynna Wainwright"
---

This is my first blog post on my website! I've learned a bunch in this class so far. For starters, I have a much better understanding of computer systems (i.e. clients, servers, networks) as a whole than before I came into this class. I've also learned how to navigate GitHub fairly well, both understanding how to make commit changes, how to view the changes live without commiting them, and how to navigate through the GitHub directories. I've also been able to learn a little bit about HTML and CSS which are both very useful knowledge for front-end developing! I'm excited to learn even more in this class in the weeks to come :)


text:
package com.spike.giantdataanalysis.model.logic.relational.expression.raw;

import com.google.common.base.Preconditions;
import com.spike.giantdataanalysis.model.logic.relational.core.RelationalAlgebraEnum;
import com.spike.giantdataanalysis.model.logic.relational.expression.raw.CompoundStatement.RoutineBody;
import com.spike.giantdataanalysis.model.logic.relational.expression.raw.DBObjects.FullId;
import com.spike.giantdataanalysis.model.logic.relational.expression.raw.DBObjects.TableName;

/**
 * <pre>
 createTrigger
    : CREATE ownerStatement?
      TRIGGER thisTrigger=fullId
      triggerTime=(BEFORE | AFTER)
      triggerEvent=(INSERT | UPDATE | DELETE)
      ON tableName FOR EACH ROW
      (triggerPlace=(FOLLOWS | PRECEDES) otherTrigger=fullId)?
      routineBody
    ;
 * </pre>
 */
public class CreateTrigger implements DdlStatement {
  public static enum TriggerTimeEnum implements RelationalAlgebraEnum {
    BEFORE, AFTER;
    @Override
    public String literal() {
      return name();
    }
  }

  public static enum TriggerEventEnum implements RelationalAlgebraEnum {
    INSERT, UPDATE, DELETE;
    @Override
    public String literal() {
      return name();
    }
  }

  public static enum TriggerPlaceEnum implements RelationalAlgebraEnum {
    FOLLOWS, PRECEDES;

    @Override
    public String literal() {
      return name();
    }
  }

  public final OwnerStatement ownerStatement;
  public final FullId thisTrigger;
  public final TriggerTimeEnum triggerTime;
  public final TriggerEventEnum triggerEvent;
  public final TableName tableName;
  public final TriggerPlaceEnum triggerPlace;
  public final FullId otherTrigger;
  public final RoutineBody routineBody;

  CreateTrigger(OwnerStatement ownerStatement, FullId thisTrigger, TriggerTimeEnum triggerTime,
      TriggerEventEnum triggerEvent, TableName tableName, TriggerPlaceEnum triggerPlace,
      FullId otherTrigger, RoutineBody routineBody) {
    Preconditions.checkArgument(thisTrigger != null);
    Preconditions.checkArgument(triggerTime != null);
    Preconditions.checkArgument(triggerEvent != null);
    Preconditions.checkArgument(tableName != null);
    Preconditions.checkArgument(routineBody != null);

    this.ownerStatement = ownerStatement;
    this.thisTrigger = thisTrigger;
    this.triggerTime = triggerTime;
    this.triggerEvent = triggerEvent;
    this.tableName = tableName;
    this.triggerPlace = triggerPlace;
    this.otherTrigger = otherTrigger;
    this.routineBody = routineBody;
  }

  @Override
  public String literal() {
    StringBuilder sb = new StringBuilder();
    sb.append("CREATE ").append(" ");
    if (ownerStatement != null) {
      sb.append("TRIGGER ").append(thisTrigger.literal()).append(" ");
    }
    sb.append(triggerTime.literal()).append(" ");
    sb.append(triggerEvent.literal()).append(" ");
    sb.append("ON ").append(tableName.literal()).append(" FOR EACH ROW");
    if (otherTrigger != null) {
      sb.append(triggerPlace.literal()).append(" ").append(otherTrigger.literal()).append(" ");
    }
    sb.append(routineBody.literal()).append(" ");

    return sb.toString();
  }
}


text:
"use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.Arrays = void 0;
var Arrays;
(function (Arrays) {
    /**
     * Searches the specified array of numbers for the specified value using the binary search algorithm. The array must
     * be sorted prior to making this call. If it is not sorted, the results are unspecified. If the array contains
     * multiple elements with the specified value, there is no guarantee which one will be found.
     *
     * @returns index of the search key, if it is contained in the array; otherwise, (-(insertion point) - 1). The
     * insertion point is defined as the point at which the key would be inserted into the array: the index of the first
     * element greater than the key, or array.length if all elements in the array are less than the specified key. Note
     * that this guarantees that the return value will be >= 0 if and only if the key is found.
     */
    function binarySearch(array, key, fromIndex, toIndex) {
        return binarySearch0(array, fromIndex !== undefined ? fromIndex : 0, toIndex !== undefined ? toIndex : array.length, key);
    }
    Arrays.binarySearch = binarySearch;
    function binarySearch0(array, fromIndex, toIndex, key) {
        let low = fromIndex;
        let high = toIndex - 1;
        while (low <= high) {
            let mid = (low + high) >>> 1;
            let midVal = array[mid];
            if (midVal < key) {
                low = mid + 1;
            }
            else if (midVal > key) {
                high = mid - 1;
            }
            else {
                // key found
                return mid;
            }
        }
        // key not found.
        return -(low + 1);
    }
    function toString(array) {
        let result = "[";
        let first = true;
        for (let element of array) {
            if (first) {
                first = false;
            }
            else {
                result += ", ";
            }
            if (element === null) {
                result += "null";
            }
            else if (element === undefined) {
                result += "undefined";
            }
            else {
                result += element;
            }
        }
        result += "]";
        return result;
    }
    Arrays.toString = toString;
})(Arrays = exports.Arrays || (exports.Arrays = {}));
//# sourceMappingURL=Arrays.js.map