Return whether a string has open quotes. This simply counts whether the number of quote characters of either type in the string is odd. Returns ------- If there is an open quote, the quote character is returned. Else, return False.
(s: str)
| 337 | |
| 338 | |
| 339 | def has_open_quotes(s: str) -> Union[str, bool]: |
| 340 | """Return whether a string has open quotes. |
| 341 | |
| 342 | This simply counts whether the number of quote characters of either type in |
| 343 | the string is odd. |
| 344 | |
| 345 | Returns |
| 346 | ------- |
| 347 | If there is an open quote, the quote character is returned. Else, return |
| 348 | False. |
| 349 | """ |
| 350 | # We check " first, then ', so complex cases with nested quotes will get |
| 351 | # the " to take precedence. |
| 352 | if s.count('"') % 2: |
| 353 | return '"' |
| 354 | elif s.count("'") % 2: |
| 355 | return "'" |
| 356 | else: |
| 357 | return False |
| 358 | |
| 359 | |
| 360 | def protect_filename(s: str, protectables: str = PROTECTABLES) -> str: |
no outgoing calls
no test coverage detected
searching dependent graphs…