1414import os
1515import pathlib
1616import platform
17- import random
1817import re
19- import secrets
2018import shutil
21- import string
2219import subprocess
2320import sys
2421import threading
25- import time
2622import warnings
2723from collections .abc import Iterable
28- from hashlib import sha256
2924from os import environ , linesep
3025from pathlib import Path
3126from tempfile import mkdtemp , mktemp
3227from typing import TypeVar
3328
3429from b2sdk .v3 import (
3530 ALL_CAPABILITIES ,
36- BUCKET_NAME_CHARS_UNIQ ,
3731 EncryptionAlgorithm ,
3832 EncryptionKey ,
3933 EncryptionMode ,
4034 EncryptionSetting ,
4135 fix_windows_path_limit ,
4236)
43- from b2sdk .v3 .testing import ONE_HOUR_MILLIS , BucketManager
37+ from b2sdk .v3 .testing import ONE_HOUR_MILLIS , RNG , BucketManager
4438
4539from b2 ._internal .console_tool import Command
4640
4741logger = logging .getLogger (__name__ )
4842
4943ONE_DAY_MILLIS = ONE_HOUR_MILLIS * 24
5044
51- NODE_DESCRIPTION = f'{ platform .node ()} : { platform .platform ()} { platform .python_version ()} '
52-
53-
54- def get_seed () -> str :
55- """
56- Get seed for random number generator.
57-
58- The `WORKFLOW_ID` variable has to be set in the CI to uniquely identify
59- the current workflow (including the attempt)
60- """
61- seed = '' .join (
62- (
63- os .getenv ('WORKFLOW_ID' , secrets .token_hex (8 )),
64- NODE_DESCRIPTION ,
65- str (time .time_ns ()),
66- os .getenv ('PYTEST_XDIST_WORKER' , 'gw0' ),
67- )
68- )
69- return sha256 (seed .encode ()).hexdigest ()[:16 ]
70-
71-
72- RNG_SEED = get_seed ()
73- RNG = random .Random (RNG_SEED )
74- RNG_COUNTER = 0
75-
7645SSE_NONE = EncryptionSetting (
7746 mode = EncryptionMode .NONE ,
7847)
@@ -93,22 +62,6 @@ def get_seed() -> str:
9362)
9463
9564
96- def random_token (length : int , chars = string .ascii_letters ) -> str :
97- return '' .join (RNG .choice (chars ) for _ in range (length ))
98-
99-
100- def bucket_name_part (length : int ) -> str :
101- assert length >= 1
102- global RNG_COUNTER
103- RNG_COUNTER += 1
104- name_part = random_token (length , BUCKET_NAME_CHARS_UNIQ )
105- logger .info ('RNG_SEED: %s' , RNG_SEED )
106- logger .info ('RNG_COUNTER: %i, length: %i' , RNG_COUNTER , length )
107- logger .info ('name_part: %s' , name_part )
108- logger .info ('WORKFLOW_ID: %s' , os .getenv ('WORKFLOW_ID' ))
109- return name_part
110-
111-
11265T = TypeVar ('T' )
11366
11467
0 commit comments