1
0
Fork 0
mirror of https://github.com/evilhero/mylar synced 2024-12-23 08:12:41 +00:00
mylar/lib/natsort/compat/fake_fastnumbers.py
evilhero 2623bbcbaf IMP: Updated CT to a newer version - changed to use rarfile, fixes size invalid errors with some cbr's encountered during conversions, IMP: Search and Post-Processing Queues now added in order to queue up all searches/post-processing in sequence instead of loading lists and iterating through it and encountering various lock-related errors, IMP: In most cases, will now post-process directly against comicid/issueid/storyarcid instead of relying on relationship via nzb/torrent, FIX: realigned some checkboxes on series detail page, FIX: in configuration, indicated that ComicRN cannot be used when Completed Download Handling is enabled for a client now, FIX: Fix for issues named as 'special' that are part of the annuals section, but would not work in various portions (also will allow for naming differences in the future hopefully), FIX: Will now trap error properly when file cannot be located during dupecheck so that post-processing can continue without error, FIX: Fixed newznab test option on configuration screen so that it will return the correct response (previous was an invalid api endpoint), FIX: When retrieving image for storyarcs would error when no image was present and stop the process, FIX: accounted for some incorrect newznab responses that would return a non-api endpoint when retrieving via rss, which resulted in invalid nzbs, FIX: in some cases, weekly pull snatches would not update properly on the weekly page due to some db values not being written
2018-06-14 13:07:39 -04:00

72 lines
2.3 KiB
Python

# -*- 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 unicodedata
from natsort.unicode_numbers import decimal_chars
from natsort.compat.py23 import PY_VERSION
if PY_VERSION >= 3:
long = int
NAN_INF = ['INF', 'INf', 'Inf', 'inF', 'iNF', 'InF', 'inf', 'iNf',
'NAN', 'nan', 'NaN', 'nAn', 'naN', 'NAn', 'nAN', 'Nan']
NAN_INF.extend(['+'+x[:2] for x in NAN_INF] + ['-'+x[:2] for x in NAN_INF])
NAN_INF = frozenset(NAN_INF)
ASCII_NUMS = '0123456789+-'
def fast_float(x, key=lambda x: x, nan=None,
uni=unicodedata.numeric, nan_inf=NAN_INF,
_first_char=frozenset(decimal_chars + list(ASCII_NUMS + '.'))):
"""\
Convert a string to a float quickly, return input as-is if not possible.
We don't need to accept all input that the real fast_int accepts because
the input will be controlled by the splitting algorithm.
"""
if x[0] in _first_char or x.lstrip()[:3] in nan_inf:
try:
x = float(x)
return nan if nan is not None and x != x else x
except ValueError:
try:
return uni(x, key(x)) if len(x) == 1 else key(x)
except TypeError: # pragma: no cover
return key(x)
else:
try:
return uni(x, key(x)) if len(x) == 1 else key(x)
except TypeError: # pragma: no cover
return key(x)
def fast_int(x, key=lambda x: x, nan=None, uni=unicodedata.digit,
_first_char=frozenset(decimal_chars + list(ASCII_NUMS))):
"""\
Convert a string to a int quickly, return input as-is if not possible.
We don't need to accept all input that the real fast_int accepts because
the input will be controlled by the splitting algorithm.
"""
if x[0] in _first_char:
try:
return long(x)
except ValueError:
try:
return uni(x, key(x)) if len(x) == 1 else key(x)
except TypeError: # pragma: no cover
return key(x)
else:
try:
return uni(x, key(x)) if len(x) == 1 else key(x)
except TypeError: # pragma: no cover
return key(x)