Re: Python Pseudo-Switch

2005-05-09 Thread Jason Mobarak
# -*- python -*-

import sys


def switchFor (target):
sw = '__switch_table__'
# please pretend the frame hack is not here,
# it happens to work for classes and messing with
# frame stack in a try/except is probably okay
try:
raise Exception()
except:
defs = sys.exc_info()[2].tb_frame.f_back.f_locals
if sw not in defs:
defs[sw] = {}
table = defs[sw]
def _(meth):
table[target] = meth
return meth
return _


class SwitchMixin (object):

def __init__ (self):
self.__switch_table__ = self.__switch_table__.copy()

def switchOn (self, target, *args, **kw):
return self.__switch_table__[target](self, *args, **kw)


if __name__ == '__main__':

class SwitchTest(SwitchMixin):

@switchFor("foo")
def switch (self, arg):
print arg * 3

@switchFor("bar")
def switch (self, arg):
print "__%s__" % (arg,)

@switchFor("baz")
def switch (self, arg):
print arg + ''.join(reversed(arg))

st = SwitchTest()

st.switchOn("foo", "oof")
st.switchOn("bar", "rab")
st.switchOn("baz", "zab")

-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Active Directory Modules?

2005-05-09 Thread Tim Golden
[Harlin Seritt]

| Does anyone know if there are any Python Active Directory Modules out
| there? I looked at LDAP module but there is no version for Python 2.4
| and it's support for Active Directory seems to be lacking a bit.

Far from perfect, but functional. Uses pywin32.

http://tgolden.sc.sabren.com/python/active_directory.html

(and also about the fifth link on Google for 
python active directory, by the way).

TJG


This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk

-- 
http://mail.python.org/mailman/listinfo/python-list


RE: how to pass an array to a VB array via COM

2005-05-09 Thread Stefan Schukat
A patch is available at sourceforge:

https://sourceforge.net/tracker/index.php?func=detail&aid=1195096&group_id=78018&atid=551956.

Stefan

> -Original Message-
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] Behalf Of
> jelle
> Sent: Friday, April 29, 2005 4:56 PM
> To: python-list@python.org
> Subject: Re: how to pass an array to a VB array via COM
> 
> 
> Hi Stefan,
> 
> Thanks for your insightful and in-depth response!
> Wonderful to hear that a solution is in the works, that's absolutely
> wonderful news.
> If I can help you out beta-testing the PySafeArray implementation, I'd
> be delighted to do so. Thanks again, Jelle.
> 
> -- 
> http://mail.python.org/mailman/listinfo/python-list
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Exception in Python 2.3.3 Interpreter

2005-05-09 Thread Saravanan
Hello,


Im running Python Application as a Windows Service (using windows
extensions).  But, sporadically the application crashes (crash in
Python23.dll) and this stops the service.  This problem cann't be
reproduced easily in my system and the call stack generated by the
application is given below. Please note that the call stack generation
is taken from crash dump file.

The crash occured at the following line:
c = strcmp(vname, wname) (object.c)

# ChildEBP RetAddr  Args to Child
00 023ffa58 1e05c6da 055b1250 00637470 
python23!default_3way_compare(struct _object * v = 0x053f2bfc, struct
_object * w = 0x0001)+0x102
[F:\Python-2.3.3\Python-2.3.3\Objects\object.c @ 689]
01 023ffa74 1e05c5ee 055b1250 00637470 
python23!do_richcmp(struct _object * v = 0x1e0b9fb8, struct _object * w
= 0x, int op = 0)+0x4a
02 023ffa94 1e0174d9 055b1250 00637470 
python23!PyObject_RichCompare(struct _object * v = 0x053f2bfc, struct
_object * w = 0x0001, int op = 0)+0x1ae
[F:\Python-2.3.3\Python-2.3.3\Objects\object.c @ 1044]
03 023ffaa4 1e013182  055b1250 00637470
python23!cmp_outcome(int op = 88026108, struct _object * v =
0x0001, struct _object * w = 0x)+0xa9
[F:\Python-2.3.3\Python-2.3.3\Python\ceval.c @ 3880]
04 023ffb18 1e016ba4 014f3318 0002 0099f170
python23!eval_frame(struct _frame * f = 0x053f2bfc)+0x542
[F:\Python-2.3.3\Python-2.3.3\Python\ceval.c @ 1965]
05 023ffb30 1e016a69 0099f170 023ffb7c 0002
python23!fast_function(struct _object * func = ,
struct _object *** pp_stack = , int n = , int na = , int nk = )+0x94 [F:\Python-2.3.3\Python-2.3.3\Python\ceval.c @ 3520]
06 023ffb5c 1e014b65 00a280d0 0002 0008
python23!call_function(struct _object *** pp_stack = 0x0001, int
oparg = 0)+0x159 [F:\Python-2.3.3\Python-2.3.3\Python\ceval.c @ 3458]
07 023ffbcc 1e016ba4 006ea160 0001 0099f1b0
python23!eval_frame(struct _frame * f = )+0x1f25
[F:\Python-2.3.3\Python-2.3.3\Python\ceval.c @ 2117]
08 023ffbe4 1e016a69 0099f1b0 023ffc30 0001
python23!fast_function(struct _object * func = ,
struct _object *** pp_stack = , int n = , int na = , int nk = )+0x94 [F:\Python-2.3.3\Python-2.3.3\Python\ceval.c @ 3520]
09 023ffc10 1e014b65 00a280d0 0001 
python23!call_function(struct _object *** pp_stack = 0x, int
oparg = 0)+0x159 [F:\Python-2.3.3\Python-2.3.3\Python\ceval.c @ 3458]
0a 023ffc80 1e015b6f 006cf6d0  00a1df9c
python23!eval_frame(struct _frame * f = )+0x1f25
[F:\Python-2.3.3\Python-2.3.3\Python\ceval.c @ 2117]
0b 023ffcac 1e040978 0096b720 0001 006cf6d0
python23!PyEval_EvalCodeEx(struct PyCodeObject * co = , struct _object * globals = , struct
_object * locals = , struct _object ** args =
, int argcount = , struct
_object ** kws = , int kwcount = , struct _object ** defs = , int defcount =
, struct _object * closure = )+0x70f [F:\Python-2.3.3\Python-2.3.3\Python\ceval.c @ 2663]
0c 023ffcf0 1e0078ec 009788b0 00a1df90 
python23!function_call(struct _object * func = 0x1e0baa50, struct
_object * arg = 0x0096b720, struct _object * kw = 0x00954390)+0x138
[F:\Python-2.3.3\Python-2.3.3\Objects\funcobject.c @ 512]
0d 023ffd04 1e01be03 009788b0 00a1df90 
python23!PyObject_Call(struct _object * func = 0x1e0d7608, struct
_object * arg = 0x0001, struct _object * kw = 0x00a280d0)+0x1c
[F:\Python-2.3.3\Python-2.3.3\Objects\abstract.c @ 1755]
0e 023fff24 1e0078ec 00a20f08 00671030 
python23!instancemethod_call(struct _object * func = 0x1e0d7608, struct
_object * arg = 0x0001, struct _object * kw = 0x00a280d0)+0x133
[F:\Python-2.3.3\Python-2.3.3\Objects\classobject.c @ 2433]
0f 023fff38 1e016827 00a20f08 00671030 
python23!PyObject_Call(struct _object * func = 0x77e4a990, struct
_object * arg = 0x01415bd8, struct _object * kw = 0x)+0x1c
[F:\Python-2.3.3\Python-2.3.3\Objects\abstract.c @ 1755]
10 023fff50 1e080c77 00a20f08 00671030 
python23!PyEval_CallObjectWithKeywords(struct _object * func =
0x77e4a990, struct _object * arg = 0x01415bd8, struct _object * kw =
0x)+0xa7 [F:\Python-2.3.3\Python-2.3.3\Python\ceval.c @ 3346]
11 023fff70 1e080675 013d8ba0  014161a8
python23!t_bootstrap(void * boot_raw = 0x77e4a990)+0x37
[F:\Python-2.3.3\Python-2.3.3\Modules\threadmodule.c @ 183]
12 023fff84 77bc90a2 0086f32c  
python23!PyThread_get_thread_ident(void)+0x5
[F:\Python-2.3.3\Python-2.3.3\Python\thread_nt.h @ 213]
13 023fffb8 77e4a990 01415bd8   msvcrt!_endthread+0xa6
14 023fffec  77bc9032 01415bd8 
kernel32!BaseThreadStart+0x34

Any clues about the problem ?

- Saravanan D

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Exception in Python 2.3.3 Interpreter

2005-05-09 Thread Saravanan D
Hello,

The crash occured at the following line :

c = strcmp(vname, wname) (object.c)

Please note that the dump has been taken with the help of adplus.


# ChildEBP RetAddr  Args to Child
00 023ffa58 1e05c6da 055b1250 00637470 
python23!default_3way_compare(struct _object * v = 0x053f2bfc, struct
_object * w = 0x0001)+0x102
[F:\Python-2.3.3\Python-2.3.3\Objects\object.c @ 689]
01 023ffa74 1e05c5ee 055b1250 00637470  python23!do_richcmp(struct
_object * v = 0x1e0b9fb8, struct _object * w = 0x, int op = 0)+0x4a
02 023ffa94 1e0174d9 055b1250 00637470 
python23!PyObject_RichCompare(struct _object * v = 0x053f2bfc, struct
_object * w = 0x0001, int op = 0)+0x1ae
[F:\Python-2.3.3\Python-2.3.3\Objects\object.c @ 1044]
03 023ffaa4 1e013182  055b1250 00637470 python23!cmp_outcome(int op
= 88026108, struct _object * v = 0x0001, struct _object * w =
0x)+0xa9 [F:\Python-2.3.3\Python-2.3.3\Python\ceval.c @ 3880]
04 023ffb18 1e016ba4 014f3318 0002 0099f170 python23!eval_frame(struct
_frame * f = 0x053f2bfc)+0x542 [F:\Python-2.3.3\Python-2.3.3\Python\ceval.c
@ 1965]
05 023ffb30 1e016a69 0099f170 023ffb7c 0002
python23!fast_function(struct _object * func = , struct
_object *** pp_stack = , int n = ,
int na = , int nk = )+0x94
[F:\Python-2.3.3\Python-2.3.3\Python\ceval.c @ 3520]
06 023ffb5c 1e014b65 00a280d0 0002 0008
python23!call_function(struct _object *** pp_stack = 0x0001, int oparg =
0)+0x159 [F:\Python-2.3.3\Python-2.3.3\Python\ceval.c @ 3458]
07 023ffbcc 1e016ba4 006ea160 0001 0099f1b0 python23!eval_frame(struct
_frame * f = )+0x1f25
[F:\Python-2.3.3\Python-2.3.3\Python\ceval.c @ 2117]
08 023ffbe4 1e016a69 0099f1b0 023ffc30 0001
python23!fast_function(struct _object * func = , struct
_object *** pp_stack = , int n = ,
int na = , int nk = )+0x94
[F:\Python-2.3.3\Python-2.3.3\Python\ceval.c @ 3520]
09 023ffc10 1e014b65 00a280d0 0001 
python23!call_function(struct _object *** pp_stack = 0x, int oparg =
0)+0x159 [F:\Python-2.3.3\Python-2.3.3\Python\ceval.c @ 3458]
0a 023ffc80 1e015b6f 006cf6d0  00a1df9c python23!eval_frame(struct
_frame * f = )+0x1f25
[F:\Python-2.3.3\Python-2.3.3\Python\ceval.c @ 2117]
0b 023ffcac 1e040978 0096b720 0001 006cf6d0
python23!PyEval_EvalCodeEx(struct PyCodeObject * co = ,
struct _object * globals = , struct _object * locals =
, struct _object ** args = , int
argcount = , struct _object ** kws = , int kwcount = , struct _object ** defs =
, int defcount = , struct _object
* closure = )+0x70f
[F:\Python-2.3.3\Python-2.3.3\Python\ceval.c @ 2663]
0c 023ffcf0 1e0078ec 009788b0 00a1df90 
python23!function_call(struct _object * func = 0x1e0baa50, struct _object *
arg = 0x0096b720, struct _object * kw = 0x00954390)+0x138
[F:\Python-2.3.3\Python-2.3.3\Objects\funcobject.c @ 512]
0d 023ffd04 1e01be03 009788b0 00a1df90 
python23!PyObject_Call(struct _object * func = 0x1e0d7608, struct _object *
arg = 0x0001, struct _object * kw = 0x00a280d0)+0x1c
[F:\Python-2.3.3\Python-2.3.3\Objects\abstract.c @ 1755]
0e 023fff24 1e0078ec 00a20f08 00671030 
python23!instancemethod_call(struct _object * func = 0x1e0d7608, struct
_object * arg = 0x0001, struct _object * kw = 0x00a280d0)+0x133
[F:\Python-2.3.3\Python-2.3.3\Objects\classobject.c @ 2433]
0f 023fff38 1e016827 00a20f08 00671030 
python23!PyObject_Call(struct _object * func = 0x77e4a990, struct _object *
arg = 0x01415bd8, struct _object * kw = 0x)+0x1c
[F:\Python-2.3.3\Python-2.3.3\Objects\abstract.c @ 1755]
10 023fff50 1e080c77 00a20f08 00671030 
python23!PyEval_CallObjectWithKeywords(struct _object * func = 0x77e4a990,
struct _object * arg = 0x01415bd8, struct _object * kw = 0x)+0xa7
[F:\Python-2.3.3\Python-2.3.3\Python\ceval.c @ 3346]
11 023fff70 1e080675 013d8ba0  014161a8 python23!t_bootstrap(void *
boot_raw = 0x77e4a990)+0x37
[F:\Python-2.3.3\Python-2.3.3\Modules\threadmodule.c @ 183]
12 023fff84 77bc90a2 0086f32c  
python23!PyThread_get_thread_ident(void)+0x5
[F:\Python-2.3.3\Python-2.3.3\Python\thread_nt.h @ 213]
13 023fffb8 77e4a990 01415bd8   msvcrt!_endthread+0xa6
14 023fffec  77bc9032 01415bd8 
kernel32!BaseThreadStart+0x34

