-
Notifications
You must be signed in to change notification settings - Fork 0
/
info.py
66 lines (55 loc) · 1.94 KB
/
info.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# -*- coding: ISO-8859-1 -*-
u"""
info
========
.. autoclass:: DimBase
"""
from dim import DimBase
class Info(tuple):
def __contains__(self, value):
if not isinstance(value, DimBase):
return False
for x in self:
if x.name == value.name and isinstance(x, value.__class__):
return True
return False
def get_matching_dim(self, value):
if isinstance(value, DimBase):
for x in self:
if x.name == value.name and isinstance(x, value.__class__):
return x
raise KeyError("No dim matching %r"%value)
def matching_index(self, value):
if isinstance(value, DimBase):
for idx, x in enumerate(self):
if x.name == value.name and isinstance(x, value.__class__):
return idx
raise KeyError("No dim matching %r"%value)
class InfoList(list):
def __contains__(self, value):
if not isinstance(value, DimBase):
return False
for x in self:
if x.name == value.name and isinstance(x, value.__class__):
return True
return False
def get_matching_dim(self, value):
if isinstance(value, DimBase):
for x in self:
if x.name == value.name and isinstance(x, value.__class__):
return x
raise KeyError("No dim matching %r"%value)
def matching_index(self, value):
if isinstance(value, DimBase):
for idx, x in enumerate(self):
if x.name == value.name and isinstance(x, value.__class__):
return idx
raise KeyError("No dim matching %r"%value)
def replace_dim(info, olddim, newdim):
out = []
for d in info:
if olddim.name == d.name:
out.append(newdim)
else:
out.append(d)
return Info(out)