EPD (Enthought Python Distribution) 4.0.300 Beta 3 available

2008-09-27 Thread Dave Peterson

Hello,

We've recently posted the third beta release of EPD (the Enthought
Python Distribution) with Python 2.5 version 4.0.300.  You may download
the beta from here:

http://www.enthought.com/products/epdbeta.php

Please help us test it out and provide feedback on the EPD Trac
instance: https://svn.enthought.com/epd  You can check out the release
notes here: http://www.enthought.com/products/epdbetareleasenotes.php


About EPD
-
The Enthought Python Distribution (EPD) is a kitchen-sink-included
distribution of the Python™ Programming Language, including over 60
additional tools and libraries. The EPD bundle includes NumPy, SciPy,
IPython, 2D and 3D visualization, database adapters, and a lot of
other tools right out of the box.

http://www.enthought.com/products/epd.php

It is currently available as a single-click installer for Windows XP
(x86), Mac OS X (a universal binary for OS X 10.4 and above), and
RedHat 3 and 4 (x86 and amd64).

EPD is free for academic use.  An annual subscription and installation
support are available for individual commercial use.  An enterprise
subscription with support for particular deployment environments is also
available for commercial purchase.  The beta versions of EPD are
available for indefinite free trial.


-- Dave


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

   Support the Python Software Foundation:
   http://www.python.org/psf/donations.html


ANN: TakeNote 0.4.2 - Note taking and organization

2008-09-27 Thread rasmus
TakeNote 0.4.2 - Note taking and organization

In this release:
  * faster loading
  * bullet point lists
  * more customization
  * bug fixes

TakeNote is a simple cross-platform note taking program implemented
in Python.  I have been using it for my research and class notes, but
it
should be applicable to many note taking situations.  Although this is
my first
release, it has most of the basic features needed for effective notes.

TakeNote is ideal for storing your class notes, TODO lists, research
notes, journal entries, paper outlines, etc in a simple notebook
hierarchy with rich-text formatting, images, and more. Using full-text
search, you can retrieve any note for later reference.

TakeNote is designed to be cross-platform (runs on Windows, Linux, and
MacOS X, implemented in Python and PyGTK) and stores your notes in
simple and easy to manipulate file formats (HTML and XML). Archiving
and transferring your notes is as easy as zipping or copying a
folder.  TakeNote is licensed under GPL.

TakeNote 0.4.2 is has the following features:

* Rich-text formatting
* Bullet point lists
* Hierarchical organization for notes
* Full-text search
* Inline images
* Integrated screenshot
* Spell checking (via gtkspell)
* Auto-saving
* Built-in backup and restore (archive to zip files)
* Cross-platform (Linux, Windows, MacOS X)

Web site and download:
http://rasm.ods.org/takenote


Matt Rasmussen
--
http://mail.python.org/mailman/listinfo/python-announce-list

Support the Python Software Foundation:
http://www.python.org/psf/donations.html


Re: what does ` ` do in ' '.join([`x * x` for x in range(1, 6)])?

2008-09-27 Thread r0g
process wrote:
 ' '.join([`x * x` for x in range(1, 6)])
 
 exactly what does this symbol do and what does it stand for?


Which symbol, the '*' ???

Are you kidding?
--
http://mail.python.org/mailman/listinfo/python-list


Re: what does ` ` do in ' '.join([`x * x` for x in range(1, 6)])?

2008-09-27 Thread r0g
process wrote:
 ' '.join([`x * x` for x in range(1, 6)])
 
 exactly what does this symbol do and what does it stand for?

Ah, just spotted the backticks - they just return whatever's inside them
as a string.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Eggs, VirtualEnv, and Apt - best practices?

2008-09-27 Thread r0g
Diez B. Roggisch wrote:
 that is a very valid point, but it seemed that Scott has homogeneous
 environment: Debian/Ubuntu so my post was relative to the original
 request.
 I agree that when you throw Windows/MacOS into the mix things
 become interesting. But then it's better when your developers
 develop on
 server/platform they are going to be using, using same stack they
 going to
 face in production etc. It all depends on requirements and current
 practices in company. 
 
 Well, you certainly want a desktop-orientied Linux for users, so you
 chose ubuntu - but then on the server you go with a more stable debian
 system. Even though the both have the same technical and even package
 management-base, they are still incompatible wrt to package versions for
 python.
 
 And other constraints such as Photoshop not being available for Linux
 can complicate things further.

Photoshop for Windows runs fine under Wine, or at least it does on my
Ubuntu box, just make sure you install the windows core fonts. I don't
think many people realise how good Wine is these days, maybe because it
was so useless for so long, it's pretty good right now. Also there's
'crossover' if you need even better out of  the box Win32 binary
compatibility.

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


Re: How to get the filename in the right case ?

2008-09-27 Thread r0g
Steven D'Aprano wrote:
 On Fri, 26 Sep 2008 01:46:15 +0200, Stef Mientki wrote:
 
 Secondly thoughtless copying of current behavior, doesn't bring any
 progress,
 and I think that's one of the reasons why we're still burdened by
 inventions done 20 years ago,
 e.g. do you want to save your changes ?.
 
 I click No about 50% of the time, and Yes Of Course You Stupid Machine 
 the other 50% of the time. Until they have a computer capable of reading 
 my mind, I'm curious what alternative you'd suggest.
 
 

Agreed, it's pretty handy, especially since every program and its dog
decided to sprout tabs everywhere.


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


Re: What do you call a class not intended to be instantiated

2008-09-27 Thread Steven D'Aprano
On Fri, 26 Sep 2008 22:15:43 -0700, Aahz wrote:

 In article [EMAIL PROTECTED],
 Steven D'Aprano  [EMAIL PROTECTED] wrote:
On Thu, 25 Sep 2008 21:17:14 -0700, Aahz wrote:

 Seems to me that if all the module is used for is to store state,
 you're wasting a file on disk.  I personally prefer to use a class
 singleton.

I don't recognise the term class singleton. Can you explain please?
How is it different from an ordinary singleton?
 
 An ordinary singleton is instantiating the class multiple times yet
 returning the same instance object; a class singleton is simply using
 the class directly (like a module).

Amazing. That's *exactly* what I was thinking of when I first asked my 
question.

Since I now no longer think I need such a beast, this is just academic 
curiosity, but given a class singleton, I'd like to be able to call it as 
if it were a function. Normally calling a class object returns an 
instance -- I wish to return something else. Is that just a matter of 
overriding __new__?

This seems to works:

 class ClassSingleton(object):
... thing = (0, 1, 2)
... def __new__(cls, *args):
... return len(args+cls.thing)
...
 ClassSingleton(1, 2, 4, 8, 16)
8



Is it really that easy?



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


Re: how to search multiple textfiles ? (Python is slow ?)

2008-09-27 Thread M�ta-MCI (MVP)

Hi !

Thanks for return.

Some infos: from a long time, I found that it's often more fast to use 
windows's command, instead of develop in high level language (and also, 
low level...)


FINDSTR is fast. OK. But internal commands are more fast. Example : DIR 
(with all his options)

And it's faster to read the result via a Pipe.
Thus, I use frequently this sort of function:


import os

def cmdone(repstart, commande, moderetour=LIST):
   os.chdir(repstart)
   sret=''.join(os.popen(commande))
   if moderetour.upper() == STR:
   return sret
   else:
   return sret.split('\n')

print cmdone('D:\\dev\\python','findstr /N /I ponx *.py','STR')
print
print cmdone('D:\\dev\\python','dir *.jpg /B')




Sorry for my bad english, and have a good day...
--
Michel Claveau


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


Negative block sizes with file-like objects

2008-09-27 Thread Steven D'Aprano
I have a proxy class that wraps an arbitrary file-like object fp and 
reads blocks of data from it. Is it safe to assume that fp.read(-1) will 
read until EOF? I know that's true for file.read() and StringIO.read(), 
but is it a reasonable assumption to make for arbitrary file-like objects?

To put it in more concrete terms, I have a class like this:

class C(object):
# Much simplified version.
def __init__(self, fp):
self.fp = fp
def read(self, size=-1):
return self.fp.read(size)


Should I re-write the read() method like this?

def read(self, size=-1):
if size  0:
return self.fp.read()
else:
return self.fp.read(size)



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


Re: Are spams on comp.lang.python a major nuisance?

2008-09-27 Thread Bob Cortopassi
On 2008-09-26, nntpman68 [EMAIL PROTECTED] wrote:

 - I'm annoyed by any spam.
 It's tough to find good rules, but the incoming spams that I see 
 currently on comp.lang.python have certain criteas.

 - most email addresses from gmail.
...snip rest of good filter criteria...

Killing all messages with googlegroups in the messageid will get rid
of a vast majority of the spam.  Killing anything with a gmail.com
email address will end up killing more legitimate posters.

-- 
email: echo [EMAIL PROTECTED] | sed 's/s/o/g' | rot13
All posts from Google Groups are auto-killed.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Negative block sizes with file-like objects

2008-09-27 Thread Peter Otten
Steven D'Aprano wrote:

 I have a proxy class that wraps an arbitrary file-like object fp and
 reads blocks of data from it. Is it safe to assume that fp.read(-1) will
 read until EOF? I know that's true for file.read() and StringIO.read(),
 but is it a reasonable assumption to make for arbitrary file-like objects?
 
 To put it in more concrete terms, I have a class like this:
 
 class C(object):
 # Much simplified version.
 def __init__(self, fp):
 self.fp = fp
 def read(self, size=-1):
 return self.fp.read(size)
 
 
 Should I re-write the read() method like this?
 
 def read(self, size=-1):
 if size  0:
 return self.fp.read()
 else:
 return self.fp.read(size)

Grepping through the python source shows that both -1 and None are used as
the default size.

# python2.5.2
 import tarfile
 open(sample, w).write(contents-of-sample)
 t = tarfile.open(sample.tar, w)
 t.add(sample)
 t.close()
 t = tarfile.open(sample.tar)
 t.extractfile(sample).read()
'contents-of-sample'
 t.extractfile(sample).read(-1)[:50]
'contents-of-sample\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'

So you may fare better with the rewrite. But even that may fail:

http://docs.python.org/lib/bltin-file-objects.html#l2h-295


read(  [size])
[...] If the size argument is negative or omitted, read all data until EOF
is reached. [...]
Also note that when in non-blocking mode, less data than what was requested
may be returned, even if no size parameter was given. 


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


Re: Are spams on comp.lang.python a major nuisance?

2008-09-27 Thread Dotan Cohen
2008/9/26 nntpman68 [EMAIL PROTECTED]:
 It's tough to find good rules, but the incoming spams that I see currently
 on comp.lang.python have certain criteas.



 - most email addresses from gmail.
 - all never posted before and then they have multiple posts within a few
 minutes  / seconds
 - the posts always contain one or more urls ( mostly cryptic names )
 - they always start a thread but never reply to one
 - the post doesn't contain python code or anything which looks only vaguely
 like source code
 - never mentions the word python
 - the amount of sexual or financial vocabulary exceeds classical python
 posts


I hope that the spammers don't read the list!

-- 
Dotan Cohen

http://what-is-what.com
http://gibberish.co.il
א-ב-ג-ד-ה-ו-ז-ח-ט-י-ך-כ-ל-ם-מ-ן-נ-ס-ע-ף-פ-ץ-צ-ק-ר-ש-ת

ä-ö-ü-ß-Ä-Ö-Ü
--
http://mail.python.org/mailman/listinfo/python-list

python for *nix system admins

2008-09-27 Thread Lars Stavholm
Hi All,

I'm new to this list and hoping that this is not off-topic.
If it is, please point me in the right direction.

I seem to recollect a python module or library for *nix sysadmins,
but I can't for the life of me find it again.

The module (or library) somehow added unix command capabilities
to the python language. It seemed like a lesser known, perhaps new,
python library or module.

Any input or ideas appreciated
/Lars Stavholm
--
http://mail.python.org/mailman/listinfo/python-list


Re: What do you call a class not intended to be instantiated

2008-09-27 Thread Ben Finney
Steven D'Aprano [EMAIL PROTECTED] writes:

 On Fri, 26 Sep 2008 22:15:43 -0700, Aahz wrote:
  An ordinary singleton is instantiating the class multiple times
  yet returning the same instance object; a class singleton is
  simply using the class directly (like a module).

Where is this class singleton terminology from? It seems redundant
to me. It also doesn't seem to have anything to do with what
singleton means as a pattern; using a class is simply using a
class.

 Since I now no longer think I need such a beast

That's a relief :-)

 I'd like to be able to call [a class] as if it were a function.
 Normally calling a class object returns an instance -- I wish to
 return something else.

In that case, you *don't* want a class at all; the entire point of a
class is to define behaviour for instances.

Instead, you want to define a class whose *instances* are callable, by
defining the '__call__' method to do whatever it is you want.

 This seems to works:
 
  class ClassSingleton(object):
 ... thing = (0, 1, 2)
 ... def __new__(cls, *args):
 ... return len(args+cls.thing)
 ...
  ClassSingleton(1, 2, 4, 8, 16)
 8

Horribly obfuscatory. Calling a class should return a new instance of
the class or something like it.

Instead, define it so the user instantiates the class by calling the
class, and *then* calls that non-class object, and so shouldn't expect
to get a new instance back:

 class CallableAppendor(object):
... thing = (0, 1, 2)
... def __call__(self, *args):
... return len(args + self.thing)
...
 appendor = CallableAppendor()
 appendor(1, 2, 4, 8, 16)
8

-- 
 \ “Pleasure's a sin, and sometimes sin's a pleasure.” —“Lord” |
  `\  George Gordon Noel Byron, _Don Juan_ |
_o__)  |
Ben Finney
--
http://mail.python.org/mailman/listinfo/python-list

Re: python for *nix system admins

2008-09-27 Thread km
import os

HTH
KM
~~

On Sat, Sep 27, 2008 at 1:35 PM, Lars Stavholm [EMAIL PROTECTED] wrote:

 Hi All,

 I'm new to this list and hoping that this is not off-topic.
 If it is, please point me in the right direction.

 I seem to recollect a python module or library for *nix sysadmins,
 but I can't for the life of me find it again.

 The module (or library) somehow added unix command capabilities
 to the python language. It seemed like a lesser known, perhaps new,
 python library or module.

 Any input or ideas appreciated
 /Lars Stavholm
 --
 http://mail.python.org/mailman/listinfo/python-list

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

Re: Running IDLE on 3.0rc1

2008-09-27 Thread Terry Reedy

Allan wrote:

Terry Reedy [EMAIL PROTECTED] writes:


I have not seen this posted, so...
To run IDLE with Python3.0rc1,
edit Python30/Libs/idlelib/run.py,
and change set_daemon(True) to daemon = True and save.
(This is about line 75, and the only appearance of 'daemon'.)
Otherwise, you get error message about not starting a subprocess.

Is this related to the tip at the end of the built-in help file in IDLE
regarding the `-n' command option?

