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

Commit

Permalink
Revert relocation of validation support code to the module itself
Browse files Browse the repository at this point in the history
(cherry picked from commit af44d44)
  • Loading branch information
stefanoborini committed Mar 10, 2017
1 parent 876cca6 commit 1198886
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion scripts/validation.template
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,43 @@ import warnings

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 check_valid_shape(value, shape, cuba_key):
Expand Down

0 comments on commit 1198886

Please sign in to comment.