- Saravanan D
"Saravanan" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Hello,
>
> Im running Python Application as a Windows Service (using windows
> extensions).  But, sporadically the application crashes (crash in
> Python23.dll) and this stops the service.  This problem cann't be
> reproduced easily in my system and the call stack generated by the
> application is given below.
>
>
> Occurrence: 2005/4/22  23:24:57
> Process Id:  3072
> Process Name : D:\Python23\lib\site-packages\win32\PythonService.exe
> Thread Id:  292
> Exception code: C005 ACCESS_VIOLATION
> Fault address:  1E05C202 01:0005B202 C:\WINDOWS\system32\python23.dll
>
> Registers:
> EAX:1E0E2EAC
> EBX

Python LDAP Schema Pickle

2005-05-09 Thread [EMAIL PROTECTED]
After much googling, I'm yet to see hint at the following topic.

Has anyone ever worked on supporting ldap persistance of python
objects? I'm a bit new to ldap, and I've noticed that there is a
java.schema file standardized that stores persists java objects in an
ldap directory.

I would think that this would be something that could implemented with
a pickle-like interface?

If anyone has done any kind of work on this, I'd be very interested in
looking into it and possibly helping out.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python LDAP Schema Pickle

2005-05-09 Thread hemanth
Why don't you check if ldaptor has implemented a similar functionality?
I got the following link while googling:


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Trouble saving unicode text to file

2005-05-09 Thread F. Petitjean
Le Mon, 09 May 2005 08:39:40 +1000, John Machin a écrit :
> On Sun, 08 May 2005 19:49:42 +0200, "Martin v. Löwis"
><[EMAIL PROTECTED]> wrote:
> 
>>John Machin wrote:
>>> Martin, I can't guess the reason for this last suggestion; why should
>>> a Windows system use iso-8859-1 instead of cp1252?
>>
>>Windows users often think that windows-1252 is the same thing as
>>iso-8859-1, and then exchange data in windows-1252, but declare them
>>as iso-8859-1 (in particular, this is common for HTML files).
>>iso-8859-1 is more portable than windows-1252, so it should be
>>preferred when the data need to be exchanged across systems.
> 
> 1. When exchanging data across systems, should not utf-8 be
> preferred???
> 
> 2. If the Windows *users* have been using characters that are in
> cp1252 but not in iso-8859-1, then attempting to convert to iso-8859-1
> will cause an exception. 
> 
 euro_win = chr(128)
 euro_uc = euro_win.decode('cp1252')
 euro_uc
> u'\u20ac'
 unicodedata.name(euro_uc)
> 'EURO SIGN'
 euro_iso = euro_uc.encode('iso-8859-1')
> Traceback (most recent call last):
>   File "", line 1, in ?
> UnicodeEncodeError: 'latin-1' codec can't encode character u'\u20ac'
> in position 0: ordinal not in range(256)

> 
> I find it a bit hard to imagine that the euro sign wouldn't get a fair
> bit of usage in Swedish data processing even if it's not their own
> currency.
For western Europe countries, another codec exists which includes the
'EURO SIGN'. It is spelled 'iso8859_15' (with an alias 'iso-8859-15'
according to the 4.9.2 Standard Encodings page of the python library
reference).
euro_iso = euro_uc.encode('iso8859_15')
>>> euro_iso
'\xa4'
> 
> 3. How portable is a character set that doesn't include the euro sign?
I think it is due to historical constraints : isoLatin1 existed before
that the EURO SIGN appeared.
> 
> Regards,
> John
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Strip white spaces from source

2005-05-09 Thread Richie Hindle

[qwweeeit]
> I need to limit as much as possible the lenght of a source line,
> stripping white spaces (except indentation).
> For example:
> .   .   max_move and AC_RowStack.acceptsCards ( self, from_stack, cards
> )
> must be reduced to:
> .   .   max_move and AC_RowStack.acceptsCards(self,from_stack,cards)

Here's a script that does some of what you want (stripping whitespace within
the three types of brackets).  It was written to make code more compliant with
the Python style guide.

--- unspace.py ---

"""Strips spaces from inside brackets in Python source code, turning
( this ) into (this) and [ 1, ( 2, 3 ) ] into [1, (2, 3)].  This makes
the code more compliant with the Python style guide.  Usage:

  unspace.py filename

Output goes to stdout.

This file is deliberately written with lots of spaces within brackets,
so you can use it as test input.
"""

import sys, re, token, tokenize

OPEN = [ '(', '[', '{' ]
CLOSE = [ ')', ']', '}' ]

class UnSpace:
"""Holds the state of the process; onToken is a tokenize.tokenize
callback.
"""
def __init__( self ):
self.line = None # The text of the current line.
self.number = -1 # The line number of the current line.
self.deleted = 0 # How many spaces have been deleted from 'line'.

self.last_srow = 0
self.last_scol = 0
self.last_erow = 0
self.last_ecol = 0
self.last_line = ''

def onToken( self, type, tok, ( srow, scol ), ( erow, ecol ), line ):
"""tokenize.tokenize callback."""
# Print trailing backslashes plus the indent for new lines.
if self.last_erow != srow:
match = re.search( r'(\s+\\\n)$', self.last_line )
if match:
sys.stdout.write( match.group( 1 ) )
sys.stdout.write( line[ :scol ] )

# Print intertoken whitespace except the stuff to strip.
if self.last_srow == srow and \
   not ( self.last_type == token.OP and self.last_tok in OPEN ) and \
   not ( type == token.OP and tok in CLOSE ):
sys.stdout.write( line[ self.last_ecol:scol ] )

# Print the token itself.
sys.stdout.write( tok )

# Remember the properties of this token.
self.last_srow, self.last_scol = ( srow, scol )
self.last_erow, self.last_ecol = ( erow, ecol )
self.last_type, self.last_tok = type, tok
self.last_line = line

def flush( self ):
if self.line is not None:
sys.stdout.write( self.line )


if __name__ == '__main__':
if len( sys.argv ) != 2:
print __doc__
else:
file = open( sys.argv[ 1 ], 'rt' )
unSpace = UnSpace()
tokenize.tokenize( file.readline, unSpace.onToken )
unSpace.flush()

-- 
Richie Hindle
[EMAIL PROTECTED]

-- 
http://mail.python.org/mailman/listinfo/python-list


regarding try/except usa

2005-05-09 Thread praba kar
Dear All,

   Is there any rules and regulations to use
try/except in python?  Can any one explain to me when
I need to use try/except and when we I need not use
try/except?.  This Question mainly for to maintain
code integrity in my project.  But I know
how to use try/except

regards
Praba
 


Yahoo! India Matrimony: Find your life partner online
Go to: http://yahoo.shaadi.com/india-matrimony
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: regarding try/except usa

2005-05-09 Thread [EMAIL PROTECTED]
Well, there is a lot to say about this subject. Start reading with
this: http://docs.python.org/tut/node10.html

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: hard memory limits

2005-05-09 Thread Fredrik Lundh
Mike Meyer wrote:

> There is something very non-unixy going on here, though. Why is
> vm_malloc exiting with an error message, instead of returning a
> failure to the calling application? I've seen other applications
> include a FOSS malloc implementation to work around bugs in the
> system's malloc. Maybe Python should do that on the Mac?

from what I can tell (by reading the google hits), the malloc implementation
prints a message, but returns NULL as usual (you can find reports of this
message preceeding a MemoryError traceback).

 



-- 
http://mail.python.org/mailman/listinfo/python-list


is there a python object which can interpret java-script?

2005-05-09 Thread Alexander Fillips
Hi,

my short question:

is there a python object which can interpret java-script?

the whole story ;-)

I wrote some streaming-scripts for the xbox mediaplayer which supports 
python. for a new script i tried to filter the stream-url from an 
website. it seems, that the site ist using java-script and the url is 
only visible if the java-script was interpreted. i am using urllib to 
retrieve the page.. but it seems that urllib is not ready for 
java-script...

the site:
http://www.prosieben.de/show_comedy/bullyrick/popup_video/07029//

the url i need:
http://redirect.streaming.szm.de/redirect/redirect.php?type=vod&codec=ms&stream=Pro7/show_comedy/bullyrick/bur_007_plattenladen.wmv&;


i hoper someone has an idea...

cya
Alex
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Fredrik Lundh

2005-05-09 Thread Fredrik Lundh
Robert Kern wrote:

>> It hides any mention that Fredrik Lundh is behind it, which is deceitful
>> when he posts any smidgeon of praise his software gets, not admitting he
>> makes his income off support fees for that same software.
>
> I think that reasonable people can draw a line. I would welcome more
> disclosure, however.

I do not make my income off support fees for the free software you can down-
load from pythonware.com or effbot.org. (if you want to know what I do for a
living, check the pythonware.com front-page).

I'm not the only daily-URL editor either; I hardly ever post links to my own 
stuff
(but that doesn't stop other editors from doing that).

And Doug doesn't work for the IronPython project.

And this is the last thing I'm ever going to say about this; I think any 
reasonable
person can tell who's the certified nutcase in this thread, and who's not.

 



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: is there a python object which can interpret java-script?

2005-05-09 Thread Robert Kern
Alexander Fillips wrote:
> Hi,
> 
> my short question:
> 
> is there a python object which can interpret java-script?
> 
> the whole story ;-)

google("python javascript")

First link is a Python binding to the SpiderMonkey JavaScript 
interpreter from the Mozilla project. It's unmaintained, and I've never 
tested it, but it's worth a try.

-- 
Robert Kern
[EMAIL PROTECTED]

"In the fields of hell where the grass grows high
  Are the graves of dreams allowed to die."
   -- Richard Harter

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: path(file)

2005-05-09 Thread Fuzzyman
Can you give us an example of the way the 'list of files' is stored in.

import os
print os.path.abspath(filename)

Will do *something*... so long as 'filename' contains a path relative
to the current working directory. What you want is undoubtably in the
os and os.path modules.

Regards,

Fuzzy
http://www.voidspace.org.uk/python

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: New Python regex Doc

2005-05-09 Thread Fredrik Lundh
Mike Meyer wrote:

> After doing a google for "regular expression greedy", the second match
> starts with the text:
>
>  By default, pattern matching is greedy, which means that the matcher
>  returns the longest match possible.
>
> Now, it can be argued that the term ought not to be used, except that
> it's a standard term with a well-known meaning, and exactly describes
> the behavior in question.

fwiw, judging from frequently asked questions and bug reports,
people have no problems understanding the phrase "greedy", but
they sometimes have problems understanding why "return the
longest match possible" doesn't always mean "return the overall
longest match possible"

(using the greedy modifier only applies to the given RE operator;
it doesn't modify the behaviour of other operators, or the method
used; e.g. | will still pick the *first* possible match even if one of
the alternatives use a greedy operator, search/find still scans the
target string from left to right, etc).





-- 
http://mail.python.org/mailman/listinfo/python-list


[ANNOUNCE] PyKota v1.08 is out

2005-05-09 Thread Jerome Alet
Hi there,

I'm pleased to announce that PyKota v1.08 is out.

PyKota is an entirely Python written, GNU GPLed, centralized, full featured,
internationalized, and easily extensible, print quota and accounting
solution for CUPS and LPRng under Unix like systems like GNU/Linux.

This release includes two major bug fixes wrt LPRng and account balance
increasing or decreasing.

Also an LDAP schema is included with a sample LDIF file, they will serve
as the basis of the future LDAP storage backend, and are included in this
release for people to look at, try, and discuss.

Minor bugs were also fixed.

IMPORTANT : before upgrading, please DELETE the old site-packages/pykota
directory since some files are not needed anymore, and replace
'postgresql' with 'pgstorage' in /etc/pykota.conf

Learn more about PyKota, see live reports or screenshots, download the CVS
version or buy an official package from :

  http://www.librelogiciel.com/software/PyKota/action_Presentation

Discuss with us, ask for help, report problems or successes, on the
mailing list at :

  http://cgi.librelogiciel.com/mailman/listinfo/pykota

Thank you for reading

Jerome Alet
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: is there a python object which can interpret java-script?

2005-05-09 Thread Kartic
The Great 'Alexander Fillips' uttered these words on 5/9/2005 7:34 AM:
> Hi,
> 
> my short question:
> 
> is there a python object which can interpret java-script?
> 
> the whole story ;-)
> 
> I wrote some streaming-scripts for the xbox mediaplayer which supports 
> python. for a new script i tried to filter the stream-url from an 
> website. it seems, that the site ist using java-script and the url is 
> only visible if the java-script was interpreted. i am using urllib to 
> retrieve the page.. but it seems that urllib is not ready for 
> java-script...

http://wwwsearch.sourceforge.net/python-spidermonkey/ is a 
Python-Javascript bridge.

To do what you are trying, you will have to execute the Javascript in 
that web page in the context of the page you are downloading...I am not 
quite sure how you will go about doing that without re-inventing what a 
Javascript-enabled browser does.

Knowing nothing about the Xbox environment, here is a suggestion that I 
feel will make your task easier. Can you not use javascript-enabled 
links text browser to access the page and capture the output HTML source 
from links into Python? (Or if you can use win32all, you can automate IE 
to view source and process that source in Python to get your URL)

Thanks,
-Kartic
-- 
http://mail.python.org/mailman/listinfo/python-list


[ANNOUNCE] PyKota v1.22 is out !

2005-05-09 Thread Jerome Alet
I'm pleased to announce the availability of PyKota v1.22 Final.

PyKota is a 100% Python written Print Quota and Accounting solution for
CUPS and LPRng, published under the terms of the GNU General Public
License of the Free Software Foundation, and is available from :

  http://www.librelogiciel.com/software/PyKota/action_Presentation

PyKota's original distribution method consists in providing Official
tarballs, DEB and RPM packages for a yearly fee of 20 US$ (minimum), while
letting everyone download Unofficial versions of this software free of
charge by using Subversion (aka svn).

Free subscriptions to Official packages and complete paper documentation
are now included for people who prefer to purchase a technical support
contract.

Finally, single Official packages (without subscription for new releases),
can now be purchased directly and anonymously for a one time 9.99 US$ fee.

This release is a minor update, and no database changes are necessary if
you already use 1.21, so installing it should be really easy.

List of changes since 1.21 :


  - Introduction of the web-enabled print quote generator :
Install it on a web server, and people will be allowed to remotely
know in advance how much a print job will cost to them.

  - The job's billing code, if present, is now saved into the