No, the above is a bug fix that did not make it into rc1 but has now 
been committed.  It arose because the interface of a class in one of the 
modules was changed from .set_var(val) to .var = val and the need to 
change IDLE was not caught.  I imagine that checking that IDLE runs in 
not in the test suite.


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


Re: python for *nix system admins

2008-09-27 Thread Lars Stavholm
km wrote:
 import os

Thanks, but I'm aware of the standard libraries like os, sys,
commands, and whatnot. I'm looking for a non-standard library
that acts like a wrapper for the unix commands. I have seen it,
I just can't find it again.
/L

 On Sat, Sep 27, 2008 at 1:35 PM, Lars Stavholm [EMAIL PROTECTED]
 mailto:[EMAIL PROTECTED] wrote:
 
 Hi All,
 
 I'm new to this list and hoping that this is not off-topic.
 If it is, please point me in the right direction.
 
 I seem to recollect a python module or library for *nix sysadmins,
 but I can't for the life of me find it again.
 
 The module (or library) somehow added unix command capabilities
 to the python language. It seemed like a lesser known, perhaps new,
 python library or module.
 
 Any input or ideas appreciated
 /Lars Stavholm
 --
 http://mail.python.org/mailman/listinfo/python-list
 
 

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


Using the 'with' statement with cStringIO objects

2008-09-27 Thread peppergrower
I've been experimenting with the 'with' statement (in __future__), and
so far I like it.  However, I can't get it to work with a cStringIO
object.  Here's a minimum working example:

###
from __future__ import with_statement
import cStringIO

teststring='this is a test'

with cStringIO.StringIO(teststring) as testfile:
pass
###

I get the following error message:

Traceback (most recent call last):
  File testfile.py, line 6, in module
with cStringIO.StringIO(teststring) as testfile:
AttributeError: 'cStringIO.StringI' object has no attribute '__exit__'

So, I'm guessing you can't use the 'with' statement with cStringIO
objects?  Is this a bug, or do I need to use the 'with' statement
differently to get this to work?

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


Re: python for *nix system admins

2008-09-27 Thread Ben Finney
Lars Stavholm [EMAIL PROTECTED] writes:

 The module (or library) somehow added unix command capabilities
 to the python language. It seemed like a lesser known, perhaps new,
 python library or module.

Which particular Unix commands?

Perhaps you're thinking of the 'shutil' module
URL:http://www.python.org/doc/lib/module-shutil, which wraps a few
filesystem manipulation commands.

-- 
 \ “Of all classes the rich are the most noticed and the least |
  `\  studied.” —John Kenneth Galbraith, _The Age of Uncertainty_, |
_o__) 1977 |
Ben Finney
--
http://mail.python.org/mailman/listinfo/python-list

Re: What do you call a class not intended to be instantiated

2008-09-27 Thread Steven D'Aprano
On Sat, 27 Sep 2008 18:20:17 +1000, Ben Finney wrote:

 Steven D'Aprano [EMAIL PROTECTED] writes:
 
 On Fri, 26 Sep 2008 22:15:43 -0700, Aahz wrote:
  An ordinary singleton is instantiating the class multiple times yet
  returning the same instance object; a class singleton is simply using
  the class directly (like a module).
 
 Where is this class singleton terminology from? 

I don't know. Googling on it brings up an awful lot of C++ and Java 
source code for regular Singletons. Perhaps Aahz can shed some light on 
it?


 It seems redundant to
 me. It also doesn't seem to have anything to do with what singleton
 means as a pattern; using a class is simply using a class.


I don't see why this idiom causes such conceptual difficulty. There are 
classes with many instances; there are classes with a single instance 
(Singleton). Why should't there be classes with no instances?

A class is just an object. If you find yourself caring whether a 
particular object is a class, an instance or a function, then you have to 
ask yourself why you are worrying about the implementation details. Of 
course as the library writer, it's your job to worry about the 
implementation details, but ideally the library user shouldn't have to.

 
 Since I now no longer think I need such a beast
 
 That's a relief :-)
 
 I'd like to be able to call [a class] as if it were a function.
 Normally calling a class object returns an instance -- I wish to return
 something else.
 
 In that case, you *don't* want a class at all; the entire point of a
 class is to define behaviour for instances.

Classes encapsulate state + behaviour in one package, and they allow 
inheritance. That's a lot more than merely defining behaviour of 
instances. Instances in turn have the additional capability of being able 
to over-ride the class' state and behaviour:

class C(object):
x = 'spam'

c = C()
c.x = 'ham'  # doesn't touch C.x

If your instance doesn't do something the class can't do on it's own, why 
bother with the instance?



 Instead, you want to define a class whose *instances* are callable, by
 defining the '__call__' method to do whatever it is you want.

Most of the time, sure.


 
 This seems to works:
 
  class ClassSingleton(object):
 ... thing = (0, 1, 2)
 ... def __new__(cls, *args):
 ... return len(args+cls.thing) ...
  ClassSingleton(1, 2, 4, 8, 16)
 8
 
 Horribly obfuscatory. Calling a class should return a new instance of
 the class or something like it.

Apart from the name, which I dislike, what is obfuscatory about it? 
Haven't you ever used factory functions or class builders? It's the same 
principle. Why do you care that ClassSingleton is a class instead of a 
function?

I'm certainly not saying that we should use classes this way all the 
time, but the capability is there, and apparently not by accident. Guido 
wrote:

__new__ must return an object. There's nothing that requires that it 
return a new object that is an instance of its class argument, although 
that is the convention. If you return an existing object of your class or 
a subclass, the constructor call will still call its __init__ method. If 
you return an object of a different class, its __init__ method will not 
be called.

http://www.python.org/download/releases/2.2.3/descrintro/



 Instead, define it so the user instantiates the class by calling the
 class, and *then* calls that non-class object, and so shouldn't expect
 to get a new instance back:
 
  class CallableAppendor(object):
 ... thing = (0, 1, 2)
 ... def __call__(self, *args):
 ... return len(args + self.thing) ...
  appendor = CallableAppendor()
  appendor(1, 2, 4, 8, 16)
 8


That's the right solution when the instance is able to override the state 
and/or behaviour of the class. Most uses of classes are like that:

class Spam(object):
def __init__(self, n):
self.n = n
def sing(self):
return spam *self.n +  glorious SPAM!!!

Because the behaviour (method 'sing') depends on state which is specific 
to the instance (attribute 'n'), it is right and proper to instantiate 
the class. The class 'Spam' is a constructor for instances, and the 
instances do all the work.

But my earlier example is not the same. In the example I gave, neither 
the behaviour nor the state depend on the instance: everything is 
specified in the class. Ben's variant behaves differently: the caller 
might override appendor.thing by hand. That is Ben's choice, of course, 
and it may be a valid one for many applications, but it's displaying 
different behaviour to my example.

In my example, the instance doesn't matter. I could write it like this:

 class CallableAppendor(object):
... thing = (0, 1, 2)
... @classmethod
... def __call__(cls, *args):
... return len(args + cls.thing)
...
 appendor = CallableAppendor()
 appendor.thing = (1, 2, 3, 4, 5, 6, 7, 8)
 appendor(1, 2, 4, 8, 16)
8
 

Re: Using the 'with' statement with cStringIO objects

2008-09-27 Thread Fredrik Lundh

peppergrower wrote:


teststring='this is a test'

with cStringIO.StringIO(teststring) as testfile:
pass


umm.  what exactly do you expect that code to do?

/F

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


Re: How to read a jpg bytearray from a Flash AS3 file

2008-09-27 Thread Fredrik Lundh

[EMAIL PROTECTED] wrote:


I'm trying to save an image from a Flash AS3 to my server as a jpg
file. I found some PHP code to do this, but I want to do this in
Python. I'm not quite sure how to convert the following code to
Python. It's mainly the $GLOBALS[HTTP_RAW_POST_DATA] part I don't
know how to convert.


depends on what framework you're using.  if you're using plain CGI, you 
should be able to read the posted data from sys.stdin:


  import sys

  im = sys.stdin.read()

  f = open(name, 'wb')
  f.write(jpg)
  f.close()

to make your code a bit more robust, you may want to check the 
content-length before doing the read, e.g.


  import os

  if os.environ.get(REQUEST_METHOD) != POST:
  ... report invalid request ...

  bytes = int(os.environ.get(CONTENT_LENGTH, 0))
  if bytes  MAX_REQUEST_SIZE:
  ... report request too large ...

  im = sys.stdin.read(bytes)

to deal with query parameters etc, see

   http://docs.python.org/lib/module-cgi.html

/F

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


Re: what does ` ` do in ' '.join([`x * x` for x in range(1, 6)])?

2008-09-27 Thread alex23
On Sep 27, 3:58 pm, r0g [EMAIL PROTECTED] wrote:
 Ah, just spotted the backticks - they just return whatever's inside them
 as a string.

No, they return the repr() of the object inside. The output of
__repr__ -has- to be a string, but typecasting into string isn't the
intention of repr() (or the ` operator).
--
http://mail.python.org/mailman/listinfo/python-list


Re: How to get the filename in the right case ?

2008-09-27 Thread Fredrik Lundh

Stef Mientki wrote:


I don't think your suggestion is a good one.
If a filename has uppercase characters in it,
the END-USER has done that for some kind of reason.


I explain how pdb works and show you how to solve the specific 
comparison problem you mentioned in your post, and you start ranting 
because it doesn't solve all your problems?  what's wrong with you?


/F

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


Re: How to get the filename in the right case ?

2008-09-27 Thread Michael Torrie
Steven D'Aprano wrote:
 On Fri, 26 Sep 2008 01:46:15 +0200, Stef Mientki wrote:
 
 Secondly thoughtless copying of current behavior, doesn't bring any
 progress,
 and I think that's one of the reasons why we're still burdened by
 inventions done 20 years ago,
 e.g. do you want to save your changes ?.
 
 I click No about 50% of the time, and Yes Of Course You Stupid Machine 
 the other 50% of the time. Until they have a computer capable of reading 
 my mind, I'm curious what alternative you'd suggest.

It's well known that just using Yes and No in a dialog box is very,
very poor UI design.  In many cases it leads to confusion.  Especially
when the dialog box has both a statement and a question, which many do.
 The correct and proper way is to use only verbs in the buttons.  For
example instead of yes/no to the question of saving work before exiting,
you'd use save and don't save.  That's extremely clear even if you
don't quite understand the statement and question the dialog is asking.

Certainly the human-interface guidelines on the more sane systems out
there (OS X, Gnome) disallow the use of yes/no buttons in dialog boxes.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Are spams on comp.lang.python a major nuisance?

2008-09-27 Thread Aaron Castironpi Brady
On Sep 26, 1:04 pm, Aaron \Castironpi\ Brady
[EMAIL PROTECTED] wrote:
 On Sep 26, 11:43 am, Tim Rowe [EMAIL PROTECTED] wrote:

  2008/9/26 Steven D'Aprano [EMAIL PROTECTED]:

   I don't have any objective numbers, but subjectively it seems to me that
   the number of spams is significantly higher, but not so high as to be a
   major nuisance.

  I consider *any* spam to be a major nuisance, but I don't see them as
  being the fault of python-list which seems to do a pretty good job of
  blocking them

 I think in June and July they were selling watches a lot which I
 haven't noticed recently.

Gucci 104 G-Bandeau Watches - Gucci Watches Discount Rolex Oyster
Perpetual Lady Datejust Pearlmaster 18kt Yellow Gold Diamond Ladies
Watch 80318C
Cartier Must 21 Watches - Cartier Watches Discount

I speak too soon.

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


Re: Are spams on comp.lang.python a major nuisance?

2008-09-27 Thread Dotan Cohen
2008/9/27 Aaron Castironpi Brady [EMAIL PROTECTED]:
 I think in June and July they were selling watches a lot which I
 haven't noticed recently.

 Gucci 104 G-Bandeau Watches - Gucci Watches Discount Rolex Oyster
 Perpetual Lady Datejust Pearlmaster 18kt Yellow Gold Diamond Ladies
 Watch 80318C
 Cartier Must 21 Watches - Cartier Watches Discount

 I speak too soon.


If we start blocking users who have no previous posts and then post
many new messages at once, then we wll just push the spammers to forge
active list users and reply to threads. That would be a worse
situation then we are in now. I say leave well enough alone.

