Commits
Chih-Hsuan Yen authored 1a3a1fa94e4
1 - | From 4fdad69659f15a9e62cf4f6c15c9f319276cf9b0 Mon Sep 17 00:00:00 2001 |
2 - | From: Jonas Obrist <jonas.obrist@hde.co.jp> |
3 - | Date: Tue, 6 Mar 2018 12:21:38 +0900 |
4 - | Subject: [PATCH 2/2] add support for Python 3.7 uuid module changes |
5 - | |
6 - | Python 3.7 removed uuid._uuid_generate_time. It now has |
7 - | uuid._load_system_functions and uuid._generate_time_safe. |
8 - | _generate_time_safe is set by calling _load_system_functions (subsequent |
9 - | calls to that function are no-op). This change detects the missing |
10 - | uuid._uuid_generate_time attribute and uses the new attribute/function |
11 - | if they're missing. |
12 - | --- |
13 - | freezegun/api.py | 14 +++++++++++--- |
14 - | 1 file changed, 11 insertions(+), 3 deletions(-) |
15 - | |
16 - | diff --git freezegun/api.py freezegun/api.py |
17 - | index eb09932..a88a392 100644 |
18 - | --- freezegun/api.py |
19 - | +++ freezegun/api.py |
20 - | |
21 - | |
22 - | try: |
23 - | real_uuid_generate_time = uuid._uuid_generate_time |
24 - | -except (AttributeError, ImportError): |
25 - | + uuid_generate_time_attr = '_uuid_generate_time' |
26 - | +except AttributeError: |
27 - | + uuid._load_system_functions() |
28 - | + real_uuid_generate_time = uuid._generate_time_safe |
29 - | + uuid_generate_time_attr = '_generate_time_safe' |
30 - | +except ImportError: |
31 - | real_uuid_generate_time = None |
32 - | + uuid_generate_time_attr = None |
33 - | |
34 - | try: |
35 - | real_uuid_create = uuid._UuidCreate |
36 - | |
37 - | time.localtime = fake_localtime |
38 - | time.gmtime = fake_gmtime |
39 - | time.strftime = fake_strftime |
40 - | - uuid._uuid_generate_time = None |
41 - | + if uuid_generate_time_attr: |
42 - | + setattr(uuid, uuid_generate_time_attr, None) |
43 - | uuid._UuidCreate = None |
44 - | uuid._last_timestamp = None |
45 - | |
46 - | |
47 - | time.localtime = time.localtime.previous_localtime_function |
48 - | time.strftime = time.strftime.previous_strftime_function |
49 - | |
50 - | - uuid._uuid_generate_time = real_uuid_generate_time |
51 - | + if uuid_generate_time_attr: |
52 - | + setattr(uuid, uuid_generate_time_attr, real_uuid_generate_time) |
53 - | uuid._UuidCreate = real_uuid_create |
54 - | uuid._last_timestamp = None |
55 - |