Package restkit :: Package util :: Module misc
[hide private]
[frames] | no frames]

Source Code for Module restkit.util.misc

 1  # -*- coding: utf-8 - 
 2  # 
 3  # This file is part of restkit released under the MIT license.  
 4  # See the NOTICE for more information. 
 5   
 6  import os 
 7  import warnings 
 8   
9 -class deprecated_property(object):
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
19 - def __get__(self, obj, type=None):
20 if obj is None: 21 return self 22 self.warn() 23 return self.decorator.__get__(obj, type)
24
25 - def __set__(self, obj, value):
26 self.warn() 27 self.decorator.__set__(obj, value)
28
29 - def __delete__(self, obj):
30 self.warn() 31 self.decorator.__delete__(obj)
32
33 - def __repr__(self):
34 return '<Deprecated attribute %s: %r>' % ( 35 self.attr, 36 self.decorator)
37
38 - def warn(self):
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:#python 2.6, use subprocess 49 import subprocess 50 subprocess.Popen # trigger ImportError early 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
63 -def locate_program(program):
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