/usr/lib/python2.7/dist-packages/plumbum/lib.py is in python-plumbum 1.6.5-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 | import sys
import os
from contextlib import contextmanager
from abc import ABCMeta
import inspect
IS_WIN32 = (sys.platform == "win32")
def _setdoc(super): # @ReservedAssignment
"""This inherits the docs on the current class. Not really needed for Python 3.5,
due to new behavoir of inspect.getdoc, but still doesn't hurt."""
def deco(func):
func.__doc__ = getattr(getattr(super, func.__name__, None), "__doc__", None)
return func
return deco
class ProcInfo(object):
def __init__(self, pid, uid, stat, args):
self.pid = pid
self.uid = uid
self.stat = stat
self.args = args
def __repr__(self):
return "ProcInfo(%r, %r, %r, %r)" % (self.pid, self.uid, self.stat, self.args)
class six(object):
"""
A light-weight version of six (which works on IronPython)
"""
PY3 = sys.version_info[0] >= 3
try:
from abc import ABC
except ImportError:
from abc import ABCMeta # type: ignore
ABC = ABCMeta('ABC', (object,), {'__module__':__name__, '__slots__':()}) # type: ignore
# Be sure to use named-tuple access, so that usage is not affected
try:
getfullargspec = staticmethod(inspect.getfullargspec)
except AttributeError:
getfullargspec = staticmethod(inspect.getargspec) # extra fields will not be available
if PY3:
integer_types = (int,)
string_types = (str,)
MAXSIZE = sys.maxsize
ascii = ascii # @UndefinedVariable
bytes = bytes # @ReservedAssignment
unicode_type = str
@staticmethod
def b(s):
return s.encode("latin-1", "replace")
@staticmethod
def u(s):
return s
@staticmethod
def get_method_function(m):
return m.__func__
else:
integer_types = (int, long)
string_types = (str, unicode)
MAXSIZE = getattr(sys, "maxsize", sys.maxint)
ascii = repr # @ReservedAssignment
bytes = str # @ReservedAssignment
unicode_type = unicode
@staticmethod
def b(st):
return st
@staticmethod
def u(s):
return s.decode("unicode-escape")
@staticmethod
def get_method_function(m):
return m.im_func
str = unicode_type
# Try/except fails because io has the wrong StringIO in Python2
# You'll get str/unicode errors
if six.PY3:
from io import StringIO
else:
from StringIO import StringIO # type: ignore
@contextmanager
def captured_stdout(stdin = ""):
"""
Captures stdout (similar to the redirect_stdout in Python 3.4+, but with slightly different arguments)
"""
prevstdin = sys.stdin
prevstdout = sys.stdout
sys.stdin = StringIO(six.u(stdin))
sys.stdout = StringIO()
try:
yield sys.stdout
finally:
sys.stdin = prevstdin
sys.stdout = prevstdout
class StaticProperty(object):
"""This acts like a static property, allowing access via class or object.
This is a non-data descriptor."""
def __init__(self, function):
self._function = function
self.__doc__ = function.__doc__
def __get__(self, obj, klass=None):
return self._function()
def getdoc(object):
"""
This gets a docstring if avaiable, and cleans it, but does not look up docs in
inheritance tree (Pre 3.5 behavior of ``inspect.getdoc``).
"""
try:
doc = object.__doc__
except AttributeError:
return None
if not isinstance(doc, str):
return None
return inspect.cleandoc(doc)
def read_fd_decode_safely(fd, size=4096):
"""
This reads a utf-8 file descriptor and returns a chunck, growing up to
three bytes if needed to decode the character at the end.
Returns the data and the decoded text.
"""
data = os.read(fd.fileno(), size)
for i in range(4):
try:
return data, data.decode("utf-8")
except UnicodeDecodeError as e:
if e.reason != 'unexpected end of data':
raise
if i == 3:
raise
data += os.read(fd.fileno(), 1)
|