0
|
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 |
from struct import pack, unpack
|
|
18 |
from hcrplugin.hcr_exceptions import InvalidHcrHeaderError
|
|
19 |
|
|
20 |
class HcrHeader(object):
|
|
21 |
"""
|
|
22 |
"""
|
|
23 |
HEADER_FMT = '<4sHHIII12x'
|
|
24 |
HEADER_SIGNATURE = 'HCRf'
|
|
25 |
def __init__(self):
|
|
26 |
self.version = 0
|
|
27 |
self.flags = 0
|
|
28 |
self.nrecords = 0
|
|
29 |
self.lsd_offset = 0
|
|
30 |
self.lsd_size = 0
|
|
31 |
|
|
32 |
def loads(self, headerstr):
|
|
33 |
if len(headerstr) != 32:
|
|
34 |
raise InvalidHcrHeaderError('Invalid length of header data %r' % headerstr)
|
|
35 |
|
|
36 |
result = unpack(self.HEADER_FMT, headerstr)
|
|
37 |
if not result[0] == self.HEADER_SIGNATURE:
|
|
38 |
raise InvalidHcrHeaderError('Invalid HCR signature in %r' % headerstr)
|
|
39 |
self.version = result[1]
|
|
40 |
self.flags = result[2]
|
|
41 |
self.nrecords = result[3]
|
|
42 |
self.lsd_offset = result[4]
|
|
43 |
self.lsd_size = result[5]
|
|
44 |
|
|
45 |
|
|
46 |
def dumps(self):
|
|
47 |
return pack(self.HEADER_FMT, self.HEADER_SIGNATURE, self.version,
|
|
48 |
self.flags,
|
|
49 |
self.nrecords,
|
|
50 |
self.lsd_offset,
|
|
51 |
self.lsd_size) |