Exemple #1
0
    def pprint_changes(self, prior, **kwArgs):
        """
        Pretty-prints the difference between the two objects.
        
        >>> e_push1 = _makeFakeHistoryEntry_push("Fred", 12, 4)
        >>> e_push2 = _makeFakeHistoryEntry_push("Fred", 12, 5)
        >>> e_refPt = _makeFakeHistoryEntry_refPt("George", 15, 1)
        >>> h = HistoryList.fromargs(e_push1, e_push2)
        >>> h2 = h.__copy__()
        >>> h2.append(e_refPt)
        >>> del h2[0]
        >>> h2.pprint_changes(h, label="Overall changes")
        Overall changes:
          Appended at end:
            Implicit zero for RP1 used at opcode index 15 in George
          Deleted from the start:
            Extra index 4 in PUSH opcode index 12 in Fred
        """

        p = pp.PP(**kwArgs)

        if not prior:
            f = lambda obj: isinstance(obj, historygroup.HistoryGroup)
            p.sequence_deep_tag_smart(self, f)
        else:
            p.diff_sequence_deep(self, prior)
Exemple #2
0
def _pprint(p, obj, **kwArgs):
    cumulOffset = 0
    currIndentSpaces = ""
    preIndenters = {0x59, 0x1B}  # EIF, ELSE
    postIndenters = {0x1B, 0x58}  # ELSE, IF
    p(obj.infoString)
    
    for i, opObj in enumerate(obj):
        label = "%04d (0x%06X): " % (i, cumulOffset)
        
        if opObj.isPush:
            p(''.join([label, currIndentSpaces, "PUSH"]))
            extra = p.indent + p.indentDelta + 17 + len(currIndentSpaces)
            p2 = pp.PP(indent=extra, stream=p.stream, maxWidth=p.maxWidth)
            p2.sequence_tag_long(list(opObj))
        
        else:
            if opObj in preIndenters:
                currIndentSpaces = currIndentSpaces[p.indentDelta:]
            
            p(''.join([label, currIndentSpaces, str(opObj)]))
            
            if opObj in postIndenters:
                currIndentSpaces += " " * p.indentDelta
        
        cumulOffset += opObj.getOriginalLength()
Exemple #3
0
    def pprint(self, **kwArgs):
        """
        Pretty-prints the object to the specified stream. Two keyword arguments
        are used:
        
            indent      How many spaces to indent on left (default 0)
            keys        Which keys to report (default all)
            stream      Stream to receive output (default sys.stdout)
        
        >>> m1 = Maxima.fromargs(cvt=10, function=45, stack=200)
        >>> m2 = Maxima.fromargs(cvt=14, function=30, point=18)
        >>> m3 = m1.merged(m2)
        >>> m3.pprint()
        Highest CVT index referred to: 14
        Highest function number referred to: 45
        Byte size of the binary hints: (no data)
        Highest point index in the glyph zone: 18
        Highest moved point index in the glyph zone: (no data)
        Deepest stack attained: 200
        Highest storage index referred to: (no data)
        Highest point index in the twilight zone: (no data)
        >>> m3.pprint(indent=3, keys=('storage', 'function'))
           Highest storage index referred to: (no data)
           Highest function number referred to: 45
        """

        p = pp.PP(**kwArgs)
        d = self.__dict__
        kd = self.keyData

        for k in kwArgs.get('keys', self.sortedKeys):
            p.simple(_dataString(d[k]), kd[k])
Exemple #4
0
    def pprint(self, **kwArgs):
        """
        Pretty-prints the object.
        
        >>> HistoryGroup().pprint()
        Empty collection of history entries
        >>> he1 = _makeFakeHistoryEntry_push("Fred", 12, 5)
        >>> he2 = _makeFakeHistoryEntry_refPt("George", 9, 2)
        >>> he3 = _makeFakeHistoryEntry_storage("George", 18, 20)
        >>> HistoryGroup.fromargs(he1, he2, he3).pprint()
        Extra index 5 in PUSH opcode index 12 in Fred
        Implicit zero for RP2 used at opcode index 9 in George
        Implicit zero for storage location 20 used at opcode index 18 in George
        """

        p = pp.PP(**kwArgs)

        if self:
            if len(self) == 1:
                p.deep(next(iter(self)))
            else:
                p.sequence_deep(self.iterSorted())

        else:
            p("Empty collection of history entries")
Exemple #5
0
    def pprint_changes(self, prior, **kwArgs):
        """
        Prints nothing if the two objects are equal. Otherwise prints a label
        (if specified) and what changed. Keyword arguments used are:
        
            indent          How many spaces to indent on left (default 0)
            indentDelta     Extra spaces per new indent (default 2)
            keys            Which keys to report (default all)
            label           Header label (no default)
            stream          Stream to receive output (default sys.stdout)
        
        >>> m = Maxima.fromargs(cvt=10, function=82, stack=200)
        >>> m.pprint_changes(Maxima())
        Highest CVT index referred to changed from (no data) to 10
        Highest function number referred to changed from (no data) to 82
        Deepest stack attained changed from (no data) to 200
        >>> m.pprint_changes(Maxima(), keys=('stack', 'cvt'))
        Deepest stack attained changed from (no data) to 200
        Highest CVT index referred to changed from (no data) to 10
        """

        p = pp.PP(**kwArgs)
        dSelf = self.__dict__
        dPrior = prior.__dict__
        kd = self.keyData

        for k in kwArgs.get('keys', self.sortedKeys):
            selfValue = dSelf[k]
            priorValue = dPrior[k]

            if selfValue != priorValue:
                p.diff(_dataString(selfValue), _dataString(priorValue), kd[k])
    def pprint_changes(self, prior, **kwArgs):
        """
        Prints nothing if the two objects are equal. Otherwise prints a label
        (if specified) and what changed. Keyword arguments used are:
        
            indent          How many spaces to indent on left (default 0)
            indentDelta     Extra spaces per new indent (default 2)
            keys            Which keys to report (default all)
            label           Header label (no default)
            stream          Stream to receive output (default sys.stdout)
        
        >>> gs1 = GraphicsState()
        >>> gs2 = GraphicsState.fromargs(loop=4, freedomVector=yAxis, zonePointer1=0)
        >>> gs2.pprint_changes(gs1)
        Freedom vector changed from (Singles: [1], Singles: [0]) to (Singles: [0], Singles: [1])
        Loop counter changed from 1 to 4
        Zone pointer 1 changed from 1 to 0
        >>> gs2.pprint_changes(gs1, label="Graphics state changes", keys=('loop',))
        Graphics state changes:
          Loop counter changed from 1 to 4
        """

        p = pp.PP(**kwArgs)
        f = p.diff
        dSelf = self.__dict__
        dPrior = prior.__dict__
        kd = self.keyData

        for k in kwArgs.get('keys', self.sortedKeys):
            selfValue = dSelf[k]
            priorValue = dPrior[k]

            if selfValue != priorValue:
                f(selfValue, priorValue, kd[k][KEYLABEL])
Exemple #7
0
    def pprint(self, **kwArgs):
        """
        Pretty-prints the object. Standard arguments are:
        
            indent          An integer representing the number of spaces in the
                            current indent. Default is 0.
            
            indentDelta     An integer representing the number of extra spaces
                            to add at each indent level. Default is 2.
            
            stream          The stream to which the output is to be written.
                            Default is sys.stdout.
        
        >>> fakeHint = _makeFakeHintObj("Fred")
        >>> HistoryEntry_op(fakeHint, 20, 0x4B, []).pprint()
        Result of opcode MPPEM at index 20 in Fred
        >>> pushHist1 = _makeFakeHistoryEntry_push("George", 12, 9)
        >>> pushHist2 = _makeFakeHistoryEntry_push("George", 12, 10)
        >>> HistoryEntry_op(fakeHint, 15, 0x63, (pushHist1, pushHist2)).pprint()
        Result of opcode MUL at index 15 in Fred, with inputs:
          Extra index 9 in PUSH opcode index 12 in George
          Extra index 10 in PUSH opcode index 12 in George
        """

        p = pp.PP(**kwArgs)
        t = (opcodeToNameMap[self.opcode], self.hintsPC,
             self.hintsObj[1].infoString)

        if self.historyTuple:
            s = "Result of opcode %s at index %d in %s, with inputs" % t
            p.sequence_deep(self.historyTuple, label=s)
        else:
            p("Result of opcode %s at index %d in %s" % t)