database, and can serve as a filter for both the standalone
data dumper, and the web-enabled print quota monitor and data
dumper. Provided your printer driver allows you to enter this
code, you'll now be able to produce invoices based on its value.
This billing code is also made available to your pre and post hooks
through an additionnal environment variable.

  - Printer's internal page counter retrieval was greatly improved
with regard to both power saving mode and buggy printers.

  - The integrated banner generator now allows the admin to put
additionnal informations dynamically onto the banner pages.

  - Diagnostic messages were greatly improved when something went
wrong at startup time.

  - Portability was improved wrt LDAP.

  - Several stability improvements and bug fixes.

  - Greatly improved documentation.

The full list of changes is available from :

  http://www.librelogiciel.com/software/PyKota/action_News

Thank you for reading !

Jerome Alet
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [ANNOUNCE] PyKota v1.08 is out

2005-05-09 Thread Jerome Alet
This one is completely outdated, sorry for the inconvenience.

In addition I wasn't able to cancel it because of some error on my part...

Sorry again

Jerome
-- 
http://mail.python.org/mailman/listinfo/python-list


memory leak

2005-05-09 Thread Carlos Garcia



Hi All,
 
  I have a 
memory leak in an application that uses the Python.exec() method multiple times,
i can see in jprobe that 
instance of classes org.python.pycode._pyx* andorg.python.proxies.* 
dynamically created during an exec  are not cleaned by the 

garbage collector. 

 
    Any idea about what can i do? 
 
Thanks,
Carlos

== Carlos 
García    
Phone  : +34 91 714 8796 Lucent 
Technologies  e-mail : [EMAIL PROTECTED] Avenida de 
Bruselas , 8   -  28108 Alcobendas 
(Madrid)==
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Exception in Python 2.3.3 Interpreter

2005-05-09 Thread Fredrik Lundh
"Saravanan D" <[EMAIL PROTECTED]> wrote:

> 03 023ffaa4 1e013182  055b1250 00637470 python23!cmp_outcome(int op
> = 88026108, struct _object * v = 0x0001, struct _object * w =
> 0x)+0xa9 [F:\Python-2.3.3\Python-2.3.3\Python\ceval.c @ 3880]
> 04 023ffb18 1e016ba4 014f3318 0002 0099f170 python23!eval_frame(struct
> _frame * f = 0x053f2bfc)+0x542 [F:\Python-2.3.3\Python-2.3.3\Python\ceval.c
> @ 1965]
> 05 023ffb30 1e016a69 0099f170 023ffb7c 0002
> python23!fast_function(struct _object * func = , struct
> _object *** pp_stack = , int n = ,
> int na = , int nk = )+0x94

the above doesn't look very healthy.  does your application involve
non-standard extensions (including extensions you've written your-
self)?  does the extensions contain callbacks into Python code?





-- 
http://mail.python.org/mailman/listinfo/python-list


ANN: rest2web 0.1.0

2005-05-09 Thread Fuzzyman
Finally, the long awaited (*ahem*) release of **rest2web**.
It's an early release - lot's more features still to be added - but it
all works. *Hurrah*

rest2web is a tool for autogenerating websites. It allows you to store
your contents in reST format, and generate pages and indexes from
templates. It uses a simple but flexible templating system and
generates index pages and navigation links.

This means that adding new pages is as easy as dropping a text file
into the right folder. rest2web will handle adding the link to the
index page and creating the new page from a template and the contents.
Removing a page is as easy as deleting a single file, and have rest2web
automatically rebuild the indexes.

The download includes the rest2web code, and docs, and a test site. The
test site serves as a simple illustration of how rest2web builds pages
and indexes.

For full details see any of the following pages :

* `rest2web Docs` - http://www.voidspace.org.uk/python/rest2web
* `Example Site` -
http://www.voidspace.org.uk/python/rest2web/test_site
* `Quick Download (608k)` -
http://www.voidspace.org.uk/cgi-bin/voidspace/downman.py?file=rest2web.zip

The next features to add will be auto sitemap generation and a bigger
change (under the hood) to make the index data available to every page
in a section. This will allow pages to have sidebars with links, rather
than just a single index page per section.

I'm already building part of the Voidspace website with rest2web, over
the next few months it will take over

Lots of other features, tested on Linux and Windoze.

Fuzzyman
http://www.voidspace.org.uk/python

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: clear the files using python

2005-05-09 Thread Peter Hansen
Sez sez:
> Each file's structure as below:
> Comments: This is article 1965 obtained from the website
> Title: Banana Report #65, September 2003
> Author: dylab
> Date: 1st September 2003
> Section: pulse
> 
> In the past month:
> A mass hit North America, cutting electricity to 50 million people
> across the North east
> 
> 
> I'm expected execute the python script so the file suppose to look like
> this:
> 
> pulse, In, the, past, month, A, mass, hit, North, America, cutting,
> electricity, to, 50, million, people, across, the, North east, dylab

You'll need either more examples or a more detailed description.  The 
above could be interpreted as something like "put the pulse section 
first, then exactly 19 words from the following text, removing 
punctuation and line breaks, and taking the last two words together as 
one, then add the 'author' field, and write them all out together with a 
field separator of ', ' (comma plus space)".

On the other hand, it could be interpreted a large number of other ways, 
and since none of us have any idea what you are trying to do with the 
results, we can't use our own intuition or experience to help.

I also personally find it hard to respond to questions like this with 
real code when there are things about the task which I find very 
surprising.  For example, you're throwing away the date information 
entirely, along with the comments and title.  Is that really intended?

And are the author and section fields always exactly one word, with no 
punctuation?  (What would happen if an author's name was "Hansen, 
Peter"?  How would you format that in the output without getting the 
first name confused with the next field?)

> Could you please point me to right direction here. Or provide some
> example code. In the mean time I'll be searching myself. I know you
> guys hate novice people like me but I would appreciated if you could
> provide little help here.

We don't "hate" novice people by any means... I suspect you are either 
trying to be self-deprecating or maybe you just haven't read this 
newsgroup for long.  c.l.p actually *loves* novices; it just doesn't 
prefer questions that aren't very clear.  Keep trying (and improving!) 
and you'll definitely get the help you need.

And your comment about Python being the best language for this is pretty 
close to the mark... but there are certainly a variety of ways to go 
about the task and the best might depend on a lot of unanswered questions.

-Peter
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: clear the files using python

2005-05-09 Thread Simon Brunning
On 8 May 2005 21:55:04 -0700, Sez <[EMAIL PROTECTED]> wrote:
> Could you please point me to right direction here. Or provide some
> example code. In the mean time I'll be searching myself. I know you
> guys hate novice people like me but I would appreciated if you could
> provide little help here.

Oh, we don't hate novices here, not at all. On the other hand, we
aren't going to write your script for you. ;-) Why not take a look at
the Python beginners guide (at
), and come back to us when
you have a specific problem.

-- 
Cheers,
Simon B,
[EMAIL PROTECTED],
http://www.brunningonline.net/simon/blog/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: __brace__ (PEP?)

2005-05-09 Thread Roy Smith
"Kay Schluehr" <[EMAIL PROTECTED]> wrote:

> Roy Smith wrote:
> 
> > foo->bar ==> foo.__arrrow__(bar)
> > foo$bar ==> foo.__dollar__(bar)
> > foo#bar ==> foo.__hash__(bar)
> > foo::bar ==> foo.__scope__(bar)
> 
> I'm strongly in favor for the arrow ( but with two "r" only ). The
> question is simply: for what?

I'm confused.  You're strongly in favor of a piece of punctuation even 
though you don't have any idea what it might be used for?
-- 
http://mail.python.org/mailman/listinfo/python-list


replace string patern with different value

2005-05-09 Thread [EMAIL PROTECTED]
Hello,

I would like to replace string with different values,
For example :
source = 'kode1 bla bla kode1 bla kode1'
I have a list with each member will replace each of kode1.
L = [11,22,33]
So the new source will become:
newsource = '11 bla bla 22 bla 33'

How can I do it ? I tried to find using string built in function
replace, but it will replace pattern with the same value.

For this moment I think about change the string into list using
string.split and then check one by one and replace it and then convert
into string with addition space in the right and left of each element
list.

Is there any better idea ?

Pujo

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Trouble saving unicode text to file

2005-05-09 Thread Fredrik Lundh
John Machin wrote:

> I find it a bit hard to imagine that the euro sign wouldn't get a fair
> bit of usage in Swedish data processing even if it's not their own
> currency.

it's spelled "Euro" or "EUR" in swedish.

(if you live in a country that use letters to represent its own currency,
you tend to prefer letters for "foreign" currencies as well)

(I just noticed that there's no euro sign on my swedish keyboard.  I've
never missed it ;-)

 



-- 
http://mail.python.org/mailman/listinfo/python-list


replace string patern with different value

2005-05-09 Thread Bill Mill
On 9 May 2005 06:23:41 -0700, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> Hello,
>
> I would like to replace string with different values,
> For example :
> source = 'kode1 bla bla kode1 bla kode1'
> I have a list with each member will replace each of kode1.
> L = [11,22,33]
> So the new source will become:
> newsource = '11 bla bla 22 bla 33'
>
> How can I do it ? I tried to find using string built in function
> replace, but it will replace pattern with the same value.
>
> For this moment I think about change the string into list using
> string.split and then check one by one and replace it and then convert
> into string with addition space in the right and left of each element
> list.
>

>>> L = ['11', '22', '33']
>>> source
"xyzzy text we've got xyzzy text xyzzy yeah yeah yeah"
>>> token
'xyzzy'
>>> for rep in L:
... source = source.replace(token, rep, 1)
...
>>> source
"11 text we've got 22 text 33 yeah yeah yeah"

And, if I may, I recommend the Python Tutorial at
http://docs.python.org/tut/tut.html .

Peace
Bill Mill
bill.mill at gmail.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: replace string patern with different value

2005-05-09 Thread Peter Otten
[EMAIL PROTECTED] wrote:

> I would like to replace string with different values,
> For example :
> source = 'kode1 bla bla kode1 bla kode1'
> I have a list with each member will replace each of kode1.
> L = [11,22,33]
> So the new source will become:
> newsource = '11 bla bla 22 bla 33'

Here's one way to do it with regular expressions:

>>> def make_sub(items):
... items = iter(items)
... def sub(m):
... return items.next()
... return sub
...
>>> re.compile("kode1").sub(make_sub(str(i) for i in [11, 22, 33]),
... "kode1 bla bla kode1 bla kode1")
'11 bla bla 22 bla 33'

Peter


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: replace string patern with different value

2005-05-09 Thread Duncan Booth
[EMAIL PROTECTED] wrote:

> I would like to replace string with different values,
> For example :
> source = 'kode1 bla bla kode1 bla kode1'
> I have a list with each member will replace each of kode1.
> L = [11,22,33]
> So the new source will become:
> newsource = '11 bla bla 22 bla 33'
> 
> How can I do it ? I tried to find using string built in function
> replace, but it will replace pattern with the same value.
> 

>>> source = 'kode1 bla bla kode1 bla kode1'
>>> L = [11,22,33]
>>> re.sub('kode1', (lambda m: str(L.pop(0))), source)
'11 bla bla 22 bla 33'
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: replace string patern with different value

2005-05-09 Thread Fredrik Lundh
Bill Mill wrote:

 for rep in L:
> ... source = source.replace(token, rep, 1)

here's another way to do it:

>>> L = ["11", "22", "33"]
>>> S = "xyzzy text we've got xyzzy text xyzzy yeah yeah yeah"
>>> L.reverse()
>>> re.sub("xyzzy", lambda x: L.pop(), S)
"11 text we've got 22 text 33 yeah yeah yeah"

or, less destructive:

>>> L = ["11", "22", "33"]
>>> S = "xyzzy text we've got xyzzy text xyzzy yeah yeah yeah"
>>> re.sub("xyzzy", lambda x, pop=iter(L).next: pop(), S)

