-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix some type errors in
LanguageProcessor
s (#701)
- Loading branch information
Showing
18 changed files
with
275 additions
and
281 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,19 @@ | ||
def remove_non_ascii(string, replace_with=""): | ||
from xml.etree.ElementTree import Element | ||
|
||
|
||
def remove_non_ascii(string: str) -> str: | ||
# ASCII control characters <=31, 127 | ||
# Extended ASCII characters: >=128 | ||
return "".join([i if 31 < ord(i) < 127 else replace_with for i in string]) | ||
return "".join([c if 31 < ord(c) < 127 else "" for c in string]) | ||
|
||
|
||
def child_text(parent: Element, element: str) -> str: | ||
""" | ||
Returns the text content of the first element of type `element` of `parent`. | ||
This defaults to the empty string if no child is found, or the child does not have any text. | ||
""" | ||
child = parent.find(element) | ||
if child is None: | ||
return "" | ||
return child.text or "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.