Exemple #8
0
    def pprint(self, **kwArgs):
        """
        Pretty-prints self.
        """

        if 'p' in kwArgs:
            p = kwArgs.pop('p')
        else:
            p = pp.PP(**kwArgs)

        p(str(self))
Exemple #9
0
    def pprint(self, **kwArgs):
        """
        Pretty-prints the object.
        
        >>> _makeFakeHistoryEntry_refPt("Fred", 2, 1).pprint()
        Implicit zero for RP1 used at opcode index 2 in Fred
        """

        p = pp.PP(**kwArgs)
        t = (self.refPtDefault, self.hintsPC, self.hintsObj[1].infoString)
        p("Implicit zero for RP%d used at opcode index %d in %s" % t)
Exemple #10
0
 def pprint(self, **kwArgs):
     """
     Pretty-prints the object.
     
     >>> _makeFakeHistoryEntry_push("Fred", 2, 3).pprint()
     Extra index 3 in PUSH opcode index 2 in Fred
     """
     
     p = pp.PP(**kwArgs)
     t = (self.extraIndex, self.hintsPC, self.hintsObj[1].infoString)
     p("Extra index %d in PUSH opcode index %d in %s" % t)
Exemple #11
0
    def pprint(self, **kwArgs):
        """
        Pretty-prints the object.
        
        >>> e_push1 = _makeFakeHistoryEntry_push("Fred", 12, 4)
        >>> e_push2 = _makeFakeHistoryEntry_push("Fred", 12, 5)
        >>> e_refPt = _makeFakeHistoryEntry_refPt("George", 15, 1)
        >>> HistoryList.fromargs(e_push1, e_push2, e_refPt).pprint()
        0: Extra index 4 in PUSH opcode index 12 in Fred
        1: Extra index 5 in PUSH opcode index 12 in Fred
        2: Implicit zero for RP1 used at opcode index 15 in George
        """

        p = pp.PP(**kwArgs)
        f = lambda obj: isinstance(obj, historygroup.HistoryGroup)
        p.sequence_deep_tag_smart(self, f)
Exemple #12
0
    def pprint(self, *a, **k):
        """
        Pretty-print the object. This does a hex dump.
        
        >>> Binary(b'In a hole in the ground there lived a hobbit.').pprint()
               0 | 496E 2061 2068 6F6C  6520 696E 2074 6865 |In a hole in the|
              10 | 2067 726F 756E 6420  7468 6572 6520 6C69 | ground there li|
              20 | 7665 6420 6120 686F  6262 6974 2E        |ved a hobbit.   |
        """

        if 'p' in k:
            p = k.pop('p')
        else:
            p = pp.PP(**k)

        k.pop('label', None)
        p.hexDump(self)
Exemple #13
0
def M_pprint(self, **kwArgs):
    """
    Pretty-prints the object.
    
    >>> _testingClass().pprint(label="The minimal string")
    The minimal string:
      ABC
    
    >>> _testingClass().pprint(label="The minimal string", useRepr=True)
    The minimal string:
      'ABC'
    """

    s = self._MINSPEC['minimal_string']
    p = (kwArgs.pop('p') if 'p' in kwArgs else pp.PP(**kwArgs))
    kwArgs.pop('label', None)
    p.simple(s, **kwArgs)
    def pprint(self, **kwArgs):
        """
        Pretty-prints the object to the specified stream. Two keyword arguments
        are used:
        
            indent      How many spaces to indent on left (default 0)
            keys        Which keys to report (default all)
            stream      Stream to receive output (default sys.stdout)
        
        >>> g = GraphicsState()
        >>> g.pprint()
        Auto-flip: True
        CVT cut-in: Singles: [1.0625]
        DELTA base: 9
        DELTA shift: 3
        Dual projection vector: (Singles: [1], Singles: [0])
        Freedom vector: (Singles: [1], Singles: [0])
        Instruction control: 0
        Loop counter: 1
        Minimum distance: Singles: [1.0]
        Projection vector: (Singles: [1], Singles: [0])
        Reference point 0: 0
        Reference point 1: 0
        Reference point 2: 0
        Round state: [Singles: [1.0], Singles: [0.0], Singles: [0.5]]
        Scan control: 0
        Scan type: 0
        Single width cut-in: Singles: [1.0]
        Single width value: 0
        Zone pointer 0: 1
        Zone pointer 1: 1
        Zone pointer 2: 1
        >>> g.pprint(indent=3, keys=('loop', 'autoFlip'))
           Loop counter: 1
           Auto-flip: True
        """

        p = pp.PP(**kwArgs)
        f = p.simple
        d = self.__dict__
        kd = self.keyData

        for k in kwArgs.get('keys', self.sortedKeys):
            if k[0] != '_':
                f(d[k], kd[k][KEYLABEL])
