File: _common.py

package info (click to toggle)
python-typepy 1.3.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 624 kB
  • sloc: python: 2,886; makefile: 78; sh: 7
file content (28 lines) | stat: -rw-r--r-- 539 bytes parent folder | download | duplicates (2)
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
"""
.. codeauthor:: Tsuyoshi Hombashi <tsuyoshi.hombashi@gmail.com>
"""

import decimal
import math


def isstring(value):
    return isinstance(value, (str,) + (str, bytes))


def isinf(value):
    try:
        return decimal.Decimal(value).is_infinite()
    except OverflowError:
        return True
    except TypeError:
        return False
    except (ValueError, decimal.InvalidOperation):
        return False


def isnan(value):
    try:
        return math.isnan(value)
    except (TypeError, OverflowError):
        return False