Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/pyasn1/compat/octets.py: 55%
22 statements
« prev ^ index » next coverage.py v7.3.2, created at 2023-12-08 06:40 +0000
« prev ^ index » next coverage.py v7.3.2, created at 2023-12-08 06:40 +0000
1#
2# This file is part of pyasn1 software.
3#
4# Copyright (c) 2005-2020, Ilya Etingof <etingof@gmail.com>
5# License: https://pyasn1.readthedocs.io/en/latest/license.html
6#
7from sys import version_info
9if version_info[0] <= 2:
10 int2oct = chr
11 # noinspection PyPep8
12 ints2octs = lambda s: ''.join([int2oct(x) for x in s])
13 null = ''
14 oct2int = ord
15 # TODO: refactor to return a sequence of ints
16 # noinspection PyPep8
17 octs2ints = lambda s: [oct2int(x) for x in s]
18 # noinspection PyPep8
19 str2octs = lambda x: x
20 # noinspection PyPep8
21 octs2str = lambda x: x
22 # noinspection PyPep8
23 isOctetsType = lambda s: isinstance(s, str)
24 # noinspection PyPep8
25 isStringType = lambda s: isinstance(s, (str, unicode))
26 # noinspection PyPep8
27 ensureString = str
28else:
29 ints2octs = bytes
30 # noinspection PyPep8
31 int2oct = lambda x: ints2octs((x,))
32 null = ints2octs()
33 # noinspection PyPep8
34 oct2int = lambda x: x
35 # noinspection PyPep8
36 octs2ints = lambda x: x
37 # noinspection PyPep8
38 str2octs = lambda x: x.encode('iso-8859-1')
39 # noinspection PyPep8
40 octs2str = lambda x: x.decode('iso-8859-1')
41 # noinspection PyPep8
42 isOctetsType = lambda s: isinstance(s, bytes)
43 # noinspection PyPep8
44 isStringType = lambda s: isinstance(s, str)
45 # noinspection PyPep8
46 ensureString = bytes