/usr/lib/python2.7/dist-packages/natsort/compat/fake_fastnumbers.py is in python-natsort 4.0.3-2.
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 | # -*- coding: utf-8 -*-
"""\
This module is intended to replicate some of the functionality
from the fastnumbers module in the event that module is not
installed.
"""
from __future__ import (
print_function,
division,
unicode_literals,
absolute_import
)
# Std. lib imports.
import sys
import re
import unicodedata
float_re = re.compile(r'[-+]?(\d*\.?\d+(?:[eE][-+]?\d+)?|inf(?:inity)?|nan)$')
if sys.version[0] == '2':
int_re = re.compile(r'[-+]?\d+[lL]?$')
else:
int_re = re.compile(r'[-+]?\d+$')
long = int
unicode = str
def fast_float(x, regex_matcher=float_re.match, uni=unicodedata.numeric):
"""Convert a string to a float quickly"""
if type(x) in (int, long, float):
return float(x)
elif regex_matcher(x):
return float(x)
elif type(x) == unicode and len(x) == 1 and uni(x, None) is not None:
return uni(x)
else:
return x
def fast_int(x, regex_matcher=int_re.match, uni=unicodedata.digit):
"""\
Convert a string to a int quickly, return input as-is if not possible.
"""
if type(x) in (int, long, float):
return int(x)
elif regex_matcher(x):
return int(x.rstrip('Ll'))
elif type(x) == unicode and len(x) == 1 and uni(x, None) is not None:
return uni(x)
else:
return x
def isfloat(x, num_only=False):
"""Returns true if the input is a float, false otherwise."""
return type(x) == float
def isint(x, num_only=False):
"""Returns true if the input is an int, false otherwise."""
return type(x) in set([int, long])
|