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)
| 210 | |
| 211 | |
| 212 | def has_open_quotes(s): |
| 213 | """Return whether a string has open quotes. |
| 214 | |
| 215 | This simply counts whether the number of quote characters of either type in |
| 216 | the string is odd. |
| 217 | |
| 218 | Returns |
| 219 | ------- |
| 220 | If there is an open quote, the quote character is returned. Else, return |
| 221 | False. |
| 222 | """ |
| 223 | # We check " first, then ', so complex cases with nested quotes will get |
| 224 | # the " to take precedence. |
| 225 | if s.count('"') % 2: |
| 226 | return '"' |
| 227 | elif s.count("'") % 2: |
| 228 | return "'" |
| 229 | else: |
| 230 | return False |
| 231 | |
| 232 | |
| 233 | def protect_filename(s, protectables=PROTECTABLES): |