ANN: SciPy 2009 student sponsorship

2009-06-29 Thread Jarrod Millman
I am pleased to announce that the Python Software Foundation is
sponsoring 10 students' travel, registration, and accommodation for
the SciPy 2009 conference (Aug. 18-23).  The focus of the conference
is both on scientific libraries and tools developed with Python and on
scientific or engineering achievements using Python.  If you're in
college or a graduate program, please check out the details here:
http://conference.scipy.org/student-funding

About the conference


SciPy 2009, the 8th Python in Science conference, will be held from
August 18-23, 2009 at Caltech in Pasadena, CA, USA.  The conference
starts with two days of tutorials to the scientific Python tools.
There will be two tracks, one for introduction of the basic tools to
beginners, and one for more advanced tools.  The tutorials will be
followed by two days of talks.  Both days of talks will begin with a
keynote address.  The first day’s keynote will be given by Peter
Norvig, the Director of Research at Google; while, the second keynote
will be delivered by Jon Guyer, a Materials Scientist in the
Thermodynamics and Kinetics Group at NIST.  The program committee will
select the remaining talks from submissions to our call for papers.
All selected talks will be included in our conference proceedings
edited by the program committee.  After the talks each day we will
provide several rooms for impromptu birds of a feather discussions.
Finally, the last two days of the conference will be used for a number
of coding sprints on the major software projects in our community.

For the 8th consecutive year, the conference will bring together the
developers and users of the open source software stack for scientific
computing with Python.  Attendees have the opportunity to review the
available tools and how they apply to specific problems.  By providing
a forum for developers to share their Python expertise with the wider
commercial, academic, and research communities, this conference
fosters collaboration and facilitates the sharing of software
components, techniques, and a vision for high level language use in
scientific computing.

For further information, please visit the conference homepage:
http://conference.scipy.org.

Important Dates
---

* Friday, July 3: Abstracts Due
* Friday, July 10: Announce accepted talks, post schedule
* Friday, July 10: Early Registration ends
* Tuesday-Wednesday, August 18-19: Tutorials
* Thursday-Friday, August 20-21: Conference
* Saturday-Sunday, August 22-23: Sprints
* Friday, September 4: Papers for proceedings due

Executive Committee
---

* Jarrod Millman, UC Berkeley, USA (Conference Chair)
* Gaël Varoquaux, INRIA Saclay, France (Program Co-Chair)
* Stéfan van der Walt, University of Stellenbosch, South Africa
(Program Co-Chair)
* Fernando Pérez, UC Berkeley, USA (Tutorial Chair)
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

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


ANN: eGenix mxODBC Connect 1.0.2 - Python Database Interface

2009-06-29 Thread eGenix Team: M.-A. Lemburg


ANNOUNCING
  eGenix.com mxODBC Connect

  Python Database Interface

Version 1.0.2


   Our new client-server product for connecting Python applications
  to relational databases - from all major platforms


This announcement is also available on our web-site for online reading:
http://www.egenix.com/company/news/eGenix-mxODBC-Connect-1.0.2-GA.html



INTRODUCTION

The mxODBC Connect Database Interface for Python allows users to
easily connect Python applications to all major databases on the
market today in a highly portable and convenient way.

Unlike our mxODBC Python extension, mxODBC Connect is designed
as client-server application, so you no longer need to find production
quality ODBC drivers for all the platforms you target with your Python
application.

Instead you use an easy to install Python client library which
connects directly to the mxODBC Connect database server over the
network.

This makes mxODBC Connect the ideal basis for writing cross-platform
database programs and utilities in Python, especially if you run
applications that need to communicate with databases such as MS SQL
Server and MS Access, Oracle Database, IBM DB2 and Informix, Sybase
ASE and Sybase Anywhere, MySQL, PostgreSQL, SAP MaxDB and many more,
that run on Windows or Linux machines.

By removing the need to install and configure ODBC drivers on the
client side, mxODBC Connect greatly simplifies setup and
configuration of database driven client applications, while at
the same time making the network communication between client and
database server more efficient and more secure.

For more information, please see the product page:

http://www.egenix.com/products/python/mxODBCConnect/



NEWS

mxODBC Connect 1.0.2 is a patch-level release of our new mxODBC Connect
product.

* More Secure

We have upgraded the server to our latest eGenix pyOpenSSL release
0.9.0-0.9.8k, which includes a number of important bug fixes to both
pyOpenSSL and the used OpenSSL library.

* More Robust

Previous versions had a timeout issue that we have solved with this
release. We have have also added a special case for shutting down the
client with a broken server connection. In such cases, the client will
no longer wait for a timeout and terminate much faster.

* Ideal for Building Bridges

mxODBC Connect Client now works on all major Python platforms. As a
result, connecting from e.g. Linux or Mac OS X to an SQL Server
database has never been easier. You can even keep the data sources you
already have configured on your Windows machine and connect to them as
if your application were running on the database server itself.



UPGRADING

You are encouraged to upgrade to this latest mxODBC Connect release.
When upgrading, please always upgrade both the server and the client
installations to the same version - even for patch level releases.

Customers who have purchased mxODBC Connect 1.0 licenses can download
and upgrade their existing installations without having to purchase
new licenses or upgrades. The licenses will continue to work with
version 1.0.2.

Users of our stand-alone mxODBC product will have to purchase new
licenses from our online shop in order to use mxODBC Connect.

You can request 30-day evaluation licenses by visiting our web-site
or writing to sa...@egenix.com, stating your name (or the name of the
company) and the number of eval licenses that you need.

http://www.egenix.com/products/python/mxODBCConnect/#Evaluation



DOWNLOADS

The download archives as well as instructions for installation and
configuration of the product can be found on the product page:

http://www.egenix.com/products/python/mxODBCConnect/

If you want to try the package, jump straight to the download
instructions:

https://cms.egenix.com/products/python/mxODBCConnect/#Download

Fully functional evaluation licenses for the mxODBC Connect Server are
available free of charge:

http://www.egenix.com/products/python/mxODBCConnect/#Evaluation

mxODBC Connect Client is always free of charge.

___

SUPPORT

Commercial support for this product is available from eGenix.com.

Please see

http://www.egenix.com/services/support/

for details about our support offerings.

Enjoy,
-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Jun 29 2009)
 Python/Zope Consulting and Support ...http://www.egenix.com/
 mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/
 mxODBC, mxDateTime, 

Re: fork, threads and proper closing

2009-06-29 Thread Tomasz Pajor



On 28 juin, 23:26, Tomasz Pajor ni...@puffy.pl wrote:
  

Hello,

Configuration is as follows.

I have a starter process which creates 3 sub processes (forks) and each
of this processes creates a number of threads.
Threads in that processes have semaphore so on KeyboardInterrupt without
sending a sigterm to the subprocess i'm not able to close threads.
Is there any work around? Can I somehow run join for the thread on
keyboard interrupt?



When creating a thread you can add a Queue parameter to communicate
with threads:
http://docs.python.org/library/queue.html
easy and reliable.

give them a poison pill in the queue: a recognizable object placed
on the queue that means when you get this, stop.
  

can You provide any working example?

better to not rely on keyboard for thread stopping.
  

i use keyboard interrupt only for debuging purposes

Olivier
  


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


Re: Flexible warning system

2009-06-29 Thread Simon Forman
On Sun, Jun 28, 2009 at 2:31 PM, Shrutarshi Basus...@basushr.net wrote:
 I'm writing a Python package where I have an underlying object model that is
 manipulated by a runtime control layer and clients that interface with this
 runtime. As I'm developing this i'm realizing that there are going to be a
 number of places where the runtime might affect the object model in ways
 that might not be immediately obvious to the user. I would like to have some
 sort of warning system where the runtime can raise a warning and then the
 clients can 'catch' those warnings and display them as they want to. Is
 there some sort of a system that will operates like that or will I have to
 roll my own? If I do need to roll my own, any ideas on how I should go about
 it? I know that there is a warning module, but it seems to that all outputs
 go to standard out which isn't what I want.
 Thanks,
 Basu

 Shrutarshi Basu
 Computer Science,
 Electrical and Computer Engineering,
 Lafayette College,
 The ByteBaker -- http://bytebaker.com


I just glanced at the docs for the warnings module and it seems like
exactly what you're asking for, and you can change the default writing
to stdout:

Warning messages are normally written to sys.stderr, but their
disposition can be changed flexibly, from ignoring all warnings to
turning them into exceptions. The disposition of warnings can vary
based on the warning category (see below), the text of the warning
message, and the source location where it is issued. Repetitions of a
particular warning for the same source location are typically
suppressed. - http://docs.python.org/library/warnings.html

That said, why not just use exceptions?

HTH,
~Simon
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: The Python Way for module configuration?

2009-06-29 Thread Simon Forman
On Sun, Jun 28, 2009 at 1:22 PM, kjno.em...@please.post wrote:
 In 87fxdlujds@benfinney.id.au Ben Finney ben+pyt...@benfinney.id.au 
 writes:

(Even if you don't want to receive email, could you please give your
actual name in the ‘From’ field instead of just initials? It makes
conversation less confusing.)

 I don't know why, but for as long as I can remember everyone calls
 me kj, even my mom.  My name is Keaweikekahialiʻiokamoku
 Jallalahwallalruwalpindi

 kj


Now that's funny.

+1 QotW

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


Re: Good books in computer science?

2009-06-29 Thread Simon Forman
On Sat, Jun 13, 2009 at 11:49 AM, koranthalakoranth...@gmail.com wrote:
 Hi all,
    I do understand that this is not a python question and I apologize
 for that straight up.
    But I am a full time follower of this group and I have seen very
 very brilliant programmers and solutions.
    I also want to be a good programmer - so this question.

    Which are the classic books in computer science which one should
 peruse?
    I have  (a) Code Complete (b) GOF (c) Art of programming.

    Art of programming was too tough for me - and I couldnt understand
 much. The other two were good books - I understood and implemented
 quite a bit from both.
    What are the other books which I should peruse?

 Regards
 K

Knuth.

I.e. The Art of Computer Programming by Prof. Knuth

