示例#1
0
文件: common.py 项目: MacLeek/mh
 def __init__(self, name, start_quote = '"', end_quote = None,
              esc_char = '\\', encoding = None, allow_eof = False):
     Construct.__init__(self, name)
     if end_quote is None:
         end_quote = start_quote
     self.start_quote = Literal(start_quote)
     self.char = Char("char")
     self.end_quote = end_quote
     self.esc_char = esc_char
     self.encoding = encoding
     self.allow_eof = allow_eof
示例#2
0
 def __init__(self, name = None, show_stream = True, 
              show_context = True, show_stack = True, 
              stream_lookahead = 100):
     Construct.__init__(self, None)
     if name is None:
         Probe.counter += 1
         name = "<unnamed %d>" % (Probe.counter,)
     self.printname = name
     self.show_stream = show_stream
     self.show_context = show_context
     self.show_stack = show_stack
     self.stream_lookahead = stream_lookahead
 def __init__(self,
              name=None,
              show_stream=True,
              show_context=True,
              show_stack=True,
              stream_lookahead=100):
     Construct.__init__(self, None)
     if name is None:
         Probe.counter += 1
         name = "<unnamed %d>" % (Probe.counter, )
     self.printname = name
     self.show_stream = show_stream
     self.show_context = show_context
     self.show_stack = show_stack
     self.stream_lookahead = stream_lookahead
示例#4
0
def test_size_at_most_validate(max_size, num, acceptable):
    """
    :py:meth:`SizeAtMost._validate` enforces its maximum size
    inclusively when encoding numbers.
    """
    bounded = SizeAtMost(Construct(name="test"), max_size=max_size)
    if acceptable:
        assert bounded._validate(num, context=object())
    else:
        assert not bounded._validate(num, context=object())
示例#5
0
 def bytes_adapted(self):
     """
     A :py:class:`tls._common._constructs.BytesAdapter` that adapts a
     trivial :py:func:`construct.Construct`.
     """
     return BytesAdapter(Construct(name=None))
示例#6
0
 def test_decode(self, byte, number):
     ubint24 = _UBInt24(Construct(name="test"))
     assert ubint24._decode(byte, context=object()) == number
示例#7
0
 def test_encode(self, byte, number):
     ubint24 = _UBInt24(Construct(name="test"))
     assert ubint24._encode(number, context=stub()) == byte