This repository was archived by the owner on Apr 23, 2021. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +49
-3
lines changed
Expand file tree Collapse file tree 2 files changed +49
-3
lines changed Original file line number Diff line number Diff line change 11# This file is copied and renamed in simphony/cuds/meta/ to support the
22# meta classes in performing validation
33import warnings
4-
4+ import re
55import numpy
66
77
@@ -43,6 +43,11 @@ def without_cuba_prefix(string):
4343 return string
4444
4545
46+ def is_cuba_key(value):
47+ """True if value is a qualified cuba key"""
48+ return isinstance(value, (str, unicode)) and value.startswith("CUBA.")
49+
50+
4651def check_valid_shape(value, shape, cuba_key):
4752 """ Check if `value` is a sequence that comply with `shape`.
4853 Note that the cuba data dimensionality is also taken into account.
Original file line number Diff line number Diff line change 11# This file is copied and renamed in simphony/cuds/meta/ to support the
22# meta classes in performing validation
33import warnings
4-
4+ import re
55import numpy
66
7- from scripts .utils import to_camel_case , without_cuba_prefix
7+
8+ def to_camel_case (text , special = {'cuds' : 'CUDS' }):
9+ """ Convert text to CamelCase (for class name)
10+
11+ Parameters
12+ ----------
13+ text : str
14+ The text to be converted
15+
16+ special : dict
17+ If any substring of text (lower case) matches a key of `special`,
18+ the substring is replaced by the value
19+
20+ Returns
21+ -------
22+ result : str
23+ """
24+
25+ def replace_func (matched ):
26+ # word should be lower case already
27+ word = matched .group (0 ).strip ("_" )
28+ if word in special :
29+ # Handle special case
30+ return special [word ]
31+ else :
32+ # Capitalise the first character
33+ return word [0 ].upper () + word [1 :]
34+
35+ return re .sub (r'(_?[a-zA-Z]+)' , replace_func , text .lower ())
36+
37+
38+ def without_cuba_prefix (string ):
39+ """Removes the CUBA. prefix to the string if there."""
40+ if is_cuba_key (string ):
41+ return string [5 :]
42+
43+ return string
44+
45+
46+ def is_cuba_key (value ):
47+ """True if value is a qualified cuba key"""
48+ return isinstance (value , (str , unicode )) and value .startswith ("CUBA." )
849
950
1051def check_valid_shape (value , shape , cuba_key ):
You can’t perform that action at this time.
0 commit comments