diff --git a/tabulate/__init__.py b/tabulate/__init__.py index 12a2950..b62253a 100644 --- a/tabulate/__init__.py +++ b/tabulate/__init__.py @@ -862,7 +862,7 @@ def _isnumber_with_thousands_separator(string): except (UnicodeDecodeError, AttributeError): pass - return bool(re.match(_float_with_thousands_separators, string)) + return bool(_float_with_thousands_separators.match(string)) def _isconvertible(conv, string): @@ -932,9 +932,12 @@ def _isint(string, inttype=int): >>> _isint("123.45") False """ + if type(string) is inttype: + return True + if type(string) is float: + return False return ( - type(string) is inttype - or ( + ( (hasattr(string, "is_integer") or hasattr(string, "__array__")) and str(type(string)).startswith("= 0: return len(string) - pos - 1 else: @@ -1089,8 +1085,12 @@ def _strip_ansi(s): """ if isinstance(s, str): + if "\x1b" not in s: + return s return _ansi_codes.sub(r"\4", s) else: # a bytestring + if b"\x1b" not in s: + return s return _ansi_codes_bytes.sub(r"\4", s) @@ -1122,9 +1122,9 @@ def _visible_width(s): def _is_multiline(s): if isinstance(s, str): - return bool(re.search(_multiline_codes, s)) + return "\n" in s or "\r" in s else: # a bytestring - return bool(re.search(_multiline_codes_bytes, s)) + return b"\n" in s or b"\r" in s def _multiline_width(multiline_s, line_width_fn=len):