Read about the Brain Blood Barrier
(http://en.wikipedia.org/wiki/Brain_Blood_Barrier) for an example in
nature where although a method to stop an attacker exists, it is not
overused to prevent the attacker from becoming more powerful.

-- 
Dotan Cohen

http://what-is-what.com
http://gibberish.co.il
א-ב-ג-ד-ה-ו-ז-ח-ט-י-ך-כ-ל-ם-מ-ן-נ-ס-ע-ף-פ-ץ-צ-ק-ר-ש-ת

ä-ö-ü-ß-Ä-Ö-Ü
--
http://mail.python.org/mailman/listinfo/python-list

Regular expression help: unable to search ' # ' character in the file

2008-09-27 Thread dudeja . rajat
Hi,

Can some help me with the regular expression. I'm looking to search #
character in my file?

My file has contents:

###

Hello World

###

length = 10
breadth = 20
height = 30

###



###

Hello World

###

length = 20
breadth = 30
height = 40

###


I used the following search :

import re

fd = open(file, 'r')
line = fd.readline
pat1 = re.compile(\#*)
while(line):
mat1 = pat1.search(line)
if mat1:
print line
line = fd.readline()


But the above prints the whole file instead of the hash lines only.


Please help


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

Re: what does ` ` do in ' '.join([`x * x` for x in range(1, 6)])?

2008-09-27 Thread Roy Smith
In article 
[EMAIL PROTECTED],
 alex23 [EMAIL PROTECTED] wrote:

 ' '.join((str(x * x) for x in range(1,6)))

Aren't the outer set of parens redundant?  This works just as well:

' '.join(str(x * x) for x in range(1,6))
--
http://mail.python.org/mailman/listinfo/python-list


Re: What do you call a class not intended to be instantiated

2008-09-27 Thread Aaron Castironpi Brady
On Sep 27, 5:33 am, Steven D'Aprano [EMAIL PROTECTED]
cybersource.com.au wrote:
 On Sat, 27 Sep 2008 18:20:17 +1000, Ben Finney wrote:
  Steven D'Aprano [EMAIL PROTECTED] writes:

  On Fri, 26 Sep 2008 22:15:43 -0700, Aahz wrote:
   An ordinary singleton is instantiating the class multiple times yet
   returning the same instance object; a class singleton is simply using
   the class directly (like a module).

  Where is this class singleton terminology from?

 I don't know. Googling on it brings up an awful lot of C++ and Java
 source code for regular Singletons. Perhaps Aahz can shed some light on
 it?

[snip]

 In my example, the instance doesn't matter. I could write it like this:

  class CallableAppendor(object):

 ...     thing = (0, 1, 2)
 ...     @classmethod
 ...     def __call__(cls, *args):
 ...         return len(args + cls.thing)
 ... appendor = CallableAppendor()
  appendor.thing = (1, 2, 3, 4, 5, 6, 7, 8)
  appendor(1, 2, 4, 8, 16)
 8
  CallableAppendor.__call__(1,2,4,8,16)

 8

 but what's the purpose of instantiating the class?

I've used them (class singletons, adopting the term) as a Globals
namespace, but only to the end of tidying.  It makes it easy to
reassign immutables.

It is too bad 'CallableAppendor.__call__(1,2,4,8,16)' doesn't work as
expected.  That is, 'CallableAppendor(1,2,4,8,16)' dosen't call
'__call__'.  I have a workaround, which may be just what you're
looking for.

 class A(type):
... def __call__( self, *ar ):
... print 'call', self, ar
...
 class B(object):
... __metaclass__= A
...
 B(3)
call class '__main__.B' (3,)

Overriding the __call__ method of 'type' has the effect of giving you
a static __call__ method on a class-- a method which doesn't need an
instance to call.  Your behavior may be counterintuitive though, to
someone who wants to instantiate 'B', in this case, and proceed like a
normal object.  That is, they want to call a generic class and use it,
and also expect instances of B to behave as B.  You can't have both,
so either return B from B.__new__, or, to instantiate B, take the long
way and call B.__new__ directly.

 B.__new__(B)
__main__.B object at 0x009FDB70

Has anyone stepped through the C code to find out when the decision is
made to call which function, B.__new__ or A.__call__, when B is
called?  I'm happy that overriding type.__call__ produced the intended
results; it's always nice when things go right.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Build-in 'repr' function (was: what does ` ` do in ' '.join([`x * x` for x in range(1, 6)])?)

2008-09-27 Thread MRAB
On Sep 27, 4:16 am, Ben Finney [EMAIL PROTECTED]
wrote:
 process [EMAIL PROTECTED] writes:
  ' '.join([`x * x` for x in range(1, 6)])

  exactly what does this symbol do and what does it stand for?

 It's an obsolete, deprecated syntactic sugar for (what is now
 implemented as) the built-in 'repr' function.

 Instead, write the above as:

     ' '.join([repr(x * x) for x in range(1, 6)])

I'd classify it as one of Guido's mistakes! :-)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Regular expression help: unable to search ' # ' character in the file

2008-09-27 Thread Fredrik Lundh

[EMAIL PROTECTED] wrote:


import re

fd = open(file, 'r')
line = fd.readline
pat1 = re.compile(\#*)
while(line):
mat1 = pat1.search(line)
if mat1:
print line
line = fd.readline()


I strongly doubt that this is the code you used.


But the above prints the whole file instead of the hash lines only.


* means zero or more matches.  all lines is a file contain zero or 
more # characters.


but using a RE is overkill in this case, of course.  to check for a 
character or substring, use the in operator:


for line in open(file):
if # in line:
print line

/F

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


Re: python for *nix system admins

2008-09-27 Thread George Boutsioukis
On Sat, 27 Sep 2008 10:05:01 +0200, Lars Stavholm wrote:

 Hi All,
 
 I'm new to this list and hoping that this is not off-topic. If it is,
 please point me in the right direction.
 
 I seem to recollect a python module or library for *nix sysadmins, but I
 can't for the life of me find it again.
 
 The module (or library) somehow added unix command capabilities to the
 python language. It seemed like a lesser known, perhaps new, python
 library or module.
 
 Any input or ideas appreciated
 /Lars Stavholm

The only modules I've come across that barely fit your description are 
python-unixtools(gzip, bzip only) and shutil(some limited capabilities). 
Running unix commands is usually done directly(os.popen, os.system) on 
*nix platforms. Why(and how) would anyone rewrite them as python modules?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Are spams on comp.lang.python a major nuisance?

2008-09-27 Thread Aaron Castironpi Brady
On Sep 27, 7:28 am, Dotan Cohen [EMAIL PROTECTED] wrote:
 2008/9/27 Aaron Castironpi Brady [EMAIL PROTECTED]:

  I think in June and July they were selling watches a lot which I
  haven't noticed recently.

  Gucci 104 G-Bandeau Watches - Gucci Watches Discount Rolex Oyster
  Perpetual Lady Datejust Pearlmaster 18kt Yellow Gold Diamond Ladies
  Watch 80318C
  Cartier Must 21 Watches - Cartier Watches Discount

  I speak too soon.

 If we start blocking users who have no previous posts and then post
 many new messages at once, then we wll just push the spammers to forge
 active list users and reply to threads. That would be a worse
 situation then we are in now. I say leave well enough alone.

 Read about the Brain Blood Barrier
 (http://en.wikipedia.org/wiki/Brain_Blood_Barrier) for an example in
 nature where although a method to stop an attacker exists, it is not
 overused to prevent the attacker from becoming more powerful.

 --
 Dotan Cohen

 http://what-is-what.comhttp://gibberish.co.il
 א-ב-ג-ד-ה-ו-ז-ח-ט-י-ך-כ-ל-ם-מ-ן-נ-ס-ע-ף-פ-ץ-צ-ק-ר-ש-ת

 ä-ö-ü-ß-Ä-Ö-Ü

Yow!  I forgot the radiolabeled polyethylene glycol coated
hexadecylcyanoacrylate nanospheres!

CMIIW correct me if I'm wrong.  Google Groups is a Usenet/c-l-py
gateway.  Other gateways aren't contributing to spam.  What are they
doing that G-Groups is not?
--
http://mail.python.org/mailman/listinfo/python-list

Re: is decorator the right thing to use?

2008-09-27 Thread George Sakkis
On Sep 27, 1:44 am, Dmitry S. Makovey [EMAIL PROTECTED] wrote:

 George Sakkis wrote:
  Although this works, the second argument to ProxyMethod shouldn't be
  necessary, it's semantically redundant;  ideally you would like to
  write it as bmethod = ProxyMethod('b').

 since I'm already on exploratory trail (what about that rug being pulled
 from under?) With my code I can do really dirty tricks like this (not
 necessary that I'm going to):

 class B_base:
 def bmethod(self):
 print 'B_base'

 class B(B_base):
 def bmethod(self):
 print 'B'

 class A:
 bmethod=ProxyMethod('b',B_base.bmethod)

Yes, that's indeed dirty; don't do it :)

  As before, I don't think
  that's doable without metaclasses (or worse, stack frame hacking).
  Below is the update of my original recipe; interestingly, it's
  (slightly) simpler than before:

 Out of curiosity (and trying to understand): why do you insist on
 dictionaries with strings contents ( {'bmethod' : 'b1' } ) rather than
 something more explicit ? Again, I can see that your code is working and I
 can even understand what it's doing, just trying to explore alternatives :)

 I guess my bias is towards more explicit declarations thus

  bmethod=ProxyMethod('b',B.bmethod)

 looks more attractive to me, but I stand to be corrected/educated why is
 that not the right thing to do?

I see where you're coming from and I also prefer explicit reflection
mechanisms instead of strings (e.g. avoid eval/exec as much as
possible). As I mentioned, the second argument to ProxyMethod is (for
all sane purposes) redundant, so if you could implement it in a way
that bmethod = ProxyMethod('b') worked, I would be all for it, but
AFAIK it's not possible without a metaclass. A dict with string keys
and values to be consumed by a metaclass is perhaps the simplest thing
that could possibly work. It contains all the relevant information for
hooking the proxy to the delegate methods and nothing more; zero
boilerplate code overhead. Also note that it's not that big of a
difference; you have to provide the attribute name as a string anyway.

 Another thing that turns me away from string dictionaries is that those are
 the ones causing me more trouble hunting down typos. Maybe it's just my
 thing so I'm not going to insist on it. I'm open to arguments against that
 theory.

From my experience, I am equally prone to typos for both strings and
regular attributes; I agree though that the traceback information is
often more helpful when you mistype an attribute.

 One argument I can bring in defence of more explicit declarations is IDE
 parsing when autocompletion for B.bme... pops up (suggesting bmethod and
 bmethod2) and with 'b':'bmethod' it never happens.

I don't rely on autocompleting IDEs, at least in dynamic languages, so
it's not much of an issue for me but yes, it's another small argument
against strings.

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


Re: Using the 'with' statement with cStringIO objects

2008-09-27 Thread George Boutsioukis

 So, I'm guessing you can't use the 'with' statement with cStringIO
 objects?  Is this a bug, or do I need to use the 'with' statement
 differently to get this to work?
 
 Thanks,
 peppergrower

Neither, just not implemented. Only classes with __enter__ and __exit__ 
methods(ie context manager types) can be used in with statements. And, 
correct me if I'm wrong, I  think it's pointless for a StringIO object to 
have those.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Regular expression help: unable to search ' # ' character in the file

2008-09-27 Thread dudeja . rajat
On Sat, Sep 27, 2008 at 1:58 PM, Fredrik Lundh [EMAIL PROTECTED]wrote:

 [EMAIL PROTECTED] wrote:

  import re

 fd = open(file, 'r')
 line = fd.readline
 pat1 = re.compile(\#*)
while(line):
mat1 = pat1.search(line)
if mat1:
print line
line = fd.readline()


 I strongly doubt that this is the code you used.

  But the above prints the whole file instead of the hash lines only.


 * means zero or more matches.  all lines is a file contain zero or more #
 characters.

 but using a RE is overkill in this case, of course.  to check for a
 character or substring, use the in operator:

for line in open(file):
if # in line:
print line

 /F

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


Thanks Fredrik, this works. Indeed  it is a much better and cleaner
approach.

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

Re: What do you call a class not intended to be instantiated

2008-09-27 Thread Aahz
In article [EMAIL PROTECTED],
Ben Finney  [EMAIL PROTECTED] wrote:
Steven D'Aprano [EMAIL PROTECTED] writes:
 On Fri, 26 Sep 2008 22:15:43 -0700, Aahz wrote:

 An ordinary singleton is instantiating the class multiple times
 yet returning the same instance object; a class singleton is
 simply using the class directly (like a module).

Where is this class singleton terminology from? It seems redundant
to me. It also doesn't seem to have anything to do with what
singleton means as a pattern; using a class is simply using a
class.

I don't remember where I picked it up, probably here some years ago.
The point of the terminology is to distinguish how the class is *used*,
in precise parallel with module singleton.

 I'd like to be able to call [a class] as if it were a function.
 Normally calling a class object returns an instance -- I wish to
 return something else.

In that case, you *don't* want a class at all; the entire point of a
class is to define behaviour for instances.

Absolutely agreed with your first clause, disagreed about the second
clause.  As I said earlier, the main point of a class singleton is to get
the effect of a module singleton without the need to create another file
on disk.  In that case there is no instance and therefore the point of
the class is no longer to define behavior for instances.

But you can't call a module, and classes have well-defined behavior for
calling them, so you shouldn't try to pervert a class singleton by
defining behavior for calling them.  In fact, I would recommend creating
an __init__() method that raises NotImplementedError precisely to prevent
this usage (or have a __new__() method that returns None, but I generally
prefer to recommend practices that work with classic classes).

One cute reason to prefer class singletons to module singletons is that
subclassing works well for creating multiple singletons.  But really,
the main reason I use class singletons is that they are the absolute
simplest way to get attribute access:

class Foo: pass
Foo.bar = 'xyz'
if data == Foo.bar:
print !

Once it gets much more complicated than that, I prefer to use a smarter
object.
-- 
Aahz ([EMAIL PROTECTED])   * http://www.pythoncraft.com/

Argue for your limitations, and sure enough they're yours.  --Richard Bach
--
http://mail.python.org/mailman/listinfo/python-list


Re: how to replace and string in a SELECT ... IN ()

2008-09-27 Thread Tino Wildenhain

Hi,

Michael Mabin wrote:

so you wouldn't object then to something like
 
' in (%)' % ','.join([str_edit_for_exploit(x) for x in aList]) 


if str_edit_for_exploit applied security edits?


Whats an security edit btw? If it is something meant to turn possibly
insecure data into 'secure' then, no I would still object.
Why? Because its a bad example of default permit. Its always better
to have a whitelist - even more so when its so easy to do.

Its just a habit you develope - if you never do it right, how would you
know when and how to do it right when you need to?

Tino


smime.p7s
Description: S/MIME Cryptographic Signature
--
http://mail.python.org/mailman/listinfo/python-list

Re: Time.sleep(0.0125) not available within Linux

2008-09-27 Thread Grant Edwards
On 2008-09-27, Lawrence D'Oliveiro [EMAIL PROTECTED] wrote:
 In message [EMAIL PROTECTED], Grant
 Edwards wrote:

 On 2008-09-26, Lawrence D'Oliveiro [EMAIL PROTECTED]
 wrote:
 In message [EMAIL PROTECTED], Grant Edwards
 wrote:

 Never assume somebody reading the article and attempting to
 help you can see the subject line.

 Why not?
 
 Because it might not be.  It depends on the user's newsreader
 and editor settings.

 So, should I not assume that they can see the content as well,
 because it might not be visible, depending on the user's
 newsreader and editor settings?

Thats seems like a bit of reductio ad absurdum.  My
observations over the years confirm the advice that you
shouldn't place information solely in the subject line.  If you
rely on people re-reading the subject line as the read and
reply to the body of the posting, you'll often get bad results.
People will miss information that was left out of the body and
placed solely in the subject line.  I've seen it happen over an
over again (this thread is an example).

If you don't care whether you get timely and accurate
responses, then do whatever you want.  Otherwise, include all
the pertinent information in the body of the posting.

-- 
Grant

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


Re: EPD (Enthought Python Distribution) 4.0.300 Beta 3 available

2008-09-27 Thread Christopher Brewster
I have always thought this idea very good, but if I download it and  
install it (on my MacBook pro) will any conflicts occur with existing  
bits and pieces of Python and its libraries?


Thank you,

Christopher Brewster

*
Department of Computer Science, University of Sheffield
Regent Court, 211 Portobello Street
Sheffield   S1 4DP   UNITED KINGDOM
Web: http://www.dcs.shef.ac.uk/~kiffer/
Tel: +44(0)114-22.21967  Fax: +44 (0)114-22.21810
Skype: christopherbrewster
SkypeIn (UK): +44 (20) 8144 0088
SkypeIn (US): +1 (617) 381-4281
*
Corruptissima re publica plurimae leges. Tacitus. Annals 3.27




On 27 Sep 2008, at 07:08, Dave Peterson wrote:

Hello,

We've recently posted the third beta release of EPD (the Enthought
Python Distribution) with Python 2.5 version 4.0.300.  You may download
the beta from here:

http://www.enthought.com/products/epdbeta.php

Please help us test it out and provide feedback on the EPD Trac
instance: https://svn.enthought.com/epd  You can check out the release
notes here: http://www.enthought.com/products/epdbetareleasenotes.php


About EPD
-
The Enthought Python Distribution (EPD) is a kitchen-sink-included
distribution of the Python™ Programming Language, including over 60
additional tools and libraries. The EPD bundle includes NumPy, SciPy,
IPython, 2D and 3D visualization, database adapters, and a lot of
other tools right out of the box.

http://www.enthought.com/products/epd.php

It is currently available as a single-click installer for Windows XP
(x86), Mac OS X (a universal binary for OS X 10.4 and above), and
RedHat 3 and 4 (x86 and amd64).

EPD is free for academic use.  An annual subscription and installation
support are available for individual commercial use.  An enterprise
subscription with support for particular deployment environments is also
available for commercial purchase.  The beta versions of EPD are
available for indefinite free trial.


-- Dave


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

  Support the Python Software Foundation:
  http://www.python.org/psf/donations.html


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


Re: What do you call a class not intended to be instantiated

2008-09-27 Thread Roy Smith
In article [EMAIL PROTECTED], [EMAIL PROTECTED] (Aahz) 
wrote:

 One cute reason to prefer class singletons to module singletons is that
 subclassing works well for creating multiple singletons.  But really,
 the main reason I use class singletons is that they are the absolute
 simplest way to get attribute access:
 
 class Foo: pass
 Foo.bar = 'xyz'
 if data == Foo.bar:
 print !

I've often done something similar, creating a dummy class:

class Data:
   pass

just so I could create instances of it to hang attributes off of:

foo = Data()
foo.bar = 'xyz'

That's a trick I've been using since the Old Days (i.e. before new-style 
classes came along).  When I saw your example, my first thought was That's 
silly, now that there's new-style classes, you can just create an instance 
of object!.  Unfortunately, when I tried it, I discovered it didn't work.  
You *can* instantiate object, but you don't get a class instance, so you 
can't create attributes on it.

 x = object()
 type(x)
type 'object'
 x.foo = 1
Traceback (most recent call last):
  File stdin, line 1, in module
AttributeError: 'object' object has no attribute 'foo'
--
http://mail.python.org/mailman/listinfo/python-list


Re: Using the 'with' statement with cStringIO objects

2008-09-27 Thread Hrvoje Niksic
George Boutsioukis [EMAIL PROTECTED] writes:

 Neither, just not implemented. Only classes with __enter__ and
 __exit__ methods(ie context manager types) can be used in with
 statements. And, correct me if I'm wrong, I think it's pointless for
 a StringIO object to have those.

It's definitely superfluous, but it should still be provided, for the
same reason a close method is provided, to allow StringIO objects to
be treated like other file-like objects.  For example, code that does
the following:

with obj.open_file(...) as f:
...

shouldn't have to care if obj.open_file returns a built-in file
instance, or a StringIO instance.  As the above code becomes more
popular, __enter__ and __exit__ are beginning to be part of the file
interface (in the duck-typing sense) and should be implemented.

Until then, the the contextlib.closing context manager can be used
instead:

with contextlib.closing(obj.open_file(...)) as f:
...
--
http://mail.python.org/mailman/listinfo/python-list


Re: is decorator the right thing to use?

2008-09-27 Thread George Sakkis
On Sep 27, 9:23 am, George Sakkis [EMAIL PROTECTED] wrote:

 On Sep 27, 1:44 am, Dmitry S. Makovey [EMAIL PROTECTED] wrote:

  I guess my bias is towards more explicit declarations thus

   bmethod=ProxyMethod('b',B.bmethod)

  looks more attractive to me, but I stand to be corrected/educated why is
  that not the right thing to do?

 I see where you're coming from and I also prefer explicit reflection
 mechanisms instead of strings (e.g. avoid eval/exec as much as
 possible). As I mentioned, the second argument to ProxyMethod is (for
 all sane purposes) redundant, so if you could implement it in a way
 that bmethod = ProxyMethod('b') worked, I would be all for it, but
 AFAIK it's not possible without a metaclass.

Just for completeness, here's a metaclass version that uses
ProxyMethod declarations instead of a dict; you'll probably like this
better:

#=== usage =
from proxies import Proxy, ProxyMethod

class B(object):
def __init__(self, val): self.val = val
def bmethod(self,n): print B::bmethod, self.val, n
def bmethod2(self,n,m): print B::bmethod2, self.val, n, m

class C(object):
def __init__(self, val): self.val = val
def cmethod(self,x): print C::cmethod, self.val, x
def cmethod2(self,x,y): print C::cmethod2,self.val, x, y
cattr = 4

class A(Proxy):
def __init__(self, b1, b2, c):
print init A()
# must call Proxy.__init__
super(A,self).__init__(b1=b1, b2=b2, c=c)

def amethod(self,a):
print A::mymethod,a

bmethod  = ProxyMethod('b1')
bmethod2 = ProxyMethod('b2')
cmethod  = ProxyMethod('c')


a = A(B(10), B(20), C(30))
a.amethod('foo')

print bound proxy calls
a.bmethod('foo')
a.bmethod2('bar','baz')
a.cmethod('foo')
try: a.cmethod2('bar','baz')
except Exception, ex: print ex

print unbound proxy calls
A.bmethod(a,'foo')
A.bmethod2(a,'bar','baz')
A.cmethod(a, 'foo')
try: A.cmethod2(a,'bar','baz')
except Exception, ex: print ex

#=== output 

init A()
A::mymethod foo
bound proxy calls
B::bmethod 10 foo
B::bmethod2 20 bar baz
C::cmethod 30 foo
'A' object has no attribute 'cmethod2'
unbound proxy calls
B::bmethod 10 foo
B::bmethod2 20 bar baz
C::cmethod 30 foo
type object 'A' has no attribute 'cmethod2'

#== proxies.py ==

class _ProxyMeta(type):
def __new__(meta, name, bases, namespace):
for attrname,value in namespace.iteritems():
if isinstance(value, ProxyMethod) and value.name is None:
value.name = attrname
return super(_ProxyMeta,meta).__new__(meta, name, bases,
namespace)


class ProxyMethod(object):
def __init__(self, proxy_attr, name=None):
self._proxy_attr = proxy_attr
self.name = name

def __get__(self, proxy, proxytype):
if proxy is not None:
return self.__get_target_attr(proxy)
else:
return self.__unbound_method

def __unbound_method(self, proxy, *args, **kwds):
method = self.__get_target_attr(proxy)
return method(*args, **kwds)

def __get_target_attr(self, proxy):
try:
delegate = getattr(proxy, self._proxy_attr)
return getattr(delegate, self.name)
except AttributeError:
raise AttributeError('%r object has no attribute %r' %
 (proxy.__class__.__name__,
self.name))


class Proxy(object):
__metaclass__ = _ProxyMeta

def __init__(self, **attr2delegate):
self.__dict__.update(attr2delegate)

#==

If you want to eliminate completely specifying attributes with
strings, it's easy to modify the above so that you write instead:

class A(Proxy):
...
bmethod  = ProxyMethod(lambda self: self.b1)
bmethod2 = ProxyMethod(lambda self: self.b2)

This is more verbose for the common case, but it's more flexible in
cases where the callable may be more complex than a plain getattr().
Actually you can support both, it doesn't have to be either/or; just
check whether the argument to ProxyMethod is a callable and if not,
make it:

from operator import attrgetter

class ProxyMethod(object):
def __init__(self, proxy_attr, name=None):
if not callable(proxy_attr):
proxy_attr = attrgetter(proxy_attr)
...

Remaining Implementation is left as an exercise to the reader ;)

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


Re: text processing SOLVED

2008-09-27 Thread [EMAIL PROTECTED]

Thanks Black Jack
Working
--
http://mail.python.org/mailman/listinfo/python-list


Re: Are spams on comp.lang.python a major nuisance?

2008-09-27 Thread Skip Montanaro
 CMIIW correct me if I'm wrong.  Google Groups is a Usenet/c-l-py
 gateway.  Other gateways aren't contributing to spam.  What are they
 doing that G-Groups is not?

Actually Google Groups appears to be just displaying the Usenet
newsgroup
comp.lang.python.  The spam filtering which is the topic of this
thread
is applied to the mailing list python-list@python.org side of things.
The
gateway between the mailing list and the Usenet newsgroup is on
mail.python.org I believe.

As to what Google Groups isn't doing, it's not clear.  I just visited
this
group and saw lots of spam.  My guess is that we on the mailing list
side
of things don't see a lot of that because of the spam filter.  It
seems
Google Groups makes it more difficult to report/eliminate spam than
other
more traditional Usenet newsgroup software might.  First you need to
view
the message (even though it's frequently obvious from the subject
alone
that it's spam), then click the More Options link, then the Report
Message link, then type something in the description field of the
form they display and click the Submit button.  After that, who knows
how long it takes for them to send out a Usenet cancel message?  Most
people probably see the subject and move on to the next message.

In short, it would appear that Google makes it harder to cancel spam
than they ought to.  Why they don't have spam filters similar to
what's
on Gmail to trap this stuff is unclear.

Skip

(Sent via Google Groups, so Grant will probably not see this...)
--
http://mail.python.org/mailman/listinfo/python-list


Re: is decorator the right thing to use?

2008-09-27 Thread George Sakkis
On Sep 27, 11:27 am, George Sakkis [EMAIL PROTECTED] wrote:

 If you want to eliminate completely specifying attributes with
 strings, it's easy to modify the above so that you write instead:

 class A(Proxy):
 ...
 bmethod  = ProxyMethod(lambda self: self.b1)
 bmethod2 = ProxyMethod(lambda self: self.b2)

It's funny how often you come with a better solution a few moments
after htting send! The snippet above can (ab)use the decorator syntax
so that it becomes:

class A(Proxy):

@ProxyMethod
def bmethod(self):
return self.b1

@ProxyMethod
def bmethod2(self):
return self.b2

With the observation that ProxyMethod has access both to the callable
that returns the delegate and the name of the delegated method, we can
remove the need for the metaclass and the Proxy base class altogether:

class proxymethod(object):
def __init__(self, get_delegate):
self._get_delegate = get_delegate

def __get__(self, proxy, proxytype):
if proxy is not None:
return self.__get_target_attr(proxy)
else:
return self.__unbound_method

def __unbound_method(self, proxy, *args, **kwds):
method = self.__get_target_attr(proxy)
return method(*args, **kwds)

def __get_target_attr(self, proxy):
get_delegate = self._get_delegate
try: return getattr(get_delegate(proxy),
get_delegate.__name__)
except AttributeError:
raise AttributeError('%r object has no attribute %r' %
(proxy.__class__.__name__, get_delegate.__name__))


class A(object):

def __init__(self, b1, b2):
self.b1 = b1
self.b2 = b2

def amethod(self,a):
print A::mymethod,a

@proxymethod
def bmethod(self):
return self.b1

@proxymethod
def bmethod2(self):
return self.b2


a = A(B(10), B(20))
a.amethod('foo')

print bound proxy calls
a.bmethod('foo')
a.bmethod2('bar','baz')

print unbound proxy calls
A.bmethod(a,'foo')
A.bmethod2(a,'bar','baz')

So back to the OP's original question and after a long circle.. a
decorator might well be the right thing to use after all :)

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


Re: how to replace and string in a SELECT ... IN ()

2008-09-27 Thread Michael Mabin
If the inputs are edited prior to the construction of the string and these
fields are used for more than one update then it's not an exploit.  It's
simply a matter not repeating yourself when coding.
In this particular case too, we're talking about a list of integers that
gets inserted into a string.  If the list is validated prior to its
insertion into an SQL statement then there is no exploit.  If I write a
batch program (not a web program) that retrieves this list of integers from
other sources and validates the data prior to using it in an SQL statement,
that should be sufficient.

As far as wrong and right is concerned. I think it's more about doing what
is appropriate according to the circumstances.  As a rule you should only
code what is appropriate for the circumstances.  If it's appropriate to code
more simply without introducing unnecessary complexity you should do so.

I work in the data warehousing ETL world, where we have to perform field
edits or transformations to load source data into databases.  If I'm already
performing edits on these fields and if these fields are going to be used
for more updates downstream, it's wasteful to perform them again when I
build the SQL insert with the list and execute it.

Finally, whatever happened to the practice of granting appropriate
privileges to IDs that perform database operations?  Shouldn't the person
acting in the capacity of DBA ensure that the user updating or retrieving
data from the database does not have DROP, ALTER, or CREATE privileges on
that database?

On Sat, Sep 27, 2008 at 9:14 AM, Tino Wildenhain [EMAIL PROTECTED] wrote:

 Hi,

 Michael Mabin wrote:

 so you wouldn't object then to something like
  ' in (%)' % ','.join([str_edit_for_exploit(x) for x in
 aList])
 if str_edit_for_exploit applied security edits?


 Whats an security edit btw? If it is something meant to turn possibly
 insecure data into 'secure' then, no I would still object.
 Why? Because its a bad example of default permit. Its always better
 to have a whitelist - even more so when its so easy to do.

 Its just a habit you develope - if you never do it right, how would you
 know when and how to do it right when you need to?

 Tino




-- 
| _ | * | _ |
| _ | _ | * |
| *  | * | * |
--
http://mail.python.org/mailman/listinfo/python-list

Borg vs Singleton vs OddClass

2008-09-27 Thread Lie
This is probably unrelated to Python, as this is more about design
pattern. I'm asking your comments about this design pattern that is
similar in functionality to Singleton and Borg: to share states.

I'm thinking about this design pattern (I don't know if anyone has
ever thought of this pattern before):

class OddClass(object):
def __init__(self):
global OddClass
OddClass = self
def __call__():
return self

The OddClass is a class that would overwrite its own class definition
at its first instantiation. OddClass defines __call__ so that
subsequent instantiation (technically it is no more an
instantiation, but Duck Typing says it does) of the class would return
the single instance.

It do have a problem though, that you can't do isinstance(a, OddClass)
since the name OddClass no longer refers to the OddClass class
descriptor, but to an instance of OddClass. I don't think that's much
of a problem though since using isinstance() is generally not a good
idea in python (although OddClass do use global which many people,
including me, would usually consider as bad form).

The problem with Borg is that it is not inheritable (in certain
sense[1]) and only work with old-style class (which is due to be
completely removed on py3k)[2], Singleton and OddClass is inheritable.

 class Singleton(object): ...
 s = Singleton()
 class A(Singleton): pass
 class B(Singleton): pass
 a = A()
 b = B()
 s.foo, a.bar = bar, 42
 b.foo, b.bar