(a few more iterations of this idea and we're in python riddle country...)

 



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Trouble saving unicode text to file

2005-05-09 Thread Max M
Fredrik Lundh wrote:

> (I just noticed that there's no euro sign on my swedish keyboard.  I've
> never missed it ;-)

It's probably "AltGR + E" like here in DK

-- 

hilsen/regards Max M, Denmark

http://www.mxm.dk/
IT's Mad Science
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Trouble saving unicode text to file

2005-05-09 Thread Simon Brunning
On 5/9/05, Max M <[EMAIL PROTECTED]> wrote:
> Fredrik Lundh wrote:
> 
> > (I just noticed that there's no euro sign on my swedish keyboard.  I've
> > never missed it ;-)
> 
> It's probably "AltGR + E" like here in DK

My UK keyboard has it as AltGr + 4, FWIW.

-- 
Cheers,
Simon B,
[EMAIL PROTECTED],
http://www.brunningonline.net/simon/blog/
-- 
http://mail.python.org/mailman/listinfo/python-list


ANN: Boston Python Interest Group Meeting

2005-05-09 Thread Chris Curvey
Thursday, 7PM

Harvard Science Center
1 Oxford St Room 507
Cambridge, mA 02101

'Nuff said.

-- 
http://mail.python.org/mailman/listinfo/python-list


include "apythonscript.py"

2005-05-09 Thread martijn
H!

I'm trying to find a python function to use like this:

-- maincode.py

Include "apythonscript_function.py"

-- end

So I can split the maincode.py file in smalle pieces.
Or yust save the function's in other file and include them once.
I really want to use this because else { the maincode.py will be super
super large. }

Thanks,
GC-Martijn

- if you don't understand what I mean: http://www.php.net/include

-- 
http://mail.python.org/mailman/listinfo/python-list


file corruption on windows - possible bug

2005-05-09 Thread Jeremy Jones
I've written a piece of code that iterates through a list of items and
determines the filename to write some piece of data to based on
something in the item itself.  Here is a small example piece of code to
show the type of thing I'm doing::

#
file_dict = {}

a_list = [("a", "a%s" % i) for i in range(2500)]
b_list = [("b", "b%s" % i) for i in range(2500)]
c_list = [("c", "c%s" % i) for i in range(2500)]
d_list = [("d", "d%s" % i) for i in range(2500)]


joined_list = a_list + b_list + c_list + d_list

for key, value in joined_list:
outfile = file_dict.setdefault(key, open("%s.txt" % key, "w"))
outfile.write("%s\n" % value)

for f in file_dict.values():
f.close()
#

Problem is, when I run this on Windows, I get 14,520 null ("\x00")
characters at the front of the file and each file is 16,390 bytes long. 
When I run this script on Linux, each file is 13,890 bytes and contains
no "\x00" characters.  This piece of code::

#
import cStringIO

file_dict = {}

a_list = [("a", "a%s" % i) for i in range(2500)]
b_list = [("b", "b%s" % i) for i in range(2500)]
c_list = [("c", "c%s" % i) for i in range(2500)]
d_list = [("d", "d%s" % i) for i in range(2500)]


joined_list = a_list + b_list + c_list + d_list

for key, value in joined_list:
#outfile = file_dict.setdefault(key, open("%s.txt" % key, "w"))
outfile = file_dict.setdefault(key, cStringIO.StringIO())
outfile.write("%s\n" % value)

for key, io_string in file_dict.items():
outfile = open("%s.txt" % key, "w")
io_string.seek(0)
outfile.write(io_string.read())
outfile.close()
#

results in files containing 16,390 bytes and no "\x00" characters on
Windows and 13,890 bytes on Linux and no "\x00" characters (file size
difference on Windows and Linux is due to line ending).  I'm still doing
a setdefault on the dictionary to create an object if the key doesn't
exist, but I'm using a cStringIO object rather than a file object.  So,
I'm treating this just like it was a file and writing it out later.

Does anyone have any idea as to why this is writing over 14,000 "\x00"
characters to my file to start off with where printable characters
should go and then writing the remainder of the file correctly? 


Jeremy Jones
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: include "apythonscript.py"

2005-05-09 Thread Larry Bates
How about?

put apythonscript_function.py in a separate file

then

inculde apythonscript_function.py at the top of maincode.py

Looks like you probably need to go back and read the tutorial.

-Larry

[EMAIL PROTECTED] wrote:
> H!
> 
> I'm trying to find a python function to use like this:
> 
> -- maincode.py
> 
> Include "apythonscript_function.py"
> 
> -- end
> 
> So I can split the maincode.py file in smalle pieces.
> Or yust save the function's in other file and include them once.
> I really want to use this because else { the maincode.py will be super
> super large. }
> 
> Thanks,
> GC-Martijn
> 
> - if you don't understand what I mean: http://www.php.net/include
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: include "apythonscript.py"

2005-05-09 Thread Chris Curvey
the PHP include doesn't have an exact match in Python, but I think you
can do what you intend.

To follow the first example from php.net, this would work

vars.py
color = 'green'
fruit = 'apple'

test.py
from vars import *
print "A " , color, fruit 

HTH

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: file corruption on windows - possible bug

2005-05-09 Thread Fredrik Lundh
Jeremy Jones wrote:

> #
> file_dict = {}
>
> a_list = [("a", "a%s" % i) for i in range(2500)]
> b_list = [("b", "b%s" % i) for i in range(2500)]
> c_list = [("c", "c%s" % i) for i in range(2500)]
> d_list = [("d", "d%s" % i) for i in range(2500)]
>
>
> joined_list = a_list + b_list + c_list + d_list
>
> for key, value in joined_list:
>outfile = file_dict.setdefault(key, open("%s.txt" % key, "w"))

you do realize that this opens the file again every time, so you end up having
4x2500 file handles pointing to 4 physical files.  that's a bad idea.

if you replace

outfile = file_dict.setdefault(key, open("%s.txt" % key, "w"))

with

outfile = file_dict.get(key)
if outfile is None:
file_dict[key] = outfile = open("%s.txt" % key, "w")

or, if you prefer,

try:
outfile = file_dict[key]
except KeyError:
file_dict[key] = outfile = open("%s.txt" % key, "w")

your code won't depend on any undefined behaviour, and will work properly
on all platforms.

 



-- 
http://mail.python.org/mailman/listinfo/python-list


Adapt PyShell's code completion into DrPython

2005-05-09 Thread dcrespo
I would like to adapt the PyShell code completion to DrPython, because
both
programs are very good... Any clue for start finding the code location
in 
both programs to accomplish this?

Thanks

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Encryption with Python?

2005-05-09 Thread Anthra Norell
Robert,
  Thanks a lot for your thorough explanations.

- Original Message -
From: "Robert Kern" <[EMAIL PROTECTED]>
To: 
Sent: Saturday, May 07, 2005 3:18 PM
Subject: Re: Encryption with Python?

( snip )

> >>You do realize that if I have two ciphertexts encrypted with the same
> >>key, I can subtract them? Then I have a sequence, that while not
> >>immediately readable, is just a straightforward combination of the two
> >>plaintexts without any encryption.
> >
> > How do you know the same key was used?
>
> I don't necessarily, but if the same key *is* used, I'll know. The
> differences of the ciphertexts will have distinctly non-random
> characteristics (well, assuming the plaintexts aren't one-time pads
> themselves).

The non-randomness of the difference is evidence of having guessed the key,
right? Why then do I need two samples? If I hack away at a single sample I
get a probably more conspicuous non-randomness twice as fast.

( snip )

> Additionally, one should not use the Mersenne Twister PRNG, which is
> what Python uses, as the PRNG for the stream cipher. Given a particular
> value or series of values, it is possible to determine one's position in
> the PRNG sequence and can, in essence derive the key. Some techniques
> can be used to hide actual current state of the PRNG like applying a
> cryptographic hash to the value from the PRNG. However, it's easier and
> far better to just use a cryptographically strong PRNG from the start.

I don't doubt that, given a series (long enough), the postion can be
derived. I doubt, though, that a series is knowable, if another, unknown,
series has been added to it.

> > If, however, it is meant to suggest
> > that it is the reversible, direct one-on-one relation between all the
> > characters of a plain text and its encryption that falls short of
> > state-of-the-art technology, I'd have no problem with that. That doesn't
> > mean, however, that an exercise is required to measure up to
> > state-of-the-art standards in order to be taken seriously. I do invent
my
> > own solutions for simple problems.
>
> This is not a simple problem.

I thought the problem was concealing passwords from ones kids or
collaborators.

>
> You haven't proved your claim that your cipher is "unbreakable." Your
> notion of "unbreakable" is also flawed; "indistinguishable from 'random'
> sequences" is only one part of cryptosystem security. For that matter,
> you haven't proven that the ciphertexts produced are "indistinguishable
> from random sequences." Note the plural. It's important.

I believe that a randomly distributed series utterly obliterates any
non-randomness or regularity of a second series, if the two are added. I
don't know how to produce a formal proof. It is just a hunch. It's actually
more than a hunch. It is a conviction. Not a certainty; a conviction. I'd be
delighted to be proved wrong (or right). The fact may be significant that we
module overflow back into the range.
  So, if the distribution of my code is indeed random, it will display
no clue about the key and can only be broken with a brute-force attack. This
imposes a second requirement, which is that a brute-force attack outtries
the patience of a teraflop machine. The function I posted, quite obviously,
does not satisfy this second requirement. The function can easily be applied
in a manner, though, that takes care of that.
  A third rquirement I cannot think of.

> You have a positive obligation to back your claim. I've pointed you to
> two obvious attacks that can be made against your system and also to
> resources that you can read to improve your knowledge of the issues. I
> *don't* have an obligation to spend more of my time meeting your
> arbitrary challenge. My reluctance to do so is not support for your claim.

I am not aiming at a Nobel prize and certainly don't presume to impose on
your priorities. So the term 'obligation' seems not very useful here.

>
> > I claim that my
> > solution satisfies the requirements of the task at hand and challenge
anyone
> > to prove the contrary. You can meet the challenge by deciphering the
> > following tiny message, knowing now the encryption method, which in
practice
> > would not be known
>
> Bull. And irrelevant.

Irrelevant okay, if the OP agrees.

( snip )

Best regards,

Frederic


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: file corruption on windows - possible bug

2005-05-09 Thread Duncan Booth
Jeremy Jones wrote:

> Here is a small example piece of code to
> show the type of thing I'm doing::
> 
> #
> file_dict = {}
> 
> a_list = [("a", "a%s" % i) for i in range(2500)]
> b_list = [("b", "b%s" % i) for i in range(2500)]
> c_list = [("c", "c%s" % i) for i in range(2500)]
> d_list = [("d", "d%s" % i) for i in range(2500)]
> 
> 
> joined_list = a_list + b_list + c_list + d_list
> 
> for key, value in joined_list:
> outfile = file_dict.setdefault(key, open("%s.txt" % key, "w"))
> outfile.write("%s\n" % value)
> 
> for f in file_dict.values():
> f.close()
> #
> 
> Problem is, when I run this on Windows, I get 14,520 null ("\x00")
> characters at the front of the file and each file is 16,390 bytes long. 

Your call to setdefault is opening the file for writing every time it is 
called, but using only the first handle to write to the file. I presume you 
get a nasty interaction between the file handle you are using to write and 
the other file handles which open the file in a destructive ("w") mode.

The fix is simply to only open each file once instead of 2500 times. e.g. 
(untested code)

for key, value in joined_list:
if key in file_dict:
outfile = file_dict[key]
else:
outfile = file_dict[key] = open("%s.txt" % key, "w")
outfile.write("%s\n" % value)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: include "apythonscript.py"

2005-05-09 Thread martijn
Ah damn , that's the way.

And what if you have a very big class and want to include some class
functions ?

class ThisIsAClass:
def __init__(self):

 Here I want to import a class def

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Trouble saving unicode text to file

2005-05-09 Thread Fredrik Lundh
Max M wrote:

>> (I just noticed that there's no euro sign on my swedish keyboard.  I've
>> never missed it ;-)
>
> It's probably "AltGR + E" like here in DK

ah, there it is.  almost entirely worn out.  and it doesn't work.  but a little
fooling around reveals that AltGr+5 does work.  oh well, you learn some-
thing new every day.

 



-- 
http://mail.python.org/mailman/listinfo/python-list


M2Crypto SSL memory leaks - fixes or alternatives ??

2005-05-09 Thread adsheehan
Hi folks,

I notice that M2Crypto (a python wrap of OpenSSL) leaks (haemorrhages)
memory significantly and affects my long running app very badly.

Does anyone know of fixes to this problem?

Does anyone recommmend alternatives to M2C ? e.g pyopenssl.

I notice that Guido Van Rossum has flamed about this in the past but I
am not aware of any resolutions.

Thanks
Alan

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: file corruption on windows - possible bug

2005-05-09 Thread Duncan Booth
Fredrik Lundh wrote:

> you do realize that this opens the file again every time, so you end
> up having 4x2500 file handles pointing to 4 physical files.  that's a
> bad idea. 
> 
Assuming he is using the common C Python most of those file handles get 
closed immediately after opening, so he never actually has more than 5 
handles open at one time. Even 5 open handles to 4 physical files is a bad 
idea though, and depending on this behaviour is also a bad idea.

If he had actually managed to try to open all the files simultaneously then 
I think an exception would be quite likely with anything approaching that 
number of handles e.g. on my XP system I can open 509 handles (or 3 more if 
I close stdin/out/err first) and just over twice that on Linux.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: file corruption on windows - possible bug

2005-05-09 Thread Jeremy Jones




Fredrik Lundh wrote:

  Jeremy Jones wrote:

  
  
#
file_dict = {}

a_list = [("a", "a%s" % i) for i in range(2500)]
b_list = [("b", "b%s" % i) for i in range(2500)]
c_list = [("c", "c%s" % i) for i in range(2500)]
d_list = [("d", "d%s" % i) for i in range(2500)]


joined_list = a_list + b_list + c_list + d_list

for key, value in joined_list:
   outfile = file_dict.setdefault(key, open("%s.txt" % key, "w"))

  
  
you do realize that this opens the file again every time, so you end up having
4x2500 file handles pointing to 4 physical files.  that's a bad idea.
  

That *is* a bad idea, and no, I didn't realize that would be the
result.  From the "mapping types" page:


  

  a.setdefault(k[,
  x])
  a[k] if k
in a, else x (also setting it)
  (5)

  



  (5)
  setdefault() is like get(), except
that if k is missing, x is both returned and
inserted into
the dictionary as the value of k. x defaults to
None.


I took this to mean that setdefault was a short-circuit and only
created the default object once if the dictionary didn't contain the
specified key.  But I guess it's *me* who is passing setdefault a new
file handle a few thousand times :-)  Ouch.

  
if you replace

outfile = file_dict.setdefault(key, open("%s.txt" % key, "w"))

with

outfile = file_dict.get(key)
if outfile is None:
file_dict[key] = outfile = open("%s.txt" % key, "w")

or, if you prefer,

try:
outfile = file_dict[key]
except KeyError:
file_dict[key] = outfile = open("%s.txt" % key, "w")

your code won't depend on any undefined behaviour, and will work properly
on all platforms.

 



  

Thanks (and thanks to you, Duncan, for your reply as well),


Jeremy


-- 
http://mail.python.org/mailman/listinfo/python-list

Re: replace string patern with different value

2005-05-09 Thread Paul McGuire
Well, not to be left out, here is a pyparsing solution.  But this looks
suspiciously like some form of mail-merge or templating application.
Google for 'python templating' for existing approaches to this problem.

Interestingly, using an iterator of L sidesteps a number of other
problems.  My original brute force version just used curelem as an
integer index into L, which required
1. a global declaration of curelem in replString
2. a separate variable to store the current element
3. a second command to increment curelem after saving the current
element
Changing curelem to be an iterator on the L list allowed me to collapse
all that junk down to a simple return statement, with no loss in
readability or maintainability.

-- Paul


from pyparsing import Literal
source = 'kode1 bla bla kode1 bla kode1'
L = [11,22,33]
curelem = iter(L)

def replString(st,loc,toks):
return str( curelem.next() )

kode = Literal("kode1").setParseAction( replString )
newsource = kode.transformString( source )
print newsource

prints:
11 bla bla 22 bla 33

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: include "apythonscript.py"

2005-05-09 Thread Duncan Booth
 wrote:

> Ah damn , that's the way.
> 
> And what if you have a very big class and want to include some class
> functions ?
> 
> class ThisIsAClass:
> def __init__(self):
> 
>  Here I want to import a class def
> 

