本文整理汇总了Python中kmip.core.primitives.Base类的典型用法代码示例。如果您正苦于以下问题:Python Base类的具体用法?Python Base怎么用?Python Base使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Base类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_read
def test_read(self):
self.stream.write(b'\x42\x00\x00\x00\x00\x00\x00\x04')
base = Base()
base.length = 4
# Check no exception thrown
base.read(self.stream)
示例2: test_read_tag
def test_read_tag(self):
encoding = (b'\x42\x00\x00')
base = Base()
self.stream = BytearrayStream(encoding)
# Check no exception thrown
base.read_tag(self.stream)
示例3: test_read_length_overflow
def test_read_length_overflow(self):
self.stream.write(b'\x00\x00\x00\x04\x00')
base = Base()
base.length = 4
# Check no exception thrown
base.read_length(self.stream)
示例4: test_read_length_underflow
def test_read_length_underflow(self):
self.stream.write(b'\x00')
base = Base()
base.length = 4
self.assertRaises(errors.ReadValueError, base.read_length,
self.stream)
示例5: test_write_type
def test_write_type(self):
encoding = b'\x00'
base = Base()
base.write_type(self.stream)
result = self.stream.read()
len_exp = len(encoding)
len_rcv = len(result)
self.assertEqual(len_exp, len_rcv,
self.bad_write.format('type',
'{0} bytes'.format(len_exp),
'{0} bytes'.format(len_rcv)))
self.assertEqual(encoding, result, self.bad_encoding.format('type'))
示例6: test_is_tag_next_invalid
def test_is_tag_next_invalid(self):
encoding = (b'\x42\x00\x01')
base = Base()
self.stream = BytearrayStream(encoding)
self.assertFalse(Base.is_tag_next(base.tag, self.stream),
self.bad_match.format('tag', 'mismatch', 'match'))
示例7: process
def process(self, istream, ostream):
stream = istream.read()
if Base.is_tag_next(Tags.REQUEST_MESSAGE, stream):
message = RequestMessage()
message.read(stream)
try:
result = self._process_request(message)
except Exception as e:
raise e
tstream = BytearrayStream()
result.write(tstream)
ostream.write(tstream.buffer)
elif Base.is_tag_next(Tags.RESPONSE_MESSAGE, stream):
message = ResponseMessage()
message.read(stream)
self._process_response(message)
else:
raise ValueError('Processing error: stream contains unknown '
'message type')
示例8: test_read_type
def test_read_type(self):
self.stream.write(b'\x00')
base = Base()
# Check no exception thrown
base.read_type(self.stream)
示例9: test_is_oversized
def test_is_oversized(self):
base = Base()
# Check no exception thrown
base.is_oversized(self.stream)
示例10: test_write_length_invalid
def test_write_length_invalid(self):
base = Base()
base.length = ''
self.assertRaises(TypeError, base.write_length, self.stream)
示例11: test_write_type_invalid
def test_write_type_invalid(self):
base = Base()
base.type = ''
self.assertRaises(TypeError, base.write_type, self.stream)