equal
deleted
inserted
replaced
|
1 # |
|
2 # Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 # All rights reserved. |
|
4 # This component and the accompanying materials are made available |
|
5 # under the terms of "Eclipse Public License v1.0" |
|
6 # which accompanies this distribution, and is available |
|
7 # at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 # |
|
9 # Initial Contributors: |
|
10 # Nokia Corporation - initial contribution. |
|
11 # |
|
12 # Contributors: |
|
13 # |
|
14 # Description: |
|
15 # |
|
16 |
|
17 def hex_to_bindata(hexdata): |
|
18 hexdata = hexdata.replace(' ', '').replace('\r', '').replace('\n', '').replace('\t', '') |
|
19 if len(hexdata) % 2 != 0: |
|
20 raise ValueError("'%s' is not divisible by 2", hexdata) |
|
21 for c in hexdata: |
|
22 if c not in "0123456789abcdefABCDEF": |
|
23 raise ValueError("'%s' is not a valid hex string", hexdata) |
|
24 |
|
25 temp = [] |
|
26 for i in xrange(len(hexdata) / 2): |
|
27 start = i * 2 |
|
28 end = start + 2 |
|
29 temp.append(chr(int(hexdata[start:end], 16))) |
|
30 return ''.join(temp) |