The usual way to handle that would be to not write a 'very big class' at 
all: create a lot of comparatively simple classes and use either 
inheritance or aggregation as appropriate to combine them.

You will find this makes your life much easier all round.

What you are doing sounds like a classic case of 'The Blob'. See 
http://www.antipatterns.com/briefing/sld024.htm
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Exception in Python 2.3.3 Interpreter

2005-05-09 Thread Terry Reedy

"Saravanan" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> Im running Python Application as a Windows Service (using windows
> extensions).  But, sporadically the application crashes (crash in
> Python23.dll) and this stops the service.  This problem cann't be
> reproduced easily in my system and the call stack generated by the
> application is given below. Please note that the call stack generation
> is taken from crash dump file.
>
> The crash occured at the following line:
> c = strcmp(vname, wname) (object.c)

I am puzzled by this line.  I can't see how it could execute.
Is this C or Python code? from the distribution or your code?
How is the result of strcmp (-1, 0, 1 ?) supposed to be callable?
Is this guarded by a rarely triggered condition?

Terry J. Reedy





-- 
http://mail.python.org/mailman/listinfo/python-list


Question about extending the interperter

2005-05-09 Thread Eli
Hi,
I've followed the Python docs about extending the Python interperter
and created an extension library.
I've added my functions like this:

static PyMethodDef pmylib_methods[] = {
{"foo", pmylib_foo, METH_VARARGS, "foo() doc string"},
...
}
static PyObject *pmylib_foo(PyObject *self, PyObject *args)
{
...
char *p;
if (!PyArg_ParseTuple(args, "s", &p))
...
}

And that's works fine.
The problem for me is that the pointer "p" in the last function points
to the arguments:
If a user caller foo("123") - p points to '123'.
What I need is to point it to the whole string received - 'foo
("123")'.

Is there a way I can do this?

Thanks in advance,
Eli

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Calling a python function from C++

2005-05-09 Thread djw
[EMAIL PROTECTED] wrote:
> Let's say I have a python function do some math like the following:
> 
> def doMath(self):
>self.val = self.val + 1
> 
> 
> How can I call this python function from C++? Assuming I have some sort
> of Python wrapper around my C++ codes.
> 

Elmer?

http://elmer.sourceforge.net/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Outlook-MAPI

2005-05-09 Thread erinhouston
This code should help.

code
import win32com.client
olMailItem = 0x0
obj = win32com.client.Dispatch("Outlook.Application")
newMail = obj.CreateItem(olMailItem)
newMail.Subject = "This works"
newMail.Body = "It worked aging\n"
newMail.display()


V.C.Sekhar wrote:
> Hi there,
>
> Can any one please help in getting me Python-Outlook
> programming issue clarified.
>
>
>
> I just wanted to do the following using Python:
>
> 1)Open a New Oulook Mail Window
>
> 2) Fill the field: to-email address and Write some body to it.(I
> DON't want to send it automatically)
>
>
>
> That's all. But, I am getting an error when I try to initiate the
> MAPI-Session using
>
> object = win32com.client.Dispatch("Outlook.Application")
>
> ns = object.GetNamespace("MAPI")
>
> mapi = win32com.client.dynamic.Dispatch("MAPI.session")
>
>
>
> Error I see is :
>
>   File "C:\Program Files\GNU\WinCvs 2.0\Macros\TemplateCvsMacro.py",
> line 140, in SendMAPIMail
>
> mapi = win32com.client.Dispatch("MAPI.session")
>
>   File "C:\Python24\Lib\site-packages\win32com\client\__init__.py",
> line 95, in Dispatch
>
> dispatch, userName = dynamic._GetGoodDispatchAndUserName
> (dispatch,userName,clsctx)
>
>   File "C:\Python24\Lib\site-packages\win32com\client\dynamic.py",
> line 91, in _GetGoodDispatchAndUserName
>
> return (_GetGoodDispatch(IDispatch, clsctx), userName)
>
>   File "C:\Python24\Lib\site-packages\win32com\client\dynamic.py",
> line 79, in _GetGoodDispatch
>
> IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx,
> pythoncom.IID_IDispatch)
>
> pywintypes.com_error: (-2147221005, 'Invalid class string', None,
> None)
>
>
>
> Can any one please help me in this regard.
> 
>  
> 
> Thanks,
> 
> Sekhar

-- 
http://mail.python.org/mailman/listinfo/python-list


Resize an Image without PIL

2005-05-09 Thread querypk
Hi I would like to know how to resize an Image without using python
Imaging library.

-- 
http://mail.python.org/mailman/listinfo/python-list


Listing of declared variables and functions

2005-05-09 Thread ohms377
Dear python users,

In interactive mode, I was wondering if there is a way to list all
declared variables and functions (and from global workspace).

Thanks,

-frankie

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Listing of declared variables and functions

2005-05-09 Thread Bill Mill
On 9 May 2005 09:58:19 -0700, ohms377 <[EMAIL PROTECTED]> wrote:
> Dear python users,
> 
> In interactive mode, I was wondering if there is a way to list all
> declared variables and functions (and from global workspace).
> 

>>> x = 12
>>> z = 13
>>> import re
>>> locals()
{'__builtins__': , 're': , 'x': 12, '__name__': '__main__', 'z': 13, '__doc__': N
one}
>>> locals().keys()
['__builtins__', 're', 'x', '__name__', 'z', '__doc__']
>>> globals()
{'__builtins__': , 're': , 'x': 12, '__name__': '__main__', 'z': 13, '__doc__': N
one}

Peace
Bill Mill
bill.mill at gmail.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Inverse confusion about floating point precision

2005-05-09 Thread Skip Montanaro
I understand why the repr() of float("95.895") is "95.8949996".
What I don't understand is why if I multiply the best approximation to
95.895 that the machine has by 1 I magically seem to get the lost
precision back.  To wit:

