mirror of
https://github.com/frappe/frappe_docker.git
synced 2026-06-20 07:05:08 +00:00
47 lines
1,014 B
Python
47 lines
1,014 B
Python
from __future__ import absolute_import
|
|
# Copyright (c) 2010-2017 openpyxl
|
|
|
|
from math import isnan
|
|
import sys
|
|
|
|
VER = sys.version_info
|
|
|
|
from .numbers import NUMERIC_TYPES
|
|
|
|
if VER[0] >= 3:
|
|
basestring = str
|
|
unicode = str
|
|
from io import BufferedReader
|
|
file = BufferedReader
|
|
from io import BufferedRandom
|
|
tempfile = BufferedRandom
|
|
bytes = bytes
|
|
else:
|
|
basestring = basestring
|
|
unicode = unicode
|
|
file = file
|
|
tempfile = file
|
|
bytes = str
|
|
|
|
|
|
def safe_string(value):
|
|
"""Safely and consistently format numeric values"""
|
|
if isinstance(value, NUMERIC_TYPES):
|
|
if isnan(value):
|
|
value = ""
|
|
else:
|
|
value = "%.16g" % value
|
|
elif value is None:
|
|
value = "none"
|
|
elif not isinstance(value, basestring):
|
|
value = str(value)
|
|
return value
|
|
|
|
|
|
def safe_repr(value):
|
|
"""
|
|
Safely convert unicode to ASCII for Python 2
|
|
"""
|
|
if VER[0] == 3:
|
|
return value
|
|
return value.encode("ascii", 'backslashreplace')
|