X-Git-Url: https://osm.etsi.org/gitweb/?a=blobdiff_plain;f=osm_ro%2Futils.py;h=0ee8efcbf5b6cda1b9673dd4e53dff933c937587;hb=20a608ce0d4a849f30d7125cf1dd63e81dc8cccc;hp=00f6f2d200947692cfe64da9636f928ef39d5329;hpb=2c290ca4088492a3c32bb6ab218d0004da68f6ea;p=osm%2FRO.git diff --git a/osm_ro/utils.py b/osm_ro/utils.py index 00f6f2d2..0ee8efcb 100644 --- a/osm_ro/utils.py +++ b/osm_ro/utils.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- ## -# Copyright 2015 Telefónica Investigación y Desarrollo, S.A.U. +# Copyright 2015 Telefonica Investigacion y Desarrollo, S.A.U. # This file is part of openmano # All Rights Reserved. # @@ -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