개정판 94ac8af8
issue #49: apply regular ex in nominal
Change-Id: Ib6d08fe2b2f6f595adfdda6bb03177789805688c
DTI_PID/DTI_PID/NominalPipeSize.py | ||
---|---|---|
65 | 65 |
''' |
66 | 66 |
|
67 | 67 |
def find(self, value, size_unit='Inch'): |
68 |
import re |
|
69 |
|
|
68 | 70 |
if size_unit.upper() == 'INCH' or size_unit.upper() == 'IMPERIAL': |
69 |
if (self.inchStr == value) or (value in self.allowable_inch_str.split(',')): |
|
71 |
# code |
|
72 |
if value == self.inchStr: |
|
70 | 73 |
return self.inchStr |
74 |
else: |
|
75 |
match = re.search(self.inchStr, value, re.DOTALL) |
|
76 |
if match and match.start() is 0 and match.end() is len(value): |
|
77 |
return value |
|
78 |
|
|
79 |
# allowable |
|
80 |
matches = [x for x in self.allowable_inch_str.split(',') if x and value == x] |
|
81 |
if matches: |
|
82 |
return self.inchStr |
|
83 |
else: |
|
84 |
if self.allowable_inch_str.split(',')[0]: |
|
85 |
match = re.search(self.allowable_inch_str.split(',')[0], value, re.DOTALL) |
|
86 |
if match and match.start() is 0 and match.end() is len(value): |
|
87 |
return self.inchStr |
|
88 |
|
|
71 | 89 |
elif size_unit.upper() == 'METRIC': |
72 |
if (self.metricStr == value) or (value in self.allowable_metric_str.split(',')): |
|
90 |
# code |
|
91 |
if value == self.metricStr: |
|
73 | 92 |
return self.metricStr |
93 |
else: |
|
94 |
match = re.search(self.metricStr, value, re.DOTALL) |
|
95 |
if match and match.start() is 0 and match.end() is len(value): |
|
96 |
return value |
|
97 |
|
|
98 |
# allowable |
|
99 |
matches = [x for x in self.allowable_metric_str.split(',') if x and value == x] |
|
100 |
if matches: |
|
101 |
return self.metricStr |
|
102 |
else: |
|
103 |
if self.allowable_metric_str.split(',')[0]: |
|
104 |
match = re.search(self.allowable_metric_str.split(',')[0], value, re.DOTALL) |
|
105 |
if match and match.start() is 0 and match.end() is len(value): |
|
106 |
return self.metricStr |
|
107 |
|
|
74 | 108 |
else: |
75 | 109 |
if (self.inchStr == value) or (value in self.allowable_inch_str.split(',')): |
76 | 110 |
return self.inchStr |
... | ... | |
80 | 114 |
|
81 | 115 |
def find_starts_with(self, value, size_unit='Inch'): |
82 | 116 |
""" find text start with """ |
117 |
import re |
|
83 | 118 |
try: |
84 | 119 |
if size_unit.upper() == 'INCH' or size_unit.upper() == 'IMPERIAL': |
120 |
# code |
|
85 | 121 |
if value.startswith(self.inchStr): |
86 | 122 |
return self.inchStr, self.inchStr |
87 | 123 |
else: |
124 |
match = re.search(self.inchStr, value, re.DOTALL) |
|
125 |
if match and match.start() is 0: |
|
126 |
return value[:match.end()], value[:match.end()] |
|
127 |
|
|
128 |
# allowable |
|
88 | 129 |
matches = [x for x in self.allowable_inch_str.split(',') if x and value.startswith(x)] |
89 |
if matches: return self.inchStr, matches[0] |
|
130 |
if matches: |
|
131 |
return self.inchStr, matches[0] |
|
132 |
else: |
|
133 |
if self.allowable_inch_str.split(',')[0]: |
|
134 |
match = re.search(self.allowable_inch_str.split(',')[0], value, re.DOTALL) |
|
135 |
if match and match.start() is 0: |
|
136 |
return self.inchStr, value[:match.end()] |
|
137 |
|
|
90 | 138 |
elif size_unit.upper() == 'METRIC': |
91 | 139 |
if value.startswith(self.metricStr): |
92 | 140 |
return self.metricStr, self.metricStr |
93 | 141 |
else: |
142 |
match = re.search(self.metricStr, value, re.DOTALL) |
|
143 |
if match and match.start() is 0: |
|
144 |
return value[:match.end()], value[:match.end()] |
|
145 |
|
|
146 |
# allowable |
|
94 | 147 |
matches = [x for x in self.allowable_metric_str.split(',') if x and value.startswith(x)] |
95 |
if matches: return self.metricStr, matches[0] |
|
148 |
if matches: |
|
149 |
return self.metricStr, matches[0] |
|
150 |
else: |
|
151 |
if self.allowable_metric_str.split(',')[0]: |
|
152 |
match = re.search(self.allowable_metric_str.split(',')[0], value, re.DOTALL) |
|
153 |
if match and match.start() is 0: |
|
154 |
return self.metricStr, value[:match.end()] |
|
155 |
|
|
96 | 156 |
else: |
97 | 157 |
if value.startswith(self.inchStr): |
98 | 158 |
return self.inchStr, self.inchStr |
내보내기 Unified diff