Commit 0982acb0bf7a586f98c6fe956d5fcb74f2afd7fb
1 parent
fdc77bfa
codepages: added get_codepage_name
Showing
1 changed file
with
13 additions
and
0 deletions
oletools/common/codepages.py
| ... | ... | @@ -3,6 +3,7 @@ codepages.py |
| 3 | 3 | |
| 4 | 4 | codepages is a python module to map code pages (numbers) to Python codecs, |
| 5 | 5 | in order to decode bytes to unicode. |
| 6 | +It also provides the name/description of code pages. | |
| 6 | 7 | |
| 7 | 8 | Author: Philippe Lagadec - http://www.decalage.info |
| 8 | 9 | License: BSD, see source code or documentation |
| ... | ... | @@ -45,6 +46,8 @@ __version__ = '0.54dev6' |
| 45 | 46 | |
| 46 | 47 | # ----------------------------------------------------------------------------- |
| 47 | 48 | # TODO: |
| 49 | +# TODO: check also http://www.aivosto.com/articles/charsets-codepages.html | |
| 50 | +# TODO: https://en.wikipedia.org/wiki/Code_page | |
| 48 | 51 | |
| 49 | 52 | # ----------------------------------------------------------------------------- |
| 50 | 53 | # REFERENCES: |
| ... | ... | @@ -290,6 +293,16 @@ def codepage2codec(codepage): |
| 290 | 293 | codec = 'utf8' |
| 291 | 294 | return codec |
| 292 | 295 | |
| 296 | + | |
| 297 | +def get_codepage_name(codepage): | |
| 298 | + """ | |
| 299 | + return the name of a codepage based on its number | |
| 300 | + :param codepage: int, codepage number | |
| 301 | + :return: str, codepage name | |
| 302 | + """ | |
| 303 | + return CODEPAGE_NAME.get(codepage, 'Unknown code page') | |
| 304 | + | |
| 305 | + | |
| 293 | 306 | # === MAIN: TESTS ============================================================ |
| 294 | 307 | |
| 295 | 308 | if __name__ == '__main__': | ... | ... |