Skip to content

Commit

Permalink
Merge pull request #60 from HENDRIX-ZT2/develop
Browse files Browse the repository at this point in the history
Python 3.7 support
  • Loading branch information
neomonkeus committed Sep 18, 2019
2 parents 440c61c + 63aef5d commit 3bb308a
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 10 deletions.
6 changes: 3 additions & 3 deletions pyffi/formats/cgf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)."""
Expand Down
22 changes: 22 additions & 0 deletions pyffi/formats/nif/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
4 changes: 2 additions & 2 deletions pyffi/object_models/xml/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
5 changes: 2 additions & 3 deletions pyffi/object_models/xml/enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -95,7 +94,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:
Expand Down
4 changes: 2 additions & 2 deletions pyffi/object_models/xsd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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
Expand Down

0 comments on commit 3bb308a

Please sign in to comment.