... Traceback, Attribute Error ...

 class OddClass(object): ...
 s = OddClass()
 class A(OddClass): pass
 class B(OddClass): pass
 a = A()
 b = B()
 s.foo, a.bar = bar, 42
 b.foo, b.bar
... Traceback, Attribute Error ...

but for Borg, see [1]

[1] classes that inherits from Borg shares state not only within
children, but also with their parents and cousins. That means
inheriting from Borg is useless, and that also means one Borg code for
every state sharing classes, instead of inheriting from Singleton/
OddClass. In code:
 class Borg: ...
 class A(Borg): ...
 class B(Borg): ...
 s, a, b = Borg(), A(), B()
 s.foo, a.attr = bar, 42
 b.foo, b.attr
bar 42
 # we want b.foo and b.attr to raise error since .foo, and .bar isn't B's 
 shared state, it's A's and Borg's shared state

[2] Actually in new-style class, they say Borg can use __slots__, but
they say it'd be slightly more complex
--
http://mail.python.org/mailman/listinfo/python-list


Re: python for *nix system admins

2008-09-27 Thread Michael Mabin
import commands ?

On Sat, Sep 27, 2008 at 8:06 AM, George Boutsioukis
[EMAIL PROTECTED]wrote:

 On Sat, 27 Sep 2008 10:05:01 +0200, Lars Stavholm wrote:

  Hi All,
 
  I'm new to this list and hoping that this is not off-topic. If it is,
  please point me in the right direction.
 
  I seem to recollect a python module or library for *nix sysadmins, but I
  can't for the life of me find it again.
 
  The module (or library) somehow added unix command capabilities to the
  python language. It seemed like a lesser known, perhaps new, python
  library or module.
 
  Any input or ideas appreciated
  /Lars Stavholm

 The only modules I've come across that barely fit your description are
 python-unixtools(gzip, bzip only) and shutil(some limited capabilities).
 Running unix commands is usually done directly(os.popen, os.system) on
 *nix platforms. Why(and how) would anyone rewrite them as python modules?
 --
 http://mail.python.org/mailman/listinfo/python-list




-- 
| _ | * | _ |
| _ | _ | * |
| *  | * | * |
--
http://mail.python.org/mailman/listinfo/python-list

Re: python for *nix system admins

2008-09-27 Thread Eric Wertman
I've been growing a library of my own functions, that use the names of
unix commands.  They are just conveniences, of course, but I'd suggest
the same for sysadmins, it's handy.
--
http://mail.python.org/mailman/listinfo/python-list


Re: python for *nix system admins

2008-09-27 Thread Sebastian Bassi
On Sat, Sep 27, 2008 at 3:32 PM, Eric Wertman [EMAIL PROTECTED] wrote:
 I've been growing a library of my own functions, that use the names of
 unix commands.  They are just conveniences, of course, but I'd suggest
 the same for sysadmins, it's handy.

Can you share it?

Best,
SB.
--
http://mail.python.org/mailman/listinfo/python-list


File modifications

2008-09-27 Thread aditya shukla
Hello folks ,

I have a file like this

