[Pymoul-svn] SF.net SVN: pymoul: [283] pymoul/trunk/src/moul
Status: Alpha
Brought to you by:
tiran
From: <ti...@us...> - 2007-04-16 18:45:32
|
Revision: 283 http://pymoul.svn.sourceforge.net/pymoul/?rev=283&view=rev Author: tiran Date: 2007-04-16 11:45:31 -0700 (Mon, 16 Apr 2007) Log Message: ----------- Added pak and sdl reader. Fixed Uru String Modified Paths: -------------- pymoul/trunk/src/moul/crypt/binary.py Added Paths: ----------- pymoul/trunk/src/moul/file/pak.py pymoul/trunk/src/moul/file/sdl.py pymoul/trunk/src/moul/file/tests/test_sdl.py Modified: pymoul/trunk/src/moul/crypt/binary.py =================================================================== --- pymoul/trunk/src/moul/crypt/binary.py 2007-04-15 22:27:52 UTC (rev 282) +++ pymoul/trunk/src/moul/crypt/binary.py 2007-04-16 18:45:31 UTC (rev 283) @@ -102,17 +102,19 @@ if self.version in (0, 5): size = size & 0x0FFF if size > 1024: # XXX: ??? - raise ValueError("size '%i' > 1024 at position %s(%s)" % + raise ValueError("size '%i' > 1024 at position %s(%s)" % (size, fd.tell(), repr(fd))) if self.version == 5: # XXX: testme # read data as tuple of integeres - data = fd.readPacked("<%iI" % size) + #data = fd.readPacked("<%iB" % size) + data = fd.read(size) # OR integers with 0xff and write their char equivalent to string - result = ''.join([chr(d ^ 0xff) for d in data]) + result = ''.join([chr(ord(d) ^ 0xff) for d in data]) elif self.version == 6: - data = fd.readPacked("<%iI" % size) - result = ''.join([chr(d ^ self.MYST5KEY[i%8]) + #data = fd.readPacked("<%iB" % size) + data = fd.read(size) + result = ''.join([chr(ord(d) ^ self.MYST5KEY[i%8]) for i, d in enumerate(data)]) else: result = fd.read(size) Added: pymoul/trunk/src/moul/file/pak.py =================================================================== --- pymoul/trunk/src/moul/file/pak.py (rev 0) +++ pymoul/trunk/src/moul/file/pak.py 2007-04-16 18:45:31 UTC (rev 283) @@ -0,0 +1,72 @@ +# pyMoul - Python interface to Myst Online URU Live +# Copyright (C) 2007 Christian Heimes <christian (at) cheimes (dot) de> + +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation; either version 2 of the License, or (at your +# option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +# more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., 59 +# Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +"""Python PAK reader (for TPOS) +""" +__author__ = "Christian Heimes" +__version__ = "$Id: utils.py 187 2007-02-23 16:41:50Z tiran $" +__revision__ = "$Revision: 187 $" + +import os + +from moul.crypt.binary import BinaryFile + +class PAKReader(object): + """Read Python pak + """ + magic = '\x3b\xf2\x0d\x0a\x00\x00\x00\x00' + + def __init__(self, fname): + self._fname = fname + self._fd = BinaryFile(fname, 'rb') + self._files = {} + self._parseHeader() + + def _parseHeader(self): + """Parse PAK header + """ + fd = self._fd + fd.seek(0) + count = fd.read32() + for i in range(count): + name = fd.readUruString() + 'c' # pyc + offset = fd.read32() + self._files[name] = offset + + def names(): + return self._files.keys() + + def getPycFile(self, name): + fd = self._fd + offset = self._files[name] + fd.seek(offset) + size = fd.read32() + data = fd.read(size) + return self.magic + data + + def dump(self, path, create=False): + if create: + os.mkdir(path) + for name in self._files: + fd = open(os.path.join(path, name), 'wb') + fd.write(self.getPycFile(name)) + fd.close() + +if __name__ == '__main__': + pak = PAKReader('python.pak') + pak.dump('pyc', True) + Property changes on: pymoul/trunk/src/moul/file/pak.py ___________________________________________________________________ Name: svn:keywords + 'Id Revision' Name: svn:eol-style + native Added: pymoul/trunk/src/moul/file/sdl.py =================================================================== --- pymoul/trunk/src/moul/file/sdl.py (rev 0) +++ pymoul/trunk/src/moul/file/sdl.py 2007-04-16 18:45:31 UTC (rev 283) @@ -0,0 +1,117 @@ +# pyMoul - Python interface to Myst Online URU Live +# Copyright (C) 2007 Christian Heimes <christian (at) cheimes (dot) de> + +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation; either version 2 of the License, or (at your +# option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +# more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., 59 +# Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +"""SDL files (for TPOS) +""" +__author__ = "Christian Heimes" +__version__ = "$Id: utils.py 187 2007-02-23 16:41:50Z tiran $" +__revision__ = "$Revision: 187 $" + +import os +import re + + +class SDLReader(object): + """Read Python pak + + >>> mo = SDLReader.comment.match('abc # def # efg') + >>> mo.group('content') + 'abc ' + + >>> mo = SDLReader.comment.match('abc') + >>> mo.group('content') + 'abc' + + >>> mo = SDLReader.comment.match('# abc') + >>> mo.group('content') + '' + + >>> mo = SDLReader.statedesc.match('STATEDESC testage') + >>> mo.group('name') + 'testage' + + >>> mo = SDLReader.version.match(' VERSION 5') + >>> mo.group('version') + '5' + + >>> mo = SDLReader.var.search('VAR BOOL testvar[1] DEFAULT=1') + >>> mo.group('type') + 'BOOL' + >>> mo.group('name') + 'testvar' + >>> mo.group('tail') + ' DEFAULT=1' + """ + comment = re.compile("^(?P<content>[^#]*)") # non greedy match + statedesc = re.compile("^STATEDESC[ ]+(?P<name>\w+)") + version = re.compile("[ \t]*VERSION[ ]+(?P<version>\d+)") + var = re.compile("VAR[ ]+(?P<type>\w+)[ ]+(?P<name>[$\w]+)\[1\](?P<tail>.*)") + def __init__(self, fname): + self._fname = fname + self._fd = open(fname, 'r') + self.states = [] + self._parseFile() + + def _parseFile(self): + for line in self._fd: + #line = self.comment.match(line).group('content') + mo = self.statedesc.match(line) + if mo: + self.states.append(mo.group('name') + +class SDLStates(object): + """SDL state object + """ + def __init__(self, name): + self._name = name.strip() + self._version = None + self._vars = [] + + def _getVersion(self): + return self._version + def _setVersion(self, version): + self._version = int(version) + version = property(_getVersion, _setVersion) + + @property + def id(self): + return "%s:%i" % (self.name, self.version) + + @property + def name(self): + return self._name + + def addVarTail(self, name, typ, tail): + elements = [el.strip() for el in tail.split('=')] + kwargs = {} + for name in ('DEFAULT', 'DEFAULTOPTION', 'DISPLAYOPTION'): + idx = elements.index(name) + if idx > -1: + kwargs[name.lower()] = elements[idx+1] + sdl = SDLVar(name, typ, **kwargs) + self._vars.append(sdl) + +class SDLVar(object): + """SDL variable + """ + def __init__(self, name, typ, default=None, defaultoption=None, + displayoption=None): + self._name = name + self._typ = typ + self._default = default + self._defaultoption = defaultoption + self._displayoption = displayoption Property changes on: pymoul/trunk/src/moul/file/sdl.py ___________________________________________________________________ Name: svn:keywords + 'Id Revision' Name: svn:eol-style + native Added: pymoul/trunk/src/moul/file/tests/test_sdl.py =================================================================== --- pymoul/trunk/src/moul/file/tests/test_sdl.py (rev 0) +++ pymoul/trunk/src/moul/file/tests/test_sdl.py 2007-04-16 18:45:31 UTC (rev 283) @@ -0,0 +1,34 @@ +# pyMoul - Python interface to Myst Online URU Live +# Copyright (C) 2007 Christian Heimes <christian (at) cheimes (dot) de> + +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the +# Free Software Foundation; either version 2 of the License, or (at your +# option) any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +# more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., 59 +# Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +"""moul.file.sdl unit tests +""" +__author__ = "Christian Heimes" +__version__ = "$Id: test_plasmalog.py 140 2007-02-05 14:51:30Z tiran $" +__revision__ = "$Revision: 140 $" + +import os +import unittest +from doctest import DocTestSuite + +def test_suite(): + return unittest.TestSuite(( + DocTestSuite('moul.file.sdl') + )) + +if __name__ == '__main__': + unittest.main(defaultTest="test_suite") Property changes on: pymoul/trunk/src/moul/file/tests/test_sdl.py ___________________________________________________________________ Name: svn:keywords + 'Id Revision' Name: svn:eol-style + native This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |