Use voussoirkit.stringtools for pascal_to_loudsnakes.

This commit is contained in:
voussoir 2020-11-15 21:07:05 -08:00
parent f08df6266f
commit 9e6f8041fb

View file

@ -1,13 +1,4 @@
import re from voussoirkit import stringtools
def pascal_to_loudsnakes(text):
'''
NoSuchPhoto -> NO_SUCH_PHOTO
'''
text = re.sub(r'([a-z])([A-Z])', r'\1_\2', text)
text = re.sub(r'([A-Z]+)([A-Z][a-z])', r'\1_\2', text)
text = text.upper()
return text
class ErrorTypeAdder(type): class ErrorTypeAdder(type):
''' '''
@ -23,7 +14,7 @@ class ErrorTypeAdder(type):
''' '''
def __init__(cls, name, bases, clsdict): def __init__(cls, name, bases, clsdict):
type.__init__(cls, name, bases, clsdict) type.__init__(cls, name, bases, clsdict)
cls.error_type = pascal_to_loudsnakes(name) cls.error_type = stringtools.pascal_to_loudsnakes(name)
class EtiquetteException(Exception, metaclass=ErrorTypeAdder): class EtiquetteException(Exception, metaclass=ErrorTypeAdder):
''' '''