/usr/share/pyshared/vsgui/utils.py is in python-vsgui 0.3.3-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 | import os
import warnings
import functools
# enable to show warring
warnings.simplefilter('default')
def deprecated(replacement=None):
"""This is a decorator which can be used to mark functions
as deprecated. It will result in a warning being emitted
when the function is used.
ref:
- recipe-391367-1 on active stack code
- recipe-577819-1 on active stack code
@replacement function replacement function
"""
def wrapper(old_func):
wrapped_func = replacement and replacement or old_func
@functools.wraps(wrapped_func)
def new_func(*args, **kwargs):
msg = "Call to deprecated function %(funcname)s." % {
'funcname': old_func.__name__}
if replacement:
msg += "; use {} instead".format(replacement.__name__)
warnings.warn_explicit(msg,
category=DeprecationWarning,
filename=old_func.func_code.co_filename,
lineno=old_func.func_code.co_firstlineno + 1
)
return wrapped_func(*args, **kwargs)
return new_func
return wrapper
def parse_kwds(kwds, extra):
"""parse options from kwds
@return filtered kwds, options
"""
opts = {}
for k in extra:
opts[k] = kwds.get(k)
try:
del(kwds[k])
except KeyError:
pass
return kwds, opts
def savefile(filename, content, backup='.bak'):
"""save file
@param filename path of filename
@param content content of file
@param backup extention of backup filename, default is .bak (optional)
"""
if backup:
os.system("cp %s %s%s" % (filename, filename, backup))
with open(filename, 'r') as old:
oldstr = old.read()
with open(filename, 'w') as new:
newstr = content
if newstr != oldstr:
new.write(newstr)
if __name__ == '__main__':
kwds = {'save':True,'nono':'oo'}
print parse_kwds(kwds, ['save'])
|