Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/rfc3986/compat.py: 100%

10 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2023-06-07 06:04 +0000

1# Copyright (c) 2014 Rackspace 

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

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

4# You may obtain a copy of the License at 

5# 

6# http://www.apache.org/licenses/LICENSE-2.0 

7# 

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

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

10# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 

11# implied. 

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

13# limitations under the License. 

14"""Compatibility module for Python 2 and 3 support.""" 

15 

16__all__ = ( 

17 "to_bytes", 

18 "to_str", 

19) 

20 

21 

22def to_str(b, encoding="utf-8"): 

23 """Ensure that b is text in the specified encoding.""" 

24 if hasattr(b, "decode") and not isinstance(b, str): 

25 b = b.decode(encoding) 

26 return b 

27 

28 

29def to_bytes(s, encoding="utf-8"): 

30 """Ensure that s is converted to bytes from the encoding.""" 

31 if hasattr(s, "encode") and not isinstance(s, bytes): 

32 s = s.encode(encoding) 

33 return s