Mercurial > pyarq-presupuestos
diff Generic/utils.py @ 17:a7b9f7e7dfa4
Improvements importing FIEBDC files
author | Miguel Ángel Bárcena Rodríguez <miguelangel@obraencurso.es> |
---|---|
date | Sat, 02 Nov 2013 19:26:09 +0100 |
parents | 2ac1551ad2ab |
children | 65e7ae0d0e63 |
line wrap: on
line diff
--- a/Generic/utils.py Fri Apr 19 00:04:20 2013 +0200 +++ b/Generic/utils.py Sat Nov 02 19:26:09 2013 +0100 @@ -3,7 +3,7 @@ ## File utils.py ## This file is part of pyArq-Presupuestos. ## -## Copyright (C) 2010 Miguel Ángel Bárcena Rodríguez +## Copyright (C) 2010-2013 Miguel Ángel Bárcena Rodríguez ## <miguelangel@obraencurso.es> ## ## pyArq-Presupuestos is free software: you can redistribute it and/or modify @@ -111,32 +111,40 @@ """ _is_valid = True if not isinstance(code, str): + print "Not a string, code:", code, type(code) return False, False if code == "": + return False, False try: - _unicode_code = unicode(code, "utf8") - _code_cp850 = _unicode_code.encode("cp850") - _unicode_code = unicode(_code_cp850, "cp850") - _code_utf8 = _unicode_code.encode("utf8") + _unicode_code = unicode(code, "utf8",'replace') + _code_utf8 = _unicode_code.encode("utf8",'replace') + _code_cp850 = _unicode_code.encode("cp850",'replace') + _unicode_code = unicode(_code_cp850, "cp850",'replace') + except UnicodeError: + print "Unicode Error, code:", code return False, False if _code_utf8 != code: + print "Not in cp950, code:", code _is_valid = False if _code_utf8 == "": return False, False code = _code_utf8 _code2 = re.sub("[\t \n\r~|\\\]","",code) if _code2 != code: + print "Control characters in code:", code if _code2 == "": return False, False _is_valid = False code = _code2 if code[-1] == "#": + print "# in code:", code _is_valid = False while code[-1] == "#": code = code[:-1] if code == "": + print "Empty code" return False, False return _is_valid, code