/T_0_size=105((-bin-ulockmgr_server:0.99[NHX:C=0.195.0],(((-bin-hostname:0.00
[NHX:C=200.0.0],
(-bin-dnsdomainname:0.00[NHX:C=200.0.0],(-bin-domainname:0.00[NHX:C=200.0.0],(-bin-nisdomainname:0.00[NHX:C=200.0.0],-bin-ypdomainname:0.00[NHX:C=200.0.0]):0.00):0.00):0.00):0.98

,(-bin-iptables-xml:0.97[NHX:C=0.183.0],(-bin-dbus-send:0.78[NHX:C=0.94.0],-bin-dbus-monitor:0.78[NHX:C=0.94.0]):0.97):0.98):0.99.

I wanna get the file in this format

((-bin-ulockmgr_server:0.99,(((-bin-hostname:0.00,(-bin-dnsdomainname:0.00,(-bin-domainname:0.00,(-bin-nisdomainname:0.00,-bin-ypdomainname:0.00):0.00):0.00):0.00):0.98

,(-bin-iptables-xml:0.97,(-bin-dbus-send:0.78,-bin-dbus-monitor:0.78):0.97):0.98):0.99

ie , remove /T_0_size , [NHC:C=0.195.0] , [NHX:C=200.0.0] and so  on ,
how should i handle this after reading the file?

Thanks


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

Re: how to replace and string in a SELECT ... IN ()

2008-09-27 Thread Tino Wildenhain

Hi,

Michael Mabin wrote:
If the inputs are edited prior to the construction of the string and 
these fields are used for more than one update then it's not an exploit. 
 It's simply a matter not repeating yourself when coding.


In python we do not fear that.

In this particular case too, we're talking about a list of integers that 
gets inserted into a string.  If the list is validated prior to its 


Its a list, if it indeed has integers in it is uncertain. It is so very
easy to check that that it doesnt even make sense to write such lengthy
emails about how bad you want to avoid it. Just do it. And even more so
if you are telling others how to do things make sure they do not so easy
shoot themselfes in their feet.

insertion into an SQL statement then there is no exploit.  If I write a 
batch program (not a web program) that retrieves this list of integers 
from other sources and validates the data prior to using it in an SQL 
statement, that should be sufficient.  


This might be well true but if you have a look at your original 
contribution you see that all these your asumtions are just not in.


As far as wrong and right is concerned. I think it's more about doing 
what is appropriate according to the circumstances.  As a rule you 


If its easy to do, why not just doing it correctly (or robust) in all
circumstances to just avoid overlooking a case?

should only code what is appropriate for the circumstances.  If it's 
appropriate to code more simply without introducing unnecessary 
complexity you should do so.


But you did not tell us about your asumtations about the circumstances.

I work in the data warehousing ETL world, where we have to perform field 
edits or transformations to load source data into databases.  If I'm 


Thats wrong. You do not edit fields. You have a validating type path 
and _always_ the database is most authoritative about what it accepts.

Any other concept is just wrong and outright dangerous. There are
many examples of how this works out (just check bugtraq)

already performing edits on these fields and if these fields are going 
to be used for more updates downstream, it's wasteful to perform them 
again when I build the SQL insert with the list and execute it. 


I still don't know what you mean by edit ;) If you mean filter out
special chars with for example replace(bad stuff,good stuff) check
your idea again, this is not going to work. (google for default permit)

Finally, whatever happened to the practice of granting appropriate 
privileges to IDs that perform database operations?  Shouldn't the 
person acting in the capacity of DBA ensure that the user updating or 
retrieving data from the database does not have DROP, ALTER, or CREATE 
privileges on that database? 


This of course is another layer which should be added - but you would
not need to - you edited the fields, right? ;)

Sorry, it was not meant to put you to the wall but you insist so much
on your still dangerous solution while top posting the hell out of
this thread I just could not ignore it ;)

T.


smime.p7s
Description: S/MIME Cryptographic Signature
--
http://mail.python.org/mailman/listinfo/python-list

Re: What do you call a class not intended to be instantiated

2008-09-27 Thread Terry Reedy

Aahz wrote:

In article [EMAIL PROTECTED],
Ben Finney  [EMAIL PROTECTED] wrote:

Steven D'Aprano [EMAIL PROTECTED] writes:



I'd like to be able to call [a class] as if it were a function.
Normally calling a class object returns an instance -- I wish to
return something else.

In that case, you *don't* want a class at all; the entire point of a
class is to define behaviour for instances.


Absolutely agreed with your first clause, disagreed about the second
clause.  As I said earlier, the main point of a class singleton is to get
the effect of a module singleton without the need to create another file
on disk.


In 3.0, at least, one does not need a disk file to create a module.

 import types
 me = types.ModuleType('me') # type(__builtins__) works, no import
 me
module 'me' (built-in)
 me.a = 1
 me.a
1
 me.a + 1
2

That said, a blank class is even easier, and the representation is better.

tjr

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


check if file is MS Word or PDF file

2008-09-27 Thread A. Joseph
What should I look for in a file to determine whether or not it is a
MS Word file or an Excel file or a PDF file, etc., etc.? including Zip
files

I don`t want to check for file extension.
os.path.splitext('Filename.jpg') will produce a tuple of filename and
extension, but some file don`t even have extension and can still be read by
MS Word or NotePad. i want to be 100% sure of the file.
--
http://mail.python.org/mailman/listinfo/python-list

Abstract Base Class register function

2008-09-27 Thread Mikolai Fajer
I have been experimenting with the abc module in py3k and thought
about using the register method of an ABC as a class decorator:

code
import abc
class MyABC(metaclass=abc.ABCMeta):
pass

@MyABC.register
class MySub():
pass
/code

This doesn't work because the register method returns None.  It would
be a fairly simple modification to have this work:

code
def register(cls, subclass):
Register a virtual subclass of an ABC.
... etc ...
return subclass
/code

What do people think of this behavior?

-- 

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


Hello boys!

2008-09-27 Thread Milenko Stojadinovic Cvrcko
Hello, this is Milenko Stojadinovic from town Banjaluka,
Bosnia and Herzegovina, also known as Cvrcko
Does anyone know of any bars in town where I can
swallow a bucket of cum? It can be either dog,
horse or human cum. Also, does anyone know of
any sex bars where people will shit in your mouth?
I also like eating shit.

--
Name: Mileno Stojadinovic - Cvrcko
Street adress: Sime Matavulja 12
Town: 78000 Banja Luka
Country: Bosnia and Herzegovina
Home phone: +38751/303-665
Cell phone: +38765/499-312
Email adress: [EMAIL PROTECTED]

~

The new pumpkin rarely pulls Terrance, it teases Sharon instead.  For
Susan the tape's sad, beside me it's unique, whereas against you it's
believing dirty.  Hey, go reject a fork!  Why did Alice open
throughout all the boats?  We can't explain poultices unless
Woody will mercilessly judge afterwards.  The frames, disks, and
shirts are all fat and fresh.  Who will we dine after Edwina
wastes the thin mirror's goldsmith?  It's very outer today, I'll
recollect strangely or Christopher will learn the teachers.
Hardly any humble brave tyrants hourly solve as the tired wrinkles
cover.

Hardly any distant buttons are short and other urban ointments are
filthy, but will Robette receive that?

Let's lift behind the deep highways, but don't promise the heavy
diets.  Who kicks badly, when Melvin burns the stale code before the
autumn?  Get your absolutely moulding barber within my cellar.  If you
will
laugh Gay's hill against porters, it will incredibly climb the
case.  Some shopkeepers arrive, irrigate, and shout.  Others
sadly expect.  To be pathetic or sticky will talk abysmal oranges to
wickedly look.

Are you healthy, I mean, moving above clever onions?  While farmers
partly taste pins, the powders often excuse against the blunt
jackets.  Generally Susanne will order the sticker, and if George
actually seeks it too, the bowl will attempt with the polite
lane.  He can hate durable kettles above the rural bad ocean, whilst
Oscar easily scolds them too.  You eventually fill against Norma when
the
kind drapers irritate among the poor summer.  As surprisingly as
Dolf converses, you can dye the cap much more familiarly.  Brion,
still
killing, behaves almost eerily, as the sauce changes on their
coffee.  You won't recommend me grasping about your lazy office.

Almost no butchers steadily live the lost signal.  Cyrus's hat
improves among our desk after we sow towards it.  Ralph measures the
weaver within hers and wanly calls.  Some cosmetic tags answer
David, and they rigidly walk Quincy too.  When Richard's elder
gardner dreams, Mark cares for weak, closed islands.  He might
strongly fear think and plays our cheap, sour painters above a
bathroom.  I creep the active yogi and cook it in back of its
dorm.  Tell Katherine it's strong loving within a tree.  Why will you
jump the angry lower exits before Murray does?  I am unbelievably
bitter, so I wander you.  How does Hector smell so regularly, whenever
Ronald likes the solid twig very slowly?

Julieta, have a hot printer.  You won't clean it.  Fucking don't
join a dryer!  She wants to nibble inner smogs under Usha's castle.
She'd rather
depart grudgingly than help with Bernadette's younger grocer.  Other
old dark cards will comb frantically alongside cans.  Try pouring the
monument's pretty cat and Oliver will attack you!  Don't try to
seek halfheartedly while you're jumping throughout a easy carpenter.

He'll be climbing in front of good Cypriene until his enigma
answers quietly.  What doesn't Janet smell inadvertently?  They are
opening before the rain now, won't explain walnuts later.  Some
light long game covers pools outside Woodrow's rich film.  Why did
Oscar judge the pear with the handsome spoon?  He will talk nearly if
Julieta's tailor isn't wet.

Just looking beside a ulcer through the store is too young for
Woody to care it.  Both filling now, Alejandro and Marty irritated the
open rivers about smart envelope.  Occasionally, dusts kill beside
rude fires, unless they're sweet.  Her pen was sharp, dull, and
fears over the spring.  Zack, on floors difficult and upper,
attacks towards it, recollecting seemingly.  We measure the raw
sauce.

They are rejecting throughout quiet, towards empty, in back of
cold units.  My wide potter won't clean before I comb it.  If you'll
pour Edward's camp with aches, it'll admiringly converse the
cup.  I was promising frogs to worthwhile Corinne, who's walking
in back of the counter's stable.  It can receive clean pickles, do you
solve them?  Many jugs will be weird lean carrots.  Roger helps, then
Walt stupidly believes a ugly lentil on Catherine's road.  We
tease them, then we weekly dream Zack and Annabel's blank candle.
A lot of shallow dose or canyon, and she'll locally excuse everybody.
If the
bizarre balls can sow bimonthly, the hollow raindrop may love more
ventilators.  We laugh weekly, unless Jezebel grasps shoes outside
Jimmie's puddle.  Jimmy!  You'll mould plates.  Just now, I'll
dine the 

Configuring pyc directory

2008-09-27 Thread Robert Moore
Is there a way to configure python to read/write compiled pyc files for
modules in a directory other than the directory containing the original py
files?

I'm trying trying to secure an Apache server running mod_python and don't
want the process compiling the pyc files to have write access to the folder
containing my site's py modules.  I realize the solution (if it exists) may
lie with mod_python rather than python itself, so I've also pinged the
mod_python mailing list for help.  I'm checking here as well, though, just
in case there's some solution built into python.

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

Re: check if file is MS Word or PDF file

2008-09-27 Thread Chris Rebert
On Sat, Sep 27, 2008 at 2:43 PM, A. Joseph [EMAIL PROTECTED] wrote:
 What should I look for in a file to determine whether or not it is a
 MS Word file or an Excel file or a PDF file, etc., etc.? including Zip
 files

 I don`t want to check for file extension.
 os.path.splitext('Filename.jpg') will produce a tuple of filename and
 extension, but some file don`t even have extension and can still be read by
 MS Word or NotePad. i want to be 100% sure of the file.

Well, if you're on unix, you could run the 'file' command and check
its output using the 'subprocess' module, but it sounds like you're on
Windows...

Regards,
Chris
-- 
Follow the path of the Iguana...
http://rebertia.com

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

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


Re: Using the 'with' statement with cStringIO objects

2008-09-27 Thread peppergrower
Thanks for the help.  I'm fairly new to programming (which you
probably could have guessed...).  When I realized that you could use a
StringIO instance as if it were a file, I wanted to try some of the
same techniques on it as I would with a file.  In this case, I wanted
to use a for line in testfile construction to iterate over the
StringIO instance.  (I did find a better way for my particular case,
one that didn't involve StringIO at all.)  When I got that particular
error, I suspected that it had something to do with the relative
newness of the 'with' statement.

If this is something that should be considered for addition in the
future, is there somewhere specific I should suggest that?
--
http://mail.python.org/mailman/listinfo/python-list


Re: multiprocessing eats memory

2008-09-27 Thread redbaron
 When processing data in parallel you will use up as muchmemoryas
 many datasets you are processing at any given time.
Worker processes eats 2-4 times more than I pass to them.


If you need to
 reducememoryuse then you need to start fewer processes and use some
 mechanism to distribute the work on them as they become free. (see
 recommendation that uses Queues)
I don't understand how could I use Queue here? If worker process
finish computing, it puts its' id into Queue, in main process I
retrieve that id and how could I retrieve result from worker process
then?

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


Re: check if file is MS Word or PDF file

2008-09-27 Thread Michael Crute
On Sat, Sep 27, 2008 at 5:43 PM, A. Joseph [EMAIL PROTECTED] wrote:
 What should I look for in a file to determine whether or not it is a
 MS Word file or an Excel file or a PDF file, etc., etc.? including Zip
 files

 I don`t want to check for file extension.
 os.path.splitext('Filename.jpg') will produce a tuple of filename and
 extension, but some file don`t even have extension and can still be read by
 MS Word or NotePad. i want to be 100% sure of the file.

You could use the mimetypes module...

 import mimetypes
 mimetypes.guess_type(LegalNotices.pdf)
 ('application/pdf', None)

-mike

-- 

Michael E. Crute
http://mike.crute.org

God put me on this earth to accomplish a certain number of things.
Right now I am so far behind that I will never die. --Bill Watterson
--
http://mail.python.org/mailman/listinfo/python-list


Re: Hello boys!

2008-09-27 Thread default
On Sat, 27 Sep 2008 14:56:07 -0700 (PDT), Milenko Stojadinovic Cvrcko
[EMAIL PROTECTED] wrote:

Hello, this is Milenko Stojadinovic from town Banjaluka,
Bosnia and Herzegovina, also known as Cvrcko
Does anyone know of any bars in town where I can
swallow a bucket of cum? It can be either dog,
horse or human cum. Also, does anyone know of
any sex bars where people will shit in your mouth?
I also like eating shit.

Come to the US and park your mouth in front of George Bush - all the
Bshit you can eat - and it keeps on coming!

I have a buddy in Bosna - he's normal.

-- 


== Posted via Pronews.Com - Unlimited-Unrestricted-Secure Usenet News==
http://www.pronews.com The #1 Newsgroup Service in the World! 100,000 
Newsgroups
---= - Total Privacy via Encryption =---
--
http://mail.python.org/mailman/listinfo/python-list


Re: Hello boys!

2008-09-27 Thread Jim Thompson

On Sat, 27 Sep 2008 18:47:16 -0400, default [EMAIL PROTECTED]
wrote:

On Sat, 27 Sep 2008 14:56:07 -0700 (PDT), Milenko Stojadinovic Cvrcko
[EMAIL PROTECTED] wrote:

Hello, this is Milenko Stojadinovic from town Banjaluka,
Bosnia and Herzegovina, also known as Cvrcko
Does anyone know of any bars in town where I can
swallow a bucket of cum? It can be either dog,
horse or human cum. Also, does anyone know of
any sex bars where people will shit in your mouth?
I also like eating shit.

Come to the US and park your mouth in front of George Bush - all the
Bshit you can eat - and it keeps on coming!

I have a buddy in Bosna - he's normal.

Now you know why I blanket kill-file googlegroups.

...Jim Thompson
-- 
| James E.Thompson, P.E.   |mens |
| Analog Innovations, Inc. | et  |
| Analog/Mixed-Signal ASIC's and Discrete Systems  |manus|
| Phoenix, Arizona  85048Skype: Contacts Only  | |
| Voice:(480)460-2350  Fax: Available upon request |  Brass Rat  |
| E-mail Icon at http://www.analog-innovations.com |1962 |
 
Viewed from afar, even whores and Democrats seem reputable
--
http://mail.python.org/mailman/listinfo/python-list


Re: check if file is MS Word or PDF file

2008-09-27 Thread Chris Rebert
On Sat, Sep 27, 2008 at 3:42 PM, Michael Crute [EMAIL PROTECTED] wrote:
 On Sat, Sep 27, 2008 at 5:43 PM, A. Joseph [EMAIL PROTECTED] wrote:
 What should I look for in a file to determine whether or not it is a
 MS Word file or an Excel file or a PDF file, etc., etc.? including Zip
 files

 I don`t want to check for file extension.
 os.path.splitext('Filename.jpg') will produce a tuple of filename and
 extension, but some file don`t even have extension and can still be read by
 MS Word or NotePad. i want to be 100% sure of the file.

 You could use the mimetypes module...

  import mimetypes
  mimetypes.guess_type(LegalNotices.pdf)
 ('application/pdf', None)

Looking at the docs for the mimetypes module, it just guesses based on
the filename (and extension), not the actual contents of the file, so
it doesn't really help the OP, who wants to make sure their program
isn't misled by an inaccurate extension.

Regards,
Chris
-- 
Follow the path of the Iguana...
http://rebertia.com


 -mike

 --
 
 Michael E. Crute
 http://mike.crute.org

 God put me on this earth to accomplish a certain number of things.
 Right now I am so far behind that I will never die. --Bill Watterson
 --
 http://mail.python.org/mailman/listinfo/python-list

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


Re: Hello boys!

2008-09-27 Thread default
On Sat, 27 Sep 2008 15:56:39 -0700, Jim Thompson
[EMAIL PROTECTED] wrote:


Now you know why I blanket kill-file googlegroups.

...Jim Thompson
I knew that!

Every now and then one groper will make it back to the scene of his
crime - but, granted, there was no hope for this one.
-- 


== Posted via Pronews.Com - Unlimited-Unrestricted-Secure Usenet News==
http://www.pronews.com The #1 Newsgroup Service in the World! 100,000 
Newsgroups
---= - Total Privacy via Encryption =---
--
http://mail.python.org/mailman/listinfo/python-list


Re: EPD (Enthought Python Distribution) 4.0.300 Beta 3 available

2008-09-27 Thread Robert Kern

Disclosure: I work for Enthought.

Christopher Brewster wrote:
I have always thought this idea very good, but if I download it and 
install it (on my MacBook pro) will any conflicts occur with existing 
bits and pieces of Python and its libraries?


For the Mac distribution, we have tried very carefully to keep EPD's Python 
separate from any previous installation. I believe the only thing that will get 
overwritten is that our bin/ directory inside our version of Python.framework 
will get prepended to your $PATH environment variable. This will be added to 
your ~/.bash_profile with a a descriptive comment. When you type


  $ python

at your Terminal prompt, you will get EPD's Python. To uninstall EPD, you can 
remove those lines in your ~/.bash_profile, delete 
/Library/Frameworks/Python.framework/Versions/4.0.300/, and delete 
/Applications/EPD something or other/. Then your previous Python 
installation should be usable again.


To just use your previous Python installation without uninstalling EPD, just 
comment out our addition to ~/.bash_profile.


If you have more questions about EPD, please join us on the enthought-dev 
mailing list:


  https://mail.enthought.com/mailman/listinfo/enthought-dev

--
Robert Kern

I have come to believe that the whole world is an enigma, a harmless enigma
 that is made terrible by our own mad attempt to interpret it as though it had
 an underlying truth.
  -- Umberto Eco

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


Re: Hello boys!

2008-09-27 Thread Cydrome Leader
In rec.crafts.metalworking Jim Thompson [EMAIL PROTECTED] wrote:
 
 On Sat, 27 Sep 2008 18:47:16 -0400, default [EMAIL PROTECTED]
 wrote:
 
On Sat, 27 Sep 2008 14:56:07 -0700 (PDT), Milenko Stojadinovic Cvrcko
[EMAIL PROTECTED] wrote:

Hello, this is Milenko Stojadinovic from town Banjaluka,
Bosnia and Herzegovina, also known as Cvrcko
Does anyone know of any bars in town where I can
swallow a bucket of cum? It can be either dog,
horse or human cum. Also, does anyone know of
any sex bars where people will shit in your mouth?
I also like eating shit.

Come to the US and park your mouth in front of George Bush - all the
Bshit you can eat - and it keeps on coming!

I have a buddy in Bosna - he's normal.
 
 Now you know why I blanket kill-file googlegroups.

So you and everybody can talk about them nonstop?
--
http://mail.python.org/mailman/listinfo/python-list


Re: What do you call a class not intended to be instantiated

2008-09-27 Thread Terry Reedy

Aaron Castironpi Brady wrote:


class A(type):

... def __call__( self, *ar ):
... print 'call', self, ar
...

class B(object):

... __metaclass__= A
...

B(3)

call class '__main__.B' (3,)

Overriding the __call__ method of 'type' has the effect of giving you
a static __call__ method on a class-- a method which doesn't need an
instance to call.  Your behavior may be counterintuitive though, to
someone who wants to instantiate 'B', in this case, and proceed like a
normal object.  That is, they want to call a generic class and use it,
and also expect instances of B to behave as B.  You can't have both,
so either return B from B.__new__, or, to instantiate B, take the long
way and call B.__new__ directly.


B.__new__(B)

__main__.B object at 0x009FDB70

Has anyone stepped through the C code to find out when the decision is
made to call which function, B.__new__ or A.__call__, when B is
called?  


For Python coded objects, ob(*args) in code translates to internal 
execution of type(ob).__call__(ob, *args) (without further 
translation!).  The interpreter compiles a statement at a time, without 
looking back to do type inferencing, and so does not know what type is 
being called or if it is even callable.


For B, B(*args) == type(B).__call__(B, *args) == A.__call__(B, *args). 
So there is no decision.


For C coded objects, I believe ob(*args) in Python code translate to a C 
call of the C equivalent of type(ob).tp_call (or something like that). 
From observation, type.tp_call acts something like this:


def __call__(cls, *args):
  if cls == type:
if len(*args):
  return arg[0].__class__
elif len(*args) == 3:
  return type.__new__(type, *args) # or maybe not pass type?
else:
  raise TypeError('type() takes 1 or 3 arguments')
  else:
return cls.__new__(cls, *args)

So, for a normal class C (an instance of type), type.__call__ calls 
C.__new__.


Terry Jan Reedy


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


Re: What do you call a class not intended to be instantiated

2008-09-27 Thread Aaron Castironpi Brady
On Sep 27, 6:16 pm, Terry Reedy [EMAIL PROTECTED] wrote:
 Aaron Castironpi Brady wrote:
  class A(type):
  ...     def __call__( self, *ar ):
  ...             print 'call', self, ar
  ...
  class B(object):
  ...     __metaclass__= A
  ...
  B(3)
  call class '__main__.B' (3,)

  Overriding the __call__ method of 'type' has the effect of giving you
  a static __call__ method on a class-- a method which doesn't need an
  instance to call.  Your behavior may be counterintuitive though, to
  someone who wants to instantiate 'B', in this case, and proceed like a
  normal object.  That is, they want to call a generic class and use it,
  and also expect instances of B to behave as B.  You can't have both,
  so either return B from B.__new__, or, to instantiate B, take the long
  way and call B.__new__ directly.

  B.__new__(B)
  __main__.B object at 0x009FDB70

  Has anyone stepped through the C code to find out when the decision is
  made to call which function, B.__new__ or A.__call__, when B is
  called?  

 For Python coded objects, ob(*args) in code translates to internal
 execution of type(ob).__call__(ob, *args) (without further
 translation!).  The interpreter compiles a statement at a time, without
 looking back to do type inferencing, and so does not know what type is
 being called or if it is even callable.

 For B, B(*args) == type(B).__call__(B, *args) == A.__call__(B, *args).
 So there is no decision.

 For C coded objects, I believe ob(*args) in Python code translate to a C
 call of the C equivalent of type(ob).tp_call (or something like that).
  From observation, type.tp_call acts something like this:

 def __call__(cls, *args):
    if cls == type:
      if len(*args):
        return arg[0].__class__
      elif len(*args) == 3:
        return type.__new__(type, *args) # or maybe not pass type?
      else:
        raise TypeError('type() takes 1 or 3 arguments')
    else:
      return cls.__new__(cls, *args)

 So, for a normal class C (an instance of type), type.__call__ calls
 C.__new__.

 Terry Jan Reedy

Oh, I see.  Then it's the class statement that calls type.__new__.

class A: ...
- A= type( 'A', ... )
- A= type.__call__( type, 'A', ... )
- A= type.__new__( type, 'A', ... )

Plus an iteration over the contents of 'namespace', to search for
properties that themselves have a __get__ method.  And returns an
unboundmethod instance of it, for a value of of that's hard to
concentrate on.  I jest.

Perhaps what Steven is looking for is a subclass of 'type' that does
not give this default behavior of 'unboundmethoding' everything it
can.  That is, defaulting to 'staticmethod' or 'classmethod', and
perhaps offering a 'boundmethod' decorator for the exceptions.

For the case of '__call__', which he does want to control, that could
merely call B.__call__, instead of B.__new__.  Untested:

 class A(type):
... def __call__( self, *ar ):
... return self.__call__( *ar )

or

... return self.__call__( self, *ar )

Which would come through to 'B' as:

 class B(object):
... __metaclass__= A
... def __call__( cls, *ar ).

This is because self == B in the example.  This makes me scowl.  Very
odd.
--
http://mail.python.org/mailman/listinfo/python-list


Re: check if file is MS Word or PDF file

2008-09-27 Thread Sean DiZazzo
On Sep 27, 4:01 pm, Chris Rebert [EMAIL PROTECTED] wrote:
 On Sat, Sep 27, 2008 at 3:42 PM, Michael Crute [EMAIL PROTECTED] wrote:
  On Sat, Sep 27, 2008 at 5:43 PM, A. Joseph [EMAIL PROTECTED] wrote:
  What should I look for in a file to determine whether or not it is a
  MS Word file or an Excel file or a PDF file, etc., etc.? including Zip
  files

  I don`t want to check for file extension.
  os.path.splitext('Filename.jpg') will produce a tuple of filename and
  extension, but some file don`t even have extension and can still be read by
  MS Word or NotePad. i want to be 100% sure of the file.

  You could use the mimetypes module...

   import mimetypes
   mimetypes.guess_type(LegalNotices.pdf)
  ('application/pdf', None)

 Looking at the docs for the mimetypes module, it just guesses based on
 the filename (and extension), not the actual contents of the file, so
 it doesn't really help the OP, who wants to make sure their program
 isn't misled by an inaccurate extension.

 Regards,
 Chris
 --
 Follow the path of the Iguana...http://rebertia.com



  -mike

  --
  
  Michael E. Crute
 http://mike.crute.org

  God put me on this earth to accomplish a certain number of things.
  Right now I am so far behind that I will never die. --Bill Watterson
  --
 http://mail.python.org/mailman/listinfo/python-list

Check http://sourceforge.net/project/showfiles.php?group_id=23617

for the 'file' command for Windows.

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


Re: how to replace and string in a SELECT ... IN ()

2008-09-27 Thread Michael Mabin
I'm exhausted, so I'll just shut up about this after a few final words.
1.  edits is used in data warehousing to describe data scrubbing or
filtering of fields in records that are used as input sources for loading
into data warehouses. It's a term that goes way back to batch processing on
the mainframe, so it's been used this way for a long time. Sometimes we use
'validation' interchangeably with 'edit' but our use of validation usually
involves a check of input data against business rules and not type or range
checking which we consider 'edits'.  So maybe you're not used to hearing the
term used this way, but it is a variation perhaps of what you're used to.

2.  The data warehousing world is quite different from the web world in many
respects.  I appreciate the fact that web application developers must always
be mindful of the 'barbarians at the gates' but our batch environments are
locked down, especially our databases.  We have secured batch IDs. Our
programs are run using an automated schedule.  Our databases are secured to
begin with so not even our batch IDs have alter, create or drop permissions
on the database.  There's no way this exploit would ever enter this
environment because those servers aren't accessible through the web or
online.

3.  When you say 'in python we don not fear that' it's curious, because it
assumes that all Python users must think as you do.  And yet, clearly I
don't think as you do.  I really like this language and praise the
Netherlands each day I wake up that they gave us someone as brilliant as
Guido to make programming fun and not such a chore.  But I think there are
valid reasons for taking different approaches to security, data validation
and dare I say it -- field editing -- despite the claims of many who say
that in Python - TOOWTDI.

4. It's also curious that I was obliged to state my assumptions about batch
programming vs. web programming.  There is nothing in the OP to suggest that
the problem was related to web programming.  It's a question about how to
interpolate the values in a list with format specifiers in a SQL statement.
 Still, if this list is not the result of user input but was derived within
the body of the program, which by itself has no malicious intent, are we
still going to code this as if it were input by a user that might be a
hacker?  This seems retarded and paranoid to me.  And where in that post
does it say that the list is from web input?  Although to be fair maybe most
of the Python community is doing web development.

Thanks for the stimulating and educational discussion.

On Sat, Sep 27, 2008 at 4:30 PM, Tino Wildenhain [EMAIL PROTECTED] wrote:

 Hi,

 Michael Mabin wrote:

 If the inputs are edited prior to the construction of the string and these
 fields are used for more than one update then it's not an exploit.  It's
 simply a matter not repeating yourself when coding.


 In python we do not fear that.

  In this particular case too, we're talking about a list of integers that
 gets inserted into a string.  If the list is validated prior to its


 Its a list, if it indeed has integers in it is uncertain. It is so very
 easy to check that that it doesnt even make sense to write such lengthy
 emails about how bad you want to avoid it. Just do it. And even more so
 if you are telling others how to do things make sure they do not so easy
 shoot themselfes in their feet.

  insertion into an SQL statement then there is no exploit.  If I write a
 batch program (not a web program) that retrieves this list of integers from
 other sources and validates the data prior to using it in an SQL statement,
 that should be sufficient.


 This might be well true but if you have a look at your original
 contribution you see that all these your asumtions are just not in.

  As far as wrong and right is concerned. I think it's more about doing what
 is appropriate according to the circumstances.  As a rule you


 If its easy to do, why not just doing it correctly (or robust) in all
 circumstances to just avoid overlooking a case?

  should only code what is appropriate for the circumstances.  If it's
 appropriate to code more simply without introducing unnecessary complexity
 you should do so.


 But you did not tell us about your asumtations about the circumstances.

  I work in the data warehousing ETL world, where we have to perform field
 edits or transformations to load source data into databases.  If I'm


 Thats wrong. You do not edit fields. You have a validating type path and
 _always_ the database is most authoritative about what it accepts.
 Any other concept is just wrong and outright dangerous. There are
 many examples of how this works out (just check bugtraq)

  already performing edits on these fields and if these fields are going to
 be used for more updates downstream, it's wasteful to perform them again
 when I build the SQL insert with the list and execute it.


 I still don't know what you mean by edit ;) If you mean filter out
 

Re: Not fully OO ?

2008-09-27 Thread Tim Rowe
2008/9/27 Aaron Castironpi Brady [EMAIL PROTECTED]:

 No way.  It's *zero* instead of one, if so, because the only thing C#
 has is a bunch of handcuffs and implicit 'self'.  You have a line
 like:

You don't follow what I said, and from your tone I get the feeling you
don't *want* to follow what I'm saying, not because I'm criticising
Python (I'm not), but because I'm guilty of the heresy of suggesting
that it's not actually simultaneoulsy optimised for every possible
use.

My point is that there are zero parameters as far as I am concerned
because I don't actually touch most of the GUI code.  There could
actually be hundreds of parameters, for all I care. They're not my
concern. Most of the time I like that -- the tools are doing my work
for me.

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


Re: check if file is MS Word or PDF file

2008-09-27 Thread Michael Crute
On Sat, Sep 27, 2008 at 7:01 PM, Chris Rebert [EMAIL PROTECTED] wrote:
 Looking at the docs for the mimetypes module, it just guesses based on
 the filename (and extension), not the actual contents of the file, so
 it doesn't really help the OP, who wants to make sure their program
 isn't misled by an inaccurate extension.

One other way to detect a pdf is to just read the first 4 bytes from
the file. Valid pdf files start with %PDF-. Something similar can be
done with Word docs but I don't know what the magic bytes are. This
approach is pretty similar to what the file command does but is
probably a better approach if you have to support multiple platforms.

-mike

-- 

Michael E. Crute
http://mike.crute.org

God put me on this earth to accomplish a certain number of things.
Right now I am so far behind that I will never die. --Bill Watterson
--
http://mail.python.org/mailman/listinfo/python-list


Re: Borg vs Singleton vs OddClass

2008-09-27 Thread Miles
Lie wrote:
 This is probably unrelated to Python, as this is more about design
 pattern. I'm asking your comments about this design pattern that is
 similar in functionality to Singleton and Borg: to share states.

 I'm thinking about this design pattern (I don't know if anyone has
 ever thought of this pattern before):

 class OddClass(object):
def __init__(self):
global OddClass
OddClass = self
def __call__():

I'll change this to def __call__(self):

return self

 The OddClass is a class that would overwrite its own class definition
 at its first instantiation. OddClass defines __call__ so that
 subsequent instantiation (technically it is no more an
 instantiation, but Duck Typing says it does) of the class would return
 the single instance.

This seems like a terrible idea to me, but then I never really
understood the appeal of the Singleton pattern, especially in Python.

 Singleton and OddClass is inheritable.

 class OddClass(object): ...
 s = OddClass()
 class A(OddClass): pass

Traceback (most recent call last):
  File stdin, line 1, in module
TypeError: Error when calling the metaclass bases
__init__() takes exactly 1 argument (4 given)

Oops!  And assuming you carefully ordered your code so that OddClass
will never be instantiated before it is subclassed (which seems
fragile), you get behavior like this:

 s = OddClass()
 s is OddClass()
True
 a = A()
 s is OddClass()
False
 a is OddClass()
True
 a is A()
False
 a is OddClass()
False

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


Re: Not fully OO ?

2008-09-27 Thread Aaron Castironpi Brady
On Sep 27, 6:55 pm, Tim Rowe [EMAIL PROTECTED] wrote:
 2008/9/27 Aaron Castironpi Brady [EMAIL PROTECTED]:

  No way.  It's *zero* instead of one, if so, because the only thing C#
  has is a bunch of handcuffs and implicit 'self'.  You have a line
  like:

 You don't follow what I said, and from your tone I get the feeling you
 don't *want* to follow what I'm saying, not because I'm criticising
 Python (I'm not), but because I'm guilty of the heresy of suggesting
 that it's not actually simultaneoulsy optimised for every possible
 use.

 My point is that there are zero parameters as far as I am concerned
 because I don't actually touch most of the GUI code.  There could
 actually be hundreds of parameters, for all I care. They're not my
 concern. Most of the time I like that -- the tools are doing my work
 for me.

 --
 Tim Rowe

flamewar.avert( ), please.  Yes, I agree, I did not follow every
word.  It's a fundamental disagreement about successful ways to
communicate, and, for the philosophers, successful communication,
whether I should have nitpicked first thing, or tried to go along with
the gist.  I tried the latter.  In your case, I guessed wrong.  Sorry.

Before I tried wxFormBuilder, I imagined that C# would be vastly
faster to develop than Python, for anything requiring any non-trivial
graphical interface.  I've done extensive VB, so I can attest to that
personally.  It is not.  The difference in dev times is about the time
it takes to write:

def onClick( event ):
   ...
controlA.bind( wx.MOUSEDOWN, onClick )

perhaps several times, which, glances at watch, is not long.  You do
get the IDE, true, and that code is auto-crafted for you.  But 'wx'
does give you data in an XML file, instead of a script.  And talk
about a difference in identifiers:

form
  button
 pos20,30/pos
 colorgray/color
  /button
/form

vs.

form.button.pos= 20, 30
form.button.color= gray

You can come up with examples that favor either.  But the opposite of
statistical is anecdotal.  Sorry again.

The last time I 'checked in' at your post, your claim was an hour or
so vs. ages.  Hence my responses.  You could probably sneak by by
claiming a factor of *two*, but if you were exaggerating, please say
so at any time.

Penultimately, forgive my sarcasm--- I'm a bit feisty right now.  I
was distinguishing between arguments in particular, and identifiers in
general.

And lastly, simultaneoulsy optimised for every possible use is a
bold claim that I didn't make, at least, to come forward, in so many
words.  I do believe, and it shows, as of today, and you can quote me
on this, that it's pretty generally applicable, though I reserve the
right to change my mind on the matter with or without notice.
Especially if I learn something.  I do not believe that C# is pretty
generally applicable.  I maintain that I will adjust that estimate if
I ever get any facts about C#, since I don't have very many.  (In
fact, outside of my VB, COM, and MFC experience, you could say I have
no clue.  Very tongue in cheek.)

In fact, do a Google for 'castironpi every possible'.  You get a
can't ... every possible, and your post, and something else.  That's
it.

Python has a lot of things C# doesn't.  Can we agree on that?


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


Re: Hello boys!

2008-09-27 Thread default
On Sat, 27 Sep 2008 23:12:59 + (UTC), Cydrome Leader
[EMAIL PROTECTED] wrote:

In rec.crafts.metalworking Jim Thompson [EMAIL PROTECTED] wrote:
 
 On Sat, 27 Sep 2008 18:47:16 -0400, default [EMAIL PROTECTED]
 wrote:
 
On Sat, 27 Sep 2008 14:56:07 -0700 (PDT), Milenko Stojadinovic Cvrcko
[EMAIL PROTECTED] wrote:

Hello, this is Milenko Stojadinovic from town Banjaluka,
Bosnia and Herzegovina, also known as Cvrcko
Does anyone know of any bars in town where I can
swallow a bucket of cum? It can be either dog,
horse or human cum. Also, does anyone know of
any sex bars where people will shit in your mouth?
I also like eating shit.

Come to the US and park your mouth in front of George Bush - all the
Bshit you can eat - and it keeps on coming!

I have a buddy in Bosna - he's normal.
 
 Now you know why I blanket kill-file googlegroups.

So you and everybody can talk about them nonstop?

If you mean Google Groups the condemnation is justified.

Who is them?  Real people do occasionally wander in to GG - or those
without news servers - or without understanding of Usenet.

Basically, in the engineering groups (in particular) outsiders are
welcome.  Engineers are smart, creative and tolerant as a general
rule.  

Lighten up.  Who are you defending?  and Who goes into Usenet with a
thin skin?  Expect ridicule, expect condemnation - water off a duck's
back.

You may think your viewpoint is the only one, the right one, the valid
one - but a few million others may disagree.  And you ain't started to
deal with culture shock - some countries place emphasis on diplomacy _
you know the how are you? stuff, others don't, and seem very cold.

Adapt.
-- 


== Posted via Pronews.Com - Unlimited-Unrestricted-Secure Usenet News==
http://www.pronews.com The #1 Newsgroup Service in the World! 100,000 
Newsgroups
---= - Total Privacy via Encryption =---
--
http://mail.python.org/mailman/listinfo/python-list


Docstrings for attributes?

2008-09-27 Thread Roy Smith
Is there any way to attach a docstring to an attribute?  I see that PEP-257 
talks about attribute docstrings, but it references PDP-258, which was 
rejected.

I suppose I could eschew plain attributes in favor of getter functions, 
because those give me a place to hang a docstring, but that feels like the 
wrong thing to do.
--
http://mail.python.org/mailman/listinfo/python-list


what's difference usage?

2008-09-27 Thread momobear
while as I try to wrap a function using boost-python, I find a strange
situation.
#include iostream
#include string
#include vector
#include boost/python/list.hpp
#include boost/python.hpp

using namespace boost::python;

int printlist(list l){
std::vectorstd::string a;
a.push_back(c++);
a.push_back(javascript);
for (std::vectorstd::string::iterator p = a.begin(); p != a.end(); +
+p)
l.append(*p);
   return 0;
}

BOOST_PYTHON_MODULE(wlist){
   def(printlist, printlist);
}

in the up code,int printlist(list l) at first time I missed add 
left of l. but when I run the following python code,
#!/usr/local/bin/python
a = list()
a.append('linux')
import wlist
wlist.printlist(a)
print a

they get the same result.
linux
c++
javascript

anyone help me figure out what's wrong here. thanks.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Docstrings for attributes?

2008-09-27 Thread alex23
On Sep 28, 11:50 am, Roy Smith [EMAIL PROTECTED] wrote:
 Is there any way to attach a docstring to an attribute?  I see that PEP-257
 talks about attribute docstrings, but it references PDP-258, which was
 rejected.

 I suppose I could eschew plain attributes in favor of getter functions,
 because those give me a place to hang a docstring, but that feels like the
 wrong thing to do.

There were a couple of solutions provided - including the use of
properties - when this question came up earlier this week:
http://groups.google.com/group/comp.lang.python/browse_frm/thread/18a8c3f09ac02f85#
--
http://mail.python.org/mailman/listinfo/python-list


Re: Borg vs Singleton vs OddClass

2008-09-27 Thread Steven D'Aprano
On Sat, 27 Sep 2008 11:12:00 -0700, Lie wrote:

 This is probably unrelated to Python, as this is more about design
 pattern. I'm asking your comments about this design pattern that is
 similar in functionality to Singleton and Borg: to share states.
 
 I'm thinking about this design pattern (I don't know if anyone has ever
 thought of this pattern before):
 
 class OddClass(object):
 def __init__(self):
 global OddClass
 OddClass = self
 def __call__():
 return self


I don't think that pattern works as you give it. I suggest you read the 
thread What do you call a class not intended to be instantiated, 
started by me on the 21st of September, which covers a similar pattern.

I'm afraid it's a rather long thread, with a lot of people 
misunderstanding what I was asking, but still worth reading. If you only 
have time to read one post, I suggest you read my reply to Ben Finney, 
posted yesterday.

My own feeling is that both your OddClass and my class without instances 
are probably solutions looking for a problem. Well, actually, no, that's 
too strong: I think the concept of Class Singleton is a perfectly valid 
solution to certain problems, but it competes with more well-known 
solutions like modules and Borg (in Python) and Singletons (the hammer 
available in Java and C++). As for which is better, that's partly a 
matter of personal taste and partly a matter of familiarity.


 It do have a problem though, that you can't do isinstance(a, OddClass)

But you can say a is OddClass, which is more appropriate for a 
Singleton.

 The problem with Borg is that it is not inheritable (in certain
 sense[1]) and only work with old-style class (which is due to be
 completely removed on py3k)[2]

No, there is a new-style Borg. Read the comments here:
http://code.activestate.com/recipes/66531/

The new-style Borg is hardly more complicated than old-style: 6 lines 
versus 4.

I like Luke Plant's comment:

classes and modules are singletons. You don't need singletons in python 
simply because classes and modules are always singletons, and they are 
also first class objects. They can have everything instances have, and as 
import statements don't make copies there is only ever one of them. We 
don't need no stinkin' design patterns.



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


Re: What do you call a class not intended to be instantiated

2008-09-27 Thread Steven D'Aprano
On Sat, 27 Sep 2008 17:41:42 -0400, Terry Reedy wrote:

 In 3.0, at least, one does not need a disk file to create a module.
 
   import types
   me = types.ModuleType('me') # type(__builtins__) works, no import
   me
 module 'me' (built-in)
   me.a = 1
   me.a
 1
   me.a + 1
 2

Seems to work for Python 2.5 as well.


 That said, a blank class is even easier, and the representation is
 better.

And modules aren't callable. I've often thought they should be.


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


Re: Hello boys!

2008-09-27 Thread Jim Thompson

On Sat, 27 Sep 2008 23:12:59 + (UTC), Cydrome Leader
[EMAIL PROTECTED] wrote:

In rec.crafts.metalworking Jim Thompson [EMAIL PROTECTED] wrote:
 
 On Sat, 27 Sep 2008 18:47:16 -0400, default [EMAIL PROTECTED]
 wrote:
 
On Sat, 27 Sep 2008 14:56:07 -0700 (PDT), Milenko Stojadinovic Cvrcko
[EMAIL PROTECTED] wrote:

Hello, this is Milenko Stojadinovic from town Banjaluka,
Bosnia and Herzegovina, also known as Cvrcko
Does anyone know of any bars in town where I can
swallow a bucket of cum? It can be either dog,
horse or human cum. Also, does anyone know of
any sex bars where people will shit in your mouth?
I also like eating shit.

Come to the US and park your mouth in front of George Bush - all the
Bshit you can eat - and it keeps on coming!

I have a buddy in Bosna - he's normal.
 
 Now you know why I blanket kill-file googlegroups.

So you and everybody can talk about them nonstop?

You're gone also ;-)

...Jim Thompson
-- 
| James E.Thompson, P.E.   |mens |
| Analog Innovations, Inc. | et  |
| Analog/Mixed-Signal ASIC's and Discrete Systems  |manus|
| Phoenix, Arizona  85048Skype: Contacts Only  | |
| Voice:(480)460-2350  Fax: Available upon request |  Brass Rat  |
| E-mail Icon at http://www.analog-innovations.com |1962 |
 
   Liberalism is a persistent vegetative state
--
http://mail.python.org/mailman/listinfo/python-list


design pattern: MVC in python

2008-09-27 Thread 甜瓜
Howdy,

I am working on a small PC game by using pygame. Since there are many
graphical objects to display and intensive user interactions, I would
like to employ MVC pattern to keep the system maintainable.
However, I cannot find a good article which discussing the general
knowledge about MVC, especially:
1. How to decouple M-V-C? That is, which function should be assigned
to which part.
2. How to communicate each other while keeping M-V-C decoupled?
3. Do I need to create Interface/Proxy class for each component?
4. What is the general principle for designing the interface of M-V-C?
As my previous experience, if without special care on the principle,
the MVC pattern would gradually become messy and the boundary between
each component becomes unclear.

Could you give me any advice? In addition, can we take the advantage
of python language to make MVC easy-to-build and easy-to-use?

Thank you in advance.

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


Re: Abstract Base Class register function

2008-09-27 Thread Benjamin
On Sep 27, 4:50 pm, Mikolai Fajer [EMAIL PROTECTED] wrote:
 I have been experimenting with the abc module in py3k and thought
 about using the register method of an ABC as a class decorator:

 code
 import abc
 class MyABC(metaclass=abc.ABCMeta):
     pass

 @MyABC.register
 class MySub():
     pass
 /code

 This doesn't work because the register method returns None.  It would
 be a fairly simple modification to have this work:

 code
     def register(cls, subclass):
         Register a virtual subclass of an ABC.
         ... etc ...
         return subclass
 /code

 What do people think of this behavior?

It's probably better to just inherit from your metclass. register is
really for use with extension types that implement an interface.

 --

      -Mikolai Fajer-

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


Re: is decorator the right thing to use?

2008-09-27 Thread Dmitry S. Makovey
George Sakkis wrote:
 It's funny how often you come with a better solution a few moments
 after htting send! The snippet above can (ab)use the decorator syntax
 so that it becomes:
 
 class A(Proxy):
 
 @ProxyMethod
 def bmethod(self):
 return self.b1
 
 @ProxyMethod
 def bmethod2(self):
 return self.b2

That is outstanding! This code looks very clean to me (just a touch cryptic
around declarations in A, but that was unavoidable anyway). Seems like the
right way to read it would be bottom up (or is it only my mind so
perverted?). By the looks of it - it does exactly what I needed with great
number of possibilities behind it and is very lightweight and transparent.
Now I regret I haven't come up with it myself :-D

George, at this point I'm out of rugs - so no more rug pulling from under
your feet for me. 

Now I'm going to apply all this knowledge to my code, see how that goes and
come back with more questions later.

Thank you (all) very much for a great discussion. This thread educated me
quite a bit on descriptors and why one would need them, and decorators -
just as subject line suggested, were not forgotten. 


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


closures and dynamic binding

2008-09-27 Thread Aaron Castironpi Brady
Hello all,

To me, this is a somewhat unintuitive behavior.  I want to discuss the
parts of it I don't understand.

 f= [ None ]* 10
 for n in range( 10 ):
... f[ n ]= lambda: n
...
 f[0]()
9
 f[1]()
9

I guess I can accept this part so far, though it took a little getting
used to.  I'm writing some code and found the following workaround,
but I don't think it should give different results.  Maybe I'm not
understanding some of the details of closures.

 f= [ None ]* 10
 for n in range( 10 ):
... f[ n ]= (lambda n: ( lambda: n ) )( n )
...
 f[0]()
0
 f[1]()
1

Which is of course the desired effect.  Why doesn't the second one
just look up what 'n' is when I call f[0], and return 9?
--
http://mail.python.org/mailman/listinfo/python-list


how to make smtplib.SMTP('localhost') work on window xp

2008-09-27 Thread zxo102
Hi,
 I am trying to use python module smtplib to send my email out on
window xp (localhost).

import smtplib
server = smtplib.SMTP('localhost')

but I got the error information as follows:

Traceback (most recent call last):
  File interactive input, line 1, in ?
  File c:\python24\lib\smtplib.py, line 244, in __init__
(code, msg) = self.connect(host, port)
  File c:\python24\lib\smtplib.py, line 311, in connect
(code, msg) = self.getreply()
  File c:\python24\lib\smtplib.py, line 355, in getreply
raise SMTPServerDisconnected(Connection unexpectedly closed)
SMTPServerDisconnected: Connection unexpectedly closed

I am not sure what is wrong with it. Should I configure my window xp
somewhere to run smtplib.SMTP('localhost')?

Thanks in advance.

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


str() should convert ANY object to a string without EXCEPTIONS !

2008-09-27 Thread est
From python manual

str( [object])

Return a string containing a nicely printable representation of an
object. For strings, this returns the string itself. The difference
with repr(object) is that str(object) does not always attempt to
return a string that is acceptable to eval(); its goal is to return a
printable string. If no argument is given, returns the empty string,
''.


now we try this under windows:

 str(u'\ue863')
Traceback (most recent call last):
  File stdin, line 1, in module
UnicodeEncodeError: 'ascii' codec can't encode character u'\ue863' in
position 0
: ordinal not in range(128)

FAIL.

also almighty Linux

Python 2.3.4 (#1, Feb  6 2006, 10:38:46)
[GCC 3.4.5 20051201 (Red Hat 3.4.5-2)] on linux2
Type help, copyright, credits or license for more information.
 str(u'\ue863')
Traceback (most recent call last):
  File stdin, line 1, in ?
UnicodeEncodeError: 'ascii' codec can't encode character u'\ue863' in
position 0: ordinal not in range(128)

Python 2.4.4 (#2, Apr  5 2007, 20:11:18)
[GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] on linux2
Type help, copyright, credits or license for more information.
 str(u'\ue863')
Traceback (most recent call last):
  File stdin, line 1, in ?
UnicodeEncodeError: 'ascii' codec can't encode character u'\ue863' in
position 0: ordinal not in range(128)

Python 2.5 (release25-maint, Jul 20 2008, 20:47:25)
[GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] on linux2
Type help, copyright, credits or license for more information.
 str(u'\ue863')
Traceback (most recent call last):
  File stdin, line 1, in module
UnicodeEncodeError: 'ascii' codec can't encode character u'\ue863' in
position 0: ordinal not in range(128)


The problem is, why the f**k set ASCII encoding to range(128) 
while str() is internally byte array it should be handled in
range(256) !!

http://bugs.python.org/issue3648

One possible solution(Windows Only)

 str(u'\ue863'.encode('mbcs'))
'\xfe\x9f'
 print u'\ue863'.encode('mbcs')
��


I now spending 60% of my developing time dealing with ASCII range(128)
errors. It was PAIN!!

Please fix this issue.

http://bugs.python.org/issue3648

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

[issue3892] bsddb: test01_basic_replication fails on Windows sometimes

2008-09-27 Thread Amaury Forgeot d'Arc

Amaury Forgeot d'Arc [EMAIL PROTECTED] added the comment:

I reproduce the test failure very consistently, on both win2k and winXP, 
and may be of some help to test stuff.

--
nosy: +amaury.forgeotdarc

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue3892
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue3187] os.listdir can return byte strings

2008-09-27 Thread STINNER Victor

Changes by STINNER Victor [EMAIL PROTECTED]:


Removed file: http://bugs.python.org/file11189/filename.py

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue3187
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue3187] os.listdir can return byte strings

2008-09-27 Thread STINNER Victor

Changes by STINNER Victor [EMAIL PROTECTED]:


Removed file: http://bugs.python.org/file11210/invalid_filename.patch

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue3187
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue3978] ZipFileExt.read() can be incredibly slow

2008-09-27 Thread Antoine Pitrou

Antoine Pitrou [EMAIL PROTECTED] added the comment:

Very interesting, but it will have to wait for 2.7/3.1. 2.6 and 3.0 are
in the final phases of the release process.

--
nosy: +pitrou
priority:  - normal
versions: +Python 3.1 -Python 2.6

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue3978
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue3872] Python 2.6rc2: Tix ComboBox error

2008-09-27 Thread Martin v. Löwis

Martin v. Löwis [EMAIL PROTECTED] added the comment:

Thanks for the patch. I have now integrated this patch into
externals/tix-8.4.3.1 (along with a patch to compile it for AMD64). Demo
installers including this code are available at

http://www.dcl.hpi.uni-potsdam.de/home/loewis/u/python-2.6.14149.msi
http://www.dcl.hpi.uni-potsdam.de/home/loewis/u/python-2.6.14149.amd64.msi

I'm skeptical about the build_tkinter patch. It seems fairly invasive,
so I'd rather defer it until after the release.

--
priority: critical - normal
resolution:  - fixed

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue3872
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue3981] Python 3, IDLE does not start

