Passed
Push — main ( a9a03d...3a643b )
by Sat CFDI
01:46
created

satdigitalinvoice.utils.to_uuid()   A

Complexity

Conditions 2

Size

Total Lines 5
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 2
nop 1
1
import base64
2
import logging
3
import random
4
from uuid import UUID
5
from satdigitalinvoice import __version__
6
7
logger = logging.getLogger(__name__)
8
9
10
def to_uuid(s):
11
    try:
12
        return UUID(s)
13
    except ValueError:
14
        return None
15
16
17
def random_string():
18
    hash = random.randbytes(32)
19
    res = base64.urlsafe_b64encode(hash).decode()
20
    return res.rstrip("=")
21
22
23
def add_file_handler():
24
    fh = logging.FileHandler(
25
        f'.data/{__version__.__package__}.error.log',
26
        mode='a'
27
    )
28
    fh.setLevel(logging.ERROR)
29
    formatter = logging.Formatter('%(asctime)s - %(message)s')
30
    fh.setFormatter(formatter)
31
    logger.addHandler(fh)
32