[Pymoul-svn] SF.net SVN: pymoul: [26] pymoul/trunk
Status: Alpha
Brought to you by:
tiran
|
From: <ti...@us...> - 2007-01-15 17:50:07
|
Revision: 26
http://pymoul.svn.sourceforge.net/pymoul/?rev=26&view=rev
Author: tiran
Date: 2007-01-15 09:28:51 -0800 (Mon, 15 Jan 2007)
Log Message:
-----------
Added dummy i18n message and message factory inspired by Zope3
Added unit test packages and first doc test
Modified Paths:
--------------
pymoul/trunk/src/moul/config/generic.py
pymoul/trunk/src/moul/crypt/elf.py
pymoul/trunk/src/moul/crypt/whatdoyousee.py
pymoul/trunk/src/moul/log.py
pymoul/trunk/src/moul/time/dni.py
Added Paths:
-----------
pymoul/trunk/src/moul/cli/tests/
pymoul/trunk/src/moul/cli/tests/__init__.py
pymoul/trunk/src/moul/config/tests/
pymoul/trunk/src/moul/config/tests/__init__.py
pymoul/trunk/src/moul/crypt/tests/
pymoul/trunk/src/moul/crypt/tests/__init__.py
pymoul/trunk/src/moul/file/tests/
pymoul/trunk/src/moul/file/tests/__init__.py
pymoul/trunk/src/moul/i18n.py
pymoul/trunk/src/moul/qt/tests/
pymoul/trunk/src/moul/qt/tests/__init__.py
pymoul/trunk/src/moul/tests/__init__.py
pymoul/trunk/src/moul/tests/test_i18n.py
pymoul/trunk/src/moul/time/tests/
pymoul/trunk/src/moul/time/tests/__init__.py
Removed Paths:
-------------
pymoul/trunk/src/moul/crypt/bitops.py
Property Changed:
----------------
pymoul/trunk/test.py
Added: pymoul/trunk/src/moul/cli/tests/__init__.py
===================================================================
--- pymoul/trunk/src/moul/cli/tests/__init__.py (rev 0)
+++ pymoul/trunk/src/moul/cli/tests/__init__.py 2007-01-15 17:28:51 UTC (rev 26)
@@ -0,0 +1,2 @@
+# testing package
+
Modified: pymoul/trunk/src/moul/config/generic.py
===================================================================
--- pymoul/trunk/src/moul/config/generic.py 2007-01-15 16:08:38 UTC (rev 25)
+++ pymoul/trunk/src/moul/config/generic.py 2007-01-15 17:28:51 UTC (rev 26)
@@ -17,20 +17,6 @@
#
"""cross platform configuration tools for pyMoul
"""
-from ConfigParser import SafeConfigParser
-
-class PyMoulConfig(object):
- _default = {
- 'pyMoul': {
- 'moul_install_dir' : 'C:\\Program Files\\Myst Online',
- }
- }
-
- def __init__(self, fname):
- self._parser = SafeConfigParser()
- self._fname = fname
- self._data = {}
-
# Stub for platform specific functions
def getMoulUserDataDir():
"""Get path of MOUL user data directory
Added: pymoul/trunk/src/moul/config/tests/__init__.py
===================================================================
--- pymoul/trunk/src/moul/config/tests/__init__.py (rev 0)
+++ pymoul/trunk/src/moul/config/tests/__init__.py 2007-01-15 17:28:51 UTC (rev 26)
@@ -0,0 +1,2 @@
+# testing package
+
Deleted: pymoul/trunk/src/moul/crypt/bitops.py
===================================================================
--- pymoul/trunk/src/moul/crypt/bitops.py 2007-01-15 16:08:38 UTC (rev 25)
+++ pymoul/trunk/src/moul/crypt/bitops.py 2007-01-15 17:28:51 UTC (rev 26)
@@ -1,49 +0,0 @@
-# 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
-#
-"""Misc bit operation helpers
-"""
-# str2int, lshift, rshift, list2int, list2str
-
-def str2int(s):
- """converts a string to an integer"""
- out = 0
- for i, e in enumerate(s):
- out += ord(e) << 8*i
- return out
-
-def int2str(i):
- """ """
- out = []
- for j in (0,1,2,3):
- s = rshift(i, 8*j)
- out.append(chr(s))
- return ''.join(out)
-
-def lshift(a, b, mask=0xff):
- """8 bit integer <<"""
- return (a << b) & mask
-
-def rshift(a, b, mask=0xff):
- """8 bit integer >>"""
- return (a >> b) & mask
-
-def list2int(lst):
- return [ord(s) for s in lst]
-
-def list2str(lst):
- return [chr(s) for s in lst]
Modified: pymoul/trunk/src/moul/crypt/elf.py
===================================================================
--- pymoul/trunk/src/moul/crypt/elf.py 2007-01-15 16:08:38 UTC (rev 25)
+++ pymoul/trunk/src/moul/crypt/elf.py 2007-01-15 17:28:51 UTC (rev 26)
@@ -19,8 +19,12 @@
Based on the C++ code from Marack
"""
-from mounl.crypt.bitops import str2int, lshift, rshift, list2int, list2str
+def list2int(lst):
+ return [ord(s) for s in lst]
+def list2str(lst):
+ return [chr(s) for s in lst]
+
def decryptElf(fin):
"""Decrypts an encrypted log file (MOUL elf file)
@@ -65,20 +69,20 @@
b = key
d = v[0]
d = d ^ b
- d = rshift(d, 5) # d >> 5
+ d = (d >> 5) & 0xff
i = size - 1
while i >=0:
a = v[i]
a = a ^ b
c = a
- a = lshift(a, 3) # a << 3
+ a = (a << 3) & 0xff
a = a | d
d = a
- d = rshift(d, 6) # d >> 6
- a = lshift(a, 2) # a << 2
+ d = (d >> 6) & 0xff
+ a = (a << 2) & 0xff
d = d | a
- c = rshift(c, 5) # c >> 5
+ c = (c >> 5) & 0xff
v[i] = d
d = c
@@ -97,28 +101,24 @@
# Startup
c = v[len - 1];
c &= 0xfc;
- c = lshift(c, 3) # c << 3;
+ c = (c << 3) & 0xff
i = 0
while i < len:
d = v[i]
a = d
- a = lshift(a, 6) # a << 6
- d = rshift(d, 2) # d >> 2
+ a = (a << 6) & 0xff
+ d = (d >> 2) & 0xff
a = a | d
d = a
- a = rshift(a, 3) # a >> 3
+ a = (a >> 3) & 0xff
a = a | c
c = key
a = a ^ c
- d = lshift(d, 5) # d << 5
+ d = (d << 5) & 0xff
v[i] = a
c = d
i+=1
return ''.join(list2str(v))
-
-if __name__ == '__main__':
- fd = open("Python.0.elf", 'rb')
- print '\n'.join(decryptElf(fd))
Added: pymoul/trunk/src/moul/crypt/tests/__init__.py
===================================================================
--- pymoul/trunk/src/moul/crypt/tests/__init__.py (rev 0)
+++ pymoul/trunk/src/moul/crypt/tests/__init__.py 2007-01-15 17:28:51 UTC (rev 26)
@@ -0,0 +1,2 @@
+# testing package
+
Modified: pymoul/trunk/src/moul/crypt/whatdoyousee.py
===================================================================
--- pymoul/trunk/src/moul/crypt/whatdoyousee.py 2007-01-15 16:08:38 UTC (rev 25)
+++ pymoul/trunk/src/moul/crypt/whatdoyousee.py 2007-01-15 17:28:51 UTC (rev 26)
@@ -26,8 +26,6 @@
"""
import struct
-from moul.crypt.bitops import str2int
-from moul.crypt.bitops import int2str
from moul.crypt.xtea import xtea_decrypt
from moul.crypt.xtea import xtea_encrypt
@@ -48,7 +46,7 @@
raise IOError("Not a whatdoyousee/xTEA encrypted file")
header = fin.read(4)
- length = str2int(header)
+ struct.unpack(ENDIAN+"L", header)
out = []
pos = 0
@@ -74,7 +72,7 @@
fout.write(HEADER)
flen = len(instr)
- length = int2str(flen)
+ length = struct.pack(ENDIAN+"L", flen)
fout.write(length)
pos = 0
Added: pymoul/trunk/src/moul/file/tests/__init__.py
===================================================================
--- pymoul/trunk/src/moul/file/tests/__init__.py (rev 0)
+++ pymoul/trunk/src/moul/file/tests/__init__.py 2007-01-15 17:28:51 UTC (rev 26)
@@ -0,0 +1,2 @@
+# testing package
+
Added: pymoul/trunk/src/moul/i18n.py
===================================================================
--- pymoul/trunk/src/moul/i18n.py (rev 0)
+++ pymoul/trunk/src/moul/i18n.py 2007-01-15 17:28:51 UTC (rev 26)
@@ -0,0 +1,91 @@
+# 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
+#
+"""pyMoul i18n
+
+A dumb and do nearly nothing i18n message factory and message implementation.
+It's a kind of a place holder.
+
+Inspired by zope.i18nmessage
+
+>>> _ = MessageFactory('test')
+>>> msg = _(u'test')
+>>> msg
+u'test'
+>>> msg.domain
+'test'
+>>> msg.default
+u'test'
+>>> msg.mapping is None
+True
+
+>>> template = _(u'id', u'This is a ${name}!')
+>>> template
+u'id'
+>>> template % {'name' : u'test'}
+u'This is a test!'
+>>> template % {'name' : u'another test'}
+u'This is a another test!'
+
+>>> error = _('id')
+Traceback (most recent call last):
+...
+TypeError: ustr must be a unicode string
+>>> error = _(u'id', 'This is a ${name}!')
+Traceback (most recent call last):
+...
+TypeError: default must be a unicode string
+"""
+from string import Template
+
+__all__ = ['_', 'PymoulMessageFactory', 'MessageFactory']
+
+class Message(unicode, Template):
+ __slots__ = ('domain', 'default', 'mapping')
+
+ def __new__(cls, ustr, domain=None, default=None, mapping=None):
+ if not isinstance(ustr, unicode):
+ raise TypeError("ustr must be a unicode string")
+ if default is not None and not isinstance(default, unicode):
+ raise TypeError("default must be a unicode string")
+
+ self = unicode.__new__(cls, ustr)
+ self.domain = domain
+ if default is None:
+ self.default = unicode(ustr)
+ else:
+ self.default = unicode(default)
+ self.mapping = mapping
+ return self
+
+ def __init__(self, *args, **kwargs):
+ return Template.__init__(self, self.default)
+
+ def __mod__(self, other):
+ return self.substitute(other)
+
+class MessageFactory(object):
+ """Factory for Messages"""
+
+ def __init__(self, domain):
+ self._domain = domain
+
+ def __call__(self, ustr, default=None, mapping=None):
+ return Message(ustr, self._domain, default, mapping)
+
+_ = PymoulMessageFactory = MessageFactory('pymoul')
+
Modified: pymoul/trunk/src/moul/log.py
===================================================================
--- pymoul/trunk/src/moul/log.py 2007-01-15 16:08:38 UTC (rev 25)
+++ pymoul/trunk/src/moul/log.py 2007-01-15 17:28:51 UTC (rev 26)
@@ -25,5 +25,4 @@
)
LOG = logging.getLogger('pyMoul')
-
-
+getLogger = logging.getLogger
Added: pymoul/trunk/src/moul/qt/tests/__init__.py
===================================================================
--- pymoul/trunk/src/moul/qt/tests/__init__.py (rev 0)
+++ pymoul/trunk/src/moul/qt/tests/__init__.py 2007-01-15 17:28:51 UTC (rev 26)
@@ -0,0 +1,2 @@
+# testing package
+
Added: pymoul/trunk/src/moul/tests/__init__.py
===================================================================
--- pymoul/trunk/src/moul/tests/__init__.py (rev 0)
+++ pymoul/trunk/src/moul/tests/__init__.py 2007-01-15 17:28:51 UTC (rev 26)
@@ -0,0 +1,2 @@
+# testing package
+
Added: pymoul/trunk/src/moul/tests/test_i18n.py
===================================================================
--- pymoul/trunk/src/moul/tests/test_i18n.py (rev 0)
+++ pymoul/trunk/src/moul/tests/test_i18n.py 2007-01-15 17:28:51 UTC (rev 26)
@@ -0,0 +1,28 @@
+# 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
+#
+import unittest
+from doctest import DocTestSuite
+
+def test_suite():
+ return unittest.TestSuite((
+ DocTestSuite('moul.i18n'),
+ ))
+
+if __name__ == '__main__':
+ unittest.main(defaultTest="test_suite")
+
Modified: pymoul/trunk/src/moul/time/dni.py
===================================================================
--- pymoul/trunk/src/moul/time/dni.py 2007-01-15 16:08:38 UTC (rev 25)
+++ pymoul/trunk/src/moul/time/dni.py 2007-01-15 17:28:51 UTC (rev 26)
@@ -29,7 +29,7 @@
('tah-vo', 25),
('gor-ahn', 25),
('pro-rahn', 1),
- )
+)
VAILATEE = (
('Leefo', ( 4, 21), ( 5, 27)), # 1: April 21st to May 27th
@@ -42,7 +42,8 @@
('Leevosahn', ( 1, 2), ( 2, 7)), # 8: January 2nd to February 7th
('Leevotar', ( 2, 7), ( 3, 15)), # 9: February 7th to March 15th
('Leenovoo', ( 3, 16), ( 4, 21)), # 10: March 16th to April 21st
- )
+)
+
PRORAHN_PER_HAHR = reduce(mul,
[float(factor) for name, factor in DNI_FACTORS[1:-1]])
Added: pymoul/trunk/src/moul/time/tests/__init__.py
===================================================================
--- pymoul/trunk/src/moul/time/tests/__init__.py (rev 0)
+++ pymoul/trunk/src/moul/time/tests/__init__.py 2007-01-15 17:28:51 UTC (rev 26)
@@ -0,0 +1,2 @@
+# testing package
+
Property changes on: pymoul/trunk/test.py
___________________________________________________________________
Name: svn:executable
+ *
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|