X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=osm_ro%2Futils.py;h=2ae062fd7e23a6cc64786aced12bbd169c757e1e;hb=6082b7d161e7ccfbb38c1b7938c88c2619b8f690;hp=00f6f2d200947692cfe64da9636f928ef39d5329;hpb=05a8b7bc29197345f9718796c110d6cf3c2ad176;p=osm%2FRO.git diff --git a/osm_ro/utils.py b/osm_ro/utils.py index 00f6f2d2..2ae062fd 100644 --- a/osm_ro/utils.py +++ b/osm_ro/utils.py @@ -30,6 +30,7 @@ __author__="Alfonso Tierno, Gerardo Garcia" __date__ ="$08-sep-2014 12:21:22$" import datetime +import warnings from jsonschema import validate as js_v, exceptions as js_e #from bs4 import BeautifulSoup @@ -178,4 +179,32 @@ def check_valid_uuid(uuid): except js_e.ValidationError: return False return False - + + +def expand_brackets(text): + """ + Change a text with TEXT[ABC..] into a list with [TEXTA, TEXTB, TEXC, ... + if no bracket is used it just return the a list with the single text + It uses recursivity to allow several [] in the text + :param text: + :return: + """ + start = text.find("[") + end = text.find("]") + if start < 0 or end < 0: + return [text] + text_list = [] + for char in text[start+1:end]: + text_list += expand_brackets(text[:start] + char + text[end+1:]) + return text_list + +def deprecated(message): + def deprecated_decorator(func): + def deprecated_func(*args, **kwargs): + warnings.warn("{} is a deprecated function. {}".format(func.__name__, message), + category=DeprecationWarning, + stacklevel=2) + warnings.simplefilter('default', DeprecationWarning) + return func(*args, **kwargs) + return deprecated_func + return deprecated_decorator \ No newline at end of file