#813 Add normalize_spaces flag to arrow.get

Merged meddir

No flags found

Use flags to group coverage reports by test type, project and/or folders.
Then setup custom commit statuses and notifications for each flag.

e.g., #unittest #integration

#production #enterprise

#frontend #backend

Learn more about Codecov Flags here.

Showing 2 of 5 files from the diff.

@@ -34,11 +34,13 @@
Loading
34 34
    def get(self, *args, **kwargs):
35 35
        """ Returns an :class:`Arrow <arrow.arrow.Arrow>` object based on flexible inputs.
36 36
37 -
        :param locale: (optional) a ``str`` specifying a locale for the parser. Defaults to
38 -
            'en_us'.
37 +
        :param locale: (optional) a ``str`` specifying a locale for the parser. Defaults to 'en_us'.
39 38
        :param tzinfo: (optional) a :ref:`timezone expression <tz-expr>` or tzinfo object.
40 39
            Replaces the timezone unless using an input form that is explicitly UTC or specifies
41 40
            the timezone in a positional argument. Defaults to UTC.
41 +
        :param normalize_whitespace: (optional) a ``bool`` specifying whether or not to normalize
42 +
            redundant whitespace (spaces, tabs, and newlines) in a datetime string before parsing.
43 +
            Defaults to false.
42 44
43 45
        Usage::
44 46
@@ -141,6 +143,7 @@
Loading
141 143
        arg_count = len(args)
142 144
        locale = kwargs.pop("locale", "en_us")
143 145
        tz = kwargs.get("tzinfo", None)
146 +
        normalize_whitespace = kwargs.pop("normalize_whitespace", False)
144 147
145 148
        # if kwargs given, send to constructor unless only tzinfo provided
146 149
        if len(kwargs) > 1:
@@ -193,7 +196,7 @@
Loading
193 196
194 197
            # (str) -> parse.
195 198
            elif isstr(arg):
196 -
                dt = parser.DateTimeParser(locale).parse_iso(arg)
199 +
                dt = parser.DateTimeParser(locale).parse_iso(arg, normalize_whitespace)
197 200
                return self.type.fromdatetime(dt, tz)
198 201
199 202
            # (struct_time) -> from struct_time
@@ -240,7 +243,9 @@
Loading
240 243
241 244
            # (str, format) -> parse.
242 245
            elif isstr(arg_1) and (isstr(arg_2) or isinstance(arg_2, list)):
243 -
                dt = parser.DateTimeParser(locale).parse(args[0], args[1])
246 +
                dt = parser.DateTimeParser(locale).parse(
247 +
                    args[0], args[1], normalize_whitespace
248 +
                )
244 249
                return self.type.fromdatetime(dt, tzinfo=tz)
245 250
246 251
            else:

@@ -114,8 +114,11 @@
Loading
114 114
115 115
    # TODO: since we support more than ISO 8601, we should rename this function
116 116
    # IDEA: break into multiple functions
117 -
    def parse_iso(self, datetime_string):
118 -
        # TODO: add a flag to normalize whitespace (useful in logs, ref issue #421)
117 +
    def parse_iso(self, datetime_string, normalize_whitespace=False):
118 +
119 +
        if normalize_whitespace:
120 +
            datetime_string = re.sub(r"\s+", " ", datetime_string.strip())
121 +
119 122
        has_space_divider = " " in datetime_string
120 123
        has_t_divider = "T" in datetime_string
121 124
@@ -213,7 +216,10 @@
Loading
213 216
214 217
        return self._parse_multiformat(datetime_string, formats)
215 218
216 -
    def parse(self, datetime_string, fmt):
219 +
    def parse(self, datetime_string, fmt, normalize_whitespace=False):
220 +
221 +
        if normalize_whitespace:
222 +
            datetime_string = re.sub(r"\s+", " ", datetime_string)
217 223
218 224
        if isinstance(fmt, list):
219 225
            return self._parse_multiformat(datetime_string, fmt)

Everything is accounted for!

No changes detected that need to be reviewed.
What changes does Codecov check for?
Lines, not adjusted in diff, that have changed coverage data.
Files that introduced coverage data that had none before.
Files that have missing coverage data that once were tracked.
Files Coverage
arrow 100.00%
Project Totals (9 files) 100.00%
Loading