(object, format, timetuple)
| 215 | |
| 216 | # Correctly substitute for %z and %Z escapes in strftime formats. |
| 217 | def _wrap_strftime(object, format, timetuple): |
| 218 | # Don't call utcoffset() or tzname() unless actually needed. |
| 219 | freplace = None # the string to use for %f |
| 220 | zreplace = None # the string to use for %z |
| 221 | colonzreplace = None # the string to use for %:z |
| 222 | Zreplace = None # the string to use for %Z |
| 223 | |
| 224 | # Scan format for %z, %:z and %Z escapes, replacing as needed. |
| 225 | newformat = [] |
| 226 | push = newformat.append |
| 227 | i, n = 0, len(format) |
| 228 | while i < n: |
| 229 | ch = format[i] |
| 230 | i += 1 |
| 231 | if ch == '%': |
| 232 | if i < n: |
| 233 | ch = format[i] |
| 234 | i += 1 |
| 235 | if ch == 'f': |
| 236 | if freplace is None: |
| 237 | freplace = '%06d' % getattr(object, |
| 238 | 'microsecond', 0) |
| 239 | newformat.append(freplace) |
| 240 | elif ch == 'z': |
| 241 | if zreplace is None: |
| 242 | if hasattr(object, "utcoffset"): |
| 243 | zreplace = _format_offset(object.utcoffset(), sep="") |
| 244 | else: |
| 245 | zreplace = "" |
| 246 | assert '%' not in zreplace |
| 247 | newformat.append(zreplace) |
| 248 | elif ch == ':': |
| 249 | if i < n: |
| 250 | ch2 = format[i] |
| 251 | i += 1 |
| 252 | if ch2 == 'z': |
| 253 | if colonzreplace is None: |
| 254 | if hasattr(object, "utcoffset"): |
| 255 | colonzreplace = _format_offset(object.utcoffset(), sep=":") |
| 256 | else: |
| 257 | colonzreplace = "" |
| 258 | assert '%' not in colonzreplace |
| 259 | newformat.append(colonzreplace) |
| 260 | else: |
| 261 | push('%') |
| 262 | push(ch) |
| 263 | push(ch2) |
| 264 | elif ch == 'Z': |
| 265 | if Zreplace is None: |
| 266 | Zreplace = "" |
| 267 | if hasattr(object, "tzname"): |
| 268 | s = object.tzname() |
| 269 | if s is not None: |
| 270 | # strftime is going to have at this: escape % |
| 271 | Zreplace = s.replace('%', '%%') |
| 272 | newformat.append(Zreplace) |
| 273 | # Note that datetime(1000, 1, 1).strftime('%G') == '1000' so |
| 274 | # year 1000 for %G can go on the fast path. |
no test coverage detected
searching dependent graphs…