summaryrefslogtreecommitdiff
path: root/venv/lib/python3.11/site-packages/faker/utils
diff options
context:
space:
mode:
authorcyfraeviolae <cyfraeviolae>2024-04-03 03:10:44 -0400
committercyfraeviolae <cyfraeviolae>2024-04-03 03:10:44 -0400
commit6d7ba58f880be618ade07f8ea080fe8c4bf8a896 (patch)
treeb1c931051ffcebd2bd9d61d98d6233ffa289bbce /venv/lib/python3.11/site-packages/faker/utils
parent4f884c9abc32990b4061a1bb6997b4b37e58ea0b (diff)
venv
Diffstat (limited to 'venv/lib/python3.11/site-packages/faker/utils')
-rw-r--r--venv/lib/python3.11/site-packages/faker/utils/__init__.py0
-rw-r--r--venv/lib/python3.11/site-packages/faker/utils/__pycache__/__init__.cpython-311.pycbin0 -> 195 bytes
-rw-r--r--venv/lib/python3.11/site-packages/faker/utils/__pycache__/checksums.cpython-311.pycbin0 -> 1744 bytes
-rw-r--r--venv/lib/python3.11/site-packages/faker/utils/__pycache__/datasets.cpython-311.pycbin0 -> 817 bytes
-rw-r--r--venv/lib/python3.11/site-packages/faker/utils/__pycache__/decorators.cpython-311.pycbin0 -> 3037 bytes
-rw-r--r--venv/lib/python3.11/site-packages/faker/utils/__pycache__/distribution.cpython-311.pycbin0 -> 4330 bytes
-rw-r--r--venv/lib/python3.11/site-packages/faker/utils/__pycache__/loading.cpython-311.pycbin0 -> 3890 bytes
-rw-r--r--venv/lib/python3.11/site-packages/faker/utils/__pycache__/text.cpython-311.pycbin0 -> 2100 bytes
-rw-r--r--venv/lib/python3.11/site-packages/faker/utils/checksums.py23
-rw-r--r--venv/lib/python3.11/site-packages/faker/utils/datasets.py8
-rw-r--r--venv/lib/python3.11/site-packages/faker/utils/decorators.py38
-rw-r--r--venv/lib/python3.11/site-packages/faker/utils/distribution.py88
-rw-r--r--venv/lib/python3.11/site-packages/faker/utils/loading.py60
-rw-r--r--venv/lib/python3.11/site-packages/faker/utils/text.py28
14 files changed, 245 insertions, 0 deletions
diff --git a/venv/lib/python3.11/site-packages/faker/utils/__init__.py b/venv/lib/python3.11/site-packages/faker/utils/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/venv/lib/python3.11/site-packages/faker/utils/__init__.py
diff --git a/venv/lib/python3.11/site-packages/faker/utils/__pycache__/__init__.cpython-311.pyc b/venv/lib/python3.11/site-packages/faker/utils/__pycache__/__init__.cpython-311.pyc
new file mode 100644
index 0000000..7a480dd
--- /dev/null
+++ b/venv/lib/python3.11/site-packages/faker/utils/__pycache__/__init__.cpython-311.pyc
Binary files differ
diff --git a/venv/lib/python3.11/site-packages/faker/utils/__pycache__/checksums.cpython-311.pyc b/venv/lib/python3.11/site-packages/faker/utils/__pycache__/checksums.cpython-311.pyc
new file mode 100644
index 0000000..b9030a6
--- /dev/null
+++ b/venv/lib/python3.11/site-packages/faker/utils/__pycache__/checksums.cpython-311.pyc
Binary files differ
diff --git a/venv/lib/python3.11/site-packages/faker/utils/__pycache__/datasets.cpython-311.pyc b/venv/lib/python3.11/site-packages/faker/utils/__pycache__/datasets.cpython-311.pyc
new file mode 100644
index 0000000..31fa472
--- /dev/null
+++ b/venv/lib/python3.11/site-packages/faker/utils/__pycache__/datasets.cpython-311.pyc
Binary files differ
diff --git a/venv/lib/python3.11/site-packages/faker/utils/__pycache__/decorators.cpython-311.pyc b/venv/lib/python3.11/site-packages/faker/utils/__pycache__/decorators.cpython-311.pyc
new file mode 100644
index 0000000..027d48b
--- /dev/null
+++ b/venv/lib/python3.11/site-packages/faker/utils/__pycache__/decorators.cpython-311.pyc
Binary files differ
diff --git a/venv/lib/python3.11/site-packages/faker/utils/__pycache__/distribution.cpython-311.pyc b/venv/lib/python3.11/site-packages/faker/utils/__pycache__/distribution.cpython-311.pyc
new file mode 100644
index 0000000..bdcff72
--- /dev/null
+++ b/venv/lib/python3.11/site-packages/faker/utils/__pycache__/distribution.cpython-311.pyc
Binary files differ
diff --git a/venv/lib/python3.11/site-packages/faker/utils/__pycache__/loading.cpython-311.pyc b/venv/lib/python3.11/site-packages/faker/utils/__pycache__/loading.cpython-311.pyc
new file mode 100644
index 0000000..8590c9d
--- /dev/null
+++ b/venv/lib/python3.11/site-packages/faker/utils/__pycache__/loading.cpython-311.pyc
Binary files differ
diff --git a/venv/lib/python3.11/site-packages/faker/utils/__pycache__/text.cpython-311.pyc b/venv/lib/python3.11/site-packages/faker/utils/__pycache__/text.cpython-311.pyc
new file mode 100644
index 0000000..423330b
--- /dev/null
+++ b/venv/lib/python3.11/site-packages/faker/utils/__pycache__/text.cpython-311.pyc
Binary files differ
diff --git a/venv/lib/python3.11/site-packages/faker/utils/checksums.py b/venv/lib/python3.11/site-packages/faker/utils/checksums.py
new file mode 100644
index 0000000..9c06daf
--- /dev/null
+++ b/venv/lib/python3.11/site-packages/faker/utils/checksums.py
@@ -0,0 +1,23 @@
+from typing import List
+
+
+def luhn_checksum(number: float) -> int:
+ def digits_of(n: float) -> List[int]:
+ return [int(d) for d in str(n)]
+
+ digits = digits_of(number)
+ odd_digits = digits[-1::-2]
+ even_digits = digits[-2::-2]
+ checksum = 0
+ checksum += sum(odd_digits)
+ for d in even_digits:
+ checksum += sum(digits_of(d * 2))
+ return checksum % 10
+
+
+def calculate_luhn(partial_number: float) -> int:
+ """
+ Generates the Checksum using Luhn's algorithm
+ """
+ check_digit = luhn_checksum(int(partial_number) * 10)
+ return check_digit if check_digit == 0 else 10 - check_digit
diff --git a/venv/lib/python3.11/site-packages/faker/utils/datasets.py b/venv/lib/python3.11/site-packages/faker/utils/datasets.py
new file mode 100644
index 0000000..eef1a77
--- /dev/null
+++ b/venv/lib/python3.11/site-packages/faker/utils/datasets.py
@@ -0,0 +1,8 @@
+from itertools import chain
+
+from faker.typing import OrderedDictType
+
+
+def add_ordereddicts(*odicts: OrderedDictType) -> OrderedDictType:
+ items = [odict.items() for odict in odicts]
+ return OrderedDictType(chain(*items))
diff --git a/venv/lib/python3.11/site-packages/faker/utils/decorators.py b/venv/lib/python3.11/site-packages/faker/utils/decorators.py
new file mode 100644
index 0000000..43c8b1b
--- /dev/null
+++ b/venv/lib/python3.11/site-packages/faker/utils/decorators.py
@@ -0,0 +1,38 @@
+from functools import wraps
+from typing import Callable, Dict, Tuple, TypeVar
+
+from ..utils import text
+
+T = TypeVar("T")
+
+
+def slugify(fn: Callable) -> Callable:
+ @wraps(fn)
+ def wrapper(*args: Tuple[T, ...], **kwargs: Dict[str, T]) -> str:
+ return text.slugify(fn(*args, **kwargs))
+
+ return wrapper
+
+
+def slugify_domain(fn: Callable) -> Callable:
+ @wraps(fn)
+ def wrapper(*args: Tuple[T, ...], **kwargs: Dict[str, T]) -> str:
+ return text.slugify(fn(*args, **kwargs), allow_dots=True)
+
+ return wrapper
+
+
+def slugify_unicode(fn: Callable) -> Callable:
+ @wraps(fn)
+ def wrapper(*args: Tuple[T, ...], **kwargs: Dict[str, T]) -> str:
+ return text.slugify(fn(*args, **kwargs), allow_unicode=True)
+
+ return wrapper
+
+
+def lowercase(fn: Callable) -> Callable:
+ @wraps(fn)
+ def wrapper(*args: Tuple[T, ...], **kwargs: Dict[str, T]) -> str:
+ return fn(*args, **kwargs).lower()
+
+ return wrapper
diff --git a/venv/lib/python3.11/site-packages/faker/utils/distribution.py b/venv/lib/python3.11/site-packages/faker/utils/distribution.py
new file mode 100644
index 0000000..45580a5
--- /dev/null
+++ b/venv/lib/python3.11/site-packages/faker/utils/distribution.py
@@ -0,0 +1,88 @@
+import bisect
+import itertools
+
+from random import Random
+from typing import Generator, Iterable, Optional, Sequence, TypeVar
+
+from faker.generator import random as mod_random
+
+
+def random_sample(random: Optional[Random] = None) -> float:
+ if random is None:
+ random = mod_random
+ return random.uniform(0.0, 1.0)
+
+
+def cumsum(it: Iterable[float]) -> Generator[float, None, None]:
+ total: float = 0
+ for x in it:
+ total += x
+ yield total
+
+
+T = TypeVar("T")
+
+
+def choices_distribution_unique(
+ a: Sequence[T],
+ p: Optional[Sequence[float]],
+ random: Optional[Random] = None,
+ length: int = 1,
+) -> Sequence[T]:
+ # As of Python 3.7, there isn't a way to sample unique elements that takes
+ # weight into account.
+ if random is None:
+ random = mod_random
+
+ assert p is not None
+ assert len(a) == len(p)
+ assert len(a) >= length, "You can't request more unique samples than elements in the dataset."
+
+ choices = []
+ items = list(a)
+ probabilities = list(p)
+ for i in range(length):
+ cdf = tuple(cumsum(probabilities))
+ normal = cdf[-1]
+ cdf2 = [i / normal for i in cdf]
+ uniform_sample = random_sample(random=random)
+ idx = bisect.bisect_right(cdf2, uniform_sample)
+ item = items[idx]
+ choices.append(item)
+ probabilities.pop(idx)
+ items.pop(idx)
+ return choices
+
+
+def choices_distribution(
+ a: Sequence[T],
+ p: Optional[Sequence[float]],
+ random: Optional[Random] = None,
+ length: int = 1,
+) -> Sequence[T]:
+ if random is None:
+ random = mod_random
+
+ if p is not None:
+ assert len(a) == len(p)
+
+ if hasattr(random, "choices"):
+ if length == 1 and p is None:
+ return [random.choice(a)]
+ else:
+ return random.choices(a, weights=p, k=length)
+ else:
+ choices = []
+
+ if p is None:
+ p = itertools.repeat(1, len(a)) # type: ignore
+
+ cdf = list(cumsum(p)) # type: ignore
+ normal = cdf[-1]
+ cdf2 = [i / normal for i in cdf]
+ for i in range(length):
+ uniform_sample = random_sample(random=random)
+ idx = bisect.bisect_right(cdf2, uniform_sample)
+ item = a[idx]
+ choices.append(item)
+ return choices
diff --git a/venv/lib/python3.11/site-packages/faker/utils/loading.py b/venv/lib/python3.11/site-packages/faker/utils/loading.py
new file mode 100644
index 0000000..0ea54ee
--- /dev/null
+++ b/venv/lib/python3.11/site-packages/faker/utils/loading.py
@@ -0,0 +1,60 @@
+import pkgutil
+import sys
+
+from importlib import import_module
+from pathlib import Path
+from types import ModuleType
+from typing import List
+
+
+def get_path(module: ModuleType) -> str:
+ if getattr(sys, "frozen", False):
+ # frozen
+
+ if getattr(sys, "_MEIPASS", False):
+ # PyInstaller
+ lib_dir = Path(getattr(sys, "_MEIPASS"))
+ else:
+ # others
+ lib_dir = Path(sys.executable).parent / "lib"
+
+ path = lib_dir.joinpath(*module.__package__.split(".")) # type: ignore
+ else:
+ # unfrozen
+ if module.__file__ is not None:
+ path = Path(module.__file__).parent
+ else:
+ raise RuntimeError(f"Can't find path from module `{module}.")
+ return str(path)
+
+
+def list_module(module: ModuleType) -> List[str]:
+ path = get_path(module)
+
+ if getattr(sys, "_MEIPASS", False):
+ # PyInstaller
+ return [file.parent.name for file in Path(path).glob("*/__init__.py")]
+ else:
+ return [name for _, name, is_pkg in pkgutil.iter_modules([str(path)]) if is_pkg]
+
+
+def find_available_locales(providers: List[str]) -> List[str]:
+ available_locales = set()
+
+ for provider_path in providers:
+ provider_module = import_module(provider_path)
+ if getattr(provider_module, "localized", False):
+ langs = list_module(provider_module)
+ available_locales.update(langs)
+ return sorted(available_locales)
+
+
+def find_available_providers(modules: List[ModuleType]) -> List[str]:
+ available_providers = set()
+ for providers_mod in modules:
+ if providers_mod.__package__:
+ providers = [
+ ".".join([providers_mod.__package__, mod]) for mod in list_module(providers_mod) if mod != "__pycache__"
+ ]
+ available_providers.update(providers)
+ return sorted(available_providers)
diff --git a/venv/lib/python3.11/site-packages/faker/utils/text.py b/venv/lib/python3.11/site-packages/faker/utils/text.py
new file mode 100644
index 0000000..5083918
--- /dev/null
+++ b/venv/lib/python3.11/site-packages/faker/utils/text.py
@@ -0,0 +1,28 @@
+import re
+import unicodedata
+
+from typing import Pattern
+
+_re_pattern: Pattern = re.compile(r"[^\w\s-]", flags=re.U)
+_re_pattern_allow_dots: Pattern = re.compile(r"[^\.\w\s-]", flags=re.U)
+_re_spaces: Pattern = re.compile(r"[-\s]+", flags=re.U)
+
+
+def slugify(value: str, allow_dots: bool = False, allow_unicode: bool = False) -> str:
+ """
+ Converts to lowercase, removes non-word characters (alphanumerics and
+ underscores) and converts spaces to hyphens. Also strips leading and
+ trailing whitespace. Modified to optionally allow dots.
+
+ Adapted from Django 1.9
+ """
+ pattern: Pattern = _re_pattern_allow_dots if allow_dots else _re_pattern
+
+ value = str(value)
+ if allow_unicode:
+ value = unicodedata.normalize("NFKC", value)
+ value = pattern.sub("", value).strip().lower()
+ return _re_spaces.sub("-", value)
+ value = unicodedata.normalize("NFKD", value).encode("ascii", "ignore").decode("ascii")
+ value = pattern.sub("", value).strip().lower()
+ return _re_spaces.sub("-", value)