Your library should have a copy (it's a multi-volume opus), if not
consider donating yours after you read them.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Fast Dictionary Access

2009-06-29 Thread Paul Rubin
Duncan Booth duncan.bo...@invalid.invalid writes:
 The suggested alternative:
 
value = data.get(key, None) 
 
 also has two dictionary lookups:...

dg = data.get
...
(inside loop):
   value = dg(key,None)
-- 
http://mail.python.org/mailman/listinfo/python-list


Abort SimpleXMLRPCServer request prematurely?

2009-06-29 Thread Joseph Turian
With SimpleXMLRPCServer, if the server is taking too long, how can I
use the client to kill the request and have the server abort
prematurely?

Thanks,

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


pythonware.com down?

2009-06-29 Thread C. Feldmann
Hi,

I am trying to get a hold of PIL, but pythonware.com seems to be down.
Are there mirrors out there?
I get a 502 Error Bad Gateway - The proxy server received an invalid
response from an upstream server.
Does anyone else get that error?

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


Re: creating garbage collectable objects (caching objects)

2009-06-29 Thread News123
Dave Angel wrote:
 News123 wrote:
 Hi.

 I started playing with PIL.

 I'm performing operations on multiple images and would like compromise
 between speed and memory requirement.
 . . .

 The question, that I have is whether there is any way to tell python,
 that certain objects could be garbage collected if needed and ask python
 at a later time whether the object has been collected so far (image has
 to be reloaded) or not (image would not have to be reloaded)



   
 You don't say what implementation of Python, nor on what OS platform. 
 Yet you're asking how to influence that implementation.

Sorry my fault. I'm using C-python under Windows and under Linux
 
 In CPython, version 2.6 (and probably most other versions, but somebody
 else would have to chime in) an object is freed as soon as its reference
 count goes to zero.  So the garbage collector is only there to catch
 cycles, and it runs relatively infrequently.

If CYthon frees objects as early as possible (as soon as the refcount is
0), then weakref wil not really help me.
In this case I'd have to elaborate into a cache like structure.
 
 So, if you keep a reference to an object, it'll not be freed. 
 Theoretically, you can use the weakref module to keep a reference
 without inhibiting the garbage collection, but I don't have any
 experience with the module.  You could start by studying its
 documentation.  But probably you want a weakref.WeakValueDictionary. 
 Use that in your third approach to store the cache.
 
 If you're using Cython or Jython, or one of many other implementations,
 the rules will be different.
 
 The real key to efficiency is usually managing locality of reference. 
 If a given image is going to be used for many output files, you might
 try to do all the work with it before going on to the next image.  In
 that case, it might mean searching all_creation_rules for rules which
 reference the file you've currently loaded, measurement is key.

Changing the order of the images to be calculated is key and I'm working
on that.

For a first step I can reorder the image creation such, that all outpout
images, that depend only on one input image will be calculated one after
the other.

so for this case I can transform:
# Slowest approach:
for creation_rule in all_creation_rules():
img = Image.new(...)
for img_file in creation_rule.input_files():
src_img = Image.open(img_file)
img = do_somethingwith(img,src_img) # wrong indentation in OP
img.save()


into
src_img = Image.open(img_file)
for creation_rule in all_creation_rules_with_on_src_img():
img = Image.new(...)
img = do_somethingwith(img,src_img)
img.save()


What I was more concerned is a group of output images depending on TWO
or more input images.

Depending on the platform (and the images) I might not be able to
preload all two (or more images)

So,  as CPython's garbage collection takes always place immediately,
then I'd like to pursue something else.
I can create a cache, which caches input files as long as python leaves
at least n MB available for the rest of the system.

For this I have to know how much RAM is still available on a system.

I'll start looking into this.

thanks again



N


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


whizBase vs. Python

2009-06-29 Thread NurAzije
Hi,
I am working on a study and I need expert opinion, I did not work with
Python before, can anyone help me with a comparison between WhizBase
(www.whizbase.com) and Python please.

Thank you in advance,
Ashraf Gheith
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: whizBase vs. Python

2009-06-29 Thread Chris Rebert
On Mon, Jun 29, 2009 at 1:24 AM, NurAzijenuraz...@gmail.com wrote:
 Hi,
 I am working on a study and I need expert opinion, I did not work with
 Python before, can anyone help me with a comparison between WhizBase
 (www.whizbase.com) and Python please.

Python is a popular, open-source, cross-platform, general-purpose
programming language with a large standard library that is often used
in web programming. Popular Python web frameworks include TurboGears
and Django.

WhizBase appears to be a proprietary, Windows-only, database-centric
web macro language (or proper programming language perhaps, I didn't
investigate deeply).

Proprietary language = Vendor lock-in = Lose.

Cheers,
Chris
-- 
http://blog.rebertia.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: No trees in the stdlib?

2009-06-29 Thread Nobody
On Sun, 28 Jun 2009 20:54:11 -0700, Paul Rubin wrote:

 João Valverde backu...@netcabo.pt writes:
 Could you clarify what you mean by immutable? As in... not mutable? As
 in without supporting insertions and deletions?  
 
 Correct.  
 
 That's has the same performance as using binary search on a sorted
 list.  What's the point of using a tree for that?
 
 The idea is you can accomplish the equivalent of insertion or deletion
 by allocating a new root, along with the path down to the place you
 want to insert, i.e. O(log n) operations.  So instead of mutating an
 existing tree, you create a new tree that shares most of its structure
 with the old tree, and switch over to using the new tree.

The main issue here is that you need to be a bit smarter when it comes to
modifying the tree.

If you want to insert, delete or replace multiple elements, using repeated
insert()s (etc) on the root is sub-optimal, as you will end up repeatedly
duplicating the upper levels. Ideally you want to provide operations which
will add/remove/replace multiple elements in a single traversal.

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


ANN: eGenix mxODBC Connect 1.0.2 - Python Database Interface

2009-06-29 Thread eGenix Team: M.-A. Lemburg


ANNOUNCING
  eGenix.com mxODBC Connect

  Python Database Interface

Version 1.0.2


   Our new client-server product for connecting Python applications
  to relational databases - from all major platforms


This announcement is also available on our web-site for online reading:
http://www.egenix.com/company/news/eGenix-mxODBC-Connect-1.0.2-GA.html



INTRODUCTION

The mxODBC Connect Database Interface for Python allows users to
easily connect Python applications to all major databases on the
market today in a highly portable and convenient way.

Unlike our mxODBC Python extension, mxODBC Connect is designed
as client-server application, so you no longer need to find production
quality ODBC drivers for all the platforms you target with your Python
application.

Instead you use an easy to install Python client library which
connects directly to the mxODBC Connect database server over the
network.

This makes mxODBC Connect the ideal basis for writing cross-platform
database programs and utilities in Python, especially if you run
applications that need to communicate with databases such as MS SQL
Server and MS Access, Oracle Database, IBM DB2 and Informix, Sybase
ASE and Sybase Anywhere, MySQL, PostgreSQL, SAP MaxDB and many more,
that run on Windows or Linux machines.

By removing the need to install and configure ODBC drivers on the
client side, mxODBC Connect greatly simplifies setup and
configuration of database driven client applications, while at
the same time making the network communication between client and
database server more efficient and more secure.

For more information, please see the product page:

http://www.egenix.com/products/python/mxODBCConnect/



NEWS

mxODBC Connect 1.0.2 is a patch-level release of our new mxODBC Connect
product.

* More Secure

We have upgraded the server to our latest eGenix pyOpenSSL release
0.9.0-0.9.8k, which includes a number of important bug fixes to both
pyOpenSSL and the used OpenSSL library.

* More Robust

Previous versions had a timeout issue that we have solved with this
release. We have have also added a special case for shutting down the
client with a broken server connection. In such cases, the client will
no longer wait for a timeout and terminate much faster.

* Ideal for Building Bridges

mxODBC Connect Client now works on all major Python platforms. As a
result, connecting from e.g. Linux or Mac OS X to an SQL Server
database has never been easier. You can even keep the data sources you
already have configured on your Windows machine and connect to them as
if your application were running on the database server itself.



UPGRADING

You are encouraged to upgrade to this latest mxODBC Connect release.
When upgrading, please always upgrade both the server and the client
installations to the same version - even for patch level releases.

Customers who have purchased mxODBC Connect 1.0 licenses can download
and upgrade their existing installations without having to purchase
new licenses or upgrades. The licenses will continue to work with
version 1.0.2.

Users of our stand-alone mxODBC product will have to purchase new
licenses from our online shop in order to use mxODBC Connect.

You can request 30-day evaluation licenses by visiting our web-site
or writing to sa...@egenix.com, stating your name (or the name of the
company) and the number of eval licenses that you need.

http://www.egenix.com/products/python/mxODBCConnect/#Evaluation



DOWNLOADS

The download archives as well as instructions for installation and
configuration of the product can be found on the product page:

http://www.egenix.com/products/python/mxODBCConnect/

If you want to try the package, jump straight to the download
instructions:

https://cms.egenix.com/products/python/mxODBCConnect/#Download

Fully functional evaluation licenses for the mxODBC Connect Server are
available free of charge:

http://www.egenix.com/products/python/mxODBCConnect/#Evaluation

mxODBC Connect Client is always free of charge.

___

SUPPORT

Commercial support for this product is available from eGenix.com.

Please see

http://www.egenix.com/services/support/

for details about our support offerings.

Enjoy,
-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Jun 29 2009)
 Python/Zope Consulting and Support ...http://www.egenix.com/
 mxODBC.Zope.Database.Adapter ... http://zope.egenix.com/
 mxODBC, mxDateTime, 

Spam? Re: whizBase vs. Python

2009-06-29 Thread Tim Harig
On 2009-06-29, NurAzije nuraz...@gmail.com wrote:
 Hi,
 I am working on a study and I need expert opinion, I did not work with
 Python before, can anyone help me with a comparison between WhizBase
 (www.whizbase.com) and Python please.

Given posts like:
http://groups.google.com/group/Server-side-programing/browse_thread/thread/16cfcf58bc943a0/15840d85eedd952e#15840d85eedd952e
is this just thinly veiled spam?  The domain and the posting IP address are
both out of Sarajevo, Bosnia.

Obviously you alreadly know your product is nothing but a database
macro processor.  Python is a dynamic programming language and therefore
far more capable.

Your product is proprietary with less capability while Python is free and
powerful.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: urllib2.URLError: urlopen error unknown url type: 'http error using twill with python

2009-06-29 Thread amadain
On Jun 8, 12:58 pm, Steven D'Aprano st...@remove-this-
cybersource.com.au wrote:
 On Mon, 08 Jun 2009 12:14:18 +0100, Mark Devine wrote:
  Hi
  I wonder if someone could point me in the right direction. I used the
  following code to access gmail but I got a
           urllib2.URLError: urlopen error unknown url type: 'http
  error when I ran it. I have included the Traceback

  import twill, string, os
  b=twill.commands.get_browser()
  b.set_agent_string(Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB;
  rv:1.8.1.14) Gecko/20080404 Firefox/2.0.0.14) b.clear_cookies()
  b.go('http://www.gmail.com')
  f=b.get_form(1)
  b.showforms()
  f['Email']= email
  f['Passwd'] =password
  b.clicked(f, f)
  b.submit()

 My bet is that the above is not the actual code you have run. I bet that
 the offending line is actually something like the following:

 b.go('http://www.gmail.com;)

 Note that there is a single character difference.

 Consider the last two lines of the traceback:

      raise URLError('unknown url type: %s' % type)
  urllib2.URLError: urlopen error unknown url type: 'http

 It seems to be saying that the url type is 'http -- note the leading
 single quote.

 --
 Steven

Actually that is the exact code run from a python shell. Try it
yourself. I could not find anybody who successfully automated sending
a gmail through python with twill so if you know how I would greatly
appreciate any pointers.
-- 
http://mail.python.org/mailman/listinfo/python-list


Timeout when connecting to sybase DBS

2009-06-29 Thread eranlevi
Hi All,

I'm using the Sybase module for connecting and using a sybase DBS.
When I try to connect when the DBS is down, it take approximately 4
minutes for the function (conn.ct_connect) to return with an error. I
have looked for a timeout parameter to limit the 4 minutes to
something more reasonable but couldn't find one.
Can anyone please help?

BTW, I'm using Sybase.connect(DBS name, Username, Password,
datetime='auto')

Thanks

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


Re: pep 8 constants

2009-06-29 Thread Rhodri James
On Mon, 29 Jun 2009 06:07:19 +0100, Eric S. Johansson e...@harvee.org  
wrote:



Rhodri James wrote:


Reject away, but I'm afraid you've still got some work to do to
convince me that PEP 8 is more work for an SR system than any other
convention.




[snip sundry examples]

Yes, yes, recognition systems need both training and a careful selection
of words to recognise to be effective.  This I learned twenty years ago:
if cap has a high failure rate, use something else.

As far as I can tell, the only thing that you are even vaguely suggesting
for convention use is underscores_with_everything.  As promised, I laugh
hollowly.

--
Rhodri James *-* Wildebeest Herder to the Masses
--
http://mail.python.org/mailman/listinfo/python-list


Re: pythonware.com down?

2009-06-29 Thread Tim Harig
On 2009-06-29, C. Feldmann casper.feldm...@googlemail.com wrote:
 I am trying to get a hold of PIL, but pythonware.com seems to be down.
 Are there mirrors out there?
 I get a 502 Error Bad Gateway - The proxy server received an invalid
 response from an upstream server.
 Does anyone else get that error?

Yes, more info below:

http://groups.google.com/group/comp.lang.python/browse_frm/thread/2dbba1a1bd6ebee6/1d832c468efc3828?tvc=1#1d832c468efc3828


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


Re: validating HTTPS certificates?

2009-06-29 Thread Nobody
On Mon, 29 Jun 2009 09:18:20 +0200, Andras.Horvath wrote:

 For a urllib-style interface, there's not much point in performing
 verification after the fact. Either the library performs verification or
 it doesn't. If it doesn't, you've just sent the (potentially confidential)
 request to an unknown server; discovering this after the fact doesn't
 really help.
 
 I was more thinking about supplying a/some CA certificate(s) and
 requiring that the site cert be valid (otherwise the connection should
 fail). This sounds very EAFP to me.

This is easier to do with urllib2 than urllib. For urllib, you would need
to either fix URLopener.open_https() or clone half of urllib (URLOpener
and FancyURLOpener). For urllib2, you can use urllib2.install_opener() to
replace the built-in HTTPSHandler with a subclass which performs
validation. Validation should just be a matter of passing
cert_reqs=CERT_REQUIRED and ca_certs= to ssl.wrap_socket(), then checking
that SSLSocket.getpeercert() returns a non-empty dictionary.

Note: the above is purely theoretical, based upon the (2.6) documentation
and source code. I suggest that you verify it by connecting to a site
with a bogus (e.g. self-signed) certificate and checking that it fails.

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


Re: Advantages of Python (for web/desktop apps)?

2009-06-29 Thread Marek Kubica
On 28 Jun 2009 11:45:06 -0700
a...@pythoncraft.com (Aahz) wrote:

 Perhaps I was unclear: I already knew what LMGTFY stands for, and I
 think that using a site that requires JavaScript is anti-social.

Maybe they could just redirect to Google if JS wasn't detected.

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


Re: pythonware.com down?

2009-06-29 Thread C. Feldmann
On 29 Jun., 11:07, Tim Harig user...@ilthio.net wrote:
 On 2009-06-29, C. Feldmann casper.feldm...@googlemail.com wrote:

  I am trying to get a hold of PIL, but pythonware.com seems to be down.
  Are there mirrors out there?
  I get a 502 Error Bad Gateway - The proxy server received an invalid
  response from an upstream server.
  Does anyone else get that error?

 Yes, more info below:

 http://groups.google.com/group/comp.lang.python/browse_frm/thread/2db...

yeah. need the windows version. guess this is another reason to add to
my why I should buy a mac list. :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [RELEASED] Python 3.1 final

2009-06-29 Thread Nobody
On Sun, 28 Jun 2009 21:25:13 +, Benjamin Peterson wrote:

  The email module is, yes, broken. You can recover the bytestrings of
  command-line arguments and environment variables.
 
 1. Does Python offer any assistance in doing so, or do you have to
 manually convert the surrogates which are generated for unrecognised bytes?
 
 fs_encoding = sys.getfilesystemencoding()
 bytes_argv = [arg.encode(fs_encoding, surrogateescape) for arg in sys.argv]

