pyslha.py

changeset 194
b6709078072b
parent 193
40d024dac179
child 195
880af4ab57ba
     1.1 --- a/pyslha.py	Sun Apr 28 18:33:16 2013 +0200
     1.2 +++ b/pyslha.py	Sun Apr 28 18:38:46 2013 +0200
     1.3 @@ -108,11 +108,6 @@
     1.4          else:
     1.5              self.entries[tuple(entry[:-1])] = entry[-1]
     1.6  
     1.7 -    # def is_indexed(self, entry):
     1.8 -    #     """Determine if this block is a multi-value object or just a single
     1.9 -    #     value. Emptiness is considered as being indexed."""
    1.10 -    #     return not( len(self.entries) == 1 and self.entries.keys()[0] is None )
    1.11 -
    1.12      def items(self, key):
    1.13          return self.entries.iteritems()
    1.14  
    1.15 @@ -271,12 +266,11 @@
    1.16                  if len(items) < 1:
    1.17                      continue
    1.18                  if currentblock != "DECAY":
    1.19 -                    if len(items) < 2:
    1.20 -                        ## Treat the ALPHA block differently
    1.21 -                        blocks[currentblock].value = _autotype(items[0])
    1.22 -                        blocks[currentblock].entries = _autotype(items[0])
    1.23 +                    if len(items) > 1:
    1.24 +                        blocks[currentblock].add_entry(items)
    1.25                      else:
    1.26 -                        blocks[currentblock].add_entry(items)
    1.27 +                        ## The ALPHA block in particular only has one, non-indexed value
    1.28 +                        blocks[currentblock].entries[None] = _autotype(items[0])
    1.29                  else:
    1.30                      br = float(items[0]) if items[0].upper() != "NAN" else None
    1.31                      nda = int(items[1])
    1.32 @@ -319,9 +313,9 @@
    1.33          for k, v in b.entries.iteritems():
    1.34              entrystr = ""
    1.35              if type(k) == tuple:
    1.36 -                entrystr = sep.join(_autostr(i) for i in k)
    1.37 -            else:
    1.38 -                entrystr = _autostr(k)
    1.39 +                entrystr += sep.join(_autostr(i) for i in k)
    1.40 +            elif k is not None:
    1.41 +                entrystr += _autostr(k)
    1.42              entrystr += sep + _autostr(v) # TODO: apply precision formatting for floats
    1.43              entrystrs.append(entrystr)
    1.44          blockstr += "\n".join(entrystrs)

mercurial