% python
Python 2.3.4 (#12, Jul  2 2004, 09:48:10) 
[GCC 3.3.2] on sunos5
Type "help", "copyright", "credits" or "license" for more information.
>>> 95.895
95.8949996
>>> 95.895 * 1
958950.0

Why isn't the last result "958949.996"?  IOW, how'd I get back the
lost bits?

Thx,

Skip
-- 
http://mail.python.org/mailman/listinfo/python-list


Does anybody know the status of PyCon recordings?

2005-05-09 Thread Bill Mill
Hey all,

There was a lot of talk on this list about recording pycon 2005 talks,
but I never saw any messages saying that they'd actually been
recorded. The wiki page (
http://www.python.org/moin/PyConDC2005/TalkRecording ) doesn't give
links to any recordings.

Does anybody know if these recordings exist and, if so, where they are?

Peace
Bill Mill
bill.mill at gmail.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Inverse confusion about floating point precision

2005-05-09 Thread Tim Peters
[Skip Montanaro]
> I understand why the repr() of float("95.895") is "95.8949996".
> What I don't understand is why if I multiply the best approximation to
> 95.895 that the machine has by 1 I magically seem to get the lost
> precision back.  To wit:
>
>% python
>Python 2.3.4 (#12, Jul  2 2004, 09:48:10)
>[GCC 3.3.2] on sunos5
>Type "help", "copyright", "credits" or "license" for more information.
>>>> 95.895
>95.8949996
>>>> 95.895 * 1
>958950.0
>
> Why isn't the last result "958949.996"?

Because it's *still* not decimal arithmetic.  You have 53 significant
bits in the approximation to 95.895, and "958949.996" is
itself a decimal approximation to the exact binary value stored (read
the Tutorial appendix on fp issues for more on that).

There are 14 significant bits in 1.  The product thus has 53+14 =
67, or 53+14-1 = 66, significant bits, and has to be rounded to fit
back into 53 significant bits.  None of that happens in base 10.

> IOW, how'd I get back the lost bits?

It happened to round up.  Here's a simpler example, where it happens
to round down instead:

>>> .1
0.10001
>>> .1 * 10
1.0
-- 
http://mail.python.org/mailman/listinfo/python-list


Advice needed on __del__

2005-05-09 Thread André Roberge
Suppose I have two classes: 'Jekyll' and 'Hyde' that are
related in a particular way.

When I create a Jekyll object, a Hyde one gets automatically
created (and displayed on a screen).

 drum roll to announce Python script ===

Nice = Jekyll()# Nice_twin, a Hyde object, gets created.

Nice.doStuff() # Nice_twin is doing his own stuff

def subplot():
 Evil = Jekyll()   # Evil_twin gets created and displayed
 Evil.doStuff()# Evil_twin does stuff on the screen

subplot()

#Evil.doMoreStuff()  would raise an error, as it no longer exists
   # in this namespace; however, Evil_twin still displayed

Nice.doMoreStuff()   # continues to work.

==End of script, and ask question===
Evil_twin is still displayed on the screen at the end.
I would like for Evil_twin to disappear.
(I would like for this Hyde, to hide  ok, bad pun!)

This morning I had the following thought:
I can, when I create a Jekyll object, update
an outside_list.
If, somehow, I could update that list when
a Jekyll object disappears
(perhaps by using __del__, which I have never touched)
that would solve my problem.

I could check outside_list each time I update
the screen display, and remove Evil_twin when
Evil no longer exists.

Any suggestions?

I've already tried lots of things, but nothing works properly.
Every attempt I make involves quite a bit of coding, as
the real-life situation is a bit more complicated than
what I explain here.
So, before I try again, I thought I would ask the
Collective Wisdom on this list.

--
André

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Does anybody know the status of PyCon recordings?

2005-05-09 Thread Sébastien Boisgérault
http://www.pycon.org/talks/

Cheers,

SB

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Inverse confusion about floating point precision

2005-05-09 Thread Dan Bishop
Skip Montanaro wrote:
> I understand why the repr() of float("95.895") is
"95.8949996".
> What I don't understand is why if I multiply the best approximation
to
> 95.895 that the machine has by 1 I magically seem to get the lost
> precision back.  To wit:
>
> % python
> Python 2.3.4 (#12, Jul  2 2004, 09:48:10)
> [GCC 3.3.2] on sunos5
> Type "help", "copyright", "credits" or "license" for more
information.
> >>> 95.895
> 95.8949996
> >>> 95.895 * 1
> 958950.0
>
> Why isn't the last result "958949.996"?  IOW, how'd I get
back the
> lost bits?

You were just lucky.

The floating-point representation of 95.895 is exactly 6748010722917089
* 2**-46.

Multiplying by 1 gives you 6748010722917089 * 2**-46.  But
floats can have only 53 significant bits, so this gets normalized to
8237317776998399.658203125 * 2**-33 and rounded to 8237317776998400 *
2**-33, which happens to be exactly equal to 958950.

For analogy, consider a decimal calculator with only 3 significant
digits.  On this calculator, 1/7=0.143, an error of 1/7000.
Multiplying 0.143 by 7 gives 1.001, which is rounded to 1.00, and so
you get an exact answer for 1/7*7 despite roundoff error in the
intermediate step.

-- 
http://mail.python.org/mailman/listinfo/python-list


Dr. Dobb's Python-URL! - weekly Python news and links (May 9)

2005-05-09 Thread Simon Brunning
QOTW: "It's not perfect, but then nobody in this thread has offered
anything even remotely resembling perfect documentation for regular
expressions yet. " - Peter Hansen

"Python's flavor of OO is perfectly valid and usable, even though it
doesn't follow the Java Holy Bible of Object Orientation (gasp!)" - Hans Nowak

"It's highly arguable if Python is "better" than C#, but from a
control-your-own-destiny angle, Python is a complete slam dunk. Python
works well on *nix, Java, .NET and Mac OS X. It's open source. It's
sane. But I won't argue it's fast. It's usually just not so slow you
care." - Jonathan Rentzsch


String Manipulation in Python:
http://www.devshed.com/c/a/Python/String-Manipulation/

Why you can't detect a float's significant digits:

http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/85eaac30c01b51a5

Dependency Injection The Python Way:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/413268

What is Paste?
http://blog.ianbicking.org/what-is-paste.html

Finding peaks and valleys:

http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/6506673a689339b7

Type-safe Enums in Python:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/413486

Python turns up again in a Microsoft outpost:

http://www.informit.com/guides/content.asp?g=windowsserver&seqNum=183&rl=1

Encryption with Python:

http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/5fb9ffada975bae9

The importance of being selfish, deja vu:
http://zephyrfalcon.org/weblog2/arch_e10_00770.html#e776

Notable releases:
CherryPy-2.0-final:

http://groups-beta.google.com/group/comp.lang.python.announce/browse_thread/thread/8905b9f2bd114f38
BeautifulSoup 2.1.0:
http://www.crummy.com/software/BeautifulSoup/
KirbyBase 1.8.2:
http://www.netpromi.com/kirbybase.html



Everything Python-related you want is probably one or two clicks away in
these pages:

Python.org's Python Language Website is the traditional
center of Pythonia
http://www.python.org
Notice especially the master FAQ
http://www.python.org/doc/FAQ.html

PythonWare complements the digest you're reading with the
marvelous daily python url
 http://www.pythonware.com/daily  
Mygale is a news-gathering webcrawler that specializes in (new)
World-Wide Web articles related to Python.
 http://www.awaretek.com/nowak/mygale.html 
While cosmetically similar, Mygale and the Daily Python-URL
are utterly different in their technologies and generally in
their results.

For far, FAR more Python reading than any one mind should
absorb, much of it quite interesting, several pages index
much of the universe of Pybloggers.
http://lowlife.jp/cgi-bin/moin.cgi/PythonProgrammersWeblog
http://www.planetpython.org/
http://mechanicalcat.net/pyblagg.html

comp.lang.python.announce announces new Python software.  Be
sure to scan this newsgroup weekly.

http://groups.google.com/groups?oi=djq&as_ugroup=comp.lang.python.announce

Steve Bethard, Tim Lesher, and Tony Meyer continue the marvelous
tradition early borne by Andrew Kuchling, Michael Hudson and Brett
Cannon of intelligently summarizing action on the python-dev mailing
list once every other week.
http://www.python.org/dev/summary/

The Python Package Index catalogues packages.
http://www.python.org/pypi/

The somewhat older Vaults of Parnassus ambitiously collects references
to all sorts of Python resources.
http://www.vex.net/~x/parnassus/   

Much of Python's real work takes place on Special-Interest Group
mailing lists
http://www.python.org/sigs/

The Python Business Forum "further[s] the interests of companies
that base their business on ... Python."
http://www.python-in-business.org

Python Success Stories--from air-traffic control to on-line
match-making--can inspire you or decision-makers to whom you're
subject with a vision of what the language makes practical.
http://www.pythonology.com/success

The Python Software Foundation (PSF) has replaced the Python
Consortium as an independent nexus of activity.  It has official
responsibility for Python's development and maintenance. 
http://www.python.org/psf/
Among the ways you can support PSF is with a donation.
http://www.python.org/psf/donate.html

Kurt B. Kaiser publishes a weekly report on faults and patches.
http://www.google.com/groups?as_usubject=weekly%20python%20patch
   
Cetus collects Python hyperlinks.
http://www.cetus-links.org/oo_python.ht

Re: replace string patern with different value

2005-05-09 Thread [EMAIL PROTECTED]
Thank you.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: __brace__ (PEP?)

2005-05-09 Thread Kay Schluehr
Roy Smith wrote:
> "Kay Schluehr" <[EMAIL PROTECTED]> wrote:
>
> > Roy Smith wrote:
> >
> > > foo->bar ==> foo.__arrrow__(bar)
> > > foo$bar ==> foo.__dollar__(bar)
> > > foo#bar ==> foo.__hash__(bar)
> > > foo::bar ==> foo.__scope__(bar)
> >
> > I'm strongly in favor for the arrow ( but with two "r" only ). The
> > question is simply: for what?
>
> I'm confused.  You're strongly in favor of a piece of punctuation
even
> though you don't have any idea what it might be used for?

Shurely I was joking. I could imagine a few purposes most likely arrows
of some category. That's what You depicted using the "==>" arrow, that
translates some infix operator expression into it's method description.
Arrows are some kind of 2-tuples that express a transition and which
are "left-exact" i.e. there must be at most a right value to some left
value.

Example:

(foo->bar) -> foo.__arrow__(bar)

This is a recursive definition of the arrow which could be further
expanded:

((foo->bar) -> foo.__arrow__(bar)) ->
foo.__arrow__(bar).__arrow__(foo.__arrow__(bar))

etc.

But something intrigues me and that is the prevalence of "foo" above
"bar" i.e. the preimage above the image. I would like to see that one
starts with the binary relation as the primary concept. A relation
should be instantiated by two classes. Let be Rel(A,B) some relation
created from classes A and B. The instances of Rel(A,B) would be arrows
from A to B depicted as arrow diagrams:

   foo->bar -> rel.__arrow__(foo,bar)

There is no absolute meaning of the arrow foo->bar, because it reflects
only the particular relation instance rel.

Besides this I guess Guido wants to use the arrow in the context of
"optional static type declarations" for declaring the return type. I
don't like this optional static stuff but the arrow is playing a role
also in this proposal.

Ciao,
Kay

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Inverse confusion about floating point precision

2005-05-09 Thread Skip Montanaro
>> Why isn't the last result "958949.996"?  IOW, how'd I get
>> back the lost bits?

Dan> You were just lucky.

Thanks for the response (and to Tim as well).

Dan> The floating-point representation of 95.895 is exactly
Dan> 6748010722917089 * 2**-46.

I seem to recall seeing some way to extract/calculate fp representation from
Python but can't find it now.  I didn't see anything obvious in the
distribution.

Thx,

Skip
-- 
http://mail.python.org/mailman/listinfo/python-list


py2exe to share binary files

2005-05-09 Thread Laguna
Hi,

With py2exe-0.3.3 for Python 2.2 in Windows XP, how to configure
setup.py such that multiple executables can share the dll files (like
wx*.dll etc.) as follows:

# Source folders
\Program1
   Program1.py
   Program1WX.py

\Program2
   Program2.py
   Program2WX.py


# Output binary folders
\SharedBinary
   _sre.dll
   bsddb.pyd
   python22.dll
   utilsc.pyd
   wxc.pyd
   wxmsw232.dll

\Executable1
   Program1.exe

\Executable2
   Program2.exe


Thanks for any help,
Laguna

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Inverse confusion about floating point precision

2005-05-09 Thread Tim Peters
[Dan] 
>Dan> The floating-point representation of 95.895 is exactly
>Dan> 6748010722917089 * 2**-46.

[Skip Montanaro]
> I seem to recall seeing some way to extract/calculate fp representation from
> Python but can't find it now.  I didn't see anything obvious in the
> distribution.

For Dan's example,

>>> import math
>>> math.frexp(95.895)
(0.7491796874997, 7)
>>> int(math.ldexp(_[0], 53))
6748010722917089L
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Strip white spaces from source

2005-05-09 Thread qwweeeit
Hi Richie,
thank you for your answer.
Your solution is interesting but does not take into account some white
spaces (like those after the commas, before or after mathematical
operands etc...).
Besides that I'm a almost a newbie in Python, and I have the very old
programmers' habits (I don't use classes...).

But I have solved nevertheless my problem (with the help of Alex
Martelli and his fab method of
"tokenize.generate_tokens(cStringIO.StringIO(string).readline"   I have
read in a clp answer of Alex to a question of Gabor Navy).

If someone is interested (I think nobody...) I can give my solution.

Bye.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Advice needed on __del__

2005-05-09 Thread Fredrik Lundh
André Roberge wrote:


> This morning I had the following thought:
> I can, when I create a Jekyll object, update
> an outside_list.
> If, somehow, I could update that list when
> a Jekyll object disappears
> (perhaps by using __del__, which I have never touched)

Python makes no guarantees whatsover about when and how to
run __del__, so relying on it to remove user-visible resources is a
rather bad idea.

> Any suggestions?

why wouldn't

def subplot():
 Evil = Jekyll()   # Evil_twin gets created and displayed
 Evil.doStuff()# Evil_twin does stuff on the screen
 Evil.destroy()

work for you?





-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Question about extending the interperter

2005-05-09 Thread Fredrik Lundh
"Eli" wrote:

> I've followed the Python docs about extending the Python interperter
> and created an extension library.
> I've added my functions like this:
>
> static PyMethodDef pmylib_methods[] = {
> {"foo", pmylib_foo, METH_VARARGS, "foo() doc string"},
> ...
> }
> static PyObject *pmylib_foo(PyObject *self, PyObject *args)
> {
> ...
> char *p;
> if (!PyArg_ParseTuple(args, "s", &p))
> ...
> }
>
> And that's works fine.
> The problem for me is that the pointer "p" in the last function points
> to the arguments:
> If a user caller foo("123") - p points to '123'.

foo("123") means "call the callable identifed by the expression 'foo' with
foo with the string '123'", so that's just what should happen.

> What I need is to point it to the whole string received - 'foo
> ("123")'.

received by whom?  if you call a function with an argument, the function
receives the argument.  the expression used to locate the callable (in this
case, the function name) is not part of the call.

> Is there a way I can do this?

no (at least not given how you've described your problem).





-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Resize an Image without PIL

2005-05-09 Thread Larry Bates
PIL is the best way.  Or you can call some external program to
do it (using os.system).

Larry Bates


[EMAIL PROTECTED] wrote:
> Hi I would like to know how to resize an Image without using python
> Imaging library.
> 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Encryption with Python?

2005-05-09 Thread Paul Rubin
"Anthra Norell" <[EMAIL PROTECTED]> writes:
> The non-randomness of the difference is evidence of having guessed the key,
> right? Why then do I need two samples? If I hack away at a single sample I
> get a probably more conspicuous non-randomness twice as fast.

No.  Let's say you encrypt two ascii strings with the same key.  The
high bit of each byte in the plaintext is zero.  Therefore if you xor
the two ciphertexts together, the high bit of each byte of the result
xor'd ciphertexts will be zero.  So just check for that and you've
immediately spotted the non-randomness.

> I don't doubt that, given a series (long enough), the postion can be
> derived. I doubt, though, that a series is knowable, if another, unknown,
> series has been added to it.

You have to assume that the attacker has access to known
plaintext-ciphertext pairs.  For example, you might not tell someone
the password you use now, but what about some old password that you
don't use any more?  If the attacker knows your old password (maybe
because your sysop set it to some default value and had you change it
on your first login), and has the encrypted version, there's a known
plaintext.

> I thought the problem was concealing passwords from ones kids or
> collaborators.

Encryption is supposed to conceal data from knowledgable attackers
willing to burn significant resources to get at the data.  That might
or might not describe your friends and collaborators.

> I believe that a randomly distributed series utterly obliterates any
> non-randomness or regularity of a second series, if the two are added. 

This is a meaningless statement since you don't give any definition of
"randomly distributed series".

> I don't know how to produce a formal proof. It is just a hunch. It's
> actually more than a hunch. It is a conviction. Not a certainty; a
> conviction. I'd be delighted to be proved wrong (or right).  

If the keystream really can't be distinguished from random, then correct,
though there's still issues with key management (you mustn't use the same
key twice) and authentication.

Generating keystreams that are indistinguishable from random is an
extremely tricky subject, there are books and papers written about it, etc.

> The fact may be significant that we module overflow back into the
> range.  So, if the distribution of my code is indeed random, 

Your code used the Python built-in PRNG algorithm which is designed to
make output with similar statistical properties as actual random numbers,
for the purpose of running stuff like simulations.  It makes no attempt
at all to be secure against attackers trying to figure out whether the
output is really random.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Declaring self in PyObject_CallMethod

2005-05-09 Thread Fredrik Lundh
"[EMAIL PROTECTED]" wrote:

> Calling a python method from C++ has the following signature:
>
> PyObject *
> PyObject_CallMethod(PyObject *self, char *method_name,
> char *arg_format, ...);
>
> I'm having trouble figuring out how to declare self.

Reading the C API documentation might provide the clues you're
looking for:

PyObject* PyObject_CallMethod(PyObject *o, char *method, char *format, ...)

Return value: New reference.

Call the method named method of object o with a variable number of C 
arguments.
/.../ This is the equivalent of the Python expression "o.method(args)".

What is the object?  What method are you calling?  What arguments
are you passing in?

> Let's say my python file is called stuff.py and is like the following,
> doMath() is defined in stuff.py and is not part of any class:
>
> #stuff.py
>
> def doMath():
>val = val + 1

That's a function, not an object method.

> In C++, I think my codes should be like the following:
>
> PyObject *resultObj = PyObject_CallMethod( self, "doMath", "");
>
> What do I put for self? Any help please?

CallMethod is used to call a method on a given object.  To call a callable 
object
(such as a function), other callable object, use PyObject_Call (or CallObject
or CallFunction).   See the C API documentation for details.





-- 
http://mail.python.org/mailman/listinfo/python-list


Re: global lists

2005-05-09 Thread Dan Christensen
andrea crotti <[EMAIL PROTECTED]> writes:

> Hi everbybody again,
> I have a little "problem", I don't understand the reason of this:
>
> a = [10,1,2,3]
> def foo():
>   global a
>   for n in range(len(a)):
> a[n] = a[n]*2

If I type the above, and then call foo, I get what looks like
reasonable output:

In [1]:a = [10,1,2,3]

In [2]:def foo():
   .2.:global a
   .2.:for n in range(len(a)):
   .2.:a[n] = a[n]*2
   .2.:

In [3]:foo()

In [4]:print a
[20, 2, 4, 6]

However, you didn't say what you expected, so I'm not sure what bug
I'm looking for!

Dan
-- 
http://mail.python.org/mailman/listinfo/python-list


PyAr - Python Argentina 9th Meeting, this Thursday

2005-05-09 Thread Batista, Facundo
Title: PyAr - Python Argentina 9th Meeting, this Thursday





The Argentine Python User Group, PyAr, will have its nineth
meeting this Thursday, May 12nd at 7:00pm.



Agenda
--


Despite our agenda tends to be rather open, this time we would
like to cover these topics:


- See what we'll do with the t-shirts, and other "merchandising".
- Analyze a future meeting point.


    
Where
-


We're meeting at Hip Bar, Hipólito Yirigoyen 640, Ciudad de Buenos
Aires, starting at 19hs. We will be in the back room, so please ask
the barman for us.



About PyAr
--


For more information on PyAr see http://pyar.decode.com.ar (in Spanish), 
or join our mailing list (Also in Spanish. For instructions see 
http://pyar.decode.com.ar/Members/ltorre/listademail)


We meet on the second Thursday of every month.


.   Facundo


  . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

ADVERTENCIA.


La información contenida en este mensaje y cualquier archivo anexo al mismo, son para uso exclusivo del destinatario y pueden contener información confidencial o propietaria, cuya divulgación es sancionada por la ley.

Si Ud. No es uno de los destinatarios consignados o la persona responsable de hacer llegar este mensaje a los destinatarios consignados, no está autorizado a divulgar, copiar, distribuir o retener información (o parte de ella) contenida en este mensaje. Por favor notifíquenos respondiendo al remitente, borre el mensaje original y borre las copias (impresas o grabadas en cualquier medio magnético) que pueda haber realizado del mismo.

Todas las opiniones contenidas en este mail son propias del autor del mensaje y no necesariamente coinciden con las de Telefónica Comunicaciones Personales S.A. o alguna empresa asociada.

Los mensajes electrónicos pueden ser alterados, motivo por el cual Telefónica Comunicaciones Personales S.A. no aceptará ninguna obligación cualquiera sea el resultante de este mensaje.

Muchas Gracias.



-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Advice needed on __del__

2005-05-09 Thread Fredrik Lundh
"phil" wrote:

> > Python makes no guarantees whatsover about when and how to
> > run __del__, so relying on it to remove user-visible resources is a
> > rather bad idea.

> What does that mean?  Is it a destructor or not?

it's a finalizer.

most Python implementations do a reasonable attempt to call finalizers
on all objects, sooner or later, but it's not guaranteed by the language
specification:

"It is not guaranteed that __del__() methods are called for
objects that still exist when the interpreter exits."

> I create thousands of instances of objects in a geometry
> instruction program and rely heavliy on __del__ to do its
> thing.  For instance when I am rotating objects, I delete and
> recreate somtimes hundreds of times. Works so far.

why do you rely on __del__ to remove your objects?  why not just
leave that to the garbage collector?

(__del__ disables cycle detection, so a program that uses __del__
carelessly is more likely to leak memory than a program that doesn't
use it at all).

> 2. If Python is an oop language, meaning instances of classes
>  are essential, then a reliable destructor method is essential.

Python is not C++.





-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [Python.NET] Announce: Python for .NET 1.0 RC1 released

2005-05-09 Thread Guy Robinson
Great Stuff!!!

 >(probably including a few specific
 > examples of embedding Python for .NET in a .NET application).

Cool!! :-)

Guy

Brian Lloyd wrote:
> Hi all -
> 
> I'm happy to announce the release of Python for .NET 1.0 RC1.
> You can download it from:
> 
>   http://www.zope.org/Members/Brian/PythonNet
> 
> Highlights of this release:
> 
> - Implemented a workaround for the fact that exceptions cannot be
> new-style
>   classes in the CPython interpreter. Managed exceptions can now be
> raised
>   and caught naturally from Python
> 
> - Implemented support for invoking methods with out and ref parameters.
>   Because there is no real equivalent to these in Python, methods that
>   have out or ref parameters will return a tuple. The tuple will contain
>   the result of the method as its first item, followed by out parameter
>   values in the order of their declaration in the method signature.
> 
> - Fixed a refcount problem that caused a crash when CLR was imported in
>   an existing installed Python interpreter.
> 
> - Added an automatic conversion from Python strings to byte[]. This
> makes
>   it easier to pass byte[] data to managed methods (or set properties,
>   etc.) as a Python string without having to write explicit conversion
>   code. Also works for sbyte arrays. Note that byte and sbyte arrays
>   returned from managed methods or obtained from properties or fields
>   do *not* get converted to Python strings - they remain instances of
>   Byte[] or SByte[].
> 
> - Added conversion of generic Python sequences to object arrays when
>   appropriate (thanks to Mackenzie Straight for the patch).
> 
> - Added a bit of cautionary documentation for embedders, focused on
>   correct handling of the Python global interpreter lock from managed
>   code for code that calls into Python.
> 
> - PyObject.FromManagedObject now correctly returns the Python None
> object
>   if the input is a null reference. Also added a new AsManagedObject
>   method to PyObject, making it easier to convert a Python-wrapped
> managed
>   object to the real managed object.
> 
> - Created a simple installer for windows platforms.
> 
> 
> All known bugs have also been fixed - thanks to all who have sent in issue
> reports and patches for past releases.
> 
> At this point, the only thing I plan to do before a 1.0 final is fix any
> new issues and add to the documentation (probably including a few specific
> examples of embedding Python for .NET in a .NET application).
> 
> Enjoy! ;)
> 
> 
> Brian Lloyd[EMAIL PROTECTED]
> V.P. Engineering   540.361.1716
> Zope Corporation   http://www.zope.com
> 

-- 
Robinson eDesign,P/F: +64 7 866 0626
Rings Beach, M: 021 238 0839 -ltd coverage
RD2, E: [EMAIL PROTECTED]
Whitianga.
New Zealand


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Advice needed on __del__

2005-05-09 Thread André Roberge
Fredrik Lundh wrote:
> André Roberge wrote:
> 
> 
> 
>>This morning I had the following thought:
>>I can, when I create a Jekyll object, update
>>an outside_list.
>>If, somehow, I could update that list when
>>a Jekyll object disappears
>>(perhaps by using __del__, which I have never touched)
> 
> 
> Python makes no guarantees whatsover about when and how to
> run __del__, so relying on it to remove user-visible resources is a
> rather bad idea

[See idea at the very end about this.]

> 
>>Any suggestions?
> 
> why wouldn't
> 
> def subplot():
>  Evil = Jekyll()   # Evil_twin gets created and displayed
>  Evil.doStuff()# Evil_twin does stuff on the screen
>  Evil.destroy()
> 
> work for you?
> 
> 
Unfortunately, it wouldn't.
It's difficult to explain in a few words why, but I'll try anyway!

I'm developping a program (rur-ple) which is designed to
help learning Python.  In an earlier version (that didn't provide
support for deriving classes from existing one) I had it working so that 
when "Evil" would get out of scope, Evil_twin would disappear
from the screen.  This came as an initial surprise for me,
but a pleasant one.  Better than having an example like:

def boring():
x = 1
print x
boring()
print x  # gives an error message.

When I added the possibility of deriving classes, I had to
change the connection between Jekyll and Hyde ... and, so
far, lost that feature.

If I need to have the user call Evil.destroy() as Evil
is getting out of scope, it would miss the whole point
of teaching about the natural way scope and namespace
work.

I guess I'll have to try and learn how to use __del__,
and see if it can solve my problem.

===
A thought occurred to me, regarding "when" __del__
is called.  Can I force Python, through some function call,
to perform this.  Each time I refresh the screen, I could
force that call, then check to see if Evil has been
destroyed by Python, which would give me the information
I need to destroy Evil_twin behind the scene myself -
which is what I am really after.


-- 
http://mail.python.org/mailman/listinfo/python-list


cimport from different packages [Pyrex]

2005-05-09 Thread George Sakkis
Does cimport work for importing from different packages in Pyrex ?
Here's a minimal example:

# in ./foo/bar.pxd
cdef class Bar:
cdef int i

# in ./foo/bar.pyx
cdef class Bar:
def __init__(self, i):
self.i = i

# in ./tmp.pyx
cimport foo.bar

$ pyrexc foo/bar.pyx
$ pyrexc tmp.pyx
tmp.pyx:1:8: 'foo.bar.pxd' not found


I tried every reasonable choice for '-I' dir, without success. Am I
missing something or it's just cimport's deficiency ?

George

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Resize an Image without PIL

2005-05-09 Thread James Carroll
Or if you're using wxPython, wx.Image can load, rescale and save. 
There's also a Python wrapper for imageMagick, which will do just
about anything to medium-small files.

One way or another you'll need to incorporate (depend on) something
that can decode the various image file formats that you need, and
something that will resample /resize the image.

What's the reason to not use PIL?  What libraries are you using?

-Jim

On 5/9/05, Larry Bates <[EMAIL PROTECTED]> wrote:
> PIL is the best way.  Or you can call some external program to
> do it (using os.system).
> 
> Larry Bates
> 
> 
> [EMAIL PROTECTED] wrote:
> > Hi I would like to know how to resize an Image without using python
> > Imaging library.
> >
> --
> http://mail.python.org/mailman/listinfo/python-list
> 
>
-- 
http://mail.python.org/mailman/listinfo/python-list


GTK progress bar not working properly with pulse()

2005-05-09 Thread lamthierry
My python file(progressbar.py) looks like the following:

pbar = gtk.ProgressBar()

def updateBar(percentage):
print percentage
pbar.pulse()

class ProgressBar:
def __init__(self):
# other gui codes

align.add(pbar)
pbar.show()

My C++ codes look like the following:

for ( int percent = 0; percent < 100; percent++ )
{
PyObject* importModule = PyImport_ImportModule("progressbar");

if ( importModule == NULL )
printf("not good\n");
PyObject* callResult = PyObject_CallMethod(importModule,
"updateBar", "i", percent, NULL);
if ( callResult == NULL )
printf("not good enough\n");

Py_XDECREF(importModule);
}

I run the above C++ code from python by clicking a button. The problem
is that when I print the percentage from the python side, it works
fine, but when I call the pulse() method for ProgressBar, nothing gets
updated on my GUI. Do I have to do anything else with the pbar object
to make it display properly?

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Trouble saving unicode text to file

2005-05-09 Thread "Martin v. Löwis"
John Machin wrote:
> Terminology disambiguation: what I call "users" wouldn't know what
> 'cp1252' and 'iso-8859-1' were. They're not expected to know. They
> just type in whatever characters they can see on their keyboard or
> find in the charmap utility. It's what I'd call 'admins' and
> 'developers' who should know better, but often don't.

I was talking about 'users' of Python, so they are 'developers'.
They often don't know what cp1252 is.

> 1. When exchanging data across systems, should not utf-8 be
> preferred???

It depends on the data, of course. People writing UTF-8 into
text files often find that their editors don't display them
correctly, in which case UTF-8 might not be the best choice.
For example, the Python source code in CVS is required to be
iso-8859-1, primarily because this is what interoperates best
across all development platforms.

For data in XHTML, the answer would be different: every XML
processor is supposed to support UTF-8.

> 2. If the Windows *users* have been using characters that are in
> cp1252 but not in iso-8859-1, then attempting to convert to iso-8859-1
> will cause an exception. 

Correct.

> I find it a bit hard to imagine that the euro sign wouldn't get a fair
> bit of usage in Swedish data processing even if it's not their own
> currency.

Yes, so the question is how to represent it. It all depends on the
application, but it is safer to only assume iso-8859-1 for the moment,
unless it is guaranteed that all code that reads the file in really
knows what cp1252 is, and what \x80 means in that charset.

> 3. How portable is a character set that doesn't include the euro sign?

Well, how portable is ASCII? It doesn't support certain characters,
sure. If you don't need these characters, this is not a problem. If
you do need the extra characters, you need to think thoroughly what
encoding meets your needs best. I was merely suggesting that cp1252
is often used without that thought, causing moji-bake later.

If representation of the euro sign is an issue, the choices are
iso-8859-15, cp1252, and UTF-8. Of those three, I would pick
cp1252 last if at all possible, because it is specific to a
vendor (i.e. non-standard)

Regards,
Martin
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Encryption with Python?

2005-05-09 Thread Anthra Norell
Paul,

  I thank you too for your response. Let me just tell you what goes
through my mind.

- Original Message -
From: "Paul Rubin" <"http://phr.cx"@NOSPAM.invalid>
Newsgroups: comp.lang.python
To: 
Sent: Monday, May 09, 2005 9:45 PM
Subject: Re: Encryption with Python?


> "Anthra Norell" <[EMAIL PROTECTED]> writes:
> > The non-randomness of the difference is evidence of having guessed the
key,
> > right? Why then do I need two samples? If I hack away at a single sample
I
> > get a probably more conspicuous non-randomness twice as fast.
>
> No.  Let's say you encrypt two ascii strings with the same key.  The
> high bit of each byte in the plaintext is zero.  Therefore if you xor
> the two ciphertexts together, the high bit of each byte of the result
> xor'd ciphertexts will be zero.  So just check for that and you've
> immediately spotted the non-randomness.

I don't follow. There is no bitwise correlation between a plain-text
character and its encoded equivalent. What's more, there is no detectable
correlation at all. Take a highly ordered plain text, such as a sting of
identical characters, e.g. 'AAA' and sequentially add a
deterministically generated random series (module 256 to keep them within
range), what you get is, quite obviously, a series of numbers that differs
from the added random series in only one respect: all values are shifted by
ord ('A'). The intervals from one byte to the next remain unchanged,
allowance made for the module 256 wrap-around. The intervals remaining
unchanged, the distribution and hence the randomness of the encryption
remains unchanged. Quite obviously, each one of the identical plain-text
characters very likely will be encrypted differently. Repeats would occur,
but they would occur randomly once every 256 times on an average.

> > I don't doubt that, given a series (long enough), the postion can be
> > derived. I doubt, though, that a series is knowable, if another,
unknown,
> > series has been added to it.
>
> You have to assume that the attacker has access to known
> plaintext-ciphertext pairs.  For example, you might not tell someone
> the password you use now, but what about some old password that you
> don't use any more?  If the attacker knows your old password (maybe
> because your sysop set it to some default value and had you change it
> on your first login), and has the encrypted version, there's a known
> plaintext.

