pymoul-svn Mailing List for pyMoul (Page 4)
Status: Alpha
Brought to you by:
tiran
You can subscribe to this list here.
2007 |
Jan
(89) |
Feb
(108) |
Mar
(62) |
Apr
(8) |
May
(9) |
Jun
(2) |
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
---|
From: <ti...@us...> - 2007-03-02 16:28:17
|
Revision: 224 http://pymoul.svn.sourceforge.net/pymoul/?rev=224&view=rev Author: tiran Date: 2007-03-02 08:28:11 -0800 (Fri, 02 Mar 2007) Log Message: ----------- Redesign of the package. Moved common stuf to common Fixed broken naming in pyx code Modified Paths: -------------- xtea/trunk/src/xtea/__init__.py xtea/trunk/src/xtea/_xtea.c xtea/trunk/src/xtea/_xtea.pyx xtea/trunk/src/xtea/cxtea.c xtea/trunk/src/xtea/cxtea.h xtea/trunk/src/xtea/tests.py xtea/trunk/src/xtea/xtea.py Added Paths: ----------- xtea/trunk/src/xtea/_common.py Modified: xtea/trunk/src/xtea/__init__.py =================================================================== --- xtea/trunk/src/xtea/__init__.py 2007-03-02 14:54:09 UTC (rev 223) +++ xtea/trunk/src/xtea/__init__.py 2007-03-02 16:28:11 UTC (rev 224) @@ -1,7 +1,11 @@ # xtea package -from xtea import new -from xtea import MODE_ECB -from xtea import MODE_OFB -from xtea import BIG_ENDIAN -from xtea import LITTLE_ENDIAN -from xtea import NETWORK_ENDIAN +from xtea import XTEA +#from xxtea import XXTEA + +from _common import MODE_ECB +from _common import MODE_OFB +from _common import BIG_ENDIAN +from _common import LITTLE_ENDIAN +from _common import NETWORK_ENDIAN +from _common import HOST_ENDIAN +from _common import pad Added: xtea/trunk/src/xtea/_common.py =================================================================== --- xtea/trunk/src/xtea/_common.py (rev 0) +++ xtea/trunk/src/xtea/_common.py 2007-03-02 16:28:11 UTC (rev 224) @@ -0,0 +1,151 @@ +""" +""" +from struct import pack +from struct import unpack +import sys + +__all__ = ['MODE_ECB', 'MODE_OFB', 'BIG_ENDIAN', 'LITTLE_ENDIAN', + 'NETWORK_ENDIAN', 'HOST_ENDIAN', 'pad'] + +MODE_ECB = 1 # Electronic Code Book +MODE_CBC = 2 # Cipher Block Chaining +MODE_CFB = 4 # Cipher Feedback +MODE_OFB = 5 # Output Feedback +MODE_CTR = 6 # Counter +BIG_ENDIAN = 'big' +LITTLE_ENDIAN = 'little' +NETWORK_ENDIAN = LITTLE_ENDIAN +HOST_ENDIAN = sys.byteorder +NULL='\x00' +ULONG_SIZE=4 + +def pad(s, align, char=NULL): + """Pad string 's' to 'align' number of elements with char 'char' + + >>> pad('abcd', 4) + 'abcd' + >>> pad('abcdabcd', 4) + 'abcdabcd' + >>> pad('abcdef', 4) + 'abcdef\\x00\\x00' + >>> pad('abcdef', 4, char='0') + 'abcdef00' + """ + mod = len(s) % align + if mod != 0: + return s+mod*char + else: + return s + +class _AbstractTEA(object): + """Abstract TEA base class + """ + @property + def key_size(self): + """Size of key + """ + return 16 + + @property + def block_size(self): + """Size of blocks + """ + return 8 + + @property + def default_rounds(self): + """Default number of rounds + """ + return 32 + + def __init__(self, key, mode=MODE_ECB, IV=8*NULL, rounds=None, + endian=HOST_ENDIAN, counter=None, segment_size=None): + if endian == BIG_ENDIAN: + self._endian = ">" + elif endian == LITTLE_ENDIAN: + self._endian = "<" + else: + raise ValueError("Unknown endian: %s" % endian) + + ks = self.key_size + if isinstance(key, tuple): + if len(key) != ks/ULONG_SIZE: + raise ValueError("Invalid key size") + for e in key: + if not isinstance(e, (long, int)): + raise TypeError("Wrong type %s in key" % repr(e)) + self._key = key + elif isinstance(key, str): + if len(key) != ks: + raise ValueError("Invalid key size") + self._key = unpack("%s%iL" % (self._endian, ks/ULONG_SIZE), key) + else: + raise TypeError("Invalid key type") + + if mode == MODE_ECB: + pass + elif mode == MODE_OFB: + if not isinstance(IV, str) or len(IV) != self.block_size: + raise ValueError("Invalid IV") + else: + raise ValueError("Unknown or unsupported mode") + self._mode = mode + self._iv = IV + + if rounds is None: + rounds = self.default_rounds + if rounds < 2 or not isinstance(rounds, int): + raise ValueError("Invalid rounds") + self._rounds = rounds + self._counter = counter + self._segment_size = segment_size + + @classmethod + def new(cls, key, **kwargs): + """PEP 272 conform constructor + """ + return cls(key, **kwargs) + + def encrypt(self, block): + """Encrypt a block + + @param block: block to encrypt + @type block: str + """ + if self._mode == MODE_ECB: + return self._ecb(block, func=self._encrypt) + elif self._mode == MODE_OFB: + return self._ofb(block) + else: + raise ValueError("Unknown or unsupported mode") + + def decrypt(self, block): + """Decrypt a block + + @param block: block to decrypt + @type block: str + """ + if self._mode == MODE_ECB: + return self._ecb(block, func=self._decrypt) + elif self._mode == MODE_OFB: + return self._ofb(block) + else: + raise ValueError("Unknown or unsupported mode") + + _decrypt = None + _encrypt = None + + def _ecb(self, block, func): + """Electronic Code Book encryption/decryption + + @type block: str + @param func: decrypt or encrypt function + @type func: callable + """ + raise NotImplementedError + + def _ofb(self, block): + """Output Feedback (OFB) encryption requires an IV + """ + raise NotImplementedError + Property changes on: xtea/trunk/src/xtea/_common.py ___________________________________________________________________ Name: svn:keywords + 'Id Revision' Name: svn:eol-style + native Modified: xtea/trunk/src/xtea/_xtea.c =================================================================== --- xtea/trunk/src/xtea/_xtea.c 2007-03-02 14:54:09 UTC (rev 223) +++ xtea/trunk/src/xtea/_xtea.c 2007-03-02 16:28:11 UTC (rev 224) @@ -1,4 +1,4 @@ -/* Generated by Pyrex 0.9.4.1 on Fri Mar 2 15:53:19 2007 */ +/* Generated by Pyrex 0.9.5.1a on Fri Mar 2 17:24:15 2007 */ #include "Python.h" #include "structmember.h" @@ -17,26 +17,6 @@ typedef struct {PyObject **p; char *s;} __Pyx_InternTabEntry; /*proto*/ typedef struct {PyObject **p; char *s; long n;} __Pyx_StringTabEntry; /*proto*/ -static PyObject *__Pyx_UnpackItem(PyObject *, int); /*proto*/ -static int __Pyx_EndUnpack(PyObject *, int); /*proto*/ -static int __Pyx_PrintItem(PyObject *); /*proto*/ -static int __Pyx_PrintNewline(void); /*proto*/ -static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb); /*proto*/ -static void __Pyx_ReRaise(void); /*proto*/ -static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list); /*proto*/ -static PyObject *__Pyx_GetExcValue(void); /*proto*/ -static int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed, char *name); /*proto*/ -static int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type); /*proto*/ -static int __Pyx_GetStarArgs(PyObject **args, PyObject **kwds, char *kwd_list[], int nargs, PyObject **args2, PyObject **kwds2); /*proto*/ -static void __Pyx_WriteUnraisable(char *name); /*proto*/ -static void __Pyx_AddTraceback(char *funcname); /*proto*/ -static PyTypeObject *__Pyx_ImportType(char *module_name, char *class_name, long size); /*proto*/ -static int __Pyx_SetVtable(PyObject *dict, void *vtable); /*proto*/ -static int __Pyx_GetVtable(PyObject *dict, void *vtabptr); /*proto*/ -static PyObject *__Pyx_CreateClass(PyObject *bases, PyObject *dict, PyObject *name, char *modname); /*proto*/ -static int __Pyx_InternStrings(__Pyx_InternTabEntry *t); /*proto*/ -static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /*proto*/ -static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name); /*proto*/ static PyObject *__pyx_m; static PyObject *__pyx_b; @@ -44,20 +24,32 @@ static char *__pyx_filename; static char **__pyx_f; +static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name); /*proto*/ + +static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb); /*proto*/ + +static int __Pyx_InternStrings(__Pyx_InternTabEntry *t); /*proto*/ + +static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /*proto*/ + +static void __Pyx_AddTraceback(char *funcname); /*proto*/ + /* Declarations from _xtea */ + /* Implementation of _xtea */ -static PyObject *__pyx_n__c_xtea_encryptQuad; -static PyObject *__pyx_n__c_xxtea_decryptQuad; +static PyObject *__pyx_n__c_xtea_encrypt; +static PyObject *__pyx_n__c_xtea_decrypt; static PyObject *__pyx_n__c_xxtea_encrypt; static PyObject *__pyx_n__c_xxtea_decrypt; +static PyObject *__pyx_n_XXX_c_xxtea_encrypt; +static PyObject *__pyx_n_XXX_c_xxtea_decrypt; -static PyObject *__pyx_f_5_xtea__c_xtea_encryptQuad(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static PyObject *__pyx_f_5_xtea__c_xtea_encryptQuad(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - unsigned long __pyx_v_v0; - unsigned long __pyx_v_v1; +static PyObject *__pyx_f_5_xtea__c_xtea_encrypt(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_f_5_xtea__c_xtea_encrypt(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_block = 0; PyObject *__pyx_v_key = 0; unsigned int __pyx_v_rounds; unsigned long (__pyx_v_v[2]); @@ -69,17 +61,28 @@ PyObject *__pyx_2 = 0; unsigned long __pyx_3; PyObject *__pyx_4 = 0; - static char *__pyx_argnames[] = {"v0","v1","key","rounds",0}; - if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "kkOI", __pyx_argnames, &__pyx_v_v0, &__pyx_v_v1, &__pyx_v_key, &__pyx_v_rounds)) return 0; + static char *__pyx_argnames[] = {"block","key","rounds",0}; + if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "OOI", __pyx_argnames, &__pyx_v_block, &__pyx_v_key, &__pyx_v_rounds)) return 0; + Py_INCREF(__pyx_v_block); Py_INCREF(__pyx_v_key); __pyx_v_rc = Py_None; Py_INCREF(Py_None); __pyx_v_result = Py_None; Py_INCREF(Py_None); /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":25 */ - (__pyx_v_v[0]) = __pyx_v_v0; + __pyx_1 = PyInt_FromLong(0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_block, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + __pyx_3 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + (__pyx_v_v[0]) = __pyx_3; /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":25 */ - (__pyx_v_v[1]) = __pyx_v_v1; + __pyx_1 = PyInt_FromLong(1); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_block, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + __pyx_3 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + (__pyx_v_v[1]) = __pyx_3; /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":26 */ __pyx_1 = PyInt_FromLong(0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 26; goto __pyx_L1;} @@ -142,19 +145,19 @@ Py_XDECREF(__pyx_1); Py_XDECREF(__pyx_2); Py_XDECREF(__pyx_4); - __Pyx_AddTraceback("_xtea._c_xtea_encryptQuad"); + __Pyx_AddTraceback("_xtea._c_xtea_encrypt"); __pyx_r = 0; __pyx_L0:; Py_DECREF(__pyx_v_rc); Py_DECREF(__pyx_v_result); + Py_DECREF(__pyx_v_block); Py_DECREF(__pyx_v_key); return __pyx_r; } -static PyObject *__pyx_f_5_xtea__c_xxtea_decryptQuad(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static PyObject *__pyx_f_5_xtea__c_xxtea_decryptQuad(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { - unsigned long __pyx_v_v0; - unsigned long __pyx_v_v1; +static PyObject *__pyx_f_5_xtea__c_xtea_decrypt(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_f_5_xtea__c_xtea_decrypt(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_block = 0; PyObject *__pyx_v_key = 0; unsigned int __pyx_v_rounds; unsigned long (__pyx_v_v[2]); @@ -166,17 +169,28 @@ PyObject *__pyx_2 = 0; unsigned long __pyx_3; PyObject *__pyx_4 = 0; - static char *__pyx_argnames[] = {"v0","v1","key","rounds",0}; - if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "kkOI", __pyx_argnames, &__pyx_v_v0, &__pyx_v_v1, &__pyx_v_key, &__pyx_v_rounds)) return 0; + static char *__pyx_argnames[] = {"block","key","rounds",0}; + if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "OOI", __pyx_argnames, &__pyx_v_block, &__pyx_v_key, &__pyx_v_rounds)) return 0; + Py_INCREF(__pyx_v_block); Py_INCREF(__pyx_v_key); __pyx_v_rc = Py_None; Py_INCREF(Py_None); __pyx_v_result = Py_None; Py_INCREF(Py_None); /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":34 */ - (__pyx_v_v[0]) = __pyx_v_v0; + __pyx_1 = PyInt_FromLong(0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_block, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + __pyx_3 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + (__pyx_v_v[0]) = __pyx_3; /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":34 */ - (__pyx_v_v[1]) = __pyx_v_v1; + __pyx_1 = PyInt_FromLong(1); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_block, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + __pyx_3 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + (__pyx_v_v[1]) = __pyx_3; /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":35 */ __pyx_1 = PyInt_FromLong(0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 35; goto __pyx_L1;} @@ -211,7 +225,7 @@ (__pyx_v_k[3]) = __pyx_3; /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":36 */ - __pyx_1 = PyInt_FromLong(xxtea_decipher(__pyx_v_v,__pyx_v_k,__pyx_v_rounds)); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; goto __pyx_L1;} + __pyx_1 = PyInt_FromLong(xtea_decipher(__pyx_v_v,__pyx_v_k,__pyx_v_rounds)); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; goto __pyx_L1;} Py_DECREF(__pyx_v_rc); __pyx_v_rc = __pyx_1; __pyx_1 = 0; @@ -239,18 +253,24 @@ Py_XDECREF(__pyx_1); Py_XDECREF(__pyx_2); Py_XDECREF(__pyx_4); - __Pyx_AddTraceback("_xtea._c_xxtea_decryptQuad"); + __Pyx_AddTraceback("_xtea._c_xtea_decrypt"); __pyx_r = 0; __pyx_L0:; Py_DECREF(__pyx_v_rc); Py_DECREF(__pyx_v_result); + Py_DECREF(__pyx_v_block); Py_DECREF(__pyx_v_key); return __pyx_r; } static PyObject *__pyx_n_len; +static PyObject *__pyx_n_ValueError; static PyObject *__pyx_n_append; +static PyObject *__pyx_k1p; + +static char (__pyx_k1[]) = "len(block) %i != rounds %i"; + static PyObject *__pyx_f_5_xtea__c_xxtea_encrypt(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static PyObject *__pyx_f_5_xtea__c_xxtea_encrypt(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyObject *__pyx_v_block = 0; @@ -268,7 +288,8 @@ PyObject *__pyx_2 = 0; PyObject *__pyx_3 = 0; int __pyx_4; - unsigned long __pyx_5; + PyObject *__pyx_5 = 0; + unsigned long __pyx_6; static char *__pyx_argnames[] = {"block","key","rounds",0}; if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "OOI", __pyx_argnames, &__pyx_v_block, &__pyx_v_key, &__pyx_v_rounds)) return 0; Py_INCREF(__pyx_v_block); @@ -288,87 +309,106 @@ __pyx_v_size = __pyx_4; /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":44 */ + __pyx_4 = (__pyx_v_size != __pyx_v_rounds); + if (__pyx_4) { + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":45 */ + __pyx_1 = __Pyx_GetName(__pyx_b, __pyx_n_ValueError); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 45; goto __pyx_L1;} + __pyx_2 = PyInt_FromLong(__pyx_v_size); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 45; goto __pyx_L1;} + __pyx_3 = PyLong_FromUnsignedLong(__pyx_v_rounds); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 45; goto __pyx_L1;} + __pyx_5 = PyTuple_New(2); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 45; goto __pyx_L1;} + PyTuple_SET_ITEM(__pyx_5, 0, __pyx_2); + PyTuple_SET_ITEM(__pyx_5, 1, __pyx_3); + __pyx_2 = 0; + __pyx_3 = 0; + __pyx_2 = PyNumber_Remainder(__pyx_k1p, __pyx_5); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 45; goto __pyx_L1;} + Py_DECREF(__pyx_5); __pyx_5 = 0; + __Pyx_Raise(__pyx_1, __pyx_2, 0); + Py_DECREF(__pyx_1); __pyx_1 = 0; + Py_DECREF(__pyx_2); __pyx_2 = 0; + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 45; goto __pyx_L1;} + goto __pyx_L2; + } + __pyx_L2:; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":46 */ __pyx_v_vsize = ((sizeof(unsigned long )) * __pyx_v_size); - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":45 */ + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":47 */ __pyx_v_v = ((unsigned long (*))malloc(__pyx_v_vsize)); - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":46 */ + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":48 */ for (__pyx_v_i = 0; __pyx_v_i < __pyx_v_size; ++__pyx_v_i) { - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":47 */ - __pyx_1 = PyInt_FromLong(__pyx_v_i); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 47; goto __pyx_L1;} - __pyx_2 = PyObject_GetItem(__pyx_v_block, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 47; goto __pyx_L1;} - Py_DECREF(__pyx_1); __pyx_1 = 0; - __pyx_5 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 47; goto __pyx_L1;} - Py_DECREF(__pyx_2); __pyx_2 = 0; - (__pyx_v_v[__pyx_v_i]) = __pyx_5; - __pyx_L2:; + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":49 */ + __pyx_3 = PyInt_FromLong(__pyx_v_i); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; goto __pyx_L1;} + __pyx_5 = PyObject_GetItem(__pyx_v_block, __pyx_3); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; goto __pyx_L1;} + Py_DECREF(__pyx_3); __pyx_3 = 0; + __pyx_6 = PyInt_AsUnsignedLongMask(__pyx_5); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 49; goto __pyx_L1;} + Py_DECREF(__pyx_5); __pyx_5 = 0; + (__pyx_v_v[__pyx_v_i]) = __pyx_6; } - __pyx_L3:; - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":48 */ - __pyx_3 = PyInt_FromLong(0); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; goto __pyx_L1;} - __pyx_1 = PyObject_GetItem(__pyx_v_key, __pyx_3); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; goto __pyx_L1;} - Py_DECREF(__pyx_3); __pyx_3 = 0; - __pyx_5 = PyInt_AsUnsignedLongMask(__pyx_1); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; goto __pyx_L1;} + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":50 */ + __pyx_1 = PyInt_FromLong(0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_key, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; goto __pyx_L1;} Py_DECREF(__pyx_1); __pyx_1 = 0; - (__pyx_v_k[0]) = __pyx_5; + __pyx_6 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + (__pyx_v_k[0]) = __pyx_6; - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":48 */ - __pyx_2 = PyInt_FromLong(1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; goto __pyx_L1;} - __pyx_3 = PyObject_GetItem(__pyx_v_key, __pyx_2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; goto __pyx_L1;} - Py_DECREF(__pyx_2); __pyx_2 = 0; - __pyx_5 = PyInt_AsUnsignedLongMask(__pyx_3); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; goto __pyx_L1;} + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":50 */ + __pyx_3 = PyInt_FromLong(1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; goto __pyx_L1;} + __pyx_5 = PyObject_GetItem(__pyx_v_key, __pyx_3); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; goto __pyx_L1;} Py_DECREF(__pyx_3); __pyx_3 = 0; - (__pyx_v_k[1]) = __pyx_5; + __pyx_6 = PyInt_AsUnsignedLongMask(__pyx_5); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; goto __pyx_L1;} + Py_DECREF(__pyx_5); __pyx_5 = 0; + (__pyx_v_k[1]) = __pyx_6; - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":48 */ - __pyx_1 = PyInt_FromLong(2); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; goto __pyx_L1;} - __pyx_2 = PyObject_GetItem(__pyx_v_key, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; goto __pyx_L1;} + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":50 */ + __pyx_1 = PyInt_FromLong(2); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_key, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; goto __pyx_L1;} Py_DECREF(__pyx_1); __pyx_1 = 0; - __pyx_5 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; goto __pyx_L1;} + __pyx_6 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; goto __pyx_L1;} Py_DECREF(__pyx_2); __pyx_2 = 0; - (__pyx_v_k[2]) = __pyx_5; + (__pyx_v_k[2]) = __pyx_6; - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":48 */ - __pyx_3 = PyInt_FromLong(3); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; goto __pyx_L1;} - __pyx_1 = PyObject_GetItem(__pyx_v_key, __pyx_3); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; goto __pyx_L1;} + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":50 */ + __pyx_3 = PyInt_FromLong(3); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; goto __pyx_L1;} + __pyx_5 = PyObject_GetItem(__pyx_v_key, __pyx_3); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; goto __pyx_L1;} Py_DECREF(__pyx_3); __pyx_3 = 0; - __pyx_5 = PyInt_AsUnsignedLongMask(__pyx_1); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; goto __pyx_L1;} - Py_DECREF(__pyx_1); __pyx_1 = 0; - (__pyx_v_k[3]) = __pyx_5; + __pyx_6 = PyInt_AsUnsignedLongMask(__pyx_5); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; goto __pyx_L1;} + Py_DECREF(__pyx_5); __pyx_5 = 0; + (__pyx_v_k[3]) = __pyx_6; - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":49 */ - __pyx_v_rc = xtea_encipher(__pyx_v_v,__pyx_v_k,__pyx_v_rounds); + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":51 */ + __pyx_v_rc = xxtea_encipher(__pyx_v_v,__pyx_v_k,__pyx_v_rounds); - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":50 */ - __pyx_2 = PyList_New(0); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; goto __pyx_L1;} + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":52 */ + __pyx_1 = PyList_New(0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 52; goto __pyx_L1;} Py_DECREF(__pyx_v_result); - __pyx_v_result = __pyx_2; - __pyx_2 = 0; + __pyx_v_result = __pyx_1; + __pyx_1 = 0; - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":51 */ + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":53 */ for (__pyx_v_i = 0; __pyx_v_i < __pyx_v_size; ++__pyx_v_i) { - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":52 */ - __pyx_3 = PyObject_GetAttr(__pyx_v_result, __pyx_n_append); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 52; goto __pyx_L1;} - __pyx_1 = PyLong_FromUnsignedLong((__pyx_v_v[__pyx_v_i])); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 52; goto __pyx_L1;} - __pyx_2 = PyTuple_New(1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 52; goto __pyx_L1;} - PyTuple_SET_ITEM(__pyx_2, 0, __pyx_1); - __pyx_1 = 0; - __pyx_1 = PyObject_CallObject(__pyx_3, __pyx_2); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 52; goto __pyx_L1;} - Py_DECREF(__pyx_3); __pyx_3 = 0; + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":54 */ + __pyx_2 = PyObject_GetAttr(__pyx_v_result, __pyx_n_append); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 54; goto __pyx_L1;} + __pyx_3 = PyLong_FromUnsignedLong((__pyx_v_v[__pyx_v_i])); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 54; goto __pyx_L1;} + __pyx_5 = PyTuple_New(1); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 54; goto __pyx_L1;} + PyTuple_SET_ITEM(__pyx_5, 0, __pyx_3); + __pyx_3 = 0; + __pyx_1 = PyObject_CallObject(__pyx_2, __pyx_5); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 54; goto __pyx_L1;} Py_DECREF(__pyx_2); __pyx_2 = 0; + Py_DECREF(__pyx_5); __pyx_5 = 0; Py_DECREF(__pyx_1); __pyx_1 = 0; - __pyx_L4:; } - __pyx_L5:; - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":53 */ + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":55 */ free(__pyx_v_v); - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":54 */ + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":56 */ Py_INCREF(__pyx_v_result); __pyx_r = __pyx_v_result; goto __pyx_L0; @@ -379,6 +419,7 @@ Py_XDECREF(__pyx_1); Py_XDECREF(__pyx_2); Py_XDECREF(__pyx_3); + Py_XDECREF(__pyx_5); __Pyx_AddTraceback("_xtea._c_xxtea_encrypt"); __pyx_r = 0; __pyx_L0:; @@ -388,6 +429,10 @@ return __pyx_r; } +static PyObject *__pyx_k2p; + +static char (__pyx_k2[]) = "len(block) %i != rounds %i"; + static PyObject *__pyx_f_5_xtea__c_xxtea_decrypt(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static PyObject *__pyx_f_5_xtea__c_xxtea_decrypt(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { PyObject *__pyx_v_block = 0; @@ -405,107 +450,127 @@ PyObject *__pyx_2 = 0; PyObject *__pyx_3 = 0; int __pyx_4; - unsigned long __pyx_5; + PyObject *__pyx_5 = 0; + unsigned long __pyx_6; static char *__pyx_argnames[] = {"block","key","rounds",0}; if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "OOI", __pyx_argnames, &__pyx_v_block, &__pyx_v_key, &__pyx_v_rounds)) return 0; Py_INCREF(__pyx_v_block); Py_INCREF(__pyx_v_key); __pyx_v_result = Py_None; Py_INCREF(Py_None); - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":59 */ - __pyx_1 = __Pyx_GetName(__pyx_b, __pyx_n_len); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 59; goto __pyx_L1;} - __pyx_2 = PyTuple_New(1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 59; goto __pyx_L1;} + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":61 */ + __pyx_1 = __Pyx_GetName(__pyx_b, __pyx_n_len); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 61; goto __pyx_L1;} + __pyx_2 = PyTuple_New(1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 61; goto __pyx_L1;} Py_INCREF(__pyx_v_block); PyTuple_SET_ITEM(__pyx_2, 0, __pyx_v_block); - __pyx_3 = PyObject_CallObject(__pyx_1, __pyx_2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 59; goto __pyx_L1;} + __pyx_3 = PyObject_CallObject(__pyx_1, __pyx_2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 61; goto __pyx_L1;} Py_DECREF(__pyx_1); __pyx_1 = 0; Py_DECREF(__pyx_2); __pyx_2 = 0; - __pyx_4 = PyInt_AsLong(__pyx_3); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 59; goto __pyx_L1;} + __pyx_4 = PyInt_AsLong(__pyx_3); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 61; goto __pyx_L1;} Py_DECREF(__pyx_3); __pyx_3 = 0; __pyx_v_size = __pyx_4; - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":60 */ + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":62 */ + __pyx_4 = (__pyx_v_size != __pyx_v_rounds); + if (__pyx_4) { + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":63 */ + __pyx_1 = __Pyx_GetName(__pyx_b, __pyx_n_ValueError); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; goto __pyx_L1;} + __pyx_2 = PyInt_FromLong(__pyx_v_size); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; goto __pyx_L1;} + __pyx_3 = PyLong_FromUnsignedLong(__pyx_v_rounds); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; goto __pyx_L1;} + __pyx_5 = PyTuple_New(2); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; goto __pyx_L1;} + PyTuple_SET_ITEM(__pyx_5, 0, __pyx_2); + PyTuple_SET_ITEM(__pyx_5, 1, __pyx_3); + __pyx_2 = 0; + __pyx_3 = 0; + __pyx_2 = PyNumber_Remainder(__pyx_k2p, __pyx_5); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; goto __pyx_L1;} + Py_DECREF(__pyx_5); __pyx_5 = 0; + __Pyx_Raise(__pyx_1, __pyx_2, 0); + Py_DECREF(__pyx_1); __pyx_1 = 0; + Py_DECREF(__pyx_2); __pyx_2 = 0; + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; goto __pyx_L1;} + goto __pyx_L2; + } + __pyx_L2:; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":64 */ __pyx_v_vsize = ((sizeof(unsigned long )) * __pyx_v_size); - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":61 */ + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":65 */ __pyx_v_v = ((unsigned long (*))malloc(__pyx_v_vsize)); - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":62 */ + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":66 */ for (__pyx_v_i = 0; __pyx_v_i < __pyx_v_size; ++__pyx_v_i) { - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":63 */ - __pyx_1 = PyInt_FromLong(__pyx_v_i); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; goto __pyx_L1;} - __pyx_2 = PyObject_GetItem(__pyx_v_block, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; goto __pyx_L1;} - Py_DECREF(__pyx_1); __pyx_1 = 0; - __pyx_5 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; goto __pyx_L1;} - Py_DECREF(__pyx_2); __pyx_2 = 0; - (__pyx_v_v[__pyx_v_i]) = __pyx_5; - __pyx_L2:; + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":67 */ + __pyx_3 = PyInt_FromLong(__pyx_v_i); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 67; goto __pyx_L1;} + __pyx_5 = PyObject_GetItem(__pyx_v_block, __pyx_3); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 67; goto __pyx_L1;} + Py_DECREF(__pyx_3); __pyx_3 = 0; + __pyx_6 = PyInt_AsUnsignedLongMask(__pyx_5); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 67; goto __pyx_L1;} + Py_DECREF(__pyx_5); __pyx_5 = 0; + (__pyx_v_v[__pyx_v_i]) = __pyx_6; } - __pyx_L3:; - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":64 */ - __pyx_3 = PyInt_FromLong(0); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; goto __pyx_L1;} - __pyx_1 = PyObject_GetItem(__pyx_v_key, __pyx_3); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; goto __pyx_L1;} - Py_DECREF(__pyx_3); __pyx_3 = 0; - __pyx_5 = PyInt_AsUnsignedLongMask(__pyx_1); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; goto __pyx_L1;} + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":68 */ + __pyx_1 = PyInt_FromLong(0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_key, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; goto __pyx_L1;} Py_DECREF(__pyx_1); __pyx_1 = 0; - (__pyx_v_k[0]) = __pyx_5; + __pyx_6 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + (__pyx_v_k[0]) = __pyx_6; - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":64 */ - __pyx_2 = PyInt_FromLong(1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; goto __pyx_L1;} - __pyx_3 = PyObject_GetItem(__pyx_v_key, __pyx_2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; goto __pyx_L1;} - Py_DECREF(__pyx_2); __pyx_2 = 0; - __pyx_5 = PyInt_AsUnsignedLongMask(__pyx_3); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; goto __pyx_L1;} + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":68 */ + __pyx_3 = PyInt_FromLong(1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; goto __pyx_L1;} + __pyx_5 = PyObject_GetItem(__pyx_v_key, __pyx_3); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; goto __pyx_L1;} Py_DECREF(__pyx_3); __pyx_3 = 0; - (__pyx_v_k[1]) = __pyx_5; + __pyx_6 = PyInt_AsUnsignedLongMask(__pyx_5); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; goto __pyx_L1;} + Py_DECREF(__pyx_5); __pyx_5 = 0; + (__pyx_v_k[1]) = __pyx_6; - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":64 */ - __pyx_1 = PyInt_FromLong(2); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; goto __pyx_L1;} - __pyx_2 = PyObject_GetItem(__pyx_v_key, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; goto __pyx_L1;} + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":68 */ + __pyx_1 = PyInt_FromLong(2); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_key, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; goto __pyx_L1;} Py_DECREF(__pyx_1); __pyx_1 = 0; - __pyx_5 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; goto __pyx_L1;} + __pyx_6 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; goto __pyx_L1;} Py_DECREF(__pyx_2); __pyx_2 = 0; - (__pyx_v_k[2]) = __pyx_5; + (__pyx_v_k[2]) = __pyx_6; - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":64 */ - __pyx_3 = PyInt_FromLong(3); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; goto __pyx_L1;} - __pyx_1 = PyObject_GetItem(__pyx_v_key, __pyx_3); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; goto __pyx_L1;} + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":68 */ + __pyx_3 = PyInt_FromLong(3); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; goto __pyx_L1;} + __pyx_5 = PyObject_GetItem(__pyx_v_key, __pyx_3); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; goto __pyx_L1;} Py_DECREF(__pyx_3); __pyx_3 = 0; - __pyx_5 = PyInt_AsUnsignedLongMask(__pyx_1); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; goto __pyx_L1;} - Py_DECREF(__pyx_1); __pyx_1 = 0; - (__pyx_v_k[3]) = __pyx_5; + __pyx_6 = PyInt_AsUnsignedLongMask(__pyx_5); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; goto __pyx_L1;} + Py_DECREF(__pyx_5); __pyx_5 = 0; + (__pyx_v_k[3]) = __pyx_6; - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":65 */ - __pyx_v_rc = xtea_encipher(__pyx_v_v,__pyx_v_k,__pyx_v_rounds); + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":69 */ + __pyx_v_rc = xxtea_decipher(__pyx_v_v,__pyx_v_k,__pyx_v_rounds); - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":66 */ - __pyx_2 = PyList_New(0); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 66; goto __pyx_L1;} + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":70 */ + __pyx_1 = PyList_New(0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 70; goto __pyx_L1;} Py_DECREF(__pyx_v_result); - __pyx_v_result = __pyx_2; - __pyx_2 = 0; + __pyx_v_result = __pyx_1; + __pyx_1 = 0; - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":67 */ + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":71 */ for (__pyx_v_i = 0; __pyx_v_i < __pyx_v_size; ++__pyx_v_i) { - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":68 */ - __pyx_3 = PyObject_GetAttr(__pyx_v_result, __pyx_n_append); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; goto __pyx_L1;} - __pyx_1 = PyLong_FromUnsignedLong((__pyx_v_v[__pyx_v_i])); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; goto __pyx_L1;} - __pyx_2 = PyTuple_New(1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; goto __pyx_L1;} - PyTuple_SET_ITEM(__pyx_2, 0, __pyx_1); - __pyx_1 = 0; - __pyx_1 = PyObject_CallObject(__pyx_3, __pyx_2); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; goto __pyx_L1;} - Py_DECREF(__pyx_3); __pyx_3 = 0; + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":72 */ + __pyx_2 = PyObject_GetAttr(__pyx_v_result, __pyx_n_append); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; goto __pyx_L1;} + __pyx_3 = PyLong_FromUnsignedLong((__pyx_v_v[__pyx_v_i])); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; goto __pyx_L1;} + __pyx_5 = PyTuple_New(1); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; goto __pyx_L1;} + PyTuple_SET_ITEM(__pyx_5, 0, __pyx_3); + __pyx_3 = 0; + __pyx_1 = PyObject_CallObject(__pyx_2, __pyx_5); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 72; goto __pyx_L1;} Py_DECREF(__pyx_2); __pyx_2 = 0; + Py_DECREF(__pyx_5); __pyx_5 = 0; Py_DECREF(__pyx_1); __pyx_1 = 0; - __pyx_L4:; } - __pyx_L5:; - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":69 */ + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":73 */ free(__pyx_v_v); - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":70 */ + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":74 */ Py_INCREF(__pyx_v_result); __pyx_r = __pyx_v_result; goto __pyx_L0; @@ -516,6 +581,7 @@ Py_XDECREF(__pyx_1); Py_XDECREF(__pyx_2); Py_XDECREF(__pyx_3); + Py_XDECREF(__pyx_5); __Pyx_AddTraceback("_xtea._c_xxtea_decrypt"); __pyx_r = 0; __pyx_L0:; @@ -525,21 +591,326 @@ return __pyx_r; } +static PyObject *__pyx_k3p; + +static char (__pyx_k3[]) = "len(block) %i != rounds %i"; + +static PyObject *__pyx_f_5_xtea_XXX_c_xxtea_encrypt(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_f_5_xtea_XXX_c_xxtea_encrypt(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_block = 0; + PyObject *__pyx_v_key = 0; + unsigned int __pyx_v_rounds; + unsigned long (__pyx_v_k[4]); + unsigned long (__pyx_v_v[2]); + int __pyx_v_rc; + int __pyx_v_size; + PyObject *__pyx_v_result; + PyObject *__pyx_r; + PyObject *__pyx_1 = 0; + PyObject *__pyx_2 = 0; + PyObject *__pyx_3 = 0; + int __pyx_4; + PyObject *__pyx_5 = 0; + unsigned long __pyx_6; + static char *__pyx_argnames[] = {"block","key","rounds",0}; + if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "OOI", __pyx_argnames, &__pyx_v_block, &__pyx_v_key, &__pyx_v_rounds)) return 0; + Py_INCREF(__pyx_v_block); + Py_INCREF(__pyx_v_key); + __pyx_v_result = Py_None; Py_INCREF(Py_None); + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":79 */ + __pyx_1 = __Pyx_GetName(__pyx_b, __pyx_n_len); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 79; goto __pyx_L1;} + __pyx_2 = PyTuple_New(1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 79; goto __pyx_L1;} + Py_INCREF(__pyx_v_block); + PyTuple_SET_ITEM(__pyx_2, 0, __pyx_v_block); + __pyx_3 = PyObject_CallObject(__pyx_1, __pyx_2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 79; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + Py_DECREF(__pyx_2); __pyx_2 = 0; + __pyx_4 = PyInt_AsLong(__pyx_3); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 79; goto __pyx_L1;} + Py_DECREF(__pyx_3); __pyx_3 = 0; + __pyx_v_size = __pyx_4; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":80 */ + __pyx_4 = (__pyx_v_size != __pyx_v_rounds); + if (__pyx_4) { + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":81 */ + __pyx_1 = __Pyx_GetName(__pyx_b, __pyx_n_ValueError); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 81; goto __pyx_L1;} + __pyx_2 = PyInt_FromLong(__pyx_v_size); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 81; goto __pyx_L1;} + __pyx_3 = PyLong_FromUnsignedLong(__pyx_v_rounds); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 81; goto __pyx_L1;} + __pyx_5 = PyTuple_New(2); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 81; goto __pyx_L1;} + PyTuple_SET_ITEM(__pyx_5, 0, __pyx_2); + PyTuple_SET_ITEM(__pyx_5, 1, __pyx_3); + __pyx_2 = 0; + __pyx_3 = 0; + __pyx_2 = PyNumber_Remainder(__pyx_k3p, __pyx_5); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 81; goto __pyx_L1;} + Py_DECREF(__pyx_5); __pyx_5 = 0; + __Pyx_Raise(__pyx_1, __pyx_2, 0); + Py_DECREF(__pyx_1); __pyx_1 = 0; + Py_DECREF(__pyx_2); __pyx_2 = 0; + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 81; goto __pyx_L1;} + goto __pyx_L2; + } + __pyx_L2:; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":82 */ + __pyx_3 = PyInt_FromLong(0); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 82; goto __pyx_L1;} + __pyx_5 = PyObject_GetItem(__pyx_v_block, __pyx_3); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 82; goto __pyx_L1;} + Py_DECREF(__pyx_3); __pyx_3 = 0; + __pyx_6 = PyInt_AsUnsignedLongMask(__pyx_5); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 82; goto __pyx_L1;} + Py_DECREF(__pyx_5); __pyx_5 = 0; + (__pyx_v_v[0]) = __pyx_6; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":82 */ + __pyx_1 = PyInt_FromLong(1); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 82; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_block, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 82; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + __pyx_6 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 82; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + (__pyx_v_v[1]) = __pyx_6; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":83 */ + __pyx_3 = PyInt_FromLong(0); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 83; goto __pyx_L1;} + __pyx_5 = PyObject_GetItem(__pyx_v_key, __pyx_3); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 83; goto __pyx_L1;} + Py_DECREF(__pyx_3); __pyx_3 = 0; + __pyx_6 = PyInt_AsUnsignedLongMask(__pyx_5); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 83; goto __pyx_L1;} + Py_DECREF(__pyx_5); __pyx_5 = 0; + (__pyx_v_k[0]) = __pyx_6; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":83 */ + __pyx_1 = PyInt_FromLong(1); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 83; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_key, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 83; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + __pyx_6 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 83; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + (__pyx_v_k[1]) = __pyx_6; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":83 */ + __pyx_3 = PyInt_FromLong(2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 83; goto __pyx_L1;} + __pyx_5 = PyObject_GetItem(__pyx_v_key, __pyx_3); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 83; goto __pyx_L1;} + Py_DECREF(__pyx_3); __pyx_3 = 0; + __pyx_6 = PyInt_AsUnsignedLongMask(__pyx_5); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 83; goto __pyx_L1;} + Py_DECREF(__pyx_5); __pyx_5 = 0; + (__pyx_v_k[2]) = __pyx_6; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":83 */ + __pyx_1 = PyInt_FromLong(3); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 83; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_key, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 83; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + __pyx_6 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 83; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + (__pyx_v_k[3]) = __pyx_6; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":84 */ + __pyx_v_rc = xxtea_encipher(__pyx_v_v,__pyx_v_k,__pyx_v_rounds); + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":85 */ + __pyx_3 = PyLong_FromUnsignedLong((__pyx_v_v[0])); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 85; goto __pyx_L1;} + __pyx_5 = PyLong_FromUnsignedLong((__pyx_v_v[1])); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 85; goto __pyx_L1;} + __pyx_1 = PyList_New(2); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 85; goto __pyx_L1;} + PyList_SET_ITEM(__pyx_1, 0, __pyx_3); + PyList_SET_ITEM(__pyx_1, 1, __pyx_5); + __pyx_3 = 0; + __pyx_5 = 0; + Py_DECREF(__pyx_v_result); + __pyx_v_result = __pyx_1; + __pyx_1 = 0; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":86 */ + Py_INCREF(__pyx_v_result); + __pyx_r = __pyx_v_result; + goto __pyx_L0; + + __pyx_r = Py_None; Py_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1:; + Py_XDECREF(__pyx_1); + Py_XDECREF(__pyx_2); + Py_XDECREF(__pyx_3); + Py_XDECREF(__pyx_5); + __Pyx_AddTraceback("_xtea.XXX_c_xxtea_encrypt"); + __pyx_r = 0; + __pyx_L0:; + Py_DECREF(__pyx_v_result); + Py_DECREF(__pyx_v_block); + Py_DECREF(__pyx_v_key); + return __pyx_r; +} + +static PyObject *__pyx_k4p; + +static char (__pyx_k4[]) = "len(block) %i != rounds %i"; + +static PyObject *__pyx_f_5_xtea_XXX_c_xxtea_decrypt(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_f_5_xtea_XXX_c_xxtea_decrypt(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_block = 0; + PyObject *__pyx_v_key = 0; + unsigned int __pyx_v_rounds; + unsigned long (__pyx_v_k[4]); + unsigned long (__pyx_v_v[2]); + int __pyx_v_rc; + int __pyx_v_size; + PyObject *__pyx_v_result; + PyObject *__pyx_r; + PyObject *__pyx_1 = 0; + PyObject *__pyx_2 = 0; + PyObject *__pyx_3 = 0; + int __pyx_4; + PyObject *__pyx_5 = 0; + unsigned long __pyx_6; + static char *__pyx_argnames[] = {"block","key","rounds",0}; + if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "OOI", __pyx_argnames, &__pyx_v_block, &__pyx_v_key, &__pyx_v_rounds)) return 0; + Py_INCREF(__pyx_v_block); + Py_INCREF(__pyx_v_key); + __pyx_v_result = Py_None; Py_INCREF(Py_None); + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":91 */ + __pyx_1 = __Pyx_GetName(__pyx_b, __pyx_n_len); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 91; goto __pyx_L1;} + __pyx_2 = PyTuple_New(1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 91; goto __pyx_L1;} + Py_INCREF(__pyx_v_block); + PyTuple_SET_ITEM(__pyx_2, 0, __pyx_v_block); + __pyx_3 = PyObject_CallObject(__pyx_1, __pyx_2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 91; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + Py_DECREF(__pyx_2); __pyx_2 = 0; + __pyx_4 = PyInt_AsLong(__pyx_3); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 91; goto __pyx_L1;} + Py_DECREF(__pyx_3); __pyx_3 = 0; + __pyx_v_size = __pyx_4; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":92 */ + __pyx_4 = (__pyx_v_size != __pyx_v_rounds); + if (__pyx_4) { + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":93 */ + __pyx_1 = __Pyx_GetName(__pyx_b, __pyx_n_ValueError); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 93; goto __pyx_L1;} + __pyx_2 = PyInt_FromLong(__pyx_v_size); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 93; goto __pyx_L1;} + __pyx_3 = PyLong_FromUnsignedLong(__pyx_v_rounds); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 93; goto __pyx_L1;} + __pyx_5 = PyTuple_New(2); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 93; goto __pyx_L1;} + PyTuple_SET_ITEM(__pyx_5, 0, __pyx_2); + PyTuple_SET_ITEM(__pyx_5, 1, __pyx_3); + __pyx_2 = 0; + __pyx_3 = 0; + __pyx_2 = PyNumber_Remainder(__pyx_k4p, __pyx_5); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 93; goto __pyx_L1;} + Py_DECREF(__pyx_5); __pyx_5 = 0; + __Pyx_Raise(__pyx_1, __pyx_2, 0); + Py_DECREF(__pyx_1); __pyx_1 = 0; + Py_DECREF(__pyx_2); __pyx_2 = 0; + {__pyx_filename = __pyx_f[0]; __pyx_lineno = 93; goto __pyx_L1;} + goto __pyx_L2; + } + __pyx_L2:; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":94 */ + __pyx_3 = PyInt_FromLong(0); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 94; goto __pyx_L1;} + __pyx_5 = PyObject_GetItem(__pyx_v_block, __pyx_3); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 94; goto __pyx_L1;} + Py_DECREF(__pyx_3); __pyx_3 = 0; + __pyx_6 = PyInt_AsUnsignedLongMask(__pyx_5); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 94; goto __pyx_L1;} + Py_DECREF(__pyx_5); __pyx_5 = 0; + (__pyx_v_v[0]) = __pyx_6; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":94 */ + __pyx_1 = PyInt_FromLong(1); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 94; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_block, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 94; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + __pyx_6 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 94; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + (__pyx_v_v[1]) = __pyx_6; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":95 */ + __pyx_3 = PyInt_FromLong(0); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 95; goto __pyx_L1;} + __pyx_5 = PyObject_GetItem(__pyx_v_key, __pyx_3); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 95; goto __pyx_L1;} + Py_DECREF(__pyx_3); __pyx_3 = 0; + __pyx_6 = PyInt_AsUnsignedLongMask(__pyx_5); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 95; goto __pyx_L1;} + Py_DECREF(__pyx_5); __pyx_5 = 0; + (__pyx_v_k[0]) = __pyx_6; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":95 */ + __pyx_1 = PyInt_FromLong(1); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 95; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_key, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 95; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + __pyx_6 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 95; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + (__pyx_v_k[1]) = __pyx_6; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":95 */ + __pyx_3 = PyInt_FromLong(2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 95; goto __pyx_L1;} + __pyx_5 = PyObject_GetItem(__pyx_v_key, __pyx_3); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 95; goto __pyx_L1;} + Py_DECREF(__pyx_3); __pyx_3 = 0; + __pyx_6 = PyInt_AsUnsignedLongMask(__pyx_5); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 95; goto __pyx_L1;} + Py_DECREF(__pyx_5); __pyx_5 = 0; + (__pyx_v_k[2]) = __pyx_6; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":95 */ + __pyx_1 = PyInt_FromLong(3); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 95; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_key, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 95; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + __pyx_6 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 95; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + (__pyx_v_k[3]) = __pyx_6; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":96 */ + __pyx_v_rc = xxtea_decipher(__pyx_v_v,__pyx_v_k,__pyx_v_rounds); + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":97 */ + __pyx_3 = PyLong_FromUnsignedLong((__pyx_v_v[0])); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 97; goto __pyx_L1;} + __pyx_5 = PyLong_FromUnsignedLong((__pyx_v_v[1])); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 97; goto __pyx_L1;} + __pyx_1 = PyList_New(2); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 97; goto __pyx_L1;} + PyList_SET_ITEM(__pyx_1, 0, __pyx_3); + PyList_SET_ITEM(__pyx_1, 1, __pyx_5); + __pyx_3 = 0; + __pyx_5 = 0; + Py_DECREF(__pyx_v_result); + __pyx_v_result = __pyx_1; + __pyx_1 = 0; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":98 */ + Py_INCREF(__pyx_v_result); + __pyx_r = __pyx_v_result; + goto __pyx_L0; + + __pyx_r = Py_None; Py_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1:; + Py_XDECREF(__pyx_1); + Py_XDECREF(__pyx_2); + Py_XDECREF(__pyx_3); + Py_XDECREF(__pyx_5); + __Pyx_AddTraceback("_xtea.XXX_c_xxtea_decrypt"); + __pyx_r = 0; + __pyx_L0:; + Py_DECREF(__pyx_v_result); + Py_DECREF(__pyx_v_block); + Py_DECREF(__pyx_v_key); + return __pyx_r; +} + static __Pyx_InternTabEntry __pyx_intern_tab[] = { - {&__pyx_n__c_xtea_encryptQuad, "_c_xtea_encryptQuad"}, + {&__pyx_n_ValueError, "ValueError"}, + {&__pyx_n_XXX_c_xxtea_decrypt, "XXX_c_xxtea_decrypt"}, + {&__pyx_n_XXX_c_xxtea_encrypt, "XXX_c_xxtea_encrypt"}, + {&__pyx_n__c_xtea_decrypt, "_c_xtea_decrypt"}, + {&__pyx_n__c_xtea_encrypt, "_c_xtea_encrypt"}, {&__pyx_n__c_xxtea_decrypt, "_c_xxtea_decrypt"}, - {&__pyx_n__c_xxtea_decryptQuad, "_c_xxtea_decryptQuad"}, {&__pyx_n__c_xxtea_encrypt, "_c_xxtea_encrypt"}, {&__pyx_n_append, "append"}, {&__pyx_n_len, "len"}, {0, 0} }; +static __Pyx_StringTabEntry __pyx_string_tab[] = { + {&__pyx_k1p, __pyx_k1, sizeof(__pyx_k1)}, + {&__pyx_k2p, __pyx_k2, sizeof(__pyx_k2)}, + {&__pyx_k3p, __pyx_k3, sizeof(__pyx_k3)}, + {&__pyx_k4p, __pyx_k4, sizeof(__pyx_k4)}, + {0, 0, 0} +}; + static struct PyMethodDef __pyx_methods[] = { - {"_c_xtea_encryptQuad", (PyCFunction)__pyx_f_5_xtea__c_xtea_encryptQuad, METH_VARARGS|METH_KEYWORDS, 0}, - {"_c_xxtea_decryptQuad", (PyCFunction)__pyx_f_5_xtea__c_xxtea_decryptQuad, METH_VARARGS|METH_KEYWORDS, 0}, + {"_c_xtea_encrypt", (PyCFunction)__pyx_f_5_xtea__c_xtea_encrypt, METH_VARARGS|METH_KEYWORDS, 0}, + {"_c_xtea_decrypt", (PyCFunction)__pyx_f_5_xtea__c_xtea_decrypt, METH_VARARGS|METH_KEYWORDS, 0}, {"_c_xxtea_encrypt", (PyCFunction)__pyx_f_5_xtea__c_xxtea_encrypt, METH_VARARGS|METH_KEYWORDS, 0}, {"_c_xxtea_decrypt", (PyCFunction)__pyx_f_5_xtea__c_xxtea_decrypt, METH_VARARGS|METH_KEYWORDS, 0}, + {"XXX_c_xxtea_encrypt", (PyCFunction)__pyx_f_5_xtea_XXX_c_xxtea_encrypt, METH_VARARGS|METH_KEYWORDS, 0}, + {"XXX_c_xxtea_decrypt", (PyCFunction)__pyx_f_5_xtea_XXX_c_xxtea_decrypt, METH_VARARGS|METH_KEYWORDS, 0}, {0, 0, 0, 0} }; @@ -554,8 +925,9 @@ if (!__pyx_b) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 7; goto __pyx_L1;}; if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 7; goto __pyx_L1;}; if (__Pyx_InternStrings(__pyx_intern_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 7; goto __pyx_L1;}; + if (__Pyx_InitStrings(__pyx_string_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 7; goto __pyx_L1;}; - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":56 */ + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":88 */ return; __pyx_L1:; __Pyx_AddTraceback("_xtea"); @@ -579,6 +951,64 @@ return result; } +static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb) { + Py_XINCREF(type); + Py_XINCREF(value); + Py_XINCREF(tb); + /* First, check the traceback argument, replacing None with NULL. */ + if (tb == Py_None) { + Py_DECREF(tb); + tb = 0; + } + else if (tb != NULL && !PyTraceBack_Check(tb)) { + PyErr_SetString(PyExc_TypeError, + "raise: arg 3 must be a traceback or None"); + goto raise_error; + } + /* Next, replace a missing value with None */ + if (value == NULL) { + value = Py_None; + Py_INCREF(value); + } + /* Next, repeatedly, replace a tuple exception with its first item */ + while (PyTuple_Check(type) && PyTuple_Size(type) > 0) { + PyObject *tmp = type; + type = PyTuple_GET_ITEM(type, 0); + Py_INCREF(type); + Py_DECREF(tmp); + } + if (PyString_Check(type)) { + if (PyErr_Warn(PyExc_DeprecationWarning, + "raising a string exception is deprecated")) + goto raise_error; + } + else if (PyType_Check(type) || PyClass_Check(type)) + ; /*PyErr_NormalizeException(&type, &value, &tb);*/ + else { + /* Raising an instance. The value should be a dummy. */ + if (value != Py_None) { + PyErr_SetString(PyExc_TypeError, + "instance exception may not have a separate value"); + goto raise_error; + } + /* Normalize to raise <class>, <instance> */ + Py_DECREF(value); + value = type; + if (PyInstance_Check(type)) + type = (PyObject*) ((PyInstanceObject*)type)->in_class; + else + type = (PyObject*) type->ob_type; + Py_INCREF(type); + } + PyErr_Restore(type, value, tb); + return; +raise_error: + Py_XDECREF(value); + Py_XDECREF(type); + Py_XDECREF(tb); + return; +} + static int __Pyx_InternStrings(__Pyx_InternTabEntry *t) { while (t->p) { *t->p = PyString_InternFromString(t->s); @@ -589,6 +1019,16 @@ return 0; } +static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) { + while (t->p) { + *t->p = PyString_FromStringAndSize(t->s, t->n - 1); + if (!*t->p) + return -1; + ++t; + } + return 0; +} + #include "compile.h" #include "frameobject.h" #include "traceback.h" Modified: xtea/trunk/src/xtea/_xtea.pyx =================================================================== --- xtea/trunk/src/xtea/_xtea.pyx 2007-03-02 14:54:09 UTC (rev 223) +++ xtea/trunk/src/xtea/_xtea.pyx 2007-03-02 16:28:11 UTC (rev 224) @@ -19,21 +19,21 @@ int xxtea_decipher(ULong *v, ULong *k, UInt n) int xxtea_encipher(ULong *v, ULong *k, UInt n) -def _c_xtea_encryptQuad(ULong v0, ULong v1, object key, UInt rounds): +def _c_xtea_encrypt(object block, object key, UInt rounds): cdef ULong v[2] cdef ULong k[4] - v[0] = v0; v[1] = v1 + v[0] = block[0]; v[1] = block[1] k[0] = key[0]; k[1] = key[1]; k[2] = key[2]; k[3] = key[3] rc = xtea_encipher(v, k, rounds) result = [v[0], v[1]] return result -def _c_xxtea_decryptQuad(ULong v0, ULong v1, object key, UInt rounds): +def _c_xtea_decrypt(object block, object key, UInt rounds): cdef ULong v[2] cdef ULong k[4] - v[0] = v0; v[1] = v1 + v[0] = block[0]; v[1] = block[1] k[0] = key[0]; k[1] = key[1]; k[2] = key[2]; k[3] = key[3] - rc = xxtea_decipher(v, k, rounds) + rc = xtea_decipher(v, k, rounds) result = [v[0], v[1]] return result @@ -41,12 +41,14 @@ cdef ULong k[4], *v cdef int rc, size, vsize, i size = len(block) + if size != rounds: + raise ValueError, "len(block) %i != rounds %i" % (size, rounds) vsize = sizeof(ULong) * size v = <ULong *>malloc(vsize) for i from 0 <= i < size: v[i] = block[i] k[0] = key[0]; k[1] = key[1]; k[2] = key[2]; k[3] = key[3] - rc = xtea_encipher(v, k, rounds) + rc = xxtea_encipher(v, k, rounds) result = [] for i from 0 <= i < size: result.append(v[i]) @@ -57,14 +59,40 @@ cdef ULong k[4], *v cdef int rc, size, vsize, i size = len(block) + if size != rounds: + raise ValueError, "len(block) %i != rounds %i" % (size, rounds) vsize = sizeof(U... [truncated message content] |
From: <ti...@us...> - 2007-03-02 14:54:16
|
Revision: 223 http://pymoul.svn.sourceforge.net/pymoul/?rev=223&view=rev Author: tiran Date: 2007-03-02 06:54:09 -0800 (Fri, 02 Mar 2007) Log Message: ----------- Added xxtea algorithm to c/pyrex code Modified Paths: -------------- xtea/trunk/src/xtea/_xtea.c xtea/trunk/src/xtea/_xtea.pyx xtea/trunk/src/xtea/cxtea.c xtea/trunk/src/xtea/cxtea.h Modified: xtea/trunk/src/xtea/_xtea.c =================================================================== --- xtea/trunk/src/xtea/_xtea.c 2007-03-01 17:41:40 UTC (rev 222) +++ xtea/trunk/src/xtea/_xtea.c 2007-03-02 14:54:09 UTC (rev 223) @@ -1,4 +1,4 @@ -/* Generated by Pyrex 0.9.4.1 on Thu Mar 1 15:44:44 2007 */ +/* Generated by Pyrex 0.9.4.1 on Fri Mar 2 15:53:19 2007 */ #include "Python.h" #include "structmember.h" @@ -11,6 +11,7 @@ #define __PYX_EXTERN_C extern #endif __PYX_EXTERN_C double pow(double, double); +#include "stdlib.h" #include "cxtea.h" @@ -48,13 +49,10 @@ /* Implementation of _xtea */ -static PyObject *__pyx_n_MODE_ECB; -static PyObject *__pyx_n_MODE_CBC; -static PyObject *__pyx_n_MODE_CFB; -static PyObject *__pyx_n_MODE_OFB; -static PyObject *__pyx_n_MODE_CTR; static PyObject *__pyx_n__c_xtea_encryptQuad; -static PyObject *__pyx_n__c_xtea_decryptQuad; +static PyObject *__pyx_n__c_xxtea_decryptQuad; +static PyObject *__pyx_n__c_xxtea_encrypt; +static PyObject *__pyx_n__c_xxtea_decrypt; static PyObject *__pyx_f_5_xtea__c_xtea_encryptQuad(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ static PyObject *__pyx_f_5_xtea__c_xtea_encryptQuad(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { @@ -64,6 +62,7 @@ unsigned int __pyx_v_rounds; unsigned long (__pyx_v_v[2]); unsigned long (__pyx_v_k[4]); + PyObject *__pyx_v_rc; PyObject *__pyx_v_result; PyObject *__pyx_r; PyObject *__pyx_1 = 0; @@ -73,62 +72,66 @@ static char *__pyx_argnames[] = {"v0","v1","key","rounds",0}; if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "kkOI", __pyx_argnames, &__pyx_v_v0, &__pyx_v_v1, &__pyx_v_key, &__pyx_v_rounds)) return 0; Py_INCREF(__pyx_v_key); + __pyx_v_rc = Py_None; Py_INCREF(Py_None); __pyx_v_result = Py_None; Py_INCREF(Py_None); - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":24 */ + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":25 */ (__pyx_v_v[0]) = __pyx_v_v0; - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":24 */ + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":25 */ (__pyx_v_v[1]) = __pyx_v_v1; - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":25 */ - __pyx_1 = PyInt_FromLong(0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; goto __pyx_L1;} - __pyx_2 = PyObject_GetItem(__pyx_v_key, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; goto __pyx_L1;} + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":26 */ + __pyx_1 = PyInt_FromLong(0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 26; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_key, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 26; goto __pyx_L1;} Py_DECREF(__pyx_1); __pyx_1 = 0; - __pyx_3 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; goto __pyx_L1;} + __pyx_3 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 26; goto __pyx_L1;} Py_DECREF(__pyx_2); __pyx_2 = 0; (__pyx_v_k[0]) = __pyx_3; - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":25 */ - __pyx_1 = PyInt_FromLong(1); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; goto __pyx_L1;} - __pyx_2 = PyObject_GetItem(__pyx_v_key, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; goto __pyx_L1;} + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":26 */ + __pyx_1 = PyInt_FromLong(1); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 26; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_key, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 26; goto __pyx_L1;} Py_DECREF(__pyx_1); __pyx_1 = 0; - __pyx_3 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; goto __pyx_L1;} + __pyx_3 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 26; goto __pyx_L1;} Py_DECREF(__pyx_2); __pyx_2 = 0; (__pyx_v_k[1]) = __pyx_3; - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":25 */ - __pyx_1 = PyInt_FromLong(2); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; goto __pyx_L1;} - __pyx_2 = PyObject_GetItem(__pyx_v_key, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; goto __pyx_L1;} + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":26 */ + __pyx_1 = PyInt_FromLong(2); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 26; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_key, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 26; goto __pyx_L1;} Py_DECREF(__pyx_1); __pyx_1 = 0; - __pyx_3 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; goto __pyx_L1;} + __pyx_3 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 26; goto __pyx_L1;} Py_DECREF(__pyx_2); __pyx_2 = 0; (__pyx_v_k[2]) = __pyx_3; - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":25 */ - __pyx_1 = PyInt_FromLong(3); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; goto __pyx_L1;} - __pyx_2 = PyObject_GetItem(__pyx_v_key, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; goto __pyx_L1;} + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":26 */ + __pyx_1 = PyInt_FromLong(3); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 26; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_key, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 26; goto __pyx_L1;} Py_DECREF(__pyx_1); __pyx_1 = 0; - __pyx_3 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; goto __pyx_L1;} + __pyx_3 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 26; goto __pyx_L1;} Py_DECREF(__pyx_2); __pyx_2 = 0; (__pyx_v_k[3]) = __pyx_3; - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":26 */ - encipher(__pyx_v_v,__pyx_v_k,__pyx_v_rounds); - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":27 */ - __pyx_1 = PyLong_FromUnsignedLong((__pyx_v_v[0])); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 27; goto __pyx_L1;} - __pyx_2 = PyLong_FromUnsignedLong((__pyx_v_v[1])); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 27; goto __pyx_L1;} - __pyx_4 = PyList_New(2); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 27; goto __pyx_L1;} - PyList_SET_ITEM(__pyx_4, 0, __pyx_1); - PyList_SET_ITEM(__pyx_4, 1, __pyx_2); + __pyx_1 = PyInt_FromLong(xtea_encipher(__pyx_v_v,__pyx_v_k,__pyx_v_rounds)); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 27; goto __pyx_L1;} + Py_DECREF(__pyx_v_rc); + __pyx_v_rc = __pyx_1; __pyx_1 = 0; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":28 */ + __pyx_2 = PyLong_FromUnsignedLong((__pyx_v_v[0])); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 28; goto __pyx_L1;} + __pyx_1 = PyLong_FromUnsignedLong((__pyx_v_v[1])); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 28; goto __pyx_L1;} + __pyx_4 = PyList_New(2); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 28; goto __pyx_L1;} + PyList_SET_ITEM(__pyx_4, 0, __pyx_2); + PyList_SET_ITEM(__pyx_4, 1, __pyx_1); __pyx_2 = 0; + __pyx_1 = 0; Py_DECREF(__pyx_v_result); __pyx_v_result = __pyx_4; __pyx_4 = 0; - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":28 */ + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":29 */ Py_INCREF(__pyx_v_result); __pyx_r = __pyx_v_result; goto __pyx_L0; @@ -142,19 +145,21 @@ __Pyx_AddTraceback("_xtea._c_xtea_encryptQuad"); __pyx_r = 0; __pyx_L0:; + Py_DECREF(__pyx_v_rc); Py_DECREF(__pyx_v_result); Py_DECREF(__pyx_v_key); return __pyx_r; } -static PyObject *__pyx_f_5_xtea__c_xtea_decryptQuad(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static PyObject *__pyx_f_5_xtea__c_xtea_decryptQuad(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { +static PyObject *__pyx_f_5_xtea__c_xxtea_decryptQuad(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_f_5_xtea__c_xxtea_decryptQuad(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { unsigned long __pyx_v_v0; unsigned long __pyx_v_v1; PyObject *__pyx_v_key = 0; unsigned int __pyx_v_rounds; unsigned long (__pyx_v_v[2]); unsigned long (__pyx_v_k[4]); + PyObject *__pyx_v_rc; PyObject *__pyx_v_result; PyObject *__pyx_r; PyObject *__pyx_1 = 0; @@ -164,62 +169,66 @@ static char *__pyx_argnames[] = {"v0","v1","key","rounds",0}; if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "kkOI", __pyx_argnames, &__pyx_v_v0, &__pyx_v_v1, &__pyx_v_key, &__pyx_v_rounds)) return 0; Py_INCREF(__pyx_v_key); + __pyx_v_rc = Py_None; Py_INCREF(Py_None); __pyx_v_result = Py_None; Py_INCREF(Py_None); - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":33 */ + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":34 */ (__pyx_v_v[0]) = __pyx_v_v0; - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":33 */ + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":34 */ (__pyx_v_v[1]) = __pyx_v_v1; - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":34 */ - __pyx_1 = PyInt_FromLong(0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; goto __pyx_L1;} - __pyx_2 = PyObject_GetItem(__pyx_v_key, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; goto __pyx_L1;} + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":35 */ + __pyx_1 = PyInt_FromLong(0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 35; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_key, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 35; goto __pyx_L1;} Py_DECREF(__pyx_1); __pyx_1 = 0; - __pyx_3 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; goto __pyx_L1;} + __pyx_3 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 35; goto __pyx_L1;} Py_DECREF(__pyx_2); __pyx_2 = 0; (__pyx_v_k[0]) = __pyx_3; - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":34 */ - __pyx_1 = PyInt_FromLong(1); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; goto __pyx_L1;} - __pyx_2 = PyObject_GetItem(__pyx_v_key, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; goto __pyx_L1;} + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":35 */ + __pyx_1 = PyInt_FromLong(1); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 35; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_key, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 35; goto __pyx_L1;} Py_DECREF(__pyx_1); __pyx_1 = 0; - __pyx_3 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; goto __pyx_L1;} + __pyx_3 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 35; goto __pyx_L1;} Py_DECREF(__pyx_2); __pyx_2 = 0; (__pyx_v_k[1]) = __pyx_3; - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":34 */ - __pyx_1 = PyInt_FromLong(2); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; goto __pyx_L1;} - __pyx_2 = PyObject_GetItem(__pyx_v_key, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; goto __pyx_L1;} + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":35 */ + __pyx_1 = PyInt_FromLong(2); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 35; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_key, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 35; goto __pyx_L1;} Py_DECREF(__pyx_1); __pyx_1 = 0; - __pyx_3 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; goto __pyx_L1;} + __pyx_3 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 35; goto __pyx_L1;} Py_DECREF(__pyx_2); __pyx_2 = 0; (__pyx_v_k[2]) = __pyx_3; - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":34 */ - __pyx_1 = PyInt_FromLong(3); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; goto __pyx_L1;} - __pyx_2 = PyObject_GetItem(__pyx_v_key, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; goto __pyx_L1;} + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":35 */ + __pyx_1 = PyInt_FromLong(3); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 35; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_key, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 35; goto __pyx_L1;} Py_DECREF(__pyx_1); __pyx_1 = 0; - __pyx_3 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; goto __pyx_L1;} + __pyx_3 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 35; goto __pyx_L1;} Py_DECREF(__pyx_2); __pyx_2 = 0; (__pyx_v_k[3]) = __pyx_3; - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":35 */ - decipher(__pyx_v_v,__pyx_v_k,__pyx_v_rounds); - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":36 */ - __pyx_1 = PyLong_FromUnsignedLong((__pyx_v_v[0])); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; goto __pyx_L1;} - __pyx_2 = PyLong_FromUnsignedLong((__pyx_v_v[1])); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; goto __pyx_L1;} - __pyx_4 = PyList_New(2); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; goto __pyx_L1;} - PyList_SET_ITEM(__pyx_4, 0, __pyx_1); - PyList_SET_ITEM(__pyx_4, 1, __pyx_2); + __pyx_1 = PyInt_FromLong(xxtea_decipher(__pyx_v_v,__pyx_v_k,__pyx_v_rounds)); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; goto __pyx_L1;} + Py_DECREF(__pyx_v_rc); + __pyx_v_rc = __pyx_1; __pyx_1 = 0; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":37 */ + __pyx_2 = PyLong_FromUnsignedLong((__pyx_v_v[0])); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 37; goto __pyx_L1;} + __pyx_1 = PyLong_FromUnsignedLong((__pyx_v_v[1])); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 37; goto __pyx_L1;} + __pyx_4 = PyList_New(2); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 37; goto __pyx_L1;} + PyList_SET_ITEM(__pyx_4, 0, __pyx_2); + PyList_SET_ITEM(__pyx_4, 1, __pyx_1); __pyx_2 = 0; + __pyx_1 = 0; Py_DECREF(__pyx_v_result); __pyx_v_result = __pyx_4; __pyx_4 = 0; - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":37 */ + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":38 */ Py_INCREF(__pyx_v_result); __pyx_r = __pyx_v_result; goto __pyx_L0; @@ -230,28 +239,307 @@ Py_XDECREF(__pyx_1); Py_XDECREF(__pyx_2); Py_XDECREF(__pyx_4); - __Pyx_AddTraceback("_xtea._c_xtea_decryptQuad"); + __Pyx_AddTraceback("_xtea._c_xxtea_decryptQuad"); __pyx_r = 0; __pyx_L0:; + Py_DECREF(__pyx_v_rc); Py_DECREF(__pyx_v_result); Py_DECREF(__pyx_v_key); return __pyx_r; } +static PyObject *__pyx_n_len; +static PyObject *__pyx_n_append; + +static PyObject *__pyx_f_5_xtea__c_xxtea_encrypt(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_f_5_xtea__c_xxtea_encrypt(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_block = 0; + PyObject *__pyx_v_key = 0; + unsigned int __pyx_v_rounds; + unsigned long (__pyx_v_k[4]); + unsigned long (*__pyx_v_v); + int __pyx_v_rc; + int __pyx_v_size; + int __pyx_v_vsize; + int __pyx_v_i; + PyObject *__pyx_v_result; + PyObject *__pyx_r; + PyObject *__pyx_1 = 0; + PyObject *__pyx_2 = 0; + PyObject *__pyx_3 = 0; + int __pyx_4; + unsigned long __pyx_5; + static char *__pyx_argnames[] = {"block","key","rounds",0}; + if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "OOI", __pyx_argnames, &__pyx_v_block, &__pyx_v_key, &__pyx_v_rounds)) return 0; + Py_INCREF(__pyx_v_block); + Py_INCREF(__pyx_v_key); + __pyx_v_result = Py_None; Py_INCREF(Py_None); + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":43 */ + __pyx_1 = __Pyx_GetName(__pyx_b, __pyx_n_len); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 43; goto __pyx_L1;} + __pyx_2 = PyTuple_New(1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 43; goto __pyx_L1;} + Py_INCREF(__pyx_v_block); + PyTuple_SET_ITEM(__pyx_2, 0, __pyx_v_block); + __pyx_3 = PyObject_CallObject(__pyx_1, __pyx_2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 43; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + Py_DECREF(__pyx_2); __pyx_2 = 0; + __pyx_4 = PyInt_AsLong(__pyx_3); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 43; goto __pyx_L1;} + Py_DECREF(__pyx_3); __pyx_3 = 0; + __pyx_v_size = __pyx_4; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":44 */ + __pyx_v_vsize = ((sizeof(unsigned long )) * __pyx_v_size); + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":45 */ + __pyx_v_v = ((unsigned long (*))malloc(__pyx_v_vsize)); + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":46 */ + for (__pyx_v_i = 0; __pyx_v_i < __pyx_v_size; ++__pyx_v_i) { + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":47 */ + __pyx_1 = PyInt_FromLong(__pyx_v_i); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 47; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_block, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 47; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + __pyx_5 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 47; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + (__pyx_v_v[__pyx_v_i]) = __pyx_5; + __pyx_L2:; + } + __pyx_L3:; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":48 */ + __pyx_3 = PyInt_FromLong(0); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; goto __pyx_L1;} + __pyx_1 = PyObject_GetItem(__pyx_v_key, __pyx_3); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; goto __pyx_L1;} + Py_DECREF(__pyx_3); __pyx_3 = 0; + __pyx_5 = PyInt_AsUnsignedLongMask(__pyx_1); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + (__pyx_v_k[0]) = __pyx_5; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":48 */ + __pyx_2 = PyInt_FromLong(1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; goto __pyx_L1;} + __pyx_3 = PyObject_GetItem(__pyx_v_key, __pyx_2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + __pyx_5 = PyInt_AsUnsignedLongMask(__pyx_3); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; goto __pyx_L1;} + Py_DECREF(__pyx_3); __pyx_3 = 0; + (__pyx_v_k[1]) = __pyx_5; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":48 */ + __pyx_1 = PyInt_FromLong(2); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_key, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + __pyx_5 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + (__pyx_v_k[2]) = __pyx_5; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":48 */ + __pyx_3 = PyInt_FromLong(3); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; goto __pyx_L1;} + __pyx_1 = PyObject_GetItem(__pyx_v_key, __pyx_3); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; goto __pyx_L1;} + Py_DECREF(__pyx_3); __pyx_3 = 0; + __pyx_5 = PyInt_AsUnsignedLongMask(__pyx_1); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 48; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + (__pyx_v_k[3]) = __pyx_5; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":49 */ + __pyx_v_rc = xtea_encipher(__pyx_v_v,__pyx_v_k,__pyx_v_rounds); + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":50 */ + __pyx_2 = PyList_New(0); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 50; goto __pyx_L1;} + Py_DECREF(__pyx_v_result); + __pyx_v_result = __pyx_2; + __pyx_2 = 0; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":51 */ + for (__pyx_v_i = 0; __pyx_v_i < __pyx_v_size; ++__pyx_v_i) { + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":52 */ + __pyx_3 = PyObject_GetAttr(__pyx_v_result, __pyx_n_append); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 52; goto __pyx_L1;} + __pyx_1 = PyLong_FromUnsignedLong((__pyx_v_v[__pyx_v_i])); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 52; goto __pyx_L1;} + __pyx_2 = PyTuple_New(1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 52; goto __pyx_L1;} + PyTuple_SET_ITEM(__pyx_2, 0, __pyx_1); + __pyx_1 = 0; + __pyx_1 = PyObject_CallObject(__pyx_3, __pyx_2); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 52; goto __pyx_L1;} + Py_DECREF(__pyx_3); __pyx_3 = 0; + Py_DECREF(__pyx_2); __pyx_2 = 0; + Py_DECREF(__pyx_1); __pyx_1 = 0; + __pyx_L4:; + } + __pyx_L5:; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":53 */ + free(__pyx_v_v); + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":54 */ + Py_INCREF(__pyx_v_result); + __pyx_r = __pyx_v_result; + goto __pyx_L0; + + __pyx_r = Py_None; Py_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1:; + Py_XDECREF(__pyx_1); + Py_XDECREF(__pyx_2); + Py_XDECREF(__pyx_3); + __Pyx_AddTraceback("_xtea._c_xxtea_encrypt"); + __pyx_r = 0; + __pyx_L0:; + Py_DECREF(__pyx_v_result); + Py_DECREF(__pyx_v_block); + Py_DECREF(__pyx_v_key); + return __pyx_r; +} + +static PyObject *__pyx_f_5_xtea__c_xxtea_decrypt(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_f_5_xtea__c_xxtea_decrypt(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_block = 0; + PyObject *__pyx_v_key = 0; + unsigned int __pyx_v_rounds; + unsigned long (__pyx_v_k[4]); + unsigned long (*__pyx_v_v); + int __pyx_v_rc; + int __pyx_v_size; + int __pyx_v_vsize; + int __pyx_v_i; + PyObject *__pyx_v_result; + PyObject *__pyx_r; + PyObject *__pyx_1 = 0; + PyObject *__pyx_2 = 0; + PyObject *__pyx_3 = 0; + int __pyx_4; + unsigned long __pyx_5; + static char *__pyx_argnames[] = {"block","key","rounds",0}; + if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "OOI", __pyx_argnames, &__pyx_v_block, &__pyx_v_key, &__pyx_v_rounds)) return 0; + Py_INCREF(__pyx_v_block); + Py_INCREF(__pyx_v_key); + __pyx_v_result = Py_None; Py_INCREF(Py_None); + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":59 */ + __pyx_1 = __Pyx_GetName(__pyx_b, __pyx_n_len); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 59; goto __pyx_L1;} + __pyx_2 = PyTuple_New(1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 59; goto __pyx_L1;} + Py_INCREF(__pyx_v_block); + PyTuple_SET_ITEM(__pyx_2, 0, __pyx_v_block); + __pyx_3 = PyObject_CallObject(__pyx_1, __pyx_2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 59; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + Py_DECREF(__pyx_2); __pyx_2 = 0; + __pyx_4 = PyInt_AsLong(__pyx_3); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 59; goto __pyx_L1;} + Py_DECREF(__pyx_3); __pyx_3 = 0; + __pyx_v_size = __pyx_4; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":60 */ + __pyx_v_vsize = ((sizeof(unsigned long )) * __pyx_v_size); + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":61 */ + __pyx_v_v = ((unsigned long (*))malloc(__pyx_v_vsize)); + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":62 */ + for (__pyx_v_i = 0; __pyx_v_i < __pyx_v_size; ++__pyx_v_i) { + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":63 */ + __pyx_1 = PyInt_FromLong(__pyx_v_i); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_block, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + __pyx_5 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 63; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + (__pyx_v_v[__pyx_v_i]) = __pyx_5; + __pyx_L2:; + } + __pyx_L3:; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":64 */ + __pyx_3 = PyInt_FromLong(0); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; goto __pyx_L1;} + __pyx_1 = PyObject_GetItem(__pyx_v_key, __pyx_3); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; goto __pyx_L1;} + Py_DECREF(__pyx_3); __pyx_3 = 0; + __pyx_5 = PyInt_AsUnsignedLongMask(__pyx_1); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + (__pyx_v_k[0]) = __pyx_5; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":64 */ + __pyx_2 = PyInt_FromLong(1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; goto __pyx_L1;} + __pyx_3 = PyObject_GetItem(__pyx_v_key, __pyx_2); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + __pyx_5 = PyInt_AsUnsignedLongMask(__pyx_3); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; goto __pyx_L1;} + Py_DECREF(__pyx_3); __pyx_3 = 0; + (__pyx_v_k[1]) = __pyx_5; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":64 */ + __pyx_1 = PyInt_FromLong(2); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_key, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + __pyx_5 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + (__pyx_v_k[2]) = __pyx_5; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":64 */ + __pyx_3 = PyInt_FromLong(3); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; goto __pyx_L1;} + __pyx_1 = PyObject_GetItem(__pyx_v_key, __pyx_3); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; goto __pyx_L1;} + Py_DECREF(__pyx_3); __pyx_3 = 0; + __pyx_5 = PyInt_AsUnsignedLongMask(__pyx_1); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 64; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + (__pyx_v_k[3]) = __pyx_5; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":65 */ + __pyx_v_rc = xtea_encipher(__pyx_v_v,__pyx_v_k,__pyx_v_rounds); + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":66 */ + __pyx_2 = PyList_New(0); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 66; goto __pyx_L1;} + Py_DECREF(__pyx_v_result); + __pyx_v_result = __pyx_2; + __pyx_2 = 0; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":67 */ + for (__pyx_v_i = 0; __pyx_v_i < __pyx_v_size; ++__pyx_v_i) { + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":68 */ + __pyx_3 = PyObject_GetAttr(__pyx_v_result, __pyx_n_append); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; goto __pyx_L1;} + __pyx_1 = PyLong_FromUnsignedLong((__pyx_v_v[__pyx_v_i])); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; goto __pyx_L1;} + __pyx_2 = PyTuple_New(1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; goto __pyx_L1;} + PyTuple_SET_ITEM(__pyx_2, 0, __pyx_1); + __pyx_1 = 0; + __pyx_1 = PyObject_CallObject(__pyx_3, __pyx_2); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 68; goto __pyx_L1;} + Py_DECREF(__pyx_3); __pyx_3 = 0; + Py_DECREF(__pyx_2); __pyx_2 = 0; + Py_DECREF(__pyx_1); __pyx_1 = 0; + __pyx_L4:; + } + __pyx_L5:; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":69 */ + free(__pyx_v_v); + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":70 */ + Py_INCREF(__pyx_v_result); + __pyx_r = __pyx_v_result; + goto __pyx_L0; + + __pyx_r = Py_None; Py_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1:; + Py_XDECREF(__pyx_1); + Py_XDECREF(__pyx_2); + Py_XDECREF(__pyx_3); + __Pyx_AddTraceback("_xtea._c_xxtea_decrypt"); + __pyx_r = 0; + __pyx_L0:; + Py_DECREF(__pyx_v_result); + Py_DECREF(__pyx_v_block); + Py_DECREF(__pyx_v_key); + return __pyx_r; +} + static __Pyx_InternTabEntry __pyx_intern_tab[] = { - {&__pyx_n_MODE_CBC, "MODE_CBC"}, - {&__pyx_n_MODE_CFB, "MODE_CFB"}, - {&__pyx_n_MODE_CTR, "MODE_CTR"}, - {&__pyx_n_MODE_ECB, "MODE_ECB"}, - {&__pyx_n_MODE_OFB, "MODE_OFB"}, - {&__pyx_n__c_xtea_decryptQuad, "_c_xtea_decryptQuad"}, {&__pyx_n__c_xtea_encryptQuad, "_c_xtea_encryptQuad"}, + {&__pyx_n__c_xxtea_decrypt, "_c_xxtea_decrypt"}, + {&__pyx_n__c_xxtea_decryptQuad, "_c_xxtea_decryptQuad"}, + {&__pyx_n__c_xxtea_encrypt, "_c_xxtea_encrypt"}, + {&__pyx_n_append, "append"}, + {&__pyx_n_len, "len"}, {0, 0} }; static struct PyMethodDef __pyx_methods[] = { {"_c_xtea_encryptQuad", (PyCFunction)__pyx_f_5_xtea__c_xtea_encryptQuad, METH_VARARGS|METH_KEYWORDS, 0}, - {"_c_xtea_decryptQuad", (PyCFunction)__pyx_f_5_xtea__c_xtea_decryptQuad, METH_VARARGS|METH_KEYWORDS, 0}, + {"_c_xxtea_decryptQuad", (PyCFunction)__pyx_f_5_xtea__c_xxtea_decryptQuad, METH_VARARGS|METH_KEYWORDS, 0}, + {"_c_xxtea_encrypt", (PyCFunction)__pyx_f_5_xtea__c_xxtea_encrypt, METH_VARARGS|METH_KEYWORDS, 0}, + {"_c_xxtea_decrypt", (PyCFunction)__pyx_f_5_xtea__c_xxtea_decrypt, METH_VARARGS|METH_KEYWORDS, 0}, {0, 0, 0, 0} }; @@ -259,44 +547,17 @@ PyMODINIT_FUNC init_xtea(void); /*proto*/ PyMODINIT_FUNC init_xtea(void) { - PyObject *__pyx_1 = 0; __pyx_init_filenames(); __pyx_m = Py_InitModule4("_xtea", __pyx_methods, 0, 0, PYTHON_API_VERSION); - if (!__pyx_m) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 8; goto __pyx_L1;}; + if (!__pyx_m) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 7; goto __pyx_L1;}; __pyx_b = PyImport_AddModule("__builtin__"); - if (!__pyx_b) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 8; goto __pyx_L1;}; - if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 8; goto __pyx_L1;}; - if (__Pyx_InternStrings(__pyx_intern_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 8; goto __pyx_L1;}; + if (!__pyx_b) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 7; goto __pyx_L1;}; + if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 7; goto __pyx_L1;}; + if (__Pyx_InternStrings(__pyx_intern_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 7; goto __pyx_L1;}; - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":15 */ - __pyx_1 = PyInt_FromLong(1); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 15; goto __pyx_L1;} - if (PyObject_SetAttr(__pyx_m, __pyx_n_MODE_ECB, __pyx_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 15; goto __pyx_L1;} - Py_DECREF(__pyx_1); __pyx_1 = 0; - - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":16 */ - __pyx_1 = PyInt_FromLong(2); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; goto __pyx_L1;} - if (PyObject_SetAttr(__pyx_m, __pyx_n_MODE_CBC, __pyx_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; goto __pyx_L1;} - Py_DECREF(__pyx_1); __pyx_1 = 0; - - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":17 */ - __pyx_1 = PyInt_FromLong(4); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 17; goto __pyx_L1;} - if (PyObject_SetAttr(__pyx_m, __pyx_n_MODE_CFB, __pyx_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 17; goto __pyx_L1;} - Py_DECREF(__pyx_1); __pyx_1 = 0; - - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":18 */ - __pyx_1 = PyInt_FromLong(5); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 18; goto __pyx_L1;} - if (PyObject_SetAttr(__pyx_m, __pyx_n_MODE_OFB, __pyx_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 18; goto __pyx_L1;} - Py_DECREF(__pyx_1); __pyx_1 = 0; - - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":19 */ - __pyx_1 = PyInt_FromLong(6); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 19; goto __pyx_L1;} - if (PyObject_SetAttr(__pyx_m, __pyx_n_MODE_CTR, __pyx_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 19; goto __pyx_L1;} - Py_DECREF(__pyx_1); __pyx_1 = 0; - - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":30 */ + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":56 */ return; __pyx_L1:; - Py_XDECREF(__pyx_1); __Pyx_AddTraceback("_xtea"); } @@ -310,6 +571,14 @@ __pyx_f = __pyx_filenames; } +static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name) { + PyObject *result; + result = PyObject_GetAttr(dict, name); + if (!result) + PyErr_SetObject(PyExc_NameError, name); + return result; +} + static int __Pyx_InternStrings(__Pyx_InternTabEntry *t) { while (t->p) { *t->p = PyString_InternFromString(t->s); Modified: xtea/trunk/src/xtea/_xtea.pyx =================================================================== --- xtea/trunk/src/xtea/_xtea.pyx 2007-03-01 17:41:40 UTC (rev 222) +++ xtea/trunk/src/xtea/_xtea.pyx 2007-03-02 14:54:09 UTC (rev 223) @@ -3,35 +3,68 @@ # License: Public Domain # http://www.python.org/dev/peps/pep-0272/ -# http://en.wikipedia.org/wiki/XTEA ctypedef unsigned long ULong ctypedef unsigned int UInt +cdef extern from "stdlib.h": + ctypedef unsigned long size_t + void *malloc(size_t size) + void free(void* ptr) + size_t sizeof(void *) + cdef extern from "cxtea.h": - void decipher(ULong *v, ULong *k, UInt rounds) - void encipher(ULong *v, ULong *k, UInt rounds) + int xtea_decipher(ULong *v, ULong *k, UInt n) + int xtea_encipher(ULong *v, ULong *k, UInt n) + int xxtea_decipher(ULong *v, ULong *k, UInt n) + int xxtea_encipher(ULong *v, ULong *k, UInt n) -MODE_ECB = 1 # Electronic Code Book -MODE_CBC = 2 # Cipher Block Chaining -MODE_CFB = 4 # Cipher Feedback -MODE_OFB = 5 # Output Feedback -MODE_CTR = 6 # Counter - def _c_xtea_encryptQuad(ULong v0, ULong v1, object key, UInt rounds): cdef ULong v[2] cdef ULong k[4] v[0] = v0; v[1] = v1 - k[0] = key[0]; k[1] = key[1]; k[2] = key[2]; k[3] = key[3]; - encipher(v, k, rounds) + k[0] = key[0]; k[1] = key[1]; k[2] = key[2]; k[3] = key[3] + rc = xtea_encipher(v, k, rounds) result = [v[0], v[1]] return result -def _c_xtea_decryptQuad(ULong v0, ULong v1, key, UInt rounds): +def _c_xxtea_decryptQuad(ULong v0, ULong v1, object key, UInt rounds): cdef ULong v[2] cdef ULong k[4] v[0] = v0; v[1] = v1 - k[0] = key[0]; k[1] = key[1]; k[2] = key[2]; k[3] = key[3]; - decipher(v, k, rounds) + k[0] = key[0]; k[1] = key[1]; k[2] = key[2]; k[3] = key[3] + rc = xxtea_decipher(v, k, rounds) result = [v[0], v[1]] return result + +def _c_xxtea_encrypt(object block, key, UInt rounds): + cdef ULong k[4], *v + cdef int rc, size, vsize, i + size = len(block) + vsize = sizeof(ULong) * size + v = <ULong *>malloc(vsize) + for i from 0 <= i < size: + v[i] = block[i] + k[0] = key[0]; k[1] = key[1]; k[2] = key[2]; k[3] = key[3] + rc = xtea_encipher(v, k, rounds) + result = [] + for i from 0 <= i < size: + result.append(v[i]) + free(v) + return result + +def _c_xxtea_decrypt(object block, key, UInt rounds): + cdef ULong k[4], *v + cdef int rc, size, vsize, i + size = len(block) + vsize = sizeof(ULong) * size + v = <ULong *>malloc(vsize) + for i from 0 <= i < size: + v[i] = block[i] + k[0] = key[0]; k[1] = key[1]; k[2] = key[2]; k[3] = key[3] + rc = xtea_encipher(v, k, rounds) + result = [] + for i from 0 <= i < size: + result.append(v[i]) + free(v) + return result Modified: xtea/trunk/src/xtea/cxtea.c =================================================================== --- xtea/trunk/src/xtea/cxtea.c 2007-03-01 17:41:40 UTC (rev 222) +++ xtea/trunk/src/xtea/cxtea.c 2007-03-02 14:54:09 UTC (rev 223) @@ -3,30 +3,81 @@ License: Public Domain Source: http://en.wikipedia.org/wiki/XTEA + http://www.cix.co.uk/~klockstone/xxtea.pdf + http://www-users.cs.york.ac.uk/~matthew/TEA/ */ #include "cxtea.h" -void decipher(ULong *const v, const ULong *const k, const UInt rounds) +/* XTEA decipher / encipher + * v - array with 2 values + * k - array with 4 values + * n - number of rounds + */ + +int xtea_decipher(ULong *const v, const ULong *const k, const UInt n) { register UInt i; - register ULong delta=0x9E3779B9; - register ULong sum=delta*rounds; - for (i=0; i < rounds; i++) { + register ULong delta=0x9E3779B9, sum=delta*n; + for (i=0; i < n; i++) { v[1] -= ((v[0]<<4 ^ v[0]>>5) + v[0]) ^ (sum + k[sum>>11 & 3]); sum -= delta; v[0] -= ((v[1]<<4 ^ v[1]>>5) + v[1]) ^ (sum + k[sum & 3]); } + return 0; } -void encipher(ULong *const v, const ULong *const k, const UInt rounds) +int xtea_encipher(ULong *const v, const ULong *const k, const UInt n) { register UInt i; - register ULong delta=0x9E3779B9; - register ULong sum=0; - for (i=0; i < rounds; i++) { + register ULong delta=0x9E3779B9, sum=0; + for (i=0; i < n; i++) { v[0] += ((v[1]<<4 ^ v[1]>>5) + v[1]) ^ (sum + k[sum & 3]); sum += delta; v[1] += ((v[0]<<4 ^ v[0]>>5) + v[0]) ^ (sum + k[sum>>11 & 3]); } + return 0; } + +/* xxTEA or block TEA 2 + * Fixed version w/o underflow issue in z=v[n-1] + * v - array with n values + * k - array with 4 values + * n - rounds and number of values in v + */ + +#define MX (((z>>5)^(y<<2))+(((y>>3)^(z<<4))^(sum^y))+(k[(p&3)^e]^z)); + +int xxtea_encipher(ULong *const v, const ULong *const k, const UInt n) + { + register long p, q=6+52/n; + register ULong z=v[n-1], y=v[0], e, DELTA=0x9e3779b9, sum=0; + while (q-- > 0) { + sum += DELTA; + e = sum >> 2 & 3; + for (p=0; p<n-1; p++) { + y = v[p+1]; + z = v[p] += MX; + } + y = v[0]; + z = v[n-1] += MX; + } + return 0; + } + +int xxtea_decipher(ULong *const v, const ULong *const k, const UInt n) + { + register long p, q=6+52/n; + register ULong z=v[n-1], y=v[0], e, DELTA=0x9e3779b9, sum=q*DELTA; + while (sum != 0) { + e = sum>>2 & 3; + for (p=n-1; p>0; p--) { + z = v[p-1]; + y = v[p] -= MX; + } + z = v[n-1]; + y = v[0] -= MX; + sum -= DELTA; + } + return 0; + } Modified: xtea/trunk/src/xtea/cxtea.h =================================================================== --- xtea/trunk/src/xtea/cxtea.h 2007-03-01 17:41:40 UTC (rev 222) +++ xtea/trunk/src/xtea/cxtea.h 2007-03-02 14:54:09 UTC (rev 223) @@ -1,8 +1,6 @@ /* Copyright (C) 2007 Christian Heimes <christian (at) cheimes (dot) de> pyrexc optimized version License: Public Domain - - Source: http://en.wikipedia.org/wiki/XTEA */ #define MODE_ECB 1 // Electronic Code Book @@ -14,6 +12,7 @@ typedef unsigned long ULong; typedef unsigned int UInt; -void decipher(ULong *const v, const ULong *const k, const UInt rounds); -void encipher(ULong *const v, const ULong *const k, const UInt rounds); - +int xtea_decipher(ULong *const v, const ULong *const k, const UInt n); +int xtea_encipher(ULong *const v, const ULong *const k, const UInt n); +int xxtea_decipher(ULong *const v, const ULong *const k, const UInt n); +int xxtea_encipher(ULong *const v, const ULong *const k, const UInt n); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ti...@us...> - 2007-03-01 17:41:39
|
Revision: 222 http://pymoul.svn.sourceforge.net/pymoul/?rev=222&view=rev Author: tiran Date: 2007-03-01 09:41:40 -0800 (Thu, 01 Mar 2007) Log Message: ----------- Use new xtea module Modified Paths: -------------- pymoul/trunk/src/moul/crypt/whatdoyousee.py Modified: pymoul/trunk/src/moul/crypt/whatdoyousee.py =================================================================== --- pymoul/trunk/src/moul/crypt/whatdoyousee.py 2007-03-01 17:33:31 UTC (rev 221) +++ pymoul/trunk/src/moul/crypt/whatdoyousee.py 2007-03-01 17:41:40 UTC (rev 222) @@ -29,19 +29,16 @@ __revision__ = "$Revision$" import struct +import xtea from logging import getLogger - from moul.crypt.binary import BinaryFile -from xtea import xtea_decrypt -from xtea import xtea_encrypt - HEADER = "whatdoyousee" CROSS_REF = (0x6c0a5452, 0x03827d0f, 0x3a170b92, 0x16db7fc2) CROSS_KEY = struct.pack("<4L", *CROSS_REF) -ENDIAN="<" # little endian (not network/big endian) - LOG = getLogger('moul.crypt.whatdoyousee') +XTEA = xtea.new(CROSS_KEY, endian=xtea.LITTLE_ENDIAN) +ENDIAN = "<" def decryptWDYS(fin): """Decrypt whatdoyousee files @@ -62,7 +59,7 @@ if not block: break try: - block = xtea_decrypt(CROSS_KEY, block, endian=ENDIAN) + block = XTEA.decrypt(block) except: LOG.exception("xTEA failure at block %r" % block) raise @@ -101,7 +98,7 @@ block = block + '\0' * (8-len(block)) assert len(block) == 8 try: - block = xtea_encrypt(CROSS_KEY, block, endian=ENDIAN) + block = XTEA.encrypt(block) except: LOG.exception("xTEA failure at block %r" % block) raise This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ti...@us...> - 2007-03-01 17:33:37
|
Revision: 221 http://pymoul.svn.sourceforge.net/pymoul/?rev=221&view=rev Author: tiran Date: 2007-03-01 09:33:31 -0800 (Thu, 01 Mar 2007) Log Message: ----------- Added tests.py Modified Paths: -------------- xtea/trunk/Makefile xtea/trunk/README.txt Added Paths: ----------- xtea/trunk/src/xtea/tests.py Modified: xtea/trunk/Makefile =================================================================== --- xtea/trunk/Makefile 2007-03-01 16:34:49 UTC (rev 220) +++ xtea/trunk/Makefile 2007-03-01 17:33:31 UTC (rev 221) @@ -32,7 +32,7 @@ # What should the default be? test: - $(PYTHON) src/xtea/xtea.py + PYTHONPATH=src $(PYTHON) src/xtea/tests.py egg: egg24 egg25 Modified: xtea/trunk/README.txt =================================================================== --- xtea/trunk/README.txt 2007-03-01 16:34:49 UTC (rev 220) +++ xtea/trunk/README.txt 2007-03-01 17:33:31 UTC (rev 221) @@ -7,19 +7,18 @@ Christian Heimes (christian (at) cheimes (dot) de) -Paul Chakravarti: - * Initial implementation of the XTEA algorithm for Python. +Paul Chakravarti +---------------- -Christian Heimes: - * PEP 272 conform implementation using the original crypt(), xtea_decrypt() - and xtea_encrypt() functions from Paul Chakravarti. +Initial implementation of the XTEA algorithm for Python. - * Pyrex/C optimization written based on the wikipedia entry - http://en.wikipedia.org/wiki/XTEA +Christian Heimes +---------------- - * setup.py, Makefile and eggification +PEP 272 conform implementation using the original crypt(), xtea_decrypt() +and xtea_encrypt() functions from Paul Chakravarti. +Pyrex/C optimization written based on the wikipedia entry +http://en.wikipedia.org/wiki/XTEA - - - +setup.py, Makefile and eggification Added: xtea/trunk/src/xtea/tests.py =================================================================== --- xtea/trunk/src/xtea/tests.py (rev 0) +++ xtea/trunk/src/xtea/tests.py 2007-03-01 17:33:31 UTC (rev 221) @@ -0,0 +1,38 @@ +# Copyright (C) 2007 Christian Heimes <christian (at) cheimes (dot) de> +"""xtea unit tests +""" +__author__ = "Christian Heimes" +__version__ = "$Id: tests.py 216 2007-02-28 12:06:48Z tiran $" +__revision__ = "$Revision: 216 $" + +import os +import unittest +from doctest import DocTestSuite + +# make sure it's the module and not the package +from xtea import HOST_ENDIAN + +class CXteaTestCase(unittest.TestCase): + def setUp(self): + pass + + def tearDown(self): + pass + +class PyXteaTestCase(unittest.TestCase): + def setUp(self): + pass + + def tearDown(self): + pass + +def test_suite(): + return unittest.TestSuite(( + unittest.makeSuite(CXteaTestCase), + unittest.makeSuite(PyXteaTestCase), + DocTestSuite('xtea'), + )) + +if __name__ == '__main__': + unittest.main(defaultTest="test_suite") + Property changes on: xtea/trunk/src/xtea/tests.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. |
From: <ti...@us...> - 2007-03-01 16:34:57
|
Revision: 220 http://pymoul.svn.sourceforge.net/pymoul/?rev=220&view=rev Author: tiran Date: 2007-03-01 08:34:49 -0800 (Thu, 01 Mar 2007) Log Message: ----------- Updated READMEs and version Modified Paths: -------------- xtea/trunk/CHANGES.txt xtea/trunk/INSTALL.txt xtea/trunk/LICENSE.txt xtea/trunk/README.txt xtea/trunk/setup.py xtea/trunk/src/xtea.egg-info/PKG-INFO xtea/trunk/src/xtea.egg-info/SOURCES.txt xtea/trunk/version.txt Modified: xtea/trunk/CHANGES.txt =================================================================== --- xtea/trunk/CHANGES.txt 2007-03-01 16:25:39 UTC (rev 219) +++ xtea/trunk/CHANGES.txt 2007-03-01 16:34:49 UTC (rev 220) @@ -0,0 +1,5 @@ +0.1 2007/03/01 + + * PEP 272 style XTEA module + * pyrex + c optimization + * setuptools and eggification Modified: xtea/trunk/INSTALL.txt =================================================================== --- xtea/trunk/INSTALL.txt 2007-03-01 16:25:39 UTC (rev 219) +++ xtea/trunk/INSTALL.txt 2007-03-01 16:34:49 UTC (rev 220) @@ -4,7 +4,11 @@ * Python 2.4+ http://www.python.org/ * easy_install http://peak.telecommunity.com/DevCenter/EasyInstall - * setuptools (via easy install) + * setuptools (via easy install) + + optional: + * C compiler for the optimized C implementation (gcc 4, MinGW32) + * pyrex ============ Installation Modified: xtea/trunk/LICENSE.txt =================================================================== --- xtea/trunk/LICENSE.txt 2007-03-01 16:25:39 UTC (rev 219) +++ xtea/trunk/LICENSE.txt 2007-03-01 16:34:49 UTC (rev 220) @@ -1 +1 @@ -Public Domain \ No newline at end of file +Public Domain Modified: xtea/trunk/README.txt =================================================================== --- xtea/trunk/README.txt 2007-03-01 16:25:39 UTC (rev 219) +++ xtea/trunk/README.txt 2007-03-01 16:34:49 UTC (rev 220) @@ -1,30 +1,25 @@ XTEA Block Encryption Algorithm +=============================== -Author: Paul Chakravarti (paul_dot_chakravarti_at_mac_dot_com) License: Public Domain -pyrex optimization: Christian Heimes +Authors: Paul Chakravarti (paul_dot_chakravarti_at_mac_dot_com) + Christian Heimes (christian (at) cheimes (dot) de) -This module provides a Python implementation of the XTEA block encryption -algorithm (http://www.cix.co.uk/~klockstone/xtea.pdf). -The module implements the basic XTEA block encryption algortithm -(`xtea_encrypt`/`xtea_decrypt`) and also provides a higher level `crypt` -function which symmetrically encrypts/decrypts a variable length string using -XTEA in OFB mode as a key generator. The `crypt` function does not use -`xtea_decrypt` which is provided for completeness only (but can be used -to support other stream modes - eg CBC/CFB). +Paul Chakravarti: + * Initial implementation of the XTEA algorithm for Python. -This module is intended to provide a simple 'privacy-grade' Python encryption -algorithm with no external dependencies. The implementation is relatively slow -and is best suited to small volumes of data. Note that the XTEA algorithm has -not been subjected to extensive analysis (though is believed to be relatively -secure - see http://en.wikipedia.org/wiki/XTEA). For applications requiring -'real' security please use a known and well tested algorithm/implementation. +Christian Heimes: + * PEP 272 conform implementation using the original crypt(), xtea_decrypt() + and xtea_encrypt() functions from Paul Chakravarti. -The security of the algorithm is entirely based on quality (entropy) and -secrecy of the key. You should generate the key from a known random source and -exchange using a trusted mechanism. In addition, you should always use a random -IV to seed the key generator (the IV is not sensitive and does not need to be -exchanged securely) + * Pyrex/C optimization written based on the wikipedia entry + http://en.wikipedia.org/wiki/XTEA + * setup.py, Makefile and eggification + + + + + Modified: xtea/trunk/setup.py =================================================================== --- xtea/trunk/setup.py 2007-03-01 16:25:39 UTC (rev 219) +++ xtea/trunk/setup.py 2007-03-01 16:34:49 UTC (rev 220) @@ -33,7 +33,7 @@ from distutils.core import setup -VERSION = "1.0" +VERSION = "0.1" me = "Christian Heimes" email = "chr...@ch..." @@ -59,7 +59,8 @@ keywords = ["xtea", "crypt", "encryption", "decryption"], platforms = ['Independent'], classifiers = ( - 'Development Status :: 6 - Mature', + #'Development Status :: 6 - Mature', + 'Development Status :: 4 - Beta', 'Intended Audience :: Developers', 'License :: Public Domain', 'Operating System :: OS Independent' @@ -75,4 +76,3 @@ ) setup(**setup_infos) - Modified: xtea/trunk/src/xtea.egg-info/PKG-INFO =================================================================== --- xtea/trunk/src/xtea.egg-info/PKG-INFO 2007-03-01 16:25:39 UTC (rev 219) +++ xtea/trunk/src/xtea.egg-info/PKG-INFO 2007-03-01 16:34:49 UTC (rev 220) @@ -1,6 +1,6 @@ Metadata-Version: 1.0 Name: xtea -Version: 1.0 +Version: 0.1 Summary: XTEA Block Encryption Algorithm Home-page: http://sourceforge.net/projects/pymoul/ Author: Christian Heimes @@ -20,7 +20,7 @@ Keywords: xtea,crypt,encryption,decryption Platform: Independent -Classifier: Development Status :: 6 - Mature +Classifier: Development Status :: 4 - Beta Classifier: Intended Audience :: Developers Classifier: License :: Public Domain Classifier: Operating System :: OS IndependentNatural Language :: English Modified: xtea/trunk/src/xtea.egg-info/SOURCES.txt =================================================================== --- xtea/trunk/src/xtea.egg-info/SOURCES.txt 2007-03-01 16:25:39 UTC (rev 219) +++ xtea/trunk/src/xtea.egg-info/SOURCES.txt 2007-03-01 16:34:49 UTC (rev 220) @@ -9,7 +9,9 @@ version.txt src/xtea/__init__.py src/xtea/_xtea.c -src/xtea/tests.py +src/xtea/_xtea.pyx +src/xtea/cxtea.c +src/xtea/cxtea.h src/xtea/xtea.py src/xtea.egg-info/PKG-INFO src/xtea.egg-info/SOURCES.txt Modified: xtea/trunk/version.txt =================================================================== --- xtea/trunk/version.txt 2007-03-01 16:25:39 UTC (rev 219) +++ xtea/trunk/version.txt 2007-03-01 16:34:49 UTC (rev 220) @@ -1 +1 @@ -1.0 +0.1 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ti...@us...> - 2007-03-01 16:25:42
|
Revision: 219 http://pymoul.svn.sourceforge.net/pymoul/?rev=219&view=rev Author: tiran Date: 2007-03-01 08:25:39 -0800 (Thu, 01 Mar 2007) Log Message: ----------- PEP 272 conform XTEA module with pyrex/c optimization Modified Paths: -------------- xtea/trunk/Makefile xtea/trunk/setup.py xtea/trunk/src/xtea/__init__.py xtea/trunk/src/xtea/_xtea.c xtea/trunk/src/xtea/_xtea.pyx xtea/trunk/src/xtea/xtea.py Added Paths: ----------- xtea/trunk/src/xtea/cxtea.c xtea/trunk/src/xtea/cxtea.h Modified: xtea/trunk/Makefile =================================================================== --- xtea/trunk/Makefile 2007-02-28 12:13:59 UTC (rev 218) +++ xtea/trunk/Makefile 2007-03-01 16:25:39 UTC (rev 219) @@ -9,15 +9,12 @@ all: inplace # Build in-place -inplace: pyrex +inplace: $(PYTHON) setup.py $(SETUPFLAGS) build_ext -i -build: pyrex +build: $(PYTHON) setup.py $(SETUPFLAGS) build -pyrex: - pyrexc src/xtea/_xtea.pyx - egg24: $(PYTHON24) setup.py $(SETUPFLAGS) bdist_egg Modified: xtea/trunk/setup.py =================================================================== --- xtea/trunk/setup.py 2007-02-28 12:13:59 UTC (rev 218) +++ xtea/trunk/setup.py 2007-03-01 16:25:39 UTC (rev 219) @@ -38,9 +38,10 @@ me = "Christian Heimes" email = "chr...@ch..." +cxtea = Extension('xtea._xtea', ['src/xtea/_xtea.pyx', 'src/xtea/cxtea.c']) ext_modules = [] if os.name == 'posix': - ext_modules.append(Extension('xtea._xtea', ['src/xtea/_xtea.c'])) + ext_modules.append(cxtea) setup_infos = dict( name = "xtea", Modified: xtea/trunk/src/xtea/__init__.py =================================================================== --- xtea/trunk/src/xtea/__init__.py 2007-02-28 12:13:59 UTC (rev 218) +++ xtea/trunk/src/xtea/__init__.py 2007-03-01 16:25:39 UTC (rev 219) @@ -1,6 +1,7 @@ # xtea package -from xtea import crypt -from xtea import xtea_encrypt -from xtea import xtea_encryptQuad -from xtea import xtea_decrypt -from xtea import xtea_decryptQuad +from xtea import new +from xtea import MODE_ECB +from xtea import MODE_OFB +from xtea import BIG_ENDIAN +from xtea import LITTLE_ENDIAN +from xtea import NETWORK_ENDIAN Modified: xtea/trunk/src/xtea/_xtea.c =================================================================== --- xtea/trunk/src/xtea/_xtea.c 2007-02-28 12:13:59 UTC (rev 218) +++ xtea/trunk/src/xtea/_xtea.c 2007-03-01 16:25:39 UTC (rev 219) @@ -1,4 +1,4 @@ -/* Generated by Pyrex 0.9.4.1 on Wed Feb 28 12:58:37 2007 */ +/* Generated by Pyrex 0.9.4.1 on Thu Mar 1 15:44:44 2007 */ #include "Python.h" #include "structmember.h" @@ -11,6 +11,7 @@ #define __PYX_EXTERN_C extern #endif __PYX_EXTERN_C double pow(double, double); +#include "cxtea.h" typedef struct {PyObject **p; char *s;} __Pyx_InternTabEntry; /*proto*/ @@ -47,6 +48,11 @@ /* Implementation of _xtea */ +static PyObject *__pyx_n_MODE_ECB; +static PyObject *__pyx_n_MODE_CBC; +static PyObject *__pyx_n_MODE_CFB; +static PyObject *__pyx_n_MODE_OFB; +static PyObject *__pyx_n_MODE_CTR; static PyObject *__pyx_n__c_xtea_encryptQuad; static PyObject *__pyx_n__c_xtea_decryptQuad; @@ -55,97 +61,74 @@ unsigned long __pyx_v_v0; unsigned long __pyx_v_v1; PyObject *__pyx_v_key = 0; - int __pyx_v_rounds; - int __pyx_v_i; - unsigned long __pyx_v_delta; - unsigned long __pyx_v_sum; + unsigned int __pyx_v_rounds; + unsigned long (__pyx_v_v[2]); + unsigned long (__pyx_v_k[4]); PyObject *__pyx_v_result; PyObject *__pyx_r; PyObject *__pyx_1 = 0; PyObject *__pyx_2 = 0; - PyObject *__pyx_3 = 0; + unsigned long __pyx_3; PyObject *__pyx_4 = 0; - PyObject *__pyx_5 = 0; - unsigned long __pyx_6; static char *__pyx_argnames[] = {"v0","v1","key","rounds",0}; - if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "kkOi", __pyx_argnames, &__pyx_v_v0, &__pyx_v_v1, &__pyx_v_key, &__pyx_v_rounds)) return 0; + if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "kkOI", __pyx_argnames, &__pyx_v_v0, &__pyx_v_v1, &__pyx_v_key, &__pyx_v_rounds)) return 0; Py_INCREF(__pyx_v_key); __pyx_v_result = Py_None; Py_INCREF(Py_None); - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":11 */ - __pyx_v_delta = 2654435769; + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":24 */ + (__pyx_v_v[0]) = __pyx_v_v0; - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":12 */ - __pyx_v_sum = 0; + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":24 */ + (__pyx_v_v[1]) = __pyx_v_v1; - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":13 */ - __pyx_1 = PyList_New(0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 13; goto __pyx_L1;} - Py_DECREF(__pyx_v_result); - __pyx_v_result = __pyx_1; - __pyx_1 = 0; + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":25 */ + __pyx_1 = PyInt_FromLong(0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_key, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + __pyx_3 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + (__pyx_v_k[0]) = __pyx_3; - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":15 */ - for (__pyx_v_i = 0; __pyx_v_i < __pyx_v_rounds; ++__pyx_v_i) { + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":25 */ + __pyx_1 = PyInt_FromLong(1); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_key, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + __pyx_3 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + (__pyx_v_k[1]) = __pyx_3; - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":16 */ - __pyx_1 = PyLong_FromUnsignedLong(__pyx_v_v0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; goto __pyx_L1;} - __pyx_2 = PyLong_FromUnsignedLong((((__pyx_v_v1 << 4) ^ (__pyx_v_v1 >> 5)) + __pyx_v_v1)); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; goto __pyx_L1;} - __pyx_3 = PyLong_FromUnsignedLong(__pyx_v_sum); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; goto __pyx_L1;} - __pyx_4 = PyLong_FromUnsignedLong((__pyx_v_sum & 3)); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; goto __pyx_L1;} - __pyx_5 = PyObject_GetItem(__pyx_v_key, __pyx_4); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; goto __pyx_L1;} - Py_DECREF(__pyx_4); __pyx_4 = 0; - __pyx_4 = PyNumber_Add(__pyx_3, __pyx_5); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; goto __pyx_L1;} - Py_DECREF(__pyx_3); __pyx_3 = 0; - Py_DECREF(__pyx_5); __pyx_5 = 0; - __pyx_3 = PyNumber_Xor(__pyx_2, __pyx_4); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; goto __pyx_L1;} - Py_DECREF(__pyx_2); __pyx_2 = 0; - Py_DECREF(__pyx_4); __pyx_4 = 0; - __pyx_5 = PyNumber_Add(__pyx_1, __pyx_3); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; goto __pyx_L1;} - Py_DECREF(__pyx_1); __pyx_1 = 0; - Py_DECREF(__pyx_3); __pyx_3 = 0; - __pyx_6 = PyInt_AsUnsignedLongMask(__pyx_5); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; goto __pyx_L1;} - Py_DECREF(__pyx_5); __pyx_5 = 0; - __pyx_v_v0 = __pyx_6; + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":25 */ + __pyx_1 = PyInt_FromLong(2); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_key, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + __pyx_3 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + (__pyx_v_k[2]) = __pyx_3; - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":17 */ - __pyx_v_sum = (__pyx_v_sum + __pyx_v_delta); + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":25 */ + __pyx_1 = PyInt_FromLong(3); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_key, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + __pyx_3 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 25; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + (__pyx_v_k[3]) = __pyx_3; - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":18 */ - __pyx_2 = PyLong_FromUnsignedLong(__pyx_v_v1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 18; goto __pyx_L1;} - __pyx_4 = PyLong_FromUnsignedLong((((__pyx_v_v0 << 4) ^ (__pyx_v_v0 >> 5)) + __pyx_v_v0)); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 18; goto __pyx_L1;} - __pyx_1 = PyLong_FromUnsignedLong(__pyx_v_sum); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 18; goto __pyx_L1;} - __pyx_3 = PyLong_FromUnsignedLong(((__pyx_v_sum >> 11) & 3)); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 18; goto __pyx_L1;} - __pyx_5 = PyObject_GetItem(__pyx_v_key, __pyx_3); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 18; goto __pyx_L1;} - Py_DECREF(__pyx_3); __pyx_3 = 0; - __pyx_3 = PyNumber_Add(__pyx_1, __pyx_5); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 18; goto __pyx_L1;} - Py_DECREF(__pyx_1); __pyx_1 = 0; - Py_DECREF(__pyx_5); __pyx_5 = 0; - __pyx_1 = PyNumber_Xor(__pyx_4, __pyx_3); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 18; goto __pyx_L1;} - Py_DECREF(__pyx_4); __pyx_4 = 0; - Py_DECREF(__pyx_3); __pyx_3 = 0; - __pyx_5 = PyNumber_Add(__pyx_2, __pyx_1); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 18; goto __pyx_L1;} - Py_DECREF(__pyx_2); __pyx_2 = 0; - Py_DECREF(__pyx_1); __pyx_1 = 0; - __pyx_6 = PyInt_AsUnsignedLongMask(__pyx_5); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 18; goto __pyx_L1;} - Py_DECREF(__pyx_5); __pyx_5 = 0; - __pyx_v_v1 = __pyx_6; - __pyx_L2:; - } - __pyx_L3:; + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":26 */ + encipher(__pyx_v_v,__pyx_v_k,__pyx_v_rounds); - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":20 */ - __pyx_4 = PyLong_FromUnsignedLong(__pyx_v_v0); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 20; goto __pyx_L1;} - __pyx_3 = PyLong_FromUnsignedLong(__pyx_v_v1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 20; goto __pyx_L1;} - __pyx_2 = PyList_New(2); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 20; goto __pyx_L1;} - PyList_SET_ITEM(__pyx_2, 0, __pyx_4); - PyList_SET_ITEM(__pyx_2, 1, __pyx_3); - __pyx_4 = 0; - __pyx_3 = 0; - Py_DECREF(__pyx_v_result); - __pyx_v_result = __pyx_2; + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":27 */ + __pyx_1 = PyLong_FromUnsignedLong((__pyx_v_v[0])); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 27; goto __pyx_L1;} + __pyx_2 = PyLong_FromUnsignedLong((__pyx_v_v[1])); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 27; goto __pyx_L1;} + __pyx_4 = PyList_New(2); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 27; goto __pyx_L1;} + PyList_SET_ITEM(__pyx_4, 0, __pyx_1); + PyList_SET_ITEM(__pyx_4, 1, __pyx_2); + __pyx_1 = 0; __pyx_2 = 0; + Py_DECREF(__pyx_v_result); + __pyx_v_result = __pyx_4; + __pyx_4 = 0; - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":21 */ + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":28 */ Py_INCREF(__pyx_v_result); __pyx_r = __pyx_v_result; goto __pyx_L0; @@ -155,9 +138,7 @@ __pyx_L1:; Py_XDECREF(__pyx_1); Py_XDECREF(__pyx_2); - Py_XDECREF(__pyx_3); Py_XDECREF(__pyx_4); - Py_XDECREF(__pyx_5); __Pyx_AddTraceback("_xtea._c_xtea_encryptQuad"); __pyx_r = 0; __pyx_L0:; @@ -171,95 +152,72 @@ unsigned long __pyx_v_v0; unsigned long __pyx_v_v1; PyObject *__pyx_v_key = 0; - int __pyx_v_rounds; - int __pyx_v_i; - unsigned long __pyx_v_delta; - unsigned long __pyx_v_sum; + unsigned int __pyx_v_rounds; + unsigned long (__pyx_v_v[2]); + unsigned long (__pyx_v_k[4]); PyObject *__pyx_v_result; PyObject *__pyx_r; PyObject *__pyx_1 = 0; PyObject *__pyx_2 = 0; - PyObject *__pyx_3 = 0; + unsigned long __pyx_3; PyObject *__pyx_4 = 0; - PyObject *__pyx_5 = 0; - unsigned long __pyx_6; static char *__pyx_argnames[] = {"v0","v1","key","rounds",0}; - if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "kkOi", __pyx_argnames, &__pyx_v_v0, &__pyx_v_v1, &__pyx_v_key, &__pyx_v_rounds)) return 0; + if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "kkOI", __pyx_argnames, &__pyx_v_v0, &__pyx_v_v1, &__pyx_v_key, &__pyx_v_rounds)) return 0; Py_INCREF(__pyx_v_key); __pyx_v_result = Py_None; Py_INCREF(Py_None); - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":27 */ - __pyx_v_delta = 2654435769; + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":33 */ + (__pyx_v_v[0]) = __pyx_v_v0; - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":28 */ - __pyx_v_sum = (__pyx_v_delta * __pyx_v_rounds); + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":33 */ + (__pyx_v_v[1]) = __pyx_v_v1; - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":29 */ - __pyx_1 = PyList_New(0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 29; goto __pyx_L1;} - Py_DECREF(__pyx_v_result); - __pyx_v_result = __pyx_1; - __pyx_1 = 0; + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":34 */ + __pyx_1 = PyInt_FromLong(0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_key, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + __pyx_3 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + (__pyx_v_k[0]) = __pyx_3; - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":31 */ - for (__pyx_v_i = 0; __pyx_v_i < __pyx_v_rounds; ++__pyx_v_i) { + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":34 */ + __pyx_1 = PyInt_FromLong(1); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_key, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + __pyx_3 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + (__pyx_v_k[1]) = __pyx_3; - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":32 */ - __pyx_1 = PyLong_FromUnsignedLong(__pyx_v_v1); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; goto __pyx_L1;} - __pyx_2 = PyLong_FromUnsignedLong((((__pyx_v_v0 << 4) ^ (__pyx_v_v0 >> 5)) + __pyx_v_v0)); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; goto __pyx_L1;} - __pyx_3 = PyLong_FromUnsignedLong(__pyx_v_sum); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; goto __pyx_L1;} - __pyx_4 = PyLong_FromUnsignedLong(((__pyx_v_sum >> 11) & 3)); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; goto __pyx_L1;} - __pyx_5 = PyObject_GetItem(__pyx_v_key, __pyx_4); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; goto __pyx_L1;} - Py_DECREF(__pyx_4); __pyx_4 = 0; - __pyx_4 = PyNumber_Add(__pyx_3, __pyx_5); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; goto __pyx_L1;} - Py_DECREF(__pyx_3); __pyx_3 = 0; - Py_DECREF(__pyx_5); __pyx_5 = 0; - __pyx_3 = PyNumber_Xor(__pyx_2, __pyx_4); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; goto __pyx_L1;} - Py_DECREF(__pyx_2); __pyx_2 = 0; - Py_DECREF(__pyx_4); __pyx_4 = 0; - __pyx_5 = PyNumber_Subtract(__pyx_1, __pyx_3); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; goto __pyx_L1;} - Py_DECREF(__pyx_1); __pyx_1 = 0; - Py_DECREF(__pyx_3); __pyx_3 = 0; - __pyx_6 = PyInt_AsUnsignedLongMask(__pyx_5); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; goto __pyx_L1;} - Py_DECREF(__pyx_5); __pyx_5 = 0; - __pyx_v_v1 = __pyx_6; + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":34 */ + __pyx_1 = PyInt_FromLong(2); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_key, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + __pyx_3 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + (__pyx_v_k[2]) = __pyx_3; - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":33 */ - __pyx_v_sum = (__pyx_v_sum - __pyx_v_delta); + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":34 */ + __pyx_1 = PyInt_FromLong(3); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; goto __pyx_L1;} + __pyx_2 = PyObject_GetItem(__pyx_v_key, __pyx_1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + __pyx_3 = PyInt_AsUnsignedLongMask(__pyx_2); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + (__pyx_v_k[3]) = __pyx_3; - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":34 */ - __pyx_2 = PyLong_FromUnsignedLong(__pyx_v_v0); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; goto __pyx_L1;} - __pyx_4 = PyLong_FromUnsignedLong((((__pyx_v_v1 << 4) ^ (__pyx_v_v1 >> 5)) + __pyx_v_v1)); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; goto __pyx_L1;} - __pyx_1 = PyLong_FromUnsignedLong(__pyx_v_sum); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; goto __pyx_L1;} - __pyx_3 = PyLong_FromUnsignedLong((__pyx_v_sum & 3)); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; goto __pyx_L1;} - __pyx_5 = PyObject_GetItem(__pyx_v_key, __pyx_3); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; goto __pyx_L1;} - Py_DECREF(__pyx_3); __pyx_3 = 0; - __pyx_3 = PyNumber_Add(__pyx_1, __pyx_5); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; goto __pyx_L1;} - Py_DECREF(__pyx_1); __pyx_1 = 0; - Py_DECREF(__pyx_5); __pyx_5 = 0; - __pyx_1 = PyNumber_Xor(__pyx_4, __pyx_3); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; goto __pyx_L1;} - Py_DECREF(__pyx_4); __pyx_4 = 0; - Py_DECREF(__pyx_3); __pyx_3 = 0; - __pyx_5 = PyNumber_Subtract(__pyx_2, __pyx_1); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; goto __pyx_L1;} - Py_DECREF(__pyx_2); __pyx_2 = 0; - Py_DECREF(__pyx_1); __pyx_1 = 0; - __pyx_6 = PyInt_AsUnsignedLongMask(__pyx_5); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; goto __pyx_L1;} - Py_DECREF(__pyx_5); __pyx_5 = 0; - __pyx_v_v0 = __pyx_6; - __pyx_L2:; - } - __pyx_L3:; + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":35 */ + decipher(__pyx_v_v,__pyx_v_k,__pyx_v_rounds); /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":36 */ - __pyx_4 = PyLong_FromUnsignedLong(__pyx_v_v0); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; goto __pyx_L1;} - __pyx_3 = PyLong_FromUnsignedLong(__pyx_v_v1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; goto __pyx_L1;} - __pyx_2 = PyList_New(2); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; goto __pyx_L1;} - PyList_SET_ITEM(__pyx_2, 0, __pyx_4); - PyList_SET_ITEM(__pyx_2, 1, __pyx_3); - __pyx_4 = 0; - __pyx_3 = 0; - Py_DECREF(__pyx_v_result); - __pyx_v_result = __pyx_2; + __pyx_1 = PyLong_FromUnsignedLong((__pyx_v_v[0])); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; goto __pyx_L1;} + __pyx_2 = PyLong_FromUnsignedLong((__pyx_v_v[1])); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; goto __pyx_L1;} + __pyx_4 = PyList_New(2); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; goto __pyx_L1;} + PyList_SET_ITEM(__pyx_4, 0, __pyx_1); + PyList_SET_ITEM(__pyx_4, 1, __pyx_2); + __pyx_1 = 0; __pyx_2 = 0; + Py_DECREF(__pyx_v_result); + __pyx_v_result = __pyx_4; + __pyx_4 = 0; /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":37 */ Py_INCREF(__pyx_v_result); @@ -271,9 +229,7 @@ __pyx_L1:; Py_XDECREF(__pyx_1); Py_XDECREF(__pyx_2); - Py_XDECREF(__pyx_3); Py_XDECREF(__pyx_4); - Py_XDECREF(__pyx_5); __Pyx_AddTraceback("_xtea._c_xtea_decryptQuad"); __pyx_r = 0; __pyx_L0:; @@ -283,6 +239,11 @@ } static __Pyx_InternTabEntry __pyx_intern_tab[] = { + {&__pyx_n_MODE_CBC, "MODE_CBC"}, + {&__pyx_n_MODE_CFB, "MODE_CFB"}, + {&__pyx_n_MODE_CTR, "MODE_CTR"}, + {&__pyx_n_MODE_ECB, "MODE_ECB"}, + {&__pyx_n_MODE_OFB, "MODE_OFB"}, {&__pyx_n__c_xtea_decryptQuad, "_c_xtea_decryptQuad"}, {&__pyx_n__c_xtea_encryptQuad, "_c_xtea_encryptQuad"}, {0, 0} @@ -298,17 +259,44 @@ PyMODINIT_FUNC init_xtea(void); /*proto*/ PyMODINIT_FUNC init_xtea(void) { + PyObject *__pyx_1 = 0; __pyx_init_filenames(); __pyx_m = Py_InitModule4("_xtea", __pyx_methods, 0, 0, PYTHON_API_VERSION); - if (!__pyx_m) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 5; goto __pyx_L1;}; + if (!__pyx_m) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 8; goto __pyx_L1;}; __pyx_b = PyImport_AddModule("__builtin__"); - if (!__pyx_b) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 5; goto __pyx_L1;}; - if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 5; goto __pyx_L1;}; - if (__Pyx_InternStrings(__pyx_intern_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 5; goto __pyx_L1;}; + if (!__pyx_b) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 8; goto __pyx_L1;}; + if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 8; goto __pyx_L1;}; + if (__Pyx_InternStrings(__pyx_intern_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 8; goto __pyx_L1;}; - /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":23 */ + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":15 */ + __pyx_1 = PyInt_FromLong(1); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 15; goto __pyx_L1;} + if (PyObject_SetAttr(__pyx_m, __pyx_n_MODE_ECB, __pyx_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 15; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":16 */ + __pyx_1 = PyInt_FromLong(2); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; goto __pyx_L1;} + if (PyObject_SetAttr(__pyx_m, __pyx_n_MODE_CBC, __pyx_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":17 */ + __pyx_1 = PyInt_FromLong(4); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 17; goto __pyx_L1;} + if (PyObject_SetAttr(__pyx_m, __pyx_n_MODE_CFB, __pyx_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 17; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":18 */ + __pyx_1 = PyInt_FromLong(5); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 18; goto __pyx_L1;} + if (PyObject_SetAttr(__pyx_m, __pyx_n_MODE_OFB, __pyx_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 18; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":19 */ + __pyx_1 = PyInt_FromLong(6); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 19; goto __pyx_L1;} + if (PyObject_SetAttr(__pyx_m, __pyx_n_MODE_CTR, __pyx_1) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 19; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":30 */ return; __pyx_L1:; + Py_XDECREF(__pyx_1); __Pyx_AddTraceback("_xtea"); } Modified: xtea/trunk/src/xtea/_xtea.pyx =================================================================== --- xtea/trunk/src/xtea/_xtea.pyx 2007-02-28 12:13:59 UTC (rev 218) +++ xtea/trunk/src/xtea/_xtea.pyx 2007-03-01 16:25:39 UTC (rev 219) @@ -2,36 +2,36 @@ # pyrexc optimized version # License: Public Domain +# http://www.python.org/dev/peps/pep-0272/ +# http://en.wikipedia.org/wiki/XTEA + ctypedef unsigned long ULong +ctypedef unsigned int UInt -def _c_xtea_encryptQuad(ULong v0, ULong v1, key, int rounds): - cdef int i - cdef ULong delta, sum +cdef extern from "cxtea.h": + void decipher(ULong *v, ULong *k, UInt rounds) + void encipher(ULong *v, ULong *k, UInt rounds) - delta=0x9E3779B9 - sum=0 - result = [] +MODE_ECB = 1 # Electronic Code Book +MODE_CBC = 2 # Cipher Block Chaining +MODE_CFB = 4 # Cipher Feedback +MODE_OFB = 5 # Output Feedback +MODE_CTR = 6 # Counter - for i from 0 <= i < rounds: - v0 = v0 + (((v1<<4 ^ v1>>5) + v1) ^ (sum + key[sum & 3])) - sum = sum + delta - v1 = v1 + (((v0<<4 ^ v0>>5) + v0) ^ (sum + key[sum>>11 & 3])) - - result = [v0, v1] +def _c_xtea_encryptQuad(ULong v0, ULong v1, object key, UInt rounds): + cdef ULong v[2] + cdef ULong k[4] + v[0] = v0; v[1] = v1 + k[0] = key[0]; k[1] = key[1]; k[2] = key[2]; k[3] = key[3]; + encipher(v, k, rounds) + result = [v[0], v[1]] return result -def _c_xtea_decryptQuad(ULong v0, ULong v1, key, int rounds): - cdef int i - cdef ULong delta, sum - - delta=0x9E3779B9 - sum=delta*rounds - result = [] - - for i from 0 <= i < rounds: - v1 = v1 - (((v0<<4 ^ v0>>5) + v0) ^ (sum + key[sum>>11 & 3])) - sum = sum - delta - v0 = v0 - (((v1<<4 ^ v1>>5) + v1) ^ (sum + key[sum & 3])) - - result = [v0, v1] +def _c_xtea_decryptQuad(ULong v0, ULong v1, key, UInt rounds): + cdef ULong v[2] + cdef ULong k[4] + v[0] = v0; v[1] = v1 + k[0] = key[0]; k[1] = key[1]; k[2] = key[2]; k[3] = key[3]; + decipher(v, k, rounds) + result = [v[0], v[1]] return result Added: xtea/trunk/src/xtea/cxtea.c =================================================================== --- xtea/trunk/src/xtea/cxtea.c (rev 0) +++ xtea/trunk/src/xtea/cxtea.c 2007-03-01 16:25:39 UTC (rev 219) @@ -0,0 +1,32 @@ +/* Copyright (C) 2007 Christian Heimes <christian (at) cheimes (dot) de> + pyrexc optimized version + License: Public Domain + + Source: http://en.wikipedia.org/wiki/XTEA +*/ + +#include "cxtea.h" + +void decipher(ULong *const v, const ULong *const k, const UInt rounds) + { + register UInt i; + register ULong delta=0x9E3779B9; + register ULong sum=delta*rounds; + for (i=0; i < rounds; i++) { + v[1] -= ((v[0]<<4 ^ v[0]>>5) + v[0]) ^ (sum + k[sum>>11 & 3]); + sum -= delta; + v[0] -= ((v[1]<<4 ^ v[1]>>5) + v[1]) ^ (sum + k[sum & 3]); + } + } + +void encipher(ULong *const v, const ULong *const k, const UInt rounds) + { + register UInt i; + register ULong delta=0x9E3779B9; + register ULong sum=0; + for (i=0; i < rounds; i++) { + v[0] += ((v[1]<<4 ^ v[1]>>5) + v[1]) ^ (sum + k[sum & 3]); + sum += delta; + v[1] += ((v[0]<<4 ^ v[0]>>5) + v[0]) ^ (sum + k[sum>>11 & 3]); + } + } Property changes on: xtea/trunk/src/xtea/cxtea.c ___________________________________________________________________ Name: svn:eol-style + native Added: xtea/trunk/src/xtea/cxtea.h =================================================================== --- xtea/trunk/src/xtea/cxtea.h (rev 0) +++ xtea/trunk/src/xtea/cxtea.h 2007-03-01 16:25:39 UTC (rev 219) @@ -0,0 +1,19 @@ +/* Copyright (C) 2007 Christian Heimes <christian (at) cheimes (dot) de> + pyrexc optimized version + License: Public Domain + + Source: http://en.wikipedia.org/wiki/XTEA +*/ + +#define MODE_ECB 1 // Electronic Code Book +#define MODE_CBC 2 // Cipher Block Chaining +#define MODE_CFB 4 // Cipher Feedback +#define MODE_OFB 5 // Output Feedback +#define MODE_CTR 6 // Counter + +typedef unsigned long ULong; +typedef unsigned int UInt; + +void decipher(ULong *const v, const ULong *const k, const UInt rounds); +void encipher(ULong *const v, const ULong *const k, const UInt rounds); + Property changes on: xtea/trunk/src/xtea/cxtea.h ___________________________________________________________________ Name: svn:eol-style + native Modified: xtea/trunk/src/xtea/xtea.py =================================================================== --- xtea/trunk/src/xtea/xtea.py 2007-02-28 12:13:59 UTC (rev 218) +++ xtea/trunk/src/xtea/xtea.py 2007-03-01 16:25:39 UTC (rev 219) @@ -1,7 +1,7 @@ -""" -XTEA Block Encryption Algorithm +"""XTEA Block Encryption Algorithm Author: Paul Chakravarti (paul_dot_chakravarti_at_mac_dot_com) + Christian Heimes (christian (at) cheimes (dot) de) License: Public Domain This module provides a Python implementation of the XTEA block encryption @@ -27,68 +27,189 @@ IV to seed the key generator (the IV is not sensitive and does not need to be exchanged securely) +""" + +from struct import pack +from struct import unpack +import sys + +__all__ = ['new', 'MODE_ECB', 'MODE_OFB', 'BIG_ENDIAN', + 'LITTLE_ENDIAN', 'NETWORK_ENDIAN'] + +MODE_ECB = 1 # Electronic Code Book +MODE_CBC = 2 # Cipher Block Chaining +MODE_CFB = 4 # Cipher Feedback +MODE_OFB = 5 # Output Feedback +MODE_CTR = 6 # Counter +BIG_ENDIAN = 'big' +LITTLE_ENDIAN = 'little' +NETWORK_ENDIAN = LITTLE_ENDIAN +HOST_ENDIAN = sys.byteorder + +class XTEA(object): + """XTEA block cipher (PEP 272 conform implementation) + + Key: 16 chars or tuple with 4 longs (128 bit) + blocksize: 8 (64 bit) + rounds: 32 (default) + endian: little or big endian (default: host endian) + IV: initialization vector for OFB (8 chars) + mode: ECB, OFB + + ECB mode encryption and decryption + >>> xtea = new('0123456789012345', mode=MODE_ECB, endian=LITTLE_ENDIAN) + >>> z = xtea.encrypt('ABCDEFGH') + >>> z.encode('hex') + 'ea0c3d7c1c22557f' + >>> xtea.decrypt(z) + 'ABCDEFGH' + + The block must be 8 characters or a multitude of 8 long + >>> z = xtea.encrypt('ABCDEFGHABCDEFGH') + >>> z.encode('hex') + 'ea0c3d7c1c22557fea0c3d7c1c22557f' + >>> xtea.decrypt(z) + 'ABCDEFGHABCDEFGH' + + You can specify the endianes of the key and data. The default value is host endian. + >>> xtea = new('0123456789012345', mode=MODE_ECB, endian=BIG_ENDIAN) + >>> z = xtea.encrypt('ABCDEFGH') + >>> z.encode('hex') + 'b67c01662ff6964a' + >>> xtea.decrypt(z) + 'ABCDEFGH' + + In OFB mode the data block can have any size. >>> import os + >>> key = os.urandom(16) + >>> iv = os.urandom(8) + >>> data = os.urandom(10000) + >>> xtea = XTEA(key, mode=MODE_OFB, IV=iv, endian=LITTLE_ENDIAN) + >>> z = xtea.encrypt(data) + >>> xtea.decrypt(z) == data + True + + >>> key = '0123456789012345' >>> iv = 'ABCDEFGH' - >>> z = crypt('0123456789012345','Hello There',iv) + >>> xtea = XTEA(key, mode=MODE_OFB, IV=iv, endian=BIG_ENDIAN) + >>> z = xtea.encrypt('Hello There!') >>> z.encode('hex') - 'fe196d0a40d6c222b9eff3' - >>> crypt('0123456789012345',z,iv) - 'Hello There' + 'fe196d0a40d6c222b9eff3e9' + >>> xtea.decrypt(z) + 'Hello There!' + """ + @property + def key_size(self): + return 16 -""" + @property + def block_size(self): + return 8 -import struct + def __init__(self, key, mode=MODE_ECB, IV=None, rounds=32, + endian=HOST_ENDIAN, **kwargs): + if endian == BIG_ENDIAN: + self._endian = ">" + elif endian == LITTLE_ENDIAN: + self._endian = "<" + else: + raise ValueError("Unknown endian: %s" % endian) -def crypt(key, data, iv='\00\00\00\00\00\00\00\00', n=32): - """ - Encrypt/decrypt variable length string using XTEA cypher as - key generator (OFB mode) - * key = 128 bit (16 char) - * iv = 64 bit (8 char) - * data = string (any length) + if isinstance(key, tuple): + if len(key) != 4: + raise ValueError("Invalid key size") + self._key = key + elif isinstance(key, str): + if len(key) != self.key_size: + raise ValueError("Invalid key size") + self._key = unpack(self._endian+"4L", key) + else: + raise TypeError("Invalid key type") - >>> import os - >>> key = os.urandom(16) - >>> iv = os.urandom(8) - >>> data = os.urandom(10000) - >>> z = crypt(key,data,iv) - >>> crypt(key,z,iv) == data - True + if mode == MODE_ECB: + if IV is not None: + raise ValueError("IV not required for ECB") + elif mode == MODE_OFB: + if IV is None or len(IV) != self.block_size: + raise ValueError("Invalid IV") + else: + raise ValueError("Unknown or unsupported mode") - """ - def keygen(key, iv, n): + self._mode = mode + self._rounds = rounds + self._iv = IV + + def encrypt(self, block): + """Encrypt a block + + @param block: block to encrypt + @type block: str + """ + if self._mode == MODE_ECB: + return self._ecb(block, func=xtea_encryptQuad) + elif self._mode == MODE_OFB: + return self._ofb(block) + else: + raise ValueError("Unknown or unsupported mode") + + def decrypt(self, block): + """Decrypt a block + + @param block: block to decrypt + @type block: str + """ + if self._mode == MODE_ECB: + return self._ecb(block, func=xtea_decryptQuad) + elif self._mode == MODE_OFB: + return self._ofb(block) + else: + raise ValueError("Unknown or unsupported mode") + + def _ecb(self, block, func): + """Electronic Code Book encryption/decryption + + @type block: str + @param func: decrypt or encrypt function + @type func: callable(v0, v1, keys[4], rounds) + """ + l = len(block) + bs = self.block_size + key, rounds = self._key, self._rounds + fmt = self._endian+"2L" + result = [] + if l % bs != 0: + raise ValueError + for i in range(l/bs): + v0, v1 = unpack(fmt, block[i*bs:(i+1)*bs]) + w0, w1 = func(v0, v1, key, rounds) + result.append(pack(fmt, w0, w1)) + return ''.join(result) + + def _ofb_keygen(self): + """Key generator + + @return: generator function + """ + key, iv, rounds = self._key, self._iv, self._rounds + fmt = self._endian+"2L" + #v0, v1 = unpack(self._endian+"2L", iv) while True: - iv = xtea_encrypt(key, iv, n) + v0, v1 = unpack(fmt, iv) + w0, w1 = xtea_encryptQuad(v0, v1, key, rounds) + iv = pack(fmt, w0, w1) for k in iv: yield ord(k) - xor = [ chr(x^y) for (x, y) in zip(map(ord, data), keygen(key, iv, n)) ] - return "".join(xor) -def xtea_encrypt(key, block, rounds=32, endian="!"): - """ - Encrypt 64 bit data block using XTEA block cypher - * key = 128 bit (16 char) - * block = 64 bit (8 char) - * n = rounds (default 32) - * endian = byte order (see 'struct' doc - default big/network) + def _ofb(self, block): + """Output Feedback (OFB) encryption requires an IV + """ + key = pack(self._endian+"4L", *self._key) + gen = self._ofb_keygen() + xor = [chr(x^y) for (x, y) in zip(map(ord, block), gen)] + return ''.join(xor) - >>> z = xtea_encrypt('0123456789012345','ABCDEFGH') - >>> z.encode('hex') - 'b67c01662ff6964a' +new = XTEA - Only need to change byte order if sending/receiving from - alternative endian implementation - - >>> z = xtea_encrypt('0123456789012345','ABCDEFGH',endian="<") - >>> z.encode('hex') - 'ea0c3d7c1c22557f' - - """ - v0,v1 = struct.unpack(endian+"2L", block) - k = struct.unpack(endian+"4L", key) - v0, v1 = xtea_encryptQuad(v0, v1, k, rounds) - return struct.pack(endian+"2L", v0, v1) - def _py_xtea_encryptQuad(v0, v1, key, rounds=32, delta=0x9e3779b9L, mask=0xffffffffL): """Encrypt a quad @@ -111,31 +232,6 @@ v1 = (v1 + (((v0<<4 ^ v0>>5) + v0) ^ (sum + key[sum>>11 & 3]))) & mask return v0, v1 -def xtea_decrypt(key, block, rounds=32, endian="!"): - """ - Decrypt 64 bit data block using XTEA block cypher - * key = 128 bit (16 char) - * block = 64 bit (8 char) - * n = rounds (default 32) - * endian = byte order (see 'struct' doc - default big/network) - - >>> z = 'b67c01662ff6964a'.decode('hex') - >>> xtea_decrypt('0123456789012345',z) - 'ABCDEFGH' - - Only need to change byte order if sending/receiving from - alternative endian implementation - - >>> z = 'ea0c3d7c1c22557f'.decode('hex') - >>> xtea_decrypt('0123456789012345',z,endian="<") - 'ABCDEFGH' - - """ - v0, v1 = struct.unpack(endian+"2L", block) - k = struct.unpack(endian+"4L", key) - v0, v1 = xtea_decryptQuad(v0, v1, k, rounds) - return struct.pack(endian+"2L", v0, v1) - def _py_xtea_decryptQuad(v0, v1, key, rounds=32, delta=0x9e3779b9L, mask=0xffffffffL): """Decrypt a quad @@ -160,11 +256,9 @@ # Try to replace core functions with optimized versions try: - #raise ImportError from _xtea import _c_xtea_encryptQuad from _xtea import _c_xtea_decryptQuad except ImportError, msg: - print msg xtea_encryptQuad = _py_xtea_encryptQuad xtea_decryptQuad = _py_xtea_decryptQuad else: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ti...@us...> - 2007-02-28 12:14:00
|
Revision: 218 http://pymoul.svn.sourceforge.net/pymoul/?rev=218&view=rev Author: tiran Date: 2007-02-28 04:13:59 -0800 (Wed, 28 Feb 2007) Log Message: ----------- Moved code to external packages included with svn:externals Modified Paths: -------------- pymoul/trunk/INSTALL.txt pymoul/trunk/src/moul/__init__.py pymoul/trunk/src/moul/crypt/binary.py pymoul/trunk/src/moul/crypt/tests/test_wdys.py pymoul/trunk/src/moul/crypt/whatdoyousee.py Added Paths: ----------- pymoul/trunk/src/EXTERNALS.txt Removed Paths: ------------- pymoul/trunk/src/moul/crypt/binaryrecord.py pymoul/trunk/src/moul/crypt/tests/test_binary.py pymoul/trunk/src/moul/crypt/tests/test_binaryrecord.py pymoul/trunk/src/moul/crypt/xtea.py pymoul/trunk/src/moul/osdependent/tests/test_processinfo.py Property Changed: ---------------- pymoul/trunk/src/ Modified: pymoul/trunk/INSTALL.txt =================================================================== --- pymoul/trunk/INSTALL.txt 2007-02-28 12:10:44 UTC (rev 217) +++ pymoul/trunk/INSTALL.txt 2007-02-28 12:13:59 UTC (rev 218) @@ -6,10 +6,14 @@ * easy_install http://peak.telecommunity.com/DevCenter/EasyInstall * setuptools (via easy_install) * pytz (via $ easy_install-2.5 -Z pytz) - * enumprocess (via $ easy_install-2.5 -Z enumprocess) * Qt4 GPL 4.2+ http://www.trolltech.com/developer/downloads/qt/ * PyQt4 4.1.1+ http://www.riverbankcomputing.co.uk/pyqt/ + These external modules were created for pyMoul and are bundled with the tool. + * binaryfile + * enumprocess + * xtea + Windows ------- Property changes on: pymoul/trunk/src ___________________________________________________________________ Name: svn:externals + xtea https://pymoul.svn.sourceforge.net/svnroot/pymoul/xtea/trunk/src/xtea enumprocess https://pymoul.svn.sourceforge.net/svnroot/pymoul/enumprocess/trunk/src/enumprocess binaryfile https://pymoul.svn.sourceforge.net/svnroot/pymoul/binaryfile/trunk/src/binaryfile Added: pymoul/trunk/src/EXTERNALS.txt =================================================================== --- pymoul/trunk/src/EXTERNALS.txt (rev 0) +++ pymoul/trunk/src/EXTERNALS.txt 2007-02-28 12:13:59 UTC (rev 218) @@ -0,0 +1,3 @@ +xtea https://pymoul.svn.sourceforge.net/svnroot/pymoul/xtea/trunk/src/xtea +enumprocess https://pymoul.svn.sourceforge.net/svnroot/pymoul/enumprocess/trunk/src/enumprocess +binaryfile https://pymoul.svn.sourceforge.net/svnroot/pymoul/binaryfile/trunk/src/binaryfile Property changes on: pymoul/trunk/src/EXTERNALS.txt ___________________________________________________________________ Name: svn:keywords + 'Id Revision' Name: svn:eol-style + native Modified: pymoul/trunk/src/moul/__init__.py =================================================================== --- pymoul/trunk/src/moul/__init__.py 2007-02-28 12:10:44 UTC (rev 217) +++ pymoul/trunk/src/moul/__init__.py 2007-02-28 12:13:59 UTC (rev 218) @@ -12,3 +12,4 @@ except ImportError: for p in __path__: modulefinder.AddPackagePath(__name__, p) + Modified: pymoul/trunk/src/moul/crypt/binary.py =================================================================== --- pymoul/trunk/src/moul/crypt/binary.py 2007-02-28 12:10:44 UTC (rev 217) +++ pymoul/trunk/src/moul/crypt/binary.py 2007-02-28 12:13:59 UTC (rev 218) @@ -21,241 +21,30 @@ __version__ = "$Id" __revision__ = "$Revision" +from binaryfile import BinaryFile as BaseBinaryFile +from binaryfile.binary import AbstractString from struct import calcsize from struct import pack from struct import unpack -from moul.crypt.binaryrecord import parseRecord -from moul.crypt.binaryrecord import registerRecord -class BinaryFile(file): - """Binary file - - A file based class with additional methods to read and write binary data. - - The class supports reading and writing: - - char: readChar / writeChar - - byte: readByte / writeByte - - bool: readBool / writeBool - - signed int8: read8 / write8 - - unsigned int8: read8s / write8s - - unsigned int 16: read16 / write16 - - signed int 16: read16s / write16s - - unsigned int 32: read32 / write32 - - signed int 32: read32s / write32s - - unsigned int 64: read64 / write64 - - signed int 64: read64s / write64s - - float: readFloat / writeFloat - - double: readDouble / writeDouble - - packed data: readPacked(fmt) / writePacked(fmt, data) - - quad (two int16): readQuad / writeQuad) - - NULL: read0 / write0 - - null string: readString0 / writeString0 (size is string + NULL) - - uru string: readUruString(version), writeUruString - - string w/ 16bit size header: readString16(null terminated) / writeString16 - - string w/ 32bit size header: readString32(null terminated) / writeString32 +class BinaryFile(BaseBinaryFile): + """Binary file with suport for Uru String - For conveniance the class has a size() method - - The class is using some optimization tricks like binding functions to the - local namespace of a method. + - uru string: readUruString(version), writeUruString """ - def __new__(cls, fname, mode='rb'): - assert 'b' in mode - self = file.__new__(cls, fname, mode) - self.NULL = '\x00' - return self - - def size(self): - pos = self.tell() - try: - self.seek(0, 2) - return self.tell() - finally: - self.seek(pos) - - def readChar(self, _unpack=unpack): - return _unpack('<c', self.read(1))[0] - - def readByte(self, _unpack=unpack): - return _unpack('<B',self.read(1))[0] - - def readBool(self, _unpack=unpack): - return bool(_unpack('<B', self.read(1))[0]) - - def read8(self, _unpack=unpack): - return _unpack('<B', self.read(1))[0] - - def read8s(self, _unpack=unpack): - return _unpack('<b', self.read(1))[0] - - def read16(self, _unpack=unpack): - return _unpack('<H', self.read(2))[0] - - def read16s(self, _unpack=unpack): - return _unpack('<h', self.read(2))[0] - - def read32(self, _unpack=unpack): - return _unpack('<I', self.read(4))[0] - - def read32s(self, _unpack=unpack): - return _unpack('<i', self.read(4))[0] - - def read64(self, _unpack=unpack): - return _unpack('<Q', self.read(8))[0] - - def read64s(self, _unpack=unpack): - return _unpack('<q',self.read(8))[0] - - def readQuad(self, _unpack=unpack): - return _unpack('<2I', self.read(8)) - - def readFloat(self, _unpack=unpack): - return _unpack('<f', self.read(4))[0] - - def readDouble(self, _unpack=unpack): - return _unpack('<d', self.read(8))[0] - - def readPacked(self, fmt, _unpack=unpack): - return unpack(fmt, self.read(calcsize(fmt))) - - def read0(self): - null = self.read(1) - if null != self.NULL: - raise ValueError("%s != NULL at %i" % (null, self.tell()-1)) - return null - def readUruString(self, version=5): return UruString('', version=version).readfd(self) - def readString0(self, size): - s = self.read(size-1) - self.read0() - return s - - def readString16(self, terminate=False): - return String16('', terminate=terminate).readfd(self) - - def readString32(self, terminate=False): - return String32('', terminate=terminate).readfd(self) - - def readRecord(self, name): - return parseRecord(name, self) - - @staticmethod - def registerRecord(name, fmt): - return registerRecord(name, fmt) - - #write - def writeChar(self, data, _pack=pack): - self.write(_pack('<c', data)) - - def writeByte(self, data, _pack=pack): - self.write(_pack('<B', data)) - - def writeBool(self, data, _pack=pack): - self.write(_pack('<B', bool(data))) - - def write8(self, data, _pack=pack): - self.write(_pack('<B', data)) - - def write8s(self, data, _pack=pack): - self.write(_pack('<b', data)) - - def write16(self, data, _pack=pack): - self.write(_pack('<H', data)) - - def write16s(self, data, _pack=pack): - self.write(_pack('<h', data)) - - def write32(self, data, _pack=pack): - self.write(_pack('<I', data)) - - def write32s(self, data, _pack=pack): - self.write(_pack('<i', data)) - - def write64(self, data, _pack=pack): - self.write(_pack('<Q', data)) - - def write64s(self, data, _pack=pack): - self.write(_pack('<q', data)) - - def writeQuad(self, tupl, _pack=pack): - self.write(_pack('<2I', *tupl)) - - def writeFloat(self, data, _pack=pack): - self.write(_pack('<f', data)) - - def writeDouble(self, data, _pack=pack): - self.write(_pack('<d', data)) - - def write0(self): - self.write(self.NULL) - - def writeString0(self, s): - self.write(s) - self.write0() - - def writePacked(self, data, fmt): - self.write(pack(fmt, data)) - def writeUruString(self, data, version=5): UruString(data, version=version).writefd(self) - def writeString16(self, data, terminate=False): - String16(data, terminate=terminate).writefd(self) - - def writeString32(self, data, terminate=False): - String32(data, terminate=terminate).writefd(self) - - def writeRecord(self, rec): - self.write(rec.read()) - -class AbstractString(object): - """Abstract string class - """ - def __init__(self, s=''): - self._data = s - - def readfd(self, fd): - raise NotImplementedError - - def writefd(self, fd): - raise NotImplementedError - - def clear(self): - """Clear data - """ - self._data = '' - - def set(self, urustr): - """Replace current data with urustr - """ - self._data = urustr - - def __repr__(self): - """repr(self) - """ - return ("<%s at %x (%i)" % (self.__class__.__name__, id(self), - len(self))) - - def __len__(self): - """len(self) - """ - return len(self._data) - - def __cmp__(self, other): - if isinstance(other, AbstractString): - return cmp(self._data, other._data) - else: - return cmp(self._data, other) - class UruString(AbstractString): """Uru Safe String - + The algorithm is based on Alcug's Ustr. This version is optimized to copy and convert as less data as possible. - + version 0 - normal str version 1 - auto (normal/inverted) version 5 - inverted @@ -329,51 +118,3 @@ result = fd.read(size) self._data = result return result - -class String32(AbstractString): - """String with 32 bit size header - """ - def __init__(self, s='', terminate=False): - AbstractString.__init__(self, s) - self._terminate = bool(terminate) - - def readfd(self, fd): - size = fd.read32() - if self._terminate: - self._data = fd.readString0(size) - else: - self._data = fd.read(size) - return self._data - - def writefd(self, fd): - size = len(self) - if self._terminate: - fd.write32(size+1) - fd.writeString0(self._data) - else: - fd.write32(size) - fd.write(self._data) - -class String16(AbstractString): - """String with 16 bit size header - """ - def __init__(self, s='', terminate=False): - AbstractString.__init__(self, s) - self._terminate = bool(terminate) - - def readfd(self, fd): - size = fd.read16() - if self._terminate: - self._data = fd.readString0(size) - else: - self._data = fd.read(size) - return self._data - - def writefd(self, fd): - size = len(self) - if self._terminate: - fd.write16(size+1) - fd.writeString0(self._data) - else: - fd.write16(size) - fd.write(self._data) Deleted: pymoul/trunk/src/moul/crypt/binaryrecord.py =================================================================== --- pymoul/trunk/src/moul/crypt/binaryrecord.py 2007-02-28 12:10:44 UTC (rev 217) +++ pymoul/trunk/src/moul/crypt/binaryrecord.py 2007-02-28 12:13:59 UTC (rev 218) @@ -1,170 +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 -# -"""Binary file helper: Records - -This module is roughly based on Maciej Obarski's recipe "parse and create -fixed size binary data" from -http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/465219 -""" -__author__ = "Christian Heimes" -__version__ = "$Id" -__revision__ = "$Revision" - -from struct import calcsize -from struct import pack -from struct import unpack - -_marker = object() - -class RecordRegistry(dict): - """Registry for record definitions - """ - __slots__ = () - def register(self, name, fmt): - """Register a format by name - - @param name: name of the format - @type name: str - @param fmt: a record format - @type fmt: str - - Example: - >>> reg = RecordRegistry() - >>> registerRecord = reg.register - >>> parseRecord = reg.parse - >>> obj = registerRecord("connection", "4B.ip >H.port >I.session_id") - >>> isinstance(obj, RecordDefinition) - True - >>> data = "\\xc0\\xa8\\x00\\x01" + "\\x00P" + "\\xFE\\xDC\\xBA\\x98" - - >>> rec = parseRecord("connection", data) - >>> rec.ip - (192, 168, 0, 1) - >>> rec.port - 80 - >>> rec.session_id - 4275878552L - >>> rec.read() == data or rec.read() - True - """ - if name in self: - raise NameError("%s already registered!" % name) - self[name] = RecordDefinition(name, fmt) - return self[name] - - def parse(self, name, fd_data): - """Parse data using the RecordDefinition 'name' - - @param name: name of the format - @type name: str - @param fd_data: data to parse: either a string or an open file - @type fd_data: str or file - """ - return self[name](fd_data) - -class RecordDefinition(object): - """A record definition - """ - __slots__ = ('_fields', '_recordsize', '_name') - - def __init__(self, name, recordfmt): - self._name = name - self._fields = [] - pos = 0 - for field in recordfmt.split(): - if field.startswith('#'): - continue - fmt, name = field.split('.') - if '#' in name: - name = name.split('#')[0] - name = name.strip() - size = calcsize(fmt) - self._fields.append((name, fmt, pos, pos+size)) - pos += size - - self._recordsize = pos - - @property - def name(self): - return self._name - - @property - def size(self): - return self._recordsize - - def __call__(self, fd_data): - """Parse data using the format string - - @param fd_data: data to parse: either a string or an open file - @type fd_data: str or file - """ - if isinstance(fd_data, basestring): - # handle string - data = fd_data - elif hasattr(fd_data, 'read'): - data = fd_data.read(self._recordsize) - else: - raise TypeError(type(fd_data)) - if len(data) != self._recordsize: - raise ValueError("Data has wrong size: %i, required: %i" % - (len(data), self._recordsize)) - return Record(self._fields, data) - -class Record(object): - __slots__ = ('_fields', '_data') - - def __init__(self, fields, data=None): - self._fields = fields - self._data = {} - if data is not None: - self.write(data) - - def write(self, data): - """Write data - - Creates the instance attributes defined in fmt - """ - for name, fmt, start, stop in self._fields: - value = unpack(fmt, data[start:stop]) - if len(value) == 1: - value = value[0] - self._data[name] = value - - def read(self): - """Convert data to binary string - """ - result = [] - for name, fmt, start, stop in self._fields: - value = self._data[name] - if not isinstance(value, (tuple, list)): - value = (value,) - result.append(pack(fmt, *value)) - return ''.join(result) - - def __getattr__(self, name, default=_marker): - value = self._data.get(name, default) - if value is _marker: - raise AttributeError(name) - return value - - def __str__(self): - return self.read() - -_recordRegistry = RecordRegistry() -registerRecord = _recordRegistry.register -parseRecord = _recordRegistry.parse Deleted: pymoul/trunk/src/moul/crypt/tests/test_binary.py =================================================================== --- pymoul/trunk/src/moul/crypt/tests/test_binary.py 2007-02-28 12:10:44 UTC (rev 217) +++ pymoul/trunk/src/moul/crypt/tests/test_binary.py 2007-02-28 12:13:59 UTC (rev 218) @@ -1,148 +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 -# -"""moul.crypt.binary unit tests -""" -__author__ = "Christian Heimes" -__version__ = "$Id$" -__revision__ = "$Revision$" - -import os -import unittest -from doctest import DocTestSuite -from tempfile import mkstemp - -from moul.crypt.binary import BinaryFile - -class BinaryFileTest(unittest.TestCase): - def setUp(self): - self.tmpname = mkstemp()[1] - self.b = BinaryFile(self.tmpname, 'wb+') - - def tearDown(self): - self.b.close() - os.unlink(self.tmpname) - - def _testrw(self, name, data): - #import pdb; pdb.set_trace() - read = getattr(self.b, 'read%s' % name) - write = getattr(self.b, 'write%s' % name) - write(data) - self.b.seek(0) - fdata = read() - self.failUnlessEqual(data, fdata) - - def test_char(self): - self._testrw('Char', 'a') - - def test_byte(self): - self._testrw('Byte', 127) - - def test_bool(self): - self._testrw('Bool', True) - - def test_8(self): - self._testrw('8', 42) - - def test_8s(self): - self._testrw('8s', -42) - - def test_16(self): - self._testrw('16', 2**15) - - def test_16s(self): - self._testrw('16s', -2**15) - - def test_32(self): - self._testrw('32', 2*31) - - def test_32s(self): - self._testrw('32s', -2*31) - - def test_64(self): - self._testrw('64', 2*63) - - def test_64s(self): - self._testrw('64s', -2*63) - - def test_float(self): - data = -0.07 - self.b.writeFloat(data) - self.b.seek(0) - self.failUnlessAlmostEqual(data, self.b.readFloat()) - - def test_double(self): - self._testrw('Double', -23*10e200) - - def test_quad(self): - data = (23, 42) - self.b.writeQuad(data) - self.b.seek(0) - self.failUnlessEqual(data, self.b.readQuad()) - - def test_urustring(self): - # XXX: no test data - pass - - def test_string0(self): - s = "a test string" - l = len(s) - self.b.writeString0(s) - self.b.seek(0) - self.failUnlessEqual(self.b.size(), l+1) - self.failUnlessEqual(self.b.readString0(l+1), s) - self.b.seek(0) - self.failUnlessEqual(self.b.read(), s+'\x00') - - def test_string16(self): - s = "a test string" - l = len(s) - self.b.writeString16(s, terminate=False) - self.b.seek(0) - self.failUnlessEqual(self.b.size(), l+2) - self.failUnlessEqual(self.b.readString16(terminate=False), s) - - self.b.seek(0) - self.b.truncate(0) - self.b.writeString16(s, terminate=True) - self.b.seek(0) - self.failUnlessEqual(self.b.size(), l+3) - self.failUnlessEqual(self.b.readString16(terminate=True), s) - - def test_string32(self): - s = "a test string" - l = len(s) - self.b.writeString32(s, terminate=False) - self.b.seek(0) - self.failUnlessEqual(self.b.size(), l+4) - self.failUnlessEqual(self.b.readString32(terminate=False), s) - - self.b.seek(0) - self.b.truncate(0) - self.b.writeString32(s, terminate=True) - self.b.seek(0) - self.failUnlessEqual(self.b.size(), l+5) - self.failUnlessEqual(self.b.readString32(terminate=True), s) - - -def test_suite(): - return unittest.TestSuite(( - unittest.makeSuite(BinaryFileTest), - )) - -if __name__ == '__main__': - unittest.main(defaultTest="test_suite") Deleted: pymoul/trunk/src/moul/crypt/tests/test_binaryrecord.py =================================================================== --- pymoul/trunk/src/moul/crypt/tests/test_binaryrecord.py 2007-02-28 12:10:44 UTC (rev 217) +++ pymoul/trunk/src/moul/crypt/tests/test_binaryrecord.py 2007-02-28 12:13:59 UTC (rev 218) @@ -1,38 +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 -# -"""moul.crypt.binaryrecord unit tests -""" -__author__ = "Christian Heimes" -__version__ = "$Id$" -__revision__ = "$Revision$" - -import os -import unittest -from doctest import DocTestSuite - -import moul.crypt.binaryrecord - -def test_suite(): - return unittest.TestSuite(( - DocTestSuite('moul.crypt.binaryrecord'), - )) - -if __name__ == '__main__': - unittest.main(defaultTest="test_suite") - - Modified: pymoul/trunk/src/moul/crypt/tests/test_wdys.py =================================================================== --- pymoul/trunk/src/moul/crypt/tests/test_wdys.py 2007-02-28 12:10:44 UTC (rev 217) +++ pymoul/trunk/src/moul/crypt/tests/test_wdys.py 2007-02-28 12:13:59 UTC (rev 218) @@ -64,7 +64,6 @@ return unittest.TestSuite(( unittest.makeSuite(WDYSTest), DocTestSuite('moul.crypt.whatdoyousee'), - DocTestSuite('moul.crypt.xtea'), )) if __name__ == '__main__': Modified: pymoul/trunk/src/moul/crypt/whatdoyousee.py =================================================================== --- pymoul/trunk/src/moul/crypt/whatdoyousee.py 2007-02-28 12:10:44 UTC (rev 217) +++ pymoul/trunk/src/moul/crypt/whatdoyousee.py 2007-02-28 12:13:59 UTC (rev 218) @@ -32,8 +32,8 @@ from logging import getLogger from moul.crypt.binary import BinaryFile -from moul.crypt.xtea import xtea_decrypt -from moul.crypt.xtea import xtea_encrypt +from xtea import xtea_decrypt +from xtea import xtea_encrypt HEADER = "whatdoyousee" @@ -87,7 +87,7 @@ instr = instr.replace("\n", "\r\n") fout.seek(0) fout.write(HEADER) - + flen = len(instr) length = struct.pack(ENDIAN+"L", flen) fout.write(length) Deleted: pymoul/trunk/src/moul/crypt/xtea.py =================================================================== --- pymoul/trunk/src/moul/crypt/xtea.py 2007-02-28 12:10:44 UTC (rev 217) +++ pymoul/trunk/src/moul/crypt/xtea.py 2007-02-28 12:13:59 UTC (rev 218) @@ -1,104 +0,0 @@ -"""XTEA Block Encryption Algorithm - -Author: Paul Chakravarti (paul_dot_chakravarti_at_mac_dot_com) -License: Public Domain - -Modified by Christian Heimes to add an endian switch. - -This module provides a Python implementation of the XTEA block encryption -algorithm (http://www.cix.co.uk/~klockstone/xtea.pdf). - -The module implements the basic XTEA block encryption algortithm -(`xtea_encrypt`/`xtea_decrypt`) and also provides a higher level `crypt` -function which symmetrically encrypts/decrypts a variable length string using -XTEA in OFB mode as a key generator. The `crypt` function does not use -`xtea_decrypt` which is provided for completeness only (but can be used -to support other stream modes - eg CBC/CFB). - -This module is intended to provide a simple 'privacy-grade' Python encryption -algorithm with no external dependencies. The implementation is relatively slow -and is best suited to small volumes of data. Note that the XTEA algorithm has -not been subjected to extensive analysis (though is believed to be relatively -secure - see http://en.wikipedia.org/wiki/XTEA). For applications requiring -'real' security please use a known and well tested algorithm/implementation. - -The security of the algorithm is entirely based on quality (entropy) and -secrecy of the key. You should generate the key from a known random source and -exchange using a trusted mechanism. In addition, you should always use a random -IV to seed the key generator (the IV is not sensitive and does not need to be -exchanged securely) - - >>> import os - >>> iv = 'ABCDEFGH' - >>> z = crypt('0123456789012345','Hello There',iv) - >>> z.encode('hex') - 'fe196d0a40d6c222b9eff3' - >>> crypt('0123456789012345',z,iv) - 'Hello There' - -""" -import struct - - -def crypt(key,data,iv='\00\00\00\00\00\00\00\00',n=32,endian="!"): - """ - Encrypt/decrypt variable length string using XTEA cypher as - key generator (OFB mode) - * key = 128 bit (16 char) / iv = 64 bit (8 char) - * data = string (any length) - - >>> import os - >>> key = os.urandom(16) - >>> iv = os.urandom(8) - >>> data = os.urandom(10000) - >>> z = crypt(key,data,iv) - >>> crypt(key,z,iv) == data - True - - """ - def keygen(key,iv,n): - while True: - iv = xtea_encrypt(key,iv,n,endian) - for k in iv: - yield ord(k) - xor = [ chr(x^y) for (x,y) in zip(map(ord,data),keygen(key,iv,n)) ] - return "".join(xor) - -def xtea_encrypt(key,block,n=32, endian="!"): - """ - Encrypt 64 bit data block using XTEA block cypher - * key = 128 bit (16 char) / block = 64 bit (8 char) - - >>> xtea_encrypt('0123456789012345','ABCDEFGH').encode('hex') - 'b67c01662ff6964a' - """ - v0,v1 = struct.unpack(endian+"2L",block) - k = struct.unpack(endian+"4L",key) - sum,delta,mask = 0L,0x9e3779b9L,0xffffffffL - for round in range(n): - v0 = (v0 + (((v1<<4 ^ v1>>5) + v1) ^ (sum + k[sum & 3]))) & mask - sum = (sum + delta) & mask - v1 = (v1 + (((v0<<4 ^ v0>>5) + v0) ^ (sum + k[sum>>11 & 3]))) & mask - return struct.pack(endian+"2L",v0,v1) - -def xtea_decrypt(key,block,n=32, endian="!"): - """ - Decrypt 64 bit data block using XTEA block cypher - * key = 128 bit (16 char) / block = 64 bit (8 char) - - >>> xtea_decrypt('0123456789012345','b67c01662ff6964a'.decode('hex')) - 'ABCDEFGH' - """ - v0,v1 = struct.unpack(endian+"2L",block) - k = struct.unpack(endian+"4L",key) - delta,mask = 0x9e3779b9L,0xffffffffL - sum = (delta * n) & mask - for round in range(n): - v1 = (v1 - (((v0<<4 ^ v0>>5) + v0) ^ (sum + k[sum>>11 & 3]))) & mask - sum = (sum - delta) & mask - v0 = (v0 - (((v1<<4 ^ v1>>5) + v1) ^ (sum + k[sum & 3]))) & mask - return struct.pack(endian+"2L",v0,v1) - -if __name__ == "__main__": - import doctest - doctest.testmod() \ No newline at end of file Deleted: pymoul/trunk/src/moul/osdependent/tests/test_processinfo.py =================================================================== --- pymoul/trunk/src/moul/osdependent/tests/test_processinfo.py 2007-02-28 12:10:44 UTC (rev 217) +++ pymoul/trunk/src/moul/osdependent/tests/test_processinfo.py 2007-02-28 12:13:59 UTC (rev 218) @@ -1,37 +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 -# -"""moul.osdependent.processinfo -""" -__author__ = "Christian Heimes" -__version__ = "$Id$" -__revision__ = "$Revision$" - -import unittest -from doctest import DocTestSuite - -import moul.osdependent.processinfo - - -def test_suite(): - return unittest.TestSuite(( - DocTestSuite('moul.osdependent.processinfo'), - )) - -if __name__ == '__main__': - unittest.main(defaultTest="test_suite") - This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ti...@us...> - 2007-02-28 12:10:45
|
Revision: 217 http://pymoul.svn.sourceforge.net/pymoul/?rev=217&view=rev Author: tiran Date: 2007-02-28 04:10:44 -0800 (Wed, 28 Feb 2007) Log Message: ----------- Mpf :( Modified Paths: -------------- xtea/trunk/src/xtea/__init__.py Modified: xtea/trunk/src/xtea/__init__.py =================================================================== --- xtea/trunk/src/xtea/__init__.py 2007-02-28 12:06:48 UTC (rev 216) +++ xtea/trunk/src/xtea/__init__.py 2007-02-28 12:10:44 UTC (rev 217) @@ -1,6 +1,6 @@ # xtea package -from xtea.xtea import crypt -from xtea.xtea import xtea_encrypt -from xtea.xtea import xtea_encryptQuad -from xtea.xtea import xtea_decrypt -from xtea.xtea import xtea_decryptQuad +from xtea import crypt +from xtea import xtea_encrypt +from xtea import xtea_encryptQuad +from xtea import xtea_decrypt +from xtea import xtea_decryptQuad This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ti...@us...> - 2007-02-28 12:06:49
|
Revision: 216 http://pymoul.svn.sourceforge.net/pymoul/?rev=216&view=rev Author: tiran Date: 2007-02-28 04:06:48 -0800 (Wed, 28 Feb 2007) Log Message: ----------- Changed imports Modified Paths: -------------- binaryfile/trunk/Makefile binaryfile/trunk/src/binaryfile/tests.py Modified: binaryfile/trunk/Makefile =================================================================== --- binaryfile/trunk/Makefile 2007-02-28 12:03:04 UTC (rev 215) +++ binaryfile/trunk/Makefile 2007-02-28 12:06:48 UTC (rev 216) @@ -32,7 +32,7 @@ # What should the default be? test: - $(PYTHON) src/binaryfile/tests.py + PYTHONPATH=src $(PYTHON) src/binaryfile/tests.py egg: egg24 egg25 Modified: binaryfile/trunk/src/binaryfile/tests.py =================================================================== --- binaryfile/trunk/src/binaryfile/tests.py 2007-02-28 12:03:04 UTC (rev 215) +++ binaryfile/trunk/src/binaryfile/tests.py 2007-02-28 12:06:48 UTC (rev 216) @@ -10,7 +10,7 @@ from doctest import DocTestSuite from tempfile import mkstemp -from binary import BinaryFile +from binaryfile.binary import BinaryFile class BinaryFileTest(unittest.TestCase): def setUp(self): This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ti...@us...> - 2007-02-28 12:03:08
|
Revision: 215 http://pymoul.svn.sourceforge.net/pymoul/?rev=215&view=rev Author: tiran Date: 2007-02-28 04:03:04 -0800 (Wed, 28 Feb 2007) Log Message: ----------- Changed imports Modified Paths: -------------- enumprocess/trunk/src/enumprocess/__init__.py Modified: enumprocess/trunk/src/enumprocess/__init__.py =================================================================== --- enumprocess/trunk/src/enumprocess/__init__.py 2007-02-28 12:01:33 UTC (rev 214) +++ enumprocess/trunk/src/enumprocess/__init__.py 2007-02-28 12:03:04 UTC (rev 215) @@ -29,4 +29,7 @@ # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. """enum processes """ -from processinfo import * +from enumprocess.processinfo import getPids +from enumprocess.processinfo import getPidNames +from enumprocess.processinfo import getPidDetails +from enumprocess.processinfo import supportedOS This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ti...@us...> - 2007-02-28 12:01:32
|
Revision: 214 http://pymoul.svn.sourceforge.net/pymoul/?rev=214&view=rev Author: tiran Date: 2007-02-28 04:01:33 -0800 (Wed, 28 Feb 2007) Log Message: ----------- Renamed some methods, classes and changed imports Modified Paths: -------------- binaryfile/trunk/src/binaryfile/__init__.py binaryfile/trunk/src/binaryfile/binary.py binaryfile/trunk/src/binaryfile/binaryrecord.py binaryfile/trunk/src/binaryfile/tests.py Modified: binaryfile/trunk/src/binaryfile/__init__.py =================================================================== --- binaryfile/trunk/src/binaryfile/__init__.py 2007-02-28 11:59:37 UTC (rev 213) +++ binaryfile/trunk/src/binaryfile/__init__.py 2007-02-28 12:01:33 UTC (rev 214) @@ -0,0 +1,4 @@ +# binaryfile package +from binaryfile.binary import BinaryFile +from binaryfile.binaryrecord import registerRecord +from binaryfile.binaryrecord import parseRecord Modified: binaryfile/trunk/src/binaryfile/binary.py =================================================================== --- binaryfile/trunk/src/binaryfile/binary.py 2007-02-28 11:59:37 UTC (rev 213) +++ binaryfile/trunk/src/binaryfile/binary.py 2007-02-28 12:01:33 UTC (rev 214) @@ -9,9 +9,10 @@ from struct import pack from struct import unpack -from binaryrecord import parseRecord -from binaryrecord import registerRecord +from binaryfile.binaryrecord import parseRecord +from binaryfile.binaryrecord import registerRecord + class BinaryFile(file): """Binary file Modified: binaryfile/trunk/src/binaryfile/binaryrecord.py =================================================================== --- binaryfile/trunk/src/binaryfile/binaryrecord.py 2007-02-28 11:59:37 UTC (rev 213) +++ binaryfile/trunk/src/binaryfile/binaryrecord.py 2007-02-28 12:01:33 UTC (rev 214) @@ -15,7 +15,7 @@ _marker = object() -class RecordRegistry(dict): +class BinaryRecordRegistry(dict): """Registry for record definitions """ __slots__ = () @@ -28,11 +28,11 @@ @type fmt: str Example: - >>> reg = RecordRegistry() + >>> reg = BinaryRecordRegistry() >>> registerRecord = reg.register >>> parseRecord = reg.parse >>> obj = registerRecord("connection", "4B.ip >H.port >I.session_id") - >>> isinstance(obj, RecordDefinition) + >>> isinstance(obj, BinaryRecordDefinition) True >>> data = "\\xc0\\xa8\\x00\\x01" + "\\x00P" + "\\xFE\\xDC\\xBA\\x98" @@ -48,7 +48,7 @@ """ if name in self: raise NameError("%s already registered!" % name) - self[name] = RecordDefinition(name, fmt) + self[name] = BinaryRecordDefinition(name, fmt) return self[name] def parse(self, name, fd_data): @@ -61,7 +61,7 @@ """ return self[name](fd_data) -class RecordDefinition(object): +class BinaryRecordDefinition(object): """A record definition """ __slots__ = ('_fields', '_recordsize', '_name') @@ -107,9 +107,9 @@ if len(data) != self._recordsize: raise ValueError("Data has wrong size: %i, required: %i" % (len(data), self._recordsize)) - return Record(self._fields, data) + return BinaryRecord(self._fields, data) -class Record(object): +class BinaryRecord(object): __slots__ = ('_fields', '_data') def __init__(self, fields, data=None): @@ -149,6 +149,6 @@ def __str__(self): return self.read() -_recordRegistry = RecordRegistry() +_recordRegistry = BinaryRecordRegistry() registerRecord = _recordRegistry.register parseRecord = _recordRegistry.parse Modified: binaryfile/trunk/src/binaryfile/tests.py =================================================================== --- binaryfile/trunk/src/binaryfile/tests.py 2007-02-28 11:59:37 UTC (rev 213) +++ binaryfile/trunk/src/binaryfile/tests.py 2007-02-28 12:01:33 UTC (rev 214) @@ -126,8 +126,8 @@ def test_suite(): return unittest.TestSuite(( unittest.makeSuite(BinaryFileTest), - DocTestSuite('binary'), - DocTestSuite('binaryrecord'), + DocTestSuite('binaryfile.binary'), + DocTestSuite('binaryfile.binaryrecord'), )) if __name__ == '__main__': This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ti...@us...> - 2007-02-28 11:59:38
|
Revision: 213 http://pymoul.svn.sourceforge.net/pymoul/?rev=213&view=rev Author: tiran Date: 2007-02-28 03:59:37 -0800 (Wed, 28 Feb 2007) Log Message: ----------- Renamed some functions Modified Paths: -------------- xtea/trunk/setup.py xtea/trunk/src/xtea/__init__.py xtea/trunk/src/xtea/_xtea.c xtea/trunk/src/xtea/_xtea.pyx xtea/trunk/src/xtea/xtea.py Modified: xtea/trunk/setup.py =================================================================== --- xtea/trunk/setup.py 2007-02-28 01:53:29 UTC (rev 212) +++ xtea/trunk/setup.py 2007-02-28 11:59:37 UTC (rev 213) @@ -16,6 +16,7 @@ __revision__ = "$Revision: 203 $" import sys +import os if sys.version_info < (2,4): raise RuntimeError("Python 2.4+ required:\n%s" % sys.version) @@ -37,6 +38,10 @@ me = "Christian Heimes" email = "chr...@ch..." +ext_modules = [] +if os.name == 'posix': + ext_modules.append(Extension('xtea._xtea', ['src/xtea/_xtea.c'])) + setup_infos = dict( name = "xtea", version = VERSION, @@ -61,7 +66,7 @@ 'Programming Language :: Python', 'Topic :: Software Development :: Libraries' ), - ext_modules=[Extension('xtea._xtea', ['src/xtea/_xtea.c'])], + ext_modules=ext_modules, setup_requires = ["setuptools>="+SETUPTOOLS_VERSION,], packages = ['xtea'], package_dir = {'' : 'src'}, Modified: xtea/trunk/src/xtea/__init__.py =================================================================== --- xtea/trunk/src/xtea/__init__.py 2007-02-28 01:53:29 UTC (rev 212) +++ xtea/trunk/src/xtea/__init__.py 2007-02-28 11:59:37 UTC (rev 213) @@ -1,6 +1,6 @@ # xtea package -from xtea import crypt -from xtea import xtea_encrypt -from xtea import xtea_encryptQuad -from xtea import xtea_decrypt -from xtea import xtea_decryptQuad +from xtea.xtea import crypt +from xtea.xtea import xtea_encrypt +from xtea.xtea import xtea_encryptQuad +from xtea.xtea import xtea_decrypt +from xtea.xtea import xtea_decryptQuad Modified: xtea/trunk/src/xtea/_xtea.c =================================================================== --- xtea/trunk/src/xtea/_xtea.c 2007-02-28 01:53:29 UTC (rev 212) +++ xtea/trunk/src/xtea/_xtea.c 2007-02-28 11:59:37 UTC (rev 213) @@ -1,4 +1,4 @@ -/* Generated by Pyrex 0.9.4.1 on Wed Feb 28 02:39:57 2007 */ +/* Generated by Pyrex 0.9.4.1 on Wed Feb 28 12:58:37 2007 */ #include "Python.h" #include "structmember.h" @@ -47,11 +47,11 @@ /* Implementation of _xtea */ -static PyObject *__pyx_n__xtea_encryptQuad; -static PyObject *__pyx_n__xtea_decryptQuad; +static PyObject *__pyx_n__c_xtea_encryptQuad; +static PyObject *__pyx_n__c_xtea_decryptQuad; -static PyObject *__pyx_f_5_xtea__xtea_encryptQuad(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static PyObject *__pyx_f_5_xtea__xtea_encryptQuad(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { +static PyObject *__pyx_f_5_xtea__c_xtea_encryptQuad(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_f_5_xtea__c_xtea_encryptQuad(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { unsigned long __pyx_v_v0; unsigned long __pyx_v_v1; PyObject *__pyx_v_key = 0; @@ -158,7 +158,7 @@ Py_XDECREF(__pyx_3); Py_XDECREF(__pyx_4); Py_XDECREF(__pyx_5); - __Pyx_AddTraceback("_xtea._xtea_encryptQuad"); + __Pyx_AddTraceback("_xtea._c_xtea_encryptQuad"); __pyx_r = 0; __pyx_L0:; Py_DECREF(__pyx_v_result); @@ -166,8 +166,8 @@ return __pyx_r; } -static PyObject *__pyx_f_5_xtea__xtea_decryptQuad(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ -static PyObject *__pyx_f_5_xtea__xtea_decryptQuad(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { +static PyObject *__pyx_f_5_xtea__c_xtea_decryptQuad(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_f_5_xtea__c_xtea_decryptQuad(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { unsigned long __pyx_v_v0; unsigned long __pyx_v_v1; PyObject *__pyx_v_key = 0; @@ -274,7 +274,7 @@ Py_XDECREF(__pyx_3); Py_XDECREF(__pyx_4); Py_XDECREF(__pyx_5); - __Pyx_AddTraceback("_xtea._xtea_decryptQuad"); + __Pyx_AddTraceback("_xtea._c_xtea_decryptQuad"); __pyx_r = 0; __pyx_L0:; Py_DECREF(__pyx_v_result); @@ -283,14 +283,14 @@ } static __Pyx_InternTabEntry __pyx_intern_tab[] = { - {&__pyx_n__xtea_decryptQuad, "_xtea_decryptQuad"}, - {&__pyx_n__xtea_encryptQuad, "_xtea_encryptQuad"}, + {&__pyx_n__c_xtea_decryptQuad, "_c_xtea_decryptQuad"}, + {&__pyx_n__c_xtea_encryptQuad, "_c_xtea_encryptQuad"}, {0, 0} }; static struct PyMethodDef __pyx_methods[] = { - {"_xtea_encryptQuad", (PyCFunction)__pyx_f_5_xtea__xtea_encryptQuad, METH_VARARGS|METH_KEYWORDS, 0}, - {"_xtea_decryptQuad", (PyCFunction)__pyx_f_5_xtea__xtea_decryptQuad, METH_VARARGS|METH_KEYWORDS, 0}, + {"_c_xtea_encryptQuad", (PyCFunction)__pyx_f_5_xtea__c_xtea_encryptQuad, METH_VARARGS|METH_KEYWORDS, 0}, + {"_c_xtea_decryptQuad", (PyCFunction)__pyx_f_5_xtea__c_xtea_decryptQuad, METH_VARARGS|METH_KEYWORDS, 0}, {0, 0, 0, 0} }; Modified: xtea/trunk/src/xtea/_xtea.pyx =================================================================== --- xtea/trunk/src/xtea/_xtea.pyx 2007-02-28 01:53:29 UTC (rev 212) +++ xtea/trunk/src/xtea/_xtea.pyx 2007-02-28 11:59:37 UTC (rev 213) @@ -4,7 +4,7 @@ ctypedef unsigned long ULong -def _xtea_encryptQuad(ULong v0, ULong v1, key, int rounds): +def _c_xtea_encryptQuad(ULong v0, ULong v1, key, int rounds): cdef int i cdef ULong delta, sum @@ -20,7 +20,7 @@ result = [v0, v1] return result -def _xtea_decryptQuad(ULong v0, ULong v1, key, int rounds): +def _c_xtea_decryptQuad(ULong v0, ULong v1, key, int rounds): cdef int i cdef ULong delta, sum Modified: xtea/trunk/src/xtea/xtea.py =================================================================== --- xtea/trunk/src/xtea/xtea.py 2007-02-28 01:53:29 UTC (rev 212) +++ xtea/trunk/src/xtea/xtea.py 2007-02-28 11:59:37 UTC (rev 213) @@ -89,7 +89,8 @@ v0, v1 = xtea_encryptQuad(v0, v1, k, rounds) return struct.pack(endian+"2L", v0, v1) -def _xtea_encryptQuad(v0, v1, key, rounds=32, delta=0x9e3779b9L, mask=0xffffffffL): +def _py_xtea_encryptQuad(v0, v1, key, rounds=32, delta=0x9e3779b9L, + mask=0xffffffffL): """Encrypt a quad @param v0: value 0 @@ -135,7 +136,8 @@ v0, v1 = xtea_decryptQuad(v0, v1, k, rounds) return struct.pack(endian+"2L", v0, v1) -def _xtea_decryptQuad(v0, v1, key, rounds=32, delta=0x9e3779b9L, mask=0xffffffffL): +def _py_xtea_decryptQuad(v0, v1, key, rounds=32, delta=0x9e3779b9L, + mask=0xffffffffL): """Decrypt a quad @param v0: value 0 @@ -159,11 +161,15 @@ # Try to replace core functions with optimized versions try: #raise ImportError - from _xtea import encipher as xtea_encryptQuad - from _xtea import decipher as xtea_decryptQuad + from _xtea import _c_xtea_encryptQuad + from _xtea import _c_xtea_decryptQuad except ImportError, msg: - xtea_encryptQuad = _xtea_encryptQuad - xtea_decryptQuad = _xtea_decryptQuad + print msg + xtea_encryptQuad = _py_xtea_encryptQuad + xtea_decryptQuad = _py_xtea_decryptQuad +else: + xtea_encryptQuad = _c_xtea_encryptQuad + xtea_decryptQuad = _c_xtea_decryptQuad if __name__ == "__main__": import doctest This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ti...@us...> - 2007-02-28 01:53:27
|
Revision: 212 http://pymoul.svn.sourceforge.net/pymoul/?rev=212&view=rev Author: tiran Date: 2007-02-27 17:53:29 -0800 (Tue, 27 Feb 2007) Log Message: ----------- Removed uru cruft Modified Paths: -------------- binaryfile/trunk/src/binaryfile/binary.py Modified: binaryfile/trunk/src/binaryfile/binary.py =================================================================== --- binaryfile/trunk/src/binaryfile/binary.py 2007-02-28 01:42:12 UTC (rev 211) +++ binaryfile/trunk/src/binaryfile/binary.py 2007-02-28 01:53:29 UTC (rev 212) @@ -108,9 +108,6 @@ raise ValueError("%s != NULL at %i" % (null, self.tell()-1)) return null - def readUruString(self, version=5): - return UruString('', version=version).readfd(self) - def readString0(self, size): s = self.read(size-1) self.read0() @@ -182,9 +179,6 @@ def writePacked(self, data, fmt): self.write(pack(fmt, data)) - def writeUruString(self, data, version=5): - UruString(data, version=version).writefd(self) - def writeString16(self, data, terminate=False): String16(data, terminate=terminate).writefd(self) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ti...@us...> - 2007-02-28 01:42:14
|
Revision: 211 http://pymoul.svn.sourceforge.net/pymoul/?rev=211&view=rev Author: tiran Date: 2007-02-27 17:42:12 -0800 (Tue, 27 Feb 2007) Log Message: ----------- Moved to package with pyrex optimization Modified Paths: -------------- xtea/trunk/Makefile xtea/trunk/README.txt xtea/trunk/setup.py xtea/trunk/src/xtea.egg-info/SOURCES.txt Added Paths: ----------- xtea/trunk/src/xtea/ xtea/trunk/src/xtea/__init__.py xtea/trunk/src/xtea/_xtea.c xtea/trunk/src/xtea/_xtea.pyx xtea/trunk/src/xtea/xtea.py xtea/trunk/src/xtea.egg-info/native_libs.txt Removed Paths: ------------- xtea/trunk/src/xtea.py Property Changed: ---------------- xtea/trunk/ Property changes on: xtea/trunk ___________________________________________________________________ Name: svn:ignore + build dist Modified: xtea/trunk/Makefile =================================================================== --- xtea/trunk/Makefile 2007-02-27 16:22:39 UTC (rev 210) +++ xtea/trunk/Makefile 2007-02-28 01:42:12 UTC (rev 211) @@ -9,30 +9,33 @@ all: inplace # Build in-place -inplace: +inplace: pyrex $(PYTHON) setup.py $(SETUPFLAGS) build_ext -i -build: +build: pyrex $(PYTHON) setup.py $(SETUPFLAGS) build +pyrex: + pyrexc src/xtea/_xtea.pyx + egg24: $(PYTHON24) setup.py $(SETUPFLAGS) bdist_egg egg25: $(PYTHON25) setup.py $(SETUPFLAGS) bdist_egg -dist25: +dist25: realclean build $(PYTHON25) setup.py $(SETUPFLAGS) bdist_egg \ sdist --formats=zip,gztar -dist_upload: realclean +dist_upload: realclean build $(PYTHON25) setup.py $(SETUPFLAGS) bdist_egg \ sdist --formats=zip,gztar \ upload --sign --identity=$(KEYID) # What should the default be? test: - $(PYTHON) xtea.py + $(PYTHON) src/xtea/xtea.py egg: egg24 egg25 Modified: xtea/trunk/README.txt =================================================================== --- xtea/trunk/README.txt 2007-02-27 16:22:39 UTC (rev 210) +++ xtea/trunk/README.txt 2007-02-28 01:42:12 UTC (rev 211) @@ -3,6 +3,8 @@ Author: Paul Chakravarti (paul_dot_chakravarti_at_mac_dot_com) License: Public Domain +pyrex optimization: Christian Heimes + This module provides a Python implementation of the XTEA block encryption algorithm (http://www.cix.co.uk/~klockstone/xtea.pdf). Modified: xtea/trunk/setup.py =================================================================== --- xtea/trunk/setup.py 2007-02-27 16:22:39 UTC (rev 210) +++ xtea/trunk/setup.py 2007-02-28 01:42:12 UTC (rev 211) @@ -28,6 +28,7 @@ # import the rest from setuptools import setup from setuptools import find_packages +from setuptools import Extension from distutils.core import setup @@ -60,9 +61,9 @@ 'Programming Language :: Python', 'Topic :: Software Development :: Libraries' ), + ext_modules=[Extension('xtea._xtea', ['src/xtea/_xtea.c'])], setup_requires = ["setuptools>="+SETUPTOOLS_VERSION,], - #packages = ['xtea'], - py_modules = ['xtea'], + packages = ['xtea'], package_dir = {'' : 'src'}, zip_safe = True, ) Property changes on: xtea/trunk/src/xtea ___________________________________________________________________ Name: svn:ignore + _xtea.so Added: xtea/trunk/src/xtea/__init__.py =================================================================== --- xtea/trunk/src/xtea/__init__.py (rev 0) +++ xtea/trunk/src/xtea/__init__.py 2007-02-28 01:42:12 UTC (rev 211) @@ -0,0 +1,6 @@ +# xtea package +from xtea import crypt +from xtea import xtea_encrypt +from xtea import xtea_encryptQuad +from xtea import xtea_decrypt +from xtea import xtea_decryptQuad Property changes on: xtea/trunk/src/xtea/__init__.py ___________________________________________________________________ Name: svn:keywords + 'Id Revision' Name: svn:eol-style + native Added: xtea/trunk/src/xtea/_xtea.c =================================================================== --- xtea/trunk/src/xtea/_xtea.c (rev 0) +++ xtea/trunk/src/xtea/_xtea.c 2007-02-28 01:42:12 UTC (rev 211) @@ -0,0 +1,391 @@ +/* Generated by Pyrex 0.9.4.1 on Wed Feb 28 02:39:57 2007 */ + +#include "Python.h" +#include "structmember.h" +#ifndef PY_LONG_LONG + #define PY_LONG_LONG LONG_LONG +#endif +#ifdef __cplusplus +#define __PYX_EXTERN_C extern "C" +#else +#define __PYX_EXTERN_C extern +#endif +__PYX_EXTERN_C double pow(double, double); + + +typedef struct {PyObject **p; char *s;} __Pyx_InternTabEntry; /*proto*/ +typedef struct {PyObject **p; char *s; long n;} __Pyx_StringTabEntry; /*proto*/ +static PyObject *__Pyx_UnpackItem(PyObject *, int); /*proto*/ +static int __Pyx_EndUnpack(PyObject *, int); /*proto*/ +static int __Pyx_PrintItem(PyObject *); /*proto*/ +static int __Pyx_PrintNewline(void); /*proto*/ +static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb); /*proto*/ +static void __Pyx_ReRaise(void); /*proto*/ +static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list); /*proto*/ +static PyObject *__Pyx_GetExcValue(void); /*proto*/ +static int __Pyx_ArgTypeTest(PyObject *obj, PyTypeObject *type, int none_allowed, char *name); /*proto*/ +static int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type); /*proto*/ +static int __Pyx_GetStarArgs(PyObject **args, PyObject **kwds, char *kwd_list[], int nargs, PyObject **args2, PyObject **kwds2); /*proto*/ +static void __Pyx_WriteUnraisable(char *name); /*proto*/ +static void __Pyx_AddTraceback(char *funcname); /*proto*/ +static PyTypeObject *__Pyx_ImportType(char *module_name, char *class_name, long size); /*proto*/ +static int __Pyx_SetVtable(PyObject *dict, void *vtable); /*proto*/ +static int __Pyx_GetVtable(PyObject *dict, void *vtabptr); /*proto*/ +static PyObject *__Pyx_CreateClass(PyObject *bases, PyObject *dict, PyObject *name, char *modname); /*proto*/ +static int __Pyx_InternStrings(__Pyx_InternTabEntry *t); /*proto*/ +static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); /*proto*/ +static PyObject *__Pyx_GetName(PyObject *dict, PyObject *name); /*proto*/ + +static PyObject *__pyx_m; +static PyObject *__pyx_b; +static int __pyx_lineno; +static char *__pyx_filename; +static char **__pyx_f; + +/* Declarations from _xtea */ + + +/* Implementation of _xtea */ + +static PyObject *__pyx_n__xtea_encryptQuad; +static PyObject *__pyx_n__xtea_decryptQuad; + +static PyObject *__pyx_f_5_xtea__xtea_encryptQuad(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_f_5_xtea__xtea_encryptQuad(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + unsigned long __pyx_v_v0; + unsigned long __pyx_v_v1; + PyObject *__pyx_v_key = 0; + int __pyx_v_rounds; + int __pyx_v_i; + unsigned long __pyx_v_delta; + unsigned long __pyx_v_sum; + PyObject *__pyx_v_result; + PyObject *__pyx_r; + PyObject *__pyx_1 = 0; + PyObject *__pyx_2 = 0; + PyObject *__pyx_3 = 0; + PyObject *__pyx_4 = 0; + PyObject *__pyx_5 = 0; + unsigned long __pyx_6; + static char *__pyx_argnames[] = {"v0","v1","key","rounds",0}; + if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "kkOi", __pyx_argnames, &__pyx_v_v0, &__pyx_v_v1, &__pyx_v_key, &__pyx_v_rounds)) return 0; + Py_INCREF(__pyx_v_key); + __pyx_v_result = Py_None; Py_INCREF(Py_None); + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":11 */ + __pyx_v_delta = 2654435769; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":12 */ + __pyx_v_sum = 0; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":13 */ + __pyx_1 = PyList_New(0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 13; goto __pyx_L1;} + Py_DECREF(__pyx_v_result); + __pyx_v_result = __pyx_1; + __pyx_1 = 0; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":15 */ + for (__pyx_v_i = 0; __pyx_v_i < __pyx_v_rounds; ++__pyx_v_i) { + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":16 */ + __pyx_1 = PyLong_FromUnsignedLong(__pyx_v_v0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; goto __pyx_L1;} + __pyx_2 = PyLong_FromUnsignedLong((((__pyx_v_v1 << 4) ^ (__pyx_v_v1 >> 5)) + __pyx_v_v1)); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; goto __pyx_L1;} + __pyx_3 = PyLong_FromUnsignedLong(__pyx_v_sum); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; goto __pyx_L1;} + __pyx_4 = PyLong_FromUnsignedLong((__pyx_v_sum & 3)); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; goto __pyx_L1;} + __pyx_5 = PyObject_GetItem(__pyx_v_key, __pyx_4); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; goto __pyx_L1;} + Py_DECREF(__pyx_4); __pyx_4 = 0; + __pyx_4 = PyNumber_Add(__pyx_3, __pyx_5); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; goto __pyx_L1;} + Py_DECREF(__pyx_3); __pyx_3 = 0; + Py_DECREF(__pyx_5); __pyx_5 = 0; + __pyx_3 = PyNumber_Xor(__pyx_2, __pyx_4); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + Py_DECREF(__pyx_4); __pyx_4 = 0; + __pyx_5 = PyNumber_Add(__pyx_1, __pyx_3); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + Py_DECREF(__pyx_3); __pyx_3 = 0; + __pyx_6 = PyInt_AsUnsignedLongMask(__pyx_5); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 16; goto __pyx_L1;} + Py_DECREF(__pyx_5); __pyx_5 = 0; + __pyx_v_v0 = __pyx_6; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":17 */ + __pyx_v_sum = (__pyx_v_sum + __pyx_v_delta); + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":18 */ + __pyx_2 = PyLong_FromUnsignedLong(__pyx_v_v1); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 18; goto __pyx_L1;} + __pyx_4 = PyLong_FromUnsignedLong((((__pyx_v_v0 << 4) ^ (__pyx_v_v0 >> 5)) + __pyx_v_v0)); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 18; goto __pyx_L1;} + __pyx_1 = PyLong_FromUnsignedLong(__pyx_v_sum); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 18; goto __pyx_L1;} + __pyx_3 = PyLong_FromUnsignedLong(((__pyx_v_sum >> 11) & 3)); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 18; goto __pyx_L1;} + __pyx_5 = PyObject_GetItem(__pyx_v_key, __pyx_3); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 18; goto __pyx_L1;} + Py_DECREF(__pyx_3); __pyx_3 = 0; + __pyx_3 = PyNumber_Add(__pyx_1, __pyx_5); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 18; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + Py_DECREF(__pyx_5); __pyx_5 = 0; + __pyx_1 = PyNumber_Xor(__pyx_4, __pyx_3); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 18; goto __pyx_L1;} + Py_DECREF(__pyx_4); __pyx_4 = 0; + Py_DECREF(__pyx_3); __pyx_3 = 0; + __pyx_5 = PyNumber_Add(__pyx_2, __pyx_1); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 18; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + Py_DECREF(__pyx_1); __pyx_1 = 0; + __pyx_6 = PyInt_AsUnsignedLongMask(__pyx_5); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 18; goto __pyx_L1;} + Py_DECREF(__pyx_5); __pyx_5 = 0; + __pyx_v_v1 = __pyx_6; + __pyx_L2:; + } + __pyx_L3:; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":20 */ + __pyx_4 = PyLong_FromUnsignedLong(__pyx_v_v0); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 20; goto __pyx_L1;} + __pyx_3 = PyLong_FromUnsignedLong(__pyx_v_v1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 20; goto __pyx_L1;} + __pyx_2 = PyList_New(2); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 20; goto __pyx_L1;} + PyList_SET_ITEM(__pyx_2, 0, __pyx_4); + PyList_SET_ITEM(__pyx_2, 1, __pyx_3); + __pyx_4 = 0; + __pyx_3 = 0; + Py_DECREF(__pyx_v_result); + __pyx_v_result = __pyx_2; + __pyx_2 = 0; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":21 */ + Py_INCREF(__pyx_v_result); + __pyx_r = __pyx_v_result; + goto __pyx_L0; + + __pyx_r = Py_None; Py_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1:; + Py_XDECREF(__pyx_1); + Py_XDECREF(__pyx_2); + Py_XDECREF(__pyx_3); + Py_XDECREF(__pyx_4); + Py_XDECREF(__pyx_5); + __Pyx_AddTraceback("_xtea._xtea_encryptQuad"); + __pyx_r = 0; + __pyx_L0:; + Py_DECREF(__pyx_v_result); + Py_DECREF(__pyx_v_key); + return __pyx_r; +} + +static PyObject *__pyx_f_5_xtea__xtea_decryptQuad(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static PyObject *__pyx_f_5_xtea__xtea_decryptQuad(PyObject *__pyx_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + unsigned long __pyx_v_v0; + unsigned long __pyx_v_v1; + PyObject *__pyx_v_key = 0; + int __pyx_v_rounds; + int __pyx_v_i; + unsigned long __pyx_v_delta; + unsigned long __pyx_v_sum; + PyObject *__pyx_v_result; + PyObject *__pyx_r; + PyObject *__pyx_1 = 0; + PyObject *__pyx_2 = 0; + PyObject *__pyx_3 = 0; + PyObject *__pyx_4 = 0; + PyObject *__pyx_5 = 0; + unsigned long __pyx_6; + static char *__pyx_argnames[] = {"v0","v1","key","rounds",0}; + if (!PyArg_ParseTupleAndKeywords(__pyx_args, __pyx_kwds, "kkOi", __pyx_argnames, &__pyx_v_v0, &__pyx_v_v1, &__pyx_v_key, &__pyx_v_rounds)) return 0; + Py_INCREF(__pyx_v_key); + __pyx_v_result = Py_None; Py_INCREF(Py_None); + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":27 */ + __pyx_v_delta = 2654435769; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":28 */ + __pyx_v_sum = (__pyx_v_delta * __pyx_v_rounds); + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":29 */ + __pyx_1 = PyList_New(0); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 29; goto __pyx_L1;} + Py_DECREF(__pyx_v_result); + __pyx_v_result = __pyx_1; + __pyx_1 = 0; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":31 */ + for (__pyx_v_i = 0; __pyx_v_i < __pyx_v_rounds; ++__pyx_v_i) { + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":32 */ + __pyx_1 = PyLong_FromUnsignedLong(__pyx_v_v1); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; goto __pyx_L1;} + __pyx_2 = PyLong_FromUnsignedLong((((__pyx_v_v0 << 4) ^ (__pyx_v_v0 >> 5)) + __pyx_v_v0)); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; goto __pyx_L1;} + __pyx_3 = PyLong_FromUnsignedLong(__pyx_v_sum); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; goto __pyx_L1;} + __pyx_4 = PyLong_FromUnsignedLong(((__pyx_v_sum >> 11) & 3)); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; goto __pyx_L1;} + __pyx_5 = PyObject_GetItem(__pyx_v_key, __pyx_4); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; goto __pyx_L1;} + Py_DECREF(__pyx_4); __pyx_4 = 0; + __pyx_4 = PyNumber_Add(__pyx_3, __pyx_5); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; goto __pyx_L1;} + Py_DECREF(__pyx_3); __pyx_3 = 0; + Py_DECREF(__pyx_5); __pyx_5 = 0; + __pyx_3 = PyNumber_Xor(__pyx_2, __pyx_4); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + Py_DECREF(__pyx_4); __pyx_4 = 0; + __pyx_5 = PyNumber_Subtract(__pyx_1, __pyx_3); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + Py_DECREF(__pyx_3); __pyx_3 = 0; + __pyx_6 = PyInt_AsUnsignedLongMask(__pyx_5); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 32; goto __pyx_L1;} + Py_DECREF(__pyx_5); __pyx_5 = 0; + __pyx_v_v1 = __pyx_6; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":33 */ + __pyx_v_sum = (__pyx_v_sum - __pyx_v_delta); + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":34 */ + __pyx_2 = PyLong_FromUnsignedLong(__pyx_v_v0); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; goto __pyx_L1;} + __pyx_4 = PyLong_FromUnsignedLong((((__pyx_v_v1 << 4) ^ (__pyx_v_v1 >> 5)) + __pyx_v_v1)); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; goto __pyx_L1;} + __pyx_1 = PyLong_FromUnsignedLong(__pyx_v_sum); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; goto __pyx_L1;} + __pyx_3 = PyLong_FromUnsignedLong((__pyx_v_sum & 3)); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; goto __pyx_L1;} + __pyx_5 = PyObject_GetItem(__pyx_v_key, __pyx_3); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; goto __pyx_L1;} + Py_DECREF(__pyx_3); __pyx_3 = 0; + __pyx_3 = PyNumber_Add(__pyx_1, __pyx_5); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; goto __pyx_L1;} + Py_DECREF(__pyx_1); __pyx_1 = 0; + Py_DECREF(__pyx_5); __pyx_5 = 0; + __pyx_1 = PyNumber_Xor(__pyx_4, __pyx_3); if (!__pyx_1) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; goto __pyx_L1;} + Py_DECREF(__pyx_4); __pyx_4 = 0; + Py_DECREF(__pyx_3); __pyx_3 = 0; + __pyx_5 = PyNumber_Subtract(__pyx_2, __pyx_1); if (!__pyx_5) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; goto __pyx_L1;} + Py_DECREF(__pyx_2); __pyx_2 = 0; + Py_DECREF(__pyx_1); __pyx_1 = 0; + __pyx_6 = PyInt_AsUnsignedLongMask(__pyx_5); if (PyErr_Occurred()) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 34; goto __pyx_L1;} + Py_DECREF(__pyx_5); __pyx_5 = 0; + __pyx_v_v0 = __pyx_6; + __pyx_L2:; + } + __pyx_L3:; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":36 */ + __pyx_4 = PyLong_FromUnsignedLong(__pyx_v_v0); if (!__pyx_4) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; goto __pyx_L1;} + __pyx_3 = PyLong_FromUnsignedLong(__pyx_v_v1); if (!__pyx_3) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; goto __pyx_L1;} + __pyx_2 = PyList_New(2); if (!__pyx_2) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 36; goto __pyx_L1;} + PyList_SET_ITEM(__pyx_2, 0, __pyx_4); + PyList_SET_ITEM(__pyx_2, 1, __pyx_3); + __pyx_4 = 0; + __pyx_3 = 0; + Py_DECREF(__pyx_v_result); + __pyx_v_result = __pyx_2; + __pyx_2 = 0; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":37 */ + Py_INCREF(__pyx_v_result); + __pyx_r = __pyx_v_result; + goto __pyx_L0; + + __pyx_r = Py_None; Py_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1:; + Py_XDECREF(__pyx_1); + Py_XDECREF(__pyx_2); + Py_XDECREF(__pyx_3); + Py_XDECREF(__pyx_4); + Py_XDECREF(__pyx_5); + __Pyx_AddTraceback("_xtea._xtea_decryptQuad"); + __pyx_r = 0; + __pyx_L0:; + Py_DECREF(__pyx_v_result); + Py_DECREF(__pyx_v_key); + return __pyx_r; +} + +static __Pyx_InternTabEntry __pyx_intern_tab[] = { + {&__pyx_n__xtea_decryptQuad, "_xtea_decryptQuad"}, + {&__pyx_n__xtea_encryptQuad, "_xtea_encryptQuad"}, + {0, 0} +}; + +static struct PyMethodDef __pyx_methods[] = { + {"_xtea_encryptQuad", (PyCFunction)__pyx_f_5_xtea__xtea_encryptQuad, METH_VARARGS|METH_KEYWORDS, 0}, + {"_xtea_decryptQuad", (PyCFunction)__pyx_f_5_xtea__xtea_decryptQuad, METH_VARARGS|METH_KEYWORDS, 0}, + {0, 0, 0, 0} +}; + +static void __pyx_init_filenames(void); /*proto*/ + +PyMODINIT_FUNC init_xtea(void); /*proto*/ +PyMODINIT_FUNC init_xtea(void) { + __pyx_init_filenames(); + __pyx_m = Py_InitModule4("_xtea", __pyx_methods, 0, 0, PYTHON_API_VERSION); + if (!__pyx_m) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 5; goto __pyx_L1;}; + __pyx_b = PyImport_AddModule("__builtin__"); + if (!__pyx_b) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 5; goto __pyx_L1;}; + if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 5; goto __pyx_L1;}; + if (__Pyx_InternStrings(__pyx_intern_tab) < 0) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 5; goto __pyx_L1;}; + + /* "/home/heimes/dev/pymoul/xtea/src/xtea/_xtea.pyx":23 */ + return; + __pyx_L1:; + __Pyx_AddTraceback("_xtea"); +} + +static char *__pyx_filenames[] = { + "_xtea.pyx", +}; + +/* Runtime support code */ + +static void __pyx_init_filenames(void) { + __pyx_f = __pyx_filenames; +} + +static int __Pyx_InternStrings(__Pyx_InternTabEntry *t) { + while (t->p) { + *t->p = PyString_InternFromString(t->s); + if (!*t->p) + return -1; + ++t; + } + return 0; +} + +#include "compile.h" +#include "frameobject.h" +#include "traceback.h" + +static void __Pyx_AddTraceback(char *funcname) { + PyObject *py_srcfile = 0; + PyObject *py_funcname = 0; + PyObject *py_globals = 0; + PyObject *empty_tuple = 0; + PyObject *empty_string = 0; + PyCodeObject *py_code = 0; + PyFrameObject *py_frame = 0; + + py_srcfile = PyString_FromString(__pyx_filename); + if (!py_srcfile) goto bad; + py_funcname = PyString_FromString(funcname); + if (!py_funcname) goto bad; + py_globals = PyModule_GetDict(__pyx_m); + if (!py_globals) goto bad; + empty_tuple = PyTuple_New(0); + if (!empty_tuple) goto bad; + empty_string = PyString_FromString(""); + if (!empty_string) goto bad; + py_code = PyCode_New( + 0, /*int argcount,*/ + 0, /*int nlocals,*/ + 0, /*int stacksize,*/ + 0, /*int flags,*/ + empty_string, /*PyObject *code,*/ + empty_tuple, /*PyObject *consts,*/ + empty_tuple, /*PyObject *names,*/ + empty_tuple, /*PyObject *varnames,*/ + empty_tuple, /*PyObject *freevars,*/ + empty_tuple, /*PyObject *cellvars,*/ + py_srcfile, /*PyObject *filename,*/ + py_funcname, /*PyObject *name,*/ + __pyx_lineno, /*int firstlineno,*/ + empty_string /*PyObject *lnotab*/ + ); + if (!py_code) goto bad; + py_frame = PyFrame_New( + PyThreadState_Get(), /*PyThreadState *tstate,*/ + py_code, /*PyCodeObject *code,*/ + py_globals, /*PyObject *globals,*/ + 0 /*PyObject *locals*/ + ); + if (!py_frame) goto bad; + py_frame->f_lineno = __pyx_lineno; + PyTraceBack_Here(py_frame); +bad: + Py_XDECREF(py_srcfile); + Py_XDECREF(py_funcname); + Py_XDECREF(empty_tuple); + Py_XDECREF(empty_string); + Py_XDECREF(py_code); + Py_XDECREF(py_frame); +} Property changes on: xtea/trunk/src/xtea/_xtea.c ___________________________________________________________________ Name: svn:eol-style + native Added: xtea/trunk/src/xtea/_xtea.pyx =================================================================== --- xtea/trunk/src/xtea/_xtea.pyx (rev 0) +++ xtea/trunk/src/xtea/_xtea.pyx 2007-02-28 01:42:12 UTC (rev 211) @@ -0,0 +1,37 @@ +# Copyright (C) 2007 Christian Heimes <christian (at) cheimes (dot) de> +# pyrexc optimized version +# License: Public Domain + +ctypedef unsigned long ULong + +def _xtea_encryptQuad(ULong v0, ULong v1, key, int rounds): + cdef int i + cdef ULong delta, sum + + delta=0x9E3779B9 + sum=0 + result = [] + + for i from 0 <= i < rounds: + v0 = v0 + (((v1<<4 ^ v1>>5) + v1) ^ (sum + key[sum & 3])) + sum = sum + delta + v1 = v1 + (((v0<<4 ^ v0>>5) + v0) ^ (sum + key[sum>>11 & 3])) + + result = [v0, v1] + return result + +def _xtea_decryptQuad(ULong v0, ULong v1, key, int rounds): + cdef int i + cdef ULong delta, sum + + delta=0x9E3779B9 + sum=delta*rounds + result = [] + + for i from 0 <= i < rounds: + v1 = v1 - (((v0<<4 ^ v0>>5) + v0) ^ (sum + key[sum>>11 & 3])) + sum = sum - delta + v0 = v0 - (((v1<<4 ^ v1>>5) + v1) ^ (sum + key[sum & 3])) + + result = [v0, v1] + return result Added: xtea/trunk/src/xtea/xtea.py =================================================================== --- xtea/trunk/src/xtea/xtea.py (rev 0) +++ xtea/trunk/src/xtea/xtea.py 2007-02-28 01:42:12 UTC (rev 211) @@ -0,0 +1,170 @@ +""" +XTEA Block Encryption Algorithm + +Author: Paul Chakravarti (paul_dot_chakravarti_at_mac_dot_com) +License: Public Domain + +This module provides a Python implementation of the XTEA block encryption +algorithm (http://www.cix.co.uk/~klockstone/xtea.pdf). + +The module implements the basic XTEA block encryption algortithm +(`xtea_encrypt`/`xtea_decrypt`) and also provides a higher level `crypt` +function which symmetrically encrypts/decrypts a variable length string using +XTEA in OFB mode as a key generator. The `crypt` function does not use +`xtea_decrypt` which is provided for completeness only (but can be used +to support other stream modes - eg CBC/CFB). + +This module is intended to provide a simple 'privacy-grade' Python encryption +algorithm with no external dependencies. The implementation is relatively slow +and is best suited to small volumes of data. Note that the XTEA algorithm has +not been subjected to extensive analysis (though is believed to be relatively +secure - see http://en.wikipedia.org/wiki/XTEA). For applications requiring +'real' security please use a known and well tested algorithm/implementation. + +The security of the algorithm is entirely based on quality (entropy) and +secrecy of the key. You should generate the key from a known random source and +exchange using a trusted mechanism. In addition, you should always use a random +IV to seed the key generator (the IV is not sensitive and does not need to be +exchanged securely) + + >>> import os + >>> iv = 'ABCDEFGH' + >>> z = crypt('0123456789012345','Hello There',iv) + >>> z.encode('hex') + 'fe196d0a40d6c222b9eff3' + >>> crypt('0123456789012345',z,iv) + 'Hello There' + +""" + +import struct + +def crypt(key, data, iv='\00\00\00\00\00\00\00\00', n=32): + """ + Encrypt/decrypt variable length string using XTEA cypher as + key generator (OFB mode) + * key = 128 bit (16 char) + * iv = 64 bit (8 char) + * data = string (any length) + + >>> import os + >>> key = os.urandom(16) + >>> iv = os.urandom(8) + >>> data = os.urandom(10000) + >>> z = crypt(key,data,iv) + >>> crypt(key,z,iv) == data + True + + """ + def keygen(key, iv, n): + while True: + iv = xtea_encrypt(key, iv, n) + for k in iv: + yield ord(k) + xor = [ chr(x^y) for (x, y) in zip(map(ord, data), keygen(key, iv, n)) ] + return "".join(xor) + +def xtea_encrypt(key, block, rounds=32, endian="!"): + """ + Encrypt 64 bit data block using XTEA block cypher + * key = 128 bit (16 char) + * block = 64 bit (8 char) + * n = rounds (default 32) + * endian = byte order (see 'struct' doc - default big/network) + + >>> z = xtea_encrypt('0123456789012345','ABCDEFGH') + >>> z.encode('hex') + 'b67c01662ff6964a' + + Only need to change byte order if sending/receiving from + alternative endian implementation + + >>> z = xtea_encrypt('0123456789012345','ABCDEFGH',endian="<") + >>> z.encode('hex') + 'ea0c3d7c1c22557f' + + """ + v0,v1 = struct.unpack(endian+"2L", block) + k = struct.unpack(endian+"4L", key) + v0, v1 = xtea_encryptQuad(v0, v1, k, rounds) + return struct.pack(endian+"2L", v0, v1) + +def _xtea_encryptQuad(v0, v1, key, rounds=32, delta=0x9e3779b9L, mask=0xffffffffL): + """Encrypt a quad + + @param v0: value 0 + @type v0: int (unsigned long 32) + @param v1: value 1 + @type v1: int (unsigned long 32) + @param key: decryption key + @type key: list[4] int + @param n: rounds + @type n: int + @return: decrypted values + @rtype: list[2] int + """ + sum = 0 + for round in range(rounds): + v0 = (v0 + (((v1<<4 ^ v1>>5) + v1) ^ (sum + key[sum & 3]))) & mask + sum = (sum + delta) & mask + v1 = (v1 + (((v0<<4 ^ v0>>5) + v0) ^ (sum + key[sum>>11 & 3]))) & mask + return v0, v1 + +def xtea_decrypt(key, block, rounds=32, endian="!"): + """ + Decrypt 64 bit data block using XTEA block cypher + * key = 128 bit (16 char) + * block = 64 bit (8 char) + * n = rounds (default 32) + * endian = byte order (see 'struct' doc - default big/network) + + >>> z = 'b67c01662ff6964a'.decode('hex') + >>> xtea_decrypt('0123456789012345',z) + 'ABCDEFGH' + + Only need to change byte order if sending/receiving from + alternative endian implementation + + >>> z = 'ea0c3d7c1c22557f'.decode('hex') + >>> xtea_decrypt('0123456789012345',z,endian="<") + 'ABCDEFGH' + + """ + v0, v1 = struct.unpack(endian+"2L", block) + k = struct.unpack(endian+"4L", key) + v0, v1 = xtea_decryptQuad(v0, v1, k, rounds) + return struct.pack(endian+"2L", v0, v1) + +def _xtea_decryptQuad(v0, v1, key, rounds=32, delta=0x9e3779b9L, mask=0xffffffffL): + """Decrypt a quad + + @param v0: value 0 + @type v0: int (unsigned long 32) + @param v1: value 1 + @type v1: int (unsigned long 32) + @param key: decryption key + @type key: list[4] int + @param rounds: rounds + @type rounds: int + @return: decrypted values + @rtype: list[2] int + """ + sum = (delta * rounds) & mask + for round in range(rounds): + v1 = (v1 - (((v0<<4 ^ v0>>5) + v0) ^ (sum + key[sum>>11 & 3]))) & mask + sum = (sum - delta) & mask + v0 = (v0 - (((v1<<4 ^ v1>>5) + v1) ^ (sum + key[sum & 3]))) & mask + return v0, v1 + +# Try to replace core functions with optimized versions +try: + #raise ImportError + from _xtea import encipher as xtea_encryptQuad + from _xtea import decipher as xtea_decryptQuad +except ImportError, msg: + xtea_encryptQuad = _xtea_encryptQuad + xtea_decryptQuad = _xtea_decryptQuad + +if __name__ == "__main__": + import doctest + doctest.testmod() Property changes on: xtea/trunk/src/xtea/xtea.py ___________________________________________________________________ Name: svn:keywords + 'Id Revision' Name: svn:eol-style + native Modified: xtea/trunk/src/xtea.egg-info/SOURCES.txt =================================================================== --- xtea/trunk/src/xtea.egg-info/SOURCES.txt 2007-02-27 16:22:39 UTC (rev 210) +++ xtea/trunk/src/xtea.egg-info/SOURCES.txt 2007-02-28 01:42:12 UTC (rev 211) @@ -7,9 +7,13 @@ ez_setup.py setup.py version.txt -src/xtea.py +src/xtea/__init__.py +src/xtea/_xtea.c +src/xtea/tests.py +src/xtea/xtea.py src/xtea.egg-info/PKG-INFO src/xtea.egg-info/SOURCES.txt src/xtea.egg-info/dependency_links.txt +src/xtea.egg-info/native_libs.txt src/xtea.egg-info/top_level.txt src/xtea.egg-info/zip-safe Added: xtea/trunk/src/xtea.egg-info/native_libs.txt =================================================================== --- xtea/trunk/src/xtea.egg-info/native_libs.txt (rev 0) +++ xtea/trunk/src/xtea.egg-info/native_libs.txt 2007-02-28 01:42:12 UTC (rev 211) @@ -0,0 +1 @@ +xtea/_xtea.so Property changes on: xtea/trunk/src/xtea.egg-info/native_libs.txt ___________________________________________________________________ Name: svn:keywords + 'Id Revision' Name: svn:eol-style + native Deleted: xtea/trunk/src/xtea.py =================================================================== --- xtea/trunk/src/xtea.py 2007-02-27 16:22:39 UTC (rev 210) +++ xtea/trunk/src/xtea.py 2007-02-28 01:42:12 UTC (rev 211) @@ -1,128 +0,0 @@ -""" -XTEA Block Encryption Algorithm - -Author: Paul Chakravarti (paul_dot_chakravarti_at_mac_dot_com) -License: Public Domain - -This module provides a Python implementation of the XTEA block encryption -algorithm (http://www.cix.co.uk/~klockstone/xtea.pdf). - -The module implements the basic XTEA block encryption algortithm -(`xtea_encrypt`/`xtea_decrypt`) and also provides a higher level `crypt` -function which symmetrically encrypts/decrypts a variable length string using -XTEA in OFB mode as a key generator. The `crypt` function does not use -`xtea_decrypt` which is provided for completeness only (but can be used -to support other stream modes - eg CBC/CFB). - -This module is intended to provide a simple 'privacy-grade' Python encryption -algorithm with no external dependencies. The implementation is relatively slow -and is best suited to small volumes of data. Note that the XTEA algorithm has -not been subjected to extensive analysis (though is believed to be relatively -secure - see http://en.wikipedia.org/wiki/XTEA). For applications requiring -'real' security please use a known and well tested algorithm/implementation. - -The security of the algorithm is entirely based on quality (entropy) and -secrecy of the key. You should generate the key from a known random source and -exchange using a trusted mechanism. In addition, you should always use a random -IV to seed the key generator (the IV is not sensitive and does not need to be -exchanged securely) - - >>> import os - >>> iv = 'ABCDEFGH' - >>> z = crypt('0123456789012345','Hello There',iv) - >>> z.encode('hex') - 'fe196d0a40d6c222b9eff3' - >>> crypt('0123456789012345',z,iv) - 'Hello There' - -""" - -import struct - -def crypt(key,data,iv='\00\00\00\00\00\00\00\00',n=32): - """ - Encrypt/decrypt variable length string using XTEA cypher as - key generator (OFB mode) - * key = 128 bit (16 char) - * iv = 64 bit (8 char) - * data = string (any length) - - >>> import os - >>> key = os.urandom(16) - >>> iv = os.urandom(8) - >>> data = os.urandom(10000) - >>> z = crypt(key,data,iv) - >>> crypt(key,z,iv) == data - True - - """ - def keygen(key,iv,n): - while True: - iv = xtea_encrypt(key,iv,n) - for k in iv: - yield ord(k) - xor = [ chr(x^y) for (x,y) in zip(map(ord,data),keygen(key,iv,n)) ] - return "".join(xor) - -def xtea_encrypt(key,block,n=32,endian="!"): - """ - Encrypt 64 bit data block using XTEA block cypher - * key = 128 bit (16 char) - * block = 64 bit (8 char) - * n = rounds (default 32) - * endian = byte order (see 'struct' doc - default big/network) - - >>> z = xtea_encrypt('0123456789012345','ABCDEFGH') - >>> z.encode('hex') - 'b67c01662ff6964a' - - Only need to change byte order if sending/receiving from - alternative endian implementation - - >>> z = xtea_encrypt('0123456789012345','ABCDEFGH',endian="<") - >>> z.encode('hex') - 'ea0c3d7c1c22557f' - - """ - v0,v1 = struct.unpack(endian+"2L",block) - k = struct.unpack(endian+"4L",key) - sum,delta,mask = 0L,0x9e3779b9L,0xffffffffL - for round in range(n): - v0 = (v0 + (((v1<<4 ^ v1>>5) + v1) ^ (sum + k[sum & 3]))) & mask - sum = (sum + delta) & mask - v1 = (v1 + (((v0<<4 ^ v0>>5) + v0) ^ (sum + k[sum>>11 & 3]))) & mask - return struct.pack(endian+"2L",v0,v1) - -def xtea_decrypt(key,block,n=32,endian="!"): - """ - Decrypt 64 bit data block using XTEA block cypher - * key = 128 bit (16 char) - * block = 64 bit (8 char) - * n = rounds (default 32) - * endian = byte order (see 'struct' doc - default big/network) - - >>> z = 'b67c01662ff6964a'.decode('hex') - >>> xtea_decrypt('0123456789012345',z) - 'ABCDEFGH' - - Only need to change byte order if sending/receiving from - alternative endian implementation - - >>> z = 'ea0c3d7c1c22557f'.decode('hex') - >>> xtea_decrypt('0123456789012345',z,endian="<") - 'ABCDEFGH' - - """ - v0,v1 = struct.unpack(endian+"2L",block) - k = struct.unpack(endian+"4L",key) - delta,mask = 0x9e3779b9L,0xffffffffL - sum = (delta * n) & mask - for round in range(n): - v1 = (v1 - (((v0<<4 ^ v0>>5) + v0) ^ (sum + k[sum>>11 & 3]))) & mask - sum = (sum - delta) & mask - v0 = (v0 - (((v1<<4 ^ v1>>5) + v1) ^ (sum + k[sum & 3]))) & mask - return struct.pack(endian+"2L",v0,v1) - -if __name__ == "__main__": - import doctest - doctest.testmod() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ti...@us...> - 2007-02-27 16:22:45
|
Revision: 210 http://pymoul.svn.sourceforge.net/pymoul/?rev=210&view=rev Author: tiran Date: 2007-02-27 08:22:39 -0800 (Tue, 27 Feb 2007) Log Message: ----------- Initial import of xtea module Added Paths: ----------- xtea/ xtea/branches/ xtea/tags/ xtea/trunk/ xtea/trunk/CHANGES.txt xtea/trunk/INSTALL.txt xtea/trunk/LICENSE.txt xtea/trunk/MANIFEST.in xtea/trunk/Makefile xtea/trunk/README.txt xtea/trunk/ez_setup.py xtea/trunk/setup.py xtea/trunk/src/ xtea/trunk/src/xtea.egg-info/ xtea/trunk/src/xtea.egg-info/PKG-INFO xtea/trunk/src/xtea.egg-info/SOURCES.txt xtea/trunk/src/xtea.egg-info/dependency_links.txt xtea/trunk/src/xtea.egg-info/top_level.txt xtea/trunk/src/xtea.egg-info/zip-safe xtea/trunk/src/xtea.py xtea/trunk/version.txt Added: xtea/trunk/CHANGES.txt =================================================================== Property changes on: xtea/trunk/CHANGES.txt ___________________________________________________________________ Name: svn:keywords + 'Id Revision' Name: svn:eol-style + native Added: xtea/trunk/INSTALL.txt =================================================================== --- xtea/trunk/INSTALL.txt (rev 0) +++ xtea/trunk/INSTALL.txt 2007-02-27 16:22:39 UTC (rev 210) @@ -0,0 +1,13 @@ +============ +Requirements +============ + + * Python 2.4+ http://www.python.org/ + * easy_install http://peak.telecommunity.com/DevCenter/EasyInstall + * setuptools (via easy install) + +============ +Installation +============ + + $ python setup.py install Property changes on: xtea/trunk/INSTALL.txt ___________________________________________________________________ Name: svn:keywords + 'Id Revision' Name: svn:eol-style + native Added: xtea/trunk/LICENSE.txt =================================================================== --- xtea/trunk/LICENSE.txt (rev 0) +++ xtea/trunk/LICENSE.txt 2007-02-27 16:22:39 UTC (rev 210) @@ -0,0 +1 @@ +Public Domain \ No newline at end of file Property changes on: xtea/trunk/LICENSE.txt ___________________________________________________________________ Name: svn:keywords + 'Id Revision' Name: svn:eol-style + native Added: xtea/trunk/MANIFEST.in =================================================================== --- xtea/trunk/MANIFEST.in (rev 0) +++ xtea/trunk/MANIFEST.in 2007-02-27 16:22:39 UTC (rev 210) @@ -0,0 +1,4 @@ +include *.txt setup.py ez_setup.py Makefile +include src/xtea.py + + Added: xtea/trunk/Makefile =================================================================== --- xtea/trunk/Makefile (rev 0) +++ xtea/trunk/Makefile 2007-02-27 16:22:39 UTC (rev 210) @@ -0,0 +1,54 @@ +PYTHON?=python2.5 +PYTHON24=python2.4 +PYTHON25=python2.5 +TESTFLAGS=-v +TESTOPTS= +SETUPFLAGS= +KEYID=AD16AB1B + +all: inplace + +# Build in-place +inplace: + $(PYTHON) setup.py $(SETUPFLAGS) build_ext -i + +build: + $(PYTHON) setup.py $(SETUPFLAGS) build + +egg24: + $(PYTHON24) setup.py $(SETUPFLAGS) bdist_egg + +egg25: + $(PYTHON25) setup.py $(SETUPFLAGS) bdist_egg + +dist25: + $(PYTHON25) setup.py $(SETUPFLAGS) bdist_egg \ + sdist --formats=zip,gztar + +dist_upload: realclean + $(PYTHON25) setup.py $(SETUPFLAGS) bdist_egg \ + sdist --formats=zip,gztar \ + upload --sign --identity=$(KEYID) + +# What should the default be? +test: + $(PYTHON) xtea.py + +egg: egg24 egg25 + +distribution: realclean dist25 egg24 gpg + +gpg: + for F in `find dist -type f -and -not -name '*.asc'`; do \ + gpg --detach-sign --armor --default-key $(KEYID) $$F; \ + done + md5sum dist/*.zip dist/*.egg dist/*.gz + +clean: + find . \( -name '*.o' -o -name '*~' -o -name '*.so' -o -name '*.py[cod]' -o -name '*.dll' \) -exec rm -f {} \; + rm -rf build + +realclean: clean + rm -f TAGS + rm -rf dist + $(PYTHON) setup.py clean -a Property changes on: xtea/trunk/Makefile ___________________________________________________________________ Name: svn:keywords + 'Id Revision' Name: svn:eol-style + native Added: xtea/trunk/README.txt =================================================================== --- xtea/trunk/README.txt (rev 0) +++ xtea/trunk/README.txt 2007-02-27 16:22:39 UTC (rev 210) @@ -0,0 +1,28 @@ +XTEA Block Encryption Algorithm + +Author: Paul Chakravarti (paul_dot_chakravarti_at_mac_dot_com) +License: Public Domain + +This module provides a Python implementation of the XTEA block encryption +algorithm (http://www.cix.co.uk/~klockstone/xtea.pdf). + +The module implements the basic XTEA block encryption algortithm +(`xtea_encrypt`/`xtea_decrypt`) and also provides a higher level `crypt` +function which symmetrically encrypts/decrypts a variable length string using +XTEA in OFB mode as a key generator. The `crypt` function does not use +`xtea_decrypt` which is provided for completeness only (but can be used +to support other stream modes - eg CBC/CFB). + +This module is intended to provide a simple 'privacy-grade' Python encryption +algorithm with no external dependencies. The implementation is relatively slow +and is best suited to small volumes of data. Note that the XTEA algorithm has +not been subjected to extensive analysis (though is believed to be relatively +secure - see http://en.wikipedia.org/wiki/XTEA). For applications requiring +'real' security please use a known and well tested algorithm/implementation. + +The security of the algorithm is entirely based on quality (entropy) and +secrecy of the key. You should generate the key from a known random source and +exchange using a trusted mechanism. In addition, you should always use a random +IV to seed the key generator (the IV is not sensitive and does not need to be +exchanged securely) + Property changes on: xtea/trunk/README.txt ___________________________________________________________________ Name: svn:keywords + 'Id Revision' Name: svn:eol-style + native Added: xtea/trunk/ez_setup.py =================================================================== --- xtea/trunk/ez_setup.py (rev 0) +++ xtea/trunk/ez_setup.py 2007-02-27 16:22:39 UTC (rev 210) @@ -0,0 +1,228 @@ +#!python +"""Bootstrap setuptools installation + +If you want to use setuptools in your package's setup.py, just include this +file in the same directory with it, and add this to the top of your setup.py:: + + from ez_setup import use_setuptools + use_setuptools() + +If you want to require a specific version of setuptools, set a download +mirror, or use an alternate download directory, you can do so by supplying +the appropriate options to ``use_setuptools()``. + +This file can also be run as a script to install or upgrade setuptools. +""" +import sys +DEFAULT_VERSION = "0.6c5" +DEFAULT_URL = "http://cheeseshop.python.org/packages/%s/s/setuptools/" % sys.version[:3] + +md5_data = { + 'setuptools-0.6b1-py2.3.egg': '8822caf901250d848b996b7f25c6e6ca', + 'setuptools-0.6b1-py2.4.egg': 'b79a8a403e4502fbb85ee3f1941735cb', + 'setuptools-0.6b2-py2.3.egg': '5657759d8a6d8fc44070a9d07272d99b', + 'setuptools-0.6b2-py2.4.egg': '4996a8d169d2be661fa32a6e52e4f82a', + 'setuptools-0.6b3-py2.3.egg': 'bb31c0fc7399a63579975cad9f5a0618', + 'setuptools-0.6b3-py2.4.egg': '38a8c6b3d6ecd22247f179f7da669fac', + 'setuptools-0.6b4-py2.3.egg': '62045a24ed4e1ebc77fe039aa4e6f7e5', + 'setuptools-0.6b4-py2.4.egg': '4cb2a185d228dacffb2d17f103b3b1c4', + 'setuptools-0.6c1-py2.3.egg': 'b3f2b5539d65cb7f74ad79127f1a908c', + 'setuptools-0.6c1-py2.4.egg': 'b45adeda0667d2d2ffe14009364f2a4b', + 'setuptools-0.6c2-py2.3.egg': 'f0064bf6aa2b7d0f3ba0b43f20817c27', + 'setuptools-0.6c2-py2.4.egg': '616192eec35f47e8ea16cd6a122b7277', + 'setuptools-0.6c3-py2.3.egg': 'f181fa125dfe85a259c9cd6f1d7b78fa', + 'setuptools-0.6c3-py2.4.egg': 'e0ed74682c998bfb73bf803a50e7b71e', + 'setuptools-0.6c3-py2.5.egg': 'abef16fdd61955514841c7c6bd98965e', + 'setuptools-0.6c4-py2.3.egg': 'b0b9131acab32022bfac7f44c5d7971f', + 'setuptools-0.6c4-py2.4.egg': '2a1f9656d4fbf3c97bf946c0a124e6e2', + 'setuptools-0.6c4-py2.5.egg': '8f5a052e32cdb9c72bcf4b5526f28afc', + 'setuptools-0.6c5-py2.3.egg': 'ee9fd80965da04f2f3e6b3576e9d8167', + 'setuptools-0.6c5-py2.4.egg': 'afe2adf1c01701ee841761f5bcd8aa64', + 'setuptools-0.6c5-py2.5.egg': 'a8d3f61494ccaa8714dfed37bccd3d5d', +} + +import sys, os + +def _validate_md5(egg_name, data): + if egg_name in md5_data: + from md5 import md5 + digest = md5(data).hexdigest() + if digest != md5_data[egg_name]: + print >>sys.stderr, ( + "md5 validation of %s failed! (Possible download problem?)" + % egg_name + ) + sys.exit(2) + return data + + +def use_setuptools( + version=DEFAULT_VERSION, download_base=DEFAULT_URL, to_dir=os.curdir, + download_delay=15 +): + """Automatically find/download setuptools and make it available on sys.path + + `version` should be a valid setuptools version number that is available + as an egg for download under the `download_base` URL (which should end with + a '/'). `to_dir` is the directory where setuptools will be downloaded, if + it is not already available. If `download_delay` is specified, it should + be the number of seconds that will be paused before initiating a download, + should one be required. If an older version of setuptools is installed, + this routine will print a message to ``sys.stderr`` and raise SystemExit in + an attempt to abort the calling script. + """ + try: + import setuptools + if setuptools.__version__ == '0.0.1': + print >>sys.stderr, ( + "You have an obsolete version of setuptools installed. Please\n" + "remove it from your system entirely before rerunning this script." + ) + sys.exit(2) + except ImportError: + egg = download_setuptools(version, download_base, to_dir, download_delay) + sys.path.insert(0, egg) + import setuptools; setuptools.bootstrap_install_from = egg + + import pkg_resources + try: + pkg_resources.require("setuptools>="+version) + + except pkg_resources.VersionConflict, e: + # XXX could we install in a subprocess here? + print >>sys.stderr, ( + "The required version of setuptools (>=%s) is not available, and\n" + "can't be installed while this script is running. Please install\n" + " a more recent version first.\n\n(Currently using %r)" + ) % (version, e.args[0]) + sys.exit(2) + +def download_setuptools( + version=DEFAULT_VERSION, download_base=DEFAULT_URL, to_dir=os.curdir, + delay = 15 +): + """Download setuptools from a specified location and return its filename + + `version` should be a valid setuptools version number that is available + as an egg for download under the `download_base` URL (which should end + with a '/'). `to_dir` is the directory where the egg will be downloaded. + `delay` is the number of seconds to pause before an actual download attempt. + """ + import urllib2, shutil + egg_name = "setuptools-%s-py%s.egg" % (version,sys.version[:3]) + url = download_base + egg_name + saveto = os.path.join(to_dir, egg_name) + src = dst = None + if not os.path.exists(saveto): # Avoid repeated downloads + try: + from distutils import log + if delay: + log.warn(""" +--------------------------------------------------------------------------- +This script requires setuptools version %s to run (even to display +help). I will attempt to download it for you (from +%s), but +you may need to enable firewall access for this script first. +I will start the download in %d seconds. + +(Note: if this machine does not have network access, please obtain the file + + %s + +and place it in this directory before rerunning this script.) +---------------------------------------------------------------------------""", + version, download_base, delay, url + ); from time import sleep; sleep(delay) + log.warn("Downloading %s", url) + src = urllib2.urlopen(url) + # Read/write all in one block, so we don't create a corrupt file + # if the download is interrupted. + data = _validate_md5(egg_name, src.read()) + dst = open(saveto,"wb"); dst.write(data) + finally: + if src: src.close() + if dst: dst.close() + return os.path.realpath(saveto) + +def main(argv, version=DEFAULT_VERSION): + """Install or upgrade setuptools and EasyInstall""" + + try: + import setuptools + except ImportError: + egg = None + try: + egg = download_setuptools(version, delay=0) + sys.path.insert(0,egg) + from setuptools.command.easy_install import main + return main(list(argv)+[egg]) # we're done here + finally: + if egg and os.path.exists(egg): + os.unlink(egg) + else: + if setuptools.__version__ == '0.0.1': + # tell the user to uninstall obsolete version + use_setuptools(version) + + req = "setuptools>="+version + import pkg_resources + try: + pkg_resources.require(req) + except pkg_resources.VersionConflict: + try: + from setuptools.command.easy_install import main + except ImportError: + from easy_install import main + main(list(argv)+[download_setuptools(delay=0)]) + sys.exit(0) # try to force an exit + else: + if argv: + from setuptools.command.easy_install import main + main(argv) + else: + print "Setuptools version",version,"or greater has been installed." + print '(Run "ez_setup.py -U setuptools" to reinstall or upgrade.)' + + + +def update_md5(filenames): + """Update our built-in md5 registry""" + + import re + from md5 import md5 + + for name in filenames: + base = os.path.basename(name) + f = open(name,'rb') + md5_data[base] = md5(f.read()).hexdigest() + f.close() + + data = [" %r: %r,\n" % it for it in md5_data.items()] + data.sort() + repl = "".join(data) + + import inspect + srcfile = inspect.getsourcefile(sys.modules[__name__]) + f = open(srcfile, 'rb'); src = f.read(); f.close() + + match = re.search("\nmd5_data = {\n([^}]+)}", src) + if not match: + print >>sys.stderr, "Internal error!" + sys.exit(2) + + src = src[:match.start(1)] + repl + src[match.end(1):] + f = open(srcfile,'w') + f.write(src) + f.close() + + +if __name__=='__main__': + if len(sys.argv)>2 and sys.argv[1]=='--md5update': + update_md5(sys.argv[2:]) + else: + main(sys.argv[1:]) + + + + + Property changes on: xtea/trunk/ez_setup.py ___________________________________________________________________ Name: svn:executable + Name: svn:keywords + 'Id Revision' Name: svn:eol-style + native Added: xtea/trunk/setup.py =================================================================== --- xtea/trunk/setup.py (rev 0) +++ xtea/trunk/setup.py 2007-02-27 16:22:39 UTC (rev 210) @@ -0,0 +1,71 @@ +#!/usr/bin/env python +"""XTEA Block Encryption Algorithm + +This module provides a Python implementation of the XTEA block encryption +algorithm (http://www.cix.co.uk/~klockstone/xtea.pdf). + +The module implements the basic XTEA block encryption algortithm +(`xtea_encrypt`/`xtea_decrypt`) and also provides a higher level `crypt` +function which symmetrically encrypts/decrypts a variable length string using +XTEA in OFB mode as a key generator. The `crypt` function does not use +`xtea_decrypt` which is provided for completeness only (but can be used +to support other stream modes - eg CBC/CFB). +""" +__author__ = "Christian Heimes" +__version__ = "$Id: setup.py 203 2007-02-27 14:31:27Z tiran $" +__revision__ = "$Revision: 203 $" + +import sys + +if sys.version_info < (2,4): + raise RuntimeError("Python 2.4+ required:\n%s" % sys.version) + +# boot strap easy setup +SETUPTOOLS_VERSION = "0.6c1" +from ez_setup import use_setuptools +use_setuptools(version=SETUPTOOLS_VERSION) + +# import the rest +from setuptools import setup +from setuptools import find_packages + +from distutils.core import setup + +VERSION = "1.0" + +me = "Christian Heimes" +email = "chr...@ch..." + +setup_infos = dict( + name = "xtea", + version = VERSION, + description = __doc__[:__doc__.find('\n')].strip(), + long_description = '\n'.join([line + for line in __doc__.split('\n')[1:]]), + author = "Paul Chakravarti", + author_email = "paul_dot_chakravarti_at_mac_dot_com", + maintainer = "Christian Heimes", + maintainer_email = "chr...@ch...", + url = "http://sourceforge.net/projects/pymoul/", + download_url= "http://cheeseshop.python.org/pypi/", + license = "Public Domain", + keywords = ["xtea", "crypt", "encryption", "decryption"], + platforms = ['Independent'], + classifiers = ( + 'Development Status :: 6 - Mature', + 'Intended Audience :: Developers', + 'License :: Public Domain', + 'Operating System :: OS Independent' + 'Natural Language :: English', + 'Programming Language :: Python', + 'Topic :: Software Development :: Libraries' + ), + setup_requires = ["setuptools>="+SETUPTOOLS_VERSION,], + #packages = ['xtea'], + py_modules = ['xtea'], + package_dir = {'' : 'src'}, + zip_safe = True, +) + +setup(**setup_infos) + Property changes on: xtea/trunk/setup.py ___________________________________________________________________ Name: svn:executable + Name: svn:keywords + 'Id Revision' Name: svn:eol-style + native Added: xtea/trunk/src/xtea.egg-info/PKG-INFO =================================================================== --- xtea/trunk/src/xtea.egg-info/PKG-INFO (rev 0) +++ xtea/trunk/src/xtea.egg-info/PKG-INFO 2007-02-27 16:22:39 UTC (rev 210) @@ -0,0 +1,28 @@ +Metadata-Version: 1.0 +Name: xtea +Version: 1.0 +Summary: XTEA Block Encryption Algorithm +Home-page: http://sourceforge.net/projects/pymoul/ +Author: Christian Heimes +Author-email: chr...@ch... +License: Public Domain +Download-URL: http://cheeseshop.python.org/pypi/ +Description: + This module provides a Python implementation of the XTEA block encryption + algorithm (http://www.cix.co.uk/~klockstone/xtea.pdf). + + The module implements the basic XTEA block encryption algortithm + (`xtea_encrypt`/`xtea_decrypt`) and also provides a higher level `crypt` + function which symmetrically encrypts/decrypts a variable length string using + XTEA in OFB mode as a key generator. The `crypt` function does not use + `xtea_decrypt` which is provided for completeness only (but can be used + to support other stream modes - eg CBC/CFB). + +Keywords: xtea,crypt,encryption,decryption +Platform: Independent +Classifier: Development Status :: 6 - Mature +Classifier: Intended Audience :: Developers +Classifier: License :: Public Domain +Classifier: Operating System :: OS IndependentNatural Language :: English +Classifier: Programming Language :: Python +Classifier: Topic :: Software Development :: Libraries Added: xtea/trunk/src/xtea.egg-info/SOURCES.txt =================================================================== --- xtea/trunk/src/xtea.egg-info/SOURCES.txt (rev 0) +++ xtea/trunk/src/xtea.egg-info/SOURCES.txt 2007-02-27 16:22:39 UTC (rev 210) @@ -0,0 +1,15 @@ +CHANGES.txt +INSTALL.txt +LICENSE.txt +MANIFEST.in +Makefile +README.txt +ez_setup.py +setup.py +version.txt +src/xtea.py +src/xtea.egg-info/PKG-INFO +src/xtea.egg-info/SOURCES.txt +src/xtea.egg-info/dependency_links.txt +src/xtea.egg-info/top_level.txt +src/xtea.egg-info/zip-safe Property changes on: xtea/trunk/src/xtea.egg-info/SOURCES.txt ___________________________________________________________________ Name: svn:keywords + 'Id Revision' Name: svn:eol-style + native Added: xtea/trunk/src/xtea.egg-info/dependency_links.txt =================================================================== --- xtea/trunk/src/xtea.egg-info/dependency_links.txt (rev 0) +++ xtea/trunk/src/xtea.egg-info/dependency_links.txt 2007-02-27 16:22:39 UTC (rev 210) @@ -0,0 +1 @@ + Property changes on: xtea/trunk/src/xtea.egg-info/dependency_links.txt ___________________________________________________________________ Name: svn:keywords + 'Id Revision' Name: svn:eol-style + native Added: xtea/trunk/src/xtea.egg-info/top_level.txt =================================================================== --- xtea/trunk/src/xtea.egg-info/top_level.txt (rev 0) +++ xtea/trunk/src/xtea.egg-info/top_level.txt 2007-02-27 16:22:39 UTC (rev 210) @@ -0,0 +1 @@ +xtea Property changes on: xtea/trunk/src/xtea.egg-info/top_level.txt ___________________________________________________________________ Name: svn:keywords + 'Id Revision' Name: svn:eol-style + native Added: xtea/trunk/src/xtea.egg-info/zip-safe =================================================================== --- xtea/trunk/src/xtea.egg-info/zip-safe (rev 0) +++ xtea/trunk/src/xtea.egg-info/zip-safe 2007-02-27 16:22:39 UTC (rev 210) @@ -0,0 +1 @@ + Added: xtea/trunk/src/xtea.py =================================================================== --- xtea/trunk/src/xtea.py (rev 0) +++ xtea/trunk/src/xtea.py 2007-02-27 16:22:39 UTC (rev 210) @@ -0,0 +1,128 @@ +""" +XTEA Block Encryption Algorithm + +Author: Paul Chakravarti (paul_dot_chakravarti_at_mac_dot_com) +License: Public Domain + +This module provides a Python implementation of the XTEA block encryption +algorithm (http://www.cix.co.uk/~klockstone/xtea.pdf). + +The module implements the basic XTEA block encryption algortithm +(`xtea_encrypt`/`xtea_decrypt`) and also provides a higher level `crypt` +function which symmetrically encrypts/decrypts a variable length string using +XTEA in OFB mode as a key generator. The `crypt` function does not use +`xtea_decrypt` which is provided for completeness only (but can be used +to support other stream modes - eg CBC/CFB). + +This module is intended to provide a simple 'privacy-grade' Python encryption +algorithm with no external dependencies. The implementation is relatively slow +and is best suited to small volumes of data. Note that the XTEA algorithm has +not been subjected to extensive analysis (though is believed to be relatively +secure - see http://en.wikipedia.org/wiki/XTEA). For applications requiring +'real' security please use a known and well tested algorithm/implementation. + +The security of the algorithm is entirely based on quality (entropy) and +secrecy of the key. You should generate the key from a known random source and +exchange using a trusted mechanism. In addition, you should always use a random +IV to seed the key generator (the IV is not sensitive and does not need to be +exchanged securely) + + >>> import os + >>> iv = 'ABCDEFGH' + >>> z = crypt('0123456789012345','Hello There',iv) + >>> z.encode('hex') + 'fe196d0a40d6c222b9eff3' + >>> crypt('0123456789012345',z,iv) + 'Hello There' + +""" + +import struct + +def crypt(key,data,iv='\00\00\00\00\00\00\00\00',n=32): + """ + Encrypt/decrypt variable length string using XTEA cypher as + key generator (OFB mode) + * key = 128 bit (16 char) + * iv = 64 bit (8 char) + * data = string (any length) + + >>> import os + >>> key = os.urandom(16) + >>> iv = os.urandom(8) + >>> data = os.urandom(10000) + >>> z = crypt(key,data,iv) + >>> crypt(key,z,iv) == data + True + + """ + def keygen(key,iv,n): + while True: + iv = xtea_encrypt(key,iv,n) + for k in iv: + yield ord(k) + xor = [ chr(x^y) for (x,y) in zip(map(ord,data),keygen(key,iv,n)) ] + return "".join(xor) + +def xtea_encrypt(key,block,n=32,endian="!"): + """ + Encrypt 64 bit data block using XTEA block cypher + * key = 128 bit (16 char) + * block = 64 bit (8 char) + * n = rounds (default 32) + * endian = byte order (see 'struct' doc - default big/network) + + >>> z = xtea_encrypt('0123456789012345','ABCDEFGH') + >>> z.encode('hex') + 'b67c01662ff6964a' + + Only need to change byte order if sending/receiving from + alternative endian implementation + + >>> z = xtea_encrypt('0123456789012345','ABCDEFGH',endian="<") + >>> z.encode('hex') + 'ea0c3d7c1c22557f' + + """ + v0,v1 = struct.unpack(endian+"2L",block) + k = struct.unpack(endian+"4L",key) + sum,delta,mask = 0L,0x9e3779b9L,0xffffffffL + for round in range(n): + v0 = (v0 + (((v1<<4 ^ v1>>5) + v1) ^ (sum + k[sum & 3]))) & mask + sum = (sum + delta) & mask + v1 = (v1 + (((v0<<4 ^ v0>>5) + v0) ^ (sum + k[sum>>11 & 3]))) & mask + return struct.pack(endian+"2L",v0,v1) + +def xtea_decrypt(key,block,n=32,endian="!"): + """ + Decrypt 64 bit data block using XTEA block cypher + * key = 128 bit (16 char) + * block = 64 bit (8 char) + * n = rounds (default 32) + * endian = byte order (see 'struct' doc - default big/network) + + >>> z = 'b67c01662ff6964a'.decode('hex') + >>> xtea_decrypt('0123456789012345',z) + 'ABCDEFGH' + + Only need to change byte order if sending/receiving from + alternative endian implementation + + >>> z = 'ea0c3d7c1c22557f'.decode('hex') + >>> xtea_decrypt('0123456789012345',z,endian="<") + 'ABCDEFGH' + + """ + v0,v1 = struct.unpack(endian+"2L",block) + k = struct.unpack(endian+"4L",key) + delta,mask = 0x9e3779b9L,0xffffffffL + sum = (delta * n) & mask + for round in range(n): + v1 = (v1 - (((v0<<4 ^ v0>>5) + v0) ^ (sum + k[sum>>11 & 3]))) & mask + sum = (sum - delta) & mask + v0 = (v0 - (((v1<<4 ^ v1>>5) + v1) ^ (sum + k[sum & 3]))) & mask + return struct.pack(endian+"2L",v0,v1) + +if __name__ == "__main__": + import doctest + doctest.testmod() Property changes on: xtea/trunk/src/xtea.py ___________________________________________________________________ Name: svn:keywords + 'Id Revision' Name: svn:eol-style + native Added: xtea/trunk/version.txt =================================================================== --- xtea/trunk/version.txt (rev 0) +++ xtea/trunk/version.txt 2007-02-27 16:22:39 UTC (rev 210) @@ -0,0 +1 @@ +1.0 Property changes on: xtea/trunk/version.txt ___________________________________________________________________ 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. |
From: <ti...@us...> - 2007-02-27 15:56:44
|
Revision: 209 http://pymoul.svn.sourceforge.net/pymoul/?rev=209&view=rev Author: tiran Date: 2007-02-27 07:56:42 -0800 (Tue, 27 Feb 2007) Log Message: ----------- Setup - added PKG-INFO and eggs Modified Paths: -------------- binaryfile/trunk/setup.py Added Paths: ----------- binaryfile/trunk/PKG-INFO binaryfile/trunk/src/binaryfile.egg-info/ binaryfile/trunk/src/binaryfile.egg-info/PKG-INFO binaryfile/trunk/src/binaryfile.egg-info/SOURCES.txt binaryfile/trunk/src/binaryfile.egg-info/dependency_links.txt binaryfile/trunk/src/binaryfile.egg-info/top_level.txt binaryfile/trunk/src/binaryfile.egg-info/zip-safe Property Changed: ---------------- binaryfile/trunk/ Property changes on: binaryfile/trunk ___________________________________________________________________ Name: svn:ignore + build dist Added: binaryfile/trunk/PKG-INFO =================================================================== --- binaryfile/trunk/PKG-INFO (rev 0) +++ binaryfile/trunk/PKG-INFO 2007-02-27 15:56:42 UTC (rev 209) @@ -0,0 +1,19 @@ +Metadata-Version: 1.0 +Name: binaryfile +Version: 0.1 +Summary: Binary file +Home-page: http://sourceforge.net/projects/pymoul/ +Author: Christian Heimes +Author-email: chr...@ch... +License: UNKNOWN +Download-URL: http://cheeseshop.python.org/pypi/ +Description: + TODO + +Platform: Independent +Classifier: Development Status :: 4 - Beta +Classifier: Intended Audience :: Developers +Classifier: License :: OSI Approved :: +Classifier: Operating System :: OS IndependentNatural Language :: English +Classifier: Programming Language :: Python +Classifier: Topic :: Software Development :: Libraries Modified: binaryfile/trunk/setup.py =================================================================== --- binaryfile/trunk/setup.py 2007-02-27 15:49:15 UTC (rev 208) +++ binaryfile/trunk/setup.py 2007-02-27 15:56:42 UTC (rev 209) @@ -1,6 +1,7 @@ #!/usr/bin/env python -""" +"""Binary file +TODO """ __author__ = "Christian Heimes" __version__ = "$Id: setup.py 203 2007-02-27 14:31:27Z tiran $" @@ -28,7 +29,7 @@ email = "chr...@ch..." setup_infos = dict( - name = "", + name = "binaryfile", version = VERSION, description = __doc__[:__doc__.find('\n')].strip(), long_description = '\n'.join([line @@ -41,18 +42,18 @@ download_url= "http://cheeseshop.python.org/pypi/", license = "", keywords = [], - platforms=['Independant'], + platforms = ['Independent'], classifiers = ( 'Development Status :: 4 - Beta', 'Intended Audience :: Developers', 'License :: OSI Approved :: ', - 'Operating System :: ' + 'Operating System :: OS Independent' 'Natural Language :: English', 'Programming Language :: Python', 'Topic :: Software Development :: Libraries' ), setup_requires = ["setuptools>="+SETUPTOOLS_VERSION,], - packages = [], + packages = ['binaryfile'], package_dir = {'' : 'src'}, zip_safe = True, ) Added: binaryfile/trunk/src/binaryfile.egg-info/PKG-INFO =================================================================== --- binaryfile/trunk/src/binaryfile.egg-info/PKG-INFO (rev 0) +++ binaryfile/trunk/src/binaryfile.egg-info/PKG-INFO 2007-02-27 15:56:42 UTC (rev 209) @@ -0,0 +1,19 @@ +Metadata-Version: 1.0 +Name: binaryfile +Version: 0.1 +Summary: Binary file +Home-page: http://sourceforge.net/projects/pymoul/ +Author: Christian Heimes +Author-email: chr...@ch... +License: UNKNOWN +Download-URL: http://cheeseshop.python.org/pypi/ +Description: + TODO + +Platform: Independent +Classifier: Development Status :: 4 - Beta +Classifier: Intended Audience :: Developers +Classifier: License :: OSI Approved :: +Classifier: Operating System :: OS IndependentNatural Language :: English +Classifier: Programming Language :: Python +Classifier: Topic :: Software Development :: Libraries Added: binaryfile/trunk/src/binaryfile.egg-info/SOURCES.txt =================================================================== --- binaryfile/trunk/src/binaryfile.egg-info/SOURCES.txt (rev 0) +++ binaryfile/trunk/src/binaryfile.egg-info/SOURCES.txt 2007-02-27 15:56:42 UTC (rev 209) @@ -0,0 +1,19 @@ +CHANGES.txt +INSTALL.txt +LICENSE.txt +MANIFEST.in +Makefile +PKG-INFO +README.txt +ez_setup.py +setup.py +version.txt +src/binaryfile/__init__.py +src/binaryfile/binary.py +src/binaryfile/binaryrecord.py +src/binaryfile/tests.py +src/binaryfile.egg-info/PKG-INFO +src/binaryfile.egg-info/SOURCES.txt +src/binaryfile.egg-info/dependency_links.txt +src/binaryfile.egg-info/top_level.txt +src/binaryfile.egg-info/zip-safe Property changes on: binaryfile/trunk/src/binaryfile.egg-info/SOURCES.txt ___________________________________________________________________ Name: svn:keywords + 'Id Revision' Name: svn:eol-style + native Added: binaryfile/trunk/src/binaryfile.egg-info/dependency_links.txt =================================================================== --- binaryfile/trunk/src/binaryfile.egg-info/dependency_links.txt (rev 0) +++ binaryfile/trunk/src/binaryfile.egg-info/dependency_links.txt 2007-02-27 15:56:42 UTC (rev 209) @@ -0,0 +1 @@ + Property changes on: binaryfile/trunk/src/binaryfile.egg-info/dependency_links.txt ___________________________________________________________________ Name: svn:keywords + 'Id Revision' Name: svn:eol-style + native Added: binaryfile/trunk/src/binaryfile.egg-info/top_level.txt =================================================================== --- binaryfile/trunk/src/binaryfile.egg-info/top_level.txt (rev 0) +++ binaryfile/trunk/src/binaryfile.egg-info/top_level.txt 2007-02-27 15:56:42 UTC (rev 209) @@ -0,0 +1 @@ +binaryfile Property changes on: binaryfile/trunk/src/binaryfile.egg-info/top_level.txt ___________________________________________________________________ Name: svn:keywords + 'Id Revision' Name: svn:eol-style + native Added: binaryfile/trunk/src/binaryfile.egg-info/zip-safe =================================================================== --- binaryfile/trunk/src/binaryfile.egg-info/zip-safe (rev 0) +++ binaryfile/trunk/src/binaryfile.egg-info/zip-safe 2007-02-27 15:56:42 UTC (rev 209) @@ -0,0 +1 @@ + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ti...@us...> - 2007-02-27 15:49:16
|
Revision: 208 http://pymoul.svn.sourceforge.net/pymoul/?rev=208&view=rev Author: tiran Date: 2007-02-27 07:49:15 -0800 (Tue, 27 Feb 2007) Log Message: ----------- Copied files Modified Paths: -------------- binaryfile/trunk/Makefile Added Paths: ----------- binaryfile/trunk/src/binaryfile/__init__.py binaryfile/trunk/src/binaryfile/binary.py binaryfile/trunk/src/binaryfile/binaryrecord.py binaryfile/trunk/src/binaryfile/tests.py Modified: binaryfile/trunk/Makefile =================================================================== --- binaryfile/trunk/Makefile 2007-02-27 15:38:21 UTC (rev 207) +++ binaryfile/trunk/Makefile 2007-02-27 15:49:15 UTC (rev 208) @@ -32,7 +32,7 @@ # What should the default be? test: - $(PYTHON) src/enumprocess/processinfo.py + $(PYTHON) src/binaryfile/tests.py egg: egg24 egg25 Added: binaryfile/trunk/src/binaryfile/__init__.py =================================================================== Property changes on: binaryfile/trunk/src/binaryfile/__init__.py ___________________________________________________________________ Name: svn:keywords + 'Id Revision' Name: svn:eol-style + native Copied: binaryfile/trunk/src/binaryfile/binary.py (from rev 204, pymoul/trunk/src/moul/crypt/binary.py) =================================================================== --- binaryfile/trunk/src/binaryfile/binary.py (rev 0) +++ binaryfile/trunk/src/binaryfile/binary.py 2007-02-27 15:49:15 UTC (rev 208) @@ -0,0 +1,283 @@ +# Copyright (C) 2007 Christian Heimes <christian (at) cheimes (dot) de> +"""Binary file helper +""" +__author__ = "Christian Heimes" +__version__ = "$Id" +__revision__ = "$Revision" + +from struct import calcsize +from struct import pack +from struct import unpack + +from binaryrecord import parseRecord +from binaryrecord import registerRecord + +class BinaryFile(file): + """Binary file + + A file based class with additional methods to read and write binary data. + + The class supports reading and writing: + - char: readChar / writeChar + - byte: readByte / writeByte + - bool: readBool / writeBool + - signed int8: read8 / write8 + - unsigned int8: read8s / write8s + - unsigned int 16: read16 / write16 + - signed int 16: read16s / write16s + - unsigned int 32: read32 / write32 + - signed int 32: read32s / write32s + - unsigned int 64: read64 / write64 + - signed int 64: read64s / write64s + - float: readFloat / writeFloat + - double: readDouble / writeDouble + - packed data: readPacked(fmt) / writePacked(fmt, data) + - quad (two int16): readQuad / writeQuad) + - NULL: read0 / write0 + - null string: readString0 / writeString0 (size is string + NULL) + - string w/ 16bit size header: readString16(null terminated) / writeString16 + - string w/ 32bit size header: readString32(null terminated) / writeString32 + + For conveniance the class has a size() method + + The class is using some optimization tricks like binding functions to the + local namespace of a method. + """ + def __new__(cls, fname, mode='rb'): + assert 'b' in mode + self = file.__new__(cls, fname, mode) + self.NULL = '\x00' + return self + + def size(self): + pos = self.tell() + try: + self.seek(0, 2) + return self.tell() + finally: + self.seek(pos) + + def readChar(self, _unpack=unpack): + return _unpack('<c', self.read(1))[0] + + def readByte(self, _unpack=unpack): + return _unpack('<B',self.read(1))[0] + + def readBool(self, _unpack=unpack): + return bool(_unpack('<B', self.read(1))[0]) + + def read8(self, _unpack=unpack): + return _unpack('<B', self.read(1))[0] + + def read8s(self, _unpack=unpack): + return _unpack('<b', self.read(1))[0] + + def read16(self, _unpack=unpack): + return _unpack('<H', self.read(2))[0] + + def read16s(self, _unpack=unpack): + return _unpack('<h', self.read(2))[0] + + def read32(self, _unpack=unpack): + return _unpack('<I', self.read(4))[0] + + def read32s(self, _unpack=unpack): + return _unpack('<i', self.read(4))[0] + + def read64(self, _unpack=unpack): + return _unpack('<Q', self.read(8))[0] + + def read64s(self, _unpack=unpack): + return _unpack('<q',self.read(8))[0] + + def readQuad(self, _unpack=unpack): + return _unpack('<2I', self.read(8)) + + def readFloat(self, _unpack=unpack): + return _unpack('<f', self.read(4))[0] + + def readDouble(self, _unpack=unpack): + return _unpack('<d', self.read(8))[0] + + def readPacked(self, fmt, _unpack=unpack): + return unpack(fmt, self.read(calcsize(fmt))) + + def read0(self): + null = self.read(1) + if null != self.NULL: + raise ValueError("%s != NULL at %i" % (null, self.tell()-1)) + return null + + def readUruString(self, version=5): + return UruString('', version=version).readfd(self) + + def readString0(self, size): + s = self.read(size-1) + self.read0() + return s + + def readString16(self, terminate=False): + return String16('', terminate=terminate).readfd(self) + + def readString32(self, terminate=False): + return String32('', terminate=terminate).readfd(self) + + def readRecord(self, name): + return parseRecord(name, self) + + @staticmethod + def registerRecord(name, fmt): + return registerRecord(name, fmt) + + #write + def writeChar(self, data, _pack=pack): + self.write(_pack('<c', data)) + + def writeByte(self, data, _pack=pack): + self.write(_pack('<B', data)) + + def writeBool(self, data, _pack=pack): + self.write(_pack('<B', bool(data))) + + def write8(self, data, _pack=pack): + self.write(_pack('<B', data)) + + def write8s(self, data, _pack=pack): + self.write(_pack('<b', data)) + + def write16(self, data, _pack=pack): + self.write(_pack('<H', data)) + + def write16s(self, data, _pack=pack): + self.write(_pack('<h', data)) + + def write32(self, data, _pack=pack): + self.write(_pack('<I', data)) + + def write32s(self, data, _pack=pack): + self.write(_pack('<i', data)) + + def write64(self, data, _pack=pack): + self.write(_pack('<Q', data)) + + def write64s(self, data, _pack=pack): + self.write(_pack('<q', data)) + + def writeQuad(self, tupl, _pack=pack): + self.write(_pack('<2I', *tupl)) + + def writeFloat(self, data, _pack=pack): + self.write(_pack('<f', data)) + + def writeDouble(self, data, _pack=pack): + self.write(_pack('<d', data)) + + def write0(self): + self.write(self.NULL) + + def writeString0(self, s): + self.write(s) + self.write0() + + def writePacked(self, data, fmt): + self.write(pack(fmt, data)) + + def writeUruString(self, data, version=5): + UruString(data, version=version).writefd(self) + + def writeString16(self, data, terminate=False): + String16(data, terminate=terminate).writefd(self) + + def writeString32(self, data, terminate=False): + String32(data, terminate=terminate).writefd(self) + + def writeRecord(self, rec): + self.write(rec.read()) + +class AbstractString(object): + """Abstract string class + """ + def __init__(self, s=''): + self._data = s + + def readfd(self, fd): + raise NotImplementedError + + def writefd(self, fd): + raise NotImplementedError + + def clear(self): + """Clear data + """ + self._data = '' + + def set(self, s): + """Replace current data with s + """ + self._data = s + + def __repr__(self): + """repr(self) + """ + return ("<%s at %x (%i)" % (self.__class__.__name__, id(self), + len(self))) + + def __len__(self): + """len(self) + """ + return len(self._data) + + def __cmp__(self, other): + if isinstance(other, AbstractString): + return cmp(self._data, other._data) + else: + return cmp(self._data, other) + +class String32(AbstractString): + """String with 32 bit size header + """ + def __init__(self, s='', terminate=False): + AbstractString.__init__(self, s) + self._terminate = bool(terminate) + + def readfd(self, fd): + size = fd.read32() + if self._terminate: + self._data = fd.readString0(size) + else: + self._data = fd.read(size) + return self._data + + def writefd(self, fd): + size = len(self) + if self._terminate: + fd.write32(size+1) + fd.writeString0(self._data) + else: + fd.write32(size) + fd.write(self._data) + +class String16(AbstractString): + """String with 16 bit size header + """ + def __init__(self, s='', terminate=False): + AbstractString.__init__(self, s) + self._terminate = bool(terminate) + + def readfd(self, fd): + size = fd.read16() + if self._terminate: + self._data = fd.readString0(size) + else: + self._data = fd.read(size) + return self._data + + def writefd(self, fd): + size = len(self) + if self._terminate: + fd.write16(size+1) + fd.writeString0(self._data) + else: + fd.write16(size) + fd.write(self._data) + Copied: binaryfile/trunk/src/binaryfile/binaryrecord.py (from rev 204, pymoul/trunk/src/moul/crypt/binaryrecord.py) =================================================================== --- binaryfile/trunk/src/binaryfile/binaryrecord.py (rev 0) +++ binaryfile/trunk/src/binaryfile/binaryrecord.py 2007-02-27 15:49:15 UTC (rev 208) @@ -0,0 +1,154 @@ +# Copyright (C) 2007 Christian Heimes <christian (at) cheimes (dot) de> +"""Binary file helper: Records + +This module is roughly based on Maciej Obarski's recipe "parse and create +fixed size binary data" from +http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/465219 +""" +__author__ = "Christian Heimes" +__version__ = "$Id" +__revision__ = "$Revision" + +from struct import calcsize +from struct import pack +from struct import unpack + +_marker = object() + +class RecordRegistry(dict): + """Registry for record definitions + """ + __slots__ = () + def register(self, name, fmt): + """Register a format by name + + @param name: name of the format + @type name: str + @param fmt: a record format + @type fmt: str + + Example: + >>> reg = RecordRegistry() + >>> registerRecord = reg.register + >>> parseRecord = reg.parse + >>> obj = registerRecord("connection", "4B.ip >H.port >I.session_id") + >>> isinstance(obj, RecordDefinition) + True + >>> data = "\\xc0\\xa8\\x00\\x01" + "\\x00P" + "\\xFE\\xDC\\xBA\\x98" + + >>> rec = parseRecord("connection", data) + >>> rec.ip + (192, 168, 0, 1) + >>> rec.port + 80 + >>> rec.session_id + 4275878552L + >>> rec.read() == data or rec.read() + True + """ + if name in self: + raise NameError("%s already registered!" % name) + self[name] = RecordDefinition(name, fmt) + return self[name] + + def parse(self, name, fd_data): + """Parse data using the RecordDefinition 'name' + + @param name: name of the format + @type name: str + @param fd_data: data to parse: either a string or an open file + @type fd_data: str or file + """ + return self[name](fd_data) + +class RecordDefinition(object): + """A record definition + """ + __slots__ = ('_fields', '_recordsize', '_name') + + def __init__(self, name, recordfmt): + self._name = name + self._fields = [] + pos = 0 + for field in recordfmt.split(): + if field.startswith('#'): + continue + fmt, name = field.split('.') + if '#' in name: + name = name.split('#')[0] + name = name.strip() + size = calcsize(fmt) + self._fields.append((name, fmt, pos, pos+size)) + pos += size + + self._recordsize = pos + + @property + def name(self): + return self._name + + @property + def size(self): + return self._recordsize + + def __call__(self, fd_data): + """Parse data using the format string + + @param fd_data: data to parse: either a string or an open file + @type fd_data: str or file + """ + if isinstance(fd_data, basestring): + # handle string + data = fd_data + elif hasattr(fd_data, 'read'): + data = fd_data.read(self._recordsize) + else: + raise TypeError(type(fd_data)) + if len(data) != self._recordsize: + raise ValueError("Data has wrong size: %i, required: %i" % + (len(data), self._recordsize)) + return Record(self._fields, data) + +class Record(object): + __slots__ = ('_fields', '_data') + + def __init__(self, fields, data=None): + self._fields = fields + self._data = {} + if data is not None: + self.write(data) + + def write(self, data): + """Write data + + Creates the instance attributes defined in fmt + """ + for name, fmt, start, stop in self._fields: + value = unpack(fmt, data[start:stop]) + if len(value) == 1: + value = value[0] + self._data[name] = value + + def read(self): + """Convert data to binary string + """ + result = [] + for name, fmt, start, stop in self._fields: + value = self._data[name] + if not isinstance(value, (tuple, list)): + value = (value,) + result.append(pack(fmt, *value)) + return ''.join(result) + + def __getattr__(self, name, default=_marker): + value = self._data.get(name, default) + if value is _marker: + raise AttributeError(name) + return value + + def __str__(self): + return self.read() + +_recordRegistry = RecordRegistry() +registerRecord = _recordRegistry.register +parseRecord = _recordRegistry.parse Copied: binaryfile/trunk/src/binaryfile/tests.py (from rev 204, pymoul/trunk/src/moul/crypt/tests/test_binary.py) =================================================================== --- binaryfile/trunk/src/binaryfile/tests.py (rev 0) +++ binaryfile/trunk/src/binaryfile/tests.py 2007-02-27 15:49:15 UTC (rev 208) @@ -0,0 +1,135 @@ +# Copyright (C) 2007 Christian Heimes <christian (at) cheimes (dot) de> +"""binaryfile unit tests +""" +__author__ = "Christian Heimes" +__version__ = "$Id$" +__revision__ = "$Revision$" + +import os +import unittest +from doctest import DocTestSuite +from tempfile import mkstemp + +from binary import BinaryFile + +class BinaryFileTest(unittest.TestCase): + def setUp(self): + self.tmpname = mkstemp()[1] + self.b = BinaryFile(self.tmpname, 'wb+') + + def tearDown(self): + self.b.close() + os.unlink(self.tmpname) + + def _testrw(self, name, data): + #import pdb; pdb.set_trace() + read = getattr(self.b, 'read%s' % name) + write = getattr(self.b, 'write%s' % name) + write(data) + self.b.seek(0) + fdata = read() + self.failUnlessEqual(data, fdata) + + def test_char(self): + self._testrw('Char', 'a') + + def test_byte(self): + self._testrw('Byte', 127) + + def test_bool(self): + self._testrw('Bool', True) + + def test_8(self): + self._testrw('8', 42) + + def test_8s(self): + self._testrw('8s', -42) + + def test_16(self): + self._testrw('16', 2**15) + + def test_16s(self): + self._testrw('16s', -2**15) + + def test_32(self): + self._testrw('32', 2*31) + + def test_32s(self): + self._testrw('32s', -2*31) + + def test_64(self): + self._testrw('64', 2*63) + + def test_64s(self): + self._testrw('64s', -2*63) + + def test_float(self): + data = -0.07 + self.b.writeFloat(data) + self.b.seek(0) + self.failUnlessAlmostEqual(data, self.b.readFloat()) + + def test_double(self): + self._testrw('Double', -23*10e200) + + def test_quad(self): + data = (23, 42) + self.b.writeQuad(data) + self.b.seek(0) + self.failUnlessEqual(data, self.b.readQuad()) + + def test_urustring(self): + # XXX: no test data + pass + + def test_string0(self): + s = "a test string" + l = len(s) + self.b.writeString0(s) + self.b.seek(0) + self.failUnlessEqual(self.b.size(), l+1) + self.failUnlessEqual(self.b.readString0(l+1), s) + self.b.seek(0) + self.failUnlessEqual(self.b.read(), s+'\x00') + + def test_string16(self): + s = "a test string" + l = len(s) + self.b.writeString16(s, terminate=False) + self.b.seek(0) + self.failUnlessEqual(self.b.size(), l+2) + self.failUnlessEqual(self.b.readString16(terminate=False), s) + + self.b.seek(0) + self.b.truncate(0) + self.b.writeString16(s, terminate=True) + self.b.seek(0) + self.failUnlessEqual(self.b.size(), l+3) + self.failUnlessEqual(self.b.readString16(terminate=True), s) + + def test_string32(self): + s = "a test string" + l = len(s) + self.b.writeString32(s, terminate=False) + self.b.seek(0) + self.failUnlessEqual(self.b.size(), l+4) + self.failUnlessEqual(self.b.readString32(terminate=False), s) + + self.b.seek(0) + self.b.truncate(0) + self.b.writeString32(s, terminate=True) + self.b.seek(0) + self.failUnlessEqual(self.b.size(), l+5) + self.failUnlessEqual(self.b.readString32(terminate=True), s) + + +def test_suite(): + return unittest.TestSuite(( + unittest.makeSuite(BinaryFileTest), + DocTestSuite('binary'), + DocTestSuite('binaryrecord'), + )) + +if __name__ == '__main__': + unittest.main(defaultTest="test_suite") + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ti...@us...> - 2007-02-27 15:38:20
|
Revision: 207 http://pymoul.svn.sourceforge.net/pymoul/?rev=207&view=rev Author: tiran Date: 2007-02-27 07:38:21 -0800 (Tue, 27 Feb 2007) Log Message: ----------- Initial and bare import of binaryfile Added Paths: ----------- binaryfile/ binaryfile/branches/ binaryfile/tags/ binaryfile/trunk/ binaryfile/trunk/CHANGES.txt binaryfile/trunk/INSTALL.txt binaryfile/trunk/LICENSE.txt binaryfile/trunk/MANIFEST.in binaryfile/trunk/Makefile binaryfile/trunk/README.txt binaryfile/trunk/ez_setup.py binaryfile/trunk/setup.py binaryfile/trunk/src/ binaryfile/trunk/src/binaryfile/ binaryfile/trunk/version.txt Added: binaryfile/trunk/CHANGES.txt =================================================================== Property changes on: binaryfile/trunk/CHANGES.txt ___________________________________________________________________ Name: svn:keywords + 'Id Revision' Name: svn:eol-style + native Added: binaryfile/trunk/INSTALL.txt =================================================================== --- binaryfile/trunk/INSTALL.txt (rev 0) +++ binaryfile/trunk/INSTALL.txt 2007-02-27 15:38:21 UTC (rev 207) @@ -0,0 +1,13 @@ +============ +Requirements +============ + + * Python 2.4+ http://www.python.org/ + * easy_install http://peak.telecommunity.com/DevCenter/EasyInstall + * setuptools (via easy install) + +============ +Installation +============ + + $ python setup.py install Property changes on: binaryfile/trunk/INSTALL.txt ___________________________________________________________________ Name: svn:keywords + 'Id Revision' Name: svn:eol-style + native Added: binaryfile/trunk/LICENSE.txt =================================================================== Property changes on: binaryfile/trunk/LICENSE.txt ___________________________________________________________________ Name: svn:keywords + 'Id Revision' Name: svn:eol-style + native Added: binaryfile/trunk/MANIFEST.in =================================================================== --- binaryfile/trunk/MANIFEST.in (rev 0) +++ binaryfile/trunk/MANIFEST.in 2007-02-27 15:38:21 UTC (rev 207) @@ -0,0 +1,3 @@ +include *.txt setup.py ez_setup.py Makefile +recursive-include src/binaryfile *.py + Added: binaryfile/trunk/Makefile =================================================================== --- binaryfile/trunk/Makefile (rev 0) +++ binaryfile/trunk/Makefile 2007-02-27 15:38:21 UTC (rev 207) @@ -0,0 +1,54 @@ +PYTHON?=python2.5 +PYTHON24=python2.4 +PYTHON25=python2.5 +TESTFLAGS=-v +TESTOPTS= +SETUPFLAGS= +KEYID=AD16AB1B + +all: inplace + +# Build in-place +inplace: + $(PYTHON) setup.py $(SETUPFLAGS) build_ext -i + +build: + $(PYTHON) setup.py $(SETUPFLAGS) build + +egg24: + $(PYTHON24) setup.py $(SETUPFLAGS) bdist_egg + +egg25: + $(PYTHON25) setup.py $(SETUPFLAGS) bdist_egg + +dist25: + $(PYTHON25) setup.py $(SETUPFLAGS) bdist_egg \ + sdist --formats=zip,gztar + +dist_upload: realclean + $(PYTHON25) setup.py $(SETUPFLAGS) bdist_egg \ + sdist --formats=zip,gztar \ + upload --sign --identity=$(KEYID) + +# What should the default be? +test: + $(PYTHON) src/enumprocess/processinfo.py + +egg: egg24 egg25 + +distribution: realclean dist25 egg24 gpg + +gpg: + for F in `find dist -type f -and -not -name '*.asc'`; do \ + gpg --detach-sign --armor --default-key $(KEYID) $$F; \ + done + md5sum dist/*.zip dist/*.egg dist/*.gz + +clean: + find . \( -name '*.o' -o -name '*~' -o -name '*.so' -o -name '*.py[cod]' -o -name '*.dll' \) -exec rm -f {} \; + rm -rf build + +realclean: clean + rm -f TAGS + rm -rf dist + $(PYTHON) setup.py clean -a Property changes on: binaryfile/trunk/Makefile ___________________________________________________________________ Name: svn:keywords + 'Id Revision' Name: svn:eol-style + native Added: binaryfile/trunk/README.txt =================================================================== Property changes on: binaryfile/trunk/README.txt ___________________________________________________________________ Name: svn:keywords + 'Id Revision' Name: svn:eol-style + native Added: binaryfile/trunk/ez_setup.py =================================================================== --- binaryfile/trunk/ez_setup.py (rev 0) +++ binaryfile/trunk/ez_setup.py 2007-02-27 15:38:21 UTC (rev 207) @@ -0,0 +1,228 @@ +#!python +"""Bootstrap setuptools installation + +If you want to use setuptools in your package's setup.py, just include this +file in the same directory with it, and add this to the top of your setup.py:: + + from ez_setup import use_setuptools + use_setuptools() + +If you want to require a specific version of setuptools, set a download +mirror, or use an alternate download directory, you can do so by supplying +the appropriate options to ``use_setuptools()``. + +This file can also be run as a script to install or upgrade setuptools. +""" +import sys +DEFAULT_VERSION = "0.6c5" +DEFAULT_URL = "http://cheeseshop.python.org/packages/%s/s/setuptools/" % sys.version[:3] + +md5_data = { + 'setuptools-0.6b1-py2.3.egg': '8822caf901250d848b996b7f25c6e6ca', + 'setuptools-0.6b1-py2.4.egg': 'b79a8a403e4502fbb85ee3f1941735cb', + 'setuptools-0.6b2-py2.3.egg': '5657759d8a6d8fc44070a9d07272d99b', + 'setuptools-0.6b2-py2.4.egg': '4996a8d169d2be661fa32a6e52e4f82a', + 'setuptools-0.6b3-py2.3.egg': 'bb31c0fc7399a63579975cad9f5a0618', + 'setuptools-0.6b3-py2.4.egg': '38a8c6b3d6ecd22247f179f7da669fac', + 'setuptools-0.6b4-py2.3.egg': '62045a24ed4e1ebc77fe039aa4e6f7e5', + 'setuptools-0.6b4-py2.4.egg': '4cb2a185d228dacffb2d17f103b3b1c4', + 'setuptools-0.6c1-py2.3.egg': 'b3f2b5539d65cb7f74ad79127f1a908c', + 'setuptools-0.6c1-py2.4.egg': 'b45adeda0667d2d2ffe14009364f2a4b', + 'setuptools-0.6c2-py2.3.egg': 'f0064bf6aa2b7d0f3ba0b43f20817c27', + 'setuptools-0.6c2-py2.4.egg': '616192eec35f47e8ea16cd6a122b7277', + 'setuptools-0.6c3-py2.3.egg': 'f181fa125dfe85a259c9cd6f1d7b78fa', + 'setuptools-0.6c3-py2.4.egg': 'e0ed74682c998bfb73bf803a50e7b71e', + 'setuptools-0.6c3-py2.5.egg': 'abef16fdd61955514841c7c6bd98965e', + 'setuptools-0.6c4-py2.3.egg': 'b0b9131acab32022bfac7f44c5d7971f', + 'setuptools-0.6c4-py2.4.egg': '2a1f9656d4fbf3c97bf946c0a124e6e2', + 'setuptools-0.6c4-py2.5.egg': '8f5a052e32cdb9c72bcf4b5526f28afc', + 'setuptools-0.6c5-py2.3.egg': 'ee9fd80965da04f2f3e6b3576e9d8167', + 'setuptools-0.6c5-py2.4.egg': 'afe2adf1c01701ee841761f5bcd8aa64', + 'setuptools-0.6c5-py2.5.egg': 'a8d3f61494ccaa8714dfed37bccd3d5d', +} + +import sys, os + +def _validate_md5(egg_name, data): + if egg_name in md5_data: + from md5 import md5 + digest = md5(data).hexdigest() + if digest != md5_data[egg_name]: + print >>sys.stderr, ( + "md5 validation of %s failed! (Possible download problem?)" + % egg_name + ) + sys.exit(2) + return data + + +def use_setuptools( + version=DEFAULT_VERSION, download_base=DEFAULT_URL, to_dir=os.curdir, + download_delay=15 +): + """Automatically find/download setuptools and make it available on sys.path + + `version` should be a valid setuptools version number that is available + as an egg for download under the `download_base` URL (which should end with + a '/'). `to_dir` is the directory where setuptools will be downloaded, if + it is not already available. If `download_delay` is specified, it should + be the number of seconds that will be paused before initiating a download, + should one be required. If an older version of setuptools is installed, + this routine will print a message to ``sys.stderr`` and raise SystemExit in + an attempt to abort the calling script. + """ + try: + import setuptools + if setuptools.__version__ == '0.0.1': + print >>sys.stderr, ( + "You have an obsolete version of setuptools installed. Please\n" + "remove it from your system entirely before rerunning this script." + ) + sys.exit(2) + except ImportError: + egg = download_setuptools(version, download_base, to_dir, download_delay) + sys.path.insert(0, egg) + import setuptools; setuptools.bootstrap_install_from = egg + + import pkg_resources + try: + pkg_resources.require("setuptools>="+version) + + except pkg_resources.VersionConflict, e: + # XXX could we install in a subprocess here? + print >>sys.stderr, ( + "The required version of setuptools (>=%s) is not available, and\n" + "can't be installed while this script is running. Please install\n" + " a more recent version first.\n\n(Currently using %r)" + ) % (version, e.args[0]) + sys.exit(2) + +def download_setuptools( + version=DEFAULT_VERSION, download_base=DEFAULT_URL, to_dir=os.curdir, + delay = 15 +): + """Download setuptools from a specified location and return its filename + + `version` should be a valid setuptools version number that is available + as an egg for download under the `download_base` URL (which should end + with a '/'). `to_dir` is the directory where the egg will be downloaded. + `delay` is the number of seconds to pause before an actual download attempt. + """ + import urllib2, shutil + egg_name = "setuptools-%s-py%s.egg" % (version,sys.version[:3]) + url = download_base + egg_name + saveto = os.path.join(to_dir, egg_name) + src = dst = None + if not os.path.exists(saveto): # Avoid repeated downloads + try: + from distutils import log + if delay: + log.warn(""" +--------------------------------------------------------------------------- +This script requires setuptools version %s to run (even to display +help). I will attempt to download it for you (from +%s), but +you may need to enable firewall access for this script first. +I will start the download in %d seconds. + +(Note: if this machine does not have network access, please obtain the file + + %s + +and place it in this directory before rerunning this script.) +---------------------------------------------------------------------------""", + version, download_base, delay, url + ); from time import sleep; sleep(delay) + log.warn("Downloading %s", url) + src = urllib2.urlopen(url) + # Read/write all in one block, so we don't create a corrupt file + # if the download is interrupted. + data = _validate_md5(egg_name, src.read()) + dst = open(saveto,"wb"); dst.write(data) + finally: + if src: src.close() + if dst: dst.close() + return os.path.realpath(saveto) + +def main(argv, version=DEFAULT_VERSION): + """Install or upgrade setuptools and EasyInstall""" + + try: + import setuptools + except ImportError: + egg = None + try: + egg = download_setuptools(version, delay=0) + sys.path.insert(0,egg) + from setuptools.command.easy_install import main + return main(list(argv)+[egg]) # we're done here + finally: + if egg and os.path.exists(egg): + os.unlink(egg) + else: + if setuptools.__version__ == '0.0.1': + # tell the user to uninstall obsolete version + use_setuptools(version) + + req = "setuptools>="+version + import pkg_resources + try: + pkg_resources.require(req) + except pkg_resources.VersionConflict: + try: + from setuptools.command.easy_install import main + except ImportError: + from easy_install import main + main(list(argv)+[download_setuptools(delay=0)]) + sys.exit(0) # try to force an exit + else: + if argv: + from setuptools.command.easy_install import main + main(argv) + else: + print "Setuptools version",version,"or greater has been installed." + print '(Run "ez_setup.py -U setuptools" to reinstall or upgrade.)' + + + +def update_md5(filenames): + """Update our built-in md5 registry""" + + import re + from md5 import md5 + + for name in filenames: + base = os.path.basename(name) + f = open(name,'rb') + md5_data[base] = md5(f.read()).hexdigest() + f.close() + + data = [" %r: %r,\n" % it for it in md5_data.items()] + data.sort() + repl = "".join(data) + + import inspect + srcfile = inspect.getsourcefile(sys.modules[__name__]) + f = open(srcfile, 'rb'); src = f.read(); f.close() + + match = re.search("\nmd5_data = {\n([^}]+)}", src) + if not match: + print >>sys.stderr, "Internal error!" + sys.exit(2) + + src = src[:match.start(1)] + repl + src[match.end(1):] + f = open(srcfile,'w') + f.write(src) + f.close() + + +if __name__=='__main__': + if len(sys.argv)>2 and sys.argv[1]=='--md5update': + update_md5(sys.argv[2:]) + else: + main(sys.argv[1:]) + + + + + Property changes on: binaryfile/trunk/ez_setup.py ___________________________________________________________________ Name: svn:executable + Name: svn:keywords + 'Id Revision' Name: svn:eol-style + native Added: binaryfile/trunk/setup.py =================================================================== --- binaryfile/trunk/setup.py (rev 0) +++ binaryfile/trunk/setup.py 2007-02-27 15:38:21 UTC (rev 207) @@ -0,0 +1,60 @@ +#!/usr/bin/env python +""" + +""" +__author__ = "Christian Heimes" +__version__ = "$Id: setup.py 203 2007-02-27 14:31:27Z tiran $" +__revision__ = "$Revision: 203 $" + +import sys + +if sys.version_info < (2,4): + raise RuntimeError("Python 2.4+ required:\n%s" % sys.version) + +# boot strap easy setup +SETUPTOOLS_VERSION = "0.6c1" +from ez_setup import use_setuptools +use_setuptools(version=SETUPTOOLS_VERSION) + +# import the rest +from setuptools import setup +from setuptools import find_packages + +from distutils.core import setup + +VERSION = "0.1" + +me = "Christian Heimes" +email = "chr...@ch..." + +setup_infos = dict( + name = "", + version = VERSION, + description = __doc__[:__doc__.find('\n')].strip(), + long_description = '\n'.join([line + for line in __doc__.split('\n')[1:]]), + author = "Christian Heimes", + author_email = "chr...@ch...", + maintainer = "Christian Heimes", + maintainer_email = "chr...@ch...", + url = "http://sourceforge.net/projects/pymoul/", + download_url= "http://cheeseshop.python.org/pypi/", + license = "", + keywords = [], + platforms=['Independant'], + classifiers = ( + 'Development Status :: 4 - Beta', + 'Intended Audience :: Developers', + 'License :: OSI Approved :: ', + 'Operating System :: ' + 'Natural Language :: English', + 'Programming Language :: Python', + 'Topic :: Software Development :: Libraries' + ), + setup_requires = ["setuptools>="+SETUPTOOLS_VERSION,], + packages = [], + package_dir = {'' : 'src'}, + zip_safe = True, +) + +setup(**setup_infos) Property changes on: binaryfile/trunk/setup.py ___________________________________________________________________ Name: svn:executable + Name: svn:keywords + 'Id Revision' Name: svn:eol-style + native Added: binaryfile/trunk/version.txt =================================================================== --- binaryfile/trunk/version.txt (rev 0) +++ binaryfile/trunk/version.txt 2007-02-27 15:38:21 UTC (rev 207) @@ -0,0 +1 @@ +0.1 \ No newline at end of file Property changes on: binaryfile/trunk/version.txt ___________________________________________________________________ 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. |
From: <ti...@us...> - 2007-02-27 15:37:20
|
Revision: 206 http://pymoul.svn.sourceforge.net/pymoul/?rev=206&view=rev Author: tiran Date: 2007-02-27 07:37:18 -0800 (Tue, 27 Feb 2007) Log Message: ----------- Initial and bare import of tqt4utils Added Paths: ----------- tqt4utils/ tqt4utils/branches/ tqt4utils/tags/ tqt4utils/trunk/ tqt4utils/trunk/CHANGES.txt tqt4utils/trunk/INSTALL.txt tqt4utils/trunk/LICENSE.txt tqt4utils/trunk/MANIFEST.in tqt4utils/trunk/Makefile tqt4utils/trunk/README.txt tqt4utils/trunk/ez_setup.py tqt4utils/trunk/setup.py tqt4utils/trunk/src/ tqt4utils/trunk/src/tqt4utils/ tqt4utils/trunk/version.txt Added: tqt4utils/trunk/CHANGES.txt =================================================================== Property changes on: tqt4utils/trunk/CHANGES.txt ___________________________________________________________________ Name: svn:keywords + 'Id Revision' Name: svn:eol-style + native Added: tqt4utils/trunk/INSTALL.txt =================================================================== --- tqt4utils/trunk/INSTALL.txt (rev 0) +++ tqt4utils/trunk/INSTALL.txt 2007-02-27 15:37:18 UTC (rev 206) @@ -0,0 +1,13 @@ +============ +Requirements +============ + + * Python 2.4+ http://www.python.org/ + * easy_install http://peak.telecommunity.com/DevCenter/EasyInstall + * setuptools (via easy install) + +============ +Installation +============ + + $ python setup.py install Property changes on: tqt4utils/trunk/INSTALL.txt ___________________________________________________________________ Name: svn:keywords + 'Id Revision' Name: svn:eol-style + native Added: tqt4utils/trunk/LICENSE.txt =================================================================== Property changes on: tqt4utils/trunk/LICENSE.txt ___________________________________________________________________ Name: svn:keywords + 'Id Revision' Name: svn:eol-style + native Added: tqt4utils/trunk/MANIFEST.in =================================================================== --- tqt4utils/trunk/MANIFEST.in (rev 0) +++ tqt4utils/trunk/MANIFEST.in 2007-02-27 15:37:18 UTC (rev 206) @@ -0,0 +1,3 @@ +include *.txt setup.py ez_setup.py Makefile +recursive-include src/binaryfile *.py + Added: tqt4utils/trunk/Makefile =================================================================== --- tqt4utils/trunk/Makefile (rev 0) +++ tqt4utils/trunk/Makefile 2007-02-27 15:37:18 UTC (rev 206) @@ -0,0 +1,54 @@ +PYTHON?=python2.5 +PYTHON24=python2.4 +PYTHON25=python2.5 +TESTFLAGS=-v +TESTOPTS= +SETUPFLAGS= +KEYID=AD16AB1B + +all: inplace + +# Build in-place +inplace: + $(PYTHON) setup.py $(SETUPFLAGS) build_ext -i + +build: + $(PYTHON) setup.py $(SETUPFLAGS) build + +egg24: + $(PYTHON24) setup.py $(SETUPFLAGS) bdist_egg + +egg25: + $(PYTHON25) setup.py $(SETUPFLAGS) bdist_egg + +dist25: + $(PYTHON25) setup.py $(SETUPFLAGS) bdist_egg \ + sdist --formats=zip,gztar + +dist_upload: realclean + $(PYTHON25) setup.py $(SETUPFLAGS) bdist_egg \ + sdist --formats=zip,gztar \ + upload --sign --identity=$(KEYID) + +# What should the default be? +test: + $(PYTHON) src/enumprocess/processinfo.py + +egg: egg24 egg25 + +distribution: realclean dist25 egg24 gpg + +gpg: + for F in `find dist -type f -and -not -name '*.asc'`; do \ + gpg --detach-sign --armor --default-key $(KEYID) $$F; \ + done + md5sum dist/*.zip dist/*.egg dist/*.gz + +clean: + find . \( -name '*.o' -o -name '*~' -o -name '*.so' -o -name '*.py[cod]' -o -name '*.dll' \) -exec rm -f {} \; + rm -rf build + +realclean: clean + rm -f TAGS + rm -rf dist + $(PYTHON) setup.py clean -a Property changes on: tqt4utils/trunk/Makefile ___________________________________________________________________ Name: svn:keywords + 'Id Revision' Name: svn:eol-style + native Added: tqt4utils/trunk/README.txt =================================================================== Property changes on: tqt4utils/trunk/README.txt ___________________________________________________________________ Name: svn:keywords + 'Id Revision' Name: svn:eol-style + native Added: tqt4utils/trunk/ez_setup.py =================================================================== --- tqt4utils/trunk/ez_setup.py (rev 0) +++ tqt4utils/trunk/ez_setup.py 2007-02-27 15:37:18 UTC (rev 206) @@ -0,0 +1,228 @@ +#!python +"""Bootstrap setuptools installation + +If you want to use setuptools in your package's setup.py, just include this +file in the same directory with it, and add this to the top of your setup.py:: + + from ez_setup import use_setuptools + use_setuptools() + +If you want to require a specific version of setuptools, set a download +mirror, or use an alternate download directory, you can do so by supplying +the appropriate options to ``use_setuptools()``. + +This file can also be run as a script to install or upgrade setuptools. +""" +import sys +DEFAULT_VERSION = "0.6c5" +DEFAULT_URL = "http://cheeseshop.python.org/packages/%s/s/setuptools/" % sys.version[:3] + +md5_data = { + 'setuptools-0.6b1-py2.3.egg': '8822caf901250d848b996b7f25c6e6ca', + 'setuptools-0.6b1-py2.4.egg': 'b79a8a403e4502fbb85ee3f1941735cb', + 'setuptools-0.6b2-py2.3.egg': '5657759d8a6d8fc44070a9d07272d99b', + 'setuptools-0.6b2-py2.4.egg': '4996a8d169d2be661fa32a6e52e4f82a', + 'setuptools-0.6b3-py2.3.egg': 'bb31c0fc7399a63579975cad9f5a0618', + 'setuptools-0.6b3-py2.4.egg': '38a8c6b3d6ecd22247f179f7da669fac', + 'setuptools-0.6b4-py2.3.egg': '62045a24ed4e1ebc77fe039aa4e6f7e5', + 'setuptools-0.6b4-py2.4.egg': '4cb2a185d228dacffb2d17f103b3b1c4', + 'setuptools-0.6c1-py2.3.egg': 'b3f2b5539d65cb7f74ad79127f1a908c', + 'setuptools-0.6c1-py2.4.egg': 'b45adeda0667d2d2ffe14009364f2a4b', + 'setuptools-0.6c2-py2.3.egg': 'f0064bf6aa2b7d0f3ba0b43f20817c27', + 'setuptools-0.6c2-py2.4.egg': '616192eec35f47e8ea16cd6a122b7277', + 'setuptools-0.6c3-py2.3.egg': 'f181fa125dfe85a259c9cd6f1d7b78fa', + 'setuptools-0.6c3-py2.4.egg': 'e0ed74682c998bfb73bf803a50e7b71e', + 'setuptools-0.6c3-py2.5.egg': 'abef16fdd61955514841c7c6bd98965e', + 'setuptools-0.6c4-py2.3.egg': 'b0b9131acab32022bfac7f44c5d7971f', + 'setuptools-0.6c4-py2.4.egg': '2a1f9656d4fbf3c97bf946c0a124e6e2', + 'setuptools-0.6c4-py2.5.egg': '8f5a052e32cdb9c72bcf4b5526f28afc', + 'setuptools-0.6c5-py2.3.egg': 'ee9fd80965da04f2f3e6b3576e9d8167', + 'setuptools-0.6c5-py2.4.egg': 'afe2adf1c01701ee841761f5bcd8aa64', + 'setuptools-0.6c5-py2.5.egg': 'a8d3f61494ccaa8714dfed37bccd3d5d', +} + +import sys, os + +def _validate_md5(egg_name, data): + if egg_name in md5_data: + from md5 import md5 + digest = md5(data).hexdigest() + if digest != md5_data[egg_name]: + print >>sys.stderr, ( + "md5 validation of %s failed! (Possible download problem?)" + % egg_name + ) + sys.exit(2) + return data + + +def use_setuptools( + version=DEFAULT_VERSION, download_base=DEFAULT_URL, to_dir=os.curdir, + download_delay=15 +): + """Automatically find/download setuptools and make it available on sys.path + + `version` should be a valid setuptools version number that is available + as an egg for download under the `download_base` URL (which should end with + a '/'). `to_dir` is the directory where setuptools will be downloaded, if + it is not already available. If `download_delay` is specified, it should + be the number of seconds that will be paused before initiating a download, + should one be required. If an older version of setuptools is installed, + this routine will print a message to ``sys.stderr`` and raise SystemExit in + an attempt to abort the calling script. + """ + try: + import setuptools + if setuptools.__version__ == '0.0.1': + print >>sys.stderr, ( + "You have an obsolete version of setuptools installed. Please\n" + "remove it from your system entirely before rerunning this script." + ) + sys.exit(2) + except ImportError: + egg = download_setuptools(version, download_base, to_dir, download_delay) + sys.path.insert(0, egg) + import setuptools; setuptools.bootstrap_install_from = egg + + import pkg_resources + try: + pkg_resources.require("setuptools>="+version) + + except pkg_resources.VersionConflict, e: + # XXX could we install in a subprocess here? + print >>sys.stderr, ( + "The required version of setuptools (>=%s) is not available, and\n" + "can't be installed while this script is running. Please install\n" + " a more recent version first.\n\n(Currently using %r)" + ) % (version, e.args[0]) + sys.exit(2) + +def download_setuptools( + version=DEFAULT_VERSION, download_base=DEFAULT_URL, to_dir=os.curdir, + delay = 15 +): + """Download setuptools from a specified location and return its filename + + `version` should be a valid setuptools version number that is available + as an egg for download under the `download_base` URL (which should end + with a '/'). `to_dir` is the directory where the egg will be downloaded. + `delay` is the number of seconds to pause before an actual download attempt. + """ + import urllib2, shutil + egg_name = "setuptools-%s-py%s.egg" % (version,sys.version[:3]) + url = download_base + egg_name + saveto = os.path.join(to_dir, egg_name) + src = dst = None + if not os.path.exists(saveto): # Avoid repeated downloads + try: + from distutils import log + if delay: + log.warn(""" +--------------------------------------------------------------------------- +This script requires setuptools version %s to run (even to display +help). I will attempt to download it for you (from +%s), but +you may need to enable firewall access for this script first. +I will start the download in %d seconds. + +(Note: if this machine does not have network access, please obtain the file + + %s + +and place it in this directory before rerunning this script.) +---------------------------------------------------------------------------""", + version, download_base, delay, url + ); from time import sleep; sleep(delay) + log.warn("Downloading %s", url) + src = urllib2.urlopen(url) + # Read/write all in one block, so we don't create a corrupt file + # if the download is interrupted. + data = _validate_md5(egg_name, src.read()) + dst = open(saveto,"wb"); dst.write(data) + finally: + if src: src.close() + if dst: dst.close() + return os.path.realpath(saveto) + +def main(argv, version=DEFAULT_VERSION): + """Install or upgrade setuptools and EasyInstall""" + + try: + import setuptools + except ImportError: + egg = None + try: + egg = download_setuptools(version, delay=0) + sys.path.insert(0,egg) + from setuptools.command.easy_install import main + return main(list(argv)+[egg]) # we're done here + finally: + if egg and os.path.exists(egg): + os.unlink(egg) + else: + if setuptools.__version__ == '0.0.1': + # tell the user to uninstall obsolete version + use_setuptools(version) + + req = "setuptools>="+version + import pkg_resources + try: + pkg_resources.require(req) + except pkg_resources.VersionConflict: + try: + from setuptools.command.easy_install import main + except ImportError: + from easy_install import main + main(list(argv)+[download_setuptools(delay=0)]) + sys.exit(0) # try to force an exit + else: + if argv: + from setuptools.command.easy_install import main + main(argv) + else: + print "Setuptools version",version,"or greater has been installed." + print '(Run "ez_setup.py -U setuptools" to reinstall or upgrade.)' + + + +def update_md5(filenames): + """Update our built-in md5 registry""" + + import re + from md5 import md5 + + for name in filenames: + base = os.path.basename(name) + f = open(name,'rb') + md5_data[base] = md5(f.read()).hexdigest() + f.close() + + data = [" %r: %r,\n" % it for it in md5_data.items()] + data.sort() + repl = "".join(data) + + import inspect + srcfile = inspect.getsourcefile(sys.modules[__name__]) + f = open(srcfile, 'rb'); src = f.read(); f.close() + + match = re.search("\nmd5_data = {\n([^}]+)}", src) + if not match: + print >>sys.stderr, "Internal error!" + sys.exit(2) + + src = src[:match.start(1)] + repl + src[match.end(1):] + f = open(srcfile,'w') + f.write(src) + f.close() + + +if __name__=='__main__': + if len(sys.argv)>2 and sys.argv[1]=='--md5update': + update_md5(sys.argv[2:]) + else: + main(sys.argv[1:]) + + + + + Property changes on: tqt4utils/trunk/ez_setup.py ___________________________________________________________________ Name: svn:executable + Name: svn:keywords + 'Id Revision' Name: svn:eol-style + native Added: tqt4utils/trunk/setup.py =================================================================== --- tqt4utils/trunk/setup.py (rev 0) +++ tqt4utils/trunk/setup.py 2007-02-27 15:37:18 UTC (rev 206) @@ -0,0 +1,60 @@ +#!/usr/bin/env python +""" + +""" +__author__ = "Christian Heimes" +__version__ = "$Id: setup.py 203 2007-02-27 14:31:27Z tiran $" +__revision__ = "$Revision: 203 $" + +import sys + +if sys.version_info < (2,4): + raise RuntimeError("Python 2.4+ required:\n%s" % sys.version) + +# boot strap easy setup +SETUPTOOLS_VERSION = "0.6c1" +from ez_setup import use_setuptools +use_setuptools(version=SETUPTOOLS_VERSION) + +# import the rest +from setuptools import setup +from setuptools import find_packages + +from distutils.core import setup + +VERSION = "0.1" + +me = "Christian Heimes" +email = "chr...@ch..." + +setup_infos = dict( + name = "", + version = VERSION, + description = __doc__[:__doc__.find('\n')].strip(), + long_description = '\n'.join([line + for line in __doc__.split('\n')[1:]]), + author = "Christian Heimes", + author_email = "chr...@ch...", + maintainer = "Christian Heimes", + maintainer_email = "chr...@ch...", + url = "http://sourceforge.net/projects/pymoul/", + download_url= "http://cheeseshop.python.org/pypi/", + license = "", + keywords = [], + platforms=['Independant'], + classifiers = ( + 'Development Status :: 4 - Beta', + 'Intended Audience :: Developers', + 'License :: OSI Approved :: ', + 'Operating System :: ' + 'Natural Language :: English', + 'Programming Language :: Python', + 'Topic :: Software Development :: Libraries' + ), + setup_requires = ["setuptools>="+SETUPTOOLS_VERSION,], + packages = [], + package_dir = {'' : 'src'}, + zip_safe = True, +) + +setup(**setup_infos) Property changes on: tqt4utils/trunk/setup.py ___________________________________________________________________ Name: svn:executable + Name: svn:keywords + 'Id Revision' Name: svn:eol-style + native Added: tqt4utils/trunk/version.txt =================================================================== --- tqt4utils/trunk/version.txt (rev 0) +++ tqt4utils/trunk/version.txt 2007-02-27 15:37:18 UTC (rev 206) @@ -0,0 +1 @@ +0.1 \ No newline at end of file Property changes on: tqt4utils/trunk/version.txt ___________________________________________________________________ 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. |
From: <ti...@us...> - 2007-02-27 14:46:02
|
Revision: 205 http://pymoul.svn.sourceforge.net/pymoul/?rev=205&view=rev Author: tiran Date: 2007-02-27 06:45:53 -0800 (Tue, 27 Feb 2007) Log Message: ----------- Moved processinfo to external module Modified Paths: -------------- pymoul/trunk/INSTALL.txt pymoul/trunk/setup.py pymoul/trunk/src/moul/osdependent/__init__.py pymoul/trunk/src/moul/osdependent/darwin/__init__.py pymoul/trunk/src/moul/osdependent/linux/__init__.py pymoul/trunk/src/moul/osdependent/win32/__init__.py Removed Paths: ------------- pymoul/trunk/src/moul/osdependent/processinfo.py Modified: pymoul/trunk/INSTALL.txt =================================================================== --- pymoul/trunk/INSTALL.txt 2007-02-27 14:32:21 UTC (rev 204) +++ pymoul/trunk/INSTALL.txt 2007-02-27 14:45:53 UTC (rev 205) @@ -4,9 +4,10 @@ * Python 2.5.x http://www.python.org/ * easy_install http://peak.telecommunity.com/DevCenter/EasyInstall - * setuptools (via easy install) - * PyTz (via $ easy_install-2.5 -Z pytz) - * Qt4 GPL 4.2+ http://www.trolltech.com/developer/downloads/qt/ + * setuptools (via easy_install) + * pytz (via $ easy_install-2.5 -Z pytz) + * enumprocess (via $ easy_install-2.5 -Z enumprocess) + * Qt4 GPL 4.2+ http://www.trolltech.com/developer/downloads/qt/ * PyQt4 4.1.1+ http://www.riverbankcomputing.co.uk/pyqt/ Windows Modified: pymoul/trunk/setup.py =================================================================== --- pymoul/trunk/setup.py 2007-02-27 14:32:21 UTC (rev 204) +++ pymoul/trunk/setup.py 2007-02-27 14:45:53 UTC (rev 205) @@ -57,7 +57,7 @@ setup_options = dict( setup_requires = ["setuptools>="+SETUPTOOLS_VERSION,], - install_requires = ["pytz>=2006p",], + install_requires = ["pytz>=2006p", "enumprocess>=0.1"], data_files = [ ('docs', list(glob('*.txt'))), ('i18n', list(glob('src/moul/qt/i18n/pymoul_*.qm'))), Modified: pymoul/trunk/src/moul/osdependent/__init__.py =================================================================== --- pymoul/trunk/src/moul/osdependent/__init__.py 2007-02-27 14:32:21 UTC (rev 204) +++ pymoul/trunk/src/moul/osdependent/__init__.py 2007-02-27 14:45:53 UTC (rev 205) @@ -38,14 +38,20 @@ import sys from types import ModuleType -from moul.osdependent.processinfo import getPidNames -from moul.osdependent.processinfo import getPids +# a program under py2exe is sys.frozen +__FROZEN__ = bool(getattr(sys, 'frozen', False)) +if not __FROZEN__: + import pkg_resources + pkg_resources.require("enumprocess>=0.1") +from enumprocess import getPidNames +from enumprocess import getPids + + LOG = getLogger('moul.osdependent') -# a program under py2exe is sys.frozen -__FROZEN__ = bool(getattr(sys, 'frozen', False)) + # OS stuff _plat = sys.platform.startswith __WIN32__ = _plat('win32') # win64, cygwin? Modified: pymoul/trunk/src/moul/osdependent/darwin/__init__.py =================================================================== --- pymoul/trunk/src/moul/osdependent/darwin/__init__.py 2007-02-27 14:32:21 UTC (rev 204) +++ pymoul/trunk/src/moul/osdependent/darwin/__init__.py 2007-02-27 14:45:53 UTC (rev 205) @@ -22,11 +22,11 @@ __revision__ = "$Revision$" import os +from logging import getLogger +from enumprocess import getPidNames from subprocess import Popen -from logging import getLogger - LOG = getLogger('moul.darwin') LOG.critical('Darwin/Mac support is not tested') Modified: pymoul/trunk/src/moul/osdependent/linux/__init__.py =================================================================== --- pymoul/trunk/src/moul/osdependent/linux/__init__.py 2007-02-27 14:32:21 UTC (rev 204) +++ pymoul/trunk/src/moul/osdependent/linux/__init__.py 2007-02-27 14:45:53 UTC (rev 205) @@ -22,12 +22,11 @@ __revision__ = "$Revision$" import os +from logging import getLogger +from enumprocess import getPidNames from subprocess import Popen -from moul.osdependent.processinfo import getPidNames -from logging import getLogger - LOG = getLogger('moul.linux') LOG.critical('Linux support is not tested') Deleted: pymoul/trunk/src/moul/osdependent/processinfo.py =================================================================== --- pymoul/trunk/src/moul/osdependent/processinfo.py 2007-02-27 14:32:21 UTC (rev 204) +++ pymoul/trunk/src/moul/osdependent/processinfo.py 2007-02-27 14:45:53 UTC (rev 205) @@ -1,465 +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 -# -"""Get process informations - -The module contains for implementations: - - - an Unsupported implementation that raises UnsupportedError - - a Linux implementation that read the data from /proc - - a Unix/POSIX implementation that parses the output of ps - - a Windows implementation that uses ctypes to get the infos from psapi.dll - -API -=== - getPids() - list of ints/longs - getPidNames() - mapping pid -> name - getPidDetails(pid) - detailed informations about a process - getPidDetails('self') - detailed informations about current process - ->>> cur = os.getpid() ->>> exe = sys.executable ->>> pids = getPids() ->>> pids > 1 -True ->>> isinstance(pids[0], (int, long)) -True ->>> cur in pids -True - ->>> mapping = getPidNames() ->>> cur in mapping -True ->>> mapping[cur].lower() in sys.executable -True - ->>> getPidDetails('self')['name'] == getPidDetails(cur)['name'] -True ->>> getPidDetails(cur)['name'] == mapping[cur] -True - ->>> for impl in (WinEnumProcesses(), LinuxProcReader(), PsParser()): -... if impl.supported(): -... isinstance(impl.getPids(), list) and None -... isinstance(impl.getPidNames(), dict) and None -""" -__author__ = "Christian Heimes" -__version__ = "$Id$" -__revision__ = "$Revision$" -__all__ = ['getPids', 'getPidNames', 'getPidDetails', 'supportedOS', - 'UnsupportedError'] - -import logging -import os -import os.path -import sys - - -LOG = logging.getLogger("processinfo") -NULL = "\x00" - -_plat = sys.platform.startswith -if _plat('win') or _plat('cygwin'): - from ctypes import windll, c_ulong, sizeof, c_buffer, byref - PSAPI = windll.psapi - KERNEL = windll.kernel32 - PROCESS_QUERY_INFORMATION = 0x0400 - PROCESS_VM_READ = 0x0010 - PROCESS_FLAGS = PROCESS_QUERY_INFORMATION | PROCESS_VM_READ -else: - from subprocess import Popen - from subprocess import PIPE - -class UnsupportedError(OSError): - """OS or command not supported error - """ - pass - -class Unsupported(object): - """Unsupported OS implementation - - Raises L{UnsupportedError} - """ - __slots__ = () - - @classmethod - def supported(cls): - """Supported flag property""" - return False - - @classmethod - def log(cls): - """Log information about the implementation""" - LOG.warning("Unsupported OS. Neither proc filesystem nor 'ps' works.") - - @classmethod - def getPids(cls): - """Get a list of pids - - @return: a list of pid numbers - @rtype: list(int) - """ - raise UnsupportedError - - @classmethod - def getPidNames(cls): - """Get a mapping of pid -> name - - @return: mapping of pid -> name - @rtype: dict(int:str) - """ - raise UnsupportedError - - @classmethod - def getPidDetails(pid): - """Get detailed informations about a process - - @param pid: pid number or 'self' - @type pid: int or basestring - @return: detailed information about a process - @rtype: dict(str:data) - """ - raise UnsupportedError - -class PsParser(object): - """Parse the output of the ps command - """ - __slots__ = () - - CMD = "ps -e --no-header --cols=1024" - PIDNAMES = "%s --format=pid,ucmd" % CMD - PIDS = "%s --format=pid" % CMD - - @classmethod - def supported(cls): - """Supported flag property""" - try: - cls._exec(cls.PIDS) - except Exception: # catch all! - return False - else: - return True - - @classmethod - def log(cls): - """Log information about the implementation""" - LOG.debug("Using the 'ps' command on POSIX os") - - @classmethod - def getPids(cls): - """Get a list of pids - """ - stdout = cls._exec(cls.PIDS) - if stdout is None: - return None - pids = [] - for line in stdout: - try: - pid = int(line.strip()) - except ValueError: - pass - else: - pids.append(pid) - return pids - - @classmethod - def getPidNames(cls): - """Get a list of pid -> name - """ - stdout = cls._exec(cls.PIDNAMES) - if stdout is None: - return None - mapping = {} - for line in stdout: - line = line.strip() - idx = line.find(' ') - pid, name = line[:idx], line[idx+1:] - try: - pid = int(pid) - except ValueError: - pass - else: - mapping[pid] = name - return mapping - - @classmethod - def getPidDetails(cls, pid): - """Get detailed informations about a process - - TODO - """ - if pid == 'self': - pid = os.getpid() - raise UnsupportedError("not implemented yet") - - @staticmethod - def _exec(cmd): - """Execute command cmd - - The method waits until the command has finished. It returns None of - something went wrong. - - @param cmd: Command to execute - @type cmd: str - @return: None or stdin as file like object - """ - try: - popen = Popen(cmd, shell=True, bufsize=-1, stdout=PIPE, - env = {'LC_ALL' : 'C'}) - rc = popen.wait() - except (OSError, ValueError): - LOG.exception("Failed to execute '%s'" % cmd) - return None - else: - if rc != 0: - LOG.error("'%s' returned with error code %i" % (cmd, rc)) - return None - else: - return popen.stdout - -class LinuxProcReader(object): - """Get process informations under Linux by reading /proc - - Tested under Linux, may work on other POSIX os with /proc, too. - """ - __slots__ = () - - PROC = "/proc" - - @classmethod - def supported(cls): - return os.path.isfile("%s/self/status" % cls.PROC) - - @classmethod - def log(cls): - """Log information about the implementation""" - LOG.debug("Using the proc filesystem on Linux") - - @classmethod - def getPids(cls): - """Get a list of pids - """ - pids = [] - for name in os.listdir(cls.PROC): - if os.path.isdir(cls.PROC + '/' + name): - try: - pids.append(int(name)) - except ValueError: - pass - return pids - - @classmethod - def getPidNames(cls): - """Get a list of pid -> name - """ - mapping = {} - for pid in cls.getPids(): - name = cls._readProcStatus(pid, searchkey='name') - if name is not None: - mapping[pid] = name - return mapping - - def getPidDetails(cls, pid): - """Get detailed informations about a process - """ - details = cls._readProcStatus(pid) - if details is None: - return None - details.update(cls._readProcOther(pid)) - details['cmdline'] = cls._readProcCmdline(pid) - return details - - @classmethod - def _readProcStatus(cls, pid, searchkey=None): - """Read and parse status informations for PID pid - - pid - pid as long or int or 'self' - - If searchkey is None the method returns a mapping of lower keys - to values (stripped). - If searchkey is given than the method immediatly returns the value - or returns None if they key can't be found. - """ - mapping = {} - status = '%s/%s/status' % (cls.PROC, pid) - try: - # read entiry file to avoid race conditions - lines = open(status, 'r').readlines() - except IOError: - LOG.exception("%s not found" % status) - return None - for line in lines: - try: - key, value = line.split(':\t') - except ValueError: - continue - key = key.lower() - value = value.strip() - #if value.endswith(' kB'): - # value = value[:-3] - if key == searchkey: - return value - mapping[key.lower()] = value - if searchkey is not None: - return None - return mapping - - @classmethod - def _readProcCmdline(cls, pid): - """Read cmdline informations for pid and returns a list similar to sys.argv - """ - try: - # read entiry file to avoid race conditions - data = open('%s/%s/cmdline' % (cls.PROC, pid), 'r').read() - except IOError: - return None - return data.split(NULL) - - @classmethod - def _readProcOther(cls, pid): - """Read other possible useful things - - cwd -> current work directory (may not exist) - exe -> path to executable (may not exist) - """ - return { - 'cwd' : os.path.realpath('%s/%s/cwd' % (cls.PROC, pid)), - 'exe' : os.path.realpath('%s/%s/exe' % (cls.PROC, pid)), - } - -class WinEnumProcesses(object): - """""Get process informations under Win32 with psapi.dll - - Based on enumprocesses from Eric Koome - http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/305279 - """ - __slots__ = () - - @classmethod - def supported(cls): - try: - cls.getPids() - except Exception: # catch all! - return False - else: - return True - - @classmethod - def log(cls): - """Log information about the implementation""" - LOG.debug("Using ctypes on Windows") - - @classmethod - def getPids(cls): - """Get a list of pids - """ - arr = c_ulong * 256 - lpidProcess = arr() - cb = sizeof(lpidProcess) - cbNeeded = c_ulong() - - # Call Enumprocesses to get hold of process id's - PSAPI.EnumProcesses(byref(lpidProcess), cb, byref(cbNeeded)) - nReturned = cbNeeded.value/sizeof(c_ulong()) # number of processes returned - return [pid for pid in lpidProcess][:nReturned] - - @classmethod - def getPidNames(cls): - """Get a list of pid -> name - """ - hModule = c_ulong() - count = c_ulong() - modname = c_buffer(51) - mapping = {} - for pid in cls.getPids(): - # Get handle to the process based on PID - hProcess = KERNEL.OpenProcess(PROCESS_FLAGS, False, pid) - if hProcess: - PSAPI.EnumProcessModules(hProcess, byref(hModule), - sizeof(hModule), byref(count)) - PSAPI.GetModuleBaseNameA(hProcess, hModule.value, modname, - sizeof(modname)) - try: - name = u"".join([c for c in modname if c != NULL]) - except UnicodeError, msg: - LOG.exception("Can't decode name of pid %s" % pid) - else: - mapping[pid] = name - modname[:] = sizeof(modname) * NULL - KERNEL.CloseHandle(hProcess) - - return mapping - - @classmethod - def getPidDetails(cls, pid): - """Get detailed informations about a process - """ - if pid == 'self': - pid = os.getpid() - - hModule = c_ulong() - count = c_ulong() - modname = c_buffer(51) - hProcess = KERNEL.OpenProcess(PROCESS_FLAGS, False, pid) - if not hProcess: - return None - - PSAPI.EnumProcessModules(hProcess, byref(hModule), - sizeof(hModule), byref(count)) - PSAPI.GetModuleBaseNameA(hProcess, hModule.value, modname, - sizeof(modname)) - try: - name = u"".join([c for c in modname if c != NULL]) - except UnicodeError, msg: - LOG.exception("Can't decode name of pid %s" % pid) - else: - name = None - - KERNEL.CloseHandle(hProcess) - return {'name' : name} - - -# Initialize global methods -_enumProcesses = None -for impl in (WinEnumProcesses(), LinuxProcReader(), PsParser()): - if impl.supported(): - impl.log() - _enumProcesses = impl - break - -if _enumProcesses is None: - LOG.error("System %s is not supported" % sys.platform) - _enumProcesses = Unsupported() - -getPids = _enumProcesses.getPids -getPidNames = _enumProcesses.getPidNames -getPidDetails = _enumProcesses.getPidDetails -supportedOS = _enumProcesses.supported() - -def test_suite(): - import unittest - from doctest import DocTestSuite - return unittest.TestSuite(( - DocTestSuite() - )) - -if __name__ == '__main__': - import unittest - logging.basicConfig() - unittest.main(defaultTest="test_suite") - print getPids() - print getPidNames() Modified: pymoul/trunk/src/moul/osdependent/win32/__init__.py =================================================================== --- pymoul/trunk/src/moul/osdependent/win32/__init__.py 2007-02-27 14:32:21 UTC (rev 204) +++ pymoul/trunk/src/moul/osdependent/win32/__init__.py 2007-02-27 14:45:53 UTC (rev 205) @@ -22,10 +22,10 @@ __revision__ = "$Revision$" import os +from enumprocess import getPidNames +from logging import getLogger from subprocess import Popen -from logging import getLogger -from moul.osdependent.processinfo import getPidNames from moul.osdependent.win32 import winpath This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ti...@us...> - 2007-02-27 14:32:21
|
Revision: 204 http://pymoul.svn.sourceforge.net/pymoul/?rev=204&view=rev Author: tiran Date: 2007-02-27 06:32:21 -0800 (Tue, 27 Feb 2007) Log Message: ----------- Tagging 0.1 release Added Paths: ----------- enumprocess/tags/0.1/ enumprocess/tags/0.1/CHANGES.txt enumprocess/tags/0.1/INSTALL.txt enumprocess/tags/0.1/LICENSE.txt enumprocess/tags/0.1/README.txt enumprocess/tags/0.1/ez_setup.py enumprocess/tags/0.1/setup.py enumprocess/tags/0.1/src/enumprocess/__init__.py enumprocess/tags/0.1/src/enumprocess/processinfo.py enumprocess/tags/0.1/src/enumprocess.egg-info/SOURCES.txt enumprocess/tags/0.1/src/enumprocess.egg-info/dependency_links.txt enumprocess/tags/0.1/src/enumprocess.egg-info/top_level.txt enumprocess/tags/0.1/version.txt Removed Paths: ------------- enumprocess/tags/0.1/CHANGES.txt enumprocess/tags/0.1/INSTALL.txt enumprocess/tags/0.1/LICENSE.txt enumprocess/tags/0.1/README.txt enumprocess/tags/0.1/ez_setup.py enumprocess/tags/0.1/setup.py enumprocess/tags/0.1/src/enumprocess/__init__.py enumprocess/tags/0.1/src/enumprocess/processinfo.py enumprocess/tags/0.1/src/enumprocess.egg-info/SOURCES.txt enumprocess/tags/0.1/src/enumprocess.egg-info/dependency_links.txt enumprocess/tags/0.1/src/enumprocess.egg-info/top_level.txt enumprocess/tags/0.1/version.txt Copied: enumprocess/tags/0.1 (from rev 202, enumprocess/trunk) Deleted: enumprocess/tags/0.1/CHANGES.txt =================================================================== Copied: enumprocess/tags/0.1/CHANGES.txt (from rev 203, enumprocess/trunk/CHANGES.txt) =================================================================== Deleted: enumprocess/tags/0.1/INSTALL.txt =================================================================== --- enumprocess/trunk/INSTALL.txt 2007-02-27 14:29:15 UTC (rev 202) +++ enumprocess/tags/0.1/INSTALL.txt 2007-02-27 14:32:21 UTC (rev 204) @@ -1,13 +0,0 @@ -============ -Requirements -============ - - * Python 2.4+ http://www.python.org/ - * easy_install http://peak.telecommunity.com/DevCenter/EasyInstall - * setuptools (via easy install) - -============ -Installation -============ - - $ python setup.py install Copied: enumprocess/tags/0.1/INSTALL.txt (from rev 203, enumprocess/trunk/INSTALL.txt) =================================================================== --- enumprocess/tags/0.1/INSTALL.txt (rev 0) +++ enumprocess/tags/0.1/INSTALL.txt 2007-02-27 14:32:21 UTC (rev 204) @@ -0,0 +1,13 @@ +============ +Requirements +============ + + * Python 2.4+ http://www.python.org/ + * easy_install http://peak.telecommunity.com/DevCenter/EasyInstall + * setuptools (via easy install) + +============ +Installation +============ + + $ python setup.py install Deleted: enumprocess/tags/0.1/LICENSE.txt =================================================================== --- enumprocess/trunk/LICENSE.txt 2007-02-27 14:29:15 UTC (rev 202) +++ enumprocess/tags/0.1/LICENSE.txt 2007-02-27 14:32:21 UTC (rev 204) @@ -1,29 +0,0 @@ -Copyright (c) 2007 Christian Heimes. All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - - 1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in - the documentation and/or other materials provided with the - distribution. - - 3. Neither the name of Infrae nor the names of its contributors may - be used to endorse or promote products derived from this software - without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INFRAE OR -CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Copied: enumprocess/tags/0.1/LICENSE.txt (from rev 203, enumprocess/trunk/LICENSE.txt) =================================================================== --- enumprocess/tags/0.1/LICENSE.txt (rev 0) +++ enumprocess/tags/0.1/LICENSE.txt 2007-02-27 14:32:21 UTC (rev 204) @@ -0,0 +1,29 @@ +Copyright (c) 2007 Christian Heimes. All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + + 3. Neither the name of Infrae nor the names of its contributors may + be used to endorse or promote products derived from this software + without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INFRAE OR +CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Deleted: enumprocess/tags/0.1/README.txt =================================================================== --- enumprocess/trunk/README.txt 2007-02-27 14:29:15 UTC (rev 202) +++ enumprocess/tags/0.1/README.txt 2007-02-27 14:32:21 UTC (rev 204) @@ -1,17 +0,0 @@ -enumprocess -=========== - -The package contains for implementations: - - - an Unsupported implementation that raises UnsupportedError - - a Linux implementation that read the data from /proc - - a Unix/POSIX implementation that parses the output of ps - - a Windows implementation that uses ctypes to get the infos from psapi.dll - -API -=== - -getPids() - list of ints/longs -getPidNames() - mapping pid -> name -getPidDetails(pid) - detailed informations about a process -getPidDetails('self') - detailed informations about current process \ No newline at end of file Copied: enumprocess/tags/0.1/README.txt (from rev 203, enumprocess/trunk/README.txt) =================================================================== --- enumprocess/tags/0.1/README.txt (rev 0) +++ enumprocess/tags/0.1/README.txt 2007-02-27 14:32:21 UTC (rev 204) @@ -0,0 +1,17 @@ +enumprocess +=========== + +The package contains for implementations: + + - an Unsupported implementation that raises UnsupportedError + - a Linux implementation that read the data from /proc + - a Unix/POSIX implementation that parses the output of ps + - a Windows implementation that uses ctypes to get the infos from psapi.dll + +API +=== + +getPids() - list of ints/longs +getPidNames() - mapping pid -> name +getPidDetails(pid) - detailed informations about a process +getPidDetails('self') - detailed informations about current process \ No newline at end of file Deleted: enumprocess/tags/0.1/ez_setup.py =================================================================== --- enumprocess/trunk/ez_setup.py 2007-02-27 14:29:15 UTC (rev 202) +++ enumprocess/tags/0.1/ez_setup.py 2007-02-27 14:32:21 UTC (rev 204) @@ -1,228 +0,0 @@ -#!python -"""Bootstrap setuptools installation - -If you want to use setuptools in your package's setup.py, just include this -file in the same directory with it, and add this to the top of your setup.py:: - - from ez_setup import use_setuptools - use_setuptools() - -If you want to require a specific version of setuptools, set a download -mirror, or use an alternate download directory, you can do so by supplying -the appropriate options to ``use_setuptools()``. - -This file can also be run as a script to install or upgrade setuptools. -""" -import sys -DEFAULT_VERSION = "0.6c5" -DEFAULT_URL = "http://cheeseshop.python.org/packages/%s/s/setuptools/" % sys.version[:3] - -md5_data = { - 'setuptools-0.6b1-py2.3.egg': '8822caf901250d848b996b7f25c6e6ca', - 'setuptools-0.6b1-py2.4.egg': 'b79a8a403e4502fbb85ee3f1941735cb', - 'setuptools-0.6b2-py2.3.egg': '5657759d8a6d8fc44070a9d07272d99b', - 'setuptools-0.6b2-py2.4.egg': '4996a8d169d2be661fa32a6e52e4f82a', - 'setuptools-0.6b3-py2.3.egg': 'bb31c0fc7399a63579975cad9f5a0618', - 'setuptools-0.6b3-py2.4.egg': '38a8c6b3d6ecd22247f179f7da669fac', - 'setuptools-0.6b4-py2.3.egg': '62045a24ed4e1ebc77fe039aa4e6f7e5', - 'setuptools-0.6b4-py2.4.egg': '4cb2a185d228dacffb2d17f103b3b1c4', - 'setuptools-0.6c1-py2.3.egg': 'b3f2b5539d65cb7f74ad79127f1a908c', - 'setuptools-0.6c1-py2.4.egg': 'b45adeda0667d2d2ffe14009364f2a4b', - 'setuptools-0.6c2-py2.3.egg': 'f0064bf6aa2b7d0f3ba0b43f20817c27', - 'setuptools-0.6c2-py2.4.egg': '616192eec35f47e8ea16cd6a122b7277', - 'setuptools-0.6c3-py2.3.egg': 'f181fa125dfe85a259c9cd6f1d7b78fa', - 'setuptools-0.6c3-py2.4.egg': 'e0ed74682c998bfb73bf803a50e7b71e', - 'setuptools-0.6c3-py2.5.egg': 'abef16fdd61955514841c7c6bd98965e', - 'setuptools-0.6c4-py2.3.egg': 'b0b9131acab32022bfac7f44c5d7971f', - 'setuptools-0.6c4-py2.4.egg': '2a1f9656d4fbf3c97bf946c0a124e6e2', - 'setuptools-0.6c4-py2.5.egg': '8f5a052e32cdb9c72bcf4b5526f28afc', - 'setuptools-0.6c5-py2.3.egg': 'ee9fd80965da04f2f3e6b3576e9d8167', - 'setuptools-0.6c5-py2.4.egg': 'afe2adf1c01701ee841761f5bcd8aa64', - 'setuptools-0.6c5-py2.5.egg': 'a8d3f61494ccaa8714dfed37bccd3d5d', -} - -import sys, os - -def _validate_md5(egg_name, data): - if egg_name in md5_data: - from md5 import md5 - digest = md5(data).hexdigest() - if digest != md5_data[egg_name]: - print >>sys.stderr, ( - "md5 validation of %s failed! (Possible download problem?)" - % egg_name - ) - sys.exit(2) - return data - - -def use_setuptools( - version=DEFAULT_VERSION, download_base=DEFAULT_URL, to_dir=os.curdir, - download_delay=15 -): - """Automatically find/download setuptools and make it available on sys.path - - `version` should be a valid setuptools version number that is available - as an egg for download under the `download_base` URL (which should end with - a '/'). `to_dir` is the directory where setuptools will be downloaded, if - it is not already available. If `download_delay` is specified, it should - be the number of seconds that will be paused before initiating a download, - should one be required. If an older version of setuptools is installed, - this routine will print a message to ``sys.stderr`` and raise SystemExit in - an attempt to abort the calling script. - """ - try: - import setuptools - if setuptools.__version__ == '0.0.1': - print >>sys.stderr, ( - "You have an obsolete version of setuptools installed. Please\n" - "remove it from your system entirely before rerunning this script." - ) - sys.exit(2) - except ImportError: - egg = download_setuptools(version, download_base, to_dir, download_delay) - sys.path.insert(0, egg) - import setuptools; setuptools.bootstrap_install_from = egg - - import pkg_resources - try: - pkg_resources.require("setuptools>="+version) - - except pkg_resources.VersionConflict, e: - # XXX could we install in a subprocess here? - print >>sys.stderr, ( - "The required version of setuptools (>=%s) is not available, and\n" - "can't be installed while this script is running. Please install\n" - " a more recent version first.\n\n(Currently using %r)" - ) % (version, e.args[0]) - sys.exit(2) - -def download_setuptools( - version=DEFAULT_VERSION, download_base=DEFAULT_URL, to_dir=os.curdir, - delay = 15 -): - """Download setuptools from a specified location and return its filename - - `version` should be a valid setuptools version number that is available - as an egg for download under the `download_base` URL (which should end - with a '/'). `to_dir` is the directory where the egg will be downloaded. - `delay` is the number of seconds to pause before an actual download attempt. - """ - import urllib2, shutil - egg_name = "setuptools-%s-py%s.egg" % (version,sys.version[:3]) - url = download_base + egg_name - saveto = os.path.join(to_dir, egg_name) - src = dst = None - if not os.path.exists(saveto): # Avoid repeated downloads - try: - from distutils import log - if delay: - log.warn(""" ---------------------------------------------------------------------------- -This script requires setuptools version %s to run (even to display -help). I will attempt to download it for you (from -%s), but -you may need to enable firewall access for this script first. -I will start the download in %d seconds. - -(Note: if this machine does not have network access, please obtain the file - - %s - -and place it in this directory before rerunning this script.) ----------------------------------------------------------------------------""", - version, download_base, delay, url - ); from time import sleep; sleep(delay) - log.warn("Downloading %s", url) - src = urllib2.urlopen(url) - # Read/write all in one block, so we don't create a corrupt file - # if the download is interrupted. - data = _validate_md5(egg_name, src.read()) - dst = open(saveto,"wb"); dst.write(data) - finally: - if src: src.close() - if dst: dst.close() - return os.path.realpath(saveto) - -def main(argv, version=DEFAULT_VERSION): - """Install or upgrade setuptools and EasyInstall""" - - try: - import setuptools - except ImportError: - egg = None - try: - egg = download_setuptools(version, delay=0) - sys.path.insert(0,egg) - from setuptools.command.easy_install import main - return main(list(argv)+[egg]) # we're done here - finally: - if egg and os.path.exists(egg): - os.unlink(egg) - else: - if setuptools.__version__ == '0.0.1': - # tell the user to uninstall obsolete version - use_setuptools(version) - - req = "setuptools>="+version - import pkg_resources - try: - pkg_resources.require(req) - except pkg_resources.VersionConflict: - try: - from setuptools.command.easy_install import main - except ImportError: - from easy_install import main - main(list(argv)+[download_setuptools(delay=0)]) - sys.exit(0) # try to force an exit - else: - if argv: - from setuptools.command.easy_install import main - main(argv) - else: - print "Setuptools version",version,"or greater has been installed." - print '(Run "ez_setup.py -U setuptools" to reinstall or upgrade.)' - - - -def update_md5(filenames): - """Update our built-in md5 registry""" - - import re - from md5 import md5 - - for name in filenames: - base = os.path.basename(name) - f = open(name,'rb') - md5_data[base] = md5(f.read()).hexdigest() - f.close() - - data = [" %r: %r,\n" % it for it in md5_data.items()] - data.sort() - repl = "".join(data) - - import inspect - srcfile = inspect.getsourcefile(sys.modules[__name__]) - f = open(srcfile, 'rb'); src = f.read(); f.close() - - match = re.search("\nmd5_data = {\n([^}]+)}", src) - if not match: - print >>sys.stderr, "Internal error!" - sys.exit(2) - - src = src[:match.start(1)] + repl + src[match.end(1):] - f = open(srcfile,'w') - f.write(src) - f.close() - - -if __name__=='__main__': - if len(sys.argv)>2 and sys.argv[1]=='--md5update': - update_md5(sys.argv[2:]) - else: - main(sys.argv[1:]) - - - - - Copied: enumprocess/tags/0.1/ez_setup.py (from rev 203, enumprocess/trunk/ez_setup.py) =================================================================== --- enumprocess/tags/0.1/ez_setup.py (rev 0) +++ enumprocess/tags/0.1/ez_setup.py 2007-02-27 14:32:21 UTC (rev 204) @@ -0,0 +1,228 @@ +#!python +"""Bootstrap setuptools installation + +If you want to use setuptools in your package's setup.py, just include this +file in the same directory with it, and add this to the top of your setup.py:: + + from ez_setup import use_setuptools + use_setuptools() + +If you want to require a specific version of setuptools, set a download +mirror, or use an alternate download directory, you can do so by supplying +the appropriate options to ``use_setuptools()``. + +This file can also be run as a script to install or upgrade setuptools. +""" +import sys +DEFAULT_VERSION = "0.6c5" +DEFAULT_URL = "http://cheeseshop.python.org/packages/%s/s/setuptools/" % sys.version[:3] + +md5_data = { + 'setuptools-0.6b1-py2.3.egg': '8822caf901250d848b996b7f25c6e6ca', + 'setuptools-0.6b1-py2.4.egg': 'b79a8a403e4502fbb85ee3f1941735cb', + 'setuptools-0.6b2-py2.3.egg': '5657759d8a6d8fc44070a9d07272d99b', + 'setuptools-0.6b2-py2.4.egg': '4996a8d169d2be661fa32a6e52e4f82a', + 'setuptools-0.6b3-py2.3.egg': 'bb31c0fc7399a63579975cad9f5a0618', + 'setuptools-0.6b3-py2.4.egg': '38a8c6b3d6ecd22247f179f7da669fac', + 'setuptools-0.6b4-py2.3.egg': '62045a24ed4e1ebc77fe039aa4e6f7e5', + 'setuptools-0.6b4-py2.4.egg': '4cb2a185d228dacffb2d17f103b3b1c4', + 'setuptools-0.6c1-py2.3.egg': 'b3f2b5539d65cb7f74ad79127f1a908c', + 'setuptools-0.6c1-py2.4.egg': 'b45adeda0667d2d2ffe14009364f2a4b', + 'setuptools-0.6c2-py2.3.egg': 'f0064bf6aa2b7d0f3ba0b43f20817c27', + 'setuptools-0.6c2-py2.4.egg': '616192eec35f47e8ea16cd6a122b7277', + 'setuptools-0.6c3-py2.3.egg': 'f181fa125dfe85a259c9cd6f1d7b78fa', + 'setuptools-0.6c3-py2.4.egg': 'e0ed74682c998bfb73bf803a50e7b71e', + 'setuptools-0.6c3-py2.5.egg': 'abef16fdd61955514841c7c6bd98965e', + 'setuptools-0.6c4-py2.3.egg': 'b0b9131acab32022bfac7f44c5d7971f', + 'setuptools-0.6c4-py2.4.egg': '2a1f9656d4fbf3c97bf946c0a124e6e2', + 'setuptools-0.6c4-py2.5.egg': '8f5a052e32cdb9c72bcf4b5526f28afc', + 'setuptools-0.6c5-py2.3.egg': 'ee9fd80965da04f2f3e6b3576e9d8167', + 'setuptools-0.6c5-py2.4.egg': 'afe2adf1c01701ee841761f5bcd8aa64', + 'setuptools-0.6c5-py2.5.egg': 'a8d3f61494ccaa8714dfed37bccd3d5d', +} + +import sys, os + +def _validate_md5(egg_name, data): + if egg_name in md5_data: + from md5 import md5 + digest = md5(data).hexdigest() + if digest != md5_data[egg_name]: + print >>sys.stderr, ( + "md5 validation of %s failed! (Possible download problem?)" + % egg_name + ) + sys.exit(2) + return data + + +def use_setuptools( + version=DEFAULT_VERSION, download_base=DEFAULT_URL, to_dir=os.curdir, + download_delay=15 +): + """Automatically find/download setuptools and make it available on sys.path + + `version` should be a valid setuptools version number that is available + as an egg for download under the `download_base` URL (which should end with + a '/'). `to_dir` is the directory where setuptools will be downloaded, if + it is not already available. If `download_delay` is specified, it should + be the number of seconds that will be paused before initiating a download, + should one be required. If an older version of setuptools is installed, + this routine will print a message to ``sys.stderr`` and raise SystemExit in + an attempt to abort the calling script. + """ + try: + import setuptools + if setuptools.__version__ == '0.0.1': + print >>sys.stderr, ( + "You have an obsolete version of setuptools installed. Please\n" + "remove it from your system entirely before rerunning this script." + ) + sys.exit(2) + except ImportError: + egg = download_setuptools(version, download_base, to_dir, download_delay) + sys.path.insert(0, egg) + import setuptools; setuptools.bootstrap_install_from = egg + + import pkg_resources + try: + pkg_resources.require("setuptools>="+version) + + except pkg_resources.VersionConflict, e: + # XXX could we install in a subprocess here? + print >>sys.stderr, ( + "The required version of setuptools (>=%s) is not available, and\n" + "can't be installed while this script is running. Please install\n" + " a more recent version first.\n\n(Currently using %r)" + ) % (version, e.args[0]) + sys.exit(2) + +def download_setuptools( + version=DEFAULT_VERSION, download_base=DEFAULT_URL, to_dir=os.curdir, + delay = 15 +): + """Download setuptools from a specified location and return its filename + + `version` should be a valid setuptools version number that is available + as an egg for download under the `download_base` URL (which should end + with a '/'). `to_dir` is the directory where the egg will be downloaded. + `delay` is the number of seconds to pause before an actual download attempt. + """ + import urllib2, shutil + egg_name = "setuptools-%s-py%s.egg" % (version,sys.version[:3]) + url = download_base + egg_name + saveto = os.path.join(to_dir, egg_name) + src = dst = None + if not os.path.exists(saveto): # Avoid repeated downloads + try: + from distutils import log + if delay: + log.warn(""" +--------------------------------------------------------------------------- +This script requires setuptools version %s to run (even to display +help). I will attempt to download it for you (from +%s), but +you may need to enable firewall access for this script first. +I will start the download in %d seconds. + +(Note: if this machine does not have network access, please obtain the file + + %s + +and place it in this directory before rerunning this script.) +---------------------------------------------------------------------------""", + version, download_base, delay, url + ); from time import sleep; sleep(delay) + log.warn("Downloading %s", url) + src = urllib2.urlopen(url) + # Read/write all in one block, so we don't create a corrupt file + # if the download is interrupted. + data = _validate_md5(egg_name, src.read()) + dst = open(saveto,"wb"); dst.write(data) + finally: + if src: src.close() + if dst: dst.close() + return os.path.realpath(saveto) + +def main(argv, version=DEFAULT_VERSION): + """Install or upgrade setuptools and EasyInstall""" + + try: + import setuptools + except ImportError: + egg = None + try: + egg = download_setuptools(version, delay=0) + sys.path.insert(0,egg) + from setuptools.command.easy_install import main + return main(list(argv)+[egg]) # we're done here + finally: + if egg and os.path.exists(egg): + os.unlink(egg) + else: + if setuptools.__version__ == '0.0.1': + # tell the user to uninstall obsolete version + use_setuptools(version) + + req = "setuptools>="+version + import pkg_resources + try: + pkg_resources.require(req) + except pkg_resources.VersionConflict: + try: + from setuptools.command.easy_install import main + except ImportError: + from easy_install import main + main(list(argv)+[download_setuptools(delay=0)]) + sys.exit(0) # try to force an exit + else: + if argv: + from setuptools.command.easy_install import main + main(argv) + else: + print "Setuptools version",version,"or greater has been installed." + print '(Run "ez_setup.py -U setuptools" to reinstall or upgrade.)' + + + +def update_md5(filenames): + """Update our built-in md5 registry""" + + import re + from md5 import md5 + + for name in filenames: + base = os.path.basename(name) + f = open(name,'rb') + md5_data[base] = md5(f.read()).hexdigest() + f.close() + + data = [" %r: %r,\n" % it for it in md5_data.items()] + data.sort() + repl = "".join(data) + + import inspect + srcfile = inspect.getsourcefile(sys.modules[__name__]) + f = open(srcfile, 'rb'); src = f.read(); f.close() + + match = re.search("\nmd5_data = {\n([^}]+)}", src) + if not match: + print >>sys.stderr, "Internal error!" + sys.exit(2) + + src = src[:match.start(1)] + repl + src[match.end(1):] + f = open(srcfile,'w') + f.write(src) + f.close() + + +if __name__=='__main__': + if len(sys.argv)>2 and sys.argv[1]=='--md5update': + update_md5(sys.argv[2:]) + else: + main(sys.argv[1:]) + + + + + Deleted: enumprocess/tags/0.1/setup.py =================================================================== --- enumprocess/trunk/setup.py 2007-02-27 14:29:15 UTC (rev 202) +++ enumprocess/tags/0.1/setup.py 2007-02-27 14:32:21 UTC (rev 204) @@ -1,64 +0,0 @@ -#!/usr/bin/env python -"""enumprocess: list pids and processes - -TODO: long description -""" -__author__ = "Christian Heimes" -__version__ = "$Id$" -__revision__ = "$Revision$" - -import sys - -if sys.version_info < (2,4): - raise RuntimeError("Python 2.4+ required:\n%s" % sys.version) - -# boot strap easy setup -SETUPTOOLS_VERSION = "0.6c1" -from ez_setup import use_setuptools -use_setuptools(version=SETUPTOOLS_VERSION) - -# import the rest -from setuptools import setup -from setuptools import find_packages - -from distutils.core import setup - -VERSION = "0.1" - -me = "Christian Heimes" -email = "chr...@ch..." - -setup_infos = dict( - name = "enumprocess", - version = VERSION, - description = __doc__[:__doc__.find('\n')].strip(), - long_description = '\n'.join([line - for line in __doc__.split('\n')[1:]]), - author = "Christian Heimes", - author_email = "chr...@ch...", - maintainer = "Christian Heimes", - maintainer_email = "chr...@ch...", - url = "http://sourceforge.net/projects/pymoul/", - download_url= "http://cheeseshop.python.org/pypi/enumprocess", - license = "BSD License", - keywords = ["pid", "process", "enum", "proc", "ps", "psapi"], - platforms=['Independant'], - classifiers = ( - 'Development Status :: 4 - Beta', - 'Intended Audience :: Developers', - 'License :: OSI Approved :: BSD License', - 'Natural Language :: English', - 'Operating System :: Microsoft :: Windows', - 'Operating System :: POSIX', - 'Operating System :: POSIX :: Linux', - 'Programming Language :: Python', - 'Topic :: System', - 'Topic :: Software Development :: Libraries' - ), - setup_requires = ["setuptools>="+SETUPTOOLS_VERSION,], - packages = ['enumprocess'], - package_dir = {'' : 'src'}, - zip_safe = True, -) - -setup(**setup_infos) Copied: enumprocess/tags/0.1/setup.py (from rev 203, enumprocess/trunk/setup.py) =================================================================== --- enumprocess/tags/0.1/setup.py (rev 0) +++ enumprocess/tags/0.1/setup.py 2007-02-27 14:32:21 UTC (rev 204) @@ -0,0 +1,64 @@ +#!/usr/bin/env python +"""enumprocess: list pids and processes + +TODO: long description +""" +__author__ = "Christian Heimes" +__version__ = "$Id$" +__revision__ = "$Revision$" + +import sys + +if sys.version_info < (2,4): + raise RuntimeError("Python 2.4+ required:\n%s" % sys.version) + +# boot strap easy setup +SETUPTOOLS_VERSION = "0.6c1" +from ez_setup import use_setuptools +use_setuptools(version=SETUPTOOLS_VERSION) + +# import the rest +from setuptools import setup +from setuptools import find_packages + +from distutils.core import setup + +VERSION = "0.1" + +me = "Christian Heimes" +email = "chr...@ch..." + +setup_infos = dict( + name = "enumprocess", + version = VERSION, + description = __doc__[:__doc__.find('\n')].strip(), + long_description = '\n'.join([line + for line in __doc__.split('\n')[1:]]), + author = "Christian Heimes", + author_email = "chr...@ch...", + maintainer = "Christian Heimes", + maintainer_email = "chr...@ch...", + url = "http://sourceforge.net/projects/pymoul/", + download_url= "http://cheeseshop.python.org/pypi/enumprocess", + license = "BSD License", + keywords = ["pid", "process", "enum", "proc", "ps", "psapi"], + platforms=['Independant'], + classifiers = ( + 'Development Status :: 4 - Beta', + 'Intended Audience :: Developers', + 'License :: OSI Approved :: BSD License', + 'Natural Language :: English', + 'Operating System :: Microsoft :: Windows', + 'Operating System :: POSIX', + 'Operating System :: POSIX :: Linux', + 'Programming Language :: Python', + 'Topic :: System', + 'Topic :: Software Development :: Libraries' + ), + setup_requires = ["setuptools>="+SETUPTOOLS_VERSION,], + packages = ['enumprocess'], + package_dir = {'' : 'src'}, + zip_safe = True, +) + +setup(**setup_infos) Deleted: enumprocess/tags/0.1/src/enumprocess/__init__.py =================================================================== --- enumprocess/trunk/src/enumprocess/__init__.py 2007-02-27 14:29:15 UTC (rev 202) +++ enumprocess/tags/0.1/src/enumprocess/__init__.py 2007-02-27 14:32:21 UTC (rev 204) @@ -1,32 +0,0 @@ -# Copyright (c) 2007 Christian Heimes. All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are -# met: -# -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in -# the documentation and/or other materials provided with the -# distribution. -# -# 3. Neither the name of Infrae nor the names of its contributors may -# be used to endorse or promote products derived from this software -# without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INFRAE OR -# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -"""enum processes -""" -from processinfo import * Copied: enumprocess/tags/0.1/src/enumprocess/__init__.py (from rev 203, enumprocess/trunk/src/enumprocess/__init__.py) =================================================================== --- enumprocess/tags/0.1/src/enumprocess/__init__.py (rev 0) +++ enumprocess/tags/0.1/src/enumprocess/__init__.py 2007-02-27 14:32:21 UTC (rev 204) @@ -0,0 +1,32 @@ +# Copyright (c) 2007 Christian Heimes. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# +# 3. Neither the name of Infrae nor the names of its contributors may +# be used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INFRAE OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +"""enum processes +""" +from processinfo import * Deleted: enumprocess/tags/0.1/src/enumprocess/processinfo.py =================================================================== --- enumprocess/trunk/src/enumprocess/processinfo.py 2007-02-27 14:29:15 UTC (rev 202) +++ enumprocess/tags/0.1/src/enumprocess/processinfo.py 2007-02-27 14:32:21 UTC (rev 204) @@ -1,477 +0,0 @@ -# Copyright (c) 2007 Christian Heimes. All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are -# met: -# -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in -# the documentation and/or other materials provided with the -# distribution. -# -# 3. Neither the name of Infrae nor the names of its contributors may -# be used to endorse or promote products derived from this software -# without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INFRAE OR -# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, -# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, -# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -"""Get process informations - -The module contains for implementations: - - - an Unsupported implementation that raises UnsupportedError - - a Linux implementation that read the data from /proc - - a Unix/POSIX implementation that parses the output of ps - - a Windows implementation that uses ctypes to get the infos from psapi.dll - -API -=== - getPids() - list of ints/longs - getPidNames() - mapping pid -> name - getPidDetails(pid) - detailed informations about a process - getPidDetails('self') - detailed informations about current process - ->>> cur = os.getpid() ->>> exe = sys.executable ->>> pids = getPids() ->>> pids > 1 -True ->>> isinstance(pids[0], (int, long)) -True ->>> cur in pids -True - ->>> mapping = getPidNames() ->>> cur in mapping -True ->>> mapping[cur].lower() in sys.executable -True - ->>> getPidDetails('self')['name'] == getPidDetails(cur)['name'] -True ->>> getPidDetails(cur)['name'] == mapping[cur] -True - ->>> for impl in (WinEnumProcesses(), LinuxProcReader(), PsParser()): -... if impl.supported(): -... isinstance(impl.getPids(), list) and None -... isinstance(impl.getPidNames(), dict) and None -""" -__author__ = "Christian Heimes" -__version__ = "$Id$" -__revision__ = "$Revision$" -__all__ = ['getPids', 'getPidNames', 'getPidDetails', 'supportedOS', - 'UnsupportedError'] - -import logging -import os -import os.path -import sys - - -LOG = logging.getLogger("processinfo") -NULL = "\x00" - -_plat = sys.platform.startswith -if _plat('win') or _plat('cygwin'): - from ctypes import windll, c_ulong, sizeof, c_buffer, byref - PSAPI = windll.psapi - KERNEL = windll.kernel32 - PROCESS_QUERY_INFORMATION = 0x0400 - PROCESS_VM_READ = 0x0010 - PROCESS_FLAGS = PROCESS_QUERY_INFORMATION | PROCESS_VM_READ -else: - from subprocess import Popen - from subprocess import PIPE - -class UnsupportedError(OSError): - """OS or command not supported error - """ - pass - -class Unsupported(object): - """Unsupported OS implementation - - Raises L{UnsupportedError} - """ - __slots__ = () - - @classmethod - def supported(cls): - """Supported flag property""" - return False - - @classmethod - def log(cls): - """Log information about the implementation""" - LOG.warning("Unsupported OS. Neither proc filesystem nor 'ps' works.") - - @classmethod - def getPids(cls): - """Get a list of pids - - @return: a list of pid numbers - @rtype: list(int) - """ - raise UnsupportedError - - @classmethod - def getPidNames(cls): - """Get a mapping of pid -> name - - @return: mapping of pid -> name - @rtype: dict(int:str) - """ - raise UnsupportedError - - @classmethod - def getPidDetails(pid): - """Get detailed informations about a process - - @param pid: pid number or 'self' - @type pid: int or basestring - @return: detailed information about a process - @rtype: dict(str:data) - """ - raise UnsupportedError - -class PsParser(object): - """Parse the output of the ps command - """ - __slots__ = () - - CMD = "ps -e --no-header --cols=1024" - PIDNAMES = "%s --format=pid,ucmd" % CMD - PIDS = "%s --format=pid" % CMD - - @classmethod - def supported(cls): - """Supported flag property""" - try: - cls._exec(cls.PIDS) - except Exception: # catch all! - return False - else: - return True - - @classmethod - def log(cls): - """Log information about the implementation""" - LOG.debug("Using the 'ps' command on POSIX os") - - @classmethod - def getPids(cls): - """Get a list of pids - """ - stdout = cls._exec(cls.PIDS) - if stdout is None: - return None - pids = [] - for line in stdout: - try: - pid = int(line.strip()) - except ValueError: - pass - else: - pids.append(pid) - return pids - - @classmethod - def getPidNames(cls): - """Get a list of pid -> name - """ - stdout = cls._exec(cls.PIDNAMES) - if stdout is None: - return None - mapping = {} - for line in stdout: - line = line.strip() - idx = line.find(' ') - pid, name = line[:idx], line[idx+1:] - try: - pid = int(pid) - except ValueError: - pass - else: - mapping[pid] = name - return mapping - - @classmethod - def getPidDetails(cls, pid): - """Get detailed informations about a process - - TODO - """ - if pid == 'self': - pid = os.getpid() - raise UnsupportedError("not implemented yet") - - @staticmethod - def _exec(cmd): - """Execute command cmd - - The method waits until the command has finished. It returns None of - something went wrong. - - @param cmd: Command to execute - @type cmd: str - @return: None or stdin as file like object - """ - try: - popen = Popen(cmd, shell=True, bufsize=-1, stdout=PIPE, - env = {'LC_ALL' : 'C'}) - rc = popen.wait() - except (OSError, ValueError): - LOG.exception("Failed to execute '%s'" % cmd) - return None - else: - if rc != 0: - LOG.error("'%s' returned with error code %i" % (cmd, rc)) - return None - else: - return popen.stdout - -class LinuxProcReader(object): - """Get process informations under Linux by reading /proc - - Tested under Linux, may work on other POSIX os with /proc, too. - """ - __slots__ = () - - PROC = "/proc" - - @classmethod - def supported(cls): - return os.path.isfile("%s/self/status" % cls.PROC) - - @classmethod - def log(cls): - """Log information about the implementation""" - LOG.debug("Using the proc filesystem on Linux") - - @classmethod - def getPids(cls): - """Get a list of pids - """ - pids = [] - for name in os.listdir(cls.PROC): - if os.path.isdir(cls.PROC + '/' + name): - try: - pids.append(int(name)) - except ValueError: - pass - return pids - - @classmethod - def getPidNames(cls): - """Get a list of pid -> name - """ - mapping = {} - for pid in cls.getPids(): - name = cls._readProcStatus(pid, searchkey='name') - if name is not None: - mapping[pid] = name - return mapping - - def getPidDetails(cls, pid): - """Get detailed informations about a process - """ - details = cls._readProcStatus(pid) - if details is None: - return None - details.update(cls._readProcOther(pid)) - details['cmdline'] = cls._readProcCmdline(pid) - return details - - @classmethod - def _readProcStatus(cls, pid, searchkey=None): - """Read and parse status informations for PID pid - - pid - pid as long or int or 'self' - - If searchkey is None the method returns a mapping of lower keys - to values (stripped). - If searchkey is given than the method immediatly returns the value - or returns None if they key can't be found. - """ - mapping = {} - status = '%s/%s/status' % (cls.PROC, pid) - try: - # read entiry file to avoid race conditions - lines = open(status, 'r').readlines() - except IOError: - LOG.exception("%s not found" % status) - return None - for line in lines: - try: - key, value = line.split(':\t') - except ValueError: - continue - key = key.lower() - value = value.strip() - #if value.endswith(' kB'): - # value = value[:-3] - if key == searchkey: - return value - mapping[key.lower()] = value - if searchkey is not None: - return None - return mapping - - @classmethod - def _readProcCmdline(cls, pid): - """Read cmdline informations for pid and returns a list similar to sys.argv - """ - try: - # read entiry file to avoid race conditions - data = open('%s/%s/cmdline' % (cls.PROC, pid), 'r').read() - except IOError: - return None - return data.split(NULL) - - @classmethod - def _readProcOther(cls, pid): - """Read other possible useful things - - cwd -> current work directory (may not exist) - exe -> path to executable (may not exist) - """ - return { - 'cwd' : os.path.realpath('%s/%s/cwd' % (cls.PROC, pid)), - 'exe' : os.path.realpath('%s/%s/exe' % (cls.PROC, pid)), - } - -class WinEnumProcesses(object): - """""Get process informations under Win32 with psapi.dll - - Based on enumprocesses from Eric Koome - http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/305279 - """ - __slots__ = () - - @classmethod - def supported(cls): - try: - cls.getPids() - except Exception: # catch all! - return False - else: - return True - - @classmethod - def log(cls): - """Log information about the implementation""" - LOG.debug("Using ctypes on Windows") - - @classmethod - def getPids(cls): - """Get a list of pids - """ - arr = c_ulong * 256 - lpidProcess = arr() - cb = sizeof(lpidProcess) - cbNeeded = c_ulong() - - # Call Enumprocesses to get hold of process id's - PSAPI.EnumProcesses(byref(lpidProcess), cb, byref(cbNeeded)) - nReturned = cbNeeded.value/sizeof(c_ulong()) # number of processes returned - return [pid for pid in lpidProcess][:nReturned] - - @classmethod - def getPidNames(cls): - """Get a list of pid -> name - """ - hModule = c_ulong() - count = c_ulong() - modname = c_buffer(51) - mapping = {} - for pid in cls.getPids(): - # Get handle to the process based on PID - hProcess = KERNEL.OpenProcess(PROCESS_FLAGS, False, pid) - if hProcess: - PSAPI.EnumProcessModules(hProcess, byref(hModule), - sizeof(hModule), byref(count)) - PSAPI.GetModuleBaseNameA(hProcess, hModule.value, modname, - sizeof(modname)) - try: - name = u"".join([c for c in modname if c != NULL]) - except UnicodeError, msg: - LOG.exception("Can't decode name of pid %s" % pid) - else: - mapping[pid] = name - modname[:] = sizeof(modname) * NULL - KERNEL.CloseHandle(hProcess) - - return mapping - - @classmethod - def getPidDetails(cls, pid): - """Get detailed informations about a process - """ - if pid == 'self': - pid = os.getpid() - - hModule = c_ulong() - count = c_ulong() - modname = c_buffer(51) - hProcess = KERNEL.OpenProcess(PROCESS_FLAGS, False, pid) - if not hProcess: - return None - - PSAPI.EnumProcessModules(hProcess, byref(hModule), - sizeof(hModule), byref(count)) - PSAPI.GetModuleBaseNameA(hProcess, hModule.value, modname, - sizeof(modname)) - try: - name = u"".join([c for c in modname if c != NULL]) - except UnicodeError, msg: - LOG.exception("Can't decode name of pid %s" % pid) - else: - name = None - - KERNEL.CloseHandle(hProcess) - return {'name' : name} - - -# Initialize global methods -_enumProcesses = None -for impl in (WinEnumProcesses(), LinuxProcReader(), PsParser()): - if impl.supported(): - impl.log() - _enumProcesses = impl - break - -if _enumProcesses is None: - LOG.error("System %s is not supported" % sys.platform) - _enumProcesses = Unsupported() - -getPids = _enumProcesses.getPids -getPidNames = _enumProcesses.getPidNames -getPidDetails = _enumProcesses.getPidDetails -supportedOS = _enumProcesses.supported() - -def test_suite(): - import unittest - from doctest import DocTestSuite - return unittest.TestSuite(( - DocTestSuite() - )) - -if __name__ == '__main__': - import unittest - logging.basicConfig() - unittest.main(defaultTest="test_suite") - print getPids() - print getPidNames() Copied: enumprocess/tags/0.1/src/enumprocess/processinfo.py (from rev 203, enumprocess/trunk/src/enumprocess/processinfo.py) =================================================================== --- enumprocess/tags/0.1/src/enumprocess/processinfo.py (rev 0) +++ enumprocess/tags/0.1/src/enumprocess/processinfo.py 2007-02-27 14:32:21 UTC (rev 204) @@ -0,0 +1,477 @@ +# Copyright (c) 2007 Christian Heimes. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# +# 3. Neither the name of Infrae nor the names of its contributors may +# be used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INFRAE OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +"""Get process informations + +The module contains for implementations: + + - an Unsupported implementation that raises UnsupportedError + - a Linux implementation that read the data from /proc + - a Unix/POSIX implementation that parses the output of ps + - a Windows implementation that uses ctypes to get the infos from psapi.dll + +API +=== + getPids() - list of ints/longs + getPidNames() - mapping pid -> name + getPidDetails(pid) - detailed informations about a process + getPidDetails('self') - detailed informations about current process + +>>> cur = os.getpid() +>>> exe = sys.executable +>>> pids = getPids() +>>> pids > 1 +True +>>> isinstance(pids[0], (int, long)) +True +>>> cur in pids +True + +>>> mapping = getPidNames() +>>> cur in mapping +True +>>> mapping[cur].lower() in sys.executable +True + +>>> getPidDetails('self')['name'] == getPidDetails(cur)['name'] +True +>>> getPidDetails(cur)['name'] == mapping[cur] +True + +>>> for impl in (WinEnumProcesses(), LinuxProcReader(), PsParser()): +... if impl.supported(): +... isinstance(impl.getPids(), list) and None +... isinstance(impl.getPidNames(), dict) and None +""" +__author__ = "Christian Heimes" +__version__ = "$Id$" +__revision__ = "$Revision$" +__all__ = ['getPids', 'getPidNames', 'getPidDetails', 'supportedOS', + 'UnsupportedError'] + +import logging +import os +import os.path +import sys + + +LOG = logging.getLogger("processinfo") +NULL = "\x00" + +_plat = sys.platform.startswith +if _plat('win') or _plat('cygwin'): + from ctypes import windll, c_ulong, sizeof, c_buffer, byref + PSAPI = windll.psapi + KERNEL = windll.kernel32 + PROCESS_QUERY_INFORMATION = 0x0400 + PROCESS_VM_READ = 0x0010 + PROCESS_FLAGS = PROCESS_QUERY_INFORMATION | PROCESS_VM_READ +else: + from subprocess import Popen + from subprocess import PIPE + +class UnsupportedError(OSError): + """OS or command not supported error + """ + pass + +class Unsupported(object): + """Unsupported OS implementation + + Raises L{UnsupportedError} + """ + __slots__ = () + + @classmethod + def supported(cls): + """Supported flag property""" + return False + + @classmethod + def log(cls): + """Log information about the implementation""" + LOG.warning("Unsupported OS. Neither proc filesystem nor 'ps' works.") + + @classmethod + def getPids(cls): + """Get a list of pids + + @return: a list of pid numbers + @rtype: list(int) + """ + raise UnsupportedError + + @classmethod + def getPidNames(cls): + """Get a mapping of pid -> name + + @return: mapping of pid -> name + @rtype: dict(int:str) + """ + raise UnsupportedError + + @classmethod + def getPidDetails(pid): + """Get detailed informations about a process + + @param pid: pid number or 'self' + @type pid: int or basestring + @return: detailed information about a process + @rtype: dict(str:data) + """ + raise UnsupportedError + +class PsParser(object): + """Parse the output of the ps command + """ + __slots__ = () + + CMD = "ps -e --no-header --cols=1024" + PIDNAMES = "%s --format=pid,ucmd" % CMD + PIDS = "%s --format=pid" % CMD + + @classmethod + def supported(cls): + """Supported flag property""" + try: + cls._exec(cls.PIDS) + except Exception: # catch all! + return False + else: + return True + + @classmethod + def log(cls): + """Log information about the implementation""" + LOG.debug("Using the 'ps' command on POSIX os") + + @classmethod + def getPids(cls): + """Get a list of pids + """ + stdout = cls._exec(cls.PIDS) + if stdout is None: + return None + pids = [] + for line in stdout: + try: + pid = int(line.strip()) + except ValueError: + pass + else: + pids.append(pid) + return pids + + @classmethod + def getPidNames(cls): + """Get a list of pid -> name + """ + stdout = cls._exec(cls.PIDNAMES) + if stdout is None: + return None + mapping = {} + for line in stdout: + line = line.strip() + idx = line.find(' ') + pid, name = line[:idx], line[idx+1:] + try: + pid = int(pid) + except ValueError: + pass + else: + mapping[pid] = name + return mapping + + @classmethod + def getPidDetails(cls, pid): + """Get detailed informations about a process + + TODO + """ + if pid == 'self': + pid = os.getpid() + raise UnsupportedError("not implemented yet") + + @staticmethod + def _exec(cmd): + """Execute command cmd + + The method waits until the command has finished. It returns None of + something went wrong. + + @param cmd: Command to execute + @type cmd: str + @return: None or stdin as file like object + """ + try: + popen = Popen(cmd, shell=True, bufsize=-1, stdout=PIPE, + env = {'LC_ALL' : 'C'}) + rc = popen.wait() + except (OSError, ValueError): + LOG.exception("Failed to execute '%s'" % cmd) + return None + else: + if rc != 0: + LOG.error("'%s' returned with error code %i" % (cmd, rc)) + return None + else: + return popen.stdout + +class LinuxProcReader(object): + """Get process informations under Linux by reading /proc + + Tested under Linux, may work on other POSIX os with /proc, too. + """ + __slots__ = () + + PROC = "/proc" + + @classmethod + def supported(cls): + return os.path.isfile("%s/self/status" % cls.PROC) + + @classmethod + def log(cls): + """Log information about the implementation""" + LOG.debug("Using the proc filesystem on Linux") + + @classmethod + def getPids(cls): + """Get a list of pids + """ + pids = [] + for name in os.listdir(cls.PROC): + if os.path.isdir(cls.PROC + '/' + name): + try: + pids.append(int(name)) + except ValueError: + pass + return pids + + @classmethod + def getPidNames(cls): + """Get a list of pid -> name + """ + mapping = {} + for pid in cls.getPids(): + name = cls._readProcStatus(pid, searchkey='name') + if name is not None: + mapping[pid] = name + return mapping + + def getPidDetails(cls, pid): + """Get detailed informations about a process + """ + details = cls._readProcStatus(pid) + if details is None: + return None + details.update(cls._readProcOther(pid)) + details['cmdline'] = cls._readProcCmdline(pid) + return details + + @classmethod + def _readProcStatus(cls, pid, searchkey=None): + """Read and parse status informations for PID pid + + pid - pid as long or int or 'self' + + If searchkey is None the method returns a mapping of lower keys + to values (stripped). + If searchkey is given than the method immediatly returns the value + or returns None if they key can't be found. + """ + mapping = {} + status = '%s/%s/status' % (cls.PROC, pid) + try: + # read entiry file to avoid race conditions + lines = open(status, 'r').readlines() + except IOError: + LOG.exception("%s not found" % status) + return None + for line in lines: + try: + key, value = line.split(':\t') + except ValueError: + continue + key = key.lower() + value = value.strip() + #if value.endswith(' kB'): + # value = value[:-3] + if key == searchkey: + return value + mapping[key.lower()] = value + if searchkey is not None: + return None + return mapping + + @classmethod + def _readProcCmdline(cls, pid): + """Read cmdline informations for pid and returns a list similar to sys.argv + """ + try: + # read entiry file to avoid race conditions + data = open('%s/%s/cmdline' % (cls.PROC, pid), 'r').read() + except IOError: + return None + return data.split(NULL) + + @classmethod + def _readProcOther(cls, pid): + """Read other possible useful things + + cwd -> current work directory (may not exist) + exe -> path to executable (may not exist) + """ + return { + 'cwd' : os.path.realpath('%s/%s/cwd' % (cls.PROC, pid)), + 'exe' : os.path.realpath('%s/%s/exe' % (cls.PROC, pid)), + ... [truncated message content] |
From: <ti...@us...> - 2007-02-27 14:31:33
|
Revision: 203 http://pymoul.svn.sourceforge.net/pymoul/?rev=203&view=rev Author: tiran Date: 2007-02-27 06:31:27 -0800 (Tue, 27 Feb 2007) Log Message: ----------- propset Property Changed: ---------------- enumprocess/trunk/CHANGES.txt enumprocess/trunk/INSTALL.txt enumprocess/trunk/LICENSE.txt enumprocess/trunk/README.txt enumprocess/trunk/ez_setup.py enumprocess/trunk/setup.py enumprocess/trunk/src/enumprocess/__init__.py enumprocess/trunk/src/enumprocess/processinfo.py enumprocess/trunk/src/enumprocess.egg-info/SOURCES.txt enumprocess/trunk/src/enumprocess.egg-info/dependency_links.txt enumprocess/trunk/src/enumprocess.egg-info/top_level.txt enumprocess/trunk/version.txt Property changes on: enumprocess/trunk/CHANGES.txt ___________________________________________________________________ Name: svn:keywords + Id Revision Property changes on: enumprocess/trunk/INSTALL.txt ___________________________________________________________________ Name: svn:keywords + Id Revision Property changes on: enumprocess/trunk/LICENSE.txt ___________________________________________________________________ Name: svn:keywords + Id Revision Property changes on: enumprocess/trunk/README.txt ___________________________________________________________________ Name: svn:keywords + Id Revision Property changes on: enumprocess/trunk/ez_setup.py ___________________________________________________________________ Name: svn:keywords + Id Revision Property changes on: enumprocess/trunk/setup.py ___________________________________________________________________ Name: svn:keywords + Id Revision Property changes on: enumprocess/trunk/src/enumprocess/__init__.py ___________________________________________________________________ Name: svn:keywords + Id Revision Property changes on: enumprocess/trunk/src/enumprocess/processinfo.py ___________________________________________________________________ Name: svn:keywords + Id Revision Property changes on: enumprocess/trunk/src/enumprocess.egg-info/SOURCES.txt ___________________________________________________________________ Name: svn:keywords + Id Revision Property changes on: enumprocess/trunk/src/enumprocess.egg-info/dependency_links.txt ___________________________________________________________________ Name: svn:keywords + Id Revision Property changes on: enumprocess/trunk/src/enumprocess.egg-info/top_level.txt ___________________________________________________________________ Name: svn:keywords + Id Revision Property changes on: enumprocess/trunk/version.txt ___________________________________________________________________ Name: svn:keywords + Id Revision This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ti...@us...> - 2007-02-27 14:29:25
|
Revision: 202 http://pymoul.svn.sourceforge.net/pymoul/?rev=202&view=rev Author: tiran Date: 2007-02-27 06:29:15 -0800 (Tue, 27 Feb 2007) Log Message: ----------- Initial import of enumprocess Added Paths: ----------- enumprocess/ enumprocess/branches/ enumprocess/tags/ enumprocess/trunk/ enumprocess/trunk/CHANGES.txt enumprocess/trunk/INSTALL.txt enumprocess/trunk/LICENSE.txt enumprocess/trunk/MANIFEST.in enumprocess/trunk/Makefile enumprocess/trunk/PKG-INFO enumprocess/trunk/README.txt enumprocess/trunk/ez_setup.py enumprocess/trunk/setup.py enumprocess/trunk/src/ enumprocess/trunk/src/enumprocess/ enumprocess/trunk/src/enumprocess/__init__.py enumprocess/trunk/src/enumprocess/processinfo.py enumprocess/trunk/src/enumprocess.egg-info/ enumprocess/trunk/src/enumprocess.egg-info/PKG-INFO enumprocess/trunk/src/enumprocess.egg-info/SOURCES.txt enumprocess/trunk/src/enumprocess.egg-info/dependency_links.txt enumprocess/trunk/src/enumprocess.egg-info/top_level.txt enumprocess/trunk/src/enumprocess.egg-info/zip-safe enumprocess/trunk/version.txt Added: enumprocess/trunk/CHANGES.txt =================================================================== Added: enumprocess/trunk/INSTALL.txt =================================================================== --- enumprocess/trunk/INSTALL.txt (rev 0) +++ enumprocess/trunk/INSTALL.txt 2007-02-27 14:29:15 UTC (rev 202) @@ -0,0 +1,13 @@ +============ +Requirements +============ + + * Python 2.4+ http://www.python.org/ + * easy_install http://peak.telecommunity.com/DevCenter/EasyInstall + * setuptools (via easy install) + +============ +Installation +============ + + $ python setup.py install Added: enumprocess/trunk/LICENSE.txt =================================================================== --- enumprocess/trunk/LICENSE.txt (rev 0) +++ enumprocess/trunk/LICENSE.txt 2007-02-27 14:29:15 UTC (rev 202) @@ -0,0 +1,29 @@ +Copyright (c) 2007 Christian Heimes. All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + + 3. Neither the name of Infrae nor the names of its contributors may + be used to endorse or promote products derived from this software + without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INFRAE OR +CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Added: enumprocess/trunk/MANIFEST.in =================================================================== --- enumprocess/trunk/MANIFEST.in (rev 0) +++ enumprocess/trunk/MANIFEST.in 2007-02-27 14:29:15 UTC (rev 202) @@ -0,0 +1,3 @@ +include *.txt setup.py ez_setup.py Makefile +recursive-include src/enumprocess *.py + Added: enumprocess/trunk/Makefile =================================================================== --- enumprocess/trunk/Makefile (rev 0) +++ enumprocess/trunk/Makefile 2007-02-27 14:29:15 UTC (rev 202) @@ -0,0 +1,54 @@ +PYTHON?=python2.5 +PYTHON24=python2.4 +PYTHON25=python2.5 +TESTFLAGS=-v +TESTOPTS= +SETUPFLAGS= +KEYID=AD16AB1B + +all: inplace + +# Build in-place +inplace: + $(PYTHON) setup.py $(SETUPFLAGS) build_ext -i + +build: + $(PYTHON) setup.py $(SETUPFLAGS) build + +egg24: + $(PYTHON24) setup.py $(SETUPFLAGS) bdist_egg + +egg25: + $(PYTHON25) setup.py $(SETUPFLAGS) bdist_egg + +dist25: + $(PYTHON25) setup.py $(SETUPFLAGS) bdist_egg \ + sdist --formats=zip,gztar + +dist_upload: realclean + $(PYTHON25) setup.py $(SETUPFLAGS) bdist_egg \ + sdist --formats=zip,gztar \ + upload --sign --identity=$(KEYID) + +# What should the default be? +test: + $(PYTHON) src/enumprocess/processinfo.py + +egg: egg24 egg25 + +distribution: realclean dist25 egg24 gpg + +gpg: + for F in `find dist -type f -and -not -name '*.asc'`; do \ + gpg --detach-sign --armor --default-key $(KEYID) $$F; \ + done + md5sum dist/*.zip dist/*.egg dist/*.gz + +clean: + find . \( -name '*.o' -o -name '*~' -o -name '*.so' -o -name '*.py[cod]' -o -name '*.dll' \) -exec rm -f {} \; + rm -rf build + +realclean: clean + rm -f TAGS + rm -rf dist + $(PYTHON) setup.py clean -a Added: enumprocess/trunk/PKG-INFO =================================================================== --- enumprocess/trunk/PKG-INFO (rev 0) +++ enumprocess/trunk/PKG-INFO 2007-02-27 14:29:15 UTC (rev 202) @@ -0,0 +1,24 @@ +Metadata-Version: 1.0 +Name: enumprocess +Version: 0.1 +Summary: enumprocess: list pids and processes +Home-page: http://sourceforge.net/projects/pymoul/ +Author: Christian Heimes +Author-email: chr...@ch... +License: BSD License +Download-URL: http://cheeseshop.python.org/pypi/enumprocess +Description: + TODO: long description + +Keywords: pid,process,enum,proc,ps,psapi +Platform: Independant +Classifier: Development Status :: 4 - Beta +Classifier: Intended Audience :: Developers +Classifier: License :: OSI Approved :: BSD License +Classifier: Natural Language :: English +Classifier: Operating System :: Microsoft :: Windows +Classifier: Operating System :: POSIX +Classifier: Operating System :: POSIX :: Linux +Classifier: Programming Language :: Python +Classifier: Topic :: System +Classifier: Topic :: Software Development :: Libraries Added: enumprocess/trunk/README.txt =================================================================== --- enumprocess/trunk/README.txt (rev 0) +++ enumprocess/trunk/README.txt 2007-02-27 14:29:15 UTC (rev 202) @@ -0,0 +1,17 @@ +enumprocess +=========== + +The package contains for implementations: + + - an Unsupported implementation that raises UnsupportedError + - a Linux implementation that read the data from /proc + - a Unix/POSIX implementation that parses the output of ps + - a Windows implementation that uses ctypes to get the infos from psapi.dll + +API +=== + +getPids() - list of ints/longs +getPidNames() - mapping pid -> name +getPidDetails(pid) - detailed informations about a process +getPidDetails('self') - detailed informations about current process \ No newline at end of file Added: enumprocess/trunk/ez_setup.py =================================================================== --- enumprocess/trunk/ez_setup.py (rev 0) +++ enumprocess/trunk/ez_setup.py 2007-02-27 14:29:15 UTC (rev 202) @@ -0,0 +1,228 @@ +#!python +"""Bootstrap setuptools installation + +If you want to use setuptools in your package's setup.py, just include this +file in the same directory with it, and add this to the top of your setup.py:: + + from ez_setup import use_setuptools + use_setuptools() + +If you want to require a specific version of setuptools, set a download +mirror, or use an alternate download directory, you can do so by supplying +the appropriate options to ``use_setuptools()``. + +This file can also be run as a script to install or upgrade setuptools. +""" +import sys +DEFAULT_VERSION = "0.6c5" +DEFAULT_URL = "http://cheeseshop.python.org/packages/%s/s/setuptools/" % sys.version[:3] + +md5_data = { + 'setuptools-0.6b1-py2.3.egg': '8822caf901250d848b996b7f25c6e6ca', + 'setuptools-0.6b1-py2.4.egg': 'b79a8a403e4502fbb85ee3f1941735cb', + 'setuptools-0.6b2-py2.3.egg': '5657759d8a6d8fc44070a9d07272d99b', + 'setuptools-0.6b2-py2.4.egg': '4996a8d169d2be661fa32a6e52e4f82a', + 'setuptools-0.6b3-py2.3.egg': 'bb31c0fc7399a63579975cad9f5a0618', + 'setuptools-0.6b3-py2.4.egg': '38a8c6b3d6ecd22247f179f7da669fac', + 'setuptools-0.6b4-py2.3.egg': '62045a24ed4e1ebc77fe039aa4e6f7e5', + 'setuptools-0.6b4-py2.4.egg': '4cb2a185d228dacffb2d17f103b3b1c4', + 'setuptools-0.6c1-py2.3.egg': 'b3f2b5539d65cb7f74ad79127f1a908c', + 'setuptools-0.6c1-py2.4.egg': 'b45adeda0667d2d2ffe14009364f2a4b', + 'setuptools-0.6c2-py2.3.egg': 'f0064bf6aa2b7d0f3ba0b43f20817c27', + 'setuptools-0.6c2-py2.4.egg': '616192eec35f47e8ea16cd6a122b7277', + 'setuptools-0.6c3-py2.3.egg': 'f181fa125dfe85a259c9cd6f1d7b78fa', + 'setuptools-0.6c3-py2.4.egg': 'e0ed74682c998bfb73bf803a50e7b71e', + 'setuptools-0.6c3-py2.5.egg': 'abef16fdd61955514841c7c6bd98965e', + 'setuptools-0.6c4-py2.3.egg': 'b0b9131acab32022bfac7f44c5d7971f', + 'setuptools-0.6c4-py2.4.egg': '2a1f9656d4fbf3c97bf946c0a124e6e2', + 'setuptools-0.6c4-py2.5.egg': '8f5a052e32cdb9c72bcf4b5526f28afc', + 'setuptools-0.6c5-py2.3.egg': 'ee9fd80965da04f2f3e6b3576e9d8167', + 'setuptools-0.6c5-py2.4.egg': 'afe2adf1c01701ee841761f5bcd8aa64', + 'setuptools-0.6c5-py2.5.egg': 'a8d3f61494ccaa8714dfed37bccd3d5d', +} + +import sys, os + +def _validate_md5(egg_name, data): + if egg_name in md5_data: + from md5 import md5 + digest = md5(data).hexdigest() + if digest != md5_data[egg_name]: + print >>sys.stderr, ( + "md5 validation of %s failed! (Possible download problem?)" + % egg_name + ) + sys.exit(2) + return data + + +def use_setuptools( + version=DEFAULT_VERSION, download_base=DEFAULT_URL, to_dir=os.curdir, + download_delay=15 +): + """Automatically find/download setuptools and make it available on sys.path + + `version` should be a valid setuptools version number that is available + as an egg for download under the `download_base` URL (which should end with + a '/'). `to_dir` is the directory where setuptools will be downloaded, if + it is not already available. If `download_delay` is specified, it should + be the number of seconds that will be paused before initiating a download, + should one be required. If an older version of setuptools is installed, + this routine will print a message to ``sys.stderr`` and raise SystemExit in + an attempt to abort the calling script. + """ + try: + import setuptools + if setuptools.__version__ == '0.0.1': + print >>sys.stderr, ( + "You have an obsolete version of setuptools installed. Please\n" + "remove it from your system entirely before rerunning this script." + ) + sys.exit(2) + except ImportError: + egg = download_setuptools(version, download_base, to_dir, download_delay) + sys.path.insert(0, egg) + import setuptools; setuptools.bootstrap_install_from = egg + + import pkg_resources + try: + pkg_resources.require("setuptools>="+version) + + except pkg_resources.VersionConflict, e: + # XXX could we install in a subprocess here? + print >>sys.stderr, ( + "The required version of setuptools (>=%s) is not available, and\n" + "can't be installed while this script is running. Please install\n" + " a more recent version first.\n\n(Currently using %r)" + ) % (version, e.args[0]) + sys.exit(2) + +def download_setuptools( + version=DEFAULT_VERSION, download_base=DEFAULT_URL, to_dir=os.curdir, + delay = 15 +): + """Download setuptools from a specified location and return its filename + + `version` should be a valid setuptools version number that is available + as an egg for download under the `download_base` URL (which should end + with a '/'). `to_dir` is the directory where the egg will be downloaded. + `delay` is the number of seconds to pause before an actual download attempt. + """ + import urllib2, shutil + egg_name = "setuptools-%s-py%s.egg" % (version,sys.version[:3]) + url = download_base + egg_name + saveto = os.path.join(to_dir, egg_name) + src = dst = None + if not os.path.exists(saveto): # Avoid repeated downloads + try: + from distutils import log + if delay: + log.warn(""" +--------------------------------------------------------------------------- +This script requires setuptools version %s to run (even to display +help). I will attempt to download it for you (from +%s), but +you may need to enable firewall access for this script first. +I will start the download in %d seconds. + +(Note: if this machine does not have network access, please obtain the file + + %s + +and place it in this directory before rerunning this script.) +---------------------------------------------------------------------------""", + version, download_base, delay, url + ); from time import sleep; sleep(delay) + log.warn("Downloading %s", url) + src = urllib2.urlopen(url) + # Read/write all in one block, so we don't create a corrupt file + # if the download is interrupted. + data = _validate_md5(egg_name, src.read()) + dst = open(saveto,"wb"); dst.write(data) + finally: + if src: src.close() + if dst: dst.close() + return os.path.realpath(saveto) + +def main(argv, version=DEFAULT_VERSION): + """Install or upgrade setuptools and EasyInstall""" + + try: + import setuptools + except ImportError: + egg = None + try: + egg = download_setuptools(version, delay=0) + sys.path.insert(0,egg) + from setuptools.command.easy_install import main + return main(list(argv)+[egg]) # we're done here + finally: + if egg and os.path.exists(egg): + os.unlink(egg) + else: + if setuptools.__version__ == '0.0.1': + # tell the user to uninstall obsolete version + use_setuptools(version) + + req = "setuptools>="+version + import pkg_resources + try: + pkg_resources.require(req) + except pkg_resources.VersionConflict: + try: + from setuptools.command.easy_install import main + except ImportError: + from easy_install import main + main(list(argv)+[download_setuptools(delay=0)]) + sys.exit(0) # try to force an exit + else: + if argv: + from setuptools.command.easy_install import main + main(argv) + else: + print "Setuptools version",version,"or greater has been installed." + print '(Run "ez_setup.py -U setuptools" to reinstall or upgrade.)' + + + +def update_md5(filenames): + """Update our built-in md5 registry""" + + import re + from md5 import md5 + + for name in filenames: + base = os.path.basename(name) + f = open(name,'rb') + md5_data[base] = md5(f.read()).hexdigest() + f.close() + + data = [" %r: %r,\n" % it for it in md5_data.items()] + data.sort() + repl = "".join(data) + + import inspect + srcfile = inspect.getsourcefile(sys.modules[__name__]) + f = open(srcfile, 'rb'); src = f.read(); f.close() + + match = re.search("\nmd5_data = {\n([^}]+)}", src) + if not match: + print >>sys.stderr, "Internal error!" + sys.exit(2) + + src = src[:match.start(1)] + repl + src[match.end(1):] + f = open(srcfile,'w') + f.write(src) + f.close() + + +if __name__=='__main__': + if len(sys.argv)>2 and sys.argv[1]=='--md5update': + update_md5(sys.argv[2:]) + else: + main(sys.argv[1:]) + + + + + Property changes on: enumprocess/trunk/ez_setup.py ___________________________________________________________________ Name: svn:executable + Added: enumprocess/trunk/setup.py =================================================================== --- enumprocess/trunk/setup.py (rev 0) +++ enumprocess/trunk/setup.py 2007-02-27 14:29:15 UTC (rev 202) @@ -0,0 +1,64 @@ +#!/usr/bin/env python +"""enumprocess: list pids and processes + +TODO: long description +""" +__author__ = "Christian Heimes" +__version__ = "$Id$" +__revision__ = "$Revision$" + +import sys + +if sys.version_info < (2,4): + raise RuntimeError("Python 2.4+ required:\n%s" % sys.version) + +# boot strap easy setup +SETUPTOOLS_VERSION = "0.6c1" +from ez_setup import use_setuptools +use_setuptools(version=SETUPTOOLS_VERSION) + +# import the rest +from setuptools import setup +from setuptools import find_packages + +from distutils.core import setup + +VERSION = "0.1" + +me = "Christian Heimes" +email = "chr...@ch..." + +setup_infos = dict( + name = "enumprocess", + version = VERSION, + description = __doc__[:__doc__.find('\n')].strip(), + long_description = '\n'.join([line + for line in __doc__.split('\n')[1:]]), + author = "Christian Heimes", + author_email = "chr...@ch...", + maintainer = "Christian Heimes", + maintainer_email = "chr...@ch...", + url = "http://sourceforge.net/projects/pymoul/", + download_url= "http://cheeseshop.python.org/pypi/enumprocess", + license = "BSD License", + keywords = ["pid", "process", "enum", "proc", "ps", "psapi"], + platforms=['Independant'], + classifiers = ( + 'Development Status :: 4 - Beta', + 'Intended Audience :: Developers', + 'License :: OSI Approved :: BSD License', + 'Natural Language :: English', + 'Operating System :: Microsoft :: Windows', + 'Operating System :: POSIX', + 'Operating System :: POSIX :: Linux', + 'Programming Language :: Python', + 'Topic :: System', + 'Topic :: Software Development :: Libraries' + ), + setup_requires = ["setuptools>="+SETUPTOOLS_VERSION,], + packages = ['enumprocess'], + package_dir = {'' : 'src'}, + zip_safe = True, +) + +setup(**setup_infos) Property changes on: enumprocess/trunk/setup.py ___________________________________________________________________ Name: svn:executable + Added: enumprocess/trunk/src/enumprocess/__init__.py =================================================================== --- enumprocess/trunk/src/enumprocess/__init__.py (rev 0) +++ enumprocess/trunk/src/enumprocess/__init__.py 2007-02-27 14:29:15 UTC (rev 202) @@ -0,0 +1,32 @@ +# Copyright (c) 2007 Christian Heimes. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# +# 3. Neither the name of Infrae nor the names of its contributors may +# be used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INFRAE OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +"""enum processes +""" +from processinfo import * Added: enumprocess/trunk/src/enumprocess/processinfo.py =================================================================== --- enumprocess/trunk/src/enumprocess/processinfo.py (rev 0) +++ enumprocess/trunk/src/enumprocess/processinfo.py 2007-02-27 14:29:15 UTC (rev 202) @@ -0,0 +1,477 @@ +# Copyright (c) 2007 Christian Heimes. All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# +# 3. Neither the name of Infrae nor the names of its contributors may +# be used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INFRAE OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +"""Get process informations + +The module contains for implementations: + + - an Unsupported implementation that raises UnsupportedError + - a Linux implementation that read the data from /proc + - a Unix/POSIX implementation that parses the output of ps + - a Windows implementation that uses ctypes to get the infos from psapi.dll + +API +=== + getPids() - list of ints/longs + getPidNames() - mapping pid -> name + getPidDetails(pid) - detailed informations about a process + getPidDetails('self') - detailed informations about current process + +>>> cur = os.getpid() +>>> exe = sys.executable +>>> pids = getPids() +>>> pids > 1 +True +>>> isinstance(pids[0], (int, long)) +True +>>> cur in pids +True + +>>> mapping = getPidNames() +>>> cur in mapping +True +>>> mapping[cur].lower() in sys.executable +True + +>>> getPidDetails('self')['name'] == getPidDetails(cur)['name'] +True +>>> getPidDetails(cur)['name'] == mapping[cur] +True + +>>> for impl in (WinEnumProcesses(), LinuxProcReader(), PsParser()): +... if impl.supported(): +... isinstance(impl.getPids(), list) and None +... isinstance(impl.getPidNames(), dict) and None +""" +__author__ = "Christian Heimes" +__version__ = "$Id$" +__revision__ = "$Revision$" +__all__ = ['getPids', 'getPidNames', 'getPidDetails', 'supportedOS', + 'UnsupportedError'] + +import logging +import os +import os.path +import sys + + +LOG = logging.getLogger("processinfo") +NULL = "\x00" + +_plat = sys.platform.startswith +if _plat('win') or _plat('cygwin'): + from ctypes import windll, c_ulong, sizeof, c_buffer, byref + PSAPI = windll.psapi + KERNEL = windll.kernel32 + PROCESS_QUERY_INFORMATION = 0x0400 + PROCESS_VM_READ = 0x0010 + PROCESS_FLAGS = PROCESS_QUERY_INFORMATION | PROCESS_VM_READ +else: + from subprocess import Popen + from subprocess import PIPE + +class UnsupportedError(OSError): + """OS or command not supported error + """ + pass + +class Unsupported(object): + """Unsupported OS implementation + + Raises L{UnsupportedError} + """ + __slots__ = () + + @classmethod + def supported(cls): + """Supported flag property""" + return False + + @classmethod + def log(cls): + """Log information about the implementation""" + LOG.warning("Unsupported OS. Neither proc filesystem nor 'ps' works.") + + @classmethod + def getPids(cls): + """Get a list of pids + + @return: a list of pid numbers + @rtype: list(int) + """ + raise UnsupportedError + + @classmethod + def getPidNames(cls): + """Get a mapping of pid -> name + + @return: mapping of pid -> name + @rtype: dict(int:str) + """ + raise UnsupportedError + + @classmethod + def getPidDetails(pid): + """Get detailed informations about a process + + @param pid: pid number or 'self' + @type pid: int or basestring + @return: detailed information about a process + @rtype: dict(str:data) + """ + raise UnsupportedError + +class PsParser(object): + """Parse the output of the ps command + """ + __slots__ = () + + CMD = "ps -e --no-header --cols=1024" + PIDNAMES = "%s --format=pid,ucmd" % CMD + PIDS = "%s --format=pid" % CMD + + @classmethod + def supported(cls): + """Supported flag property""" + try: + cls._exec(cls.PIDS) + except Exception: # catch all! + return False + else: + return True + + @classmethod + def log(cls): + """Log information about the implementation""" + LOG.debug("Using the 'ps' command on POSIX os") + + @classmethod + def getPids(cls): + """Get a list of pids + """ + stdout = cls._exec(cls.PIDS) + if stdout is None: + return None + pids = [] + for line in stdout: + try: + pid = int(line.strip()) + except ValueError: + pass + else: + pids.append(pid) + return pids + + @classmethod + def getPidNames(cls): + """Get a list of pid -> name + """ + stdout = cls._exec(cls.PIDNAMES) + if stdout is None: + return None + mapping = {} + for line in stdout: + line = line.strip() + idx = line.find(' ') + pid, name = line[:idx], line[idx+1:] + try: + pid = int(pid) + except ValueError: + pass + else: + mapping[pid] = name + return mapping + + @classmethod + def getPidDetails(cls, pid): + """Get detailed informations about a process + + TODO + """ + if pid == 'self': + pid = os.getpid() + raise UnsupportedError("not implemented yet") + + @staticmethod + def _exec(cmd): + """Execute command cmd + + The method waits until the command has finished. It returns None of + something went wrong. + + @param cmd: Command to execute + @type cmd: str + @return: None or stdin as file like object + """ + try: + popen = Popen(cmd, shell=True, bufsize=-1, stdout=PIPE, + env = {'LC_ALL' : 'C'}) + rc = popen.wait() + except (OSError, ValueError): + LOG.exception("Failed to execute '%s'" % cmd) + return None + else: + if rc != 0: + LOG.error("'%s' returned with error code %i" % (cmd, rc)) + return None + else: + return popen.stdout + +class LinuxProcReader(object): + """Get process informations under Linux by reading /proc + + Tested under Linux, may work on other POSIX os with /proc, too. + """ + __slots__ = () + + PROC = "/proc" + + @classmethod + def supported(cls): + return os.path.isfile("%s/self/status" % cls.PROC) + + @classmethod + def log(cls): + """Log information about the implementation""" + LOG.debug("Using the proc filesystem on Linux") + + @classmethod + def getPids(cls): + """Get a list of pids + """ + pids = [] + for name in os.listdir(cls.PROC): + if os.path.isdir(cls.PROC + '/' + name): + try: + pids.append(int(name)) + except ValueError: + pass + return pids + + @classmethod + def getPidNames(cls): + """Get a list of pid -> name + """ + mapping = {} + for pid in cls.getPids(): + name = cls._readProcStatus(pid, searchkey='name') + if name is not None: + mapping[pid] = name + return mapping + + def getPidDetails(cls, pid): + """Get detailed informations about a process + """ + details = cls._readProcStatus(pid) + if details is None: + return None + details.update(cls._readProcOther(pid)) + details['cmdline'] = cls._readProcCmdline(pid) + return details + + @classmethod + def _readProcStatus(cls, pid, searchkey=None): + """Read and parse status informations for PID pid + + pid - pid as long or int or 'self' + + If searchkey is None the method returns a mapping of lower keys + to values (stripped). + If searchkey is given than the method immediatly returns the value + or returns None if they key can't be found. + """ + mapping = {} + status = '%s/%s/status' % (cls.PROC, pid) + try: + # read entiry file to avoid race conditions + lines = open(status, 'r').readlines() + except IOError: + LOG.exception("%s not found" % status) + return None + for line in lines: + try: + key, value = line.split(':\t') + except ValueError: + continue + key = key.lower() + value = value.strip() + #if value.endswith(' kB'): + # value = value[:-3] + if key == searchkey: + return value + mapping[key.lower()] = value + if searchkey is not None: + return None + return mapping + + @classmethod + def _readProcCmdline(cls, pid): + """Read cmdline informations for pid and returns a list similar to sys.argv + """ + try: + # read entiry file to avoid race conditions + data = open('%s/%s/cmdline' % (cls.PROC, pid), 'r').read() + except IOError: + return None + return data.split(NULL) + + @classmethod + def _readProcOther(cls, pid): + """Read other possible useful things + + cwd -> current work directory (may not exist) + exe -> path to executable (may not exist) + """ + return { + 'cwd' : os.path.realpath('%s/%s/cwd' % (cls.PROC, pid)), + 'exe' : os.path.realpath('%s/%s/exe' % (cls.PROC, pid)), + } + +class WinEnumProcesses(object): + """""Get process informations under Win32 with psapi.dll + + Based on enumprocesses from Eric Koome + http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/305279 + """ + __slots__ = () + + @classmethod + def supported(cls): + try: + cls.getPids() + except Exception: # catch all! + return False + else: + return True + + @classmethod + def log(cls): + """Log information about the implementation""" + LOG.debug("Using ctypes on Windows") + + @classmethod + def getPids(cls): + """Get a list of pids + """ + arr = c_ulong * 256 + lpidProcess = arr() + cb = sizeof(lpidProcess) + cbNeeded = c_ulong() + + # Call Enumprocesses to get hold of process id's + PSAPI.EnumProcesses(byref(lpidProcess), cb, byref(cbNeeded)) + nReturned = cbNeeded.value/sizeof(c_ulong()) # number of processes returned + return [pid for pid in lpidProcess][:nReturned] + + @classmethod + def getPidNames(cls): + """Get a list of pid -> name + """ + hModule = c_ulong() + count = c_ulong() + modname = c_buffer(51) + mapping = {} + for pid in cls.getPids(): + # Get handle to the process based on PID + hProcess = KERNEL.OpenProcess(PROCESS_FLAGS, False, pid) + if hProcess: + PSAPI.EnumProcessModules(hProcess, byref(hModule), + sizeof(hModule), byref(count)) + PSAPI.GetModuleBaseNameA(hProcess, hModule.value, modname, + sizeof(modname)) + try: + name = u"".join([c for c in modname if c != NULL]) + except UnicodeError, msg: + LOG.exception("Can't decode name of pid %s" % pid) + else: + mapping[pid] = name + modname[:] = sizeof(modname) * NULL + KERNEL.CloseHandle(hProcess) + + return mapping + + @classmethod + def getPidDetails(cls, pid): + """Get detailed informations about a process + """ + if pid == 'self': + pid = os.getpid() + + hModule = c_ulong() + count = c_ulong() + modname = c_buffer(51) + hProcess = KERNEL.OpenProcess(PROCESS_FLAGS, False, pid) + if not hProcess: + return None + + PSAPI.EnumProcessModules(hProcess, byref(hModule), + sizeof(hModule), byref(count)) + PSAPI.GetModuleBaseNameA(hProcess, hModule.value, modname, + sizeof(modname)) + try: + name = u"".join([c for c in modname if c != NULL]) + except UnicodeError, msg: + LOG.exception("Can't decode name of pid %s" % pid) + else: + name = None + + KERNEL.CloseHandle(hProcess) + return {'name' : name} + + +# Initialize global methods +_enumProcesses = None +for impl in (WinEnumProcesses(), LinuxProcReader(), PsParser()): + if impl.supported(): + impl.log() + _enumProcesses = impl + break + +if _enumProcesses is None: + LOG.error("System %s is not supported" % sys.platform) + _enumProcesses = Unsupported() + +getPids = _enumProcesses.getPids +getPidNames = _enumProcesses.getPidNames +getPidDetails = _enumProcesses.getPidDetails +supportedOS = _enumProcesses.supported() + +def test_suite(): + import unittest + from doctest import DocTestSuite + return unittest.TestSuite(( + DocTestSuite() + )) + +if __name__ == '__main__': + import unittest + logging.basicConfig() + unittest.main(defaultTest="test_suite") + print getPids() + print getPidNames() Added: enumprocess/trunk/src/enumprocess.egg-info/PKG-INFO =================================================================== --- enumprocess/trunk/src/enumprocess.egg-info/PKG-INFO (rev 0) +++ enumprocess/trunk/src/enumprocess.egg-info/PKG-INFO 2007-02-27 14:29:15 UTC (rev 202) @@ -0,0 +1,24 @@ +Metadata-Version: 1.0 +Name: enumprocess +Version: 0.1 +Summary: enumprocess: list pids and processes +Home-page: http://sourceforge.net/projects/pymoul/ +Author: Christian Heimes +Author-email: chr...@ch... +License: BSD License +Download-URL: http://cheeseshop.python.org/pypi/enumprocess +Description: + TODO: long description + +Keywords: pid,process,enum,proc,ps,psapi +Platform: Independant +Classifier: Development Status :: 4 - Beta +Classifier: Intended Audience :: Developers +Classifier: License :: OSI Approved :: BSD License +Classifier: Natural Language :: English +Classifier: Operating System :: Microsoft :: Windows +Classifier: Operating System :: POSIX +Classifier: Operating System :: POSIX :: Linux +Classifier: Programming Language :: Python +Classifier: Topic :: System +Classifier: Topic :: Software Development :: Libraries Added: enumprocess/trunk/src/enumprocess.egg-info/SOURCES.txt =================================================================== --- enumprocess/trunk/src/enumprocess.egg-info/SOURCES.txt (rev 0) +++ enumprocess/trunk/src/enumprocess.egg-info/SOURCES.txt 2007-02-27 14:29:15 UTC (rev 202) @@ -0,0 +1,16 @@ +CHANGES.txt +INSTALL.txt +LICENSE.txt +MANIFEST.in +Makefile +README.txt +ez_setup.py +setup.py +version.txt +src/enumprocess/__init__.py +src/enumprocess/processinfo.py +src/enumprocess.egg-info/PKG-INFO +src/enumprocess.egg-info/SOURCES.txt +src/enumprocess.egg-info/dependency_links.txt +src/enumprocess.egg-info/top_level.txt +src/enumprocess.egg-info/zip-safe Added: enumprocess/trunk/src/enumprocess.egg-info/dependency_links.txt =================================================================== --- enumprocess/trunk/src/enumprocess.egg-info/dependency_links.txt (rev 0) +++ enumprocess/trunk/src/enumprocess.egg-info/dependency_links.txt 2007-02-27 14:29:15 UTC (rev 202) @@ -0,0 +1 @@ + Added: enumprocess/trunk/src/enumprocess.egg-info/top_level.txt =================================================================== --- enumprocess/trunk/src/enumprocess.egg-info/top_level.txt (rev 0) +++ enumprocess/trunk/src/enumprocess.egg-info/top_level.txt 2007-02-27 14:29:15 UTC (rev 202) @@ -0,0 +1 @@ +enumprocess Added: enumprocess/trunk/src/enumprocess.egg-info/zip-safe =================================================================== --- enumprocess/trunk/src/enumprocess.egg-info/zip-safe (rev 0) +++ enumprocess/trunk/src/enumprocess.egg-info/zip-safe 2007-02-27 14:29:15 UTC (rev 202) @@ -0,0 +1 @@ + Added: enumprocess/trunk/version.txt =================================================================== --- enumprocess/trunk/version.txt (rev 0) +++ enumprocess/trunk/version.txt 2007-02-27 14:29:15 UTC (rev 202) @@ -0,0 +1 @@ +0.1 \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ti...@us...> - 2007-02-27 11:46:40
|
Revision: 201 http://pymoul.svn.sourceforge.net/pymoul/?rev=201&view=rev Author: tiran Date: 2007-02-27 03:46:40 -0800 (Tue, 27 Feb 2007) Log Message: ----------- processinfo cleanup Modified Paths: -------------- pymoul/trunk/src/moul/osdependent/processinfo.py Modified: pymoul/trunk/src/moul/osdependent/processinfo.py =================================================================== --- pymoul/trunk/src/moul/osdependent/processinfo.py 2007-02-27 03:20:16 UTC (rev 200) +++ pymoul/trunk/src/moul/osdependent/processinfo.py 2007-02-27 11:46:40 UTC (rev 201) @@ -51,69 +51,87 @@ True >>> getPidDetails(cur)['name'] == mapping[cur] True + +>>> for impl in (WinEnumProcesses(), LinuxProcReader(), PsParser()): +... if impl.supported(): +... isinstance(impl.getPids(), list) and None +... isinstance(impl.getPidNames(), dict) and None """ __author__ = "Christian Heimes" __version__ = "$Id$" __revision__ = "$Revision$" +__all__ = ['getPids', 'getPidNames', 'getPidDetails', 'supportedOS', + 'UnsupportedError'] +import logging import os +import os.path import sys -from logging import getLogger -LOG = getLogger("processinfo") +LOG = logging.getLogger("processinfo") +NULL = "\x00" + _plat = sys.platform.startswith if _plat('win') or _plat('cygwin'): - LOG.debug("Using ctypes on Windows") - IMPL = 'win' from ctypes import windll, c_ulong, sizeof, c_buffer, byref - PSAPI = windll.psapi KERNEL = windll.kernel32 PROCESS_QUERY_INFORMATION = 0x0400 PROCESS_VM_READ = 0x0010 PROCESS_FLAGS = PROCESS_QUERY_INFORMATION | PROCESS_VM_READ else: - import os - PROC = '/proc' - if os.path.isfile("%s/self/status" % PROC): - LOG.debug("Using /proc on Linux") - IMPL = 'proc' - elif os.system('ps') == 0: - LOG.debug("Using the 'ps' command on POSIX os") - IMPL = 'ps' - from subprocess import Popen - from subprocess import PIPE - else: - LOG.warning("Unsupported OS. Neither /proc nor 'ps' works.") - IMPL = "unsupported" + from subprocess import Popen + from subprocess import PIPE -NULL = "\x00" - class UnsupportedError(OSError): + """OS or command not supported error + """ pass class Unsupported(object): - """Unsupported OS + """Unsupported OS implementation + + Raises L{UnsupportedError} """ __slots__ = () - def supported(self): + @classmethod + def supported(cls): + """Supported flag property""" return False - supported = property(supported) - def getPids(self): + @classmethod + def log(cls): + """Log information about the implementation""" + LOG.warning("Unsupported OS. Neither proc filesystem nor 'ps' works.") + + @classmethod + def getPids(cls): """Get a list of pids + + @return: a list of pid numbers + @rtype: list(int) """ raise UnsupportedError - def getPidNames(self): - """Get a list of pid -> name + @classmethod + def getPidNames(cls): + """Get a mapping of pid -> name + + @return: mapping of pid -> name + @rtype: dict(int:str) """ raise UnsupportedError - def getPidDetails(self, pid): + @classmethod + def getPidDetails(pid): """Get detailed informations about a process + + @param pid: pid number or 'self' + @type pid: int or basestring + @return: detailed information about a process + @rtype: dict(str:data) """ raise UnsupportedError @@ -126,14 +144,26 @@ PIDNAMES = "%s --format=pid,ucmd" % CMD PIDS = "%s --format=pid" % CMD - def supported(self): - return False - supported = property(supported) + @classmethod + def supported(cls): + """Supported flag property""" + try: + cls._exec(cls.PIDS) + except Exception: # catch all! + return False + else: + return True - def getPids(self): + @classmethod + def log(cls): + """Log information about the implementation""" + LOG.debug("Using the 'ps' command on POSIX os") + + @classmethod + def getPids(cls): """Get a list of pids """ - stdout = self._exec(self.PIDS) + stdout = cls._exec(cls.PIDS) if stdout is None: return None pids = [] @@ -146,10 +176,11 @@ pids.append(pid) return pids - def getPidNames(self): + @classmethod + def getPidNames(cls): """Get a list of pid -> name """ - stdout = self._exec(self.PIDNAMES) + stdout = cls._exec(cls.PIDNAMES) if stdout is None: return None mapping = {} @@ -165,14 +196,18 @@ mapping[pid] = name return mapping - def getPidDetails(self, pid): + @classmethod + def getPidDetails(cls, pid): """Get detailed informations about a process TODO """ - raise UnsupportedError + if pid == 'self': + pid = os.getpid() + raise UnsupportedError("not implemented yet") - def _exec(self, cmd): + @staticmethod + def _exec(cmd): """Execute command cmd The method waits until the command has finished. It returns None of @@ -203,42 +238,53 @@ """ __slots__ = () - def supported(self): - return True - supported = property(supported) + PROC = "/proc" - @staticmethod - def getPids(): + @classmethod + def supported(cls): + return os.path.isfile("%s/self/status" % cls.PROC) + + @classmethod + def log(cls): + """Log information about the implementation""" + LOG.debug("Using the proc filesystem on Linux") + + @classmethod + def getPids(cls): """Get a list of pids """ pids = [] - for name in os.listdir(PROC): - if os.path.isdir(PROC + '/' + name): + for name in os.listdir(cls.PROC): + if os.path.isdir(cls.PROC + '/' + name): try: pids.append(int(name)) except ValueError: pass return pids - def getPidNames(self): + @classmethod + def getPidNames(cls): """Get a list of pid -> name """ mapping = {} - for pid in self.getPids(): - name = self._readProcStatus(pid, searchkey='name') + for pid in cls.getPids(): + name = cls._readProcStatus(pid, searchkey='name') if name is not None: mapping[pid] = name return mapping - def getPidDetails(self, pid): + def getPidDetails(cls, pid): """Get detailed informations about a process """ - details = self._readProcStatus(pid) - details.update(self._readProcOther(pid)) - details['cmdline'] = self._readProcCmdline(pid) + details = cls._readProcStatus(pid) + if details is None: + return None + details.update(cls._readProcOther(pid)) + details['cmdline'] = cls._readProcCmdline(pid) return details - def _readProcStatus(self, pid, searchkey=None): + @classmethod + def _readProcStatus(cls, pid, searchkey=None): """Read and parse status informations for PID pid pid - pid as long or int or 'self' @@ -249,10 +295,12 @@ or returns None if they key can't be found. """ mapping = {} + status = '%s/%s/status' % (cls.PROC, pid) try: # read entiry file to avoid race conditions - lines = open('%s/%s/status' % (PROC, pid), 'r').readlines() + lines = open(status, 'r').readlines() except IOError: + LOG.exception("%s not found" % status) return None for line in lines: try: @@ -270,25 +318,27 @@ return None return mapping - def _readProcCmdline(self, pid): + @classmethod + def _readProcCmdline(cls, pid): """Read cmdline informations for pid and returns a list similar to sys.argv """ try: # read entiry file to avoid race conditions - data = open('%s/%s/cmdline' % (PROC, pid), 'r').read() + data = open('%s/%s/cmdline' % (cls.PROC, pid), 'r').read() except IOError: return None return data.split(NULL) - def _readProcOther(self, pid): + @classmethod + def _readProcOther(cls, pid): """Read other possible useful things cwd -> current work directory (may not exist) exe -> path to executable (may not exist) """ return { - 'cwd' : os.path.realpath('%s/%s/cwd' % (PROC, pid)), - 'exe' : os.path.realpath('%s/%s/exe' % (PROC, pid)), + 'cwd' : os.path.realpath('%s/%s/cwd' % (cls.PROC, pid)), + 'exe' : os.path.realpath('%s/%s/exe' % (cls.PROC, pid)), } class WinEnumProcesses(object): @@ -299,11 +349,22 @@ """ __slots__ = () - def supported(self): - return True - supported = property(supported) + @classmethod + def supported(cls): + try: + cls.getPids() + except Exception: # catch all! + return False + else: + return True - def getPids(self): + @classmethod + def log(cls): + """Log information about the implementation""" + LOG.debug("Using ctypes on Windows") + + @classmethod + def getPids(cls): """Get a list of pids """ arr = c_ulong * 256 @@ -316,14 +377,15 @@ nReturned = cbNeeded.value/sizeof(c_ulong()) # number of processes returned return [pid for pid in lpidProcess][:nReturned] - def getPidNames(self): + @classmethod + def getPidNames(cls): """Get a list of pid -> name """ hModule = c_ulong() count = c_ulong() modname = c_buffer(51) mapping = {} - for pid in self.getPids(): + for pid in cls.getPids(): # Get handle to the process based on PID hProcess = KERNEL.OpenProcess(PROCESS_FLAGS, False, pid) if hProcess: @@ -342,7 +404,8 @@ return mapping - def getPidDetails(self, pid): + @classmethod + def getPidDetails(cls, pid): """Get detailed informations about a process """ if pid == 'self': @@ -371,21 +434,32 @@ # Initialize global methods -if IMPL == 'proc': - _enumProcesses = LinuxProcReader() -elif IMPL == 'ps': - _enumProcesses = PsParser() -elif IMPL == 'win': - _enumProcesses = WinEnumProcesses() -else: +_enumProcesses = None +for impl in (WinEnumProcesses(), LinuxProcReader(), PsParser()): + if impl.supported(): + impl.log() + _enumProcesses = impl + break + +if _enumProcesses is None: LOG.error("System %s is not supported" % sys.platform) _enumProcesses = Unsupported() getPids = _enumProcesses.getPids getPidNames = _enumProcesses.getPidNames getPidDetails = _enumProcesses.getPidDetails -supportedOS = _enumProcesses.supported +supportedOS = _enumProcesses.supported() +def test_suite(): + import unittest + from doctest import DocTestSuite + return unittest.TestSuite(( + DocTestSuite() + )) + if __name__ == '__main__': + import unittest + logging.basicConfig() + unittest.main(defaultTest="test_suite") + print getPids() print getPidNames() - print getPidDetails('self') This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ti...@us...> - 2007-02-27 03:20:16
|
Revision: 200 http://pymoul.svn.sourceforge.net/pymoul/?rev=200&view=rev Author: tiran Date: 2007-02-26 19:20:16 -0800 (Mon, 26 Feb 2007) Log Message: ----------- Updated language files and German translation Modified Paths: -------------- pymoul/trunk/src/moul/qt/i18n/pymoul_de.qm pymoul/trunk/src/moul/qt/i18n/pymoul_de.ts pymoul/trunk/src/moul/qt/i18n/pymoul_es.ts pymoul/trunk/src/moul/qt/i18n/pymoul_fr.ts pymoul/trunk/src/moul/qt/i18n/pymoul_it.ts pymoul/trunk/src/moul/qt/i18n/pymoul_nl.ts Modified: pymoul/trunk/src/moul/qt/i18n/pymoul_de.qm =================================================================== (Binary files differ) Modified: pymoul/trunk/src/moul/qt/i18n/pymoul_de.ts =================================================================== --- pymoul/trunk/src/moul/qt/i18n/pymoul_de.ts 2007-02-27 03:10:11 UTC (rev 199) +++ pymoul/trunk/src/moul/qt/i18n/pymoul_de.ts 2007-02-27 03:20:16 UTC (rev 200) @@ -1,42 +1,52 @@ -<!DOCTYPE TS><TS> +<?xml version="1.0" encoding="utf-8"?> +<!DOCTYPE TS><TS version="1.1" language="de"> <context> <name>DniTimeNumberContainer</name> <message> + <location filename="" line="7471221"/> <source>cyclic 0</source> - <translation type="unfinished"></translation> + <translation>zyklische 0</translation> </message> </context> <context> <name>IniFileContainer</name> <message> + <location filename="" line="7471221"/> <source>Error opening graphics.ini</source> <translation>Fehler beim Öffnen von graphics.ini</translation> </message> <message> + <location filename="" line="7471221"/> <source>Error opening audio.ini</source> <translation>Fehler beim Öffnen von audio.ini</translation> </message> <message> + <location filename="" line="7471221"/> <source>Graphics.ini not found</source> <translation>Graphics.ini nicht gefunden</translation> </message> <message> + <location filename="" line="7471221"/> <source>Graphics.ini could not be found. Do you want to create a file with default settings?</source> <translation>Graphics.ini konnte nicht gefunden werden. Wollen sie eine eine Datei mit vorgegebenen Einstellungen erstellen?</translation> </message> <message> + <location filename="" line="7471221"/> <source>Audio.ini not found</source> <translation>Audio.ini nicht gefunden</translation> </message> <message> + <location filename="" line="7471221"/> <source>Audio.ini could not be found. Do you want to create a file with default settings?</source> <translation>Audio.ini konnte nicht gefunden werden. Wollen sie eine eine Datei mit vorgegebenen Einstellungen erstellen?</translation> </message> <message> + <location filename="" line="7471221"/> <source>Something bad happend while opening the graphics.ini file. Creating file with default values.</source> <translation>Graphics.ini konnte nicht geöffnet werden, erstelle Datei mit vorgegebenen Einstellungen.</translation> </message> <message> + <location filename="" line="7471221"/> <source>Something bad happend while opening the audio.ini file. Creating file with default values.</source> <translation>Audio.ini konnte nicht geöffnet werden, erstelle Datei mit vorgegebenen Einstellungen.</translation> </message> @@ -44,22 +54,27 @@ <context> <name>LocalizationContainer</name> <message> + <location filename="" line="7471221"/> <source>Unable to load journals.</source> <translation>Fehler beim Laden der Journale.</translation> </message> <message> + <location filename="" line="7471221"/> <source>No journals found.</source> <translation>Keine Journale gefunden.</translation> </message> <message> + <location filename="" line="7471221"/> <source>Loading journals</source> <translation>Lade Journale</translation> </message> <message> + <location filename="" line="7471221"/> <source>Journals loaded.</source> <translation>Journale geladen.</translation> </message> <message> + <location filename="" line="7471221"/> <source>Journals not loaded.</source> <translation>Journale nicht geladen.</translation> </message> @@ -67,302 +82,377 @@ <context> <name>MainWindow</name> <message> + <location filename="" line="7471221"/> <source>Windowed</source> <translation>Fenstermodus</translation> </message> <message> + <location filename="" line="7471221"/> <source>Display Shadows</source> <translation>Zeige Schatten</translation> </message> <message> + <location filename="" line="7471221"/> <source>Screen Resolution</source> <translation>Auflösung</translation> </message> <message> + <location filename="" line="7471221"/> <source>800x600 (4:3)</source> - <translation type="unfinished"></translation> + <translation>800x600 (4:3)</translation> </message> <message> + <location filename="" line="7471221"/> <source>Quality</source> <translation>Qualität</translation> </message> <message> + <location filename="" line="7471221"/> <source>Texture Quality</source> <translation>Texturqualität</translation> </message> <message> + <location filename="" line="7471221"/> <source>Low</source> <translation>Niedrig</translation> </message> <message> + <location filename="" line="7471221"/> <source>High</source> <translation>Hoch</translation> </message> <message> + <location filename="" line="7471221"/> <source>Anti-Aliasing</source> <translation>Anti Alias Filter</translation> </message> <message> + <location filename="" line="7471221"/> <source>Graphics Quality</source> <translation>Grafikqualität</translation> </message> <message> + <location filename="" line="7471221"/> <source>Med.</source> <translation>Med.</translation> </message> <message> + <location filename="" line="7471221"/> <source>Ultra</source> <translation>Ultra</translation> </message> <message> + <location filename="" line="7471221"/> <source>Shadow Quality</source> <translation>Schattenqualität</translation> </message> <message> + <location filename="" line="7471221"/> <source>Anisotropic-Filtering</source> <translation>Anisotropischer Filter</translation> </message> <message> + <location filename="" line="7471221"/> <source>Graphics</source> <translation>Grafik</translation> </message> <message> + <location filename="" line="7471221"/> <source>Level</source> <translation>Level</translation> </message> <message> + <location filename="" line="7471221"/> <source>NPC Voices</source> <translation>NSC Stimmen</translation> </message> <message> + <location filename="" line="7471221"/> <source>Sound FX</source> <translation></translation> </message> <message> + <location filename="" line="7471221"/> <source>Ambience Sound</source> <translation>Hintergrundgeräusche</translation> </message> <message> + <location filename="" line="7471221"/> <source>Music</source> <translation>Musik</translation> </message> <message> + <location filename="" line="7471221"/> <source>Mute all</source> <translation>Alles stumm</translation> </message> <message> + <location filename="" line="7471221"/> <source>Hardware</source> <translation>Hardware</translation> </message> <message> + <location filename="" line="7471221"/> <source>Generic Software</source> <translation></translation> </message> <message> + <location filename="" line="7471221"/> <source>Enable EAX</source> <translation>Aktivier EAX</translation> </message> <message> + <location filename="" line="7471221"/> <source>Voice chat</source> <translation>Voice Chat</translation> </message> <message> + <location filename="" line="7471221"/> <source>Enable Voice Chat</source> <translation>Aktiviere Voice Chat</translation> </message> <message> + <location filename="" line="7471221"/> <source>Audio</source> <translation>Audio</translation> </message> <message> + <location filename="" line="7471221"/> <source>Time zones</source> <translation>Zeitzonen</translation> </message> <message> + <location filename="" line="7471221"/> <source>Cavern time:</source> <translation>Höhlenzeit:</translation> </message> <message> + <location filename="" line="7471221"/> <source>Cyan time:</source> <translation>Cyan Zeit:</translation> </message> <message> + <location filename="" line="7471221"/> <source>UTC -0</source> - <translation type="unfinished"></translation> + <translation>UTC -0</translation> </message> <message> + <location filename="" line="7471221"/> <source>Ping servers</source> <translation>Server anpingen</translation> </message> <message> + <location filename="" line="7471221"/> <source>Ping</source> <translation>Ping</translation> </message> <message> + <location filename="" line="7471221"/> <source>Servers</source> <translation>Server</translation> </message> <message> + <location filename="" line="7471221"/> <source>Age</source> <translation>Zeitalter</translation> </message> <message> + <location filename="" line="7471221"/> <source>Element</source> <translation>Element</translation> </message> <message> + <location filename="" line="7471221"/> <source>Language</source> <translation>Sprache</translation> </message> <message> + <location filename="" line="7471221"/> <source>Set</source> <translation>Set</translation> </message> <message> + <location filename="" line="7471221"/> <source>About</source> <translation>Über</translation> </message> <message> + <location filename="" line="7471221"/> <source>MOUL is running</source> <translation>MOUL läuft</translation> </message> <message> + <location filename="" line="7471221"/> <source>MOUL</source> <translation>MOUL</translation> </message> <message> + <location filename="" line="7471221"/> <source>MOUL is not running</source> <translation>MOUL läuft nicht</translation> </message> <message> + <location filename="" line="7471221"/> <source>Chat and debug logs</source> <translation>Chat- und Fehlerlogs</translation> </message> <message> + <location filename="" line="7471221"/> <source>Archive chatlogs and zip log files</source> <translation>Archiviere Chatlogs und packe Logdateien</translation> </message> <message> + <location filename="" line="7471221"/> <source>Remove zipped logs</source> <translation type="obsolete">Entferne gepackte Logs</translation> </message> <message> + <location filename="" line="7471221"/> <source>Remove</source> <translation>Entferne</translation> </message> <message> + <location filename="" line="7471221"/> <source>Archive</source> <translation>Archiviere</translation> </message> <message> + <location filename="" line="7471221"/> <source>Zip debug logs</source> <translation type="obsolete">Packe Debuglogs</translation> </message> <message> + <location filename="" line="7471221"/> <source>Delete debug logs</source> <translation>Lösche Debuglogs</translation> </message> <message> + <location filename="" line="7471221"/> <source>KI Image repair</source> <translation>Repariere KI Bilder</translation> </message> <message> + <location filename="" line="7471221"/> <source>Repair</source> <translation>Repariere</translation> </message> <message> + <location filename="" line="7471221"/> <source>Fix KI and avatar images</source> <translation>Repariert KI- und Avatarbilder</translation> </message> <message> + <location filename="" line="7471221"/> <source>Tasks</source> <translation>Aufgaben</translation> </message> <message> + <location filename="" line="7471221"/> <source>Other</source> <translation>Anderes</translation> </message> <message> + <location filename="" line="7471221"/> <source>VSync</source> <translation>VSync</translation> </message> <message> + <location filename="" line="7471221"/> <source>pyMoul</source> <translation>pyMoul</translation> </message> <message> + <location filename="" line="7471221"/> <source>Settings</source> <translation>Einstellungen</translation> </message> <message> + <location filename="" line="7471221"/> <source>Read chatlogs</source> <translation>Lese Chatlogs</translation> </message> <message> + <location filename="" line="7471221"/> <source>Chat logs</source> <translation>Chatlogs</translation> </message> <message> + <location filename="" line="7471221"/> <source>Browse journals and notes</source> <translation>Lese Journale und Nachrichten</translation> </message> <message> + <location filename="" line="7471221"/> <source>Journals</source> <translation>Journale</translation> </message> <message> + <location filename="" line="7471221"/> <source>Browse</source> <translation>Lese</translation> </message> <message> + <location filename="" line="7471221"/> <source>About pyMoul</source> <translation>Über pyMoul</translation> </message> <message> + <location filename="" line="7471221"/> <source>License</source> <translation>Lizenz</translation> </message> <message> + <location filename="" line="7471221"/> <source>Load journals</source> <translation>Lade Journale</translation> </message> <message> + <location filename="" line="7471221"/> <source>TextLabel</source> <translation type="unfinished"></translation> </message> <message> + <location filename="" line="7471221"/> <source>Repairing KI images</source> <translation>Repariere KI Bilder</translation> </message> <message> + <location filename="" line="7471221"/> <source>Sound priority</source> <translation>Tonpriorität</translation> </message> <message> + <location filename="" line="7471221"/> <source>Not implemented</source> <translation>Nicht implementiert</translation> </message> <message> + <location filename="" line="7471221"/> <source>Unsaved changes!</source> <translation>Ungespeicherte Änderungen!</translation> </message> <message> + <location filename="" line="7471221"/> <source>Do you want to save your changes?</source> <translation>Wollen sie die Änderungen speichern?</translation> </message> <message> + <location filename="" line="7471221"/> <source>No KI images to repair</source> <translation>Keine KI Bilder zu reparieren</translation> </message> <message> + <location filename="" line="7471221"/> <source>No KI images to repair were found.</source> <translation>Es müssen keine KI Bilder repariert werden.</translation> </message> <message> + <location filename="" line="7471221"/> <source>KI images repaired</source> <translation>KI Bilder repariert</translation> </message> <message> + <location filename="" line="7471221"/> <source>%1 repaired KI images were written to %2</source> <translation>%1 reparierte KI Bilder wurden nach @@ -370,18 +460,22 @@ kopiert</translation> </message> <message> + <location filename="" line="7471221"/> <source>Chatlog archive</source> <translation>Chatlog Archiv</translation> </message> <message> + <location filename="" line="7471221"/> <source>%1 chatlog(s) were moved to the archive.</source> <translation>%1 Chatlog wurden ins Archiv verschoben.</translation> </message> <message> + <location filename="" line="7471221"/> <source>No chatlog(s) to archive</source> <translation>Keine Chatlogs im Archiv</translation> </message> <message> + <location filename="" line="7471221"/> <source> <center> <h3>Tool for Myst Online : Uru Live</h3> @@ -406,70 +500,82 @@ <translation type="unfinished"></translation> </message> <message> + <location filename="" line="7471221"/> <source>D'ni time</source> - <translation type="unfinished"></translation> + <translation>D'ni Zeit</translation> </message> <message> + <location filename="" line="7471221"/> <source>Zip and delete debug logs</source> - <translation type="unfinished"></translation> + <translation>Packe und lösche Debuglogs</translation> </message> <message> + <location filename="" line="7471221"/> <source>Remove all zipped logs</source> - <translation type="unfinished"></translation> + <translation>Lösche alle gepackten Logs</translation> </message> <message> + <location filename="" line="7471221"/> <source>D'ni Numbers</source> - <translation type="unfinished"></translation> + <translation>D'ni Zahlen</translation> </message> <message> + <location filename="" line="7471221"/> <source>Choose Time</source> - <translation type="unfinished"></translation> + <translation>Wähle Zeit</translation> </message> <message> + <location filename="" line="7471221"/> <source>Earth Time</source> - <translation type="unfinished"></translation> + <translation>Erdzeit</translation> </message> <message> + <location filename="" line="7471221"/> <source>:</source> - <translation type="unfinished"></translation> + <translation>:</translation> </message> <message> + <location filename="" line="7471221"/> <source>/</source> - <translation type="unfinished"></translation> + <translation>/</translation> </message> <message> + <location filename="" line="7471221"/> <source>local time</source> - <translation type="unfinished"></translation> + <translation>Lokale Zeit</translation> </message> <message> - <source>cavern time</source> - <translation type="unfinished"></translation> - </message> - <message> + <location filename="" line="7471221"/> <source>UTC</source> - <translation type="unfinished"></translation> + <translation>UTC</translation> </message> <message> + <location filename="" line="7471221"/> <source>D'ni Time</source> - <translation type="unfinished"></translation> + <translation>D'ni Zeit</translation> </message> <message> + <location filename="" line="7471221"/> <source>Time</source> - <translation type="unfinished"></translation> + <translation>Zeit</translation> </message> <message> + <location filename="" line="7471221"/> <source>Clock</source> - <translation type="unfinished"></translation> + <translation>Uhr</translation> </message> <message> + <location filename="" line="7471221"/> <source>Holidays</source> - <translation type="unfinished"></translation> + <translation>Feiertage</translation> </message> <message> + <location filename="" line="7471221"/> <source>8 Leevosahn</source> - <translation type="unfinished"></translation> + <translation></translation> </message> <message> + <location filename="" line="7471221"/> <source><html><head><meta name="qrichtext" content="1" /><style type="text/css"> p, li { white-space: pre-wrap; } </style></head><body style=" font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal; text-decoration:none;"> @@ -477,16 +583,28 @@ <translation type="unfinished"></translation> </message> <message> + <location filename="" line="7471221"/> <source><html><head><meta name="qrichtext" content="1" /><style type="text/css"> p, li { white-space: pre-wrap; } </style></head><body style=" font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal; text-decoration:none;"> <p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"></p></body></html></source> <translation type="unfinished"></translation> </message> + <message> + <location filename="" line="7471221"/> + <source>Server</source> + <translation>Server</translation> + </message> + <message> + <location filename="" line="7471221"/> + <source>DNS</source> + <translation>DNS</translation> + </message> </context> <context> <name>SimpleProgressbar</name> <message> + <location filename="" line="7471221"/> <source>Title</source> <translation>Titel</translation> </message> @@ -494,10 +612,12 @@ <context> <name>app</name> <message> + <location filename="" line="7471221"/> <source>pyMoul QT already running</source> <translation>pyMoul QT läuft schon</translation> </message> <message> + <location filename="" line="7471221"/> <source>An instance of pyMoul QT is already running!</source> <translation>Eine Instanz von pyMoul QT läuft bereits!</translation> </message> @@ -505,10 +625,12 @@ <context> <name>context</name> <message> + <location filename="" line="7471221"/> <source>Not Implemented</source> <translation>Nicht implementiert</translation> </message> <message> + <location filename="" line="7471221"/> <source>Sorry, this feature is not implemented yet!</source> <translation>Dieses Feature wurde noch nicht implementiert!</translation> </message> @@ -516,8 +638,9 @@ <context> <name>excepthook</name> <message> + <location filename="" line="7471221"/> <source>An unhandled error has occured</source> - <translation type="unfinished"></translation> + <translation>Unbekannter Fehler</translation> </message> </context> </TS> Modified: pymoul/trunk/src/moul/qt/i18n/pymoul_es.ts =================================================================== --- pymoul/trunk/src/moul/qt/i18n/pymoul_es.ts 2007-02-27 03:10:11 UTC (rev 199) +++ pymoul/trunk/src/moul/qt/i18n/pymoul_es.ts 2007-02-27 03:20:16 UTC (rev 200) @@ -432,10 +432,6 @@ <translation type="unfinished"></translation> </message> <message> - <source>cavern time</source> - <translation type="unfinished"></translation> - </message> - <message> <source>UTC</source> <translation type="unfinished"></translation> </message> @@ -473,6 +469,14 @@ <p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"></p></body></html></source> <translation type="unfinished"></translation> </message> + <message> + <source>Server</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>DNS</source> + <translation type="unfinished"></translation> + </message> </context> <context> <name>SimpleProgressbar</name> Modified: pymoul/trunk/src/moul/qt/i18n/pymoul_fr.ts =================================================================== --- pymoul/trunk/src/moul/qt/i18n/pymoul_fr.ts 2007-02-27 03:10:11 UTC (rev 199) +++ pymoul/trunk/src/moul/qt/i18n/pymoul_fr.ts 2007-02-27 03:20:16 UTC (rev 200) @@ -432,10 +432,6 @@ <translation type="unfinished"></translation> </message> <message> - <source>cavern time</source> - <translation type="unfinished"></translation> - </message> - <message> <source>UTC</source> <translation type="unfinished"></translation> </message> @@ -473,6 +469,14 @@ <p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"></p></body></html></source> <translation type="unfinished"></translation> </message> + <message> + <source>Server</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>DNS</source> + <translation type="unfinished"></translation> + </message> </context> <context> <name>SimpleProgressbar</name> Modified: pymoul/trunk/src/moul/qt/i18n/pymoul_it.ts =================================================================== --- pymoul/trunk/src/moul/qt/i18n/pymoul_it.ts 2007-02-27 03:10:11 UTC (rev 199) +++ pymoul/trunk/src/moul/qt/i18n/pymoul_it.ts 2007-02-27 03:20:16 UTC (rev 200) @@ -432,10 +432,6 @@ <translation type="unfinished"></translation> </message> <message> - <source>cavern time</source> - <translation type="unfinished"></translation> - </message> - <message> <source>UTC</source> <translation type="unfinished"></translation> </message> @@ -473,6 +469,14 @@ <p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"></p></body></html></source> <translation type="unfinished"></translation> </message> + <message> + <source>Server</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>DNS</source> + <translation type="unfinished"></translation> + </message> </context> <context> <name>SimpleProgressbar</name> Modified: pymoul/trunk/src/moul/qt/i18n/pymoul_nl.ts =================================================================== --- pymoul/trunk/src/moul/qt/i18n/pymoul_nl.ts 2007-02-27 03:10:11 UTC (rev 199) +++ pymoul/trunk/src/moul/qt/i18n/pymoul_nl.ts 2007-02-27 03:20:16 UTC (rev 200) @@ -432,10 +432,6 @@ <translation type="unfinished"></translation> </message> <message> - <source>cavern time</source> - <translation type="unfinished"></translation> - </message> - <message> <source>UTC</source> <translation type="unfinished"></translation> </message> @@ -473,6 +469,14 @@ <p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"></p></body></html></source> <translation type="unfinished"></translation> </message> + <message> + <source>Server</source> + <translation type="unfinished"></translation> + </message> + <message> + <source>DNS</source> + <translation type="unfinished"></translation> + </message> </context> <context> <name>SimpleProgressbar</name> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |