StarCluster 0.91 Released - Scientific Computing on Amazon EC2

2010-05-28 Thread Justin Riley
Hi All,

The next version, 0.91, of StarCluster (http://web.mit.edu/starcluster)
has been released. StarCluster is a utility for creating and managing
scientific computing clusters hosted on Amazon's Elastic Compute Cloud
(EC2). StarCluster utilizes Amazon's EC2 web service to create and
destroy clusters of Linux virtual machines on demand.

New in this version:


* support for launching and managing multiple clusters on EC2

* added listclusters command for showing all active clusters on EC2

* support for attaching and NFS-sharing multiple EBS volumes

* added createimage and createvolume commands for easily creating new
AMIs and EBS volumes for use with StarCluster

* experimental support for launching clusters using spot instances

* added support for StarCluster plugins that provide the ability to
perform additional configuration/setup routines on top of StarCluster's
default cluster configuration

* added listpublic command for listing all available public StarCluser
AMIs that can be used with StarCluster

* bash/zsh command line completion for StarCluster's command line interface

Download

StarCluster is available on PyPI
(http://pypi.python.org/pypi/StarCluster) and also on the website:

http://web.mit.edu/starcluster

You will find the docs as well as links to the StarCluster mailing list
on the website.

Learn More
-

For those that are interested in learning more there is an article about
StarCluster on www.hpcinthecloud.com

http://www.hpcinthecloud.com/features/StarCluster-Brings-HPC-to-the-Amazon-Cloud-94099324.html

There is also a screencast of installing, configuring, launching, and
terminating an HPC cluster on Amazon EC2:

http://www.hpcinthecloud.com/blogs/MITs-StarCluster-An-Update-with-Screencast-94599554.html

StarCluster Description (From PYPI):

StarCluster is a utility for creating and managing computing clusters
hosted on Amazon's Elastic Compute Cloud (EC2). StarCluster utilizes
Amazon's EC2 web service to create and destroy clusters of Linux virtual
machines configured for scientific computing on demand.

To get started, the user creates a simple configuration file with their
AWS account details and a few cluster preferences (e.g. number of
machines, machine type, ssh keypairs, etc). After creating the
configuration file and running StarCluster's start command, a cluster
of Linux machines configured with the Sun Grid Engine queuing system, an
NFS-shared /home directory, and OpenMPI with password-less ssh is
created and ready to go out-of-the-box. Running StarCluster's stop
command will shutdown the cluster and stop paying for service. This
allows the user to only pay for what they use.

StarCluster can also utilize Amazon's Elastic Block Storage (EBS)
volumes to provide persistent data storage for a cluster. EBS volumes
allow you to store large amounts of data in the Amazon cloud and are
also easy to back-up and replicate in the cloud. StarCluster will mount
and NFS-share any volumes specified in the config. StarCluster's
createvolume command provides the ability to automatically create,
format, and partition new EBS volumes for use with StarCluster.

StarCluster provides a Ubuntu-based Amazon Machine Image (AMI) in 32bit
and 64bit architectures. The AMI contains an optimized
NumPy/SciPy/Atlas/Blas/Lapack installation compiled for the larger
Amazon EC2 instance types. The AMI also comes with Sun Grid Engine (SGE)
and OpenMPI compiled with SGE support. The public AMI can easily be
customized by launching a single instance of the public AMI, installing
additional software on the instance, and then using StarCluster's
createimage command to completely automate the process of creating a
new AMI from an EC2 instance.
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

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


asciitable 0.2.4: an extensible ASCII table reader

2010-05-28 Thread Tald
I'm pleased to announce the release of version 0.2.4 of the asciitable
module.  Please see the project home page or PyPI for download and
documentation:

http://cxc.harvard.edu/contrib/asciitable/

At the top level asciitable looks like many other ASCII table readers
since it provides a default read() function with a long list of
parameters to accommodate the many variations possible in commonly
encountered ASCII table formats. But unlike other monolithic table
reader implementations, asciitable is based on a modular and
extensible class structure. Formats that cannot be handled by the
existing hooks in the read() function can be accomodated by modifying
the underlying class methods as needed.

Asciitable can read a wide range of ASCII table formats via built-in
Extension Reader Classes (derived from base class elements):

 * Basic: basic table with customizable delimiters and header
configurations
 * Cds: CDS format table (also Vizier and ApJ machine readable tables)
 * CommentedHeader: column names given in a line that begins with the
comment character
 * Daophot: table from the IRAF DAOphot package
 * Ipac: IPAC format table
 * NoHeader: basic table with no header where columns are auto-named
 * Rdb: tab-separated values with an extra line after the column
definition line
 * Tab: tab-separated values

Copyright: Smithsonian Astrophysical Observatory (2010)
Author: Tom Aldcroft (aldcr...@head.cfa.harvard.edu)
License: BSD (3-clause)
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

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


Tryton 1.6 series is out

2010-05-28 Thread ced
Tryton is a three-tiers high-level general purpose application
platform under the license GPL-3 written in Python and using
PostgreSQL as main database engine.

It is the core base of a complete business solution providing
modularity, scalability and security.

This new release comes with the support of MySQL and various
improvements and polishing of the framework. As always database
migration is ensured from any previous version. This release also
marks the end of support for the 1.0 series.

The most noteworthy new features are:

- The add of MySQL support as DBMS
- Some new modules:
  - Calendar Scheduling
  - Dashboard
  - Project Plan
- The Russian translation
- The security enforcement with fingerprint and CA checks for SSL
- The introduction of PYSON[1] for dynamic domain
- The add of JSON-RPC protocol
- The lazy load of fields in Export/Import windows
- The usage of python-dateutil instead of egenix-mx-base
- A versioned configuration directory for the client
- A bundle of Neso (standalone version of Tryton) for MacOSX
- The digits validation on numeric fields[2]
- The usage of singleton model[3] for various sequences configuration
- Some speed improvements of the report engine

A more complete list of the new features on: 
http://www.tryton.org/news.html#d2010-05-17

:Homepage: http://www.tryton.org/
:Downloads: http://www.tryton.org/downloads.html
:Screenshots: http://www.tryton.org/screenshots.html
:Demo: http://www.tryton.org/demo.html

[1] http://doc.tryton.org/1.6/trytond/doc/topics/pyson.html
[2] http://doc.tryton.org/1.6/trytond/doc/ref/models/fields.html#numeric
[3] 
http://doc.tryton.org/1.6/trytond/doc/ref/models/models.html#trytond.model.ModelSingleton
-- 
http://mail.python.org/mailman/listinfo/python-announce-list

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


Nagare IDE 0.1.0 - Pure Web IDE for the Nagare framework

2010-05-28 Thread Alain Poirier
Hi all,

I'm pleased to announce that the first (0.1.0) version of the
Nagare IDE is released!

Nagare IDE is a pure Web Integrated Development Environment
dedicated to the Nagare Web framework.

Using YUI, the Bespin editor, ajax and comet communications,
it offers the browsing of your projects, the edition of the
sources, the debugging of the raised exceptions and the
consultation in real-time of the applications logs.

The full documentation with screenshots and how to install it
is available at http://www.nagare.org/trac/wiki/NagareIde

Enjoy!

A. Poirier

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

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


Re: First script. Need some help

2010-05-28 Thread ledpepper
Thanks Everyone. I followed your instructions and my script is
successfully copying the result to the clipboard. Now for the fun. To
work out the rest of the script :)

I use the IDLE IDE and not codepad.org. I just thought that was the
standard for pasting scripts here in this group.

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


Hansika Motwani IN DENIM JEANS Hansika Motwani BEAUTIFUL BELLY Hansika Motwani as college GIRL Hansika Motwani in GYM in RED BRA Hansika Motwani in GREEN SAREE BELLY BOLLYWOOD GIRLS on h

2010-05-28 Thread Naeem
Hansika Motwani IN DENIM JEANS Hansika Motwani BEAUTIFUL BELLY
Hansika Motwani as college GIRL Hansika Motwani in GYM in RED BRA
Hansika Motwani in GREEN SAREE BELLY BOLLYWOOD GIRLS on
http://hollywood-bollywood-pics.blogspot.com Hansika Motwani IN
DENIM JEANS Hansika Motwani BEAUTIFUL BELLY  Hansika Motwani as
college GIRL Hansika Motwani in GYM in RED BRA Hansika Motwani in
GREEN SAREE BELLY BOLLYWOOD GIRLS on 
http://hollywood-bollywood-pics.blogspot.com
Hansika Motwani IN DENIM JEANS Hansika Motwani BEAUTIFUL BELLY
Hansika Motwani as college GIRL Hansika Motwani in GYM in RED BRA
Hansika Motwani in GREEN SAREE BELLY BOLLYWOOD GIRLS on
http://hollywood-bollywood-pics.blogspot.com Hansika Motwani IN
DENIM JEANS Hansika Motwani BEAUTIFUL BELLY  Hansika Motwani as
college GIRL Hansika Motwani in GYM in RED BRA Hansika Motwani in
GREEN SAREE BELLY BOLLYWOOD GIRLS on 
http://hollywood-bollywood-pics.blogspot.com
Hansika Motwani IN DENIM JEANS Hansika Motwani BEAUTIFUL BELLY
Hansika Motwani as college GIRL Hansika Motwani in GYM in RED BRA
Hansika Motwani in GREEN SAREE BELLY BOLLYWOOD GIRLS on
http://hollywood-bollywood-pics.blogspot.com Hansika Motwani IN
DENIM JEANS Hansika Motwani BEAUTIFUL BELLY  Hansika Motwani as
college GIRL Hansika Motwani in GYM in RED BRA Hansika Motwani in
GREEN SAREE BELLY BOLLYWOOD GIRLS on 
http://hollywood-bollywood-pics.blogspot.com
Hansika Motwani IN DENIM JEANS Hansika Motwani BEAUTIFUL BELLY
Hansika Motwani as college GIRL Hansika Motwani in GYM in RED BRA
Hansika Motwani in GREEN SAREE BELLY BOLLYWOOD GIRLS on
http://hollywood-bollywood-pics.blogspot.com Hansika Motwani IN
DENIM JEANS Hansika Motwani BEAUTIFUL BELLY  Hansika Motwani as
college GIRL Hansika Motwani in GYM in RED BRA Hansika Motwani in
GREEN SAREE BELLY BOLLYWOOD GIRLS on 
http://hollywood-bollywood-pics.blogspot.com
Hansika Motwani IN DENIM JEANS Hansika Motwani BEAUTIFUL BELLY
Hansika Motwani as college GIRL Hansika Motwani in GYM in RED BRA
Hansika Motwani in GREEN SAREE BELLY BOLLYWOOD GIRLS on
http://hollywood-bollywood-pics.blogspot.com Hansika Motwani IN
DENIM JEANS Hansika Motwani BEAUTIFUL BELLY  Hansika Motwani as
college GIRL Hansika Motwani in GYM in RED BRA Hansika Motwani in
GREEN SAREE BELLY BOLLYWOOD GIRLS on 
http://hollywood-bollywood-pics.blogspot.com
Hansika Motwani IN DENIM JEANS Hansika Motwani BEAUTIFUL BELLY
Hansika Motwani as college GIRL Hansika Motwani in GYM in RED BRA
Hansika Motwani in GREEN SAREE BELLY BOLLYWOOD GIRLS on
http://hollywood-bollywood-pics.blogspot.com Hansika Motwani IN
DENIM JEANS Hansika Motwani BEAUTIFUL BELLY  Hansika Motwani as
college GIRL Hansika Motwani in GYM in RED BRA Hansika Motwani in
GREEN SAREE BELLY BOLLYWOOD GIRLS on 
http://hollywood-bollywood-pics.blogspot.com
Hansika Motwani IN DENIM JEANS Hansika Motwani BEAUTIFUL BELLY
Hansika Motwani as college GIRL Hansika Motwani in GYM in RED BRA
Hansika Motwani in GREEN SAREE BELLY BOLLYWOOD GIRLS on
http://hollywood-bollywood-pics.blogspot.com Hansika Motwani IN
DENIM JEANS Hansika Motwani BEAUTIFUL BELLY  Hansika Motwani as
college GIRL Hansika Motwani in GYM in RED BRA Hansika Motwani in
GREEN SAREE BELLY BOLLYWOOD GIRLS on 
http://hollywood-bollywood-pics.blogspot.com
Hansika Motwani IN DENIM JEANS Hansika Motwani BEAUTIFUL BELLY
Hansika Motwani as college GIRL Hansika Motwani in GYM in RED BRA
Hansika Motwani in GREEN SAREE BELLY BOLLYWOOD GIRLS on
http://hollywood-bollywood-pics.blogspot.com Hansika Motwani IN
DENIM JEANS Hansika Motwani BEAUTIFUL BELLY  Hansika Motwani as
college GIRL Hansika Motwani in GYM in RED BRA Hansika Motwani in
GREEN SAREE BELLY BOLLYWOOD GIRLS on 
http://hollywood-bollywood-pics.blogspot.com
Hansika Motwani IN DENIM JEANS Hansika Motwani BEAUTIFUL BELLY
Hansika Motwani as college GIRL Hansika Motwani in GYM in RED BRA
Hansika Motwani in GREEN SAREE BELLY BOLLYWOOD GIRLS on
http://hollywood-bollywood-pics.blogspot.com Hansika Motwani IN
DENIM JEANS Hansika Motwani BEAUTIFUL BELLY  Hansika Motwani as
college GIRL Hansika Motwani in GYM in RED BRA Hansika Motwani in
GREEN SAREE BELLY BOLLYWOOD GIRLS on 
http://hollywood-bollywood-pics.blogspot.com
Hansika Motwani IN DENIM JEANS Hansika Motwani BEAUTIFUL BELLY
Hansika Motwani as college GIRL Hansika Motwani in GYM in RED BRA
Hansika Motwani in GREEN SAREE BELLY BOLLYWOOD GIRLS on
http://hollywood-bollywood-pics.blogspot.com Hansika Motwani IN
DENIM JEANS Hansika Motwani BEAUTIFUL BELLY  Hansika Motwani as
college GIRL Hansika Motwani in GYM in RED BRA Hansika Motwani in
GREEN SAREE BELLY BOLLYWOOD GIRLS on 
http://hollywood-bollywood-pics.blogspot.com
Hansika Motwani IN DENIM JEANS Hansika Motwani BEAUTIFUL BELLY
Hansika Motwani as college GIRL Hansika Motwani in GYM in RED BRA
Hansika Motwani in GREEN SAREE BELLY BOLLYWOOD GIRLS on
http://hollywood-bollywood-pics.blogspot.com Hansika Motwani IN
DENIM JEANS Hansika Motwani BEAUTIFUL BELLY  Hansika Motwani as
college GIRL Hansika 

Re: Minor annoyances with properties

2010-05-28 Thread eb303
On May 27, 3:24 pm, Christian Heimes li...@cheimes.de wrote:
   Do I miss something?
  Is this the way to do it, or is there a better one?

 A better way was introduced in Python 2.6. 
 Seehttp://docs.python.org/library/functions.html?highlight=property#prop...
 I have a Python only version around if you are still using Python 2.5.

 Christian

Mmmm, I might still miss something. OK, I can replace my initial
property using @property and @p.setter, but it doesn't seem to work in
subclasses:

class A(object):
  @property
  def p(self):
return self._p
  @p.setter
  def _set_p(self, p):
self._p = p
class B(A):
  @p.setter
  def _set_p(self, p):
…

results in:

Traceback (most recent call last):
  File toto.py, line 8, in module
class B(A):
  File toto.py, line 9, in B
@p.setter
NameError: name 'p' is not defined
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Minor annoyances with properties

2010-05-28 Thread eb303
On May 27, 8:56 pm, Francesco Bochicchio bieff...@gmail.com wrote:
 On 27 Mag, 14:37, eb303 eric.brunel.pragma...@gmail.com wrote:



  Hello all,

  I've been using Python properties quite a lot lately and I've found a
  few things that are a bit annoying about them in some cases. I
  wondered if I missed something or if anybody else has this kind of
  problems too, and if there are better solutions than the ones I'm
  using ATM.

  The first annoyance is when I want to specialize a property in a
  subclass. This happens quite often actually, and it is even sometimes
  the reason why a plain attribute is turned into a property: a subclass
  needs to do more things than the superclass when the property is
  updated for example. So, of course, my first try was:

  class A(object):
    def __init__(self):
      self._p = None
    def _get_p(self):
      return self._p
    def _set_p(self, p):
      self._p = p
    p = property(_get_p, _set_p)
  class B(A):
    def _set_p(self, p):
      ## Additional things here…
      super(B, self)._set_p(p)

  And of course, it doesn't work: the property has been bound to
  A._set_p in A, so any new definition of _set_p in any subclass does
  not replace the set method for the property. So I always have to add a
  line:
  p = property(A._get_p, _set_p)
  in the subclass too. This is a bit awkward to me, since I have to
  specify the superclass's name (super(…) can't be used, since it should
  take B as an argument, and B isn't defined yet…). Do I miss something?
  Is this the way to do it, or is there a better one?

 Don't know if is better, but you could add a level of indirection to
 solve it

  class A(object):
    def __init__(self):
      self._p = None
    def _get_p(self):
      return self._p
    def _set_p(self, p):
      self._p = p
    def _virtual_get_p (self): _get_p(self)
    def _virtual_set_p (self,v): _set_p(self, v)
    p = property(_virtual_get_p, _virtual_set_p)

 At this point, the subclasses of A can reimplement _get_p and _set_p
 as they like (I think)

 Ciao
 -
 FB

Well, I've thought about that too and it should work, but that makes 2
function calls instead of one for every property access… I'd really
like to avoid that.

By the way, I think your 'virtual' methods should be written as:
def _virtual_get_p (self): return self._get_p()
def _virtual_set_p (self,v): self._set_p(v)

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


Re: Minor annoyances with properties

2010-05-28 Thread eb303
On May 27, 3:14 pm, Neil Cerutti ne...@norwich.edu wrote:
 On 2010-05-27, eb303 eric.brunel.pragma...@gmail.com wrote:

  I've been using Python properties quite a lot lately and I've
  found a few things that are a bit annoying about them in some
  cases. I wondered if I missed something or if anybody else has
  this kind of problems too, and if there are better solutions
  than the ones I'm using ATM.
  The first annoyance is when I want to specialize a property in a
  subclass.

 See:

 URI:http://infinitesque.net/articles/2005/enhancing%20Python%27s%20proper...

 --
 Neil Cerutti
 *** You found a dead moose-rat. You sell the hide for $200. ***

Thanks for the suggestion, but it looks a bit heavy… Performing the
name lookup on the specialized object each time the property is
accessed seems a bit overkill. I'd really just like a simple way to
tell in the subclass: now, the setter methof for property p is this
one, only that…

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


Re: Minor annoyances with properties

2010-05-28 Thread Christian Heimes
Am 28.05.2010 11:31, schrieb eb303:
 On May 27, 3:24 pm, Christian Heimes li...@cheimes.de wrote:
  Do I miss something?
 Is this the way to do it, or is there a better one?

 A better way was introduced in Python 2.6. 
 Seehttp://docs.python.org/library/functions.html?highlight=property#prop...
 I have a Python only version around if you are still using Python 2.5.

 Christian
 
 Mmmm, I might still miss something. OK, I can replace my initial
 property using @property and @p.setter, but it doesn't seem to work in
 subclasses:
 
 class A(object):
   @property
   def p(self):
 return self._p
   @p.setter
   def _set_p(self, p):
 self._p = p
 class B(A):
   @p.setter
   def _set_p(self, p):
 …
 
 results in:
 
 Traceback (most recent call last):
   File toto.py, line 8, in module
 class B(A):
   File toto.py, line 9, in B
 @p.setter
 NameError: name 'p' is not defined

It doesn't work because p is not in the scope of B's body while B is
created. You have to write

class B(A):
# access the p property from class A
@A.p.setter
def p(self, p):
pass

# once p is in the class body scope, you must not use A.p again
@p.deleter
def p(self):
pass

Christian

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


Re: if, continuation and indentation

2010-05-28 Thread Jonathan Hartley
On May 27, 1:57 pm, Jean-Michel Pichavant jeanmic...@sequans.com
wrote:
 HH wrote:
  I have a question about best practices when it comes to line wrapping/
  continuation and indentation, specifically in the case of an if
  statement.

  When I write an if statement with many conditions, I prefer to use a
  parenthesis around the whole block and get the implicit continuation,
  rather than ending each line with an escape character.  Thus, using
  the example from the style guide (http://www.python.org/dev/peps/
  pep-0008/) I would write:

      if (width == 0 and
          height == 0 and
          color == 'red' and
          emphasis == 'strong' or
          highlight  100):
          raise ValueError(sorry, you lose)

  The problem should be obvious -- it's not easy to see where the
  conditional ends and the statement begins since they have the same
  indentation.  Part of the problem, I suppose, is that Emacs indents
  'height' and the other lines in the conditional to 4 spaces (because
  of the parenthesis).  How do people deal with this situation?

  Thanks,
  Henrik

 One possible solution

     if (
             width == 0 and
             height == 0 and
             color == 'red' and
             emphasis == 'strong' or
             highlight  100
        ):
         raise ValueError(sorry, you lose)

 JM  

I've always liked this, or even:

  if (
  width == 0 and
  height == 0 and
  color == 'red' and
  emphasis == 'strong' or
  highlight  100
  ):
  raise ValueError(sorry, you lose)


but my co-workers have uniformly gone bananas whenever I try it.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: if, continuation and indentation

2010-05-28 Thread Jean-Michel Pichavant

Jonathan Hartley wrote:

On May 27, 1:57 pm, Jean-Michel Pichavant jeanmic...@sequans.com
wrote:
  

HH wrote:


I have a question about best practices when it comes to line wrapping/
continuation and indentation, specifically in the case of an if
statement.
  
When I write an if statement with many conditions, I prefer to use a

parenthesis around the whole block and get the implicit continuation,
rather than ending each line with an escape character.  Thus, using
the example from the style guide (http://www.python.org/dev/peps/
pep-0008/) I would write:
  
if (width == 0 and

height == 0 and
color == 'red' and
emphasis == 'strong' or
highlight  100):
raise ValueError(sorry, you lose)
  
The problem should be obvious -- it's not easy to see where the

conditional ends and the statement begins since they have the same
indentation.  Part of the problem, I suppose, is that Emacs indents
'height' and the other lines in the conditional to 4 spaces (because
of the parenthesis).  How do people deal with this situation?
  
Thanks,

Henrik
  

One possible solution

if (
width == 0 and
height == 0 and
color == 'red' and
emphasis == 'strong' or
highlight  100
   ):
raise ValueError(sorry, you lose)

JM  



I've always liked this, or even:

  if (
  width == 0 and
  height == 0 and
  color == 'red' and
  emphasis == 'strong' or
  highlight  100
  ):
  raise ValueError(sorry, you lose)


but my co-workers have uniformly gone bananas whenever I try it.
  
I tried to give a layout that fits the OP way of doing, but I would not 
use what I described above, so I can understand why your co workers go 
bananas :)


when it comes to extended conditions in if statement I prefer to write 
something like


if self.haveLost():
   raise ValueError(sorry, you lose)

It drastically improves the reading because it splits the notion of what 
to do in which case, and how do you identify the cases (i.e. what should 
I do when I've lost, and how do I know that I've lost). If you don't 
want to pollute your upper namespace you can embed the function that way:


def foo():
   width = 0
   height = 0
   color = 'red'
   emphasis = 'strong'

   def haveLost():
   return not width and not height and color == 'red' and emphasis 
=='strong'


   if haveLost():
   raise ValueError(sorry you lose)

It has the cool side effect to name your condition as well, that helps 
debugging the condition *a lot*.


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


Re: if, continuation and indentation

2010-05-28 Thread Jonathan Hartley

On 28/05/2010 11:34, Jean-Michel Pichavant wrote:

Jonathan Hartley wrote:

On May 27, 1:57 pm, Jean-Michel Pichavant jeanmic...@sequans.com
wrote:

HH wrote:

I have a question about best practices when it comes to line wrapping/
continuation and indentation, specifically in the case of an if
statement.
  When I write an if statement with many conditions, I prefer 
to use a

parenthesis around the whole block and get the implicit continuation,
rather than ending each line with an escape character.  Thus, using
the example from the style guide (http://www.python.org/dev/peps/
pep-0008/) I would write:
  if (width == 0 and
height == 0 and
color == 'red' and
emphasis == 'strong' or
highlight  100):
raise ValueError(sorry, you lose)
  The problem should be obvious -- it's not easy to see where the
conditional ends and the statement begins since they have the same
indentation.  Part of the problem, I suppose, is that Emacs indents
'height' and the other lines in the conditional to 4 spaces (because
of the parenthesis).  How do people deal with this situation?
  Thanks,
Henrik

One possible solution

if (
width == 0 and
height == 0 and
color == 'red' and
emphasis == 'strong' or
highlight  100
   ):
raise ValueError(sorry, you lose)

JM 


I've always liked this, or even:

  if (
  width == 0 and
  height == 0 and
  color == 'red' and
  emphasis == 'strong' or
  highlight  100
  ):
  raise ValueError(sorry, you lose)


but my co-workers have uniformly gone bananas whenever I try it.
I tried to give a layout that fits the OP way of doing, but I would 
not use what I described above, so I can understand why your co 
workers go bananas :)


when it comes to extended conditions in if statement I prefer to write 
something like


if self.haveLost():
   raise ValueError(sorry, you lose)

It drastically improves the reading


Good point.

+1 for naming the condition, hooray for self-documenting code.

Sometime last year at my workplace, we started referring to comments as 
'lies', we now always try to use techniques like this instead of comments.


--
Jonathan Hartley  Made of meat.  http://tartley.com
tart...@tartley.com   +44 7737 062 225   twitter/skype: tartley

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


Sockets and xml problem

2010-05-28 Thread kak...@gmail.com
Hi in the following code

class MyClientHandler(SocketServer.BaseRequestHandler):
def handle(self):
print self.client_address, now( )
time.sleep(5)
while True:
xmltxt = self.request.recv(1024)--is this ok -
enough?
if not xmltxt: break

doc = minidom.parseString(data)
 --- it also fails for parse(data)
rootNode = doc.documentElement

level = 0

walk(rootNode, outFile, level)
  ---just a function to print the xml
self.request.send('Echo=%s at %s' % (data, now( )))
rootNode = doc.documentElement
level = 0
walk(rootNode, outFile, level)
self.request.send('Echo=%s at %s' % (data, now( )))
self.request.close( )

# make a threaded server, listen/handle clients forever
myaddr = (myHost, myPort)
server = SocketServer.ThreadingTCPServer(myaddr, MyClientHandler)
server.serve_forever( )


I want to send XML messages from my client. The server sends back the
XML it receives but
the parser exits with error codes.
What am i doing wrong.

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


Re: Yet Another MySQL Problem

2010-05-28 Thread Victor Subervi
On Thu, May 27, 2010 at 5:47 PM, Tim Chase python.l...@tim.thechases.comwrote:

 On 05/27/2010 03:32 PM, Victor Subervi wrote:

  On Thu, May 27, 2010 at 1:15 PM, Tim Chase wrote:

 That should be:

 ', '.join(['%s'] * len(values)))


 Or as I've done in the past:

  ', '.join('%s' for _ in values)


 Huh? Can you describe that underscore to me? Fascinating!


 The underscore is a valid variable-name, idiomatically used for I don't
 care about this, often seen in places like tuple assignment:

  a,_,_,d = some_4_element_tuple

 So in my above case, it could also have been written as

  ', '.join('%s' for value in values)
  ', '.join('%s' for dont_care_about_the_value in values)

 but the _ idiom means I'm iterating over 'values' but I'm not actually
 using the values I get from it


I should have known. Thanks!
beno
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Some More MySQL

2010-05-28 Thread Victor Subervi
On Fri, May 28, 2010 at 2:17 AM, Dennis Lee Bieber wlfr...@ix.netcom.comwrote:

 On Thu, 27 May 2010 23:22:24 +0100, MRAB pyt...@mrabarnett.plus.com
 declaimed the following in gmane.comp.python.general:

 
  Placeholders which are handled by .execute shouldn't be wrapped in
  quotes, even is the value is a string, because .execute will handle that
  (and any other details) itself.

 Even more internal details -- the MySQLdb placeholder is %s because
 the adapter, internally, converts ALL parameters to strings, applies
 escapes to them, and THEN wraps them with quotes before using Python
 string interpolation to make the query that gets submitted to the
 server.

This is why you can not use, say %d as a placeholder for a numeric
 parameter... MySQLdb will convert that numeric to a string, and then
 Python will choke when it tries to use a %d formatter and is given a
 string value.


 All of your and MRAB's comments were very helpful. However, I don't see how
these two problems are addressed:

  sql = 'select * from options%s where ID=%%s', (opTable[0].upper() +
opTable[1:])
#  cursor.execute(sql, id)
  cursor.execute('select * from options%s where ID=%s' %
(opTable[0].upper() + opTable[1:], id))

The last one works, but if I comment it out and uncomment the middle line,
it doesn't. Same here:

sql = update options%s set PriceDiff='%%s' where Field='%%s' and
ID=%%s and Store='%%s' % (opTable[0].upper() + opTable[1:])
#cursor.execute(sql, (value, opName, id, store))
cursor.execute('update options%s set PriceDiff=%s where Field=%s
and ID=%s and Store=%s' % (opTable[0].upper() + opTable[1:], value,
opName, id, store))

TIA,
beno
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: multiprocessing and accessing server's stdout

2010-05-28 Thread Adam Tauno Williams
On Thu, 2010-05-27 at 08:36 -0700, Tim Arnold wrote:
 On May 26, 4:52 pm, Adam Tauno Williams awill...@whitemice.org
 wrote:
  On Wed, 2010-05-26 at 11:47 -0700, Tim Arnold wrote:
   Hi,
   I'm using multiprocessing's BaseManager to create a server on one
   machine and a client on another. The client fires a request and the
   server does some work, the result of which ends up on a shared file
   system that both the client and server can see.
   However, I need the client machine to see the stdout of the process
   running on the server. Not sure this is doable--I've been unable to
   google anything useful on this one.
 
  Nope, it isn't.  Don't use stdout, use an IPC mechanism to communicate
  between the client and the server if you need feedback.
 Thanks for that info, it saves me some time. This is a new area for me
 though: do you redirect stdout on the server to a socket and have the
 client listen and somehow pipe the sockets contents to the client
 stdout?

No, I close stdin, stderr, and stdout on the server processes and attach
them to /dev/null.  Just don't use stdout.

 Interestingly, the RPYc package manages it--that is, the client gets
 the stdout of the server process, so I'll dig into that code to get an
 idea. In the meantime, are there any recipes or other docs that would
 be helpful? I've been googling but without much luck.

Closing stdout and attaching it to any other file descriptor is pretty
simple.

sys.stdout = open('/dev/null', 'w')

You should be able to point it any any file-like object.  But, again,
why?

If you have the data in the process why send it to stdout and redirect
it.  Why not just send the data to the client directly?
-- 
Adam Tauno Williams awill...@whitemice.org LPIC-1, Novell CLA
http://www.whitemiceconsulting.com
OpenGroupware, Cyrus IMAPd, Postfix, OpenLDAP, Samba

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


Re: Sockets and xml problem

2010-05-28 Thread Stefan Behnel

kak...@gmail.com, 28.05.2010 13:50:

Hi in the following code

class MyClientHandler(SocketServer.BaseRequestHandler):
 def handle(self):
 print self.client_address, now( )
 time.sleep(5)
 while True:
 xmltxt = self.request.recv(1024)--is this ok -
enough?


Depends. If your messages are never larger than 1K, this is enough. 
Otherwise, you have to collect the data, instead of parsing each chunk 
separately.


I suggest using the incremental parser in xml.etree.ElementTree, which 
allows you to push more data into the parser as it comes in. When done, 
call it's .close() method to retrieve the result.


http://docs.python.org/library/xml.etree.elementtree.html#xmltreebuilder-objects



I want to send XML messages from my client. The server sends back the
XML it receives but the parser exits with error codes.