Exemple #15
0
 def pprint(self, **kwArgs):
     """
     Pretty-print the object.
     
     >>> h = _testingState()
     >>> h.pprint()
     000: AA [5]
     001: SVTCA[y]
     002: DELTAP1 [224, 9, 240, 9, 2]
     003: SRP1 [9]
     004: SHZ[RP1] [1]
     005: DELTAS1 [53, 70, 2, 9]
     """
     
     p = pp.PP(**kwArgs)
     
     for index, obj in enumerate(self.hints):
         p("%03d: %s" % (index, obj))
Exemple #16
0
    def pprint(self, **kwArgs):
        """
        Pretty-prints the object.
        
        >>> dc = DistanceColor.fromargs(gray=C([T(32, 96, 64)], 64))
        >>> dc.pprint(label="Colors")
        Colors:
          Black distance: Singles: [0.0]
          Gray distance: Singles: [0.5]
          White distance: Singles: [0.0]
        >>> dc.pprint(indent=3, keys=('gray', 'black'))
           Gray distance: Singles: [0.5]
           Black distance: Singles: [0.0]
        """

        p = pp.PP(**kwArgs)
        d = self.__dict__
        kd = self.keyData

        for k in kwArgs.get('keys', self.sortedKeys):
            p.simple(d[k], kd[k])
Exemple #17
0
    def pprint_changes(self, prior, **kwArgs):
        """
        Prints nothing if the two objects are equal. Otherwise prints a label
        (if specified) and what changed. Keyword arguments used are:
        
            indent          How many spaces to indent on left (default 0)
            indentDelta     Extra spaces per new indent (default 2)
            keys            Which keys to report (default all)
            label           Header label (no default)
            stream          Stream to receive output (default sys.stdout)
        
        >>> s = Statistics()
        >>> he = _makeFakeHistoryEntry_push("fake hint object", 2, 14)
        >>> s.addHistory('storage', 18, he)
        >>> s.pprint_changes(Statistics(), label="Summary of changes")
        Summary of changes:
          Maxima values (changes):
            Highest storage index referred to changed from (no data) to 18
          History for storage locations (changes):
            Added records:
              18:
                Extra index 14 in PUSH opcode index 2 in fake hint object
        """

        poKeys = kwArgs.pop('keys', self.printOrderKeys)
        p = pp.PP(**kwArgs)
        dSelf = self.__dict__
        dPrior = prior.__dict__
        kd = self.keyData

        for k in poKeys:
            t = kd[k]
            selfValue = dSelf[k]
            priorValue = dPrior[k]

            if selfValue != priorValue:
                s = "%s (changes)" % (t[KEYLABEL], )
                t[KEYPPDIFF](p, selfValue, priorValue, label=s)
Exemple #18
0
    def pprint_changes(self, prior, **kwArgs):
        """
        Pretty-prints the difference in the two objects.
        
        >>> he11 = _makeFakeHistoryEntry_push("Fred", 12, 5)
        >>> he12 = _makeFakeHistoryEntry_push("Fred", 12, 6)
        >>> he2 = _makeFakeHistoryEntry_refPt("George", 9, 2)
        >>> he3 = _makeFakeHistoryEntry_storage("George", 18, 20)
        >>> g1 = HistoryGroup.fromargs(he11, he2, he3)
        >>> g2 = HistoryGroup.fromargs(he12, he2, he3)
        >>> f = utilities.debugStream()
        >>> g1.pprint_changes(None, stream=f)
        >>> v = f.getvalue().splitlines()
        >>> v = v[0:1] + sorted(v[1:])
        >>> for line in v:
        ...   print(line)
        All new records:
          Extra index 5 in PUSH opcode index 12 in Fred
          Implicit zero for RP2 used at opcode index 9 in George
          Implicit zero for storage location 20 used at opcode index 18 in George
        >>> f.close()
        
        >>> f = utilities.debugStream()
        >>> g1.pprint_changes(g2)
        Added records:
          Extra index 5 in PUSH opcode index 12 in Fred
        Deleted records:
          Extra index 6 in PUSH opcode index 12 in Fred
        """

        p = pp.PP(**kwArgs)

        if not prior:
            p.setlike_deep(self, label="All new records")
        else:
            p.diff_setlike_deep(self, prior)
