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

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

13 statements  

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']