You should also rethink your approach one more time. Are you sure that a 
raw socket is a good protocol for sending your messages? In many cases, a 
proper higher-level transport protocol like HTTP is much better suited. If 
you provide more details about what you are trying to do, others may be 
able to help you further.


Stefan

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


Re: Sockets and xml problem

2010-05-28 Thread kak...@gmail.com
On May 28, 3:23 pm, Stefan Behnel stefan...@behnel.de wrote:
 kak...@gmail.com, 28.05.2010 13:50:

  Hi in the following code

  class MyClientHandler(SocketServer.BaseRequestHandler):
       def handle(self):
           print self.client_address, now( )
           time.sleep(5)
           while True:
               xmltxt = self.request.recv(1024)--is this ok -
  enough?

 Depends. If your messages are never larger than 1K, this is enough.
 Otherwise, you have to collect the data, instead of parsing each chunk
 separately.

 I suggest using the incremental parser in xml.etree.ElementTree, which
 allows you to push more data into the parser as it comes in. When done,
 call it's .close() method to retrieve the result.

 http://docs.python.org/library/xml.etree.elementtree.html#xmltreebuil...

  I want to send XML messages from my client. The server sends back the
  XML it receives but the parser exits with error codes.

 You should also rethink your approach one more time. Are you sure that a
 raw socket is a good protocol for sending your messages? In many cases, a
 proper higher-level transport protocol like HTTP is much better suited. If
 you provide more details about what you are trying to do, others may be
 able to help you further.

 Stefan

Stefan first of all thank you for your response.
I don't want anything fancy. Just a simple server that accepts xml
messages from multple clients in xml,
parses the XML and show it in a console.
Antonis
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Some More MySQL

2010-05-28 Thread Kushal Kumaran
On Fri, May 28, 2010 at 5:46 PM, Victor Subervi victorsube...@gmail.com wrote:
 On Fri, May 28, 2010 at 2:17 AM, Dennis Lee Bieber wlfr...@ix.netcom.com
 wrote:

 On Thu, 27 May 2010 23:22:24 +0100, MRAB pyt...@mrabarnett.plus.com
 declaimed the following in gmane.comp.python.general:

 
  Placeholders which are handled by .execute shouldn't be wrapped in
  quotes, even is the value is a string, because .execute will handle that
  (and any other details) itself.

        Even more internal details -- the MySQLdb placeholder is %s because
 the adapter, internally, converts ALL parameters to strings, applies
 escapes to them, and THEN wraps them with quotes before using Python
 string interpolation to make the query that gets submitted to the
 server.

        This is why you can not use, say %d as a placeholder for a numeric
 parameter... MySQLdb will convert that numeric to a string, and then
 Python will choke when it tries to use a %d formatter and is given a
 string value.


 All of your and MRAB's comments were very helpful. However, I don't see how
 these two problems are addressed:

   sql = 'select * from options%s where ID=%%s', (opTable[0].upper() +
 opTable[1:])
 #  cursor.execute(sql, id)
   cursor.execute('select * from options%s where ID=%s' %
 (opTable[0].upper() + opTable[1:], id))


The second argument to cursor.execute needs to be a tuple.  Change the
call to this:

cursor.execute(sql, (id,))

 The last one works, but if I comment it out and uncomment the middle line,
 it doesn't. Same here:

     sql = update options%s set PriceDiff='%%s' where Field='%%s' and
 ID=%%s and Store='%%s' % (opTable[0].upper() + opTable[1:])
 #    cursor.execute(sql, (value, opName, id, store))
     cursor.execute('update options%s set PriceDiff=%s where Field=%s
 and ID=%s and Store=%s' % (opTable[0].upper() + opTable[1:], value,
 opName, id, store))


Lose the quotes around the %s.  You are replying to a post that
describes why this is important.

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


Re: Free chapter about Python and databases (MySQL and SQLite)

2010-05-28 Thread Tino Wildenhain

Hi,

Am 28.05.2010 04:45, schrieb Sebastian Bassi:

Hello, I want to announce that the publisher of Python for
Bioinformatis (CRC Press) allowed me to publish a chapter from my
book.
I decided to publish the chapter about Python and databases. I think
it may be useful for somebody.
The official announcement and download link is here:
http://py4bio.com/2010/05/28/python_databases_mysql_sqlite/
For more information about the book: www.tinyurl.com/biopython
Best,
SB.


This is nice! Congrats!
Did you consider adding a part dealing with postgresql too?
(Especially interesting in the way you can write stored functions
in python there)

Regards
Tino



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


Re: multiprocessing and accessing server's stdout

2010-05-28 Thread Martin P. Hellwig

On 05/28/10 13:17, Adam Tauno Williams wrote:
cut


You should be able to point it any any file-like object.  But, again,
why?

If you have the data in the process why send it to stdout and redirect
it.  Why not just send the data to the client directly?


Well you might want to multiplex it to more then one client, not saying 
that this is the case here, just something I imagine possible.


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


Re: Minor annoyances with properties

2010-05-28 Thread eb303
On May 28, 11:50 am, Christian Heimes li...@cheimes.de wrote:
 Am 28.05.2010 11:31, schrieb eb303:



  On May 27, 3:24 pm, Christian Heimes li...@cheimes.de wrote:
   Do I miss something?
  Is this the way to do it, or is there a better one?

  A better way was introduced in Python 2.6. 
  Seehttp://docs.python.org/library/functions.html?highlight=property#prop...
  I have a Python only version around if you are still using Python 2.5.

  Christian

  Mmmm, I might still miss something. OK, I can replace my initial
  property using @property and @p.setter, but it doesn't seem to work in
  subclasses:

  class A(object):
    @property
    def p(self):
      return self._p
    @p.setter
    def _set_p(self, p):
      self._p = p
  class B(A):
    @p.setter
    def _set_p(self, p):
      …

  results in:

  Traceback (most recent call last):
    File toto.py, line 8, in module
      class B(A):
    File toto.py, line 9, in B
      @p.setter
  NameError: name 'p' is not defined

 It doesn't work because p is not in the scope of B's body while B is
 created. You have to write

 class B(A):
     # access the p property from class A
     @A.p.setter
     def p(self, p):
         pass

     # once p is in the class body scope, you must not use A.p again
     @p.deleter
     def p(self):
         pass

 Christian

Well, I still have to explicitely specify the superclass's name then,
so IMHO it's not a big improvement over repeating:
p = property(A._get_p, _set_p)

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


Re: Free chapter about Python and databases (MySQL and SQLite)

2010-05-28 Thread Sebastian Bassi
On Fri, May 28, 2010 at 9:41 AM, Tino Wildenhain t...@wildenhain.de wrote:
 Did you consider adding a part dealing with postgresql too?
 (Especially interesting in the way you can write stored functions
 in python there)

That is a good idea for the next version/edition. But meanwhile I
could write something in my blog at www.py4bio.com
Best,
SB
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: http post

2010-05-28 Thread christian schulze
On 28 Mai, 16:47, yqyq22 yqy...@hotmail.com wrote:
 Hy, i would like to create a little script to reproduce this one
 below:
 Do you have suggestion?

 POST /folder/path/upload.exe?/dir HTTP/1.1
 Host: 192.168.100.1:8080
 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:
 1.9.2.3) Gecko/20100401 Firefox/3.6.3 (.NET CLR 3.5.30729)
 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/
 *;q=0.8
 Accept-Language: en-us,en;q=0.5
 Accept-Encoding: gzip,deflate
 Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
 Keep-Alive: 115
 Proxy-Connection: keep-alive
 Referer:http://192.168.1.100:8080/dir1
 Content-Type: multipart/form-data;
 boundary=---7075104567331
 Content-Length: 539
 Connection: close

 -7075104567331
 Content-Disposition: form-data; name=F1; filename=file.txt
 Content-Type: application/octet-stream

 -7075104567331
 Content-Disposition: form-data; name=p4

 -7075104567331--

 THANKS A LOT

Just send it via a socket? Or use urllib, afair you can send custom
HTTP headers.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: http post

2010-05-28 Thread yqyq22
On May 28, 5:17 pm, christian schulze xcr...@googlemail.com wrote:
 On 28 Mai, 16:47, yqyq22 yqy...@hotmail.com wrote:





  Hy, i would like to create a little script to reproduce this one
  below:
  Do you have suggestion?

  POST /folder/path/upload.exe?/dir HTTP/1.1
  Host: 192.168.100.1:8080
  User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:
  1.9.2.3) Gecko/20100401 Firefox/3.6.3 (.NET CLR 3.5.30729)
  Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/
  *;q=0.8
  Accept-Language: en-us,en;q=0.5
  Accept-Encoding: gzip,deflate
  Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
  Keep-Alive: 115
  Proxy-Connection: keep-alive
  Referer:http://192.168.1.100:8080/dir1
  Content-Type: multipart/form-data;
  boundary=---7075104567331
  Content-Length: 539
  Connection: close

  -7075104567331
  Content-Disposition: form-data; name=F1; filename=file.txt
  Content-Type: application/octet-stream

  -7075104567331
  Content-Disposition: form-data; name=p4

  -7075104567331--

  THANKS A LOT

 Just send it via a socket? Or use urllib, afair you can send custom
 HTTP headers.- Hide quoted text -

 - Show quoted text -

If i understood right i would use only socket.. is it possible?
thanks
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Free chapter about Python and databases (MySQL and SQLite)

2010-05-28 Thread christian schulze
On 28 Mai, 17:12, Sebastian Bassi sba...@clubdelarazon.org wrote:
 On Fri, May 28, 2010 at 9:41 AM, Tino Wildenhain t...@wildenhain.de wrote:
  Did you consider adding a part dealing with postgresql too?
  (Especially interesting in the way you can write stored functions
  in python there)

 That is a good idea for the next version/edition. But meanwhile I
 could write something in my blog atwww.py4bio.com
 Best,
 SB

Indeed a style like
 user=root
is not that nice.

I had no look at the chapter but recommend you to read the PEP 8 -
Python style guides (code conventions for python).

Imo a book have to be kinda exemplary. And bad style sucks anyway ...

PS:
 user = 'root' or user = root
... would be much more beautyful.
-- 
http://mail.python.org/mailman/listinfo/python-list


Omit the headers from XML message

2010-05-28 Thread kak...@gmail.com
Hi i have the following xml message i want to omit the headers, any
hints?

POST /test/pcp/Listener HTTP/1.1
User-Agent: Jakarta Commons-HttpClient/3.1
Host: 127.0.0.1:50002
Content-Length: 547

pt_control_message xmlns=http://demo.com/demo;
  cmdReply
sessionList
  session
idscvdcvsdv/id
subscriberIdsdfv/subscriberId
subscriberNameAntonis Kaklis/subscriberName
presenceaway/presence
notetesting the new client/note
ipAddressjlkdjf/ipAddress
deviceClassandroid/deviceClass
  /session
/sessionList
  /cmdReply
/pt_control_message
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: http post

2010-05-28 Thread christian schulze
On 28 Mai, 17:20, yqyq22 yqy...@hotmail.com wrote:
 On May 28, 5:17 pm, christian schulze xcr...@googlemail.com wrote:



  On 28 Mai, 16:47, yqyq22 yqy...@hotmail.com wrote:

   Hy, i would like to create a little script to reproduce this one
   below:
   Do you have suggestion?

   POST /folder/path/upload.exe?/dir HTTP/1.1
   Host: 192.168.100.1:8080
   User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:
   1.9.2.3) Gecko/20100401 Firefox/3.6.3 (.NET CLR 3.5.30729)
   Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/
   *;q=0.8
   Accept-Language: en-us,en;q=0.5
   Accept-Encoding: gzip,deflate
   Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
   Keep-Alive: 115
   Proxy-Connection: keep-alive
   Referer:http://192.168.1.100:8080/dir1
   Content-Type: multipart/form-data;
   boundary=---7075104567331
   Content-Length: 539
   Connection: close

   -7075104567331
   Content-Disposition: form-data; name=F1; filename=file.txt
   Content-Type: application/octet-stream

   -7075104567331
   Content-Disposition: form-data; name=p4

   -7075104567331--

   THANKS A LOT

  Just send it via a socket? Or use urllib, afair you can send custom
  HTTP headers.- Hide quoted text -

  - Show quoted text -

 If i understood right i would use only socket.. is it possible?
 thanks

Yeah i think so, but i am not quite sure. Just test it :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: http post

2010-05-28 Thread yqyq22
On May 28, 5:24 pm, christian schulze xcr...@googlemail.com wrote:
 On 28 Mai, 17:20, yqyq22 yqy...@hotmail.com wrote:





  On May 28, 5:17 pm, christian schulze xcr...@googlemail.com wrote:

   On 28 Mai, 16:47, yqyq22 yqy...@hotmail.com wrote:

Hy, i would like to create a little script to reproduce this one
below:
Do you have suggestion?

POST /folder/path/upload.exe?/dir HTTP/1.1
Host: 192.168.100.1:8080
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:
1.9.2.3) Gecko/20100401 Firefox/3.6.3 (.NET CLR 3.5.30729)
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/
*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 115
Proxy-Connection: keep-alive
Referer:http://192.168.1.100:8080/dir1
Content-Type: multipart/form-data;
boundary=---7075104567331
Content-Length: 539
Connection: close

-7075104567331
Content-Disposition: form-data; name=F1; filename=file.txt
Content-Type: application/octet-stream

-7075104567331
Content-Disposition: form-data; name=p4

-7075104567331--

THANKS A LOT

   Just send it via a socket? Or use urllib, afair you can send custom
   HTTP headers.- Hide quoted text -

   - Show quoted text -

  If i understood right i would use only socket.. is it possible?
  thanks

 Yeah i think so, but i am not quite sure. Just test it :)- Hide quoted text -

 - Show quoted text -

Do u have an example/link closed to my need? thanks
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Some More MySQL

2010-05-28 Thread Victor Subervi
I still have this code:

  sql = 'select * from options%s where ID=%%s', (opTable[0].upper() +
opTable[1:])
  cursor.execute(sql, (id,))

which throws this error:

 /var/www/html/angrynates.com/cart/enterOptionsPrices2.py
   70 print 'All options prices have been successfully updated.'
   71 print '/body\n/html'
   72
   73 enterOptionsPrices2()
   74
enterOptionsPrices2 = function enterOptionsPrices2
 /var/www/html/angrynates.com/cart/enterOptionsPrices2.py in
enterOptionsPrices2()
   58   id = form.getfirst('%sID' % option)
   59   sql = 'select * from options%s where ID=%%s',
(opTable[0].upper() + opTable[1:])
   60   cursor.execute(sql, (id,))
   61 #  cursor.execute('select * from options%s where ID=%s' %
(opTable[0].upper() + opTable[1:], id))
   62   if cursor.fetchone() is not None:
cursor = MySQLdb.cursors.Cursor object, cursor.execute = bound method
Cursor.execute of MySQLdb.cursors.Cursor object, sql = ('select * from
options%s where ID=%%s', 'Sizes'), id = '0.00'
 /usr/lib64/python2.4/site-packages/MySQLdb/cursors.py in
execute(self=MySQLdb.cursors.Cursor object, query=('select * from
options%s where ID=%%s', 'Sizes'), args=('0.00',))
  144 db = self._get_db()
  145 charset = db.character_set_name()
  146 query = query.encode(charset)
  147 if args is not None:
  148 query = query % db.literal(args)
query = ('select * from options%s where ID=%%s', 'Sizes'), query.encode
undefined, charset = 'latin1'

AttributeError: 'tuple' object has no attribute 'encode'
  args = ('tuple' object has no attribute 'encode',)


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


Re: Yet Another MySQL Problem

2010-05-28 Thread Malcolm Greene
Tim,

 The underscore is a valid variable-name, idiomatically used for I don't care 
 about this, often seen in places like tuple assignment:

The underscore is also used as an alias for gettext.gettext or
gettext.ugettext so you may want to use another variable-name.

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


Re: Omit the headers from XML message

2010-05-28 Thread Jon Clements
On 28 May, 16:24, kak...@gmail.com kak...@gmail.com wrote:
 Hi i have the following xml message i want to omit the headers, any
 hints?

 POST /test/pcp/Listener HTTP/1.1
 User-Agent: Jakarta Commons-HttpClient/3.1
 Host: 127.0.0.1:50002
 Content-Length: 547

 pt_control_message xmlns=http://demo.com/demo;
   cmdReply
     sessionList
       session
         idscvdcvsdv/id
         subscriberIdsdfv/subscriberId
         subscriberNameAntonis Kaklis/subscriberName
         presenceaway/presence
         notetesting the new client/note
         ipAddressjlkdjf/ipAddress
         deviceClassandroid/deviceClass
       /session
     /sessionList
   /cmdReply
 /pt_control_message

Assuming the header is separated by a blank line, something like:

list(islice(dropwhile(bool, s.split('\n')), 1, None))
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Free chapter about Python and databases (MySQL and SQLite)

2010-05-28 Thread Peter Otten
christian schulze wrote:

 On 28 Mai, 17:12, Sebastian Bassi sba...@clubdelarazon.org wrote:
 On Fri, May 28, 2010 at 9:41 AM, Tino Wildenhain t...@wildenhain.de
 wrote:
  Did you consider adding a part dealing with postgresql too?
  (Especially interesting in the way you can write stored functions
  in python there)

 That is a good idea for the next version/edition. But meanwhile I
 could write something in my blog atwww.py4bio.com
 Best,
 SB
 
 Indeed a style like
 user=root
 is not that nice.
 
 I had no look at the chapter but recommend you to read the PEP 8 -
 Python style guides (code conventions for python).
 
 Imo a book have to be kinda exemplary. And bad style sucks anyway ...
 
 PS:
 user = 'root' or user = root
 ... would be much more beautyful.

My crystal ball says that the post you are not quoting is concerned about 
the security implications of accessing a database as the superuser rather 
than about spaces surrounding the assignment operator.

My crystal ball then starts nitpicking and adds that in the sample chapter 
user=root occurs within an argument list where its format is actually 
required by the PEP:


- Don't use spaces around the '=' sign when used to indicate a
  keyword argument or a default parameter value.

  Yes:

  def complex(real, imag=0.0):
  return magic(r=real, i=imag)


Cheers,
Peter

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


Re: Some More MySQL

2010-05-28 Thread MRAB

Victor Subervi wrote:

I still have this code:

  sql = 'select * from options%s where ID=%%s', (opTable[0].upper() 
+ opTable[1:])

  cursor.execute(sql, (id,))

which throws this error:

 /var/www/html/angrynates.com/cart/enterOptionsPrices2.py 
http://angrynates.com/cart/enterOptionsPrices2.py

   70 print 'All options prices have been successfully updated.'
   71 print '/body\n/html'
   72
   73 enterOptionsPrices2()
   74
enterOptionsPrices2 = function enterOptionsPrices2
 /var/www/html/angrynates.com/cart/enterOptionsPrices2.py 
http://angrynates.com/cart/enterOptionsPrices2.py in enterOptionsPrices2()

   58   id = form.getfirst('%sID' % option)
   59   sql = 'select * from options%s where ID=%%s', 
(opTable[0].upper() + opTable[1:])

   60   cursor.execute(sql, (id,))
   61 #  cursor.execute('select * from options%s where ID=%s' % 
(opTable[0].upper() + opTable[1:], id))

   62   if cursor.fetchone() is not None:
cursor = MySQLdb.cursors.Cursor object, cursor.execute = bound method 
Cursor.execute of MySQLdb.cursors.Cursor object, sql = ('select * 
from options%s where ID=%%s', 'Sizes'), id = '0.00'
 /usr/lib64/python2.4/site-packages/MySQLdb/cursors.py in 
execute(self=MySQLdb.cursors.Cursor object, query=('select * from 
options%s where ID=%%s', 'Sizes'), args=('0.00',))

  144 db = self._get_db()
  145 charset = db.character_set_name()
  146 query = query.encode(charset)
  147 if args is not None:
  148 query = query % db.literal(args)
query = ('select * from options%s where ID=%%s', 'Sizes'), query.encode 
undefined, charset = 'latin1'


AttributeError: 'tuple' object has no attribute 'encode'
  args = ('tuple' object has no attribute 'encode',)


Please advise.


On line 59 you're making a tuple.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Omit the headers from XML message

2010-05-28 Thread kak...@gmail.com
On 28 Μάϊος, 18:45, Jon Clements jon...@googlemail.com wrote:
 On 28 May, 16:24, kak...@gmail.com kak...@gmail.com wrote:





  Hi i have the following xml message i want to omit the headers, any
  hints?

  POST /test/pcp/Listener HTTP/1.1
  User-Agent: Jakarta Commons-HttpClient/3.1
  Host: 127.0.0.1:50002
  Content-Length: 547

  pt_control_message xmlns=http://demo.com/demo;
    cmdReply
      sessionList
        session
          idscvdcvsdv/id
          subscriberIdsdfv/subscriberId
          subscriberNameAntonis Kaklis/subscriberName
          presenceaway/presence
          notetesting the new client/note
          ipAddressjlkdjf/ipAddress
          deviceClassandroid/deviceClass
        /session
      /sessionList
    /cmdReply
  /pt_control_message

 Assuming the header is separated by a blank line, something like:

 list(islice(dropwhile(bool, s.split('\n')), 1, None))

Thank you!!!

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


Re: Omit the headers from XML message

2010-05-28 Thread Stefan Behnel

kak...@gmail.com, 28.05.2010 17:24:

Hi i have the following xml message i want to omit the headers, any
hints?

POST /test/pcp/Listener HTTP/1.1
User-Agent: Jakarta Commons-HttpClient/3.1
Host: 127.0.0.1:50002
Content-Length: 547

pt_control_message xmlns=http://demo.com/demo;
   cmdReply
 sessionList
   session
 idscvdcvsdv/id
 subscriberIdsdfv/subscriberId
 subscriberNameAntonis Kaklis/subscriberName
 presenceaway/presence
 notetesting the new client/note
 ipAddressjlkdjf/ipAddress
 deviceClassandroid/deviceClass
   /session
 /sessionList
   /cmdReply
/pt_control_message


Use the HTTP server that comes with Python, instead of the plain socket server.

Stefan

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


Re: Omit the headers from XML message

2010-05-28 Thread Peter Otten
Jon Clements wrote:

 On 28 May, 16:24, kak...@gmail.com kak...@gmail.com wrote:
 Hi i have the following xml message i want to omit the headers, any
 hints?

 Assuming the header is separated by a blank line, something like:
 
 list(islice(dropwhile(bool, s.split('\n')), 1, None))

Making the same assumptions, but giving a single string instead of a list of 
lines:

s.partition(\n\n)[-1]

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


Re: ElementTree write creates large one line XML file ....

2010-05-28 Thread robert somerville
Thanks Robert Kern :

prettyprint ; indent()  does the trick ;-)


ElementTree writes exactly what you tell it to. In XML, whitespace is
significant. If you want newlines and/or indentation to make it pretty-looking,
then you need to add those to your elements.

Fredrik provides an example function for doing this:

   http://effbot.org/zone/element-lib.htm#prettyprint
-- 
http://mail.python.org/mailman/listinfo/python-list


Like __getattr__ but with args and kwargs as well

2010-05-28 Thread Giampaolo Rodolà
I know, the title doesn't say much, but I had no better ideas. =)
I have a class within a serie of redundant methods, which looks like this:

class MixedAuthorizer:

def __init__(self, *args):
# expected a list of class instances
self.authorizers = args

def get_home(self, user):
for auth in self.authorizers:
if not auth.has_user(user):
continue
return auth.get_home(user)
return 

def get_password(self, user):
for auth in self.authorizers:
if not auth.has_user(user):
continue
return auth.get_password(user)
return 

 # follows a long list of get_* methods as above
 ...


Considering that I always do the same thing (iterate over a list of
objects - call obj.has_user() - call obj.get_*()) I would like to
know if there's a more compact way to do that.
What I basically need is something like __getattr__ but which provides
the arguments and eventually the keyword arguments a method has been
called with, other than just its name.
Actually I'm not even sure whether Python can reach such a level of
dynamism but I wanted to give it a try anyway.
Is there a way to do such a thing?


--- Giampaolo
http://code.google.com/p/pyftpdlib
http://code.google.com/p/psutil
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Like __getattr__ but with args and kwargs as well

2010-05-28 Thread Miki
class MixedAuthorizer:
def __init__(self, *args):
# expected a list of class instances
self.authorizers = args
self._set_methods()

def _set_methods(self):
for attr in (home, password):
def fn(user):
return self._get_attr(user, attr)
setattr(self, get_%s % attr, fn)

def _get_attr(self, user, attr):
auths = [auth for auth in self.authorizers if
auth.has_user(user)]
if not auths:
return 

method_name = get_%s % attr
method = getattr(auths[0], method_name, None)
if not fn:
raise ValueError(Unknown attribute - %s % method_name)

return fn(user)

HTH,
--
Miki
http://pythonwise.blogspot.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Like __getattr__ but with args and kwargs as well

2010-05-28 Thread Chris Rebert
On Fri, May 28, 2010 at 10:08 AM, Giampaolo Rodolà g.rod...@gmail.com wrote:
 I know, the title doesn't say much, but I had no better ideas. =)
 I have a class within a serie of redundant methods, which looks like this:

 class MixedAuthorizer:

    def __init__(self, *args):
        # expected a list of class instances
        self.authorizers = args

    def get_home(self, user):
        for auth in self.authorizers:
            if not auth.has_user(user):
                continue
            return auth.get_home(user)
        return 

    def get_password(self, user):
        for auth in self.authorizers:
            if not auth.has_user(user):
                continue
            return auth.get_password(user)
        return 

     # follows a long list of get_* methods as above
     ...


 Considering that I always do the same thing (iterate over a list of
 objects - call obj.has_user() - call obj.get_*()) I would like to
 know if there's a more compact way to do that.
 What I basically need is something like __getattr__ but which provides
 the arguments and eventually the keyword arguments a method has been
 called with, other than just its name.
 Actually I'm not even sure whether Python can reach such a level of
 dynamism but I wanted to give it a try anyway.
 Is there a way to do such a thing?

There's no such über-__getattr__, but with some indirection we can
achieve much the same effect:

#Note: Completely untested
from functools import partial

class Whatever(object):
def _getter(self, _name, user, *args, **kwds):
# I assume your actual code will use the *args and **kwds
for auth in self.authorizers:
if not auth.has_user(user):
continue
return getattr(auth, _name)(user)
return 

def __getattr__(self, name):
if name.startswith(get_):
return partial(self._getter, _name=name)
else:
raise AttributeError

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


Re: Like __getattr__ but with args and kwargs as well

2010-05-28 Thread Miki
         method = getattr(auths[0], method_name, None)
Should be
fn = getattr(auths[0], method_name, None)

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


Re: Like __getattr__ but with args and kwargs as well

2010-05-28 Thread Peter Otten
Giampaolo Rodolà wrote:

 I know, the title doesn't say much, but I had no better ideas. =)
 I have a class within a serie of redundant methods, which looks like this:
 
 class MixedAuthorizer:
 
 def __init__(self, *args):
 # expected a list of class instances
 self.authorizers = args
 
 def get_home(self, user):
 for auth in self.authorizers:
 if not auth.has_user(user):
 continue
 return auth.get_home(user)
 return 
 
 def get_password(self, user):
 for auth in self.authorizers:
 if not auth.has_user(user):
 continue
 return auth.get_password(user)
 return 
 
  # follows a long list of get_* methods as above
  ...
 
 
 Considering that I always do the same thing (iterate over a list of
 objects - call obj.has_user() - call obj.get_*()) I would like to
 know if there's a more compact way to do that.
 What I basically need is something like __getattr__ but which provides
 the arguments and eventually the keyword arguments a method has been
 called with, other than just its name.
 Actually I'm not even sure whether Python can reach such a level of
 dynamism but I wanted to give it a try anyway.
 Is there a way to do such a thing?

Yes, and for the above example it is easier to implement than you think:

class MA(object):
def __init__(self, authorizers):
self.authorizers = authorizers
def __getattr__(self, name):
def get(self, user):
for auth in self.authorizers:
if auth.has_user(user):
return getattr(auth, name)(user)
return get.__get__(self)

You can modify it to pass along arbitrary keyword arguments:

class MA(object):
def __init__(self, authorizers):
self.authorizers = authorizers
def __getattr__(self, name):
def get(self, **kw):
for auth in self.authorizers:
if auth.has_user(kw[user]):
return getattr(auth, name)(**kw)
return get.__get__(self)

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


Re: if, continuation and indentation

2010-05-28 Thread Colin J. Williams

On 28-May-10 05:54 AM, Jonathan Hartley wrote:

On May 27, 1:57 pm, Jean-Michel Pichavantjeanmic...@sequans.com
wrote:

HH wrote:

I have a question about best practices when it comes to line wrapping/
continuation and indentation, specifically in the case of an if
statement.



When I write an if statement with many conditions, I prefer to use a
parenthesis around the whole block and get the implicit continuation,
rather than ending each line with an escape character.  Thus, using
the example from the style guide (http://www.python.org/dev/peps/
pep-0008/) I would write:



 if (width == 0 and
 height == 0 and
 color == 'red' and
 emphasis == 'strong' or
 highlight  100):
 raise ValueError(sorry, you lose)



The problem should be obvious -- it's not easy to see where the
conditional ends and the statement begins since they have the same
indentation.  Part of the problem, I suppose, is that Emacs indents
'height' and the other lines in the conditional to 4 spaces (because
of the parenthesis).  How do people deal with this situation?



Thanks,
Henrik


One possible solution

 if (
 width == 0 and
 height == 0 and
 color == 'red' and
 emphasis == 'strong' or
 highlight  100
):
 raise ValueError(sorry, you lose)

JM


I've always liked this, or even:

   if (
   width == 0 and
   height == 0 and
   color == 'red' and
   emphasis == 'strong' or
   highlight  100
   ):
   raise ValueError(sorry, you lose)


but my co-workers have uniformly gone bananas whenever I try it.

I liked:

On 27-May-10 08:48 AM, Xavier Ho wrote:
 On 27 May 2010 22:22, HH henri...@gmail.com
 mailto:henri...@gmail.com wrote:

 if (width == 0 and
 height == 0 and
 color == 'red' and
 emphasis == 'strong' or
 highlight  100):
 raise ValueError(sorry, you lose)


 I've gotta say - I've bumped into this problem before, and I'm sure many
 other have - this is a valid question. It just hasn't bothered me enough
 to ask...

 Correct me if I'm wrong, but I think the following is equivalent, and
 looks better. Although this won't fix all ugly cases in that problem..

 if (width, height, color, emphasis) == (0, 0, 'red', 'strong') or
 highlight  100:
  raise ValueError(sorry, you lose)

 Cheers,
 Xav

but nobody commented.

Colin W.

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


Re: Like __getattr__ but with args and kwargs as well

2010-05-28 Thread Giampaolo Rodolà
2010/5/28 Peter Otten __pete...@web.de:
 Giampaolo Rodolà wrote:

 I know, the title doesn't say much, but I had no better ideas. =)
 I have a class within a serie of redundant methods, which looks like this:

 class MixedAuthorizer:

     def __init__(self, *args):
         # expected a list of class instances
         self.authorizers = args

     def get_home(self, user):
         for auth in self.authorizers:
             if not auth.has_user(user):
                 continue
             return auth.get_home(user)
         return 

     def get_password(self, user):
         for auth in self.authorizers:
             if not auth.has_user(user):
                 continue
             return auth.get_password(user)
         return 

      # follows a long list of get_* methods as above
      ...


 Considering that I always do the same thing (iterate over a list of
 objects - call obj.has_user() - call obj.get_*()) I would like to
 know if there's a more compact way to do that.
 What I basically need is something like __getattr__ but which provides
 the arguments and eventually the keyword arguments a method has been
 called with, other than just its name.
 Actually I'm not even sure whether Python can reach such a level of
 dynamism but I wanted to give it a try anyway.
 Is there a way to do such a thing?

 Yes, and for the above example it is easier to implement than you think:

 class MA(object):
    def __init__(self, authorizers):
        self.authorizers = authorizers
    def __getattr__(self, name):
        def get(self, user):
            for auth in self.authorizers:
                if auth.has_user(user):
                    return getattr(auth, name)(user)
        return get.__get__(self)

 You can modify it to pass along arbitrary keyword arguments:

 class MA(object):
    def __init__(self, authorizers):
        self.authorizers = authorizers
    def __getattr__(self, name):
        def get(self, **kw):
            for auth in self.authorizers:
                if auth.has_user(kw[user]):
                    return getattr(auth, name)(**kw)
        return get.__get__(self)

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




Thanks, this has been helpful.
I managed to write this monster: =)


class MixedAuthorizer(object):

def __init__(self, *authorizers):
self.authorizers = authorizers

def __getattr__(self, name):

def get(self, user, *args, **kwargs):
for auth in self.authorizers:
if auth.has_user(user):
method = getattr(auth, name)
return method(user, *args, **kwargs)

# if we reached this point no user was found
if name == validate_authentication:
return False
if name.startswith(get):
return 
if name.startswith(has):
return False

return get.__get__(self)


--- Giampaolo
http://code.google.com/p/pyftpdlib
http://code.google.com/p/psutil
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Like __getattr__ but with args and kwargs as well

2010-05-28 Thread MRAB

Giampaolo Rodolà wrote:

I know, the title doesn't say much, but I had no better ideas. =)
I have a class within a serie of redundant methods, which looks like this:

class MixedAuthorizer:

def __init__(self, *args):
# expected a list of class instances
self.authorizers = args

def get_home(self, user):
for auth in self.authorizers:
if not auth.has_user(user):
continue
return auth.get_home(user)
return 

def get_password(self, user):
for auth in self.authorizers:
if not auth.has_user(user):
continue
return auth.get_password(user)
return 

 # follows a long list of get_* methods as above
 ...


Considering that I always do the same thing (iterate over a list of
objects - call obj.has_user() - call obj.get_*()) I would like to
know if there's a more compact way to do that.
What I basically need is something like __getattr__ but which provides
the arguments and eventually the keyword arguments a method has been
called with, other than just its name.
Actually I'm not even sure whether Python can reach such a level of
dynamism but I wanted to give it a try anyway.
Is there a way to do such a thing?


Here's a way (mis)using a decorator (written in Python 3):

def locate(func):
def lookup(self, user):
for auth in self.authorizers:
if auth.has_user(user):
return getattr(auth, func.__name__)()
return 
return lookup

class Authorizer:
def __init__(self, user):
self.user = user
def has_user(self, user):
return self.user == user
def get_home(self):
return {}-HOME.format(self.user)
def get_password(self):
return {}-PASSWORD.format(self.user)

class MixedAuthorizer:
def __init__(self, *authorizers):
self.authorizers = authorizers
# The following methods are used only as placeholders.
@locate
def get_home(self): pass
@locate
def get_password(self): pass

a1 = Authorizer(USER1)
a2 = Authorizer(USER2)
m = MixedAuthorizer(a1, a2)
print(m.get_home(USER1))
print(m.get_password(USER2))

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


Re: Omit the headers from XML message

2010-05-28 Thread kak...@gmail.com
On May 28, 7:48 pm, Peter Otten __pete...@web.de wrote:
 Jon Clements wrote:
  On 28 May, 16:24, kak...@gmail.com kak...@gmail.com wrote:
  Hi i have the following xml message i want to omit the headers, any
  hints?
  Assuming the header is separated by a blank line, something like:

  list(islice(dropwhile(bool, s.split('\n')), 1, None))

 Making the same assumptions, but giving a single string instead of a list of
 lines:

 s.partition(\n\n)[-1]

 Peter

Thank you all for your responses!

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


Re: multiprocessing and accessing server's stdout

2010-05-28 Thread Adam Tauno Williams
On Fri, 2010-05-28 at 15:41 +0100, Martin P. Hellwig wrote:
 On 05/28/10 13:17, Adam Tauno Williams wrote:
 cut
  You should be able to point it any any file-like object.  But, again,
  why?
  If you have the data in the process why send it to stdout and redirect
  it.  Why not just send the data to the client directly?
 Well you might want to multiplex it to more then one client, not saying 
 that this is the case here, just something I imagine possible.

That still doesn't make sense.  Why 'multiplex stdout'?  Why not just
multiplex the data into proper IPC channels in the first place?
-- 
Adam Tauno Williams awill...@whitemice.org LPIC-1, Novell CLA
http://www.whitemiceconsulting.com
OpenGroupware, Cyrus IMAPd, Postfix, OpenLDAP, Samba

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


A Friday Python Programming Pearl: random sampling

2010-05-28 Thread Mark Dickinson
For a lazy Friday evening, here's a Python algorithm that seemed so
cute that I just had to share it with everyone.  I'm sure it's well
known to many here, but it was new to me.  Skip directly to the
'sample2' function to see the algorithm and avoid the commentary...

Suppose that you want to select a number of elements, k, say, from a
population, without replacement.  E.g., selecting 3 elements from
range(30) might give you:

[13, 3, 27]

Order matters, so the above is considered distinct from [3, 13, 27].
And you want to be sure that each possible selection has equal
probability of occurring (to within the limits of the underlying
PRNG).

One solution is to select elements from the population one-by-one,
keep track of the indices of already-selected elements in a set, and
if you end up selecting something that's already in your set, simply
try again.  Something like this (code stolen and adapted from
Random.sample in Python's standard library 'random' module):

from random import randrange

def sample1(population, k):
n = len(population)
result = [None] * k
selected = set()
for i in range(k):
j = randrange(n)
# retry until we get something that's not already selected
while j in selected:
j = randrange(n)
selected.add(j)
result[i] = population[j]
return result


N.B.  The above is Python 3 code; for Python 2, replace range with
xrange.

All that's required of 'population' here is that it implements __len__
and __getitem__.  The method works well for k significantly smaller
than n, but as k approaches n the number of reselections required
increases.  So for larger k, Random.sample uses a different method:
roughly, make a copy of 'population', do a partial in-place shuffle of
that copy that randomizes the first k elements, and return those.
This second method isn't so great when k is small and n is huge, since
it ends up being O(n) from the list copy, but it works out that the
two methods complement each other nicely.

Looking at the above code, I was idly wondering whether there was a
way to alter 'sample1' to avoid the need for resampling, thus giving a
single algorithm that works reasonably efficiently regardless of the
population size and requested sample size.  And it turns out that
there is.  The code below is similar to 'sample1' above, except that
instead of using a set to keep track of indices of already-selected
members of the population, it uses a dict; for an index i
(corresponding to a member of the population), d[i] gives the position
that population[i] will occupy in the resulting sample.


from random import randrange

def sample2(population, k):
n = len(population)

d = {}
for i in reversed(range(k)):
j = randrange(i, n)
if j in d:
d[i] = d[j]
d[j] = i

result = [None] * k
for j, i in d.items():
result[i] = population[j]
return result


Note that no resampling is required, and that there's no copying of
the population list.  The really clever bit is the 'if j in d: ...'
block.  If you stare at the algorithm for long enough (and it does
take some staring), you can convince yourself that after the first
'for' loop, d can be any of the n*(n-1)*...*(n-k+1)
mappings-with-no-repeated-elements from some set of k elements of
range(n) to range(k), and that each one of these mappings is equally
likely to occur.  In a sense, this d is the inverse of the desired
sample, which would be a map with no repetitions from range(k) to
range(n).  So inverting d, and replacing d's keys by the corresponding
population elements, gives the random sample.

N.B.  I don't claim any originality for the algorithm; only for the
implementation: the algorithm is based on an algorithm attributed to
Robert Floyd, and appearing in Jon Bentley's 'Programming Pearls' book
(though that algorithm produces a set, so doesn't worry about the
ordering of the sample).  But I was struck by its beauty and
simplicity, and thought it deserved to be better known.

Happy Friday!

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


Re: TypeError: _new_() takes exactly 3 arguments (2 given) - what does it mean?

2010-05-28 Thread Jesse McDonnell
On Wed, 26 May 2010 14:30:21 -0400
Terry Reedy tjre...@udel.edu wrote:

 On 5/24/2010 2:52 PM, Jesse McDonnell wrote:
  I'm attempting to install Powerline http://code.google.com/p/powerline/,
  a computer reservation software based on CherryPy/Python using a MYSql
  database, at my local library and I've run up against an error that I
  
 
 Honestly, unless you find a Python+Powerline expert who will help, I 
 suggest that you delete Powerline and look for something else. The most 
 recent release is an alpha release over 2 years old. Except for the Feb 
 2010 wiki updates, the project appears to be dead. Even if someone 
 helped you past this, there is no evidence that the fix would applied 
 back to the codebase. And what about the next bug or problem?

 Terry Jan Reedy
 
and

On Wed, 26 May 2010 12:04:53 -0700 (PDT)
Carl Banks pavlovevide...@gmail.com wrote:

 [Again, can't see the original, sorry]
 
 On May 26, 11:30 am, Terry Reedy tjre...@udel.edu wrote:
  On 5/24/2010 2:52 PM, Jesse McDonnell wrote:

 
 The most common reason for this message is trying to subclass a
 module.  (Very easy mistake when a module has the same name as a
 class, which is part of why I don't like the practice, though the
 modern PEP 8 reduces the issue.)
 
 IOW, someone did something like this:
 
 import foo
 class bar(foo): pass
 
 when they should have done this:
 
 from foo import foo
 class bar(foo): pass
 

Terry and Carl,

Thanks for your replies. I got a response from the guy who coded Powerline 
through the google group for the app and upgrading dbwrap resolved this 
particular error. He also helped me work through some python-genshi issues and 
I now have  a working web interface.

Thanks again for your help.

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


Re: multiprocessing and accessing server's stdout

2010-05-28 Thread Martin P. Hellwig

On 05/28/10 21:44, Adam Tauno Williams wrote:

On Fri, 2010-05-28 at 15:41 +0100, Martin P. Hellwig wrote:

On 05/28/10 13:17, Adam Tauno Williams wrote:
cut

You should be able to point it any any file-like object.  But, again,
why?
If you have the data in the process why send it to stdout and redirect
it.  Why not just send the data to the client directly?

Well you might want to multiplex it to more then one client, not saying
that this is the case here, just something I imagine possible.


That still doesn't make sense.  Why 'multiplex stdout'?  Why not just
multiplex the data into proper IPC channels in the first place?


I am going on a stretch here, I mostly agree with you, just trying to 
illustrate that there could be corner cases where this is sensible.
The current situation could be that there is a client/server program 
(binary only perhaps) which is not multi-user safe.


Python can be used as a wrapper around the server to make it 
multi-client, by emulating the exact behavior towards the client, the 
client program does not have to be changed.


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


Re: function that counts...

2010-05-28 Thread Lie Ryan
On 05/26/10 11:04, Bryan wrote:
 Jean-Michel Pichavant wrote:
 I still don't see how many positive integers less than n have digits
 that sum up to m makes it a partition though if that what prttn
 means. Surely because I miss the context.
 
 A partition of a positive integer m is an unordered collection of
 positive integers that sum to m. [1, 1, 2, 5] is a partition of 9. The
 problem at issue here is not that of counting partitions.
 
 My algorithm for our prttn separated out the 'ndsums' sub-problem:
 Count d-digit ints with digits summing to m. I found a generalization
 of that problem stated in the /CRC Handbook of Discrete and
 Combinatorial Mathematics/ (2000 edition, section 2.1) among counting
 problems as:
 
Solutions to x_1 + ... x_n = k
0 = x_i = a_i for one or more i
 
 Alas, the handbook does not provide a formula or algorithm. It refers
 to the inclusion/exclusion principle, which I did not see how to turn
 into an efficient algorithm.

superpollo posted this question in comp.programming
(http://groups.google.com/group/comp.programming/browse_thread/thread/e3b10346db8ebd0a/579ca67f8b9b5a8c;
http://groups.google.com/group/comp.programming/msg/f7323d6e6942e883;
http://groups.google.com/group/comp.programming/browse_thread/thread/e3b10346db8ebd0a/dc4cd1e2feb89500
)

I went through the mathematical foundation of using
partition/distribution and inclusion-exclusion, and have written some
code that solves a subset of the problem, feel free if you or superpollo
are interested in continuing my answer (I won't be able to continue it
until next week, have been a little bit busy here)


copying the code here for convenience:

# memoization would be very useful here
def fact(n):
 factorial function (i.e. n! = n * (n-1) * ... * 2 * 1) 
return n * fact(n - 1) if n != 0 else 1

def C(n, r):
 regular Combination (nCr) 
return fact(n) / (fact(n - r) * fact(r))

def D(M, N):
 Distribution aka Partitioning 
return C(M + N - 1, M)

def partition10(M, i):
 Count how many integer  N sums to M where N = 10**int(i) 
s = 0
sign = 1
for j in range(i + 1):
s += sign * D(M, i) * C(i, j)

# flip the sign for inclusion-exclusion
sign *= -1

# if M = 32, then 32, 22, 12, 2, -8
M -= 10
return s

# still need to write:
# def partitionN10(...): -- applies a restriction/boundary to
#   the most significant digit
# then make it recurse.

# assuming factorials calculation is constant time (hint: memoization)
# the resulting code should work in O(n**2)
# an improvement over the naive method which is O(10**n)
# where n is the number of digits in N
# DISCLAIMER: the big-O is a quick guess, not really calculated
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Free chapter about Python and databases (MySQL and SQLite)

2010-05-28 Thread John Bokma
Sebastian Bassi sba...@clubdelarazon.org writes:

 On Fri, May 28, 2010 at 12:37 AM, John Bokma j...@castleamber.com wrote:
 I feel more than uncomfortable with example code that uses: user=root

 What's wrong with this? It is just an example of connection string.
 The reader will use his/her user/pass/dbname according to their own
 settings.

A bit down you're contradicting yourself: your audience is not familiar
with databases, yet you assume that they will use their own settings?

 (e.g. p291). I never get why people write a short (IMO) /bad/ intro to
 databases while there are books out there that do a way better

 The intended audience of this book are biologist who may be not
 familiarized with relational databases. Most of my colleagues (at
 least from the bio camp) don't even know that behind most dynamic web
 pages there are databases and I think that most of them will find the
 intro section useful. You can always skip what you know and go to the
 point you want.

My point is that the intro I (speed) read is weak at best. You say
you're doing your audience a favor, but I don't agree.

 I am not sure that price in this kind of book are tied to the number
 of pages. There must be some relation, but this is not the main factor
 affecting price.

Even if it's just a few bucks, it's still money saved [0]. On top of
that I think it's way better to point your audience to good books on the
topic and skip the intro instead of doing a (half hearted IMO) attempt
at it yourself.

 I would love to see more technical books that start at page 1 with the
 topic, not with an introduction to the language (170+ pages) and some
 ...

 I see where you go, it seems you are not the target audience for this
 book. Anyway I appreciate your feedback.

You're welcome. And to be honest, if the book didn't have those filler
chapters (which they are IMO) I would certainly have been interested in
it. Note that I am not trying to convince you to rewrite your book, but
my bookcase could have 20% more room if technical writers stopped to
write books that tried to introduce their audience to everything but the
kitchen sink [1]. My favourite books are the ones that /don't/ do the
everything but the kitchensink gig, but direct me to other high quality
books.


[0] I've been a technical editor for a book, and got paid by the page.
[1] I mean the books that seem to handle a single specific topic. If I
buy Ubuntu up and running I expect everything, including the
kitchensink.

-- 
John Bokma   j3b

Hacking  Hiking in Mexico -  http://johnbokma.com/
http://castleamber.com/ - Perl  Python Development
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Free chapter about Python and databases (MySQL and SQLite)

2010-05-28 Thread Robinow



Mobile

On May 28, 2010, at 10:05 PM, John Bokma j...@castleamber.com wrote:


Sebastian Bassi sba...@clubdelarazon.org writes:

On Fri, May 28, 2010 at 12:37 AM, John Bokma j...@castleamber.com  
wrote:


Even if it's just a few bucks, it's still money saved [0]. On top of
that I think it's way better to point your audience to good books on  
the

topic and skip the intro instead of doing a (half hearted IMO) attempt
at it yourself.





OK, John. What book do you recommend?

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


Neha Dhupia IN WATER Neha Dhupia IN BIKINI SEXY Neha Dhupia SEXY BELLY Neha Dhupia IN YELLOW BIKINI Neha Dhupia IN WHITE BIKINI Neha Dhupia AS MISS WORLD BOLLYWOOD BIKINI on http://

2010-05-28 Thread Naeem
Neha Dhupia IN WATER Neha Dhupia  IN BIKINI  SEXY Neha Dhupia
SEXY BELLY Neha Dhupia IN YELLOW BIKINI Neha Dhupia IN WHITE
BIKINI Neha Dhupia  AS MISS WORLD BOLLYWOOD BIKINI on
http://hollywood-bollywood-pics.blogspot.com/   Neha Dhupia IN WATER
Neha Dhupia  IN BIKINI  SEXY Neha Dhupia SEXY BELLY Neha Dhupia
IN YELLOW BIKINI Neha Dhupia IN WHITE BIKINI Neha Dhupia  AS MISS
WORLD BOLLYWOOD BIKINI on  http://hollywood-bollywood-pics.blogspot.com/
Neha Dhupia IN WATER Neha Dhupia  IN BIKINI  SEXY Neha Dhupia
SEXY BELLY Neha Dhupia IN YELLOW BIKINI Neha Dhupia IN WHITE
BIKINI Neha Dhupia  AS MISS WORLD BOLLYWOOD BIKINI on
http://hollywood-bollywood-pics.blogspot.com/   Neha Dhupia IN WATER
Neha Dhupia  IN BIKINI  SEXY Neha Dhupia SEXY BELLY Neha Dhupia
IN YELLOW BIKINI Neha Dhupia IN WHITE BIKINI Neha Dhupia  AS MISS
WORLD BOLLYWOOD BIKINI on  http://hollywood-bollywood-pics.blogspot.com/
Neha Dhupia IN WATER Neha Dhupia  IN BIKINI  SEXY Neha Dhupia
SEXY BELLY Neha Dhupia IN YELLOW BIKINI Neha Dhupia IN WHITE
BIKINI Neha Dhupia  AS MISS WORLD BOLLYWOOD BIKINI on
http://hollywood-bollywood-pics.blogspot.com/   Neha Dhupia IN WATER
Neha Dhupia  IN BIKINI  SEXY Neha Dhupia SEXY BELLY Neha Dhupia
IN YELLOW BIKINI Neha Dhupia IN WHITE BIKINI Neha Dhupia  AS MISS
WORLD BOLLYWOOD BIKINI on  http://hollywood-bollywood-pics.blogspot.com/
Neha Dhupia IN WATER Neha Dhupia  IN BIKINI  SEXY Neha Dhupia
SEXY BELLY Neha Dhupia IN YELLOW BIKINI Neha Dhupia IN WHITE
BIKINI Neha Dhupia  AS MISS WORLD BOLLYWOOD BIKINI on
http://hollywood-bollywood-pics.blogspot.com/   Neha Dhupia IN WATER
Neha Dhupia  IN BIKINI  SEXY Neha Dhupia SEXY BELLY Neha Dhupia
IN YELLOW BIKINI Neha Dhupia IN WHITE BIKINI Neha Dhupia  AS MISS
WORLD BOLLYWOOD BIKINI on  http://hollywood-bollywood-pics.blogspot.com/
Neha Dhupia IN WATER Neha Dhupia  IN BIKINI  SEXY Neha Dhupia
SEXY BELLY Neha Dhupia IN YELLOW BIKINI Neha Dhupia IN WHITE
BIKINI Neha Dhupia  AS MISS WORLD BOLLYWOOD BIKINI on
http://hollywood-bollywood-pics.blogspot.com/   Neha Dhupia IN WATER
Neha Dhupia  IN BIKINI  SEXY Neha Dhupia SEXY BELLY Neha Dhupia
IN YELLOW BIKINI Neha Dhupia IN WHITE BIKINI Neha Dhupia  AS MISS
WORLD BOLLYWOOD BIKINI on  http://hollywood-bollywood-pics.blogspot.com/
Neha Dhupia IN WATER Neha Dhupia  IN BIKINI  SEXY Neha Dhupia
SEXY BELLY Neha Dhupia IN YELLOW BIKINI Neha Dhupia IN WHITE
BIKINI Neha Dhupia  AS MISS WORLD BOLLYWOOD BIKINI on
http://hollywood-bollywood-pics.blogspot.com/   Neha Dhupia IN WATER
Neha Dhupia  IN BIKINI  SEXY Neha Dhupia SEXY BELLY Neha Dhupia
IN YELLOW BIKINI Neha Dhupia IN WHITE BIKINI Neha Dhupia  AS MISS
WORLD BOLLYWOOD BIKINI on  http://hollywood-bollywood-pics.blogspot.com/
Neha Dhupia IN WATER Neha Dhupia  IN BIKINI  SEXY Neha Dhupia
SEXY BELLY Neha Dhupia IN YELLOW BIKINI Neha Dhupia IN WHITE
BIKINI Neha Dhupia  AS MISS WORLD BOLLYWOOD BIKINI on
http://hollywood-bollywood-pics.blogspot.com/   Neha Dhupia IN WATER
Neha Dhupia  IN BIKINI  SEXY Neha Dhupia SEXY BELLY Neha Dhupia
IN YELLOW BIKINI Neha Dhupia IN WHITE BIKINI Neha Dhupia  AS MISS
WORLD BOLLYWOOD BIKINI on  http://hollywood-bollywood-pics.blogspot.com/
Neha Dhupia IN WATER Neha Dhupia  IN BIKINI  SEXY Neha Dhupia
SEXY BELLY Neha Dhupia IN YELLOW BIKINI Neha Dhupia IN WHITE
BIKINI Neha Dhupia  AS MISS WORLD BOLLYWOOD BIKINI on
http://hollywood-bollywood-pics.blogspot.com/   Neha Dhupia IN WATER
Neha Dhupia  IN BIKINI  SEXY Neha Dhupia SEXY BELLY Neha Dhupia
IN YELLOW BIKINI Neha Dhupia IN WHITE BIKINI Neha Dhupia  AS MISS
WORLD BOLLYWOOD BIKINI on  http://hollywood-bollywood-pics.blogspot.com/
Neha Dhupia IN WATER Neha Dhupia  IN BIKINI  SEXY Neha Dhupia
SEXY BELLY Neha Dhupia IN YELLOW BIKINI Neha Dhupia IN WHITE
BIKINI Neha Dhupia  AS MISS WORLD BOLLYWOOD BIKINI on
http://hollywood-bollywood-pics.blogspot.com/   Neha Dhupia IN WATER
Neha Dhupia  IN BIKINI  SEXY Neha Dhupia SEXY BELLY Neha Dhupia
IN YELLOW BIKINI Neha Dhupia IN WHITE BIKINI Neha Dhupia  AS MISS
WORLD BOLLYWOOD BIKINI on  http://hollywood-bollywood-pics.blogspot.com/
Neha Dhupia IN WATER Neha Dhupia  IN BIKINI  SEXY Neha Dhupia
SEXY BELLY Neha Dhupia IN YELLOW BIKINI Neha Dhupia IN WHITE
BIKINI Neha Dhupia  AS MISS WORLD BOLLYWOOD BIKINI on
http://hollywood-bollywood-pics.blogspot.com/   Neha Dhupia IN WATER
Neha Dhupia  IN BIKINI  SEXY Neha Dhupia SEXY BELLY Neha Dhupia
IN YELLOW BIKINI Neha Dhupia IN WHITE BIKINI Neha Dhupia  AS MISS
WORLD BOLLYWOOD BIKINI on  http://hollywood-bollywood-pics.blogspot.com/
Neha Dhupia IN WATER Neha Dhupia  IN BIKINI  SEXY Neha Dhupia
SEXY BELLY Neha Dhupia IN YELLOW BIKINI Neha Dhupia IN WHITE
BIKINI Neha Dhupia  AS MISS WORLD BOLLYWOOD BIKINI on
http://hollywood-bollywood-pics.blogspot.com/   Neha Dhupia IN WATER
Neha Dhupia  IN BIKINI  SEXY Neha Dhupia SEXY BELLY Neha Dhupia
IN YELLOW BIKINI Neha Dhupia IN WHITE BIKINI Neha Dhupia  AS MISS
WORLD BOLLYWOOD BIKINI on  

[issue8825] int(0,0) throws exception

2010-05-28 Thread Mark Dickinson

Mark Dickinson dicki...@gmail.com added the comment:

Dino:  I think Clark already did this:

http://ironpython.codeplex.com/WorkItem/View.aspx?WorkItemId=27186

Sorry;  I checked that there was an IronPython issue open before I closed this 
one, but forgot to mention it here.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue8825
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue8838] Remove codecs.readbuffer_encode() and codecs.charbuffer_encode()

2010-05-28 Thread Marc-Andre Lemburg

Marc-Andre Lemburg m...@egenix.com added the comment:

STINNER Victor wrote:
 
 New submission from STINNER Victor victor.stin...@haypocalc.com:
 
 readbuffer_encode() and charbuffer_encode() are not really encoder nor 
 related to encodings: they are related to PyBuffer. readbuffer_encode() uses 
 s# format and charbuffer_encode() uses t# format to parse their 
 arguments. Both functions were introduced by the creation of the _codecs 
 module 10 years ago (r14660).
 
 I think that these functions should be removed. memoryview() should be used 
 instead.
 
 Note: charbuffer_encode() is the last function using on of the t format (t, 
 t#, t*) in Python3.

Those two encoder functions were meant to be used by Python codec
implementations which want to use the readbuffer and charbuffer
interfaces available in Python via s# and t# to access input
object data.

They are not used by the builtin codecs, but may well be in use
by 3rd party codecs.

I'm not sure why you think those functions are not encoders.

--
nosy: +lemburg
title: Remove codecs.readbuffer_encode() and codecs.charbuffer_encode() - 
Remove codecs.readbuffer_encode() andcodecs.charbuffer_encode()

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue8838
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue8839] PyArg_ParseTuple(): remove t# format

2010-05-28 Thread Marc-Andre Lemburg

Marc-Andre Lemburg m...@egenix.com added the comment:

STINNER Victor wrote:
 
 New submission from STINNER Victor victor.stin...@haypocalc.com:
 
 t# format was introduced by r11803 (11 years ago): Implement new format 
 character 't#'. This is like s#, accepting an object that implements the 
 buffer interface, but requires a buffer that contains 8-bit character data.
 
 Python3 now has a strict separation between byte string (bytes and bytearray 
 types) and unicode string (str), and has PyBuffer and PyCapsule APIs. t# 
 format can be replaced by y# or y*.

 Extract of getarg.c:
 
   /*TEO: This can be eliminated --- here only for backward
 compatibility */
 case 't': { /* 8-bit character buffer, read-only access */
 
 In Python, the last function using t# is _codecs.charbuffer_encode() and I 
 proposed to remove this function in #8838. We can also patch this function.
 
 I don't know if third party modules use this format or not. I don't know if 
 it can be just removed or if it should raise a deprecation warning (but who 
 will notice such warning since there are disabled by default?).

Since Python3 completely removed the getcharbuffer interface
to which the t# interfaces in Python2, t# does indeed no
longer serve any special purpose.

It's probably wise to just map t# to y# in order to ease
porting extensions from 2.x to 3.x.

--
nosy: +lemburg

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue8839
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue8839] PyArg_ParseTuple(): remove t# format

2010-05-28 Thread Marc-Andre Lemburg

Marc-Andre Lemburg m...@egenix.com added the comment:

STINNER Victor wrote:
 
 STINNER Victor victor.stin...@haypocalc.com added the comment:
 
 Patch to remove t#:
  - Update c-api/arg.rst documentation
  - Replace t# format by y# in codecs.charbuffer_encode()
  - Add a note in Doc/whatsnew/3.2.rst (in Porting to Python 3.2)

Given that y# is not (yet) in wide-spread use, it may actually make
more sense, to replace y# with t# and introduce t* to replace
y*.

y# and y* could then be setup as synonyms for t# and t*.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue8839
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue8839] PyArg_ParseTuple(): remove t# format

2010-05-28 Thread STINNER Victor

STINNER Victor victor.stin...@haypocalc.com added the comment:

 Given that y# is not (yet) in wide-spread use, ...

t# is only used once (in codecs.charbuffer_encode()), whereas y# is used by 
ossaudiodev, socket and mmap modules (there are 8 functions using y#). There 
are 46 functions using y* format. y format is not used in Python3.

To me, it looks easier to just drop t# and continue to use y, y* and y# formats 
in Python3.

 y# and y* could then be setup as synonyms for t# and t*

If we have to keep backward compatibility, yes, t# can be kept as a synonym for 
y#. But I don't think that backward compatibility of the C API is important in 
Python3 because only few 3rd party modules are compatible with Python3.

--

I prefer to use y, y* and y# formats because they target the *bytes* type 
(which is the Python3 type to store byte strings), whereas s# is used in 
Python2 to get text, *str* type.. which are byte strings, but most Python2 
programmers consider that the str type is the type of chararacter string. I see 
the change of s# to y#, as the change from str to bytes (the strict separation 
between bytes and str).

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue8839
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue8838] Remove codecs.readbuffer_encode() and codecs.charbuffer_encode()

2010-05-28 Thread STINNER Victor

STINNER Victor victor.stin...@haypocalc.com added the comment:

 Those two encoder functions were meant to be used by Python codec
 implementations which want to use the readbuffer and charbuffer
 interfaces available in Python via s# and t# to access input
 object data.

Ah ok.

 They are not used by the builtin codecs, 
 but may well be in use by 3rd party codecs.

My quick Google search didn't found any of those. I suppose that str and bytes 
are enough for most people. Do you know an usecase of text or bytes stored in 
different types than str and bytes? (I suppose the bytearray is compatible with 
bytes, and so it can be used instead of bytes)

 I'm not sure why you think those functions are not encoders.

I consider that Python3 codecs module only encode and decode text to/from an 
encoding, whereas Python2 had extra unrelated codecs like base64 or hex 
(but it was decided to remove them to cleanup the codecs module).

--
title: Remove codecs.readbuffer_encode() andcodecs.charbuffer_encode() - 
Remove codecs.readbuffer_encode() and codecs.charbuffer_encode()

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue8838
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue8835] buildbot: support.transient_internet() doesn't catch DNS socket.gaierror

2010-05-28 Thread STINNER Victor

STINNER Victor victor.stin...@haypocalc.com added the comment:

There is another error:

test test_ssl failed -- Traceback (most recent call last):
  File 
/scratch/pybot-buildarea/trunk.klose-ubuntu-i386/build/Lib/test/test_ssl.py, 
line 261, in test_algorithms
s.connect(remote)
  File /scratch/pybot-buildarea/trunk.klose-ubuntu-i386/build/Lib/ssl.py, 
line 292, in connect
socket.connect(self, addr)
  File /scratch/pybot-buildarea/trunk.klose-ubuntu-i386/build/Lib/socket.py, 
line 222, in meth
return getattr(self._sock,name)(*args)
error: [Errno 110] Connection timed out

transient_internet() should also catch socket.error(errno.ETIMEDOUT).

--

See also #8455, #8499 and #8574.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue8835
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue8842] sqlite3 library outdated in Windows builds

2010-05-28 Thread Marko Kohtala

New submission from Marko Kohtala marko.koht...@gmail.com:

The Windows builds seem to come with SQLite library version 3.5.9, as seen from 
sqlite3.sqlite_version. This is from 2008-May-12.

I've been using the sqlite3 module, but keep running into bugs on Windows. 
Replacing the DLLs\sqlite3.dll with a newer library (sqlite is going at version 
3.6.23), seems to fix those problems.

One problem was locking failures when performing a lot of changes and 
committing after each change. This happens within a single script accessing the 
file, apparently locking himself out. I did not want users needing to patch 
installed Python, so I got around that by removing the smaller commits and 
making one huge commit at end.

Now I had a problem that ANALYZE does not result in good queries. Performing 
ANALYZE with newer library speeded queries significantly. I do not know how to 
get around that.

On Linux I see Python 2.6 using sqlite 3.6.x versions, so I'd expect the reason 
for old library on Windows can not be incompatibility.

--
components: Library (Lib), Windows
messages: 106647
nosy: Marko.Kohtala
priority: normal
severity: normal
status: open
title: sqlite3 library outdated in Windows builds
type: behavior
versions: Python 2.6, Python 3.1

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue8842
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue8839] PyArg_ParseTuple(): remove t# format

2010-05-28 Thread Marc-Andre Lemburg

Marc-Andre Lemburg m...@egenix.com added the comment:

STINNER Victor wrote:
 
 STINNER Victor victor.stin...@haypocalc.com added the comment:
 
 Given that y# is not (yet) in wide-spread use, ...
 
 t# is only used once (in codecs.charbuffer_encode()), whereas y# is used by 
 ossaudiodev, socket and mmap modules (there are 8 functions using y#). There 
 are 46 functions using y* format. y format is not used in Python3.
 
 To me, it looks easier to just drop t# and continue to use y, y* and y# 
 formats in Python3.

You are forgetting our main target: to get extension writers to
port their extensions to Python3. Changes to the Python core are
a lot easier to implement than getting thousands of extensions
ported.

t# is in wide-spread use, since it's the only way a Python2
extension can request access to an object's text data version.

y# was introduced with Python3, and there are only very few
extensions written for it.

Given these facts, it's better to drop y# and replace it with
t#. This is easily done for the core modules and by adding
synonyms for y# we can also automatically take care of the
few Python3 extensions possibly using it.

 y# and y* could then be setup as synonyms for t# and t*
 
 If we have to keep backward compatibility, yes, t# can be kept as a synonym 
 for y#. But I don't think that backward compatibility of the C API is 
 important in Python3 because only few 3rd party modules are compatible with 
 Python3.

True and that's why we have to make it easier for extension writer
to port their extensions rather than making it harder.

It is not too difficult to adjust a Python2 extension to work
in Python3 as well, so that's most likely the route that
many extension writer will take, hence the need to reduce the
number of differences between the Python2 and Python3 C API.

 --
 
 I prefer to use y, y* and y# formats because they target the *bytes* type 
 (which is the Python3 type to store byte strings), whereas s# is used in 
 Python2 to get text, *str* type.. which are byte strings, but most Python2 
 programmers consider that the str type is the type of chararacter string. I 
 see the change of s# to y#, as the change from str to bytes (the strict 
 separation between bytes and str).

