99e70a41b1fc831d4a8ff391138bf5a2f1276852
[integration/test.git] / test / csit / libraries / HsfJson / hsfl.py
1 """This module contains single class, to store a sorted list."""
2 # Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3 #
4 # This program and the accompanying materials are made available under the
5 # terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 # and is available at http://www.eclipse.org/legal/epl-v10.html
7
8 __author__ = "Vratko Polak"
9 __copyright__ = "Copyright(c) 2015, Cisco Systems, Inc."
10 __license__ = "Eclipse Public License v1.0"
11 __email__ = "vrpolak@cisco.com"
12
13
14 class Hsfl(list):
15     """
16     Hashable sorted frozen list implementation stub.
17
18     Supports only __init__, __repr__ and __hash__ methods.
19     Other list methods are available, but they may break contract.
20     """
21
22     def __init__(self, *args, **kwargs):
23         """Contruct super, sort and compute repr and hash cache values."""
24         sup = super(Hsfl, self)
25         sup.__init__(*args, **kwargs)
26         sup.sort(key=repr)
27         self.__repr = repr(tuple(self))
28         self.__hash = hash(self.__repr)
29
30     def __repr__(self):
31         """Return cached repr string."""
32         return self.__repr
33
34     def __hash__(self):
35         """Return cached hash."""
36         return self.__hash