Skip to content
This repository has been archived by the owner on Apr 23, 2021. It is now read-only.

Commit

Permalink
Merge branch 'v0.6' into release-0.6.1
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanoborini committed Mar 10, 2017
2 parents 43e24ee + 633d746 commit 532f666
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 3 deletions.
7 changes: 6 additions & 1 deletion scripts/validation.template
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# This file is copied and renamed in simphony/cuds/meta/ to support the
# meta classes in performing validation
import warnings

import re
import numpy


Expand Down Expand Up @@ -43,6 +43,11 @@ def without_cuba_prefix(string):
return string


def is_cuba_key(value):
"""True if value is a qualified cuba key"""
return isinstance(value, (str, unicode)) and value.startswith("CUBA.")


def check_valid_shape(value, shape, cuba_key):
""" Check if `value` is a sequence that comply with `shape`.
Note that the cuba data dimensionality is also taken into account.
Expand Down
45 changes: 43 additions & 2 deletions simphony/cuds/meta/validation.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,51 @@
# This file is copied and renamed in simphony/cuds/meta/ to support the
# meta classes in performing validation
import warnings

import re
import numpy

from scripts.utils import to_camel_case, without_cuba_prefix

def to_camel_case(text, special={'cuds': 'CUDS'}):
""" Convert text to CamelCase (for class name)
Parameters
----------
text : str
The text to be converted
special : dict
If any substring of text (lower case) matches a key of `special`,
the substring is replaced by the value
Returns
-------
result : str
"""

def replace_func(matched):
# word should be lower case already
word = matched.group(0).strip("_")
if word in special:
# Handle special case
return special[word]
else:
# Capitalise the first character
return word[0].upper() + word[1:]

return re.sub(r'(_?[a-zA-Z]+)', replace_func, text.lower())


def without_cuba_prefix(string):
"""Removes the CUBA. prefix to the string if there."""
if is_cuba_key(string):
return string[5:]

return string


def is_cuba_key(value):
"""True if value is a qualified cuba key"""
return isinstance(value, (str, unicode)) and value.startswith("CUBA.")


def check_valid_shape(value, shape, cuba_key):
Expand Down

0 comments on commit 532f666

Please sign in to comment.