comparison planemo/lib/python3.7/site-packages/distlib/_backport/misc.py @ 0:d30785e31577 draft

"planemo upload commit 6eee67778febed82ddd413c3ca40b3183a3898f1"
author guerler
date Fri, 31 Jul 2020 00:18:57 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:d30785e31577
1 # -*- coding: utf-8 -*-
2 #
3 # Copyright (C) 2012 The Python Software Foundation.
4 # See LICENSE.txt and CONTRIBUTORS.txt.
5 #
6 """Backports for individual classes and functions."""
7
8 import os
9 import sys
10
11 __all__ = ['cache_from_source', 'callable', 'fsencode']
12
13
14 try:
15 from imp import cache_from_source
16 except ImportError:
17 def cache_from_source(py_file, debug=__debug__):
18 ext = debug and 'c' or 'o'
19 return py_file + ext
20
21
22 try:
23 callable = callable
24 except NameError:
25 from collections import Callable
26
27 def callable(obj):
28 return isinstance(obj, Callable)
29
30
31 try:
32 fsencode = os.fsencode
33 except AttributeError:
34 def fsencode(filename):
35 if isinstance(filename, bytes):
36 return filename
37 elif isinstance(filename, str):
38 return filename.encode(sys.getfilesystemencoding())
39 else:
40 raise TypeError("expect bytes or str, not %s" %
41 type(filename).__name__)