/usr/lib/python3/dist-packages/glue/helpers.py is in glue-sprite 0.11.1-2build1.
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 | import os
import sys
import contextlib
from io import StringIO
def round_up(value):
int_value = int(value)
diff = 1 if value > 0 else -1
return int_value + diff if value != int_value else int_value
def nearest_fration(value):
"""
Return the nearest fraction.
If fraction.Fraction is not available, return a fraction.
Note: used for Opera CSS pixel-ratio media queries.
"""
try:
from fraction import Fraction
return str(Fraction(value))
except ImportError:
return '%i/100' % int(float(value) * 100)
class _Missing(object):
""" Missing object necessary for cached_property"""
def __repr__(self):
return 'no value'
def __reduce__(self):
return '_missing'
_missing = _Missing()
class cached_property(object):
"""
Decorator inspired/copied from mitsuhiko/werkzeug.
A decorator that converts a function into a lazy property. The
function wrapped is called the first time to retrieve the result
and then that calculated result is used the next time you access
the value"""
def __init__(self, func, name=None, doc=None):
self.__name__ = name or func.__name__
self.__module__ = func.__module__
self.__doc__ = doc or func.__doc__
self.func = func
def __get__(self, obj, type=None):
if obj is None:
return self
value = obj.__dict__.get(self.__name__, _missing)
if value is _missing:
value = self.func(obj)
obj.__dict__[self.__name__] = value
return value
@contextlib.contextmanager
def redirect_stdout(stream=None):
stream = stream or StringIO()
sys.stdout = stream
yield
sys.stdout = sys.__stdout__
|