|
2 | 2 |
|
3 | 3 | from .any import Any |
4 | 4 | from .duration import Duration |
| 5 | +from .google_values import ( |
| 6 | + BoolValue, |
| 7 | + BytesValue, |
| 8 | + DoubleValue, |
| 9 | + FloatValue, |
| 10 | + Int32Value, |
| 11 | + Int64Value, |
| 12 | + StringValue, |
| 13 | + UInt32Value, |
| 14 | + UInt64Value, |
| 15 | +) |
5 | 16 | from .timestamp import Timestamp |
6 | 17 |
|
7 | 18 | # For each (package, message name), lists the methods that should be added to the message definition. |
8 | 19 | # The source code of the method is read from the `known_types` folder. If imports are needed, they can be directly added |
9 | 20 | # to the template file: they will automatically be removed if not necessary. |
10 | 21 | KNOWN_METHODS: dict[tuple[str, str], list[Callable]] = { |
11 | 22 | ("google.protobuf", "Any"): [Any.pack, Any.unpack, Any.to_dict], |
12 | | - ("google.protobuf", "Timestamp"): [Timestamp.from_datetime, Timestamp.to_datetime, Timestamp.timestamp_to_json], |
13 | | - ("google.protobuf", "Duration"): [Duration.from_timedelta, Duration.to_timedelta, Duration.delta_to_json], |
| 23 | + ("google.protobuf", "Timestamp"): [ |
| 24 | + Timestamp.from_datetime, |
| 25 | + Timestamp.to_datetime, |
| 26 | + Timestamp.timestamp_to_json, |
| 27 | + Timestamp.from_dict, |
| 28 | + Timestamp.to_dict, |
| 29 | + Timestamp.from_wrapped, |
| 30 | + Timestamp.to_wrapped, |
| 31 | + ], |
| 32 | + ("google.protobuf", "Duration"): [ |
| 33 | + Duration.from_timedelta, |
| 34 | + Duration.to_timedelta, |
| 35 | + Duration.delta_to_json, |
| 36 | + Duration.from_dict, |
| 37 | + Duration.to_dict, |
| 38 | + Duration.from_wrapped, |
| 39 | + Duration.to_wrapped, |
| 40 | + ], |
| 41 | + ("google.protobuf", "BoolValue"): [ |
| 42 | + BoolValue.from_dict, |
| 43 | + BoolValue.to_dict, |
| 44 | + BoolValue.from_wrapped, |
| 45 | + BoolValue.to_wrapped, |
| 46 | + ], |
| 47 | + ("google.protobuf", "Int32Value"): [ |
| 48 | + Int32Value.from_dict, |
| 49 | + Int32Value.to_dict, |
| 50 | + Int32Value.from_wrapped, |
| 51 | + Int32Value.to_wrapped, |
| 52 | + ], |
| 53 | + ("google.protobuf", "Int64Value"): [ |
| 54 | + Int64Value.from_dict, |
| 55 | + Int64Value.to_dict, |
| 56 | + Int64Value.from_wrapped, |
| 57 | + Int64Value.to_wrapped, |
| 58 | + ], |
| 59 | + ("google.protobuf", "UInt32Value"): [ |
| 60 | + UInt32Value.from_dict, |
| 61 | + UInt32Value.to_dict, |
| 62 | + UInt32Value.from_wrapped, |
| 63 | + UInt32Value.to_wrapped, |
| 64 | + ], |
| 65 | + ("google.protobuf", "UInt64Value"): [ |
| 66 | + UInt64Value.from_dict, |
| 67 | + UInt64Value.to_dict, |
| 68 | + UInt64Value.from_wrapped, |
| 69 | + UInt64Value.to_wrapped, |
| 70 | + ], |
| 71 | + ("google.protobuf", "FloatValue"): [ |
| 72 | + FloatValue.from_dict, |
| 73 | + FloatValue.to_dict, |
| 74 | + FloatValue.from_wrapped, |
| 75 | + FloatValue.to_wrapped, |
| 76 | + ], |
| 77 | + ("google.protobuf", "DoubleValue"): [ |
| 78 | + DoubleValue.from_dict, |
| 79 | + DoubleValue.to_dict, |
| 80 | + DoubleValue.from_wrapped, |
| 81 | + DoubleValue.to_wrapped, |
| 82 | + ], |
| 83 | + ("google.protobuf", "StringValue"): [ |
| 84 | + StringValue.from_dict, |
| 85 | + StringValue.to_dict, |
| 86 | + StringValue.from_wrapped, |
| 87 | + StringValue.to_wrapped, |
| 88 | + ], |
| 89 | + ("google.protobuf", "BytesValue"): [ |
| 90 | + BytesValue.from_dict, |
| 91 | + BytesValue.to_dict, |
| 92 | + BytesValue.from_wrapped, |
| 93 | + BytesValue.to_wrapped, |
| 94 | + ], |
| 95 | +} |
| 96 | + |
| 97 | +# A wrapped type is the type of a message that is automatically replaced by a known Python type. |
| 98 | +WRAPPED_TYPES: dict[tuple[str, str], str] = { |
| 99 | + ("google.protobuf", "BoolValue"): "bool", |
| 100 | + ("google.protobuf", "StringValue"): "str", |
| 101 | + ("google.protobuf", "Timestamp"): "datetime.datetime", |
| 102 | + ("google.protobuf", "Duration"): "datetime.timedelta", |
14 | 103 | } |
0 commit comments