Skip to content

Commit

Permalink
Issue 173: simply name fetcher parameters (#174)
Browse files Browse the repository at this point in the history
* remove NXcollection attribute for nexus_logs

* trigger the tests

* simply name fetcher parameters

* bump the version

* update manpage

* add tests

* drop support for python2

* improve the tests

* improve tests

* fix typo

* revert py2 tests

* add utf8 support in py2

* improve support for py2
  • Loading branch information
jkotan authored Jan 13, 2025
1 parent a9e4f72 commit ba0815a
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 16 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
2025-01-13 Jan Kotanski <[email protected]>
* add support for utf8 in xmla attribute/field values (#174)
* add support for utf8 in py2 (#176)
* tagged as 3.13.0

2024-09-27 Jan Kotanski <[email protected]>
* remove NXcollection attribute for nexus_logs (#168)
* tagged as 3.12.0
Expand Down
2 changes: 1 addition & 1 deletion man/nxswriter.1
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
.\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
.in \\n[rst2man-indent\\n[rst2man-indent-level]]u
..
.TH "NXSWRITER" "1" "Nov 07, 2024" "3.12" "NXSDataWriter"
.TH "NXSWRITER" "1" "Jan 13, 2025" "3.13" "NXSDataWriter"
.SH NAME
nxswriter \- nxswriter Documentation
.sp
Expand Down
9 changes: 6 additions & 3 deletions nxswriter/FElement.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def _findShape(self, rank, lengths=None, extraD=False,
if sys.version_info > (3,):
val = ("".join(self.content)).strip()
else:
val = ("".join(self.content)).strip().encode()
val = ("".join(self.content)).strip().encode("utf8")
found = False
if checkData and self.source and self.source.isValid():
data = self.source.getData()
Expand Down Expand Up @@ -497,9 +497,12 @@ def _setAttributes(self, excluded=None):
ekey, "string", overwrite=True)[...] \
= self._tagAttrs[key].strip()
else:
try:
vl = self._tagAttrs[key].strip().encode()
except Exception:
vl = self._tagAttrs[key].strip().encode("utf8")
self.h5Object.attributes.create(
ekey, "string", overwrite=True)[...] \
= self._tagAttrs[key].strip().encode()
ekey, "string", overwrite=True)[...] = vl

def h5Attribute(self, name):
""" provides attribute h5 object
Expand Down
2 changes: 1 addition & 1 deletion nxswriter/Release.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@


#: package version
__version__ = "3.12.0"
__version__ = "3.13.0"
18 changes: 15 additions & 3 deletions nxswriter/TangoDataWriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
#: (:obj:`bool`) tango bug #213 flag related to EncodedAttributes in python3
PYTG_BUG_213 = False
if sys.version_info > (3,):
unicode = str
try:
try:
import tango
Expand Down Expand Up @@ -315,9 +316,12 @@ def __setXML(self, xmlset):
"""
self.__fetcher = FetchNameHandler(streams=self._streams)
if sys.version_info > (3,):
sax.parseString(bytes(xmlset, 'utf-8'), self.__fetcher)
else:
sax.parseString(xmlset, self.__fetcher)
else:
if isinstance(xmlset, unicode):
sax.parseString(xmlset.encode('utf-8'), self.__fetcher)
else:
sax.parseString(xmlset, self.__fetcher)
self.__xmlsettings = xmlset

def __delXML(self):
Expand Down Expand Up @@ -504,7 +508,15 @@ def openEntry(self):
parser.setContentHandler(handler)
parser.setErrorHandler(errorHandler)
inpsrc = sax.InputSource()
inpsrc.setByteStream(StringIO(self.xmlsettings))
if sys.version_info > (3,):
inpsrc.setByteStream(StringIO(self.xmlsettings))
else:
if isinstance(self.xmlsettings, unicode):
inpsrc.setByteStream(
StringIO(self.xmlsettings.encode('utf-8')))
else:
inpsrc.setByteStream(StringIO(self.xmlsettings))

parser.parse(inpsrc)

self.__initPool = handler.initPool
Expand Down
8 changes: 4 additions & 4 deletions test/TangoDataWriterH5Cpp_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ class TangoDataWriterH5CppTest(unittest.TestCase):
def __init__(self, methodName):
unittest.TestCase.__init__(self, methodName)

self._scanXmlpart = """
self._scanXmlpart = u"""
<group type="NXinstrument" name="instrument">
<attribute name ="short_name"> scan instrument </attribute>
<group type="NXdetector" name="detector">
<field units="m" type="NX_FLOAT" name="counter1">
<field units="\u03bcm" type="NX_FLOAT" name="counter1">
<strategy mode="STEP"/>
<datasource type="CLIENT">
<record name="exp_c01"/>
Expand Down Expand Up @@ -1683,7 +1683,7 @@ def test_scanRecord_nexuspath(self):
self.assertEqual(at.shape, ())
self.assertEqual(at.dtype, "string")
self.assertEqual(at.name, "units")
self.assertEqual(at[...], "m")
self.assertEqual(at[...], u"\u03bcm")

at = cnt.attributes["nexdatas_source"]
self.assertTrue(at.is_valid)
Expand Down Expand Up @@ -1749,7 +1749,7 @@ def test_scanRecord_nexuspath(self):

if os.path.isfile(fname):
os.remove(fname)
# pass
# pass

# scanRecord test
# \brief It tests recording of simple h5 file
Expand Down
8 changes: 4 additions & 4 deletions test/TangoDataWriterH5PY_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ class TangoDataWriterH5PYTest(unittest.TestCase):
def __init__(self, methodName):
unittest.TestCase.__init__(self, methodName)

self._scanXmlpart = """
self._scanXmlpart = u"""
<group type="NXinstrument" name="instrument">
<attribute name ="short_name"> scan instrument </attribute>
<group type="NXdetector" name="detector">
<field units="m" type="NX_FLOAT" name="counter1">
<field units="\u03bcm" type="NX_FLOAT" name="counter1">
<strategy mode="STEP"/>
<datasource type="CLIENT">
<record name="exp_c01"/>
Expand Down Expand Up @@ -1681,7 +1681,7 @@ def test_scanRecord_nexuspath(self):
self.assertEqual(at.shape, ())
self.assertEqual(at.dtype, "string")
self.assertEqual(at.name, "units")
self.assertEqual(at[...], "m")
self.assertEqual(at[...], u"\u03bcm")

at = cnt.attributes["nexdatas_source"]
self.assertTrue(at.is_valid)
Expand Down Expand Up @@ -1747,7 +1747,7 @@ def test_scanRecord_nexuspath(self):

if os.path.isfile(fname):
os.remove(fname)
# pass
# pass

# scanRecord test
# \brief It tests recording of simple h5 file
Expand Down

0 comments on commit ba0815a

Please sign in to comment.