Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/past/types/basestring.py: 100%

12 statements  

« prev     ^ index     » next       coverage.py v7.3.1, created at 2023-09-25 06:53 +0000

1""" 

2An implementation of the basestring type for Python 3 

3 

4Example use: 

5 

6>>> s = b'abc' 

7>>> assert isinstance(s, basestring) 

8>>> from past.types import str as oldstr 

9>>> s2 = oldstr(b'abc') 

10>>> assert isinstance(s2, basestring) 

11 

12""" 

13 

14import sys 

15 

16from past.utils import with_metaclass, PY2 

17 

18if PY2: 

19 str = unicode 

20 

21ver = sys.version_info[:2] 

22 

23 

24class BaseBaseString(type): 

25 def __instancecheck__(cls, instance): 

26 return isinstance(instance, (bytes, str)) 

27 

28 def __subclasscheck__(cls, subclass): 

29 return super(BaseBaseString, cls).__subclasscheck__(subclass) or issubclass(subclass, (bytes, str)) 

30 

31 

32class basestring(with_metaclass(BaseBaseString)): 

33 """ 

34 A minimal backport of the Python 2 basestring type to Py3 

35 """ 

36 

37 

38__all__ = ['basestring']