This results in an internal error:

 \udce4\udceb\udcef\udcf6\udcfc.encode(iso-8859-1, surrogateescape)
Traceback (most recent call last):
  File stdin, line 1, in module
SystemError: Objects/bytesobject.c:3182: bad argument to internal function

[FWIW, the error corresponds to _PyBytes_Resize, which has a
cautionary comment almost as large as the code.]

The documentation gives the impression that surrogateescape is only
meaningful for decoding.

 2. How do you do this for non-invertible encodings (e.g. ISO-2022)?
 
 What's a non-invertible encoding? I can't find a reference to the term.

One where different inputs can produce the same output.

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


Re: pythonware.com down?

2009-06-29 Thread Godson Gera
way back machine,comes to rescue.

http://web.archive.org/web/20071011003451/www.pythonware.com/products/pil/index.htm

On Mon, Jun 29, 2009 at 4:01 PM, C. Feldmann casper.feldm...@googlemail.com
 wrote:

 On 29 Jun., 11:07, Tim Harig user...@ilthio.net wrote:
  On 2009-06-29, C. Feldmann casper.feldm...@googlemail.com wrote:
 
   I am trying to get a hold of PIL, but pythonware.com seems to be down.
   Are there mirrors out there?
   I get a 502 Error Bad Gateway - The proxy server received an invalid
   response from an upstream server.
   Does anyone else get that error?
 
  Yes, more info below:
 
  http://groups.google.com/group/comp.lang.python/browse_frm/thread/2db...

 yeah. need the windows version. guess this is another reason to add to
 my why I should buy a mac list. :)
 --
 http://mail.python.org/mailman/listinfo/python-list




-- 
Thanks  Regards,
Godson Gera
http://godson.in
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: creating garbage collectable objects (caching objects)

2009-06-29 Thread Dave Angel

News123 wrote:

Dave Angel wrote:
  

News123 wrote:


Hi.

I started playing with PIL.

I'm performing operations on multiple images and would like compromise
between speed and memory requirement.
. . .

The question, that I have is whether there is any way to tell python,
that certain objects could be garbage collected if needed and ask python
at a later time whether the object has been collected so far (image has
to be reloaded) or not (image would not have to be reloaded)


  


  
  
  
You don't say what implementation of Python, nor on what OS platform. 
Yet you're asking how to influence that implementation.



Sorry my fault. I'm using C-python under Windows and under Linux
  

In CPython, version 2.6 (and probably most other versions, but somebody
else would have to chime in) an object is freed as soon as its reference
count goes to zero.  So the garbage collector is only there to catch
cycles, and it runs relatively infrequently.



If CYthon frees objects as early as possible (as soon as the refcount is
0), then weakref wil not really help me.
In this case I'd have to elaborate into a cache like structure.
  
So, if you keep a reference to an object, it'll not be freed. 
Theoretically, you can use the weakref module to keep a reference

without inhibiting the garbage collection, but I don't have any
experience with the module.  You could start by studying its
documentation.  But probably you want a weakref.WeakValueDictionary. 
Use that in your third approach to store the cache.


If you're using Cython or Jython, or one of many other implementations,
the rules will be different.

The real key to efficiency is usually managing locality of reference. 
If a given image is going to be used for many output files, you might

try to do all the work with it before going on to the next image.  In
that case, it might mean searching all_creation_rules for rules which
reference the file you've currently loaded, measurement is key.



Changing the order of the images to be calculated is key and I'm working
on that.

For a first step I can reorder the image creation such, that all outpout
images, that depend only on one input image will be calculated one after
the other.

so for this case I can transform:
# Slowest approach:
for creation_rule in all_creation_rules():
img = Image.new(...)
for img_file in creation_rule.input_files():
src_img = Image.open(img_file)
img = do_somethingwith(img,src_img) # wrong indentation in OP
img.save()


into
src_img = Image.open(img_file)
for creation_rule in all_creation_rules_with_on_src_img():
img = Image.new(...)
img = do_somethingwith(img,src_img)
img.save()


What I was more concerned is a group of output images depending on TWO
or more input images.

Depending on the platform (and the images) I might not be able to
preload all two (or more images)

So,  as CPython's garbage collection takes always place immediately,
then I'd like to pursue something else.
I can create a cache, which caches input files as long as python leaves
at least n MB available for the rest of the system.

For this I have to know how much RAM is still available on a system.

I'll start looking into this.

thanks again



N


  
As I said earlier, I think weakref is probably what you need.  A weakref 
is still a reference from the point of view of the ref-counting, but not 
from the point of view of the garbage collector.  Have you read the help 
on weakref module?  In particular, did you read Pep 0205?   
http://www.python.org/dev/peps/pep-0205/


Object cache is one of the two reasons for the weakref module.

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


Re: [RELEASED] Python 3.1 final

2009-06-29 Thread Nobody
On Sun, 28 Jun 2009 14:36:37 +0200, Martin v. Löwis wrote:

 That's a significant improvement. It still decodes os.environ and sys.argv
 before you have a chance to call sys.setfilesystemencoding(), but it
 appears to be recoverable (with some effort; I can't find any way to re-do
 the encoding without manually replacing the surrogates).
 
 See PEP 383.

Okay, that's useful, except that it may have some bugs:

 r = \udce4\udceb\udcef\udcf6\udcfc.encode(iso-8859-1, surrogateescape)
Traceback (most recent call last):
  File stdin, line 1, in module
SystemError: Objects/bytesobject.c:3182: bad argument to internal function

Trying a few random test cases suggests that the ratio of valid to invalid
bytes has an effect. Strings which consist mostly of invalid bytes trigger
the error, those which are mostly valid don't.

The error corresponds to _PyBytes_Resize(), which has the following
words of caution in a preceding comment:

/* The following function breaks the notion that strings are immutable:
   it changes the size of a string.  We get away with this only if there
   is only one module referencing the object.  You can also think of it
   as creating a new string object and destroying the old one, only
   more efficiently.  In any case, don't use this if the string may
   already be known to some other part of the code...
   Note that if there's not enough memory to resize the string, the original
   string object at *pv is deallocated, *pv is set to NULL, an out of
   memory exception is set, and -1 is returned.  Else (on success) 0 is
   returned, and the value in *pv may or may not be the same as on input.
   As always, an extra byte is allocated for a trailing \0 byte (newsize
   does *not* include that), and a trailing \0 byte is stored.
*/

Assuming that this gets fixed, it should make most of the problems with
3.0 solvable. OTOH, it wouldn't have killed them to have added e.g.
sys.argv_bytes and os.environ_bytes.

 However, sys.std{in,out,err} are still created as text streams, and AFAICT
 there's nothing you can do about this from within your code.
 
 That's intentional, and not going to change. You can access the
 underlying byte streams if you want to, as you could already in 3.0.

Okay, I've since been pointed to the relevant information (I was looking
under File Objects; I didn't think to look at sys).

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


Re: What does Guido want in a GUI toolkit for Python?

2009-06-29 Thread Lawson English

Martin v. Löwis wrote:

I sorta' wish he'd just come out and say, This is what I think would
be suitable for a GUI toolkit for Python: 



He is not in the business of designing GUI toolkits, but in the business
of designing programming languages. So he abstains from specifying
(or even recommending) a GUI library.

What he makes clear is the point that Terry cites: no matter what the
GUI toolkit is or what features it has - it should be simple to create
GUIs, as simple as creating HTML.

  


Tim Berners-Lee would laugh to hear html described as simple. He was 
very frustrated with

how long it took anyone to create a graphical toolkit to create webpages.


So, what *does* Guido want in a GUI toolkit for Python?



His concern really isn't what is in the toolkit, but what isn't.
It must not require lots of lines of code to produce a simple
GUI, it must not require specification of absolute coordinates,
... - you should be able to continue the list yourself.

Regards,
Martin
  


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


python extend c++ module

2009-06-29 Thread ���m�ۤv...@����
I have written a c++ extend module and I use distutils to build.

setup.py

from distutils.core import setup, Extension

setup(name=noddy, version=1.0,
  ext_modules=[
 Extension(noddy3, [noddy3.cpp, a.cpp])
 ])

I found it's quite strange when compiling. I didn't use extern C at all
, how can python get the right c++ funciton name without any compile error??

I found that it first use gcc to compile noddy3.cpp and then link by g++.

Could anyone explain what it's all about?

Thanks a lot!!


here is the compiling message.
---
running install

running build

running build_ext

building 'noddy3' extension

gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O3 -Wall
-Wstrict-prototypes -fPIC -I/usr/local/include/python2.6 -c noddy3.cpp -o
build/temp.linux-i686-2.6/noddy3.o

cc1plus: warning: command line option -Wstrict-prototypes is valid for
Ada/C/ObjC but not for C++
g++ -pthread -shared build/temp.linux-i686-2.6/noddy3.o
build/temp.linux-i686-2.6/a.o -o build/lib.linux-i686-2.6/noddy3.so
running install_lib

copying build/lib.linux-i686-2.6/noddy3.so -
/usr/local/lib/python2.6/site-packages

running install_egg_info

Removing /usr/local/lib/python2.6/site-packages/noddy-1.0-py2.6.egg-info

Writing /usr/local/lib/python2.6/site-packages/noddy-1.0-py2.6.egg-info


--
※Post by command   from 59-124-255-226.HINET-IP.
老鼠的香香乳酪洞˙電子佈告欄系統˙alexbbs.twbbs.org˙140.113.166.7
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Imaging Library download link broken?

2009-06-29 Thread Lawrence D'Oliveiro
In message xgz1m.1934$wj7...@nlpi065.nbdc.sbc.com, Tim Harig wrote:

 On 2009-06-29, Lawrence D'Oliveiro l...@geek-central.gen.new_zealand
 wrote:

 apt-get install python-imaging, anybody?
 
 C:\apt-get install python-imaging
 Bad command or file name

Sounds more like broken OS with no integrated package management.

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


Re: pythonware.com down?

2009-06-29 Thread Tim Harig
On 2009-06-29, C. Feldmann casper.feldm...@googlemail.com wrote:
 On 29 Jun., 11:07, Tim Harig user...@ilthio.net wrote:
 On 2009-06-29, C. Feldmann casper.feldm...@googlemail.com wrote:

  I am trying to get a hold of PIL, but pythonware.com seems to be down.
  Are there mirrors out there?
  I get a 502 Error Bad Gateway - The proxy server received an invalid
  response from an upstream server.
  Does anyone else get that error?

 Yes, more info below:

 http://groups.google.com/group/comp.lang.python/browse_frm/thread/2db...

 yeah. need the windows version. guess this is another reason to add to
 my why I should buy a mac list. :)

The source is operating system agnostic.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pep 8 constants

2009-06-29 Thread Tim Chase

Reject away, but I'm afraid you've still got some work to do to
convince me that PEP 8 is more work for an SR system than any other
convention.  


Name  capname
higher than normal recognition error rate. can require multiple tries 
or hand
correction

MultiWordName  capmulitno-spacecapwordnospacecapname
very high error rate.  many retries or hand hurting typing.

multi_word_name multiunderscorewordunderscorename
normal error rate (low), can need multiple tries or hand correction


It sounds like the issue should be one of making your 
screen-reader smarter, not dumbing down Python conventions.  I 
don't know what SR you're using (Jaws?  Window Eyes?  yasr? 
screeder?  speakup?  VoiceOver?)  but it sounds like at least for 
the above cases, along with the PEP-8 MULTI_WORD_NAME constant 
convention, a simple regexp+transformation should be able to 
reprocess the input into something easier to 
handle/hear/understand.  I'm not sure any/all of the 
previously-listed screen-readers give such regexp transformation 
control, but I would expect that at least the OSS ones (yasr, 
screeder,  speakup) it would be possible to add the feature if 
it doesn't already exist.  For these three, you might ping the 
blinux mailing list to see if anybody there knows how to 
implement such transforms.



StdlYCps  capsierra tango delta lima capyankee capcharley papa sierra

*** very high error rate *** search and replace for all instances with 
a x_y_z
form name is recommended


As for StuDlyCaps, it's hard on the seeing too, so I advocate a 
firm smack on the back of the head for those that prefer this 
abomination. :-)


-tkc




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


Running Invisible console Application

2009-06-29 Thread Elf Scripter
Hi, i have a console application that i want to ran (invisible) as a daemon,
how can i do that?
Thank you in advance.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python extend c++ module

2009-06-29 Thread Christian Heimes
找尋自己的一片天 schrieb:
 I found it's quite strange when compiling. I didn't use extern C at all
 , how can python get the right c++ funciton name without any compile error??
 
 I found that it first use gcc to compile noddy3.cpp and then link by g++.
 
 Could anyone explain what it's all about?

The Python header files already contain the necessary extern C
declarations. You can safely import the Python.h header file in a cpp
file without an extern C block.

Christian

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


Re: [RELEASED] Python 3.1 final

2009-06-29 Thread Antoine Pitrou
Nobody nobody at nowhere.com writes:
 
 This results in an internal error:
 
  \udce4\udceb\udcef\udcf6\udcfc.encode(iso-8859-1, surrogateescape)
 Traceback (most recent call last):
   File stdin, line 1, in module
 SystemError: Objects/bytesobject.c:3182: bad argument to internal function

Please report a bug on http://bugs.python.org

As for a bytes version of sys.argv and os.environ, you're welcome to propose a
patch (this would be a separate issue on the aforementioned issue tracker).

Thanks

Antoine.


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


Re: [RELEASED] Python 3.1 final

2009-06-29 Thread Hallvard B Furuseth
Nobody nob...@nowhere.com writes:
On Sun, 28 Jun 2009 14:36:37 +0200, Martin v. Löwis wrote:
 See PEP 383.

 Okay, that's useful, except that it may have some bugs:
 (...)
 Assuming that this gets fixed, it should make most of the problems with
 3.0 solvable. OTOH, it wouldn't have killed them to have added e.g.
 sys.argv_bytes and os.environ_bytes.

That's hopeless to keep track of across modules if something modifies
sys.argv or os.environ.

If the current scheme for recovering the original bytes proves
insufficient, what could work is a string type which can have an
attribute with the original bytes (if the source was bytes).  And/or
sys.argv and os.environ maintaining the correspondence when feasible.

Anyway, I haven't looked at whether any of this is a problem, so don't
mind me:-)  As long as it's definitely possible to tell python once
and for all not to apply locales and string conversions, instead of
having to keep track of an ever-expanding list of variables to tame
it's bytes-character conversions (as happened with Emacs).

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


Re: No trees in the stdlib?

2009-06-29 Thread Tim Wintle
On Sat, 2009-06-27 at 06:03 +0100, João Valverde wrote:
 To answer the question of what I need the BSTs for, without getting
 into too many boring details it is to merge and sort IP blocklists,
 that is, large datasets of ranges in the form of (IP address, IP
 address, string).

snip

 As an anecdotal data point (honestly not trying to raise the Python
 is slow strawman), I implemented the same algorithm in C and Python,
 using pyavl. Round numbers were 4 mins vs 4 seconds, against Python
 (plus pyavl).

Out of interest, I recently wrote something similar that imported (a
class of) snort rules for blacklisting ip traffic. I could only use the
standard library.

I ended up writing a simple tree using dict-like objects [1]. Afraid I
haven't got a taught CS background to know the name of the structure.

(note insertion wasn't the focus, and I didn't bother writing it to
handle updates/merges - this is a quick script I run every now and then,
so I'm sure it could be done better - I just liked having the standard
dict interface for each node)

I only had three levels of branching, using the first octet to branch at
the root node, the second octet to branch as the second node, and the
final two to branch at the third node's depth (since even then that's
normally sparse relative to the first two nodes).

It works well enough for me - I'm IO bound reading in ip addresses from
logs to check against the blacklist, and there is a fair bit of other
processing going on for each line.

(Obviously I converted the ip addresses to integers before doing all
this to avoid hashing strings etc)


[1]
(As rules could be for any subnet I overloaded some of the dict methods
to check against rules on unusual subnets etc. before checking
individual ips in the final part)


  Even considering I'm a worse Python programmer than C 
 programmer, it's a lot. I know many will probably think I tried to do
 C in Python but that's not the case, at least I don' t think so.
 Anyway like I said, not really relevant to this discussion.
 

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


Re: [RELEASED] Python 3.1 final

2009-06-29 Thread Paul Moore
2009/6/29 Antoine Pitrou solip...@pitrou.net:
 As for a bytes version of sys.argv and os.environ, you're welcome to propose a
 patch (this would be a separate issue on the aforementioned issue tracker).

But please be aware that such a proposal would have to consider:

1. That on Windows, the native form is the character version, and the
bytes version would have to address all the same sorts of encoding
issues that the OP is complaining about in the character versions. [1]

2. That the proposal address the question of how to write portable,
robust, code (given that choosing argv vs argv_bytes based on
sys.platform is unlikely to count as a good option...)

3. Why defining your own argv_bytes as argv_bytes =
[a.encode(iso-8859-1, surrogateescape) for a in sys.argv] is
insufficient (excluding issues with bugs, which will be fixed
regardless) for the occasional cases where it's needed.

Before writing the proposal, the OP should probably review the
extensive discussions which can be found in the python-dev archives.
It would be wrong for people reading this thread to think that the
implemented approach is in any sense a quick fix - it's certainly a
compromise (and no-one likes all aspects of any compromise!) but it's
one made after a lot of input from people with widely differing
requirements.

Paul.

[1] And my understanding, from the PEP, is that even on POSIX, the
argv and environ data is intended to be character data, even though
the native C APIs expose a byte-oriented interface. So conceptually,
character format is correct on POSIX as well... (But I don't write
code for POSIX systems, so I'll leave it to the POSIX users to debate
this point further).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Good books in computer science?

2009-06-29 Thread rustom

This thread has thrown up some interesting suggestions but they all
seem to fall into one of two categories:
- the high-ground: Dijkstra, Knuth etc
- the low-ground: write (any-which-how) a lot of code

And both these 'grounds' seem to cause more argument and less
suggestions for good books.

Let me therefore try to find a middle-ground and make a suggestion
that I used to make to my students when I taught them programming:
Read the Python Manual  -- specifically the library.  It contains a
fairly good conspectus of modern day IT/CS.

Some examples of what I mean:

Want to study TDD?  Read unittest and doctest and then go on to
reading (and practising) Kent Beck etc
Want to get into unix system programming?  Nothing like playing around
with os.path and stat before burining your hands with C.
Networking protocols? smtplib, urllib, ftplib etc
Low level networking? socket, select etc
Algorithms? Good to get your feet on the ground with timeit
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Imaging Library download link broken?

2009-06-29 Thread Tim Harig
On 2009-06-29, Lawrence D'Oliveiro l...@geek-central.gen.new_zealand wrote:
 Sounds more like broken OS with no integrated package management.

Package managers with dependency tracking were all the rage when I first
started using Linux.  So I tried Red Hat and everything worked great until
the depency database corrupted itself.  Since then, I have learned to
install using whatever package manager but to upgrade or install new
packages from source.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Running Invisible console Application

2009-06-29 Thread MRAB

Elf Scripter wrote:
Hi, i have a console application that i want to ran (invisible) as 
a daemon, how can i do that?



Change the extension from .py to .pyw.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Good books in computer science?

2009-06-29 Thread Anul
On Jun 29, 5:08 pm, rustom rustompm...@gmail.com wrote:

 Want to study TDD?  Read unittest and doctest and then go on to
 reading (and practising) Kent Beck etc
 Want to get into unix system programming?  Nothing like playing around
 with os.path and stat before burining your hands with C.
 Networking protocols? smtplib, urllib, ftplib etc
 Low level networking? socket, select etc
 Algorithms? Good to get your feet on the ground with timeit

Ive found twisted is a good excuse to study lot of CS arcana
ranging from laziness of lambdas, event driven programming
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: fork, threads and proper closing

2009-06-29 Thread Francesco Bochicchio
On 29 Giu, 07:10, OdarR olivier.da...@gmail.com wrote:
 On 28 juin, 23:26, Tomasz Pajor ni...@puffy.pl wrote:

  Hello,

  Configuration is as follows.

  I have a starter process which creates 3 sub processes (forks) and each
  of this processes creates a number of threads.
  Threads in that processes have semaphore so on KeyboardInterrupt without
  sending a sigterm to the subprocess i'm not able to close threads.
  Is there any work around? Can I somehow run join for the thread on
  keyboard interrupt?

 When creating a thread you can add a Queue parameter to communicate
 with threads:http://docs.python.org/library/queue.html
 easy and reliable.

 give them a poison pill in the queue: a recognizable object placed
 on the queue that means when you get this, stop.


This is the way I usually go, but it has one important limitation: if
the thread is waiting
for a blocking I/O operation to complete, like reading from a socket
with no data or waiting
for a locked resource (i.e. semaphore) to be unlocked, it will not
service the queue and will
not read the 'quit command' (the poison pill), and therefore will not
quit until the blocking
I/O terminates (and it could be never).

ASAIK, there is no way - in python - to solve this.



 Olivier

Ciao

FB

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


Re: Python Imaging Library download link broken?

2009-06-29 Thread peter
Whilst this is an interesting discussion about installers, I'm still
trying to find a copy of PIL.  Any ideas?
-- 
http://mail.python.org/mailman/listinfo/python-list


problems with mysql db

2009-06-29 Thread golu
here i have posted my code...plz tell why am i getting the error int
argument required on the hash marked line(see below) although i am
giving an int value
#the code
import os
import string
import MySQLdb
import stopcheck
conn = MySQLdb.connect(host='localhost',user='root',db='urdb')

def file_extractor(dir_name):
url_count = 0

for file in os.listdir(dir_name):
  if(file[-4:] == '.txt'):
file_path = os.path.join(dir_name,file)
curse = conn.cursor()
url_count += 1
curse.execute(INSERT INTO URL_TABLE VALUES(%d,%s),
(url_count,file_path)) #error
word_extractor(url_count,file_path)
def word_extractor(url_count,file):
fhandle =  open(file)
line = fhandle.readline()
k=stopcheck.checker()
k.create()

while line:
   words = line.split()
   cursor = conn.cursor()
   for word1 in words:
   if word1 not in string.punctuation:
if (k.check(word1) is 0) and (word1[0:4] != 'http') :
   word_count+=1
   try:
cursor.execute(INSERT INTO word_table(id,word)
VALUES(%d,%s) , (word_count,word1))
cursor.execute(INSERT INTO wordmatch
(word_id,url_id) values(%d,%d),(word_count,url_count))
   except MySQLdb.Error, e:
 print Error %d: %s % (e.args[0], e.args[1])
   line=fhandle.readline()

if __name__ == '__main__':
#url_count=0
#word_count=0

dir = os.path.join('D://','acm')
file_extractor(dir)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: validating HTTPS certificates?

2009-06-29 Thread Andras.Horvath
 validation. Validation should just be a matter of passing
 cert_reqs=CERT_REQUIRED and ca_certs= to ssl.wrap_socket(), then checking
 that SSLSocket.getpeercert() returns a non-empty dictionary.

That'd be cool unless I can't use an already-open socket (by SSL, for
verification) in any of the built-in HTTP engines, by the look of it.

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


Re: Advantages of Python (for web/desktop apps)?

2009-06-29 Thread Aahz
In article 20090629121940.42b88...@halmanfloyd.lan.local,
Marek Kubica  ma...@xivilization.net wrote:
On 28 Jun 2009 11:45:06 -0700
a...@pythoncraft.com (Aahz) wrote:

 Perhaps I was unclear: I already knew what LMGTFY stands for, and I
 think that using a site that requires JavaScript is anti-social.

Maybe they could just redirect to Google if JS wasn't detected.

Exactly.  They have chosen to be anti-social; therefore, I think anyone
using lmgtfy.com is also anti-social.
-- 
Aahz (a...@pythoncraft.com)   * http://www.pythoncraft.com/

as long as we like the same operating system, things are cool. --piranha
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Imaging Library download link broken?

2009-06-29 Thread Tim Harig
On 2009-06-29, peter peter.mos...@talk21.com wrote:
 Whilst this is an interesting discussion about installers, I'm still
 trying to find a copy of PIL.  Any ideas?

I alluded to a source version below.  It will compile on Windows as well as
on *nix.

Google finds what looks like older versions here:

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


Re: problems with mysql db

2009-06-29 Thread Petr Messner
Hi,

use %s instead of %d in SQL statements, because (AFAIK) conversions
(including SQL escaping) from Python values to SQL values are done
before the % operator is called - that value is not a number by that
point.

I hope you understood it, sorry for my English :-) You can also check
MySQLdb module source, it's pretty clear.

PM

2009/6/29 golu bhardwajjaye...@gmail.com:
 here i have posted my code...plz tell why am i getting the error int
 argument required on the hash marked line(see below) although i am
 giving an int value
 #the code
 import os
 import string
 import MySQLdb
 import stopcheck
 conn = MySQLdb.connect(host='localhost',user='root',db='urdb')

 def file_extractor(dir_name):
url_count = 0

for file in os.listdir(dir_name):
  if(file[-4:] == '.txt'):
file_path = os.path.join(dir_name,file)
curse = conn.cursor()
url_count += 1
curse.execute(INSERT INTO URL_TABLE VALUES(%d,%s),
 (url_count,file_path)) #error
word_extractor(url_count,file_path)
 def word_extractor(url_count,file):
fhandle =  open(file)
line = fhandle.readline()
k=stopcheck.checker()
k.create()

while line:
   words = line.split()
   cursor = conn.cursor()
   for word1 in words:
   if word1 not in string.punctuation:
if (k.check(word1) is 0) and (word1[0:4] != 'http') :
   word_count+=1
   try:
cursor.execute(INSERT INTO word_table(id,word)
 VALUES(%d,%s) , (word_count,word1))
cursor.execute(INSERT INTO wordmatch
 (word_id,url_id) values(%d,%d),(word_count,url_count))
   except MySQLdb.Error, e:
 print Error %d: %s % (e.args[0], e.args[1])
   line=fhandle.readline()

 if __name__ == '__main__':
#url_count=0
#word_count=0

dir = os.path.join('D://','acm')
file_extractor(dir)
 --
 http://mail.python.org/mailman/listinfo/python-list

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


Re: Running Invisible console Application

2009-06-29 Thread Charles Yeomans


On Jun 29, 2009, at 7:28 AM, Elf Scripter wrote:

Hi, i have a console application that i want to ran (invisible) as a  
daemon, how can i do that?




Search the web for python + daemon.  I found plenty of code, including  
mostly prewritten solutions, for my own work.


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


Re: creating garbage collectable objects (caching objects)

2009-06-29 Thread Gabriel Genellina

En Mon, 29 Jun 2009 08:01:20 -0300, Dave Angel da...@ieee.org escribió:

News123 wrote:



What I was more concerned is a group of output images depending on TWO
or more input images.

Depending on the platform (and the images) I might not be able to
preload all two (or more images)

So,  as CPython's garbage collection takes always place immediately,
then I'd like to pursue something else.
I can create a cache, which caches input files as long as python leaves
at least n MB available for the rest of the system.


As I said earlier, I think weakref is probably what you need.  A weakref  
is still a reference from the point of view of the ref-counting, but not  
from the point of view of the garbage collector.  Have you read the help  
on weakref module?  In particular, did you read Pep 0205?
http://www.python.org/dev/peps/pep-0205/


You've misunderstood something. A weakref is NOT a reference from the  
point of view of the ref-counting, it adds zero to the reference count.  
When the last real reference to some object is lost, the object is  
destroyed, even if there exist weak references to it. That's the whole  
point of a weak reference. The garbage collector isn't directly related.


py from sys import getrefcount as rc
py class X(object): pass
...
py x=X()
py rc(x)
2
py y=x
py rc(x)
3
py import weakref
py r=weakref.ref(x)
py r
weakref at 00BE56C0; to 'X' at 00BE4F30
py rc(x)
3
py del y
py rc(x)
2
py del x
py r
weakref at 00BE56C0; dead

(remember that getrefcount -as any function- holds a temporary reference  
to its argument, so the number it returns is one more than the expected  
value)



Object cache is one of the two reasons for the weakref module.


...when you don't want the object to stay artificially alive just because  
it's referenced in the cache. But the OP wants a different behavior, it  
seems. A standard dictionary where images are removed when they're no more  
needed (or a memory restriction is fired).


--
Gabriel Genellina

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


Configuring Python for Tcl/Tk in UNIX

2009-06-29 Thread Chris Marshall
My goal is to use Tkinter on a ScientificLinux machine for a GUI I wrote.  I 
installed Python 2.6.2, then built Tcl and Tk 8.5.7 from source.  The final 
step is to configure Python 2.6 to run Tk.  When I use the make command in 
the Python 2.6.2 directory, all is well until it tries to built _tkinter.so.  I 
get an error as follows:
*** WARNING: renaming _tkinter since importing it failed: libtk8.5.so: cannot 
open shared object file: No such file or directory.
Failed to build the following modules:
_tkinter

I cannot use the default install location of /usr/bin, so I am trying to 
install into another directory.  I line-by-line edited the setup.py file to 
point to the proper directory and I get the same error.

Has anyone had a similar problem?

Any advice is greatly appreciated.

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


Re: problems with mysql db

2009-06-29 Thread Gabriel Genellina
En Mon, 29 Jun 2009 10:32:40 -0300, Petr Messner petr.mess...@gmail.com  
escribió:



use %s instead of %d in SQL statements, because (AFAIK) conversions
(including SQL escaping) from Python values to SQL values are done
before the % operator is called - that value is not a number by that
point.

I hope you understood it, sorry for my English :-) You can also check
MySQLdb module source, it's pretty clear.


It's best to think of %s as just a marker; other adapters use ? or :3 for  
the same purpose, and other styles exist too.
The fact that it's the same character used for formatting strings with the  
% operator is an unfortunate coincidence (or a very bad choice, I don't  
know).


--
Gabriel Genellina

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


Re: pep 8 constants

2009-06-29 Thread Eric S. Johansson
Peter Otten wrote:
 Eric S. Johansson wrote:
 
 MultiWordName  capmulitno-spacecapwordnospacecapname
 very high error rate.  many retries or hand hurting typing.
 
 Can you define macros in your speech recognition software?
 
 capmulticamelwordcamelname
 
 might slightly lower the error rate.
 

Yes it would. I think it would be possible to specify a better grammar however.
In the context of speech engine, if you know how the word is going to be used,
(i.e. it's a method, it's a class, etc.) you can automatically do the
transformation as part of the editors function. You need to know where you are
in the syntax tree and that gives you enough knowledge to do the name
transformation.

When you stop thinking of speech recognition interactions as discrete macros or
magic tricks, you can do a lot to accelerate coding.

Fruit equals pear tree sub branch plus 5

The translator should know that the name on the lval is a variable (type
signature determined later) and is terminated by the word equals (or =). The
system would then apply the appropriate the name transformation. Continue on,
equals would be transformed =, pear tree would be considered a complete name and
based on whether it is a class definition or instance, would be transformed as a
single name. Sub means there's an index here and would put the appropriate
brackets between the expression branch (symbol terminated by plus) and 5 (symbol
terminated by the end of line,

fruit = pear_tree[branch+5]

The next challenge comes in editing. It's fairly simple I would like to say
edit line [1*digits] and put that line in an isolated buffer where I can
edit the English form using all of the Select-and-Say controls.

That should close the cycle from creation through editing.  a small port of the
development cycle.

fyiw, the symbol trandformation code exists and has existed for almost 10 years.
 we need smart editing environments to make use of it.
-- 
http://mail.python.org/mailman/listinfo/python-list


Python-URL! - weekly Python news and links (Jun 29)

2009-06-29 Thread Gabriel Genellina
QOTW:  Fortunately, I have assiduously avoided the real wor[l]d, and am
happy to embrace the world from our 'bot overlords.  Congratulations on
another release from the hydra-like world of multi-head development. - Scott
David Daniels, on release of 3.1
http://groups.google.com/group/comp.lang.python/msg/620d014fb549dbe6


A success story (involving a game server):

http://groups.google.com/group/comp.lang.python/browse_thread/thread/11abba7af6e266b0/

Floats and Decimal objects demythified:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/77a9ecc671602e79/

Converting Python code to C/C++: how to do it, alternatives, and when
it would be advisable:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/7152ab4f1c7dbced/

A generator expression declared at class scope: the namespace resolution
rules aren't so intuitive:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/e1ab6188673fc623/

A look at 2.1 sample code shows how much (or how little) the language
evolved over time:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/3e2139c2191bb191/

No tree data structure is available in the standard library - should
one exist?

http://groups.google.com/group/comp.lang.python/browse_thread/thread/c632217cfc7c7dcc/

Correctly implementing rich comparisons so 'set' membership works as
expected:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/c0b1c58585c110eb/

Python threading and the GIL (again):

http://groups.google.com/group/comp.lang.python/browse_thread/thread/9e22ab012388b538/

In ElementTree, XML() and fromstring() aren't the same thing:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/397f410b060afca2/

Open source Python projects that need help:

http://groups.google.com/group/comp.lang.python/browse_thread/thread/667b9922a60ea836/

Meta issue: some posts appear to be missing, depending on where you
read this (the mailing list, the newsgroup, the gmane gateway...)

http://groups.google.com/group/comp.lang.python/browse_thread/thread/6cc24ff07dfd3afd/e7ad466392094c8c?#e7ad466392094c8c

http://groups.google.com/group/comp.lang.python/browse_thread/thread/f67e695fa6364ec9/9174d8c5b4f07f74?#9174d8c5b4f07f74

[OT] Measuring Fractal Dimension (mad mathematicians only):

http://groups.google.com/group/comp.lang.python/browse_thread/thread/a258b6c9005146c5/



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

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

PythonWare complements the digest you're reading with the
marvelous daily python url
 http://www.pythonware.com/daily

Just beginning with Python?  This page is a great place to start:
http://wiki.python.org/moin/BeginnersGuide/Programmers

The Python Papers aims to publish the efforts of Python enthusiasts:
http://pythonpapers.org/
The Python Magazine is a technical monthly devoted to Python:
http://pythonmagazine.com

Readers have recommended the Planet sites:
http://planetpython.org
http://planet.python.org

comp.lang.python.announce announces new Python software.  Be
sure to scan this newsgroup weekly.
http://groups.google.com/group/comp.lang.python.announce/topics

Python411 indexes podcasts ... to help people learn Python ...
Updates appear more-than-weekly:
http://www.awaretek.com/python/index.html

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

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

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

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

The Summary of Python Tracker Issues is an automatically generated
report summarizing new bugs, closed ones, and patch submissions. 

http://search.gmane.org/?author=status%40bugs.python.orggroup=gmane.comp.python.develsort=date

Although unmaintained since 2002, 

Re: [RELEASED] Python 3.1 final

2009-06-29 Thread Nobody
On Mon, 29 Jun 2009 13:57:49 +0200, Hallvard B Furuseth wrote:

 Okay, that's useful, except that it may have some bugs:
 (...)
 Assuming that this gets fixed, it should make most of the problems with
 3.0 solvable. OTOH, it wouldn't have killed them to have added e.g.
 sys.argv_bytes and os.environ_bytes.
 
 That's hopeless to keep track of across modules if something modifies
 sys.argv or os.environ.

Oh, I wasn't suggesting that they should be updated. Just that there
should be some way to get at the original data.

The mechanism used in 3.1 is sufficient. I'm mostly concerned that it's
*possible* to recover the data; convenience is of secondary importance.

Calling sys.setfilesystemencoding('iso-8859-1') right at the start of the
code eliminates most of the issues. It's just the stuff which happens
before the first line of code is executed (sys.argv, os.environ, sys.stdin
etc) which was problematic.

[BTW, it isn't just Python that has problems. The directory where I was
performing tests happened to be an svn checkout. A subsequent svn update
promptly crapped out because I'd left behind a file whose name wasn't
valid ASCII.]

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


Find the name of a setup tools plugin when its class is known.

2009-06-29 Thread Mr SZ

Hi,

Using pkg_resources, I can iterate through the plugins in an entrypoint and 
note down the plugin classes and all using 
pkg_resources.iter_entry_points(ENTRYPOINT)

Now, when the plugin is loaded, I want to know it's entrypoint name as I have 
to load a bunch of settings identified by the name string.


Regards,
SZ


 life isn't heavy enough,it flies away and floats far above action


  Access Yahoo!7 Mail on your mobile. Anytime. Anywhere.
Show me how: http://au.mobile.yahoo.com/mail
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [RELEASED] Python 3.1 final

2009-06-29 Thread Nobody
On Mon, 29 Jun 2009 11:41:11 +, Antoine Pitrou wrote:

 Nobody nobody at nowhere.com writes:
 
 This results in an internal error:
 
  \udce4\udceb\udcef\udcf6\udcfc.encode(iso-8859-1, surrogateescape)
 Traceback (most recent call last):
   File stdin, line 1, in module
 SystemError: Objects/bytesobject.c:3182: bad argument to internal function
 
 Please report a bug on http://bugs.python.org

Done.

 As for a bytes version of sys.argv and os.environ, you're welcome to propose a
 patch (this would be a separate issue on the aforementioned issue tracker).

Assuming that the above bug gets fixed, it isn't really necessary. In
particular, maintaining bytes/string versions in the presence of updates
is likely to be more trouble than it's worth. 

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


Re: pep 8 constants

2009-06-29 Thread Eric S. Johansson
alex23 wrote:
 Eric S. Johansson e...@harvee.org wrote:
 no, I know the value if convention when editors can't tell you anything about
 the name in question.  I would like to see more support for disabled 
 programmers
 like myself and the thousands of programmers injured every year and forced to
 leave the field.  seriously, there is no money in disability access 
 especially
 for programmers.
 
 Well, if we can't use conventions like uppercasing, camelcasing and
 underscoring, what are you recommending we do instead?

help build a smart editing environment please.
 
 You seem to be asking us to change our behaviour to benefit only
 others, but without offering any guidance on to how that is possible.
 More importantly, shouldn't these modifications to common conventions
 be coming _from_ the community of disabled programmers? I have a hard
 time ensuring that I've gotten accurate requirements from co-workers
 with whom I can actually see and speak, trying to determine how I
 could write my code with accessibility in mind without any established
 means of gauging success just seems impossible.

Extremely valid point. The behavior I'm asking you to change is to consider the
impact choices you make have on people with disabilities. I can only advocate
for disabled programmer since I am one. Have been so for over 15 years. Have
tried to maintain my position as architectural expert only to receive from
venture capitalists and the likes what good are you, you can't know enough to
design our systems because you can't code (yes, real quote). This is not always
the case but enough that it really hurts my economics as well as the economics
of other disabled programmers.

Back in early 2000, I ran a series of workshops on the very issue of programming
by voice. Back then we recognized the necessity for very smart editing
environments which can tell us enough about what each symbol means so that we
can direct the appropriate transformations from a higher-level grammar. I've
introduce concepts such as command disambiguation through reduction of scope.
Other people have added very good ideas with regards to usability and user
interfaces for speech driven environment. Unfortunately, they all are gluons to
an editor and they don't really integrate well because the editor isn't smart
enough.

Heck, have you ever noticed how most Python smart editors can't even indent
properly according to local contexts. Emacs is the only one and even that one
sometimes fails

I can give you guidance as to what needs to be done. Other people can give
guidance but I'm shooting for what may seem unachievable. Work with me a while
and I will guide you as to how it's achievable. Maybe not by you but by someone
we can find. I have lived way too many years with circus tricks. I don't want to
end my life realizing I wasted my time in IT and regretting that I didn't take
up the offer by mass rehab to go in restaurant or hotel management.

one thing you can do to get a feel for out life is to get a copy of Naturally
Speaking standard (100$ staples) and remove/cover keyboard.  write email etc at
first (10h) then try to write pep8 code.  note to anyone who tries this,  I'll
support you in getting DNS running and help figure out any problems.  only cost
is if I tell you to do something like get a new mic, *do it*.

I've lived this works and probably have put more deep thought and 8kloc into it
because I do not accept circures tricks as a way of life.  I want it to work
right and I know how to do it.  I just don't have the hands and hte money to pay
me to do it.

 
 and forgive me if this comes off sounding like a jerk but if
 the collective you don't give a sh** about your fellow programmers, who will?
 
 This isn't intended to be callous, as I feel that the collective
 doesn't care as a whole about _any_ programmers, but isn't the answer
 the very same disabled programmers for whom accessibility is an issue?
 Programming tends to be needs driven (which, admittedly, can be simply
 to pay the bills), and those who have a need tend to be better at
 working out how to address it.

yup  how long will i be before you become disablesd?  maybe not as badly as I am
but you should start feeling some hand problems in your later 40's to early 50's
and it goes down hill from there.  self preservation/interest comes to mind as a
possible motive for action.  I thought 15 years would be enough for somebody
else to push the isssue but no.  if it is going to be, it has to be me.
 
 One possibility may be to approach a group for whom accessibility is
 already a consideration, such as the Gnome Accessibility Project:
 http://live.gnome.org/GAP

not right focus for this project.  tis one needs **deep** python knowledge (gvr
level) and embedding it into an editor.  heck, maybe we need a python
interpreter in the editor to resolve some of the symbol stuff  if we can get
useful data  from incomplete code.

and I'll leave you an editor feature that may be usefull for all


Re: problems with mysql db

2009-06-29 Thread Scott David Daniels

golu wrote:

here i have posted my code...plz tell why am i getting the error int
argument required on the hash marked line(see below) although i am
giving an int value
... url_count += 1
curse.execute(INSERT INTO URL_TABLE VALUES(%d,%s),
  (url_count,file_path)) #error

 ...

Try something more like:
 ... url_count += 1
 curse.execute(INSERT INTO URL_TABLE VALUES(%d,%s),
   [(url_count,file_path)])
 ...
--
http://mail.python.org/mailman/listinfo/python-list


Using Python for file packing

2009-06-29 Thread Aaron Scott
I'm working on a Python application right now that uses a large number
of audio assets. Instead of having a directory full of audio, I'd like
to pack all the audio into a single file. Is there any easy way to do
this in Python? My first instinct was to attempt to pickle all the
audio data, but something tells me that that experiment would only end
in tears.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pep 8 constants

2009-06-29 Thread Eric S. Johansson
Tim Chase wrote:
 It sounds like the issue should be one of making your screen-reader
 smarter, not dumbing down Python conventions.  I don't know what SR
 you're using (Jaws?  Window Eyes?  yasr? screeder?  speakup? 

Naturally speaking is speech recognition (speech in text out)  it is not text to
speech although it does have a pluging for that
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: creating garbage collectable objects (caching objects)

2009-06-29 Thread Dave Angel

Gabriel Genellina wrote:
div class=moz-text-flowed style=font-family: -moz-fixedEn Mon, 
29 Jun 2009 08:01:20 -0300, Dave Angel da...@ieee.org escribió:

News123 wrote:



What I was more concerned is a group of output images depending on TWO
or more input images.

Depending on the platform (and the images) I might not be able to
preload all two (or more images)

So,  as CPython's garbage collection takes always place immediately,
then I'd like to pursue something else.
I can create a cache, which caches input files as long as python leaves
at least n MB available for the rest of the system.


As I said earlier, I think weakref is probably what you need.  A 
weakref is still a reference from the point of view of the 
ref-counting, but not from the point of view of the garbage 
collector.  Have you read the help on weakref module?  In particular, 
did you read Pep 0205?   http://www.python.org/dev/peps/pep-0205/


You've misunderstood something. A weakref is NOT a reference from the 
point of view of the ref-counting, it adds zero to the reference 
count. When the last real reference to some object is lost, the 
object is destroyed, even if there exist weak references to it. That's 
the whole point of a weak reference. The garbage collector isn't 
directly related.


py from sys import getrefcount as rc
py class X(object): pass
...
py x=X()
py rc(x)
2
py y=x
py rc(x)
3
py import weakref
py r=weakref.ref(x)
py r
weakref at 00BE56C0; to 'X' at 00BE4F30
py rc(x)
3
py del y
py rc(x)
2
py del x
py r
weakref at 00BE56C0; dead

(remember that getrefcount -as any function- holds a temporary 
reference to its argument, so the number it returns is one more than 
the expected value)



Object cache is one of the two reasons for the weakref module.


...when you don't want the object to stay artificially alive just 
because it's referenced in the cache. But the OP wants a different 
behavior, it seems. A standard dictionary where images are removed 
when they're no more needed (or a memory restriction is fired).


Thanks for correcting me.  As I said earlier, I have no experience with 
weakref.  The help and the PEP did sound to me like it would work for 
his needs.


So how about adding an attribute in the large object that refers to the 
object iself?.  Then the ref count will never go to zero, but it can be 
freed by the gc.  Also store the ref in a WeakValueDictionary, and you 
can find the object without blocking its gc.


And no, I haven't tried it, and wouldn't unless a machine had nothing 
important running on it.  Clearly, the gc might not be able to keep up 
with this kind of abuse.  But if gc is triggered by any attempt to make 
too-large an object, it might work.


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


Creating an Instance Messenger type of application

2009-06-29 Thread Elf Scripter
Hello,Has anyone created an Instance Messenger in Python before, i mean a
simple or Complex GUI based instance messenger?

I thought about something like, the client also act as server, has it`s own
listening port, but how can i handle uer auth? and adding visual effects to
it.

Please i am not trying to design another Yahoo IM/Skype but just for
learning and also want to create real live application using the socket
module.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [RELEASED] Python 3.1 final

2009-06-29 Thread Nobody
On Mon, 29 Jun 2009 13:05:51 +0100, Paul Moore wrote:

 As for a bytes version of sys.argv and os.environ, you're welcome to
 propose a patch (this would be a separate issue on the aforementioned
 issue tracker).
 
 But please be aware that such a proposal would have to consider:
 
 1. That on Windows, the native form is the character version, and the
 bytes version would have to address all the same sorts of encoding
 issues that the OP is complaining about in the character versions. [1]

A bytes version doesn't make sense on Windows (at least, not on the
NT-based versions, and the DOS-based branch isn't worth bothering about,
IMHO).

Also, Windows *needs* to deal with characters due to the
fact that filenames, environment variables, etc are case-insensitive.

 2. That the proposal address the question of how to write portable,
 robust, code (given that choosing argv vs argv_bytes based on
 sys.platform is unlikely to count as a good option...)

There is a tension here between robustness and portability. In my
situation, robustness means getting the unadulterated data. I can always
adulterate it myself if I need to.

 3. Why defining your own argv_bytes as argv_bytes =
 [a.encode(iso-8859-1, surrogateescape) for a in sys.argv] is
 insufficient (excluding issues with bugs, which will be fixed
 regardless) for the occasional cases where it's needed.

Other than the bug, it appears to be sufficient. I don't need to support
a locale where nl_langinfo(CODESET) is ISO-2022 (I *do* need to support
lossless round-trip of ISO-2022 filenames, possibly stored in argv and
maybe even in environ, but that's a different matter; the code only
really needs to run with LANG=C).

 [1] And my understanding, from the PEP, is that even on POSIX, the
 argv and environ data is intended to be character data, even though
 the native C APIs expose a byte-oriented interface. So conceptually,
 character format is correct on POSIX as well... (But I don't write
 code for POSIX systems, so I'll leave it to the POSIX users to debate
 this point further).

Even if it's intended to be character data, it isn't *required* to be.
In particular, it's not required to be in the locale's encoding.

A common example of what I need to handle is:

find /www ... -print0 | xargs -0 myscript

where the filenames can be in a wide variety of different encodings
(sometimes even within a single directory).

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


Ctypes, pthreads and pthread_mutex_t

2009-06-29 Thread Doug
Has any converted the structure  pthread_mutex_t bits/wordsize.h  to
a ctypes structure class ?
I looking at some C code that is using pthreads and need to translate
pthreads_mutex_t structure into python (via ctypes)

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


Making code run in both source tree and installation path

2009-06-29 Thread Javier Collado
Hello,

I would like to be able to run the main script in a python project
from both the source tree and the path in which it's installed on
Ubuntu. The script, among other things, imports a package which in
turns makes use of some data files that contains some metadata that is
needed in xml format.

The source tree has an structure such as this one:
setup.py
debian/ (packaging files)
src/ (source code)
src/lib (package files)
src/data (data files)
src/bin (main script)

However, when the project is installed using setup.py install, the
directory structure is approximately this way:
/usr/local/bin (main script)
/usr/local/share/project_name (data files)
/usr/local/lib/python2.x/dist-packages/project_name (library files)

And when installing the code through a package, the structure is the
same one, but removing local.

Hence, the data files aren't always in the same relative directories
depending on we're executing code from the source tree or from the
installation. To make it possible to run the code from both places,
I've seen different approaches:
- distutils trick in setup.py to modify the installed script (i.e.
changing a global variable value) so that it has a reference to the
data files location.
- Heuristic in the package code to detect when it's being executed
from the source tree and when it has been the installed
- Just using an environment variable that the user must set according
to his needs

I guess that there are other options, for example, maybe using
buildout. What would you say it's the best/more elegant option to
solve this problem?

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


Re: Using Python for file packing

2009-06-29 Thread Kushal Kumaran
On Mon, Jun 29, 2009 at 9:17 PM, Aaron Scottaaron.hildebra...@gmail.com wrote:
 I'm working on a Python application right now that uses a large number
 of audio assets. Instead of having a directory full of audio, I'd like
 to pack all the audio into a single file. Is there any easy way to do
 this in Python? My first instinct was to attempt to pickle all the
 audio data, but something tells me that that experiment would only end
 in tears.

Do you mean like a zip or tar file?

http://docs.python.org/library/zipfile.html
http://docs.python.org/library/tarfile.html

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


Re: Using Python for file packing

2009-06-29 Thread Aaron Scott
 Do you mean like a zip or tar file?

 http://docs.python.org/library/zipfile.htmlhttp://docs.python.org/library/tarfile.html


I had no idea you could access a single file from a ZIP or TAR without
explicitly extracting it somewhere. Thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Creating an Instance Messenger type of application

2009-06-29 Thread Simon Forman
On Mon, Jun 29, 2009 at 12:18 PM, Elf Scripterlfscrip...@gmail.com wrote:
 Hello,
 Has anyone created an Instance Messenger in Python before, i mean a simple
 or Complex GUI based instance messenger?
 I thought about something like, the client also act as server, has it`s own
 listening port, but how can i handle uer auth? and adding visual effects to
 it.
 Please i am not trying to design another Yahoo IM/Skype but just for
 learning and also want to create real live application using the socket
 module.

Instant, not Instance,  Did you check google?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: pythonware.com down?

2009-06-29 Thread bunnybones
I'm having the same problem accessing pythonware or effbot.
I can't find any news about their server status.
I can ping both addresses just fine.
Does anyone know what is going on?
Maybe the ghosts of celebrities recently passed are mucking with the
tubes.

RIP Billy Mays
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Creating an Instance Messenger type of application

2009-06-29 Thread Simon Forman
On Mon, Jun 29, 2009 at 12:44 PM, Elf Scripterlfscrip...@gmail.com wrote:
 Thank you for correcting my mistake.
 I checked google but nothing close. did you have any idea?

 On Mon, Jun 29, 2009 at 5:42 PM, Simon Forman sajmik...@gmail.com wrote:

 On Mon, Jun 29, 2009 at 12:18 PM, Elf Scripterlfscrip...@gmail.com
 wrote:
  Hello,
  Has anyone created an Instance Messenger in Python before, i mean a
  simple
  or Complex GUI based instance messenger?
  I thought about something like, the client also act as server, has it`s
  own
  listening port, but how can i handle uer auth? and adding visual effects
  to
  it.
  Please i am not trying to design another Yahoo IM/Skype but just for
  learning and also want to create real live application using the socket
  module.

 Instant, not Instance,  Did you check google?



I wouldn't try writing an IM or IRC client and/or server directly on
the socket module, unless you really really wanted the learning
experience.  You might look at the words sub-project of the Twisted
project [1] (although Twisted code has a significant learning curve
itself, they do almost all of the network related heavy lifting for
you.)

There's also apparently a python binding to something called libpurple
which seems to be a library used/provided by the purple
multi-protocol IM/IRC client (used to be called GAIM). [2]

HTH,
~Simon

[1] http://twistedmatrix.com/trac/wiki/TwistedWords
[2] http://briglia.net/wiki/tiki-index.php?page=Python-purple+Howto
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: fork, threads and proper closing

2009-06-29 Thread OdarR
On 29 juin, 14:44, Francesco Bochicchio bieff...@gmail.com wrote:
 On 29 Giu, 07:10, OdarR olivier.da...@gmail.com wrote:



  On 28 juin, 23:26, Tomasz Pajor ni...@puffy.pl wrote:

   Hello,

   Configuration is as follows.

   I have a starter process which creates 3 sub processes (forks) and each
   of this processes creates a number of threads.
   Threads in that processes have semaphore so on KeyboardInterrupt without
   sending a sigterm to the subprocess i'm not able to close threads.
   Is there any work around? Can I somehow run join for the thread on
   keyboard interrupt?

  When creating a thread you can add a Queue parameter to communicate
  with threads:http://docs.python.org/library/queue.html
  easy and reliable.

  give them a poison pill in the queue: a recognizable object placed
  on the queue that means when you get this, stop.

 This is the way I usually go, but it has one important limitation: if
 the thread is waiting
 for a blocking I/O operation to complete, like reading from a socket
 with no data or waiting

add a small wait (time.sleep()), and also, I/O function in Python can
often releas the GIL...

 for a locked resource (i.e. semaphore) to be unlocked, it will not
 service the queue and will
 not read the 'quit command' (the poison pill), and therefore will not
 quit until the blocking
 I/O terminates (and it could be never).

 ASAIK, there is no way - in python - to solve this.

no easy way, yes...
but I think I gave a good advice to our friend Tomasz :)

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


python library call equivalent to `which' command

2009-06-29 Thread destroooooy
Hi,
  I'm looking for a Python library function that provides the same
functionality as the `which' command--namely, search the $PATH
variable for a given string and see if it exists anywhere within. I
currently examine the output from `which' itself, but I would like
something more portable. I looked through the `os' and `os.path'
modules but I didn't find anything.

TIA

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


Re: pep 8 constants

2009-06-29 Thread Ethan Furman

Eric S. Johansson wrote:


yup  how long will i[t] be before you become disablesd?  maybe not as badly as 
I am
but you should start feeling some hand problems in your later 40's to early 50's
and it goes down hill from there.  self preservation/interest comes to mind as a
possible motive for action.  I thought 15 years would be enough for somebody
else to push the isssue but no.  if it is going to be, it has to be me.


For anyone who is still able to use their hands for typing, especially 
if you're beginning to encounter the painful wrists, consider switching 
to a Dvorak layout.  It was a system I was curious about even before I 
needed it, and when I did need it I was able to create the layout in 
assembler (now, of course, it's widely available as a standard keyboard 
layout).  I started noticing the pain in my late twenties (aggravated, 
I'm sure, by arthritis), but with switching to Dvorak the pain left and 
has only very rarely been noticable again.  It will mostly likely be a 
challenge to switch, but well worth it.


http://en.wikipedia.org/wiki/Dvorak_Simplified_Keyboard

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


Re: validating HTTPS certificates?

2009-06-29 Thread Heikki Toivonen
andras.horv...@cern.ch wrote:
 I'm in the process of picking a language for a client application that
 accesses a HTTPS (actually SOAP) server.  This would be easy enough in
 Python, but I came across a strange fact: neither httplib nor urllib
 offer the possibility to actually verify the server's certificate.

Right, stdlib does not do this for you automatically. You'd either need
to write that code yourself, or use a third party library. I wrote a
long post about this when 2.6 came out:

http://www.heikkitoivonen.net/blog/2008/10/14/ssl-in-python-26/

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


Re: Python Imaging Library download link broken?

2009-06-29 Thread geo
On Jun 29, 2:54 pm, peter peter.mos...@talk21.com wrote:
 Whilst this is an interesting discussion about installers, I'm still
 trying to find a copy of PIL.  Any ideas?

Hello,

I had the very same problem and found this:

http://www.portablepython.com/

It contains PIL and some other cool stuff. Hope it helps.

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


Re: python library call equivalent to `which' command

2009-06-29 Thread Tim Pinkawa
On Mon, Jun 29, 2009 at 12:54 PM, destroydestrooo...@gmail.com wrote:
 Hi,
  I'm looking for a Python library function that provides the same
 functionality as the `which' command--namely, search the $PATH
 variable for a given string and see if it exists anywhere within. I
 currently examine the output from `which' itself, but I would like
 something more portable. I looked through the `os' and `os.path'
 modules but I didn't find anything.

This works on POSIX systems. Windows uses semicolons to separate paths
rather than colons so that would need to be taken into account when
running on Windows. This also doesn't recognize shell built-ins, only
real binaries.

import os

def which(file):
for path in os.environ[PATH].split(:):
if file in os.listdir(path):
print %s/%s % (path, file)

 which(ls)
/bin/ls
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python library call equivalent to `which' command

2009-06-29 Thread Tim Golden

Tim Pinkawa wrote:

On Mon, Jun 29, 2009 at 12:54 PM, destroydestrooo...@gmail.com wrote:

Hi,
 I'm looking for a Python library function that provides the same
functionality as the `which' command--namely, search the $PATH
variable for a given string and see if it exists anywhere within. I
currently examine the output from `which' itself, but I would like
something more portable. I looked through the `os' and `os.path'
modules but I didn't find anything.


This works on POSIX systems. Windows uses semicolons to separate paths
rather than colons so that would need to be taken into account when
running on Windows. This also doesn't recognize shell built-ins, only
real binaries.

import os

def which(file):
for path in os.environ[PATH].split(:):
if file in os.listdir(path):
print %s/%s % (path, file)


which(ls)

/bin/ls


There's a which.py in the tools directory included in
the Python distribution. On windows, that's
c:\python26\tools\scripts; don't know where to look
on Linux.

Don't know how good it is as I -- like many, I suspect --
wrote my own, which in my case is Windows-specific.

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


TWiki Python API Wrapper

2009-06-29 Thread ma
Has anyone come across a decent python API wrapper for TWiki? I'm trying to
automate some reports and logs to automatically post, create topics, and
re-arrange a few things on our TWiki, but my googleFu has failed me :(

I did find an interesting module in Perl,
http://cpanratings.perl.org/dist/WWW-Mechanize-TWiki . Looking at the TWiki
documentations, I found a perl API reference:
http://twiki.org/cgi-bin/view/TWiki/TWikiFuncDotPm . A proof of concept,
using these two perl modules, was generated by a blog post here:
http://roberthanson.blogspot.com/2006/01/copying-from-blogger-to-twiki-with.html

Before I make my own pythonic port, using mechanize, and wrapping around the
aforementioned TWiki api, I wanted to see if anyone had any other ideas,
approaches, or modules to help expedite the task?

Thanks!
Mahmoud Abdelkader
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: No trees in the stdlib?

2009-06-29 Thread Terry Reedy

Paul Rubin wrote:


The idea is you can accomplish the equivalent of insertion or deletion
by allocating a new root, along with the path down to the place you
want to insert, i.e. O(log n) operations.  So instead of mutating an
existing tree, you create a new tree that shares most of its structure
with the old tree, and switch over to using the new tree.


Now I get what your have been talking about over several posts.
Update and mutate are kind of synonymous in my mind, but the above 
explains how they can be different.


  This

trivially lets you maintain snapshots of old versions of the tree,
implement an undo operation, have a background thread do a complex
operation on a snapshot while the foreground thread does any number of
update-and-replace operations, etc.

This is very standard stuff.


Now for someone raised on arrays, iteration, and procedural programming ;-).


  http://en.wikipedia.org/wiki/Persistent_data_structure


Reading it now.



The wikipedia article on AVL trees makes it pretty obvious how an
implementation would work.


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


Re: pep 8 constants

2009-06-29 Thread Eric S. Johansson
Ethan Furman wrote:
 Eric S. Johansson wrote:

 yup  how long will i[t] be before you become disablesd?  maybe not as
 badly as I am
 but you should start feeling some hand problems in your later 40's to
 early 50's
 and it goes down hill from there.  self preservation/interest comes to
 mind as a
 possible motive for action.  I thought 15 years would be enough for
 somebody
 else to push the isssue but no.  if it is going to be, it has to be me.
 
 For anyone who is still able to use their hands for typing, especially
 if you're beginning to encounter the painful wrists, consider switching
 to a Dvorak layout.  It was a system I was curious about even before I
 needed it, and when I did need it I was able to create the layout in
 assembler (now, of course, it's widely available as a standard keyboard
 layout).  I started noticing the pain in my late twenties (aggravated,
 I'm sure, by arthritis), but with switching to Dvorak the pain left and
 has only very rarely been noticable again.  It will mostly likely be a
 challenge to switch, but well worth it.

a good suggestion but not really addressing the point I'm trying to make of
building a system that would help people more profoundly injured.  for example,
I've tried Dvorak and the act of typing was so painful that I couldn't learn it
-- 
http://mail.python.org/mailman/listinfo/python-list


Direct interaction with subprocess - the curse of blocking I/O

2009-06-29 Thread Pascal Chambon

Hello everyone

I've had real issues with subprocesses recently : from a python script, 
on windows, I wanted to give control to a command line utility, i.e 
forward user in put to it and display its output on console. It seems 
simple, but I ran into walls :
- subprocess.communicate() only deals with a forecast input, not 
step-by-step user interaction

- pexpect module is unix-only, and for automation, not interactive input
- when wanting to do all the job manually (transfering data between the 
standard streams of the python program and the binary subprocess, I met 
the issue : select() works only on windows, and python's I/O are 
blocking, so I can't just, for example, get data from the subprocess' 
stdout and expect the function to return if no input is present - the 
requesting thread might instead block forever.


Browsing the web, I found some hints :
- use the advanced win32 api to create non-blocking I/O : rather 
complicated, non portable and far from the python normal files
- use threads that block on the different streams and eat/feed them 
without ever stopping : rather portable, but gives problems on shutdown 
(How to terminate these threads without danger ? On some OSes, a process 
never dies as long as any thread - even daemonic - lives, I've seen 
people complaining about it).


So well, I'd like to know, do you people know any solution to this 
simple problem - making a user interact directly with a subprocess ? Or 
would this really require a library handling each case separately (win32 
api, select().) ?


Thanks a lot for your interest and advice,
regards,
Pascal
--
http://mail.python.org/mailman/listinfo/python-list


Re: python library call equivalent to `which' command

2009-06-29 Thread Christian Heimes
Tim Pinkawa wrote:
 def which(file):
 for path in os.environ[PATH].split(:):
 if file in os.listdir(path):
 print %s/%s % (path, file)

if file in os.list() is slow and not correct. You have to check if the
file is either a real file or a symlink to a file and not a directory or
special. Then you have to verify that the file has the executable bit, too.

Christian

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


Re: python library call equivalent to `which' command

2009-06-29 Thread Nobody
On Mon, 29 Jun 2009 13:53:30 -0500, Tim Pinkawa wrote:

  I'm looking for a Python library function that provides the same
 functionality as the `which' command--namely, search the $PATH
 variable for a given string and see if it exists anywhere within. I
 currently examine the output from `which' itself, but I would like
 something more portable. I looked through the `os' and `os.path'
 modules but I didn't find anything.
 
 This works on POSIX systems. Windows uses semicolons to separate paths
 rather than colons so that would need to be taken into account when
 running on Windows. This also doesn't recognize shell built-ins, only
 real binaries.

FWIW, which doesn't recognise built-ins either; the type built-in
does.

 import os
 
 def which(file):
 for path in os.environ[PATH].split(:):
 if file in os.listdir(path):
 print %s/%s % (path, file)

There are a couple of problems with this:

1. which only considers executable files, and the default behaviour is
to only display the first matching file. Also, I'm assuming that the OP
wants a function which returns the path rather than printing it.

2. os.listdir() requires read permission (enumerate permission) on each
directory. The standard which utility stat()s each possible candidate,
so it only requires execute permission (lookup permission) on the
directories. A secondary issue is performance; enumerating a directory to
check for a specific entry can be much slower than stat()ing the specific
entry. IOW:

def which(file):
for path in os.environ[PATH].split(os.pathsep):
if os.access(os.path.join(path, file), os.X_OK):
return %s/%s % (path, file)

But for Windows, you also need to use PATHEXT, e.g.:

for dir in os.environ[PATH].split(os.pathsep):
for ext in os.environ[PATHEXT].split(os.pathsep):
 full = os.path.join(dir, %s.%s % (file, ext))
 if os.access(full, os.X_OK):
 return full

Disclaimer: I don't know how accurate os.access(..., os.X_OK) is on
Windows; OTOH, it's probably as good as you'll get.

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


Re: python library call equivalent to `which' command

2009-06-29 Thread Robert Kern

On 2009-06-29 14:31, Tim Pinkawa wrote:

On Mon, Jun 29, 2009 at 2:17 PM, Christian Heimesli...@cheimes.de  wrote:

if file in os.list() is slow and not correct. You have to check if the
file is either a real file or a symlink to a file and not a directory or
special. Then you have to verify that the file has the executable bit, too.


I realize four lines of Python does not replicate the functionality of
which exactly. It was intended to give the original poster something
to start with.

I am curious about it being slow, though. Is there a faster way to get
the contents of a directory than os.listdir() or is there a faster way
to see if an element is in a list other than x in y? I believe
'which' will terminate once it finds any match, which mine does not,
but that can be fixed by adding a break after the print.


Just check if os.path.exists(os.path.join(path, filename)).

--
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: python library call equivalent to `which' command

2009-06-29 Thread Christian Heimes
Tim Pinkawa wrote:
 I realize four lines of Python does not replicate the functionality of
 which exactly. It was intended to give the original poster something
 to start with.

Agreed!

 I am curious about it being slow, though. Is there a faster way to get
 the contents of a directory than os.listdir() or is there a faster way
 to see if an element is in a list other than x in y? I believe
 'which' will terminate once it finds any match, which mine does not,
 but that can be fixed by adding a break after the print.

You don't need to get the entire directory content to see if a file
exists. The stat() syscall is much faster because it requires fewer disk
reads. On modern file systems stat() is a O(1) operation while file in
listdir() is a O(n) operation.

By the way you need the result of os.stat anyway to see if the file has
the executable bits set.

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


Re: Tutorials on Jinja

2009-06-29 Thread wwwayne
On Thu, 25 Jun 2009 07:17:42 -0700 (PDT), Saurabh
saurabh.gupt...@gmail.com wrote:

On Jun 25, 2:04 am, Wayne Brehaut wbreh...@mcsnet.ca wrote:
 On Wed, 24 Jun 2009 11:46:55 -0700 (PDT), Saurabh

 saurabh.gupt...@gmail.com wrote:
 Hi All,

 I am trying to move my application on a MVC architecture and plan to
 use Jinja for the same. Can anyone provide me with few quick links
 that might help me to get started with Jinja?

 Perhaps the most useful link is:

 http://www.google.com/

 from which you can easily find many more with a very basic search,
 including:

 http://jinja.pocoo.org/

 Hope that helps?
 wwwayne



 Thanks,
 Saby



Thanks (Sir!). I was hoping to get some good tutorial on
implementation (which I wasn't able to find with a basic search -
http://dev.pocoo.org/projects/lodgeit/ is what I was referring to
earlier) as this is my first assignment on any template engine (never
used Cheetah, MakO, Tempita).
I would appreciate people responding with something helpful. If you
find a question pretty naive, kindly ignore the question rather than
passing comments on it. Doesn't helps anyone's time.

Not phrasing questions in a helpful way initially also doesn't lead to
good use of anyone's time, and I suggest another link:
 http://catb.org/esr/faqs/smart-questions.html

Your original question asked for a few quick links that might help me
to get started with Jinja, which made it appear you didn't know where
to start and hadn't yet done even a basic search yourself, so I
thought I  *was* being helpful. 

Now that you provide the information that would have helped others to
respond more usefully previously, perhaps they will.

w

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


Re: Q: finding distance between 2 time's

2009-06-29 Thread Nobody
On Mon, 29 Jun 2009 19:15:08 +, John Gordon wrote:

  if time_difference  3601:
 
 That's a potential off-by-one error. [...] The right test is:
 
 if time_difference = 3600:
 
 Aren't those two comparisons the same?

Not if time_difference is a float.

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


Re: Q: finding distance between 2 time's

2009-06-29 Thread Scott David Daniels

John Gordon wrote:

In 023130ef$0$19421$c3e8...@news.astraweb.com Steven D'Aprano 
st...@remove-this-cybersource.com.au writes:

if time_difference  3601:

That's a potential off-by-one error. [...] The right test is:
if time_difference = 3600:

Aren't those two comparisons the same?


Only if time_difference is an integer.

--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list


Re: python library call equivalent to `which' command

2009-06-29 Thread Nobody
On Mon, 29 Jun 2009 14:31:25 -0500, Tim Pinkawa wrote:

 if file in os.list() is slow and not correct. You have to check if the
 file is either a real file or a symlink to a file and not a directory or
 special. Then you have to verify that the file has the executable bit, too.
 
 I realize four lines of Python does not replicate the functionality of
 which exactly. It was intended to give the original poster something
 to start with.
 
 I am curious about it being slow, though. Is there a faster way to get
 the contents of a directory than os.listdir()

No.

 or is there a faster way to see if an element is in a list other than
 x in y? 

No.

However, there is a faster (and more correct) way to test for file
existence than enumerating the directory then checking whether the file is
in the resulting list, namely to stat() the file. I.e. os.path.exists()
or os.access(); the latter will allow you to check for execute permission
at the same time.

On some systems, the speed difference may be very significant. If
readdir() is a system call, os.listdir() will make one system call (two
context switches) per directory entry, while os.access() will make one
system call in total.

[Linux has the (non-standard) getdents() system call, which returns
multiple directory entries per call. The readdir() library
function uses getdents(), as it is much more efficient than using the
readdir() system call.]

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


Re: Advantages of Python (for web/desktop apps)?

2009-06-29 Thread Michael Torrie
iceangel89 wrote:
 i am mainly a PHP (mainly using Zend Framework MVC now) Web Developer. used
 .NET (VB  C#) for Desktop apps. i nv used Python and am looking at Python
 now (for desktop apps since its open source and just want to try what it
 offers, but will like to know what good it has for web development also)

Give it a try.  wxPython or PyQt is preferred for GUI development in
general on win32.  PyGTK also works on win32 but maybe isn't as
nice-looking as the first two options (although the API is much more
pythonic by some accounts).

The Idle IDE may get you started.  When you've profiled your program and
found where the common cases are slow, then you can work on optimization
substitution pure python routines with native ones written in C, C++, etc
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Direct interaction with subprocess - the curse of blocking I/O

2009-06-29 Thread Nobody
On Mon, 29 Jun 2009 21:15:52 +0200, Pascal Chambon wrote:

 I've had real issues with subprocesses recently : from a python script, 
 on windows, I wanted to give control to a command line utility, i.e 
 forward user in put to it and display its output on console.

Are you talking about a popen(..., 'w') situation? I.e. where Python
feeds data to the child's stdin but the child's stdout doesn't go through
Python?

Or a slave process, where both stdin and stdout/stderr are piped to/from
Python?

The latter is inherently tricky (which is why C's popen() lets you connect
to stdin or stdout but not both). You have to use either multiple threads,
select/poll, or non-blocking I/O.

If the child's output is to the console, it should presumably be the
former, i.e. piping stdin but allowing the child to inherit stdout, in
which case, where's the problem? Or are you piping its stdout via Python
for the hell of it?

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


Re: Using Python for file packing

2009-06-29 Thread Scott David Daniels

Aaron Scott wrote:

Do you mean like a zip or tar file?

http://docs.python.org/library/zipfile.htmlhttp://docs.python.org/library/tarfile.html



I had no idea you could access a single file from a ZIP or TAR without
explicitly extracting it somewhere. Thanks.

You will find the zip format works better if you are compressing.  The
zipfile compression is per file in the archive, rather than applied to
the entire archive (as in tarfile).  The results of the tar format
decision is that extracting the last file in a .tgz (.tar.gz) or
.tar.bz2 (sometimes called .tbz) requires the expansion of the entire
archive, while extraction on a .zip is reposition, read, and possibly
expand.

--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python Imaging Library download link broken?

2009-06-29 Thread Piet van Oostrum
 peter peter.mos...@talk21.com (p) wrote:

p Whilst this is an interesting discussion about installers, I'm still
p trying to find a copy of PIL.  Any ideas?

Pythonware is up again:

http://pythonware.com/products/pil/index.htm
-- 
Piet van Oostrum p...@cs.uu.nl
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: p...@vanoostrum.org
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python library call equivalent to `which' command

2009-06-29 Thread Scott David Daniels

Robert Kern wrote:

On 2009-06-29 14:31, Tim Pinkawa wrote:
On Mon, Jun 29, 2009 at 2:17 PM, Christian Heimesli...@cheimes.de  
wrote:

if file in os.list() is slow and not correct. You have to check if the
file is either a real file or a symlink to a file and not a directory or
special. Then you have to verify that the file has the executable 
bit, too.


I realize four lines of Python does not replicate the functionality of
which exactly. It was intended to give the original poster something
to start with.

I am curious about it being slow, though. Is there a faster way to get
the contents of a directory than os.listdir() or is there a faster way
to see if an element is in a list other than x in y? I believe
'which' will terminate once it finds any match, which mine does not,
but that can be fixed by adding a break after the print.


Just check if os.path.exists(os.path.join(path, filename)).


But on windows, checking for a list of possible extensions, it may well
be faster to operate on the listdir output.  I made my which-equivalent
function a generator, so I could choose to stop at the first entry or
continue at the invoker's pleasure (good for both Trojan-discovery and
forgot to delete the .pyc operations).

--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list


Re: Direct interaction with subprocess - the curse of blocking I/O

2009-06-29 Thread Scott David Daniels

Pascal Chambon wrote:
I've had real issues with subprocesses recently : from a python script, 
on windows, I wanted to give control to a command line utility, i.e 
forward user in put to it and display its output on console

Browsing the web, I found some hints :
- use the advanced win32 api to create non-blocking I/O : rather 
complicated, non portable ...


So well, I'd like to know, do you people know any solution to this 
simple problem - making a user interact directly with a subprocess ? Or 
would this really require a library handling each case separately (win32 
api, select().) ?


I would guess the architectural differences are so great that an attempt
to do something simple is going to involve architecture-specific code.
and I personally wouldn't have it any other way.  Simulating a shell
with hooks on its I/O should be so complicated that a script kiddie
has trouble writing a Trojan.

--Scott David Daniels
scott.dani...@acm.org
--
http://mail.python.org/mailman/listinfo/python-list


Re: python library call equivalent to `which' command

2009-06-29 Thread Trent Mick

destroy wrote:

Hi,
  I'm looking for a Python library function that provides the same
functionality as the `which' command--namely, search the $PATH
variable for a given string and see if it exists anywhere within. I
currently examine the output from `which' itself, but I would like
something more portable. I looked through the `os' and `os.path'
modules but I didn't find anything.


http://code.google.com/p/which/


Trent

--
Trent Mick
trentm at activestate.com
http://trentm.com/blog/
--
http://mail.python.org/mailman/listinfo/python-list


using input(), raw_input() to allow user to run different functions

2009-06-29 Thread rhvonl...@gmail.com
Something's been giving me difficulty..

We have a USB-attached device that we frequently debug with simple
python scripts.  The model has always been that each script logs on to
the device, does something, then logs off.  As it turns out, we have
mostly written scripts as unit tests for each API command.  So, we'll
call one script that will configure a process on the device, and a
separate script that will retrieve the results of that process.

The model is changing inside the device such that all settings will be
lost when we log off.  This means we'll have to merge a bunch of
scripts in various ways.

I thought it would be neat if I could have one master python script do
the logon, then allow the user to input the name of a previously-
written script he wanted to execute while logged on.  Finally, when
exiting the master script, the user would logout from the device.

I'm trying to test this by using input() or raw_input() to get the
function the user wants to execute.  I'm not having much luck.  Here's
an example:



Shell.py:
#! /usr/bin/env python
from CollectNDResults import *
...
request = input('Script shell  ')
print request
exec (request)   ## I realize the parentheses are not needed
...


When I run Shell.py I get this:

Script shell  CollectNDResults
function CollectNDResults at 0x00AA75F0
Traceback (most recent call last):
  File ./Shell.py, line 35, in ?
Shell(sys.argv[1:])
  File ./Shell.py, line 24, in Shell
exec (request)
TypeError: exec: arg 1 must be a string, file, or code object


Is there a good reference for me to figure out how to turn my function
name into the code object that I want to execute?  Is there a better
way to do what I'm trying to do?

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


Re: No trees in the stdlib?

2009-06-29 Thread João Valverde

João Valverde wrote:

Paul Rubin wrote:

João Valverde backu...@netcabo.pt writes:
 

Interesting, thanks. The concept is not difficult to understand but
I'm not sure it would be preferable. A copy operation should have the
same cost as a snapshot, 


You mean a deep-copy?  That is unnecessarily expensive; with a
functional structure you can snapshot (or copy) by copying a single
pointer.

  


Shallow copy...


undo is kind of redundant and multithreading... don't see a
compelling use that would justify it. 


Here is one:
 http://groups.google.com/group/comp.lang.python/msg/1fbe66701e4bc65b

  


I just skimmed that but if someone really needs multithreading for 
such intensive processing without wanting a database, fair enough I 
guess.


Have you considered how the syntax would work in Python by the way? 
This:

new_tree = old_tree.insert(object)
Just looks wrong. 


It looks fine to me.  Obviously you could support a wrapper with
a mutating slot that holds a pointer to the tree.
  
I didn't get the last part, sorry. But I think you'd have a lot of 
users annoyed that the interface is similar to a list yet their 
objects mysteriously disappear. To me, tree.insert() implies 
mutability but I defer that to others like yourself with more 
experience in Python than me.




Rereading this I got what you meant by wrapper with mutating slot.  
But that is (like I think you implied) functionally equivalent to a 
mutating data structure, with worse performance because of additional 
memory allocation and such. Is it faster to rebalance the tree with a 
persistent data structure?

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


Drawing in PDF

2009-06-29 Thread Jun
HEllo,

I've a pdf file, and i want to draw some additional stuff on it, by
example : some markup  notation. Anyone has idea how to do that ?
thank you in advance.
-- 
http://mail.python.org/mailman/listinfo/python-list


  1   2   3   >