From cf2d5c7a8be55e87e47af9659e03a3e9aba01584 Mon Sep 17 00:00:00 2001 From: HENDRIX-ZT2 Date: Wed, 18 Sep 2019 12:12:11 +0200 Subject: [PATCH 1/4] python 3.7 support - replace `raise StopIteration` by `return` https://www.python.org/dev/peps/pep-0479/#examples-of-breakage - replace time.clock() by time.time() since we don't really care which time it is but the latter still works --- pyffi/object_models/xml/__init__.py | 4 ++-- pyffi/object_models/xml/enum.py | 2 +- pyffi/object_models/xsd/__init__.py | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pyffi/object_models/xml/__init__.py b/pyffi/object_models/xml/__init__.py index 13809cf18..bd8fac875 100644 --- a/pyffi/object_models/xml/__init__.py +++ b/pyffi/object_models/xml/__init__.py @@ -101,13 +101,13 @@ def __init__(cls, name, bases, dct): # which takes care of the class creation cls.logger.debug("Parsing %s and generating classes." % xml_file_name) - start = time.clock() + start = time.time() try: parser.parse(xml_file) finally: xml_file.close() cls.logger.debug("Parsing finished in %.3f seconds." - % (time.clock() - start)) + % (time.time() - start)) class FileFormat(pyffi.object_models.FileFormat, metaclass=MetaFileFormat): diff --git a/pyffi/object_models/xml/enum.py b/pyffi/object_models/xml/enum.py index 1979d4209..92d5f887e 100644 --- a/pyffi/object_models/xml/enum.py +++ b/pyffi/object_models/xml/enum.py @@ -95,7 +95,7 @@ def __next__(cls): cls.__i += 1 return (cls._enumkeys[cls.__i-1], cls._enumvalues[cls.__i-1]) else: - raise StopIteration + return def __getitem__(cls, key): if key in cls._enumkeys: diff --git a/pyffi/object_models/xsd/__init__.py b/pyffi/object_models/xsd/__init__.py index 75a63c110..c9910d378 100644 --- a/pyffi/object_models/xsd/__init__.py +++ b/pyffi/object_models/xsd/__init__.py @@ -520,7 +520,7 @@ def __init__(cls, name, bases, dct): # parse the XSD file cls.logger.debug("Parsing %s and generating classes." % xsdfilename) - start = time.clock() + start = time.time() try: # create nodes for every element in the XSD tree schema = Tree.node_factory( @@ -535,7 +535,7 @@ def __init__(cls, name, bases, dct): # generate attributes schema.attribute_walker(cls) cls.logger.debug("Parsing finished in %.3f seconds." - % (time.clock() - start)) + % (time.time() - start)) class Type(object): _node = None From f6b6d77ceb4a18e31a67714d501ecde24d2b6911 Mon Sep 17 00:00:00 2001 From: HENDRIX-ZT2 Date: Wed, 18 Sep 2019 13:48:04 +0200 Subject: [PATCH 2/4] Rollback enum snakeCase We can keep the original formatting of attribute names. snakeCase broke access to enum attributes in the blender plugin. --- pyffi/object_models/xml/enum.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pyffi/object_models/xml/enum.py b/pyffi/object_models/xml/enum.py index 92d5f887e..0869f8c7f 100644 --- a/pyffi/object_models/xml/enum.py +++ b/pyffi/object_models/xml/enum.py @@ -40,7 +40,6 @@ import logging import struct -from pyffi.object_models import FileFormat as snakeCase from pyffi.object_models.xml.basic import BasicBase from pyffi.object_models.editable import EditableComboBox @@ -84,7 +83,7 @@ def __init__(cls, name, bases, dct): # set enum values as class attributes for item, value in zip(cls._enumkeys, cls._enumvalues): - setattr(cls, "".join(snakeCase.name_parts(item)), value) + setattr(cls, item, value) def __iter__(cls): cls.__i = 0 From f03342d5f34e7cb2003274591b10d4201368621c Mon Sep 17 00:00:00 2001 From: HENDRIX-ZT2 Date: Wed, 18 Sep 2019 13:53:11 +0200 Subject: [PATCH 3/4] Vector3: convenience access add a setter function and implicit access to the x,y,z properties --- pyffi/formats/nif/__init__.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/pyffi/formats/nif/__init__.py b/pyffi/formats/nif/__init__.py index 2b044eb85..849336c1e 100644 --- a/pyffi/formats/nif/__init__.py +++ b/pyffi/formats/nif/__init__.py @@ -1973,6 +1973,28 @@ def sup_norm(self): for row in self.as_list()) class Vector3: + + def assign(self, vec): + """ Set this vector to values from another object that supports iteration or x,y,z properties """ + # see if it is an iterable + try: + self.x = vec[0] + self.y = vec[1] + self.z = vec[2] + except: + if hasattr(vec, "x"): + self.x = vec.x + if hasattr(vec, "y"): + self.y = vec.y + if hasattr(vec, "z"): + self.z = vec.z + + def __iter__(self): + # just a convenience so we can do: x,y,z = Vector3() + yield self.x + yield self.y + yield self.z + def as_list(self): return [self.x, self.y, self.z] From 63aef5dc256c342f1396f84f0aea78d50ea0c570 Mon Sep 17 00:00:00 2001 From: HENDRIX-ZT2 Date: Wed, 18 Sep 2019 15:54:33 +0200 Subject: [PATCH 4/4] Rewrite generator to avoid iter/next should do the trick --- pyffi/formats/cgf/__init__.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pyffi/formats/cgf/__init__.py b/pyffi/formats/cgf/__init__.py index 585651130..dedbb9e3a 100644 --- a/pyffi/formats/cgf/__init__.py +++ b/pyffi/formats/cgf/__init__.py @@ -1842,9 +1842,9 @@ def get_triangles(self): for face in self.faces: yield face.v_0, face.v_1, face.v_2 elif self.indices_data: - it = iter(self.indices_data.indices) - while True: - yield next(it), next(it), next(it) + inds = self.indices_data.indices + for i in range(0, len(inds), 3): + yield inds[i], inds[i+1], inds[i+2] def get_material_indices(self): """Generator for all materials (per triangle)."""