Re: converting html escape sequences to unicode characters

2004-12-10 Thread Craig Ringer
On Fri, 2004-12-10 at 08:36, harrelson wrote:
> I have a list of about 2500 html escape sequences (decimal) that I need
> to convert to utf-8.  Stuff like:

I'm pretty sure this somewhat horrifying code does it, but is probably
an example of what not to do:

>>> escapeseq = '비'
>>> uescape = ("\\u%x" % int(escapeseq[2:-1])).decode("unicode_escape")
>>> uescape
u'\ube44'
>>> print uescape
비
(I don't seem to have the font for it, but I think that's right - my
terminal font seems to show it correctly).

I just get the decimal value of the escape, format it as a Python
unicode hex escape sequence, and tell Python to interpret it as an
escaped unicode string.

>>> entities = ['비', '행', '기', '로',
'보', '낼', '거', '에', '요', '내',
'면', '금', '이', '얼', '마', '지',
'잠']
>>> def unescape(escapeseq):
... return ("\\u%x" % int(escapeseq[2:-1])).decode("unicode_escape")
...
>>> print ' '.join([ unescape(x) for x in entities ])
비 행 기 로 보 낼 거 에 요 내 면 금 이 얼 마 지 잠

--
Craig Ringer

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


Re: converting html escape sequences to unicode characters

2004-12-10 Thread Craig Ringer
On Fri, 2004-12-10 at 16:09, Craig Ringer wrote:
> On Fri, 2004-12-10 at 08:36, harrelson wrote:
> > I have a list of about 2500 html escape sequences (decimal) that I need
> > to convert to utf-8.  Stuff like:
> 
> I'm pretty sure this somewhat horrifying code does it, but is probably
> an example of what not to do:

It is. Sorry. I initially misread Kent Johnson's post. He just used
'unichr()'. Colour me an idiot. If you ever need to know the hard way to
build a unicode character...

--
Craig Ringer

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


Re: threading problem

2004-12-10 Thread Egor Bolonev
On Fri, 10 Dec 2004 00:12:16 GMT, Steven Bethard  
<[EMAIL PROTECTED]> wrote:

I think if you change the call to look like:
threading.Thread(target=run, args=(os.path.join('c:\\', path),)).start()
oh i see now. thanks
s='sdgdfgdfg'
s == (s)
True
s == (s,)
False

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


Re: exec'ing functions

2004-12-10 Thread Peter Otten
Mel Wilson wrote:

> The thing is, that once you drop local-namespace
> optimization, the entire function gets slowed down, possibly
> by 40%:

It's not that bad as most of the extra time is spend on compiling the
string.

def fib5(n):
a, b, i = 0, 1, n
while i > 0:
a, b = b, a+b
yield a
i -= 1

def fib6(n):
exec "a, b, i = 0, 1, n" 
while i > 0:
a, b = b, a+b
yield a
i -= 1

def fib7(n, c=compile("a, b, i = 0, 1, n", "", "exec")):
exec c
while i > 0:
a, b = b, a+b
yield a
i -= 1

[Python 2.3]
$ timeit.py -s"from fib import fib5 as fib" "list(fib(100))"
1 loops, best of 3: 143 usec per loop
$ timeit.py -s"from fib import fib6 as fib" "list(fib(100))"
1 loops, best of 3: 208 usec per loop
$ timeit.py -s"from fib import fib7 as fib" "list(fib(100))"
1 loops, best of 3: 151 usec per loop

Peter


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


Re: VC++ 6.0 and 2.4

2004-12-10 Thread "Martin v. Löwis"
Jive wrote:
Theoretically, if I messed around with the 2.4 project until I got it to
build under MS VC++ 6.0, would the python.exe play correctly with version
2.4 .pyd extensions?
My initial answer was no, as 2.4 .pyd extensions are build with VC 7.1,
and that uses a different CRT. However, as David Fraser points out,
"2.4 .pyd extensions" doesn't really say much what compiler has been
used, so if you use VC6 to build the extensions, it will work fine.
Also, I'm not sure what "mess around with the 2.4 project" means. Are
you talking about the project and solution files in PCbuild? Don't
mess with them, use PC/VC6 instead.
Regards,
Martin
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python 2.3.5 ?

2004-12-10 Thread Fuzzyman
Hello Peter,

Sorry to confuse you. It was actually a reply to Stefans dig about top
posting.

Regards,

Fuzzy

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


Re: building python extensions with .net sdk compiler?

2004-12-10 Thread Zuurcool
Anthony Baxter wrote:
I'm trying to build a binary of fastaudio (the wrapper for the PortAudio
library, from http://www.freenet.org.nz/python/pyPortAudio/) for Python 2.3.
There's a lot of FAQs and the like out there that give some simple directions,
involving fetching the .net sdk from MSDN and distutils "should work" - 
however, when I follow them and try to do the setup.py build step, I get
a message:
  error: Python was built with version 6 of Visual Studio, and extensions need 
  to be built with the same version of the compiler, but it isn't installed.
Hello Anthony,
I got this insane message, how did you solve this "problem" ?

running install
running build
running build_py
running build_ext
error: The .NET Framework SDK needs to be installed before building 
extensions for Python.
-

Or does anyone know why i get this message, the .net sdk is about 100Mb, 
no fun !

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


Re: samba/windows shares (with python?)

2004-12-10 Thread Eino Mäkitalo
I.V. Aprameya Rao wrote:
hi
does anybody know how to access samba/windows shares on a network? is 
there any module that does this?

i am running linux and i thought of using the mount command to mount that 
remote share and then access it, but i was wondering whether that is the 
right way?

Aprameya
With python, CIFS client for python?
If not, try smbclient
Eino
--
http://mail.python.org/mailman/listinfo/python-list


Re: samba/windows shares

2004-12-10 Thread Martin Franklin
On Thu, 9 Dec 2004 20:03:55 +0530 (IST), I.V. Aprameya Rao  
<[EMAIL PROTECTED]> wrote:

hi
does anybody know how to access samba/windows shares on a network? is
there any module that does this?
i am running linux and i thought of using the mount command to mount that
remote share and then access it, but i was wondering whether that is the
right way?
Aprameya

Hi,
I was looking for this just yesterday... I 'found' a pure python samba  
client
package here:-

http://miketeo.net/projects/pysmb/
It seems to work too!
I also found, but did not look into further, python bindings in the samba  
source
code tree http://www.samba.org/

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


Re: PIL for Windows for Python 2.4

2004-12-10 Thread Robin Becker
Fuzzyman wrote:
So you've built PIL for windows, Python 2.4 ?
Any chance of sharing it ? What compiler have you configured distutils
to use ?
Regards,
Fuzzyman
I have compiled 1.1.4's _imaging & _imagingft for 2.4 and have placed them at
http://www.reportlab.org/ftp/win32-dlls/2.4
Don't have a decent TCL any more so haven't compiled that stuff.
--
Robin Becker
--
http://mail.python.org/mailman/listinfo/python-list


Re: Wrapper objects

2004-12-10 Thread Nick Coghlan
Simon Brunning wrote:
On 9 Dec 2004 06:11:41 -0800, Egil M?ller <[EMAIL PROTECTED]> wrote:
Is there any way to create transparent wrapper objects in Python?

This work - ?
Only for old-style classes, though. If you inherit from object or another 
builtin, that recipe fails.

Cheers,
Nick.
--
Nick Coghlan   |   [EMAIL PROTECTED]   |   Brisbane, Australia
---
http://boredomandlaziness.skystorm.net
--
http://mail.python.org/mailman/listinfo/python-list


Building Windows debug distribution

2004-12-10 Thread Mark English
I have a Windows build of Python 2.4 core with all the extensions, both
debug and release. The release installer is built by msi.py
Is there a way to build a debug distribution other than rewriting msi.py
?


---
The information contained in this e-mail is confidential and solely 
for the intended addressee(s). Unauthorised reproduction, disclosure, 
modification, and/or distribution of this email may be unlawful. If you 
have received this email in error, please notify the sender immediately 
and delete it from your system. The views expressed in this message 
do not necessarily reflect those of LIFFE Holdings Plc or any of its subsidiary 
companies.
---

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


Re: Rationale behind the deprecation of __getslice__?

2004-12-10 Thread Nick Coghlan
Steven Bethard wrote:
Carl Banks wrote:
Wouldn't it work to have __getslice__ call __getitem__?  And, since
that would be too much of a performance hit, have it check whether its
type is list (or str or tuple), and only call __getitem__ if it is not
(i.e., only for subclasses).  I don't think that would be too bad.
Subclasses would still be free to override __getslice__, but wouldn't
have to.
Yeah, that doesn't seem like it would be too bad.  Probably someone 
would have to actually run some benchmarks to see what kind of 
performance hit you get...  But it would definitely solve the OP's 
problem...
It might be better handled at construction time - if the class supplied to 
__new__ is a subclass of the builtin type, swap the __getslice__ implementation 
for one which delegates to __getitem__.

Cheers,
Nick.
--
Nick Coghlan   |   [EMAIL PROTECTED]   |   Brisbane, Australia
---
http://boredomandlaziness.skystorm.net
--
http://mail.python.org/mailman/listinfo/python-list


Re: Rationale behind the deprecation of __getslice__?

2004-12-10 Thread Nick Coghlan
Steven Bethard wrote:
Presumably the numarray code has to do quite a bit of type checking to 
perform all these slicings right (and I didn't even show you what 
happens when you use another array as an "index").  I'm not necessarily 
saying that all this type checking is a good thing, but because people 
will always find new things that they want to index by, adding 
__getxxx__ methods for each of the index types is probably not the right 
road to go down...
I suspect Steve's hit the nail on the head here - the requirements of the numpy 
folks certainly drove the development of extended slicing in the first place (it 
wasn't until 2.3 that Python's builtin sequences supported extended slicing at all).

Cheers,
Nick.
--
Nick Coghlan   |   [EMAIL PROTECTED]   |   Brisbane, Australia
---
http://boredomandlaziness.skystorm.net
--
http://mail.python.org/mailman/listinfo/python-list


problem with datetime

2004-12-10 Thread bncarper
Relatively new to python.  I can get the following to work from the
command line:

Python 2.3.4 (#2, Aug 18 2004, 21:49:15)
[GCC 3.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import datetime
>>> d = datetime.datetime.today()
>>> d
datetime.datetime(2004, 12, 10, 6, 13, 28, 154472)
>>>

But when I try to run the following small program I get the following
results:

import datetime
d = datetime.datetime.today()
print d

Traceback (most recent call last):
File "datetime.py", line 1, in ?
import datetime
File "/home/bob/pyshow/datetime.py", line 3, in ?
d = datetime.datetime.today()
AttributeError: 'module' object has no attribute 'today'

Do I need to change a path?
Running python 2.3.4 on linux redhat 7.3.

Bob

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


problem with datetime

2004-12-10 Thread Bob
Relatively new to python.  I can get the following to work from the
command line:

Python 2.3.4 (#2, Aug 18 2004, 21:49:15)
[GCC 3.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import datetime
>>> d = datetime.datetime.today()
>>> d
datetime.datetime(2004, 12, 10, 6, 13, 28, 154472)
>>>

But when I try to run the following small program I get the following
results:

import datetime
d = datetime.datetime.today()
print d

Traceback (most recent call last):
File "datetime.py", line 1, in ?
import datetime
File "/home/bob/pyshow/datetime.py", line 3, in ?
d = datetime.datetime.today()
AttributeError: 'module' object has no attribute 'today'

Do I need to change a path?
Running python 2.3.4 on linux redhat 7.3.

Bob

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


Re: problem with datetime

2004-12-10 Thread Gerhard Haering
On Fri, Dec 10, 2004 at 04:19:56AM -0800, [EMAIL PROTECTED] wrote:
> Relatively new to python.  I can get the following to work from the
> command line:
> 
> Python 2.3.4 (#2, Aug 18 2004, 21:49:15)
> [GCC 3.2] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import datetime
> >>> d = datetime.datetime.today()
> >>> d
> datetime.datetime(2004, 12, 10, 6, 13, 28, 154472)
> >>>
> 
> But when I try to run the following small program I get the following
> results:
> 
> import datetime
> d = datetime.datetime.today()
> print d
> 
> Traceback (most recent call last):
> File "datetime.py", line 1, in ?
> import datetime
> File "/home/bob/pyshow/datetime.py", line 3, in ?
 ^^^

> d = datetime.datetime.today()
> AttributeError: 'module' object has no attribute 'today'
> 
> Do I need to change a path?
> Running python 2.3.4 on linux redhat 7.3.

Change your script's name from datetime.py to something else. Otherwise the
script will import itself, and not the datetime module from the standard
library.

-- Gerhard
-- 
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?


signature.asc
Description: Digital signature
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Building Windows debug distribution

2004-12-10 Thread Thomas Heller
"Mark English" <[EMAIL PROTECTED]> writes:

> I have a Windows build of Python 2.4 core with all the extensions, both
> debug and release. The release installer is built by msi.py
> Is there a way to build a debug distribution other than rewriting msi.py
> ?

But rewriting msi.py shouldn't be hard (replace xyz.pyd by xyz_d.pyd,
basically)

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


Re: problem with datetime

2004-12-10 Thread Peter Otten
Bob wrote:

> But when I try to run the following small program I get the following
> results:
> 
> import datetime
> d = datetime.datetime.today()
> print d
> 
> Traceback (most recent call last):
> File "datetime.py", line 1, in ?
> import datetime

You are importing your script, not the library module here.

> File "/home/bob/pyshow/datetime.py", line 3, in ?

Just rename that file to mydatetime.py or something, and you're fine.
But don't forget to delete /home/bob/pyshow/datetime.pyc or .pyo, too.

Peter


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


Re: Python 2.3.5 ?

2004-12-10 Thread Peter Hansen
Fuzzyman wrote:
Hello Peter,
Sorry to confuse you. It was actually a reply to Stefans dig about top
posting.
Hmm... I don't even see any named Stefan posting in this thread.
I hope my newsreader isn't dropping messages...  :-(
Anyway, not important, never mind.
-Peter
--
http://mail.python.org/mailman/listinfo/python-list


Re: wxPython bug

2004-12-10 Thread Sion Arrowsmith
Jive <[EMAIL PROTECTED]> wrote:
>In wxPython 2.5, run the demo, samples/wxProject/wxProject.py
> [ ... ]
>TypeError: TreeCtrl_GetFirstChild() takes exactly 2 arguments (3 given)

GetFirstChild() changed from taking 2 arguments in wxPython 2.4 to
(the more sensible) 1 in wxPython 2.5. Clearly wxProject hasn't
been thoroughly 2.5ified. (Looking at it, it's not using the wx
namespace, so I'd say it's not been 2.5ified at all.)

>What to do?

(a) Fix your copy of wxProject.py (someone else has already
pointed this out).

(b) File a bug report 
(http://sourceforge.net/tracker/?group_id=9863&atid=109863)
with a "wxPython specific" category.

-- 
\S -- [EMAIL PROTECTED] -- http://www.chaos.org.uk/~sion/
  ___  |  "Frankly I have no feelings towards penguins one way or the other"
  \X/  |-- Arthur C. Clarke
   her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python for Palm OS?

2004-12-10 Thread Gustavo Niemeyer
> Is there any news regarding Python on the Palm OS front?

As an interesting side effect of the recently announced PalmOS
on Linux, porting Python for that platform will become a lot
easier, hopefully. If only I could find Tim's time-machine and
bring a unit from the future. ;-)

-- 
Gustavo Niemeyer
http://niemeyer.net
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: collaborative editing

2004-12-10 Thread Robert Kern
Michele Simionato wrote:
Suppose I want to write a book with many authors via the Web. The book has 
a hierarchical structure with chapter, sections, subsections, subsubsections, 
etc. At each moment it must be possible to print the current version of the 
book in PDF format. There must be automatic generation of the table of contents,
indices, etc. Conversions to many formats (Latex, DocBook, etc.) would be
welcome. Does something like that already exists? Alternatively, I would need
some hierarchical Wiki with the ability of printing its contents in an
structured way. 
Does it have to be via the Web? Why doesn't LaTeX/DocBook with a central 
CVS/Subversion repository work for what you want to do?

Personally, I loathe writing at any length inside a Web browser and 
prefer to use a real editor at all times.

--
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: Possible to insert variables into regular expressions?

2004-12-10 Thread Chris Lasher
Robert, Craig, thanks for your replies.  I'll only be dealing with
alphanumerics for this project, I think, but it's good to be aware of
this possible problem for later projects. The re.escape(...) is a handy
method to know about. Thanks very much.

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


Re: How to set condition breakpoints?

2004-12-10 Thread Colin J. Williams
Christopher J. Bottaro wrote:
I have a script with a class in it:
class Class:
def f(x, y):
# do something
I start up the debugger like this:
python /usr/lib/python2.3/pdb.py myscript.py
I want to set a conditional breakpoint:
b Class.f, x == 1 and y == 2
but that doesn't work.  How can I do what I want?
Thank you.
You might consider boa-constructor, implemented for Windows and Linux.
I believe that it provides this functionality.  Of course it provides a 
lot more.

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


RE: results of division

2004-12-10 Thread Batista, Facundo
Title: RE: results of division





[Paul McGuire]


#- Errr?  How come round() is able to understand 1.775 
#- correctly, whereas
#- string interp is not?  I'm guessing that round() adds some 
#- small epsilon to
#- the value to be rounded, or perhaps even does the brute 
#- force rounding I
#- learned in FORTRAN back in the 70's:  add 0.5 and truncate.  
#- But this would
#- still truncate 1.77999 to two places, so this theory 
#- fails also.  What
#- magic is round() doing, and should this same be done in the 
#- string interp
#- code?


This is a great example of "how to get your life easier" for my paper on Decimal. I will use it, if you don't mind.


.   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: collaborative editing

2004-12-10 Thread Jeremy Jones
Robert Kern wrote:
Michele Simionato wrote:
Suppose I want to write a book with many authors via the Web. The 
book has a hierarchical structure with chapter, sections, 
subsections, subsubsections, etc. At each moment it must be possible 
to print the current version of the book in PDF format. There must be 
automatic generation of the table of contents,
indices, etc. Conversions to many formats (Latex, DocBook, etc.) 
would be
welcome. Does something like that already exists? Alternatively, I 
would need
some hierarchical Wiki with the ability of printing its contents in an
structured way. 

Does it have to be via the Web? Why doesn't LaTeX/DocBook with a 
central CVS/Subversion repository work for what you want to do?

Personally, I loathe writing at any length inside a Web browser and 
prefer to use a real editor at all times.

Actually, in a sense, if you put up a SVN repository under Apache, the 
repository is available "via the Web" just as the OP requires.  He'll 
have to specify further, but I'm not so sure this is a requirement to be 
able to edit via a browser over the web, or just have the repository on 
the web somewhere that multiple people can access it.

But SVN will work pretty well, I think, for what you're doing.  
Especially if the authors are editing different sections of the file.  
If two (or more) authors try to edit the same section of file, the first 
one to commit the change will "win" and any subsequent commits will not 
be able to commit the change until the resolve the conflict.

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


Re: Find Items & Indices In A List...

2004-12-10 Thread Joachim Bauch
Hi Andrea,
[EMAIL PROTECTED] wrote:
  I was wondering if there is a faster/nicer method (than a for loop)
that will allow me to find the elements (AND their indices) in a list that
verify a certain condition. For example, assuming that I have a list like:
mylist = [0, 1, 1, 1, 1, 5, 6, 7, 8, 1, 10]
I would like to find the indices of the elements in the list that are equal
to 1 (in this case, the 1,2,3,4,9 elements are equal to 1). I could easily
use a for loop but I was wondering if there is a faster method...
you could use something like this:
>>> mylist = [0, 1, 1, 1, 1, 5, 6, 7, 8, 1, 10]
>>> [x[0] for x in enumerate(mylist) if x[1] == 1]
[1, 2, 3, 4, 9]
Greetings,
  Joachim
--
Joachim Bauch, struktur AG
Download icoya OpenContent 1.3 for FREE!visit http://www.icoya.de/iOC4free 
<-


signature.asc
Description: OpenPGP digital signature
-- 
http://mail.python.org/mailman/listinfo/python-list

Re: Parse XML using Python

2004-12-10 Thread Uche Ogbuji
This is a neat solution.  You can parse any well-formed general
entitity (e.g. Anil's document with multiple root nodes) in 4Suite
1.0a4:

from Ft.Xml.Domlette import EntityReader
s = """
eggs
more eggs
"""
docfrag = EntityReader.parseString(s, 'http://foo/test/spam.xml')

docfrag is now ready for processing using DOM methods.

--
Uche OgbujiFourthought, Inc.
http://uche.ogbuji.nethttp://4Suite.orghttp://fourthought.com
Use CSS to display XML -
http://www.ibm.com/developerworks/edu/x-dw-x-xmlcss-i.html
Location, Location, Location -
http://www.xml.com/pub/a/2004/11/24/py-xml.html
The State of Python-XML in 2004 -
http://www.xml.com/pub/a/2004/10/13/py-xml.html
Be humble, not imperial (in design) -
http://www.adtmag.com/article.asp?id=10286XMLOpen and more XML Hacks -
http://www.ibm.com/developerworks/xml/library/x-think27.html
A survey of XML standards -
http://www-106.ibm.com/developerworks/xml/library/x-stand4/

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


Re: Find Items & Indices In A List...

2004-12-10 Thread kaerbuhez
<[EMAIL PROTECTED]> a écrit dans le message de news: 
[EMAIL PROTECTED]
> For example, assuming that I have a list like:
>
> mylist = [0, 1, 1, 1, 1, 5, 6, 7, 8, 1, 10]
>
> I would like to find the indices of the elements in the list that are 
> equal
> to 1 (in this case, the 1,2,3,4,9 elements are equal to 1).

List comprehension is your friend:

PythonWin 2.4 (#60, Nov 30 2004, 11:49:19) [MSC v.1310 32 bit (Intel)] on 
win32.
Portions Copyright 1994-2004 Mark Hammond ([EMAIL PROTECTED]) - see 
'Help/About PythonWin' for further copyright information.
>>> mylist = [0, 1, 1, 1, 1, 5, 6, 7, 8, 1, 10]
>>> [i for i, j in enumerate(mylist) if j==1]
[1, 2, 3, 4, 9]
>>> 

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


MDaemon Warning - virus found: Returned mail: see transcript for details

2004-12-10 Thread clientes

*** WARNING **
Este mensaje ha sido analizado por MDaemon AntiVirus y ha encontrado 
un fichero anexo(s) infectado(s).  Por favor revise el reporte de abajo.

AttachmentVirus name   Action taken
--
text.pif  I-Worm.Mydoom.m  Removed


**


The original message was received at Fri, 10 Dec 2004 16:27:35 +0100
from 115.174.131.117

- The following addresses had permanent fatal errors -
<[EMAIL PROTECTED]>



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

Re: Find Items & Indices In A List...

2004-12-10 Thread Ola Natvig
[EMAIL PROTECTED] wrote:
Hello NG,
  I was wondering if there is a faster/nicer method (than a for loop)
that will allow me to find the elements (AND their indices) in a list that
verify a certain condition. For example, assuming that I have a list like:
mylist = [0, 1, 1, 1, 1, 5, 6, 7, 8, 1, 10]
I would like to find the indices of the elements in the list that are equal
to 1 (in this case, the 1,2,3,4,9 elements are equal to 1). I could easily
use a for loop but I was wondering if there is a faster method...
Thanks for every suggestion.
Andrea.
--
 Message for the recipient only, if received in error, please notify the
sender and read http://www.eni.it/disclaimer/

You could do a list comprehension /generator expression. Like this:
[i for i in range(len(mylist)) if mylist[i] == 1]
--
--
 Ola Natvig <[EMAIL PROTECTED]>
 infoSense AS / development
--
http://mail.python.org/mailman/listinfo/python-list


Re: Find Items & Indices In A List...

2004-12-10 Thread Bengt Richter
On Fri, 10 Dec 2004 16:01:26 +0100, [EMAIL PROTECTED] wrote:

>Hello NG,
>
>  I was wondering if there is a faster/nicer method (than a for loop)
>that will allow me to find the elements (AND their indices) in a list that
>verify a certain condition. For example, assuming that I have a list like:
>
>mylist = [0, 1, 1, 1, 1, 5, 6, 7, 8, 1, 10]
>
>I would like to find the indices of the elements in the list that are equal
>to 1 (in this case, the 1,2,3,4,9 elements are equal to 1). I could easily
>use a for loop but I was wondering if there is a faster method...
>
>Thanks for every suggestion.
>
One way:

 >>> mylist = [0, 1, 1, 1, 1, 5, 6, 7, 8, 1, 10]
 >>> [i for i,v in enumerate(mylist) if v==1]
 [1, 2, 3, 4, 9]

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


Re: collaborative editing

2004-12-10 Thread Nick Craig-Wood
Robert Kern <[EMAIL PROTECTED]> wrote:
>  Personally, I loathe writing at any length inside a Web browser and 
>  prefer to use a real editor at all times.

Me too!  You need mozex...

  http://mozex.mozdev.org/

Not sure about Mac support though

/OT
-- 
Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python 2.3.5 ?

2004-12-10 Thread Brad Tilley
Tim Peters wrote:
Not everyone is willing and able to switch to a
new 2.j release as soon as it appears. 
The reason I jumped on 2.4 right away was the msi installer for Windows 
systems. We can do unattended/automated installs... it's really great... 
a killer feature for Windows users who need to install Python on lots of 
machines.

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


Re: Help beautify ugly heuristic code

2004-12-10 Thread Stuart D. Gathman
On Thu, 09 Dec 2004 00:01:36 -0800, Lonnie Princehouse wrote:

> I believe you can still do this with only compiling a regex once and
> then performing a few substitutions on the hostname.

Cool idea.  Convert ip matches to fixed patterns before matching a fixed
regex. The leftovers like shaw cable (which has the MAC address of the
cable modem instead of the IP) can still be handled with regex patterns.

I had an idea last night to compile 254 regexes, one for each possible
last IP byte - but I think your idea is better.

Mitja suggested a socring system reminiscent of SpamAssassin.

That gives me a few things to try.

-- 
  Stuart D. Gathman <[EMAIL PROTECTED]>
Business Management Systems Inc.  Phone: 703 591-0911 Fax: 703 591-6154
"Confutatis maledictis, flamis acribus addictis" - background song for
a Microsoft sponsored "Where do you want to go from here?" commercial.

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


style query: function attributes for return codes?

2004-12-10 Thread george young
[python 2.3.3, x86 linux]
I recently found myself writing something like:

def get_connection():
if tcp_conn():
if server_allows_conn():
return 'good_conn'
else:
return 'bad_auth'
else:
return 'no_server'


cn = get_connection()
if cn == 'good_con': ...


This is obviously just evil, since a misspelling in the string
return is treacherous.  I'm considering function attributes:

def get_connection():
if tcp_conn():
if server_allows_conn():
return get_connection.GOOD
else:
return get_connection.BAD_AUTH
else:
return get_connection.NO_SERVER
get_connection.GOOD = 1
get_connection.BAD_AUTH = 2
get_connection.NO_SERVER = 3


If I put this function in it's own module, the solution is obvious:

GOOD_CONN = 1
def get_connection():
...
return GOOD_CONN   


But if this is a small utility function that belongs inside a
larger module/class, I would like to have it's return values
closely associated with the function, not just another value in
the parent class.

Is anybody using function attributes like this?
Is this good python style?


-- George Young
-- 
"Are the gods not just?"  "Oh no, child.
What would become of us if they were?" (CSL)
-- 
http://mail.python.org/mailman/listinfo/python-list


MySQLdb blob and binary data

2004-12-10 Thread Rune Hansen
I'm storing gzipped data in a MySQL blob field. I can fetch the blob and 
"wb" write the data to a file. It becomes a file containg gz data.

I can't take the same data and do anything sensible with it in python - 
like say zlib.decompress(data).

How can I convert the binary data from the blob field to the gzipped 
string it was stored as (java stores the string, Pickle is not an option)?

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


Tibia 0.1 DOM-based website editor

2004-12-10 Thread Robert Brewer
Cross-posted here to encourage comments/discussion. I know there's a big
feature or two I'm missing out on ;) Suggestions welcome.

Tibia is an in-browser editor for web pages. It allows you to quickly
and easily modify the content of your web pages. It allows you to
directly view, edit, and save files on your webserver. It also allows
you to upload files from your local filesystem to your webserver, and
then edit those documents. It also allows you to grab web pages from
other websites and save them on your server, and then edit _those_.

Stick the single tibia.tba file on your webserver (assuming Python is
installed) and you're off and editing files in the same folder or below.
Admins can edit any element; non-admins can edit any element for which
admins give them permission.

You should probably have IE6 or Firefox; IE has limitations. If you want
to test it with another recent browser (it's all DOM-based), feel free
and let me know what breaks: [EMAIL PROTECTED] Ditto for other
webserver/OS/Python versions. You can also fill out complete bug reports
or feature requests at http://www.casadeamor.com/FogBugz.

Tibia is public domain.


Download: http://www.aminus.org/rbre/tibia/tibia.tba

Subversion: svn://casadeamor.com/tibia/trunk

Help: http://www.aminus.org/rbre/tibia/tibia.html

Demo: http://www.aminus.org/rbre/tibia/demo/tibia.tba
Log in as an admin with iwethey/yammer.
Log in as a guest with guest/guest.
Please don't break my little home webserver ;)


Robert Brewer
MIS
Amor Ministries
[EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list


Re: Find Items & Indices In A List...

2004-12-10 Thread Steven Bethard
[EMAIL PROTECTED] wrote:
Hello NG,
  I was wondering if there is a faster/nicer method (than a for loop)
that will allow me to find the elements (AND their indices) in a list that
verify a certain condition. For example, assuming that I have a list like:
mylist = [0, 1, 1, 1, 1, 5, 6, 7, 8, 1, 10]
I would like to find the indices of the elements in the list that are equal
to 1 (in this case, the 1,2,3,4,9 elements are equal to 1). I could easily
use a for loop but I was wondering if there is a faster method...
Everyone has already given you the answer (enumerate in a LC or GE), I'd 
just comment that it's easy enough to extend their answers to any given 
condition:

>>> def getindices(sequence, predicate):
... return [i for i, v in enumerate(sequence) if predicate(v)]
...
>>> getindices([0,1,1,1,1,5,6,7,8,1,10], bool)
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
>>> def equalsone(v):
... return v == 1
...
>>> getindices([0,1,1,1,1,5,6,7,8,1,10], equalsone)
[1, 2, 3, 4, 9]
>>> def f(v):
... return pow(v, 3, 4) == 3
...
>>> getindices([0,1,1,1,1,5,6,7,8,1,10], f)
[7]
Steve
--
http://mail.python.org/mailman/listinfo/python-list


thread/queue bug

2004-12-10 Thread phil

I have a very strange bug.  A thread in a .pyc stops dead.
This program has many threads and queues and has worked
great for months.
One thread listens for UDP messages from other programs,
and puts the messages in listenq.
Procmsgs gets from listenq and for a certain kind of
message creates another mq = Queue(0).
I don't wish to distribute the source to pnetx.py
so I have a short program pnet.py import it, that is
pnetx.pyc.
Then the procmsgs thread dies at the Queue statement.
But if I run pnetx.py as the main program, all works fine.
So if pnetx.py or .pyc is imported this thread dies. ???
I've tried this with 2.3.3 and 2.3.4.  Anyone?
--
http://mail.python.org/mailman/listinfo/python-list


Re: style query: function attributes for return codes?

2004-12-10 Thread Steven Bethard
george young wrote:
This is obviously just evil, since a misspelling in the string
return is treacherous.  I'm considering function attributes:
def get_connection():
if tcp_conn():
if server_allows_conn():
return get_connection.GOOD
else:
return get_connection.BAD_AUTH
else:
return get_connection.NO_SERVER
get_connection.GOOD = 1
get_connection.BAD_AUTH = 2
get_connection.NO_SERVER = 3
Although in most cases this is probably okay, you're not guaranteed that 
the name of your function will stay the same, so there are some hazards 
in this style:

>>> def f(x):
... return f.y * x
...
>>> f.y = 100
>>> f(2)
200
>>> g, f = f, None
>>> g(2)
Traceback (most recent call last):
  File "", line 1, in ?
  File "", line 2, in f
AttributeError: 'NoneType' object has no attribute 'y'
One option is to turn your function into a class:
class get_connection(object):
GOOD = 1
BAD_AUTH = 2
NO_SERVER = 3
def __new__(cls):
if tcp_conn():
if server_allows_conn():
return cls.GOOD
else:
return cls.BAD_AUTH
else:
return cls.NO_SERVER
This is a little sneaky here -- because you only need shared state 
between all instances of get_connection, you don't actually ever need to 
create an instance.  So I've overridden __new__ to return the result of 
the function instead.  This allows you to call the function just like 
you would have before.  I haven't tested the code above, but here's a 
simpler example that works:

>>> class look_ma_no_function(object):
... X = 42
... def __new__(cls):
... return cls.X
...
>>> look_ma_no_function()
42
If you need to do this with a function that takes more parameters, you 
can just add them to the __new__ declaration:

>>> class look_ma_no_function(object):
... X = 42
... def __new__(cls, s):
... return cls.X / float(len(s))
...
>>> look_ma_no_function('answer to life the universe and everything')
1.0
Despite the fact that this particular use seems a little sneaky to me, I 
do usually end up turning most functions that seem to need attributes 
into classes (usually with a __call__ method defined).

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


Re: style query: function attributes for return codes?

2004-12-10 Thread Steven Bethard
george young wrote:
[python 2.3.3, x86 linux]
I recently found myself writing something like:
def get_connection():
if tcp_conn():
if server_allows_conn():
return 'good_conn'
else:
return 'bad_auth'
else:
return 'no_server'
cn = get_connection()
if cn == 'good_con': ...
This is obviously just evil, since a misspelling in the string
return is treacherous.  I'm considering function attributes:
def get_connection():
if tcp_conn():
if server_allows_conn():
return get_connection.GOOD
else:
return get_connection.BAD_AUTH
else:
return get_connection.NO_SERVER
get_connection.GOOD = 1
get_connection.BAD_AUTH = 2
get_connection.NO_SERVER = 3
If I put this function in it's own module, the solution is obvious:
GOOD_CONN = 1
def get_connection():
...
return GOOD_CONN   

But if this is a small utility function that belongs inside a
larger module/class, I would like to have it's return values
closely associated with the function, not just another value in
the parent class.
Sorry, I also meant to add that the other obvious way of dealing with 
this kind of thing is to make the results keyword parameters:

def get_connection(GOOD=1, BAD_AUTH=2, NO_SERVER=3):
if tcp_conn():
if server_allows_conn():
return GOOD
else:
return BAD_AUTH
else:
return NO_SERVER
This has the benefit that if your user wants different return values 
they can specify them, but the disadvantage that someone improperly 
calling the function with more than 0 parameters will get, instead of an 
error message, a strange return value.

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


Re: Python + Newspipe

2004-12-10 Thread kael
Dave Kuhlman wrote:
1. Read about ConfigParser here:
http://docs.python.org/lib/module-ConfigParser.html
Thank you very for this link.
2. Read the traceback from the bottom up:  (1) The exception is
   raised in ConfigParser.py on line 240 in function/method options.
   (2) This was called from newspipe.py on line 895 in
   function/method LeerConfig.
Should the changes be made in the newspipe/* directory only ? Or should 
I manage the ConfigParser.py ?

3. It's looking for a section named "NewsPipe" in your
   options/config file.  Check your config file.  Is that
   section name misspelled?  Is the section missing?  Does
   the NewsPipe documentation tell you where the config file
   should be and what it's name is?  If not, look in newspipe.py.
According to the Newspipe documentation 
http://newspipe.sourceforge.net/#configuration, only the 'smtp_server' 
and 'opml' lines are absolutely needed in newspipe.py.

Please, see newspipe.py below:
--
[NewsPipe]
log_console=1
smtp_server=smtp.free.fr
opml=test.opml
sleep_time=30
check_online=http://www.google.com
--
Do you think any lines are missing ?
Unless, it could come from the OPML file ?
Hope this helps.
Yes. But, unfortunately, not enough - it's hard to be a newbie. :-/
I thank you very much for your help.
--
kael
@759 .beats, 2004-12-10
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to set condition breakpoints?

2004-12-10 Thread Christopher J. Bottaro
Colin J. Williams wrote:

> Christopher J. Bottaro wrote:
>> I have a script with a class in it:
>> class Class:
>> def f(x, y):
>> # do something
>> 
>> I start up the debugger like this:
>> python /usr/lib/python2.3/pdb.py myscript.py
>> 
>> I want to set a conditional breakpoint:
>> b Class.f, x == 1 and y == 2
>> 
>> but that doesn't work.  How can I do what I want?
>> 
>> Thank you.
>> 
> You might consider boa-constructor, implemented for Windows and Linux.
> 
> I believe that it provides this functionality.  Of course it provides a
> lot more.

Hmm, thanks for the suggestions.  One more quick question.  Is it even
possible to set a breakpoint in a class method in pdb.py?  I can't even say
"break Class.f" without the condition.  I don't think the documentation for
pdb is very good...=(

Thanks.

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


Re: Wrapper objects

2004-12-10 Thread Nick Coghlan
Kent Johnson wrote:
Nick Coghlan wrote:
Simon Brunning wrote:
This work - 
?

Only for old-style classes, though. If you inherit from object or 
another builtin, that recipe fails.

Could you explain, please? I thought __getattr__ worked the same with 
new- and old-style classes?
Looking at the recipe more closely, I believe you are correct - the behaviour 
shouldn't change much between old and new style classes (the main difference 
being that the new-style version is affected by descriptors, along with the 
other things which may prevent __getattr__ from being invoked in either sort of 
class).

However, all that means is that the recipe wouldn't help the OP even with a 
classic class. In neither case will implicit invocation find the correct methods 
on the object we are delegating to.

The trick has to do with the way special values are often looked up by the 
Python interpreter.

Every class object contains entries that correspond to all the magic methods 
that Python knows about (in CPython, these are function pointers inside a C 
structure, FWIW).

When looking for a special method, the interpreter may simply check the relevant 
entry in the class object directly - if it's empty, it assumes the magic method 
is not defined and continues on that basis.

A simple example:
  class foo:
def __init__(self):
  print "Hi there!"
When a class object is built from this definition, the "def __init__" line 
actually means two things:
  1. Declare a standard Python function called '__init__' in the class 'foo'
  2. Populate the appropriate magic method entry in class 'foo'

When overriding __getattribute__ only, step 2 never happens for most of the 
magic methods, so, as far as the interpreter is concerned, the class may provide 
access to an attribute called "__add__" (via delegation), but it does NOT 
provide the magic function "__add__".

In order to have the delegation work as expected, Python has to be told which 
magic method entries should be populated (there is no sensible way for Python to 
guess which methods you intend to delegate - delegating __init__ or 
__getattribute__ is almost certainly insane, but what about methods like 
__call__ or __getattr__? __repr__ and __str__ pose interesting questions, too)

A nice way to do this is with a custom metaclass (thanks to Bengt for inspiring 
this design - note that his version automatically delegates everything when you 
call wrapit, but you have to call wrapit for each class you want to wrap, 
whereas in this one you spell out in your wrapper class which methods are 
delegated, but that class can then wrap just about anything).

wrapper.py:
=
# A descriptor for looking up the item
class LookupDescr(object):
def __init__(self, name):
self._name = name
def __get__(self, inst, cls=None):
if inst is None:
return self
# Look it up in the Python namespace
print self._name # Debug output
return inst.__getattr__(self._name)
# Our metaclass
class LookupSpecialAttrs(type):
"""Metaclass that looks up specified 'magic' attributes consistently
   __lookup__: a list of strings specifying method calls to look up
"""
def __init__(cls, name, bases, dict):
# Create the 'normal' class
super(LookupSpecialAttrs, cls).__init__(name, bases, dict)
# Now create our looked up methods
if (hasattr(cls, "__lookup__")):
for meth in cls.__lookup__:
setattr(cls, meth, LookupDescr(meth))
# Simple wrapper
class Wrapper(object):
"""Delegates attribute access and addition"""
__metaclass__ = LookupSpecialAttrs
__lookup__ = ["__add__", "__radd__", "__str__", "__int__"]
def __init__(self, obj):
super(Wrapper, self).__setattr__("_wrapped", obj)
def __getattr__(self, attr):
wrapped = super(Wrapper, self).__getattribute__("_wrapped")
return getattr(wrapped, attr)
def __setattr__(self, attr, value):
setattr(self._wrapped, attr, value)
=
Using our new wrapper type:
=
.>>> from wrapper import Wrapper
.>>> x = Wrapper(1)
.>>> x + 1
__add__
2
.>>> 1 + x
__radd__
2
.>>> print x
__str__
1
.>>> x + x
__add__
__add__
Traceback (most recent call last):
  File "", line 1, in ?
TypeError: unsupported operand type(s) for +: 'Wrapper' and 'Wrapper'
.>>> x = wrapper.Wrapper("Hi")
.>>> x + " there!"
__add__
'Hi there!'
.>>> "Wrapper says " + x
__radd__
Traceback (most recent call last):
  File "", line 1, in ?
  File "wrapper.py", line 11, in __get__
return inst.__getattr__(self._name)
  File "wrapper.py", line 40, in __getattr__
return getattr(wrapped, attr)
AttributeError: 'str' object has no attribute '__radd__'
.>>> x + x
__add__
Traceback (most recent call last):
  File "", line 1, in ?
TypeError: cannot concatenate 'str' and 'Wrapper' objects
=
So close! What's going wrong her

Re: style query: function attributes for return codes?

2004-12-10 Thread Robert Kern
Steven Bethard wrote:
Sorry, I also meant to add that the other obvious way of dealing with 
this kind of thing is to make the results keyword parameters:

def get_connection(GOOD=1, BAD_AUTH=2, NO_SERVER=3):
if tcp_conn():
if server_allows_conn():
return GOOD
else:
return BAD_AUTH
else:
return NO_SERVER
This has the benefit that if your user wants different return values 
they can specify them, but the disadvantage that someone improperly 
calling the function with more than 0 parameters will get, instead of an 
error message, a strange return value.
Another disadvantage is that one must compare the return value by value 
and not by name. That is, I cannot do something like this:

code = get_connection()
if code == NO_SERVER:
...
--
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: Tibia 0.1 DOM-based website editor

2004-12-10 Thread Gabriel Cooper

Robert Brewer wrote:
[...]
Tibia is an in-browser editor for web pages. It allows you to quickly
and easily modify the content of your web pages. 
[...]

I couldn't get it to work using Firefox on Red Hat Fedora Core 2. From 
what I garnered from the help you're supposed to be able to double-click 
on any page element with a big block-border around it, right? If so, 
nothing happened for me. :(

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


Re: Wrapper objects

2004-12-10 Thread redhog
Bengt Richter wrote:
> On 9 Dec 2004 06:11:41 -0800, [EMAIL PROTECTED] (Egil M?ller) wrote:
>
> >Is there any way to create transparent wrapper objects in Python?
> >
> >I thought implementing __getattribute__ on either the wrapper class
or
> >its metaclass would do the trick, but it does not work for the built
> >in operators:
> >
> >class Foo(object):
> >class __metaclass__(type):
> >def __getattribute__(self, name):
> >print "Klass", name
> >return type.__getattribute__(self, name)
> >def __getattribute__(self, name):
> >print "Objekt", name
> >return object.__getattribute__(self, name)
> >
> >
>  Foo() + 1
> >Traceback (most recent call last):
> >  File "", line 1, in ?
> >TypeError: unsupported operand type(s) for +: 'Foo' and 'int'
>  Foo().__add__(1)
> >Objekt __add__
> >Traceback (most recent call last):
> >  File "", line 1, in ?
> >  File "", line 8, in __getattribute__
> >AttributeError: 'Foo' object has no attribute '__add__'
> >
> >
> >Thus, note that a + b does not do
> >
> >try:
> >return a.__add__(b)
> >except:
> >return b.__radd__(a)
> >
> >and neither, as I first thought
> >
> >try:
> >return type(a).__add__(a, b)
> >...
> >
> >but something along the lines of
> >
> >try:
> >return type.__getattribute__(type(a), '__add__')(a, b)
> >...
> >
> >
> >So my naive implementation of a wrapper class,
> >
> >
> >class wrapper(object):
> >def __init__(self, value, otherdata):
> >self.value = value
> >self.otherdata = otherdata
> >def __getattribute__(self, name):
> >return getattr(self.value, name)
> >
> >
> >does not work. Any ideas for a solution?
>
> This seems to go some way towards it:
>
>  >>> class MethodDesc(object):
>  ... def __get__(self, inst, cls=None):
>  ... if inst is None: return self
>  ... func = self.__dict__['func']
>  ... if func: return func.__get__(self.thing,
type(self.thing))
>  ... else: return getattr(self.thing, self.name)
>  ... def __init__(self, name, thing, func):
>  ... self.name = name
>  ... self.thing = thing
>  ... self.func = func
>  ... def __call__(self, *args, **kw): print 'called %s: %r
%r'%(self.name, args, kw)
>  ...
>  >>> def wrapit(thing, *otherdata):
>  ... class Wrapper(object):
>  ... def __metaclass__(cname, cbases, cdict):
>  ... for name, func in type(thing).__dict__.items():
>  ... if callable(func):
>  ... if name not in [
>  ... '__getattr__', '__getattribute__',
'__setattr__',
>  ... '__new__', '__init__']:
>  ... cdict[name] = MethodDesc(name,
thing, func)
>  ... else:
>  ... cdict[name] = MethodDesc(name, thing, None)
>  ... return type(cname, cbases, cdict)
>  ... def __init__(self, *otherdata):
>  ... if otherdata: self.otherdata = otherdata
>  ... def __getattr__(self, name):
>  ... raise AttributeError('Wrapped %r object has no
attribute %r'% (type(self).__name__, name))
>  ... Wrapper.__name__ = 'Wrapped_'+type(thing).__name__
>  ... return Wrapper(*otherdata)
>  ...
>  >>> class Demo(object):
>  ... a = 'eigh'
>  ... two = 2
>  ... def foo(self): return 'Demo foo'
>  ... def bar(self, *args, **kw): print 'Demo bar %r %r'%(args,
kw)
>  ...
>  >>> o2 = wrapit( Demo(), 'stuff')
>  >>> o2.foo
>  >
>  >>> o2.foo()
>  'Demo foo'
>  >>> o2.bar(1,2,3,x=111,y=222)
>  Demo bar (1, 2, 3) {'y': 222, 'x': 111}
>  >>> o2.a
>  'eigh'
>  >>> o2.two
>  2
>  >>> o2.z
>  Traceback (most recent call last):
>File "", line 1, in ?
>File "", line 16, in __getattr__
>  AttributeError: Wrapped 'Wrapped_Demo' object has no attribute 'z'
>  >>> o2.z = 'zee'
>  >>> o2.z
>  'zee'
>  >>> o2
>  
>  >>> o2.a = 'not eigh'
>  >>> o2.a
>  'not eigh'
>  >>> del o2.a
>  >>> o2.a
>  'eigh'
>  >>> o3 = wrapit('strange', 'stuff')
>  >>> o3
>  'strange'
>  >>> o3.otherdata
>  ('stuff',)
>  >>> o3[2:]
>  'range'
>  >>>
>  >>> o3.z
>  Traceback (most recent call last):
>File "", line 1, in ?
>File "", line 16, in __getattr__
>  AttributeError: Wrapped 'Wrapped_str' object has no attribute 'z'
>
> Not tested beyond what you see ;-) This doesn't wrap setting
attributes on the wrapped object,
> so setting attributes sets them on the wrapper itself, but that could
be fixed.
>
> Now what was it you wanted to use a wrapper for? ;-)
> Note:
>
>  >>> o3 += 'fail'
>  >>> o3
>  'strangefail'
>  >>> type(o3)
>  
>
> So if you want new wrapped instances as results from various ops, we
need some more code ;-)
> Another time ... (cf. a recent post of mine re wrapping complex as a
point type).
>
> Regards,
> Bengt Richter


Ah, thanks. I didn't think of the possibility of creating a list of
methods that needed wrapping, and wrapping them uppon creation of

Re: Tibia 0.1 DOM-based website editor

2004-12-10 Thread Dirkjan Ochtman
Stick the single tibia.tba file on your webserver (assuming Python is
installed) and you're off and editing files in the same folder or below.
Admins can edit any element; non-admins can edit any element for which
admins give them permission.
- Stuck in /var/www/localhost/cgi-bin/
- Changed permissions to 755
- Renamed to tibia.cgi
... 500 Internal Server Error.
I don't have a lot of experience with CGI, though, so any help would be 
welcome.

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


Re: MySQLdb blob and binary data

2004-12-10 Thread Denis S. Otkidach
On Fri, 10 Dec 2004 16:58:56 +0100
Rune Hansen <[EMAIL PROTECTED]> wrote:

> I'm storing gzipped data in a MySQL blob field. I can fetch the blob and 
> "wb" write the data to a file. It becomes a file containg gz data.
> 
> I can't take the same data and do anything sensible with it in python - 
> like say zlib.decompress(data).
> 
> How can I convert the binary data from the blob field to the gzipped 
> string it was stored as (java stores the string, Pickle is not an option)?

You can pass any file-like object to GzipFile class:

from gzip import GzipFile
from cStringIO import StringIO
GzipFile(fileobj=StringIO(data)).read()

-- 
Denis S. Otkidach
http://www.python.ru/  [ru]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: style query: function attributes for return codes?

2004-12-10 Thread holger krekel
Hi George, 

[george young Fri, Dec 10, 2004 at 10:45:47AM -0500]
> [python 2.3.3, x86 linux]
> I recently found myself writing something like:
> 
> def get_connection():
> if tcp_conn():
> if server_allows_conn():
> return 'good_conn'
> else:
> return 'bad_auth'
> else:
> return 'no_server'
> 
> cn = get_connection()
> if cn == 'good_con': ...
> 
> 
> This is obviously just evil, since a misspelling in the string
> return is treacherous.

Right. 

I usually like to look at such problems from the angle of 
what is most convenient for the *caller* side? 

And having to adress function attributes does
not seem convenient.  I'd probably like to do from 
the caller side something like: 

conn = get_connection() 
if conn.good: 
... 
elif conn.badauth: 
... 
elif conn.noserver: 
... 

which allows you to freely choose and hide your actual
implementation at the "called" side. Example: 

class Connection(object): 
def __init__(self, **kw): 
for name in kw: 
assert name in ('good', 'badauth', 'noserver'), name 
setattr(self, name, kw[name]) 

def get_connection():
if tcp_conn():
if server_allows_conn():
return Connection(good=True) 
else:
return Connection(badauth=True) 
else:
return Connection(noserver=True) 
 
And btw, the view of "what do i want at the caller side?" 
is natural if you do test-driven development and actually 
first write your tests.  Another reason why testing is 
a good thing :-) 

cheers & HTH, 

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


Re: Blank ASP pages

2004-12-10 Thread ElCapitan
I have same exact problem and get the sourcecode right back (asp source
code) when i right click page and view source code. Not sure what
server they are using this is not in my company.
Thanks in advance

Gordon McMillan wrote:
> Jason S. Nadler wrote:
>
> > My server is spitting out blank .asp pages which use python. If
Python is
> > not declared, the asp pages work fine.
> > I just yesterday stepped up to Python 1.52 and the new win32all
> > After the install, the blanks started appearing.
> > All the paths look fine in registry.
> > Any clues?
>
> You've asked before, and got no replies, so it's safe to say
> this is not a common problem among the asp users. So you'll
> need to go into more detail.
>
> What's a "blank page"? One with nothing between 
> and ? What does view -> source show you in a
> browser?
>
> Can you tell (from logs or whatever) that the Python scripts
> are getting run?
>
> Have you tried setting the debug flag on the components and
> running with the Trace Collector?
>
> (I know nothing about asp, so I won't be able to help).
> 
> 
> 
> - Gordon

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


RE: Tibia 0.1 DOM-based website editor

2004-12-10 Thread Robert Brewer
Gabriel Cooper wrote:
> Robert Brewer wrote:
> 
> >[...]
> >Tibia is an in-browser editor for web pages. It allows you to quickly
> >and easily modify the content of your web pages. 
> >[...]
> >
> I couldn't get it to work using Firefox on Red Hat Fedora 
> Core 2. From 
> what I garnered from the help you're supposed to be able to 
> double-click 
> on any page element with a big block-border around it, right? If so, 
> nothing happened for me. :(

I assume you're using the demo? My copy of Firefox has an error browser
under Tools->Javascript Console. Does the double-click report any error
there? Make sure you clear the list before trying, since errors from all
other webpages gt dumped in the same list.

Thanks for the feedback!


Robert Brewer
MIS
Amor Ministries
[EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list


Compiling Python 2.4 extensions with free VC++ Toolkit

2004-12-10 Thread Burns
Hi all,
I've been wondering if there's anything on the drawing board about 
patching distutils/msvccompiler.py so that it can compile Python 
extensions using the free Visual C++ toolkit instead of the entire 
Visual C++ development environment.

I know it's possible, because I was able to compile and install PyCrypto 
2.0 for Python 2.4 today.  I did this by commenting out the part of 
msvccompiler that checks for VS library paths and manually adding them 
to my LIB environment variable.

I looked through the CVS and couldn't find anything about this, although 
 msvccompiler.py has been patched to give a better error message about 
requiring the .NET framework if you have don't have it installed.

Your thoughts?
--Jody
--
http://mail.python.org/mailman/listinfo/python-list


RE: tibia error in apache2

2004-12-10 Thread Robert Brewer
>From tibia log file:
2004-12-10 16:05:56,322 ERROR None: GET frameset
Traceback (most recent call last):
  File "C:\PYTHON23\lib\site-packages\tibia.py", line 997, in __init__
self.username = self.username.split("\\")[-1]
AttributeError: 'NoneType' object has no attribute 'split'
2004-12-10 16:05:57,102 ERROR None: GET logo
Traceback (most recent call last):
  File "C:\PYTHON23\lib\site-packages\tibia.py", line 997, in __init__
self.username = self.username.split("\\")[-1]
AttributeError: 'NoneType' object has no attribute 'split'
2004-12-10 16:05:57,102 ERROR None: GET logo
Traceback (most recent call last):
  File "C:\PYTHON23\lib\site-packages\tibia.py", line 997, in __init__
self.username = self.username.split("\\")[-1]
AttributeError: 'NoneType' object has no attribute 'split'



You need to use some sort of authentication with Tibia, or it can't tell
who's an admin and who's not. The demo uses Basic Auth. Add something like
the following to your .conf for the tibia folder:

AuthType Basic
AuthName "Tibia"
AuthUserFile D:\htdocs\tibia\passwords
Require valid-user

...and then use htpasswd to create the passwords file.

I will look into ways to use Tibia without auth, for intranets, perhaps.
Thanks!


Robert Brewer
MIS
Amor Ministries
[EMAIL PROTECTED]

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


Re: Python + Newspipe

2004-12-10 Thread Peter Hansen
kael wrote:
Dave Kuhlman wrote:
3. It's looking for a section named "NewsPipe" in your
   options/config file.  Check your config file.  Is that
   section name misspelled?  Is the section missing?  Does
   the NewsPipe documentation tell you where the config file
   should be and what it's name is?  If not, look in newspipe.py.
According to the Newspipe documentation 
http://newspipe.sourceforge.net/#configuration, only the 'smtp_server' 
and 'opml' lines are absolutely needed in newspipe.py.

Please, see newspipe.py below:
--
[NewsPipe]
log_console=1
smtp_server=smtp.free.fr
opml=test.opml
sleep_time=30
check_online=http://www.google.com
--
You are misreading something.  On the page you referenced above,
it clearly states in "Installation" that the file in question
is named "newspipe.ini", not "newspipe.py".  You are confusing
the two, since what you show above is not "newspipe.py" or,
if it is, somebody has messed up...
newspipe.py should contain Python code, newspipe.ini should
contain configuration info like you show above.
If you *have* a newspipe.ini file that contains the above,
but are still getting the error message you reported earlier,
then the program is not *finding* your newspipe.ini file and
you should probably contact the author(s) for assistance,
since this is not a Python issue.
-Peter
--
http://mail.python.org/mailman/listinfo/python-list


Re: Compiling Python 2.4 extensions with free VC++ Toolkit

2004-12-10 Thread Peter Hansen
Jody Burns > wrote:
I've been wondering if there's anything on the drawing board about 
patching distutils/msvccompiler.py so that it can compile Python 
extensions using the free Visual C++ toolkit instead of the entire 
Visual C++ development environment.

I know it's possible, because I was able to compile and install PyCrypto 
2.0 for Python 2.4 today.  I did this by commenting out the part of 
msvccompiler that checks for VS library paths and manually adding them 
to my LIB environment variable.

I looked through the CVS and couldn't find anything about this, although 
 msvccompiler.py has been patched to give a better error message about 
requiring the .NET framework if you have don't have it installed.

Your thoughts?
None, other than to note that if you and/or others were able to
solve this and make it "easy" for those less VC++-savvy, you
might significantly decrease the bar for those of us who have
not been able to get into hacking on the core of Python because
of being stuck in the MS world yet not willing to shell out more
cash to billg...  maybe, just maybe, that would get a few more
people out there reviewing patches and maybe fixing bugs.
-Peter
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python + Newspipe

2004-12-10 Thread kael
Peter Hansen wrote:
kael wrote
Dave Kuhlman wrote:
3. It's looking for a section named "NewsPipe" in your
  options/config file.  Check your config file.  Is that
  section name misspelled?  Is the section missing?  Does
  the NewsPipe documentation tell you where the config file
  should be and what it's name is?  If not, look in newspipe.py.
According to the Newspipe documentation 
http://newspipe.sourceforge.net/#configuration, only the 'smtp_server' 
and 'opml' lines are absolutely needed in newspipe.py.

Please, see newspipe.py below:
--
[NewsPipe]
log_console=1
smtp_server=smtp.free.fr
opml=test.opml
sleep_time=30
check_online=http://www.google.com
--
You are misreading something.  On the page you referenced above,
it clearly states in "Installation" that the file in question
is named "newspipe.ini", not "newspipe.py".  You are confusing
the two, since what you show above is not "newspipe.py" or,
if it is, somebody has messed up...
Sorry. The lines above are from *newspipe.ini* not newspipe.py. Thanks 
for pointing the confusion.

newspipe.py should contain Python code, newspipe.ini should
contain configuration info like you show above.
If you *have* a newspipe.ini file that contains the above,
but are still getting the error message you reported earlier,
then the program is not *finding* your newspipe.ini file and
you should probably contact the author(s) for assistance,
since this is not a Python issue.
I'm going to contact him. Thank you very much for your reply.
Cheers.
--
kael
@829 .beats, 2004-12-10
--
http://mail.python.org/mailman/listinfo/python-list


Re: style query: function attributes for return codes?

2004-12-10 Thread Steven Bethard
Robert Kern wrote:
Steven Bethard wrote:
Sorry, I also meant to add that the other obvious way of dealing with 
this kind of thing is to make the results keyword parameters:

def get_connection(GOOD=1, BAD_AUTH=2, NO_SERVER=3):
if tcp_conn():
if server_allows_conn():
return GOOD
else:
return BAD_AUTH
else:
return NO_SERVER
This has the benefit that if your user wants different return values 
they can specify them, but the disadvantage that someone improperly 
calling the function with more than 0 parameters will get, instead of 
an error message, a strange return value.

Another disadvantage is that one must compare the return value by value 
and not by name. That is, I cannot do something like this:

code = get_connection()
if code == NO_SERVER:
...
Good point.  The class-type implementation does allow you to do this:
>>> class get_connection(object):
... GOOD = 1
... BAD_AUTH = 2
... NO_SERVER = 3
... def __new__(cls):
... if tcp_conn():
... if server_allows_conn():
... return cls.GOOD
... else:
... return cls.BAD_AUTH
... else:
... return cls.NO_SERVER
...
>>> get_connection.GOOD
1
>>> get_connection.BAD_AUTH
2
>>> get_connection.NO_SERVER
3
Steve
--
http://mail.python.org/mailman/listinfo/python-list


[Newby] question about modules

2004-12-10 Thread Jon
Hi,

The following four lines of code:

import sys, os, re
sentence = raw_input("Enter a sentence:  ")
capwords (sentence)
print sentence

gives me the following error:  NameError: name 'capwords' is not defined

As far as I can tell from the online docs, "capwords" should be defined in
the built-in "regex" module.  Why is it telling me that capwords is not
defined?

I am completely new to Python so my apologies for such a basic question!

Thanks,
Jon


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


Re: Possible to insert variables into regular expressions?

2004-12-10 Thread Terry Hancock
On Thursday 09 December 2004 03:51 pm, Chris Lasher wrote:
> Thanks for the reply, Steve! That ought to work quite nicely! For some
> reason, I hadn't thought of using %-formatting. I probably should have,
> but I'm still learning Python and re-learning programming in general.
> This helps a lot, so thanks again.

Remember, in Python, a regex (well, regex source) is just a string, so
you can do any string manipulation you want to with it, and python has
a lot of tools for doing that.

One cool way to make regexes more readable, that i've seen proposed,
is to break them into components like the following (please pardon my
lack of regex skill, these may not actually work , but you get the idea):

normalword  = r'[A-Za-z][a-z]*'
digit   = r'\d'
capletter   = r'[A-Z]'

codeblock = normalword + 4*digit + '-' + 3*digit + 2*capletter + '\s+' + 
normalword

or somesuch (the 'r' BTW stands for 'raw', not 'regex', and while it's the most
obvious use, there's nothing particularly special about r strings, except for
not trying to process escape characters, thus avoiding the "pile of toothpicks"
problem).

And hey, you could probably use a regex to modify a regex, if you were
really twisted. ;-)

Sorry.  I really shouldn't have said that. Somebody's going to do it now. :-P

Cheers,
Terry

--
Terry Hancock ( hancock at anansispaceworks.com )
Anansi Spaceworks  http://www.anansispaceworks.com

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


Re: thread/queue bug

2004-12-10 Thread Peter Hansen
phil wrote:
I have a very strange bug.  A thread in a .pyc stops dead.
This program has many threads and queues and has worked
great for months.
One thread listens for UDP messages from other programs,
and puts the messages in listenq.
Procmsgs gets from listenq and for a certain kind of
message creates another mq = Queue(0).
I don't wish to distribute the source to pnetx.py
so I have a short program pnet.py import it, that is
pnetx.pyc.
Then the procmsgs thread dies at the Queue statement.
But if I run pnetx.py as the main program, all works fine.
So if pnetx.py or .pyc is imported this thread dies. ???
I've tried this with 2.3.3 and 2.3.4.  Anyone?
A few random thoughts:
1. You haven't provided nearly enough info for anyone
to be able to help much, I suspect.
2. Threading problems can be incredibly complex and race
conditions are frequently next to impossible to troubleshoot,
let alone reproduce reliably.
3. Distributing a .pyc does very little to prevent someone
from getting your source, since it is possible to "decompile"
.pyc files into something fairly closely resembling the
original source.
4. The fact that you have a .pyc file instead of a .py
file very likely has *nothing* to do with any threading
problem you are facing, so I suggest you get past that mental
block and look elsewhere.
5. Sorry I can't be more help.  You don't give anyone much
to go on.  All that stuff about "Queue(0)" and "listenq"
is pretty much meaningless to us, you know...
-Peter
--
http://mail.python.org/mailman/listinfo/python-list


RE: Blank ASP pages

2004-12-10 Thread Robert Brewer
ElCapitan wrote:
> Gordon McMillan wrote:
> > Jason S. Nadler wrote:
> >
> > > My server is spitting out blank .asp pages which use python. If
> Python is
> > > not declared, the asp pages work fine.
> > > I just yesterday stepped up to Python 1.52 and the new win32all
> > > After the install, the blanks started appearing.
> > > All the paths look fine in registry.
> > > Any clues?
> >
> > You've asked before, and got no replies, so it's safe to say
> > this is not a common problem among the asp users. So you'll
> > need to go into more detail.
> >
> > What's a "blank page"? One with nothing between 
> > and ? What does view -> source show you in a
> > browser?
> >
> > Can you tell (from logs or whatever) that the Python scripts
> > are getting run?
> >
> > Have you tried setting the debug flag on the components and
> > running with the Trace Collector?
>
> I have same exact problem and get the sourcecode right back 
> (asp source
> code) when i right click page and view source code. Not sure what
> server they are using this is not in my company.

I've run into this a couple of times. Often, setting the default ASP
language to Python is the trick.
Internet Services Manager->Site->Folder->Properties->Configuration->App
Options->Default ASP Language.


Robert Brewer
MIS
Amor Ministries
[EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list


Re: collaborative editing

2004-12-10 Thread A.M. Kuchling
On 10 Dec 2004 05:20:42 -0800, 
Michele Simionato <[EMAIL PROTECTED]> wrote:
> welcome. Does something like that already exists? Alternatively, I would need
> some hierarchical Wiki with the ability of printing its contents in an
> structured way. 

At least one book, Eric van der Vlist's RELAX NG book, was written using a
Wiki; see http://books.xmlschemata.org/relaxng/pr01s05.html/ .

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


Yahoo! Auto Response

2004-12-10 Thread plegend2001
THIS IS AN AUTO-RESPONSE SYSTEM FOR PLEGEND2001

We are experiencing an unusual high-volume of e-mail.  For questions, please 
click the link for FAQ page:
http://members.ebay.com/ws2/eBayISAPI.dll?ViewUserPage&userid=plegend2001

If you have receive a tracking number, please allow FedEx,UPS,or DHL 72 
business hours to update the system.  

for FASTER RESPONSE or questions, please call us at 909-595-1150 We are here 
M~F 9:00A.M.~5:00 P.M. PST.  WE DO NOT WORK ON WEEKENDS NOR HOLIDAYS. SENDING 
MULTIPLE MAILS WILL NOT SPEED UP THE REPLY PROCESS, HOWEVER IT MIGHT DELAY YOUR 
REPLY.

Thank you for your understanding and sorry for the inconvenience that we may 
have caused!




Original Message:


X-YahooFilteredBulk: 64.151.34.242
Authentication-Results: mta134.mail.dcn.yahoo.com
  from=python.org; domainkeys=neutral (no sig)
X-Originating-IP: [64.151.34.242]
Return-Path: <[EMAIL PROTECTED]>
Received: from 64.151.34.242  (EHLO yahoo.com) (64.151.34.242)
  by mta134.mail.dcn.yahoo.com with SMTP; Fri, 10 Dec 2004 11:09:35 -0800
From: [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Subject: Hi
Date: Thu, 9 Dec 2004 13:15:36 -0600
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary="=_NextPart_000_0012_7F17.1F9F"
X-Priority: 1
X-MSMail-Priority: High

This is a multi-part message in MIME format.

--=_NextPart_000_0012_7F17.1F9F
Content-Type: text/plain;
charset="Windows-1252"
Content-Transfer-Encoding: 7bit

Important details!


--=_NextPart_000_0012_7F17.1F9F
Content-Type: application/octet-stream;

_
DO YOU YAHOO!?
Get your free @yahoo.com address at http://mail.yahoo.com

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


Re: Wrapper objects

2004-12-10 Thread Bengt Richter
On 10 Dec 2004 09:33:51 -0800, [EMAIL PROTECTED] wrote:

>Bengt Richter wrote:
>> On 9 Dec 2004 06:11:41 -0800, [EMAIL PROTECTED] (Egil M?ller) wrote:
>>
>> >So my naive implementation of a wrapper class,
>> >
>> >
>> >class wrapper(object):
>> >def __init__(self, value, otherdata):
>> >self.value =3D value
>> >self.otherdata =3D otherdata
>> >def __getattribute__(self, name):
>> >return getattr(self.value, name)
>> >
>> >
>> >does not work. Any ideas for a solution?
>>
>> This seems to go some way towards it:
>>
[snip ugly wrapper hack]
>> Not tested beyond what you see ;-) This doesn't wrap setting
>attributes on the wrapped object,
>> so setting attributes sets them on the wrapper itself, but that could
>be fixed.
>>
>> Now what was it you wanted to use a wrapper for? ;-)
[...]
>
>
>Ah, thanks. I didn't think of the possibility of creating a list of
>methods that needed wrapping, and wrapping them uppon creation of the
>wrapper object. Mainly I think, becaus it seems to me as such an uggly
>workaround for a misdesign in Python. Also, if the wrapped object gets
It is ugly. I am not satisfied with it, but I wanted to offer some
experimental results that might be useful (if only to decide not to
go that way ;-)
>some extra methods/callable member variables added "after the fact",
>those will not get wrapped (this is however not a common thing to
>happen, it just annoys me that it won't work).
Well, that could be a feature, depending on what your use case is.
Or you could make a method for adding methods, I suppose.
A perfectly transparent wrap of obj would be to do nothing ;-)
What do you actually want to do?
>
>However, I do have some questions about your implementation:
>
>If "if inst is None: return self" to protect for infinite recursion
>when looking up self.__dict__?
What self are you referring to? Anyway, inst is None when you access
a descriptor instance as a class attribute, e.g., MyClass.desc as opposed
to as an attribute of an instance of that class, e.g., MyClass().desc.
Even __dict__ is actually itself a descriptor. Try
type(obj).__dict__['__dict__'].__get__ (on a new style obj instance).
vs type(obj).__dict__.__get__ which doesn't work.

>
>What is the reason to give func to the MethodDesc property object, why
>does its __get__ method have to do
>
>if func: return func.__get__(self.thing, type(self.thing))
>
>?
This is to create a bound method that's bound to the thing, not to the
wrapper object. I guess this could be done at wrapping time instead.
I was just hacking down the path of least resistance ;-)

>
>What is the reason to neither wrap, nor just copy, any of __getattr__,
>__getattribute__, __setattr__, '__new__' or '__init__'? Especially
>__getattr__, __getattribute__ and __setattr__ seems to need at least
>some type of wrapping (but perheaps some special one)?
Sorry, this was to eliminate some problems I had along the way. But __new__
and __init__ have to be kept out of the Wrapper class or they will be
invoked when Wrapper() is done to create the wrapped object.

I have hacked something better, not using def __metaclass__, which isn't
necessary. (I just prepare a cdict similarly, and then use that in
 
Wrapper = type('Wrapped_'+type(thing).__name__, (object,), cdict)

plus playing games to avoid the wrong __init__ and __new__ etc.) 

Also, I just remembered an idea that someone had used to limit
methods in an attempt at security by assigning obj.__class__ with a
compatible class. So that might be an avenue too. Maybe a wrapper could
be a subclass of type(obj), and then just copy method function references
to the wrapper class dict? I'll have to explore that another time...

What is your actual use case? ;-)

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


Re: 2D array

2004-12-10 Thread Adam DePrince
On Wed, 2004-12-08 at 16:22, Steven Bethard wrote:
> Adam DePrince wrote:
> > The use of  None as the default parameter was on purpose; the lack of
> > "magic" in python is often cited in religious wars between python and
> > perl aficionados.  Use of get(something, None) was on purpose, the level
> > of familiarity with the language implied by the original question
> > suggested that the notion of optional parameters, and specifically those
> > of get, may not have been immediately obvious.
> > 
> > As for a[0,0] instead of a[(0,0)] ... the former just *looks* so
> > aesthetically wrong to me that I've never used it, and had forgotten
> > that it was even possible.   
> 
> Sorry, I hadn't meant any of my comments as criticisms -- just wanted to 
> make sure the OP knew about all the options open to them.  I'm used to 
> a[0,0] because I've used numarray a bit, but to each his own, of course. =)

Even if you were, there is certainly no need to apologize.  In
hindsight, my response seems rather naive; as naive perhaps as the
students in my freshman year undergrad C class who having grown up on
Turbo pascal would add to their programs:

#define BEGIN {
#define END {

because it "looked right." 


Adam DePrince 


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


Re: Fun with Outlook and MAPI

2004-12-10 Thread Will McGugan
Chris wrote:
I'm trying to send an e-mail through outlook.  So far I've gotten it to 
work with the mail script at 
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/149461  My only 
problem is that when I call Resolve() and Send(), I get confirmation 
dialogs.  I will be sending out quite a few e-mails at a time, and would 
rather not have the user have to click yes for every single one.  Does 
anyone know a workaround?  I know about smtplib, but I would prefer to 
simply make what I have work.  Thanks.
Alas, I dont think that there is much you can do to prevent the 
confirmation dialogs with Outlook's MAPI dll. MS added them in a service 
pack as an anti-virus measure, so no work-around. Not all clients show 
these anoying dialogs though. Thunderbird definately doesn't.

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


Re: Find Items & Indices In A List...

2004-12-10 Thread Bengt Richter
On Fri, 10 Dec 2004 16:27:29 GMT, Steven Bethard <[EMAIL PROTECTED]> wrote:

>[EMAIL PROTECTED] wrote:
>> Hello NG,
>> 
>>   I was wondering if there is a faster/nicer method (than a for loop)
>> that will allow me to find the elements (AND their indices) in a list that
>> verify a certain condition. For example, assuming that I have a list like:
>> 
>> mylist = [0, 1, 1, 1, 1, 5, 6, 7, 8, 1, 10]
>> 
>> I would like to find the indices of the elements in the list that are equal
>> to 1 (in this case, the 1,2,3,4,9 elements are equal to 1). I could easily
>> use a for loop but I was wondering if there is a faster method...
>
>Everyone has already given you the answer (enumerate in a LC or GE), I'd 
>just comment that it's easy enough to extend their answers to any given 
>condition:
>
> >>> def getindices(sequence, predicate):
>...return [i for i, v in enumerate(sequence) if predicate(v)]
>...
> >>> getindices([0,1,1,1,1,5,6,7,8,1,10], bool)
>[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
> >>> def equalsone(v):
>...return v == 1
>...
> >>> getindices([0,1,1,1,1,5,6,7,8,1,10], equalsone)
>[1, 2, 3, 4, 9]
> >>> def f(v):
>...return pow(v, 3, 4) == 3
>...
> >>> getindices([0,1,1,1,1,5,6,7,8,1,10], f)
>[7]
>
Conclusion:
Python is programmer's Lego ;-)

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


Re: Possible to insert variables into regular expressions?

2004-12-10 Thread Steven Bethard
Terry Hancock wrote:
And hey, you could probably use a regex to modify a regex, if you were
really twisted. ;-)
Sorry.  I really shouldn't have said that. Somebody's going to do it now. :-P
Sure, but only 'cause you asked so nicely. =)
>>> import re
>>> def internationalize(expr,
...  letter_matcher=re.compile(r'\[A-(?:Za-)?z\]')):
... return letter_matcher.sub(r'[^\W_\d]', expr)
...
>>> def compare(expr, text):
... def item_str(matcher):
... return ' '.join(matcher.findall(text))
... print 'reg: ', item_str(re.compile(expr))
... print 'intl:', item_str(re.compile(internationalize(expr),
...re.UNICODE))
...
>>> compare(r'\d+\s+([A-z]+)', '1 viola. 2 voilà')
reg:  viola voil
intl: viola voilà
>>> compare(r'\d+\s+([A-Za-z]+)', '1 viola. 2 voilà')
reg:  viola voil
intl: viola voilà
This code converts [A-z] style regexps to a regexp that is suitable for 
use with other encodings.  Note that without the conversion, characters 
like 'à' are not found.

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


Re: Fun with Outlook and MAPI

2004-12-10 Thread David Fraser
Will McGugan wrote:
Chris wrote:
I'm trying to send an e-mail through outlook.  So far I've gotten it 
to work with the mail script at 
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/149461  My 
only problem is that when I call Resolve() and Send(), I get 
confirmation dialogs.  I will be sending out quite a few e-mails at a 
time, and would rather not have the user have to click yes for every 
single one.  Does anyone know a workaround?  I know about smtplib, but 
I would prefer to simply make what I have work.  Thanks.

Alas, I dont think that there is much you can do to prevent the 
confirmation dialogs with Outlook's MAPI dll. MS added them in a service 
pack as an anti-virus measure, so no work-around. Not all clients show 
these anoying dialogs though. Thunderbird definately doesn't.


There is actually a workaround. You're using Simple MAPI which has a 
nice easy interface. The confirmation dialogs are only for Simple MAPI. 
Using Extended MAPI can work around the problem but its a lot more tricky.
See the initial discussion here: 
http://aspn.activestate.com/ASPN/Mail/Message/Python-win32/2160646

This code has now been included in pywin32 somehow but I can't remember 
where and its late. Should also be a cookbook entry. Maybe Google can 
help :-)

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


Re: [Newby] question about modules

2004-12-10 Thread James Stroud
Is it in "regex" or "re"? If in "re" then:

re.capwords(sentence)

If in "regex", then:

regex.capwords(sentence)


You can also do

from re import *

then you will not have to prefix. But careful not to clutter your namespace.

On Friday 10 December 2004 10:29 am, Jon wrote:
> Hi,
>
> The following four lines of code:
>
> import sys, os, re
> sentence = raw_input("Enter a sentence:  ")
> capwords (sentence)
> print sentence
>
> gives me the following error:  NameError: name 'capwords' is not defined
>
> As far as I can tell from the online docs, "capwords" should be defined in
> the built-in "regex" module.  Why is it telling me that capwords is not
> defined?


-- 
James Stroud, Ph.D.
UCLA-DOE Institute for Genomics and Proteomics
611 Charles E. Young Dr. S.
MBI 205, UCLA 951570
Los Angeles CA 90095-1570
http://www.jamesstroud.com/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: question about modules

2004-12-10 Thread Jon
Hi Jeff,

That makes sense -- thanks.  However now when I use "re.capwords (sentence)"
I get a different error message:

AttributeError: 'module' object has no attribute 'capwords'

Each of the other two suggested implimentations produce a similar error
message.  Is there something even more basic that I am failing to do?  I'm
using the IDLE GUI in WinXP, Python release 2.4...

Thanks!
Jon


"Jeffrey Maitland" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Jon writes:
>
> > Hi,
> >
> > The following four lines of code:
> >
> > import sys, os, re
> > sentence = raw_input("Enter a sentence:  ")
> > capwords (sentence)
> > print sentence
> >
> > gives me the following error:  NameError: name 'capwords' is not defined
> >
> > As far as I can tell from the online docs, "capwords" should be defined
in
> > the built-in "regex" module.  Why is it telling me that capwords is not
> > defined?
> >
> > I am completely new to Python so my apologies for such a basic question!
> >
> > Thanks,
> > Jon
> >
> >
> > -- 
> > http://mail.python.org/mailman/listinfo/python-list
>
> Hello Jon,
>
> The reason for that is you only imported the module(class/object) now to
use
> its methodes you need to call the object.
>
> in this case to fix the problem you are having you would have to do it
> either one of these methodes (unless there are more that I am not aware
of)
> 1/
> import sys, os, re
> sentence = raw_input("Enter a sentence:  ")
> re.capwords (sentence) # <-- notice the re.capwords this
>   # calling the capword method of the re module.
> print sentence
>
> 2/
> import sys, os
> from re import * # < import all methods of re and allow them to be
> #   used locally
> sentence = raw_input("Enter a sentence:  ")
> capwords (sentence)
> print sentence
> # this imports all the methodes in the re module so they can be used
> # localy.
>
> or
> import sys, os
> from re import capwords  # < import only capwords method of re
> sentence = raw_input("Enter a sentence:  ")
> capwords (sentence)
> print sentence
> # this import only imports the capwords methode of the re module
>
>
> I hope this helps you some and if i used the incorrect terminology I am
> sorry and I hope someone points it out to me.
>
> Jeff Maitland


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


Re: UrlLib2 Proxy and Https

2004-12-10 Thread Tom
I would like to access an HTTPS site via a proxy
The following code is working for HTTP://www.hotmail.com but not for HTTPS
I have try with other sites without success
  l_proxy_info = {
 'user' : mylogin,
 'pass' : mypassword,
 'host' : myproxy,
 'port' : 8080
  }
I have no idea if this is your problem, but you are aware that https is 
usually on port 443, not 80 or 8080 like http?

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


thread/queue bug

2004-12-10 Thread phil
> 4. The fact that you have a .pyc file instead of a .py
> file very likely has *nothing* to do with any threading
> problem you are facing, so I suggest you get past that mental
> block and look elsewhere.
Well, I tried to make it clear that the ONLY difference between
working and not working was the pnetx.pyc when imported did not
work when
#!/usr/bin/python
# pnet.py, exists only to import pnetx.py
import pnetx.py
Otherwise the program has worked fine for months.
I don't think its a mental block, its the ONLY difference.
It freezes on the following statement:
mq = Queue(0)
and I haven't a clue why.  All the other threads continue to run.
> 5. Sorry I can't be more help.  You don't give anyone much
> to go on.  All that stuff about "Queue(0)" and "listenq"
> is pretty much meaningless to us, you know...
You know, I get this all the time on language support groups.
All of my Linux support groups, if they don't understand, say
why and ask for elaboration.  I tried to explain what was going on,
without incuding the source.  I have about 200 man hours in the source
and I bet it would take longer to understand it.
If my explanation was insufficient, I'm sorry.
ALSO, you did not respond to my email, so I didn't know how to reply.
There is nothing on the archives page which gives me a clue as to
how to respond.
SO, if there is ZERO chance there is some sort of inadvertent lock
occuring in saved byte code, I just kludge around and move on.
Maybe 2.4
Thanks.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Fun with Outlook and MAPI

2004-12-10 Thread Will McGugan
David Fraser wrote:
Alas, I dont think that there is much you can do to prevent the 
confirmation dialogs with Outlook's MAPI dll. MS added them in a 
service pack as an anti-virus measure, so no work-around. Not all 
clients show these anoying dialogs though. Thunderbird definately 
doesn't.


There is actually a workaround. You're using Simple MAPI which has a 
I stand corrected.
Will McGugan
--
http://mail.python.org/mailman/listinfo/python-list


Re: Fun with Outlook and MAPI

2004-12-10 Thread Chris
Will McGugan wrote:
I'm trying to send an e-mail through outlook.  So far I've gotten it 
to work with the mail script at 
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/149461  My 
only problem is that when I call Resolve() and Send(), I get 
confirmation dialogs.  I will be sending out quite a few e-mails at a 
time, and would rather not have the user have to click yes for every 
single one.  Does anyone know a workaround?  I know about smtplib, but 
I would prefer to simply make what I have work.  Thanks.
Alas, I dont think that there is much you can do to prevent the 
confirmation dialogs with Outlook's MAPI dll. MS added them in a service 
pack as an anti-virus measure, so no work-around. Not all clients show 
these anoying dialogs though. Thunderbird definately doesn't.
Unfortunately, I don't have the option of installing Thunderbird.
Chris
--
http://mail.python.org/mailman/listinfo/python-list


capwords (WAS: [Newby] question about modules)

2004-12-10 Thread Steven Bethard
Jon wrote:
As far as I can tell from the online docs, "capwords" should be defined in
the built-in "regex" module.  Why is it telling me that capwords is not
defined?
Hmm... are you looking instead for "capwords" from the string module?
>>> s = """\
... Well, he's...
... he's, ah...
... probably pining for the fjords."""
>>> import string
>>> print string.capwords(s)
Well, He's... He's, Ah... Probably Pining For The Fjords.
>>> print s.title()
Well, He'S...
He'S, Ah...
Probably Pining For The Fjords.
Note that there are a few subtle differences between string.capwords and 
str.title -- string.capwords capitalizes only at whitespace boundaries 
(and replaces runs of whitespace with spaces), while str.title 
capitalizes at alphanumeric boundaries.

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


Clarification of two concepts (or maybe one?)

2004-12-10 Thread Eddie Parker








Sorry, I’ve tried to search the web on this,
but I’m still a little fuzzy. I was hoping a quick e-mail might clear
this up.


What I’m looking for, is a way to turn a python ‘application’,
into a ‘stand-alone’ application. i.e., you don’t need the
Python interpreter, libraries, etc, installed on your hard drive. (I’m OK
with .py files existing – I just don’t want to have to bother the
user to install more then just my app). 

 

One alternative is to embed the Python interpreter in
a C++ app, and then just call the entry point... But I’m curious if there’s
a better way?

 

On the unrelated (or maybe related) concept, the words
“python freezing” keeps buzzing around my subconscious. I’m
not sure if this item can help me in any such way, but I can’t find any
good articles on what this phenomenon *is*.
Can anyone point me to a definitive web page that describe this, or indicate if
it *is* in fact what I’m
looking for? (I’m probably way off base on this one).

 

Anyhow, your help is most appreciated! Thank you!

 

-e-








---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.788 / Virus Database: 533 - Release Date: 01/11/2004
 
-- 
http://mail.python.org/mailman/listinfo/python-list

sources for DOS-16bit

2004-12-10 Thread McBooCzech
Hi all,

before I decided to bother you by e-mail, I spent days (not kidding)
searching on the Internet. I am looking for Python binaries for
DOS-16bit
Not for Win-16bit or DOS-32 which are the only DOS availabele sources
on Python official site and on the other sites as well!!!
I will prefere sources for Borland C 3.x.

I was trying to use Python 1.0.1 (16python.exe file) for my
application,
but I realized it doesn't work on NEC V25 CPU (8086/8088 compatible
CPU developed by NEC).

I was involved in to our school computer "research" :) and we need
this piece of code to reach our goal.

We have to demonstrate the power of the free software (mainly its
compatiblity for different platforms)!!!

Can you please search your archives or route me somewhere?


I will really appreciate your answer and help
Petr Jakes
Gymnasium student
Jicin
Czech republic

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


Re: Zip with a list comprehension

2004-12-10 Thread Steven Bethard
Matt Gerrans wrote:
This is probably so easy that I'll be embarrassed by the answer.   While 
enhancing and refactoring some old code, I was just changing some map()s to 
list comprehensions, but I couldn't see any easy way to change a zip() to a 
list comprehension.Should I just let those sleeping dogs lie?   (list 
comprehensions seem more readable than map(), but if the list comprehension 
that does the equivalent of zip() is less expressive than zip(), I'll stick 
with zip()).
Hmmm...  I couldn't do any better than:
>>> seqs = [(1, 2, 3), (4, 5, 6, 7)]
>>> zip(*seqs)
[(1, 4), (2, 5), (3, 6)]
>>> [tuple(seq[i] for seq in seqs)
...  for i in range(min(len(seq) for seq in seqs))]
[(1, 4), (2, 5), (3, 6)]
I think I'll stick with zip. ;)
I too have been trying to make my code more conformant with Python 3000 
recommendations (e.g. removing maps in favor of LCs or GEs, replacing 
lambdas with named functions, etc.) but I've left zip pretty much alone.

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


Zip with a list comprehension

2004-12-10 Thread Matt Gerrans
This is probably so easy that I'll be embarrassed by the answer.   While 
enhancing and refactoring some old code, I was just changing some map()s to 
list comprehensions, but I couldn't see any easy way to change a zip() to a 
list comprehension.Should I just let those sleeping dogs lie?   (list 
comprehensions seem more readable than map(), but if the list comprehension 
that does the equivalent of zip() is less expressive than zip(), I'll stick 
with zip()).

 


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


Re: Tibia 0.1 DOM-based website editor

2004-12-10 Thread Gabriel Cooper

Robert Brewer wrote:
I assume you're using the demo? My copy of Firefox has an error browser
under Tools->Javascript Console. Does the double-click report any error
there? Make sure you clear the list before trying, since errors from all
other webpages gt dumped in the same list.
 

I was using the demo on your site as Admin, but it looks like your 
server is overloaded now as the pages no longer load... Ah well. ;)
--
http://mail.python.org/mailman/listinfo/python-list


Re: thread/queue bug

2004-12-10 Thread Peter Hansen
phil wrote:
You know, I get this all the time on language support groups.
All of my Linux support groups, if they don't understand, say
why and ask for elaboration.  
Wow, amazing!  Imagine that... asking for elaboration when
someone posts unclear confusing questions and extraneous
information.  The noive!
I also find it remarkable that so many different people are
all doing the same thing to you.  It must be a conspiracy.
Certainly not a problem with, say, you...
--
http://mail.python.org/mailman/listinfo/python-list


Re: Clarification of two concepts (or maybe one?)

2004-12-10 Thread Fredrik Lundh
Eddie Parker wrote:

> What I’m looking for, is a way to turn a python ‘application’, into a
> ‘stand-alone’ application. i.e., you don’t need the Python interpreter,
> libraries, etc, installed on your hard drive. (I’m OK with .py files
> existing – I just don’t want to have to bother the user to install more then
> just my app).

you cannot run Python without a Python interpreter -- but you can ship the
interpreter DLL and the necessary library components with your app, and
you can use bundling tools to reduce the number of files to a minimum:

http://effbot.org/zone/python-compile.htm
http://www.python.org/cgi-bin/moinmoin/DistributionUtilities

 



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


Re: Wrapper objects

2004-12-10 Thread redhog
Ah, thanks. I didn't think of the possibility of creating a list of
methods that needed wrapping, and wrapping them uppon creation of the
wrapper object. Mainly I think, becaus it seems to me as such an uggly
workaround for a misdesign in Python. Also, if the wrapped object gets
some extra methods/callable member variables added "after the fact",
those will not get wrapped (this is however not a common thing to
happen, it just annoys me that it won't work).

As to what I want to use this for, I today have a huge program in which
several objects are wrapped up with comments (made up by some DOMish
structre) which are displayed to the user at various times. For
example, a list of users may be represented as as comment "List of
users" and a python list of elements, each being a user id (represented
as an integer), with a comment being the username. This means the list
is usable both for user-output and for machine-handling. Hm, this
wasn't prolly such a good example, but hopefully, it shows enought of
the idea...

Todya, the comment-value-pair is an ordinary object with two member
variables, and there are two functions, getComment and getValue, which
extracts a comment if its argument is such an object, or None
otherwise, and the wrapped value if its argument is such an object, and
the argument itself otherwize, respectively.

This means my code is literally filled with calls to getValue(), which
I would like to be able to remove by making the comment-value pair more
transparent.

Anyway, I do have some questions about your implementation:

If "if inst is None: return self" to protect for infinite recursion
when looking up self.__dict__?

What is the reason to give func to the MethodDesc property object, why
does its __get__ method have to do

if func: return func.__get__(self.thing, type(self.thing))

?

What is the reason to neither wrap, nor just copy, any of __getattr__,
__getattribute__, __setattr__, '__new__' or '__init__'? Especially
__getattr__, __getattribute__ and __setattr__ seems to need at least
some type of wrapping (but perheaps some special one)?
Regards,
Egil Möller

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


thread/queue bug

2004-12-10 Thread phil
>Wow, amazing!  Imagine that... asking for elaboration when
>someone posts unclear confusing questions and extraneous
>information.  The noive!
I would be happy to elaborate. No one asked to me to elaborate.
I was simply told I didn't give enough information.
I wasn't given an idea of what additional information
was needed or some clue as to how to better phrase my question.
>I also find it remarkable that so many different people are
>all doing the same thing to you.  It must be a conspiracy.
>Certainly not a problem with, say, you...
I didn't say so many people are doing the same thing to me.
Some language support groups make me feel like I am asking
stupid questions in a stupid way, not all.  And the Linux
and FreeBSD support groups never do.  In fact it seems
on those groups the more newbie and inadequate your questions
are the more patience and help you get.
I've never before on any group seen anyone told they
had a mental block, because they were fishing for info.
I have a genuine problem here, which I have no clue how to approach,
and I am very sorry I started a flame over protocol.
THAT has certainly never happened to me before. signing off.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Wrapper objects

2004-12-10 Thread redhog
As to what I want to use this for, I today have a huge program in which
several objects are wrapped up with comments (made up by some DOMish
structre) which are displayed to the user at various times. For
example, a list of users may be represented as as comment "List of
users" and a python list of elements, each being a user id (represented
as an integer), with a comment being the username. This means the list
is usable both for user-output and for machine-handling. Hm, this
wasn't prolly such a good example, but hopefully, it shows enought of
the idea...

Tody, the comment-value-pair is an ordinary object with two member
variables, and there are two functions, getComment and getValue, which
extracts a comment if its argument is such an object, or None
otherwise, and the wrapped value if its argument is such an object, and
the argument itself otherwize, respectively.

This means my code is literally filled with calls to getValue(), which
I would like to be able to remove by making the comment-value pair more
transparent.

The wrapper objects needs to work as dictionary keys, to support
printing, concatenation/addition, getitem/setitem and such things...

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


Re: sources for DOS-16bit

2004-12-10 Thread Peter Hansen
McBooCzech wrote:
I am looking for Python binaries for DOS-16bit
Not for Win-16bit or DOS-32 which are the only DOS availabele sources
on Python official site and on the other sites as well!!!
I will prefere sources for Borland C 3.x.
I was trying to use Python 1.0.1 (16python.exe file) for my
application,
but I realized it doesn't work on NEC V25 CPU (8086/8088 compatible
CPU developed by NEC).
I was involved in to our school computer "research" :) and we need
this piece of code to reach our goal.
We have to demonstrate the power of the free software (mainly its
compatiblity for different platforms)!!!
Can you please search your archives or route me somewhere?
Does it have to be Python?  There are other languages that
are arguably as portable, and certainly more compact.  Lua,
for example, has been ported to quite small devices.  See
http://www.lua.org/ for more on that, but note there are
other options as well.  Python's not the only "free portable
software" around, though it's the best in many ways.
-Peter
--
http://mail.python.org/mailman/listinfo/python-list


Re: collaborative editing

2004-12-10 Thread MMM
Michele Simionato wrote:
> Suppose I want to write a book with many authors via the Web. The
book has
> a hierarchical structure with chapter, sections, subsections,
subsubsections,
> etc. At each moment it must be possible to print the current version
of the
> book in PDF format. There must be automatic generation of the table
of contents,
> indices, etc. Conversions to many formats (Latex, DocBook, etc.)
would be
> welcome. Does something like that already exists? Alternatively, I
would need
> some hierarchical Wiki with the ability of printing its contents in
an
> structured way.
>
>
> Michele Simionato
Tkae a look at 
http://www.infrae.org/products/silva/

Regards,
Mikhail

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


Re: Distutils vs. Extension header files

2004-12-10 Thread David M. Cooke
Mike Meyer <[EMAIL PROTECTED]> writes:

> I've got a package that includes an extension that has a number of
> header files in the directory with the extension. They are specified
> as "depends = [...]" in the Extension class. However, Distutils
> doesn't seem to do anything with them.
>
> If I do an sdist, the include files aren't added to the tarball.
>
> If I do a bdist_rpm, the source files get copied into the build
> directory and the build starts, but the header files aren't copied
> with the source file, so the build fails with a missing header file.
>
> I find it hard to believe that this is a bug in distutils, so I'd
> appreciate it if someone could tell me what I'm doing wrong.

vincent has the solution (you need to specify them in MANIFEST.in),
but I'll add my 2 cents.

depends = [...] is used in building (it's like dependencies in make).
If one of those files change, distutils will rebuild the extension.
But that's all distutils does with it. It's braindead including stuff
in the source distribution, including depends, data files, and other
stuff you'd think it would do. When in doubt, add it to MANIFEST.in.

-- 
|>|\/|<
/--\
|David M. Cooke
|cookedm(at)physics(dot)mcmaster(dot)ca
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: UrlLib2 Proxy and Https

2004-12-10 Thread j_belbo
I have made some tests with Curl and this proxy setting is correct
It's seems that there is a problem with HTTPS and urllib2 + proxy
Bye,
Jacobo
"Tom" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED]
> > I would like to access an HTTPS site via a proxy
> > The following code is working for HTTP://www.hotmail.com but not for
HTTPS
> > I have try with other sites without success
> >
> >   l_proxy_info = {
> >  'user' : mylogin,
> >  'pass' : mypassword,
> >  'host' : myproxy,
> >  'port' : 8080
> >   }
>
> I have no idea if this is your problem, but you are aware that https is
> usually on port 443, not 80 or 8080 like http?
>
> HTH
>
> Tom


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


Re: collaborative editing

2004-12-10 Thread Doug Holton
Michele Simionato wrote:
Suppose I want to write a book with many authors via the Web. The book has 
a hierarchical structure with chapter, sections, subsections, subsubsections, 
etc. At each moment it must be possible to print the current version of the 
book in PDF format. There must be automatic generation of the table of contents,
indices, etc. Conversions to many formats (Latex, DocBook, etc.) would be
welcome. Does something like that already exists? Alternatively, I would need
some hierarchical Wiki with the ability of printing its contents in an
structured way. 
You want a wiki engine.  There are many to choose from, some of which 
have all the features you want.
See for example Atlassian Confluence.  We are using it to create 
documentation for boo ( http://boo.codehaus.org ).  This page for 
example has child pages and you can export pages to html, pdf, or xml.
http://docs.codehaus.org/display/BOO/Recipes
http://docs.codehaus.org/spaces/exportspace.action?key=BOO

I think the PHP/MySQL-based Tiki wiki has similar features, too.
http://tikiwiki.org/tiki-index.php
--
http://mail.python.org/mailman/listinfo/python-list


Re: Help beautify ugly heuristic code

2004-12-10 Thread JanC
Stuart D. Gathman schreef:

> I have a function that recognizes PTR records for dynamic IPs.  There
> is no hard and fast rule for this - every ISP does it differently, and
> may change their policy at any time, and use different conventions in
> different places.  Nevertheless, it is useful to apply stricter
> authentication standards to incoming email when the PTR for the IP
> indicates a dynamic IP (namely, the PTR record is ignored since it
> doesn't mean anything except to the ISP).  This is because Windoze
> Zombies are the favorite platform of spammers.

Did you also think about ISPs that use such a PTR record for both dynamic 
and fixed IPs?

-- 
JanC

"Be strict when sending and tolerant when receiving."
RFC 1958 - Architectural Principles of the Internet - section 3.9
-- 
http://mail.python.org/mailman/listinfo/python-list


request for book-recommendation

2004-12-10 Thread patrick c.d.
hi,

does here anyone of ya geeks know a book teaching you how to handle gtk,
web-dev with mysql-db-connection and scripting under gnu/linux with phyton?

i'm german (hhaarr) but due to my efficiency-course in english (shool) i
want to learn english by learning phyton ;-)

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


ANNOUNCE: PyPHP, Python programming using the PHP web framework

2004-12-10 Thread Antony Lesuisse
PyPHP the python php bridge
===

Download it at http://lesuisse.net/pyphp-0.1.tgz

WARNING this is experimental !

Summary:


PyPHP enables Python programming in the PHP web framework.
PyPHP is not yet another Python Web framework, it is the PHP web framework made
available to Python programmers.

With PyPHP you get the best of both Python and PHP world:
- The power, cleanness and robustness of the Python language
- The much used, developped and maintained PHP framework

The most useful PHP framework features you get access to are:
- Session management (using pickle you are be able to store your python objects
  in the PHP sessions)
- Persistent database connections
- HTTP authentification
- Ouput buffering and header/cookie management

While most python programmers would favor the Python Standard Library to the
PHP functions library, PyPHP allows PHP programmers to use the PHP functions
from their Python code and brings new features to the Python programmers.


Quickstart:
---

Hello world in pyphp, hello.php:

---

from pyphp import php

print "Hello World"
---

Accessing php functions, test.php:

---

# vim:syntax=python:
from pyphp import php

php.header("Content-Type: text/plain")
print "Hello from python\n"
print php.explode("/","/etc/passwd")
php.eval("print_r($_SERVER);")


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


Re: Compiling Python 2.4 extensions with free VC++ Toolkit

2004-12-10 Thread Mike C. Fletcher
Jody Burns wrote (with Peter):
See Mike C. Fletcher's post and 
http://www.vrplumber.com/programming/mstoolkit/ for a way to do it 
very easily (you have to be able to use the GNU patch tool, but that's 
not difficult at all).

--Jody
...
not been able to get into hacking on the core of Python because

...
-Peter

Keep in mind that the recipe there is for building *extensions*, not 
core Python.  There's a pointer from my page to a post by someone who 
seemed to have built core Python with the Toolkit, but my page isn't 
going to help Peter much with hacking on core Python.

Just an FYI,
Mike

 Mike C. Fletcher
 Designer, VR Plumber, Coder
 http://www.vrplumber.com
 http://blog.vrplumber.com
--
http://mail.python.org/mailman/listinfo/python-list


Re: How do I do this? (eval() on the left hand side)

2004-12-10 Thread Peter Hansen
Carl Banks wrote:
It's a bit more honest to set module attributes using setattr than dict
access, I would say.  
Granted.
But I think it's also more honest to change a module's dict by
using globals() than by using a setattr call. <0.500 wink>
-Peter
--
http://mail.python.org/mailman/listinfo/python-list


Re: How do I do this? (eval() on the left hand side)

2004-12-10 Thread Carl Banks
> From my point of view, they're basically identical, and
> although I find Carl's approach slightly less explicit
> and harder to read (mainly the uncommon __import__ call,
> but it's not a big deal), I can't see why either of them
> would be considered evil.

Of course, when I said evil, I didn't mean evil, I meant Evil(tm).  I
suspect Nick meant so as well.

Personally, I just think __import__(__name__) is a bit more honest than
globals() for a simple reason.

What are you doing?  You're changing module attributes.  Well, here's
the module object.  You're using setattr on the module object to set
module attributes.

What are you doing?  You're changing module attributes.  Well, here's
the module's dict.  You're using dictionary access on the modules dict
to set modules attributes.

It's a bit more honest to set module attributes using setattr than dict
access, I would say.  That's why I prefer it.  I admit, it's pretty
weak.  (But then again, so is __import__ being uncommon. :)  It's not a
big deal which you choose, as you say.  Although I don't use globals()
in this way, I do modify object dicts to get the effect of changing
object attributes from time to time (mostly to take advantage of dict
methods, which I could see being a reason to use globals() as well).
-- 
CARL BANKS

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


  1   2   >