Updated docs
This commit is contained in:
@@ -1,21 +1,21 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
cpl-core sh-edraft Common Python library
|
||||
cpl-core CPL core
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
sh-edraft Common Python library
|
||||
CPL core package
|
||||
|
||||
:copyright: (c) 2020 - 2023 sh-edraft.de
|
||||
:license: MIT, see LICENSE for more details.
|
||||
|
||||
"""
|
||||
|
||||
__title__ = 'cpl_core.pipes'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2023 sh-edraft.de'
|
||||
__version__ = '2022.12.1'
|
||||
__title__ = "cpl_core.pipes"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2020 - 2023 sh-edraft.de"
|
||||
__version__ = "2023.2.0"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -29,5 +29,5 @@ from .pipe_abc import PipeABC
|
||||
from .to_camel_case_pipe import ToCamelCasePipe
|
||||
from .to_snake_case_pipe import ToSnakeCasePipe
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='12', micro='1')
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="2023", minor="2", micro="0")
|
||||
|
||||
@@ -2,8 +2,8 @@ from cpl_core.pipes.pipe_abc import PipeABC
|
||||
|
||||
|
||||
class BoolPipe(PipeABC):
|
||||
|
||||
def __init__(self): pass
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def transform(self, value: bool, *args):
|
||||
return 'True' if value else 'False'
|
||||
return "True" if value else "False"
|
||||
|
||||
@@ -2,19 +2,17 @@ from cpl_core.pipes.pipe_abc import PipeABC
|
||||
|
||||
|
||||
class FirstCharToLowerPipe(PipeABC):
|
||||
|
||||
def __init__(self): pass
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def transform(self, value: any, *args):
|
||||
r"""Converts first char to lower
|
||||
|
||||
Parameter
|
||||
---------
|
||||
Parameter:
|
||||
value: :class:`str`
|
||||
String to convert
|
||||
|
||||
Returns
|
||||
-------
|
||||
Returns:
|
||||
String with first char as lower
|
||||
"""
|
||||
return f'{value[0].lower()}{value[1:]}'
|
||||
return f"{value[0].lower()}{value[1:]}"
|
||||
|
||||
@@ -2,19 +2,17 @@ from cpl_core.pipes.pipe_abc import PipeABC
|
||||
|
||||
|
||||
class FirstToUpperPipe(PipeABC):
|
||||
|
||||
def __init__(self): pass
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def transform(self, value: str, *args):
|
||||
r"""Converts first char to upper
|
||||
|
||||
Parameter
|
||||
---------
|
||||
Parameter:
|
||||
chars: :class:`str`
|
||||
String to convert
|
||||
|
||||
Returns
|
||||
-------
|
||||
Returns:
|
||||
String with first char as upper
|
||||
"""
|
||||
return f'{value[0].upper()}{value[1:]}'
|
||||
return f"{value[0].upper()}{value[1:]}"
|
||||
|
||||
@@ -2,23 +2,23 @@ from cpl_core.pipes.pipe_abc import PipeABC
|
||||
|
||||
|
||||
class IPAddressPipe(PipeABC):
|
||||
|
||||
def __init__(self): pass
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def transform(self, value: list[int], *args):
|
||||
string = ""
|
||||
|
||||
if len(value) != 4:
|
||||
raise Exception('Invalid IP')
|
||||
raise Exception("Invalid IP")
|
||||
|
||||
for i in range(0, len(value)):
|
||||
byte = value[i]
|
||||
if byte > 255:
|
||||
raise Exception('Invalid IP')
|
||||
raise Exception("Invalid IP")
|
||||
|
||||
if i == len(value) - 1:
|
||||
string += f'{byte}'
|
||||
string += f"{byte}"
|
||||
else:
|
||||
string += f'{byte}.'
|
||||
string += f"{byte}."
|
||||
|
||||
return string
|
||||
|
||||
@@ -2,9 +2,10 @@ from abc import ABC, abstractmethod
|
||||
|
||||
|
||||
class PipeABC(ABC):
|
||||
@abstractmethod
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self): pass
|
||||
|
||||
@abstractmethod
|
||||
def transform(self, value: any, *args): pass
|
||||
def transform(self, value: any, *args):
|
||||
pass
|
||||
|
||||
@@ -4,25 +4,23 @@ from cpl_core.pipes import PipeABC
|
||||
|
||||
|
||||
class ToCamelCasePipe(PipeABC):
|
||||
|
||||
def __init__(self): pass
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def transform(self, value: str, *args) -> str:
|
||||
r"""Converts string to camel case
|
||||
|
||||
Parameter
|
||||
---------
|
||||
Parameter:
|
||||
chars: :class:`str`
|
||||
String to convert
|
||||
|
||||
Returns
|
||||
-------
|
||||
Returns:
|
||||
String converted to CamelCase
|
||||
"""
|
||||
converted_name = value
|
||||
char_set = string.punctuation + ' '
|
||||
char_set = string.punctuation + " "
|
||||
for char in char_set:
|
||||
if char in converted_name:
|
||||
converted_name = ''.join(word.title() for word in converted_name.split(char))
|
||||
converted_name = "".join(word.title() for word in converted_name.split(char))
|
||||
|
||||
return converted_name
|
||||
|
||||
@@ -4,26 +4,24 @@ from cpl_core.pipes import PipeABC
|
||||
|
||||
|
||||
class ToSnakeCasePipe(PipeABC):
|
||||
|
||||
def __init__(self): pass
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def transform(self, value: str, *args) -> str:
|
||||
r"""Converts string to snake case
|
||||
|
||||
Parameter
|
||||
---------
|
||||
Parameter:
|
||||
chars: :class:`str`
|
||||
String to convert
|
||||
|
||||
Returns
|
||||
-------
|
||||
Returns:
|
||||
String converted to snake_case
|
||||
"""
|
||||
# convert to train-case to CamelCase
|
||||
if '-' in value:
|
||||
value = ''.join(word.title() for word in value.split('-'))
|
||||
if "-" in value:
|
||||
value = "".join(word.title() for word in value.split("-"))
|
||||
|
||||
pattern1 = re.compile(r'(.)([A-Z][a-z]+)')
|
||||
pattern2 = re.compile(r'([a-z0-9])([A-Z])')
|
||||
file_name = re.sub(pattern1, r'\1_\2', value)
|
||||
return re.sub(pattern2, r'\1_\2', file_name).lower()
|
||||
pattern1 = re.compile(r"(.)([A-Z][a-z]+)")
|
||||
pattern2 = re.compile(r"([a-z0-9])([A-Z])")
|
||||
file_name = re.sub(pattern1, r"\1_\2", value)
|
||||
return re.sub(pattern2, r"\1_\2", file_name).lower()
|
||||
|
||||
@@ -3,15 +3,15 @@ from cpl_core.pipes.pipe_abc import PipeABC
|
||||
|
||||
|
||||
class VersionPipe(PipeABC):
|
||||
|
||||
def __init__(self): pass
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def transform(self, value: dict, *args):
|
||||
for atr in VersionSettingsNameEnum:
|
||||
if atr.value not in value:
|
||||
raise KeyError(atr.value)
|
||||
|
||||
v_str = f'{value[VersionSettingsNameEnum.major.value]}.{value[VersionSettingsNameEnum.minor.value]}'
|
||||
v_str = f"{value[VersionSettingsNameEnum.major.value]}.{value[VersionSettingsNameEnum.minor.value]}"
|
||||
if value[VersionSettingsNameEnum.micro.value] is not None:
|
||||
v_str += f'.{value[VersionSettingsNameEnum.micro.value]}'
|
||||
v_str += f".{value[VersionSettingsNameEnum.micro.value]}"
|
||||
return v_str
|
||||
|
||||
Reference in New Issue
Block a user