Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/proto/marshal/compat.py: 68%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

22 statements  

1# Copyright 2018 Google LLC 

2# 

3# Licensed under the Apache License, Version 2.0 (the "License"); 

4# you may not use this file except in compliance with the License. 

5# You may obtain a copy of the License at 

6# 

7# https://www.apache.org/licenses/LICENSE-2.0 

8# 

9# Unless required by applicable law or agreed to in writing, software 

10# distributed under the License is distributed on an "AS IS" BASIS, 

11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 

12# See the License for the specific language governing permissions and 

13# limitations under the License. 

14 

15# This file pulls in the container types from internal protocol buffers, 

16# and exports the types available. 

17# 

18# If the C extensions were not installed, then their container types will 

19# not be included. 

20 

21from google.protobuf.internal import containers 

22import google.protobuf 

23 

24PROTOBUF_VERSION = google.protobuf.__version__ 

25 

26# Import protobuf 4.xx first and fallback to earlier version 

27# if not present. 

28try: 

29 from google._upb import _message 

30except ImportError: 

31 _message = None 

32 

33if not _message: 

34 try: 

35 from google.protobuf.pyext import _message 

36 except ImportError: 

37 _message = None 

38 

39repeated_composite_types = (containers.RepeatedCompositeFieldContainer,) 

40repeated_scalar_types = (containers.RepeatedScalarFieldContainer,) 

41map_composite_types = (containers.MessageMap,) 

42 

43# In `proto/marshal.py`, for compatibility with protobuf 5.x, 

44# we'll use `map_composite_type_names` to check whether 

45# the name of the class of a protobuf type is 

46# `MessageMapContainer`, and, if `True`, return a MapComposite. 

47# See https://github.com/protocolbuffers/protobuf/issues/16596 

48map_composite_type_names = ("MessageMapContainer",) 

49 

50if _message: 

51 repeated_composite_types += (_message.RepeatedCompositeContainer,) 

52 repeated_scalar_types += (_message.RepeatedScalarContainer,) 

53 

54 # In `proto/marshal.py`, for compatibility with protobuf 5.x, 

55 # we'll use `map_composite_type_names` to check whether 

56 # the name of the class of a protobuf type is 

57 # `MessageMapContainer`, and, if `True`, return a MapComposite. 

58 # See https://github.com/protocolbuffers/protobuf/issues/16596 

59 if PROTOBUF_VERSION[0:2] in ["3.", "4."]: 

60 map_composite_types += (_message.MessageMapContainer,) 

61 

62__all__ = ( 

63 "repeated_composite_types", 

64 "repeated_scalar_types", 

65 "map_composite_types", 

66 "map_composite_type_names", 

67)