That's not correct: s# is used in Python2 to get at the bytes
representation of an object, not the text version. t# was
specifically added to access a text version of the content.

In Python3, this distinction is no longer available (for whatever
reason), so only the bytes representation of the object remains.

Looking at the implementation again, I found that y# rejects
Unicode, while s# returns the default encoded version like
t# does in Python2.

So I have to correct what I said earlier:

y# is not the right replacement for t# in order to stay compatible
with its Python2 pendant. The t# implementation in Python3 is not
compatible with the Python2 approach - it's in fact, a totally
different parser, since Unicode no longer provides a buffer interface
and thus cannot be used as input for t#.

The only compatible pendant to the Python2 t# parser marker
in Python3 appears to be s#.

I'll have to think about this some more, but seen in that light,
removing t# in Python3 may actually be a better strategy after
all - mostly to remove a misguided forward-porting attempt
and to reduce the number of surprising extension writer will
see when porting their apps to Python3.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue8839
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue8843] urllib2 Digest Authorization uri must match request URI

2010-05-28 Thread Andrew Nelis

New submission from Andrew Nelis andrew.ne...@gmail.com:

When using Digest authentication to authenticate with a web server, according 
to rfc2617 (section 3.2.2.5) the uri in the Authorization header MUST match the 
request URI.

urllib2.AbstractDigestAuthHandler doesn't honour this when we request a url of 
the form 'http://hostname' without the trailing slash and we end up with 
request headers of the form:

GET / 1.1
...
Authorization: Digest ... uri= - should be uri=/!

A web server will return 400 Bad Request error.

I attach a patch to fix urllib2.AbstractDigestAuthHandler.get_authorization 
that simply checks for the empty uri and uses '/' instead. It's the same thing 
that httplib.HTTPConnection does when it builds the GET line.

However I do wonder if this uri normalisation should be part of 
Request.get_selector?

Following is a script to demonstrate the behaviour, if you call it as:

./do_digest_request.py http://myserver username password

(and assuming myserver is using Digest authentication) there will a 400 
response instead of it working.

--- do_digest_request.py
#!/usr/bin/env python

import sys
import urllib2
import urlparse

def request( url, username, password ):

p = urlparse.urlparse( url )
password_manager = urllib2.HTTPPasswordMgrWithDefaultRealm()
password_manager.add_password( None, p.hostname, username, password )

handlers = [
urllib2.HTTPDigestAuthHandler( password_manager ),
]

opener = urllib2.build_opener( *handlers )
request = urllib2.Request( url )
response = opener.open( request )
response.read()


if __name__ == '__main__':
request( sys.argv[1], sys.argv[2], sys.argv[3] )

--
components: Library (Lib)
files: urllib2.diff
keywords: patch
messages: 106649
nosy: anelis
priority: normal
severity: normal
status: open
title: urllib2 Digest Authorization uri must match request URI
type: behavior
versions: Python 2.7
Added file: http://bugs.python.org/file17480/urllib2.diff

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue8843
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue8838] Remove codecs.readbuffer_encode() and codecs.charbuffer_encode()

2010-05-28 Thread Marc-Andre Lemburg

Marc-Andre Lemburg m...@egenix.com added the comment:

STINNER Victor wrote:
 
 STINNER Victor victor.stin...@haypocalc.com added the comment:
 
 Those two encoder functions were meant to be used by Python codec
 implementations which want to use the readbuffer and charbuffer
 interfaces available in Python via s# and t# to access input
 object data.
 
 Ah ok.
 
 They are not used by the builtin codecs, 
 but may well be in use by 3rd party codecs.
 
 My quick Google search didn't found any of those. I suppose that str and 
 bytes are enough for most people. Do you know an usecase of text or bytes 
 stored in different types than str and bytes? (I suppose the bytearray is 
 compatible with bytes, and so it can be used instead of bytes)

Any Python object can expose a buffer interface and the above
functions then allow accessing these interfaces from within
Python.

Think of e.g. memory mapped files, image/audio/video objects,
database BLOBs, scientific data types, numeric arrays, etc.
There are lots of such object types.

 I'm not sure why you think those functions are not encoders.
 
 I consider that Python3 codecs module only encode and decode text to/from an 
 encoding, whereas Python2 had extra unrelated codecs like base64 or hex 
 (but it was decided to remove them to cleanup the codecs module).

Those codecs will be reenabled in Python 3.2. Removing them was
a mistake. The codec machinery is not limited to only working
on Unicode and bytes. It can work on arbitrary type combinations,
depending on what a codec wants to implement.

--
title: Remove codecs.readbuffer_encode() and codecs.charbuffer_encode() - 
Remove codecs.readbuffer_encode() andcodecs.charbuffer_encode()

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue8838
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue2920] Patch to print symbolic value or errno in EnvironmentError.__str__()

2010-05-28 Thread Amaury Forgeot d'Arc

Amaury Forgeot d'Arc amaur...@gmail.com added the comment:

I don't like the import errno while printing an exception...
It would be much more robust to store errorcode_dict in a static variable when 
python starts, and reuse it directly.

--
nosy: +amaury.forgeotdarc

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue2920
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue8839] PyArg_ParseTuple(): remove t# format

2010-05-28 Thread STINNER Victor

STINNER Victor victor.stin...@haypocalc.com added the comment:

Le vendredi 28 mai 2010 13:30:22, vous avez écrit :
 Looking at the implementation again, I found that y# rejects
 Unicode, while s# returns the default encoded version like
 t# does in Python2.

Oh, I didn't noticed that.

 So I have to correct what I said earlier:
 
 y# is not the right replacement for t# in order to stay compatible
 with its Python2 pendant. The t# implementation in Python3 is not
 compatible with the Python2 approach - it's in fact, a totally
 different parser, since Unicode no longer provides a buffer interface
 and thus cannot be used as input for t#.
 
 The only compatible pendant to the Python2 t# parser marker
 in Python3 appears to be s#.
 
 I'll have to think about this some more, but seen in that light,
 removing t# in Python3 may actually be a better strategy after
 all - mostly to remove a misguided forward-porting attempt
 and to reduce the number of surprising extension writer will
 see when porting their apps to Python3.

So t#, s# and y# are all different. I'm waiting for your final decision.

reduce the number of surprising extension writer ... is a good argument in 
favor of removing t# :-)

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue8839
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue8838] Remove codecs.readbuffer_encode() and codecs.charbuffer_encode()

2010-05-28 Thread Antoine Pitrou

Antoine Pitrou pit...@free.fr added the comment:

 Any Python object can expose a buffer interface and the above
 functions then allow accessing these interfaces from within
 Python.

What's the point? The codecs functions already support objects exposing the 
buffer interface:

 b = b\xe9
 codecs.latin_1_decode(memoryview(b))
('é', 1)
 codecs.latin_1_decode(array.array(b, b))
('é', 1)

Those two functions are undocumented. They serve no useful purpose (you can 
call the bytes(...) constructor instead, or even use the buffer object directly 
as showed above). They are badly named since they don't have anything to do 
with codecs. Google Code Search shows them not appearing anywhere else than 
implementations of the Python stdlib. Removing them only seems reasonable.

--
nosy: +loewis, pitrou

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue8838
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue2920] Patch to print symbolic value or errno in EnvironmentError.__str__()

2010-05-28 Thread Antoine Pitrou

Antoine Pitrou pit...@free.fr added the comment:

Agreed with Amaury. Module import could fail for various reasons (perhaps the 
same ones which led to the exception being raised!), or could deadlock if the 
import lock is being held. Also, having __str__ fail is usually very annoying 
for users (especially when it's the __str__ of an exception object).

If it's too hard to import errno at startup (because of bootstrapping), I would 
suggest using PyImport_ImportModuleNoBlock() instead, and silence errors (just 
print the numeric value of errno instead).

--
nosy: +pitrou
versions: +Python 2.7, Python 3.1, Python 3.2

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue2920
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue2920] Patch to print symbolic value or errno in EnvironmentError.__str__()

2010-05-28 Thread Alexander Belopolsky

Alexander Belopolsky alexander.belopol...@gmail.com added the comment:

The patch already checks for failed import and falls back to printing  
numerical error code. However, I don't like the import either. I will  
think about the alternatives.

On May 28, 2010, at 8:27 AM, Antoine Pitrou rep...@bugs.python.org  
wrote:


 Antoine Pitrou pit...@free.fr added the comment:

 Agreed with Amaury. Module import could fail for various reasons  
 (perhaps the same ones which led to the exception being raised!), or  
 could deadlock if the import lock is being held. Also, having  
 __str__ fail is usually very annoying for users (especially when  
 it's the __str__ of an exception object).

 If it's too hard to import errno at startup (because of  
 bootstrapping), I would suggest using PyImport_ImportModuleNoBlock()  
 instead, and silence errors (just print the numeric value of errno  
 instead).

 --
 nosy: +pitrou
 versions: +Python 2.7, Python 3.1, Python 3.2

 ___
 Python tracker rep...@bugs.python.org
 http://bugs.python.org/issue2920
 ___

--
nosy: +Alexander.Belopolsky

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue2920
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue8838] Remove codecs.readbuffer_encode() and codecs.charbuffer_encode()

2010-05-28 Thread Marc-Andre Lemburg

Marc-Andre Lemburg m...@egenix.com added the comment:

Antoine Pitrou wrote:
 
 Antoine Pitrou pit...@free.fr added the comment:
 
 Any Python object can expose a buffer interface and the above
 functions then allow accessing these interfaces from within
 Python.
 
 What's the point? The codecs functions already support objects exposing the 
 buffer interface:
 
 b = b\xe9
 codecs.latin_1_decode(memoryview(b))
 ('é', 1)
 codecs.latin_1_decode(array.array(b, b))
 ('é', 1)

 Those two functions are undocumented. They serve no useful purpose (you can 
 call the bytes(...) constructor instead, or even use the buffer object 
 directly as showed above). They are badly named since they don't have 
 anything to do with codecs. Google Code Search shows them not appearing 
 anywhere else than implementations of the Python stdlib. Removing them only 
 seems reasonable.

readbuffer_encode and charbuffer_encode convert objects to bytes
and provide a codec encoder interface for this, hence the naming.

They are meant to be used as encode methods for codecs, just like
the other *_encode functions exposed in the _codecs module, e.g.

class BinaryDataCodec(codecs.Codec):

# Note: Binding these as C functions will result in the class not
# converting them to methods. This is intended.
encode = codecs.readbuffer_encode
decode = codecs.latin_1_decode

While it's possible to emulate the functions via other methods,
these methods always introduce intermediate objects, which isn't
necessary and only costs performance.

Given than t# was basically rendered useless in Python3 (see
issue8839), removing charbuffer_encode() is indeed possible,
so

+1 on removing charbuffer_encode()
-1 on removing readbuffer_encode()

--
title: Remove codecs.readbuffer_encode() andcodecs.charbuffer_encode() - 
Remove codecs.readbuffer_encode() and codecs.charbuffer_encode()

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue8838
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue8838] Remove codecs.readbuffer_encode() and codecs.charbuffer_encode()

2010-05-28 Thread Éric Araujo

Éric Araujo mer...@netwok.org added the comment:

I’d be grateful if someone could post links to discussion about the removal of 
codecs like hex and rot13 and about their coming back. It may be useful for a 
NEWS entry too, not just for my personal curiosity ;) I’ll try to find them 
next week or so if nobody posts them before. Thanks.

--
nosy: +merwok

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue8838
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue8838] Remove codecs.readbuffer_encode() and codecs.charbuffer_encode()

2010-05-28 Thread Antoine Pitrou

Antoine Pitrou pit...@free.fr added the comment:

 class BinaryDataCodec(codecs.Codec):
 
 # Note: Binding these as C functions will result in the class not
 # converting them to methods. This is intended.
 encode = codecs.readbuffer_encode
 decode = codecs.latin_1_decode

What's the point, though? Creating a non-symmetrical codec doesn't sound
like a very useful or recommandable thing to do. Especially in the py3k
codec model where encode() only works on unicode objects.

 While it's possible to emulate the functions via other methods,
 these methods always introduce intermediate objects, which isn't
 necessary and only costs performance.

The bytes() constructor doesn't (shouldn't) create any more intermediate
objects than read/charbuffer_encode() do.

And all this doesn't address the fact that these functions have never
been documented, and don't seem used in the outside world
(understandably so, since there's no way to know about their existence,
and their intended use).

--
title: Remove codecs.readbuffer_encode()and 
codecs.charbuffer_encode() - Remove codecs.readbuffer_encode() and 
codecs.charbuffer_encode()

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue8838
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue8838] Remove codecs.readbuffer_encode() and codecs.charbuffer_encode()

2010-05-28 Thread STINNER Victor

STINNER Victor victor.stin...@haypocalc.com added the comment:

 I’d be grateful if someone could post links to discussion
 about the removal of codecs like hex and rot13

r55932 (~3 years ago):

Rip out all codecs that can't work in a unicode/bytes world:
base64, uu, zlib, rot_13, hex, quopri, bz2, string_escape.

However codecs.escape_encode() and codecs.escape_decode()
still exist, as they are used for pickling str8 objects
(so those two functions can go, when the str8 type is removed).

There were removed 1 year and an half before Python 3.0 release.

 ... and about their coming back

which coming back?

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue8838
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue8838] Remove codecs.readbuffer_encode() and codecs.charbuffer_encode()

2010-05-28 Thread Éric Araujo

Éric Araujo mer...@netwok.org added the comment:

Thanks for the link. Do you have a pointer to the PEP or ML thread
discussing that change?

“Which coming back?”
Martin said these codecs are coming back in 3.2.

--
title: Remove codecs.readbuffer_encode()and codecs.charbuffer_encode() 
- Remove codecs.readbuffer_encode() and codecs.charbuffer_encode()

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue8838
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue8843] urllib2 Digest Authorization uri must match request URI

2010-05-28 Thread Antoine Pitrou