Exemple #19
0
    def pprint_changes(self, prior, **kwArgs):
        """
        Prints nothing if the two objects are equal. Otherwise prints what's
        changed.
        
        >>> dc = DistanceColor()
        >>> dc2 = DistanceColor.fromargs(gray=C([T(32, 96, 64)], 64))
        >>> dc2.pprint_changes(dc, label="Summary of changes")
        Summary of changes:
          Gray distance changed from Singles: [0.0] to Singles: [0.5]
        >>> dc2.pprint_changes(dc, label="The Data", keys=('white',))
        """

        p = pp.PP(**kwArgs)
        dSelf = self.__dict__
        dPrior = prior.__dict__
        kd = self.keyData

        for k in kwArgs.get('keys', self.sortedKeys):
            selfValue = dSelf[k]
            priorValue = dPrior[k]

            if selfValue != priorValue:
                p.diff(selfValue, priorValue, kd[k])
Exemple #20
0
    def pprint(self, **kwArgs):
        """
        Pretty-prints the object to the specified stream. Three keyword
        arguments are used:
        
            indent      How many spaces to indent on left (default 0)
            keys        Which keys to report (default all)
            stream      Stream to receive output (default sys.stdout)
        
        >>> s = Statistics()
        >>> he = _makeFakeHistoryEntry_push("fake hint object", 2, 14)
        >>> s.addHistory('aa', 253, he)
        >>> s.addHistory('contour', (1, 4), he)
        >>> s.addHistory('cvt', 215, he)
        >>> s.addHistory('debug', 12, he)
        >>> s.addHistory('function', 82, he)
        >>> s.addHistory('point', (1, 15), he)
        >>> s.addHistory('refPt', (0, 19), he)
        >>> s.addHistory('storage', 18, he)
        >>> s.addHistory('zone', 1, he)
        >>> s.pprint()
        Maxima values:
          Highest CVT index referred to: 215
          Highest function number referred to: 82
          Byte size of the binary hints: (no data)
          Highest point index in the glyph zone: 15
          Highest moved point index in the glyph zone: (no data)
          Deepest stack attained: (no data)
          Highest storage index referred to: 18
          Highest point index in the twilight zone: 19
        History for AA opcodes:
          253: Extra index 14 in PUSH opcode index 2 in fake hint object
        History for SHC contours (glyph zone):
          4: Extra index 14 in PUSH opcode index 2 in fake hint object
        History for CVT values:
          215: Extra index 14 in PUSH opcode index 2 in fake hint object
        History for DEBUG opcodes:
          12: Extra index 14 in PUSH opcode index 2 in fake hint object
        History for function calls:
          82: Extra index 14 in PUSH opcode index 2 in fake hint object
        History for outline points (glyph zone):
          15: Extra index 14 in PUSH opcode index 2 in fake hint object
        History for reference points (twilight zone):
          19: Extra index 14 in PUSH opcode index 2 in fake hint object
        History for storage locations:
          18: Extra index 14 in PUSH opcode index 2 in fake hint object
        History for SHZ zones:
          1: Extra index 14 in PUSH opcode index 2 in fake hint object
        >>> s.pprint(keys=('function', 'aa'))
        History for function calls:
          82: Extra index 14 in PUSH opcode index 2 in fake hint object
        History for AA opcodes:
          253: Extra index 14 in PUSH opcode index 2 in fake hint object
        """

        p = pp.PP(**kwArgs)
        d = self.__dict__
        kd = self.keyData

        for k in kwArgs.get('keys', self.printOrderKeys):
            value = d[k]

            if value:
                t = kd[k]
                t[KEYPPRINT](p, value, label=t[KEYLABEL])