glTF exporter: No texture export when original can't be retrieved
[blender-addons.git] / io_import_dxf / dxfgrabber / __init__.py
blobf46c691e6202ab1d9524158254b11ade4dfa391d
1 # SPDX-License-Identifier: MIT
2 # Copyright 2012 Manfred Moitzi (mozman)
4 # Purpose: grab information from DXF drawings - all DXF versions supported
5 # Created: 21.07.2012
7 version = (0, 8, 4)
8 VERSION = "%d.%d.%d" % version
10 __author__ = "mozman <mozman@gmx.at>"
11 __doc__ = """A Python library to grab information from DXF drawings - all DXF versions supported."""
14 # Python27/3x support should be done here
15 import sys
17 PYTHON3 = sys.version_info.major > 2
19 if PYTHON3:
20 tostr = str
21 else: # PYTHON27
22 tostr = unicode
24 # end of Python 2/3 adaption
25 # if tostr does not work, look at package 'dxfwrite' for escaping unicode chars
27 from .const import BYBLOCK, BYLAYER
29 import io
30 from .tags import dxfinfo
31 from .color import aci_to_true_color
34 def read(stream, options=None):
35 if hasattr(stream, 'readline'):
36 from .drawing import Drawing
37 return Drawing(stream, options)
38 else:
39 raise AttributeError('stream object requires a readline() method.')
42 def readfile(filename, options=None):
43 try: # is it ascii code-page encoded?
44 return readfile_as_asc(filename, options)
45 except UnicodeDecodeError: # try unicode and ignore errors
46 return readfile_as_utf8(filename, options, errors='ignore')
49 def readfile_as_utf8(filename, options=None, errors='strict'):
50 return _read_encoded_file(filename, options, encoding='utf-8', errors=errors)
53 def readfile_as_asc(filename, options=None):
54 def get_encoding():
55 with io.open(filename) as fp:
56 info = dxfinfo(fp)
57 return info.encoding
59 return _read_encoded_file(filename, options, encoding=get_encoding())
62 def _read_encoded_file(filename, options=None, encoding='utf-8', errors='strict'):
63 from .drawing import Drawing
65 with io.open(filename, encoding=encoding, errors=errors) as fp:
66 dwg = Drawing(fp, options)
67 dwg.filename = filename
68 return dwg