Password management is certainly a problem, but of course is totally
unrelated to the quality of an encryption method.

> > I thought the problem was concealing passwords from ones kids or
> > collaborators.
>
> Encryption is supposed to conceal data from knowledgable attackers
> willing to burn significant resources to get at the data.  That mightof
> or might not describe your friends and collaborators.

I agree. Depending on a situation, a solution might or might not be
adequate.

> > I believe that a randomly distributed series utterly obliterates any
> > non-randomness or regularity of a second series, if the two are added.
>
> This is a meaningless statement since you don't give any definition of
> "randomly distributed series".

No, in fact I don't. I am quite confident that the library module 'random'
produces random distributions. As to the distribution of a non-random series
added to a random series, my intuition tells me that it remains random.

> > I don't know how to produce a formal proof. It is just a hunch. It's
> > actually more than a hunch. It is a conviction. Not a certainty; a
> > conviction. I'd be delighted to be proved wrong (or right).

I don't think it would be difficult for a mathematician to prove or disprove
the hypothesis. I did come up with an informal proof. It is a function I
will add at the bottom of this message. You can copy and run it, if you have
the Image package installed.

>
> If the keystream really can't be distinguished from random, then correct,
> though there's still issues with key management (you mustn't use the same
> key twice) and authentication.

The key is the seed of the random generator.

> Generating keystreams that are indistinguishable from random is an
> extremely tricky subject, there are books and papers written about it,
etc.

I agree. I wouldn't know how to design a random generator. Fortunately I
don't need to. I can use ready made ones.

> > The fact may be significant that we module overflow back into the
> > range.  So, if the distribution of my code is indeed random,

> Your code used the Python built-in PRNG algorithm which is designed to
> make output with similar statistical properties as actual random numbers,
> for the purpose of running stuff like simulations.  It makes no attempt
> at all to be secure against attackers trying to figure out whether the
> output is really random.

Try out the following function. You need the Image package.

Regards

Frederic

###