Changes by Antoine Pitrou pit...@free.fr:


--
assignee:  - orsenthil
nosy: +orsenthil
stage:  - patch review
versions: +Python 2.6, Python 3.1, Python 3.2

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue8843
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue8839] PyArg_ParseTuple(): remove t# format

2010-05-28 Thread Antoine Pitrou

Changes by Antoine Pitrou pit...@free.fr:


--
nosy: +loewis

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue8839
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue8838] Remove codecs.readbuffer_encode() and codecs.charbuffer_encode()

2010-05-28 Thread STINNER Victor

STINNER Victor victor.stin...@haypocalc.com added the comment:

 Martin said these codecs are coming back in 3.2.

Oh, there is the issue #7485 where Martin wrote:
* 2009-12-10 23:15: It was a mistake that they were integrated
* 2009-12-12 19:25: I would still be opposed to such a change (...) adding 
them would be really confusing.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue8838
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7475] codecs missing: base64 bz2 hex zlib ...

2010-05-28 Thread STINNER Victor

Changes by STINNER Victor victor.stin...@haypocalc.com:


--
nosy: +haypo

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue7475
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue8838] Remove codecs.readbuffer_encode() and codecs.charbuffer_encode()

2010-05-28 Thread Walter Dörwald

Walter Dörwald wal...@livinglogic.de added the comment:

  I’d be grateful if someone could post links to discussion
  about the removal of codecs like hex and rot13
 r55932 (~3 years ago):

That was my commit. ;)

 Thanks for the link. Do you have a pointer to the PEP or ML thread
 discussing that change?

The removal is documented here: 
http://www.artima.com/weblogs/viewpost.jsp?thread=208549


We are adopting a slightly different approach to codecs: while in Python 2, 
codecs can accept either Unicode or 8-bits as input and produce either as 
output, in Py3k, encoding is always a translation from a Unicode (text) string 
to an array of bytes, and decoding always goes the opposite direction. This 
means that we had to drop a few codecs that don't fit in this model, for 
example rot13, base64 and bz2 (those conversions are still supported, just not 
through the encode/decode API).


A post by Georg Brandl about this is at 
http://mail.python.org/pipermail/python-3000/2007-June/008420.html

(Note that this thread began in private email between Guido, MvL, Georg and 
myself. If needed I can dig up the emails.)

--
nosy: +doerwalter

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue8838
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue8838] Remove codecs.readbuffer_encode() and codecs.charbuffer_encode()

2010-05-28 Thread Marc-Andre Lemburg

Marc-Andre Lemburg m...@egenix.com added the comment:

Antoine Pitrou wrote:
 
 Antoine Pitrou pit...@free.fr added the comment:
 
 class BinaryDataCodec(codecs.Codec):

 # Note: Binding these as C functions will result in the class not
 # converting them to methods. This is intended.
 encode = codecs.readbuffer_encode
 decode = codecs.latin_1_decode
 
 What's the point, though? Creating a non-symmetrical codec doesn't sound
 like a very useful or recommandable thing to do. 

Why not ? If you're only interested in the binary data and
don't care about the original input object type, that's a
very natural thing to do.

E.g. you could use a memory mapped file as input to the encoder.
Would you really expect the codec to recreate such a file object when
decoding the binary data ?

 Especially in the py3k
 codec model where encode() only works on unicode objects.

That's a common misunderstanding. The codec system does not
mandate a specific type combination. Only the helper methods
.encode() and .decode() on bytes and str objects in Python3 do.

 While it's possible to emulate the functions via other methods,
 these methods always introduce intermediate objects, which isn't
 necessary and only costs performance.
 
 The bytes() constructor doesn't (shouldn't) create any more intermediate
 objects than read/charbuffer_encode() do.

Looking at the code, the data takes quite a long path through
the whole machinery. For non-Unicode objects, it always tries to create
an integer and only if that fails reverts back to the buffer
interface after a few more function calls.

Furthermore, the bytes() constructor accepts a lot more
objects than the s# parser marker, e.g. lists of integers,
plain integers, arbitrary iterators, which a codec
just interested in the binary representation of an
object via the buffer interface most likely doesn't
want to accept.

 And all this doesn't address the fact that these functions have never
 been documented, and don't seem used in the outside world
 (understandably so, since there's no way to know about their existence,
 and their intended use).

That's a documentation bug and probably the result of the fact
that none of the exposed encoder/decoder APIs are documented.

--
title: Remove codecs.readbuffer_encode() and codecs.charbuffer_encode() - 
Remove codecs.readbuffer_encode()and codecs.charbuffer_encode()

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue8838
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue8838] Remove codecs.readbuffer_encode() and codecs.charbuffer_encode()

2010-05-28 Thread STINNER Victor

STINNER Victor victor.stin...@haypocalc.com added the comment:

 Oh, there is the issue #7485 where Martin wrote:

Copy/paste failure: issue #7475.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue8838
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue8838] Remove codecs.readbuffer_encode() and codecs.charbuffer_encode()

2010-05-28 Thread Marc-Andre Lemburg

Marc-Andre Lemburg m...@egenix.com added the comment:

STINNER Victor wrote:
 
 Martin said these codecs are coming back in 3.2.

I said that and it was discussed on the python-dev mailing list
a while back.

We'll also add .transform() methods on bytes and str objects
to access same-type codecs.

--
title: Remove codecs.readbuffer_encode()and 
codecs.charbuffer_encode() - Remove codecs.readbuffer_encode() and 
codecs.charbuffer_encode()

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue8838
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue8838] Remove codecs.readbuffer_encode() and codecs.charbuffer_encode()

2010-05-28 Thread STINNER Victor

STINNER Victor victor.stin...@haypocalc.com added the comment:

 readbuffer_encode() and charbuffer_encode() are not really encoder 
 nor related to encodings: they are related to PyBuffer

That was the initial problem: codecs is specific to encodings (in Python3), 
encodes str to bytes, and decodes bytes (or any read buffer) to str.

I don't like readbuffer_*encode* and *charbuffer_encode*  function names, 
because there are different than other codecs: they encode *bytes* to bytes 
(and not str to bytes). I think that these functions should be removed or moved 
somewhere else under a different name.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue8838
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue8838] Remove codecs.readbuffer_encode() and codecs.charbuffer_encode()

2010-05-28 Thread Antoine Pitrou

Antoine Pitrou pit...@free.fr added the comment:

  And all this doesn't address the fact that these functions have never
  been documented, and don't seem used in the outside world
  (understandably so, since there's no way to know about their existence,
  and their intended use).
 
 That's a documentation bug and probably the result of the fact
 that none of the exposed encoder/decoder APIs are documented.

Are you planning to fix it? It is not obvious anybody else is able to
properly document those functions.

--
title: Remove codecs.readbuffer_encode() andcodecs.charbuffer_encode() - 
Remove codecs.readbuffer_encode() and codecs.charbuffer_encode()

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue8838
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue8842] sqlite3 library outdated in Windows builds

2010-05-28 Thread Brian Curtin

Brian Curtin cur...@acm.org added the comment:

SQLite was upgraded to 3.6.21 about 4 months ago for 2.7 and 3.2.

--
nosy: +brian.curtin
resolution:  - out of date
status: open - closed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue8842
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7475] codecs missing: base64 bz2 hex zlib ...

2010-05-28 Thread STINNER Victor

STINNER Victor victor.stin...@haypocalc.com added the comment:

I agree with Martin: codecs choosed the wrong direction in Python2, and it's 
fixed in Python3. The codecs module is related to charsets (encodings), should 
encode str to bytes, and should decode bytes (or any read buffer) to str.

Eg. rot13 encodes str to str.

base64 bz2 hex zlib ...: use base64, bz2, binascii and zlib modules for that.

The documentation should be fixed (explain how to port code from Python2 to 
Python3).

It's maybe possible for write some 2to3 fixers for the following examples:

encode(base64) = base64.b64encode(...)
encode(rot13) = do nothing (but display a warning?)
encode(zlib) = zlib.compress(...)
encode(hex) = base64.b16encode(...)
encode(bz2) = bz2.compress(...)

decode(base64) = base64.b64decode(...)
decode(rot13) = do nothing (but display a warning?)
decode(zlib) = zlib.decompress(...)
decode(hex) = base64.b16decode(...)
decode(bz2) = bz2.decompress(...)

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue7475
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7475] codecs missing: base64 bz2 hex zlib ...

2010-05-28 Thread STINNER Victor

STINNER Victor victor.stin...@haypocalc.com added the comment:

Explanation the change in Python3 by Guido:

We are adopting a slightly different approach to codecs: while in Python 2, 
codecs can accept either Unicode or 8-bits as input and produce either as 
output, in Py3k, encoding is always a translation from a Unicode (text) string 
to an array of bytes, and decoding always goes the opposite direction. This 
means that we had to drop a few codecs that don't fit in this model, for 
example rot13, base64 and bz2 (those conversions are still supported, just not 
through the encode/decode API).

http://www.artima.com/weblogs/viewpost.jsp?thread=208549

--

See also issue #8838.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue7475
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue4015] [patch] make installed scripts executable on windows

2010-05-28 Thread Per

Per pybugs.pho...@safersignup.com added the comment:

On POSIX the interpreter will be read from the first line of a file.
On Windows the interpreter will be read from the Registry 
HKEY_CLASSES_ROOT\.file-extension .

So the correct way to associate a interpreter to a file is to invent a 
file-extension for every interpreter.
Like /usr/bin/python /usr/bin/python3 and /usr/bin/python3.1 on POSIX, there 
should be .py .py3 and .py31 on Windows!

I attached a example-registry-patch to register extensions for 2.5, 2.6 and 3.1 
.
If you want to use it, you need to adjust the paths!

I propose to change all Python-Windows-installer to install versioned 
extensions.

If you want a switcher application, it should read the first line of the script 
and match it against .*/python(.*)$. So the default POSIX 
#!/usr/bin/python3.1 can be kept unchanged. With that rexex the app-path can 
be read from 
HKEY_LOCAL_MACHINE\SOFTWARE\Python\PythonCore\regex-match\InstallPath\.

BTW.
It would be nice if Python would call itself Python 3.1 instead of python 
in the Open with...-list! The current naming is problematic if you install 
more than one Python version.

--
nosy: +phobie
Added file: http://bugs.python.org/file17481/hklm_python_extensions.reg

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue4015
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue8838] Remove codecs.readbuffer_encode() and codecs.charbuffer_encode()

2010-05-28 Thread Éric Araujo

Éric Araujo mer...@netwok.org added the comment:

 I don't like readbuffer_*encode* and *charbuffer_encode*
 function names, because there are different than other codecs
“transform” as hinted by MvL seems perfect.

Thanks everyone for the pointers here and in #7475! I’ll search the missing one 
(“it was discussed on the python-dev mailing list a while back”) later.

--
title: Remove codecs.readbuffer_encode()and codecs.charbuffer_encode() 
- Remove codecs.readbuffer_encode() and codecs.charbuffer_encode()

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue8838
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue4015] [patch] make installed scripts executable on windows

2010-05-28 Thread Éric Araujo

Éric Araujo mer...@netwok.org added the comment:

Related to #870479 (should we make that one a meta-bug?)

--
nosy: +merwok

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue4015
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7475] codecs missing: base64 bz2 hex zlib ...

2010-05-28 Thread Marc-Andre Lemburg

Marc-Andre Lemburg m...@egenix.com added the comment:

STINNER Victor wrote:
 
 STINNER Victor victor.stin...@haypocalc.com added the comment:
 
 I agree with Martin: codecs choosed the wrong direction in Python2, and it's 
 fixed in Python3. The codecs module is related to charsets (encodings), 
 should encode str to bytes, and should decode bytes (or any read buffer) to 
 str.

No, that's just not right: the codec system in Python does not
mandate the types used or accepted by the codecs.

The only change that was applied in Python3 was to make sure
that the str.encode() and bytes.decode() methods always return
the same type to assure type-safety.

Python2 does not apply that check, but instead provides a
direct interface to codecs.encode() and codecs.decode().

Please don't mix the helper methods on those objects with what
the codec system was designed for. The helper methods apply
a strategy that's more constrained than the codec system.

The addition of .transform() and .untransform() for same
type conversions was discussed in 2008, but didn't make it into 3.0
since I hadn't had time to add the methods:

http://mail.python.org/pipermail/python-3000/2008-August/014533.html
http://mail.python.org/pipermail/python-3000/2008-August/014533.html
http://mail.python.org/pipermail/python-3000/2008-August/014534.html

The removed codecs don't rely on the helper methods in any way.
They are easily usable via codecs.encode() and codecs.decode()
even without .transform() and .untransform().

Esp. the hex codec is very handy and at least in our eGenix
code base in wide-spread use. Using a single well-defined
interface to such encodings is just much more user friendly
than having to research the different APIs for each of them.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue7475
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue7475] codecs missing: base64 bz2 hex zlib ...

2010-05-28 Thread Éric Araujo

Changes by Éric Araujo mer...@netwok.org:


--
nosy: +merwok

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue7475
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1759169] clean up Solaris port and allow C99 extension modules

2010-05-28 Thread Martin v . Löwis

Martin v. Löwis mar...@v.loewis.de added the comment:

Thanks for the patch. Committed as r81582 and r81583.

Antoine was right: subsequent references to Solaris needed to be removed also.

--
resolution:  - accepted
status: open - closed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue1759169
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1100562] deepcopying listlike and dictlike objects

2010-05-28 Thread Ryan Coyner

Changes by Ryan Coyner rcoy...@gmail.com:


--
nosy: +rcoyner

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue1100562
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue8713] multiprocessing needs option to eschew fork() under Linux

2010-05-28 Thread Ryan Coyner

Changes by Ryan Coyner rcoy...@gmail.com:


--
nosy: +rcoyner

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue8713
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue8405] Improve test_os._kill (failing on slow machines)

2010-05-28 Thread Brian Curtin

Brian Curtin cur...@acm.org added the comment:

Committed to trunk in r81584 and py3k in r81585.

--
resolution:  - fixed
stage: patch review - committed/rejected
status: open - closed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue8405
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue8405] Improve test_os._kill (failing on slow machines)

2010-05-28 Thread STINNER Victor

STINNER Victor victor.stin...@haypocalc.com added the comment:

 Committed to trunk in r81584 and py3k in r81585

sparc solaris10 gcc trunk buildbot slave doesn't compile anymore. I'm not 
sure that it's related, so I prefer to not reopen the issue :-)

http://www.python.org/dev/buildbot/trunk/builders/sparc%20solaris10%20gcc%20trunk/builds/891

---
...
building '_struct' extension
gcc -fPIC -fno-strict-aliasing -g -O2 -g -O0 -Wall -Wstrict-prototypes -I. 
-IInclude -I./Include -I/usr/local/include 
-I/home2/buildbot/slave/trunk.loewis-sun/build/Include 
-I/home2/buildbot/slave/trunk.loewis-sun/build -c 
/home2/buildbot/slave/trunk.loewis-sun/build/Modules/_struct.c -o 
build/temp.solaris-2.10-sun4u-2.7-pydebug/home2/buildbot/slave/trunk.loewis-sun/build/Modules/_struct.o
gcc -shared 
build/temp.solaris-2.10-sun4u-2.7-pydebug/home2/buildbot/slave/trunk.loewis-sun/build/Modules/_struct.o
 -L/usr/local/lib -o build/lib.solaris-2.10-sun4u-2.7-pydebug/_struct.so
Assertion failed: min = 0, file Python/getargs.c, line 1826
*** Error code 134
The following command caused the error:
case $MAKEFLAGS in \
*s*)  CC='gcc' LDSHARED='gcc -shared' LDFLAGS='' OPT='-g -O0 -Wall 
-Wstrict-prototypes' ./python -E ./setup.py -q build;; \
*)  CC='gcc' LDSHARED='gcc -shared' LDFLAGS='' OPT='-g -O0 -Wall 
-Wstrict-prototypes' ./python -E ./setup.py build;; \
esac
make: Fatal error: Command failed for target `sharedmods'
program finished with exit code 1
---

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue8405
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



  1   2   >