1
2
3
4
5
6 import os
7 import warnings
8
10 """
11 Wraps a decorator, with a deprecation warning or error
12 """
13 - def __init__(self, decorator, attr, message, warning=True):
14 self.decorator = decorator
15 self.attr = attr
16 self.message = message
17 self.warning = warning
18
20 if obj is None:
21 return self
22 self.warn()
23 return self.decorator.__get__(obj, type)
24
28
32
34 return '<Deprecated attribute %s: %r>' % (
35 self.attr,
36 self.decorator)
37
39 if not self.warning:
40 raise DeprecationWarning(
41 'The attribute %s is deprecated: %s' % (self.attr, self.message))
42 else:
43 warnings.warn(
44 'The attribute %s is deprecated: %s' % (self.attr, self.message),
45 DeprecationWarning,
46 stacklevel=3)
47
48 try:
49 import subprocess
50 subprocess.Popen
51 closefds = os.name == 'posix'
52
53 - def popen3(cmd, mode='t', bufsize=0):
54 p = subprocess.Popen(cmd, shell=True, bufsize=bufsize,
55 stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
56 close_fds=closefds)
57 p.wait()
58 return (p.stdin, p.stdout, p.stderr)
59 except ImportError:
60 subprocess = None
61 popen3 = os.popen3
62
64 if os.path.isabs(program):
65 return program
66 if os.path.dirname(program):
67 program = os.path.normpath(os.path.realpath(program))
68 return program
69 paths = os.getenv('PATH')
70 if not paths:
71 return False
72 for path in paths.split(os.pathsep):
73 filename = os.path.join(path, program)
74 if os.access(filename, os.X_OK):
75 return filename
76 return False
77