def informal_proof_of_randomness (text_fi

Re: pyvm -- faster python

2005-05-09 Thread djw
Paul Rubin wrote:
> Stelios Xanthakis <[EMAIL PROTECTED]> writes:
> 
>>- The demo is an x86/linux binary only. You shouldn't trust binaries,
>>   run it in a chrooted environment not as root!
> 
> 
> Are you going to release the source?  If not, it's a lot less interesting.

 From the website:

"...the source will be released when it becomes more complete and stable."
-- 
http://mail.python.org/mailman/listinfo/python-list


Unique Elements in a List

2005-05-09 Thread [EMAIL PROTECTED]
Is there an easy way to grab the Unique elements from a list?
For Example:
data = [0.1,0.5,0.6,0.4,0.1,0.5,0.6,0.9]

what I am looking for is the unique elements 0.4 and 0.9 with their
index from the list.
Probably something like a Hash Table approach!!
I would like to get this done without unnecessary overhead.And the list
could be essentially anything strings,floats,int etc...

Or is it already avaliable as an attr to a list or an array?
I dont remember seeing anything like that.

-- 
http://mail.python.org/mailman/listinfo/python-list


Dr. Dobb's Python-URL! - weekly Python news and links (May 9)

2005-05-09 Thread Simon Brunning
QOTW: "It's not perfect, but then nobody in this thread has offered
anything even remotely resembling perfect documentation for regular
expressions yet. " - Peter Hansen

"Python's flavor of OO is perfectly valid and usable, even though it
doesn't follow the Java Holy Bible of Object Orientation (gasp!)" - Hans Nowak

"It's highly arguable if Python is "better" than C#, but from a
control-your-own-destiny angle, Python is a complete slam dunk. Python
works well on *nix, Java, .NET and Mac OS X. It's open source. It's
sane. But I won't argue it's fast. It's usually just not so slow you
care." - Jonathan Rentzsch


String Manipulation in Python:
http://www.devshed.com/c/a/Python/String-Manipulation/

Why you can't detect a float's significant digits:

http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/85eaac30c01b51a5

Dependency Injection The Python Way:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/413268

What is Paste?
http://blog.ianbicking.org/what-is-paste.html

Finding peaks and valleys:

http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/6506673a689339b7

Type-safe Enums in Python:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/413486

Python turns up again in a Microsoft outpost:

http://www.informit.com/guides/content.asp?g=windowsserver&seqNum=183&rl=1

Encryption with Python:

http://groups-beta.google.com/group/comp.lang.python/browse_thread/thread/5fb9ffada975bae9

The importance of being selfish, deja vu:
http://zephyrfalcon.org/weblog2/arch_e10_00770.html#e776

Notable releases:
CherryPy-2.0-final:

http://groups-beta.google.com/group/comp.lang.python.announce/browse_thread/thread/8905b9f2bd114f38
BeautifulSoup 2.1.0:
http://www.crummy.com/software/BeautifulSoup/
KirbyBase 1.8.2:
http://www.netpromi.com/kirbybase.html



Everything Python-related you want is probably one or two clicks away in
these pages:

Python.org's Python Language Website is the traditional
center of Pythonia
http://www.python.org
Notice especially the master FAQ
http://www.python.org/doc/FAQ.html

PythonWare complements the digest you're reading with the
marvelous daily python url
 http://www.pythonware.com/daily  
Mygale is a news-gathering webcrawler that specializes in (new)
World-Wide Web articles related to Python.
 http://www.awaretek.com/nowak/mygale.html 
While cosmetically similar, Mygale and the Daily Python-URL
are utterly different in their technologies and generally in
their results.

For far, FAR more Python reading than any one mind should
absorb, much of it quite interesting, several pages index
much of the universe of Pybloggers.
http://lowlife.jp/cgi-bin/moin.cgi/PythonProgrammersWeblog
http://www.planetpython.org/
http://mechanicalcat.net/pyblagg.html

comp.lang.python.announce announces new Python software.  Be
sure to scan this newsgroup weekly.

http://groups.google.com/groups?oi=djq&as_ugroup=comp.lang.python.announce

Steve Bethard, Tim Lesher, and Tony Meyer continue the marvelous
tradition early borne by Andrew Kuchling, Michael Hudson and Brett
Cannon of intelligently summarizing action on the python-dev mailing
list once every other week.
http://www.python.org/dev/summary/

The Python Package Index catalogues packages.
http://www.python.org/pypi/

The somewhat older Vaults of Parnassus ambitiously collects references
to all sorts of Python resources.
http://www.vex.net/~x/parnassus/   

Much of Python's real work takes place on Special-Interest Group
mailing lists
http://www.python.org/sigs/

The Python Business Forum "further[s] the interests of companies
that base their business on ... Python."
http://www.python-in-business.org

Python Success Stories--from air-traffic control to on-line
match-making--can inspire you or decision-makers to whom you're
subject with a vision of what the language makes practical.
http://www.pythonology.com/success

The Python Software Foundation (PSF) has replaced the Python
Consortium as an independent nexus of activity.  It has official
responsibility for Python's development and maintenance. 
http://www.python.org/psf/
Among the ways you can support PSF is with a donation.
http://www.python.org/psf/donate.html

Kurt B. Kaiser publishes a weekly report on faults and patches.
http://www.google.com/groups?as_usubject=weekly%20python%20patch
   
Cetus collects Python hyperlinks.
http://www.cetus-links.org/oo_python.ht

Re: Language documentation ( was Re: Computing Industry shams)

2005-05-09 Thread Sean Burke

alex goldman <[EMAIL PROTECTED]> writes:

> vermicule wrote:
> 
> > 
> > What is so hard to understand ?
> > Should be perfectly clear even to a first year undergraduate.
> > 
> > As for "greedy" even a minimal exposure to Djikstra's shortest path
> > algorithm would have made the concept intuitive. And from memory,
> > that is the sort of thing done in Computing 101 and in  Data Structures
> > and Algorithms 101
> > 
> > It seems to me that you want the Python doc to be written for morons.
> > And that is not a valid complaint.
> 
> He's right actually. If we understand the term "greedy" as it's used in
> graph search and optimization algorithms, Python's RE matching actually IS
> greedy.

No, you're just confused about the optimization metric.
In regexes, "greedy" match optimizes for the longest match,
not the fastest.

And this is common regex terminology - man perlre and you will
find discussion of "greedy" vs. "stingy" matching.

-SEan

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Encryption with Python?

2005-05-09 Thread Paul Rubin
"Anthra Norell" <[EMAIL PROTECTED]> writes:
> I don't follow. There is no bitwise correlation between a plain-text
> character and its encoded equivalent. What's more, there is no detectable
> correlation at all. 

Your question was how could you tell if two ciphertexts were encrypted
with the same key.  Answer: suppose both plaintext are ascii strings.
Then both plaintexts have 0 as the top bit of every byte.  So do this:

   x = ciphertext1 xor ciphertext2

If ciphertext1 and ciphertext2 were encrypted with two different keys,
the top bit of x's bytes will be random-looking.  If ciphertext1 and
ciphertext2 were encrypted with the same key, the top bit of each of
x's bytes will be 0.  So just check whether the top bit of x is always
0.  If it is, then ciphertexts 1 and 2 were probably encrypted with
the same key.

> Password management is certainly a problem, but of course is totally
> unrelated to the quality of an encryption method.

You're ignoring your own question.  With a good encryption scheme,
finding out an old password doesn't tell you anything about new
messages.  With your encryption scheme, finding out an old password
leaks information about the new one.

> I agree. Depending on a situation, a solution might or might not be
> adequate.

Since good encryption schemes that don't have significant performance
penalties are widely available, why mess with a crap scheme EVER?  Why
use a solution that "might or might not be adequate" when you can use
one that's definitely ok?

> No, in fact I don't. I am quite confident that the library module 'random'
> produces random distributions.

The author of the algorithm doesn't agree with you.  The documentation
is very explicit, it's no good for cryptography, and if you study how
it works you can see that it's easily distinguishable from random.

> I don't think it would be difficult for a mathematician to prove or
> disprove the hypothesis.

It's true of a genuine random keystream, but that's not what we're
talking about.  We're talking about the output of python's random
module, which is not of cryptographic quality.  It's fine for
statistical simulations in that it doesn't have correlations that are
likely to accidentally cause trouble.  It's no good for defeating
adversaries who are looking for correlations on purpose.  Lots of
people don't understand the difference.  Please see the book "Security
Engineering" by Ross Anderson to get an idea of what you're up against.

> > Generating keystreams that are indistinguishable from random is an
> > extremely tricky subject, there are books and papers written about
> > it, etc.
> 
> I agree. I wouldn't know how to design a random generator. Fortunately I
> don't need to. I can use ready made ones.

There are good ready ones available, but the one you're proposing to
use is not one of them and was not designed to be.

> Try out the following function. You need the Image package.

That doesn't prove a thing.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Unique Elements in a List

2005-05-09 Thread runes
This is not the most beautiful idiom, but it works...

d = {}
for k in data:
try:
d[k] += 1
except:
d[k] = 1

for k,v in d.items():
if v == 1:
print k

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Unique Elements in a List

2005-05-09 Thread [EMAIL PROTECTED]
OK I need to be more clear I guess!Unique Elements I mean, elements
that are non repeating. so in the above list 0.4, 0.9 are unique as
they exist only once in the list.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Unique Elements in a List

2005-05-09 Thread Roie Kerstein
[EMAIL PROTECTED] wrote:

> Is there an easy way to grab the Unique elements from a list?
> 
Yes.
The set data type.
Look in the reference of python 2.4.
-- 
Best regards
Roie Kerstein

-- 
http://mail.python.org/mailman/listinfo/python-list


Unique Elements in a List

2005-05-09 Thread James Stroud

On Monday 09 May 2005 03:15 pm, [EMAIL PROTECTED] wrote:
> Is there an easy way to grab the Unique elements from a list?

from sets import Set

data = [0.1,0.5,0.6,0.4,0.1,0.5,0.6,0.9]

[x for x in Set(data) if data.count(x) == 1]

--
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

http://www.jamesstroud.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Unique Elements in a List

2005-05-09 Thread James Stroud
On Monday 09 May 2005 03:15 pm, [EMAIL PROTECTED] wrote:
> Is there an easy way to grab the Unique elements from a list?
> For Example:
> data = [0.1,0.5,0.6,0.4,0.1,0.5,0.6,0.9]
>
> what I am looking for is the unique elements 0.4 and 0.9 with their
> index from the list.
> Probably something like a Hash Table approach!!
> I would like to get this done without unnecessary overhead.And the list
> could be essentially anything strings,floats,int etc...
>
> Or is it already avaliable as an attr to a list or an array?
> I dont remember seeing anything like that.

from sets import Set

data = [0.1,0.5,0.6,0.4,0.1,0.5,0.6,0.9]

[x for x in Set(data) if data.count(x) == 1]

-- 
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

http://www.jamesstroud.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: replace string patern with different value

2005-05-09 Thread Bengt Richter
On Mon, 9 May 2005 15:48:14 +0200, "Fredrik Lundh" <[EMAIL PROTECTED]> wrote:

>Bill Mill wrote:
>
> for rep in L:
>> ... source = source.replace(token, rep, 1)
>
>here's another way to do it:
>
 L = ["11", "22", "33"]
 S = "xyzzy text we've got xyzzy text xyzzy yeah yeah yeah"
 L.reverse()
 re.sub("xyzzy", lambda x: L.pop(), S)
>"11 text we've got 22 text 33 yeah yeah yeah"
>
>or, less destructive:
>
 L = ["11", "22", "33"]
 S = "xyzzy text we've got xyzzy text xyzzy yeah yeah yeah"
 re.sub("xyzzy", lambda x, pop=iter(L).next: pop(), S)
>
>(a few more iterations of this idea and we're in python riddle country...)
>
Another:

 >>> L = ["11", "22", "33"]
 >>> S = "xyzzy text we've got xyzzy text xyzzy yeah yeah yeah"
 >>> ''.join([(i%2 and [n()] or [s()])[0] for s, n in
 ... [(iter(S.split('xyzzy')).next, iter(L).next)] for i in 
xrange(2*len(L)+1)])
 "11 text we've got 22 text 33 yeah yeah yeah"

Or maybe:

 >>> ''.join(map(lambda x,y:(x or '')+(y or ''), S.split('xyzzy'), L))
 "11 text we've got 22 text 33 yeah yeah yeah"

Regards,
Bengt Richter
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Unique Elements in a List

2005-05-09 Thread runes
Your set-approach is very nice, but if the list of data is huge, it is
rather slow because you'll have to loop through the data list and count
every member.

-- 
http://mail.python.org/mailman/listinfo/python-list


RE: py23-pysvn-svn114-1.2.0-415.exe << won't load on win98

2005-05-09 Thread Timothy Smith
hello there,
i get the following error when attempting to load pysvn on a win98 system

Traceback (most recent call last):
>  File "PubWare.py", line 11, in ?
>  File "Main.pyc", line 46, in ?
>  File "pysvn\__init__.pyc", line 12, in ?
>  File "pysvn\_pysvn.pyc", line 9, in ?
>  File "pysvn\_pysvn.pyc", line 7, in __load
>ImportError: DLL load failed: A device attached to the system is not 
>functioning.

i installed the package on a windows xp system, and on other xp systems
it is also fine, however on win98 systems it errors


ok i have installed win98 on a test machine and sure enough i get the 
exact same error on trying to import pysvn.

it's python 2.3, pysvn 1.2.0 build 415. it's a totally virgin install, 
nothing but those 2 are installed on the system. note that is' standard 
win98, not win98 SE

now how do i start trying to track down whats wrong and do you think it 
will be possible to fix it?



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: file corruption on windows - possible bug

2005-05-09 Thread Bengt Richter
On Mon, 09 May 2005 10:54:22 -0400, Jeremy Jones <[EMAIL PROTECTED]> wrote:

>I've written a piece of code that iterates through a list of items and
>determines the filename to write some piece of data to based on
>something in the item itself.  Here is a small example piece of code to
>show the type of thing I'm doing::
>
>#
>file_dict = {}
>
>a_list = [("a", "a%s" % i) for i in range(2500)]
>b_list = [("b", "b%s" % i) for i in range(2500)]
>c_list = [("c", "c%s" % i) for i in range(2500)]
>d_list = [("d", "d%s" % i) for i in range(2500)]
>
>
>joined_list = a_list + b_list + c_list + d_list
>
>for key, value in joined_list:
>outfile = file_dict.setdefault(key, open("%s.txt" % key, "w"))
You are opening files multiply, since the open is a default value expression 
that is
always evaluated. Try replacing the above line with the following two lines:
 try: outfile = file_dict[key]
 except KeyError: outfile = file_dict[key] = open("%s.txt" % key, 'w')
>outfile.write("%s\n" % value)
>
>for f in file_dict.values():
>f.close()
>#
>
>Problem is, when I run this on Windows, I get 14,520 null ("\x00")
>characters at the front of the file and each file is 16,390 bytes long. 
>When I run this script on Linux, each file is 13,890 bytes and contains
>no "\x00" characters.  This piece of code::
>
I don't want to think about the _exact_ explanation, but try the above 
(untested ;-)
and see if the symptoms change ;-)

Regards,
Bengt Richter
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   >