/usr/lib/python3/dist-packages/leather/utils.py is in python3-leather 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 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 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 | #!/usr/bin/env python
from collections import namedtuple
from datetime import date, datetime, timedelta
from decimal import Decimal
import math
import sys
import warnings
import six
try:
__IPYTHON__
from IPython.display import SVG as IPythonSVG
except (NameError, ImportError):
IPythonSVG = lambda x: x
# Shorthand
ZERO = Decimal('0')
NINE_PLACES = Decimal('1e-9')
#: X data dimension index
X = 0
#: Y data dimension index
Y = 1
#: Z data dimension index
Z = 2
DIMENSION_NAMES = ['X', 'Y', 'Z']
#: Data structure for representing margins or other CSS-edge like properties
Box = namedtuple('Box', ['top', 'right', 'bottom', 'left'])
#: Data structure for a single series data point
Datum = namedtuple('Datum', ['i', 'x', 'y', 'z', 'row'])
#: Dummy object used in place of a series when rendering legends for categories
DummySeries = namedtuple('DummySeries', ['name'])
formatwarning_orig = warnings.formatwarning
warnings.formatwarning = lambda message, category, filename, lineno, line=None: \
formatwarning_orig(message, category, filename, lineno, line='')
warn = warnings.warn
warnings.resetwarnings()
warnings.simplefilter('always')
# In Python 3.5 use builtin C implementation of `isclose`
if sys.version_info >= (3, 5):
from math import isclose
else:
def isclose(a, b, rel_tol=NINE_PLACES, abs_tol=ZERO):
"""
Test if two floating points numbers are close enough to be considered
equal.
Via: https://github.com/PythonCHB/close_pep/blob/master/isclose.py
Verified against final CPython 3.5 implemenation.
:param a:
The first number to check.
:param b:
The second number to check.
:param rel_tol:
Relative tolerance. The amount of error allowed, relative to the larger
input value. Defaults to nine decimal places of accuracy.
:param abs_tol:
Absolute minimum tolerance. Disabled by default.
"""
if a == b:
return True
if rel_tol < ZERO or abs_tol < ZERO:
raise ValueError('Tolerances must be non-negative')
if math.isinf(abs(a)) or math.isinf(abs(b)):
return False
diff = abs(b - a)
return (((diff <= abs(rel_tol * b)) or
(diff <= abs(rel_tol * a))) or
(diff <= abs_tol))
def to_year_count(d):
"""
date > n years
"""
return d.year
def from_year_count(n, t=date):
"""
n years > date
"""
return t(n, 1, 1)
def to_month_count(d):
"""
date > n months
"""
return (d.year * 12) + d.month
def from_month_count(n, t=date):
"""
n months > date
"""
return t(n // 12, (n % 12) + 1, 1)
def to_day_count(d):
"""
date > n days
"""
return (d - type(d).min).days
def from_day_count(n, t=date):
"""
n days > date
"""
return t.min + timedelta(days=n)
def to_hour_count(d):
"""
date > n hours
"""
return (d - datetime.min).total_seconds() / (60 * 60)
def from_hour_count(n, t=datetime):
"""
n hours > date
"""
return t.min + timedelta(hours=n)
def to_minute_count(d):
"""
date > n minutes
"""
return (d - datetime.min).total_seconds() / 60
def from_minute_count(n, t=datetime):
"""
n minutes > date
"""
return t.min + timedelta(minutes=n)
def to_second_count(d):
"""
date > n seconds
"""
return (d - datetime.min).total_seconds()
def from_second_count(n, t=datetime):
"""
n seconds > date
"""
return t.min + timedelta(seconds=n)
def to_microsecond_count(d):
"""
date > n microseconds
"""
return (d - datetime.min).total_seconds() * 1000
def from_microsecond_count(n, t=datetime):
"""
n microseconds > date
"""
return t.min + timedelta(microseconds=n)
|