Completed
Push — master ( 8fc5fd...8beaf7 )
by Oleksandr
01:19
created

isotopic_logging.generate_oid()   A

Complexity

Conditions 1

Size

Total Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1
Metric Value
cc 1
dl 0
loc 2
ccs 2
cts 2
cp 1
crap 1
rs 10
1
# -*- coding: utf-8 -*-
2
3 1
import uuid
4
5 1
from .defaults import OID_LENGTH, OID_MAX_LENGTH
6 1
from .concurrency import threadsafe_iter
7
8
9 1
def generate_uuid_based_oid(length=None):
10
    """
11
    OID generator which uses uuid.uuid4 (random UUIDs) to produce result.
12
    """
13 1
    length = min(length or OID_LENGTH, OID_MAX_LENGTH)
14
15 1
    while True:
16 1
        yield uuid.uuid4().hex.upper()[:length]
17
18
19 1
generate_default_oid = generate_uuid_based_oid
20 1
default_oid_generator = threadsafe_iter(generate_default_oid())
21
22
23 1
def generate_oid(generator=None):
24
    return next(generator or default_oid_generator)
25