1 | # encoding: utf-8 |
||
2 | """ |
||
3 | __init__.py |
||
4 | |||
5 | Created by Thomas Mangin on 2015-05-15. |
||
6 | Copyright (c) 2009-2017 Exa Networks. All rights reserved. |
||
7 | License: 3-clause BSD. (See the COPYRIGHT file) |
||
8 | """ |
||
9 | |||
10 | import string |
||
11 | |||
12 | |||
13 | def hexstring(value): |
||
14 | def spaced(value): |
||
15 | for v in value: |
||
16 | yield '%02X' % v |
||
17 | |||
18 | return '0x' + ''.join(spaced(value)) |
||
19 | |||
20 | |||
21 | def hexbytes(value): |
||
22 | return bytes(hexstring(str(value, 'ascii')), 'ascii') |
||
23 | |||
24 | |||
25 | def string_is_hex(s): |
||
26 | if s[:2].lower() != '0x': |
||
27 | return False |
||
28 | if len(s) <= 2: |
||
29 | return False |
||
30 | return all(c in string.hexdigits for c in s[2:]) |
||
31 | |||
32 | |||
33 | def split(data, step): |
||
34 | return (data[i:i + step] for i in range(0, len(data), step)) |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
Loading history...
|
|||
35 |