Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'io_import_dxf/dxfgrabber/decode.py')
-rwxr-xr-xio_import_dxf/dxfgrabber/decode.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/io_import_dxf/dxfgrabber/decode.py b/io_import_dxf/dxfgrabber/decode.py
new file mode 100755
index 00000000..3187cc8f
--- /dev/null
+++ b/io_import_dxf/dxfgrabber/decode.py
@@ -0,0 +1,38 @@
+# Purpose: decode DXF proprietary data
+# Created: 01.05.2014
+# Copyright (C) 2014, Manfred Moitzi
+# License: MIT License
+from __future__ import unicode_literals
+__author__ = "mozman <mozman@gmx.at>"
+
+from . import PYTHON3
+
+_replacement_table = {
+ 0x20: ' ',
+ 0x40: '_',
+ 0x5F: '@',
+}
+for c in range(0x41, 0x5F):
+ _replacement_table[c] = chr(0x41 + (0x5E - c)) # 0x5E -> 'A', 0x5D->'B', ...
+
+
+def decode(text_lines):
+ def _decode(text):
+ s = []
+ skip = False
+ if PYTHON3:
+ text = bytes(text, 'ascii')
+ else:
+ text = map(ord, text)
+
+ for c in text:
+ if skip:
+ skip = False
+ continue
+ if c in _replacement_table:
+ s += _replacement_table[c]
+ skip = (c == 0x5E) # skip space after 'A'
+ else:
+ s += chr(c ^ 0x5F)
+ return ''.join(s)
+ return [_decode(line) for line in text_lines]