2008-09-27 Thread bahiminin

New submission from bahiminin [EMAIL PROTECTED]:

I have Windows XP with Live OneCare as protection. Python 3 IDLE won't
start because of sub-process issues while Python 2.5.2 IDLE does start
without any problem.

--
messages: 73923
nosy: dah
severity: normal
status: open
title: Python 3, IDLE does not start
versions: Python 3.0

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue3981
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue3665] Support \u and \U escapes in regexes

2008-09-27 Thread Jeffrey C. Jacobs

Changes by Jeffrey C. Jacobs [EMAIL PROTECTED]:


--
nosy: +timehorse

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue3665
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue3482] re.split, re.sub and re.subn should support flags

2008-09-27 Thread Jeffrey C. Jacobs

Changes by Jeffrey C. Jacobs [EMAIL PROTECTED]:


--
nosy: +timehorse

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue3482
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue3482] re.split, re.sub and re.subn should support flags

2008-09-27 Thread Jeffrey C. Jacobs

Changes by Jeffrey C. Jacobs [EMAIL PROTECTED]:


--
versions: +Python 2.7, Python 3.1 -Python 2.6, Python 3.0

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue3482
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue3299] invalid object destruction in re.finditer()

2008-09-27 Thread Jeffrey C. Jacobs

Changes by Jeffrey C. Jacobs [EMAIL PROTECTED]:


--
versions: +Python 2.7 -Python 2.6

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue3299
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



  1   2   >