Re: Is Unicode support so hard...

2013-04-21 Thread 88888 Dihedral
jmfauth於 2013年4月21日星期日UTC+8上午1時12分43秒寫道:
 In a previous post,
 
 
 
 http://groups.google.com/group/comp.lang.python/browse_thread/thread/6aec70817705c226#
 
 ,
 
 
 
 Chris “Kwpolska” Warrick wrote:
 
 
 
 “Is Unicode support so hard, especially in the 21st century?”
 
 
 
 --
 
 
 
 Unicode is not really complicate and it works very well (more
 
 than two decades of development if you take into account
 
 iso-14).
 
 
 
 But, - I can say, as usual - people prefer to spend their
 
 time to make a better Unicode than Unicode and it usually
 
 fails. Python does not escape to this rule.
 
 
 
 -
 
 
 
 I'm busy with TeX (unicode engine variant), fonts and typography.
 
 This gives me plenty of ideas to test the flexible string
 
 representation (FSR). I should recognize this FSR is failing
 
 particulary very well...
 
 
 
 I can almost say, a delight.
 
 
 
 jmf
 
 Unicode lover

To support the unicode is easy in the language part.
But to support the unicode in a platform involves
the OS and the display and input hardware devices 
which are not suitable to be free most of the time.
-- 
http://mail.python.org/mailman/listinfo/python-list


django vs zope vs web2py

2013-04-21 Thread Alok Singh Mahor
Hi everyone,
few months back I decided to adopt python for my all sort of work including web 
progra
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: django vs zope vs web2py

2013-04-21 Thread Alok Singh Mahor
I am sorry by mistake I sent incomplete mail here is my mail.

Hi everyone,
few months back I decided to adopt python for my all sort of work including web 
programming. and I have wasted long time deciding which to adopt out of django, 
zope and web2py. 
I am from php and drupal background. which framework would be better for me. I 
am open to learn anything, anything new. but I want to adopt best thing full of 
features and lot of plugins/extensions and easy to use and have better 
documentation and books etc. 

please suggest me so without wasting more time I can start learning 
thanks in advance :)
-- 
http://mail.python.org/mailman/listinfo/python-list


ask for note keeper tomboy's style

2013-04-21 Thread LordMax
Hi to all.

I am new to python and I was asked to implement a system of notes in tomboy's 
style for my company.

As one of the requirements is the ability to synchronize notes between multiple 
PC (program level or through cloud-folder does not matter) I was wondering if 
there is something similar where I can work on.

Do you have any suggestions?

thank you very much
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [TYPES] The type/object distinction and possible synthesis of OOP and imperative programming languages

2013-04-21 Thread 88888 Dihedral
Uday S Reddy於 2013年4月17日星期三UTC+8下午5時10分58秒寫道:
 Mark Janssen writes:
 
 
 
   Having said that, theorists do want to unify concepts wherever possible
 
   and wherever they make sense.  Imperative programming types, which I
 
   will call storage types, are semantically the same as classes.
 
  
The imperative part is supported in Python by tuples only.
The name binding assignment of an object is perative in Python.

Anyway it is not so difficult to mimic the behaviors
and to gain  the benefits of imperative languages  
 at least in the c-python implementation by those
who can play with the Python language in programming.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: django vs zope vs web2py

2013-04-21 Thread rusi
On Apr 21, 11:18 am, Alok Singh Mahor alokma...@gmail.com wrote:
 I am sorry by mistake I sent incomplete mail here is my mail.

 Hi everyone,
 few months back I decided to adopt python for my all sort of work including 
 web programming. and I have wasted long time deciding which to adopt out of 
 django, zope and web2py.
 I am from php and drupal background. which framework would be better for me. 
 I am open to learn anything, anything new. but I want to adopt best thing 
 full of features and lot of plugins/extensions and easy to use and have 
 better documentation and books etc.

 please suggest me so without wasting more time I can start learning
 thanks in advance :)

I am not the best person to advise on this area (hopefully others with
more python-for-web knowledge will speak up)
I see some implicit misconceptions/contradictions in your question so
just saying something…

Python is a general purpose programming language.
php has some (poor?) pretensions to that title.
Drupal cannot even pretend I guess.

Therefore when switching to something like python its important to
have high on your TODO list the need to grok what 'general purpose
programming language' means.
Many people use mega-frameworks like RoR, Django etc without really
knowing much of the underlying programming language.  This has some
consequences:
a. You function suboptimally, basically following the cookie-cutter
approach
b. When you have to switch out of Django into python (say) it can be
very unnerving and frustrating because you suddenly find you dont know
the 'ABC'

So the longer but more fruitful in the long-run approach is to
identify what are the general areas that web programming needs, study
these in isolation and then switch to a mega-framework like django.
Something like:

- templating with cheetah
- ORM with sqlalchemy connecting to some proper database
- web-serving with cherrypy (web.py?, bottle? flask?)

[I am not claiming that this list is complete or the examples are
good.  Of the above Ive only used cheetah]

After your hands are a little dirty with the plumbing, you can switch
to a mega-framework like django.

Also for someone who has mostly web experience, its good to put aside
web (for a while) and try out python for something completely un-web-
ish (a game? a sysadmin script?) to get a feel for 'general purpose
programming language'
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: itertools.groupby

2013-04-21 Thread Peter Otten
Jason Friedman wrote:

 I have a file such as:
 
 $ cat my_data
 Starting a new group
 a
 b
 c
 Starting a new group
 1
 2
 3
 4
 Starting a new group
 X
 Y
 Z
 Starting a new group
 
 I am wanting a list of lists:
 ['a', 'b', 'c']
 ['1', '2', '3', '4']
 ['X', 'Y', 'Z']
 []
 
 I wrote this:
 
 #!/usr/bin/python3
 from itertools import groupby
 
 def get_lines_from_file(file_name):
 with open(file_name) as reader:
 for line in reader.readlines():

readlines() slurps the whole file into memory! Don't do that, iterate over 
the file directly instead:

  for line in reader:

 yield(line.strip())
 
 counter = 0
 def key_func(x):
 if x.startswith(Starting a new group):
 global counter
 counter += 1
 return counter
 
 for key, group in groupby(get_lines_from_file(my_data), key_func):
 print(list(group)[1:])
 
 
 I get the output I desire, but I'm wondering if there is a solution
 without the global counter.

If you were to drop the empty groups you could simplify it to

def is_header(line):
return line.startswith(Starting a new group)

with open(my_data) as lines:
stripped_lines = (line.strip() for line in lines)
for header, group in itertools.groupby(stripped_lines, key=is_header):
if not header:
print(list(group))

And here's a refactoring for your initial code. The main point is the use of 
nonlocal instead of global state to make the function reentrant.

def split_groups(items, header):
odd = True
def group_key(item):
nonlocal odd
if header(item):
odd = not odd
return odd

for _key, group in itertools.groupby(items, key=group_key):
yield itertools.islice(group, 1, None)

def is_header(line):
return line.startswith(Starting a new group)

with open(my_data) as lines:
stripped_lines = map(str.strip, lines)
for group in split_groups(stripped_lines, header=is_header):
print(list(group))

One remaining problem with that code is that it will silently drop the first 
line of the file if it doesn't start with a header:

$ cat my_data 
alpha
beta
gamma
Starting a new group
a
b
c
Starting a new group
Starting a new group
1
2
3
4
Starting a new group
X
Y
Z
Starting a new group
$ python3 group.py 
['beta', 'gamma'] # where's alpha?
['a', 'b', 'c']
[]
['1', '2', '3', '4']
['X', 'Y', 'Z']
[]

How do you want to handle that case?

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


ANN: Albow 2.2.0

2013-04-21 Thread Gregory Ewing

ALBOW - A Little Bit of Widgetry for PyGame

Version 2.2 is now available.

  http://www.cosc.canterbury.ac.nz/greg.ewing/python/Albow/

Highlights of this version:

  * Multichoice control
  * Powerful new facilities for hot-linking controls to application data

There are also many other improvements and bug fixes. See the
Change Log for details.

What is Albow?

Albow is a library for creating GUIs using PyGame that I have been
developing over the course of several PyWeek competitions. I am documenting
and releasing it as a separate package so that others may benefit from it,
and so that it will be permissible for use in future PyGame entries.

The download includes HTML documentation and some example programs
demonstrating most of the library's features. You can also see some
screenshots and browse the documentation on-line.

--
Gregory Ewing
greg.ew...@canterbury.ac.nz
--
http://mail.python.org/mailman/listinfo/python-list


Re: Is Unicode support so hard...

2013-04-21 Thread Terry Jan Reedy

On 4/20/2013 9:37 PM, rusi wrote:


I believe that the recent correction in unicode performance followed
jmf's grumbles


No, the correction followed upon his accurate report of a regression, 
last August, which was unfortunately mixed in with grumbles and 
inaccurate claims. Others separated out and verified the accurate 
report. I reported it to pydev and enquired as to its necessity, I 
believe Mark opened the tracker issue, and the two people who worked on 
optimizing 3.3 a year ago fairly quickly came up with two different 
patches. The several month delay after was a matter of testing and 
picking the best approach.



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


Re: clear the screen

2013-04-21 Thread Dave Angel

On 04/20/2013 10:45 PM, Yuanyuan Li wrote:

How to clear the screen? For example, in the two player game. One player sets a 
number and the second player guesses the number. When the first player enters 
the number, it should be cleared so that the second number is not able to see 
it. My question is how to clear the number.
Thank you!



Welcome to the python mailing list.

The first thing you'd have to specify is your environment.  Are you 
writing a gui program, and if so, with which toolkit (tk, wx, etc.).


Or are you writing a console program?  The simplest portable way is to 
issue 50 or so newlines, so things scroll beyond easy visibility. Of 
course, many terminal programs can easily scroll back, perhaps by using 
the mouse wheel.


If you want something better than that, you'd have to specify your 
Python version and Operating System.  Then somebody familiar with the 
quirks of that particular system can chime in.



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


Re: django vs zope vs web2py

2013-04-21 Thread Roy Smith
In article 47fb29e2-3e78-4989-850b-24359d84b...@googlegroups.com,
 Alok Singh Mahor alokma...@gmail.com wrote:

 I am sorry by mistake I sent incomplete mail here is my mail.
 
 Hi everyone,
 few months back I decided to adopt python for my all sort of work including 
 web programming. and I have wasted long time deciding which to adopt out of 
 django, zope and web2py. 
 I am from php and drupal background. which framework would be better for me. 
 I am open to learn anything, anything new. but I want to adopt best thing 
 full of features and lot of plugins/extensions and easy to use and have 
 better documentation and books etc. 

Zope is a much older framework, and much lower level than django.  It's 
almost certainly not what you want.

I'm not familiar with web2py, so I can't comment on that.

Django is sort of the killer app these days in the python web world.  
That's not to say that it's necessarily the best, but at least it's well 
documented, and has a thriving user community of people who can help 
you.  There's also a lot of add-on software available for it.

The basic things you get from django are:

1) A built-in ORM (Object Relational Mapper) layer.  This is the thing 
which lets you ignore all the horrible details of how your underlying 
database works and just deal with Python objects.

2) A structure for parsing incoming HTTP requests, and calling the right 
bit of your code to handle each request.

3) A template language, to simplify the generation of your HTML pages.

There are others besides the three you mentioned.  You might want to 
start at http://wiki.python.org/moin/WebFrameworks to explore the 
possibilities.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is Unicode support so hard...

2013-04-21 Thread Mark Lawrence

On 21/04/2013 10:02, Terry Jan Reedy wrote:

On 4/20/2013 9:37 PM, rusi wrote:


I believe that the recent correction in unicode performance followed
jmf's grumbles


No, the correction followed upon his accurate report of a regression,
last August, which was unfortunately mixed in with grumbles and
inaccurate claims. Others separated out and verified the accurate
report. I reported it to pydev and enquired as to its necessity, I
believe Mark opened the tracker issue, and the two people who worked on
optimizing 3.3 a year ago fairly quickly came up with two different
patches. The several month delay after was a matter of testing and
picking the best approach.




I'd again like to point out that all I did was raise the issue.  It was 
based on data provided by Steven D'Aprano and confirmed by Serhiy Storchaka.


--
If you're using GoogleCrap™ please read this 
http://wiki.python.org/moin/GoogleGroupsPython.


Mark Lawrence

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


Re: django vs zope vs web2py

2013-04-21 Thread Surya Kasturi
On Sun, Apr 21, 2013 at 11:48 AM, Alok Singh Mahor alokma...@gmail.comwrote:

 I am sorry by mistake I sent incomplete mail here is my mail.

 Hi everyone,
 few months back I decided to adopt python for my all sort of work
 including web programming. and I have wasted long time deciding which to
 adopt out of django, zope and web2py.
 I am from php and drupal background. which framework would be better for
 me. I am open to learn anything, anything new. but I want to adopt best
 thing full of features and lot of plugins/extensions and easy to use and
 have better documentation and books etc.

 please suggest me so without wasting more time I can start learning
 thanks in advance :)
 --
 http://mail.python.org/mailman/listinfo/python-list


You see, in my experience, if you are trying to find the best before
starting (to learn), probably might never going to start.
I don't know what's your Python experience but Django is a decent option to
start over! To start Django, the documentation is one of the best way to
start over!!

Since, you are already into web dev using php, drupal etc. Unless you are
very particular in starting with Django... I suggest you to take a look
into other areas of Python.

May be Network programming or systems programming or getting around
algorithms - trying to learn some mind blowing algos.. hack around on
network..

Come back and do Django.. you will see a lot of fresh ideas!!
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: django vs zope vs web2py

2013-04-21 Thread Modulok
 Hi everyone,
 few months back I decided to adopt python for my all sort of work including
 web programming...
 --
 http://mail.python.org/mailman/listinfo/python-list


Pick Django or web2py. You'll be happy with either. (I have no experience with
zope.)

They're both full featured do-everything-you-ever-wanted frameworks with great
communities and lots of documentation. You can buy books on either. I'd say
web2py is a little more elegant and easier to get started with. (An admittedly
subjective claim.) Django has a little larger community and has more third
party stuff.

If you just need to get it done and don't care about how it happens, they're
both excellent. You'll meet deadlines with either of them. The communities are
smart the docs are great. You can't really go wrong any way you slice it.
There's more third party documentation and books for Django right now but
that's just because Django came out first. Give it another couple years and
there won't be much difference.

Basically, flip a coin and just go with it.



And now for the gritty details approach...

The problem with web frameworks is they are magic, i.e. things just happen.
It's the price we pay for using a high level abstraction. The higher the
abstraction the more magic there is. Often times magic is good. It saves us
time and money. However depending on your needs, other options are worth
considering.

If you are willing to invest a lot of time not being initially productive but
learn a *ton* in exchange, you can use something like cherrypy. (Don't get me
wrong, I love and often use cherrypy.) It's dirt simple and works. However,
because it's so simple it doesn't do half of what you need for a non-trivial
production site. Result? You'll have to fill in the tool chain gaps with other
modules. This is what web frameworks do for you.

If you go the cherrypy route you'll need to learn other things like like markup
languages and some kind of way to talk to a database. Security is also entirely
in your hands. You'll learn a ton about HTTP, SQL, markup languages, web
security, encryption, etc. You'll be basically re-creating a web framework of
your own brand. Again it's a time spent vs. knowledge gained trade off.

For a template language I really liked wheezy.template but it's a little too
new for me to feel comfortable using it on any big project. It has a very
simple inheritance model, which is refreshing. I hope to use it more in the
future.

I usually use Mako for my templates. By 'template' I mean any template, not
just HTML. I use mako for HTML, documentation, I even use mako to write SQL
templates. The inheritance model of Mako takes a little more mental gymnastics
to wrap your head around than the simpler (read nicer) wheezy.template model,
but it's a more mature code base. (Not as mature as cheetah.) I had only minor
experience with cheetah but found I preferred Mako. It was a matter of taste.
There's nothing wrong with cheetah.

As for database access: sqlalchemy is truly excellent and very flexible. For
most things sqlalchemy is great. However for some projects it may contain too
much magic. (Again we're going deeper.) Sometimes a backend-specific module is
called for, in which case psycopg2 on postgresql is nice. The ability to use
python context managers as transaction blocks is very clean.

In short, how much do you want to learn? Do you prefer a top-down or bottom-up
approach? Gritty details or elegant abstractions?

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


Re: clear the screen

2013-04-21 Thread Steven D'Aprano
On Sat, 20 Apr 2013 19:45:46 -0700, Yuanyuan Li wrote:

 How to clear the screen? For example, in the two player game. One player
 sets a number and the second player guesses the number. When the first
 player enters the number, it should be cleared so that the second number
 is not able to see it. My question is how to clear the number. Thank
 you!


What sort of screen? A GUI window, or in a terminal?

If you have a GUI window, you will need to read the documentation for 
your GUI toolkit.

If it is in a terminal, that will depend on the terminal. The best 
solution is to use Curses, if you can, but that is Unix only.

Another solution is this:

print(\x1b[H\x1b[2J)

although that only works in some terminals, and it will not work in IDLE.


Another solution is this:

import os
result = os.system(clear)  # Linux, Mac, Unix

or for Windows:

result = os.system(cls)


but again, it may not work in IDLE.


Last but not least, if everything else fails, try printing a whole lot of 
blank lines:

print(\n*100)


ought to do it on all but the tallest terminals, and amazingly, it even 
works in IDLE!



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


Re: There must be a better way

2013-04-21 Thread Colin J. Williams

On 20/04/2013 9:07 PM, Terry Jan Reedy wrote:

On 4/20/2013 8:34 PM, Tim Chase wrote:

In 2.x, the csv.reader() class (and csv.DictReader() class) offered
a .next() method that is absent in 3.x


In Py 3, .next was renamed to .__next__ for *all* iterators. The
intention is that one iterate with for item in iterable or use builtin
functions iter() and next().



Thanks to Chris, Tim and Terry for their helpful comments.

I was seeking some code that would be acceptable to both Python 2.7 and 3.3.

In the end, I used:

inData= csv.reader(inFile)

def main():
if ver == '2':
headerLine= inData.next()
else:
headerLine= inData.__next__()
...
for item in inData:
assert len(dataStore) == len(item)
j= findCardinal(item[10])
...

This is acceptable to both versions.

It is not usual to have a name with preceding and following 
udserscores,imn user code.


Presumably, there is a rationale for the change from csv.reader.next
to csv.reader.__next__.

If next is not acceptable for the version 3 csv.reader, perhaps __next__ 
could be added to the version 2 csv.reader, so that the same code can be 
used in the two versions.


This would avoid the kluge I used above.

Colin W.

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


Re: There must be a better way

2013-04-21 Thread Jussi Piitulainen
Colin J. Williams writes:
...
 It is not usual to have a name with preceding and following
 udserscores,imn user code.
 
 Presumably, there is a rationale for the change from csv.reader.next
 to csv.reader.__next__.
...

I think the user code is supposed to be next(csv.reader). For example,
current documentation contains the following.

# csvreader.__next__()
# Return the next row of the reader’s iterable object as a list,
# parsed according to the current dialect. Usually you should call
# this as next(reader).
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: There must be a better way

2013-04-21 Thread Peter Otten
Colin J. Williams wrote:

 I was seeking some code that would be acceptable to both Python 2.7 and
 3.3.
 
 In the end, I used:
 
 inData= csv.reader(inFile)
 
 def main():
  if ver == '2':
  headerLine= inData.next()
  else:
  headerLine= inData.__next__()
  ...

I think it was mentioned before, but to be explicit:

def main():
headerLine = next(inData)
...

works in Python 2.6, 2.7, and 3.x.

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


Porting 2.x to 3.3: BaseHTTPServer

2013-04-21 Thread Chris Angelico
I'm porting an old project to Python 3, with the intention of making
one codebase that will still run on 2.6/2.7 as well as 3.2+ (or 3.3+,
if 3.2 is in any way annoying). My first step was to run the code
through 2to3, and the basics are already sorted out by that. Got one
question though, and it's more of an advice one.

In the current version of the code, I use BaseHTTPServer as the main
structure of the request handler. 2to3 translated this into
http.server, which seems to be the nearest direct translation. But is
that the best way to go about making a simple HTTP server?

Also, it's expecting bytes everywhere, and I can't find a simple way
to declare an encoding and let self.wfile.write() accept str. Do I
have to explicitly encode everything that I write, or is there a
cleaner way? (I could always make my own helper function, but would
prefer something standard if there's a way.)

The current version of the code is at: https://github.com/Rosuav/Yosemite

It's ugly in quite a few places; when I wrote most of that, I was
fairly new to Python, so I made a lot of naughty mistakes (bare except
clauses all over the place, ugh!). Adding support for Python 3 seems
like a good excuse to clean all that up, too :)

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


Re: Porting 2.x to 3.3: BaseHTTPServer

2013-04-21 Thread Roy Smith
In article mailman.879.1366551990.3114.python-l...@python.org,
 Chris Angelico ros...@gmail.com wrote:

 In the current version of the code, I use BaseHTTPServer as the main
 structure of the request handler. 2to3 translated this into
 http.server, which seems to be the nearest direct translation. But is
 that the best way to go about making a simple HTTP server?

For most purposes, I would suggest one of the third-party web 
frameworks.  For simple things, I'm partial to Tornado, but it's not the 
only choice.  The advantage of these frameworks is they give you a lot 
of boilerplate code that handles all the low-level protocol gunk and 
lets you concentrate on writing your application logic.

My gut feeling is that nobody should ever be using BaseHTTPServer for 
anything other than as a learning exercise (or as a base on which to 
build other frameworks).  It's just too low level.  I haven't used the 
3.x http.server, but http.server looks like much of the same.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Porting 2.x to 3.3: BaseHTTPServer

2013-04-21 Thread Chris Angelico
On Mon, Apr 22, 2013 at 12:01 AM, Roy Smith r...@panix.com wrote:
 In article mailman.879.1366551990.3114.python-l...@python.org,
  Chris Angelico ros...@gmail.com wrote:

 In the current version of the code, I use BaseHTTPServer as the main
 structure of the request handler. 2to3 translated this into
 http.server, which seems to be the nearest direct translation. But is
 that the best way to go about making a simple HTTP server?

 For most purposes, I would suggest one of the third-party web
 frameworks.  For simple things, I'm partial to Tornado, but it's not the
 only choice.  The advantage of these frameworks is they give you a lot
 of boilerplate code that handles all the low-level protocol gunk and
 lets you concentrate on writing your application logic.

 My gut feeling is that nobody should ever be using BaseHTTPServer for
 anything other than as a learning exercise (or as a base on which to
 build other frameworks).  It's just too low level.  I haven't used the
 3.x http.server, but http.server looks like much of the same.

Have a look at the code in question:

https://github.com/Rosuav/Yosemite/blob/master/Yosemite.py#L81

It's REALLY simple. I don't need any sort of framework; it's basically
just using a web browser as its UI, to save on writing a client. So
I'm looking for the simplest possible option; I don't need security or
anything (this is designed for a trusted LAN), nor scaleability (we're
talking queries per hour, not per second).

I'm actually looking at cutting it back even further. There are
os.system() calls that I'm thinking should possibly become popen(),
and maybe copy a binary into /tmp and giving a full path to it, as
sometimes this is used on a low-end system and needs to perform
actions with low latency.

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


Re: django vs zope vs web2py

2013-04-21 Thread Alok Singh Mahor
On Sun, Apr 21, 2013 at 5:49 PM, Modulok modu...@gmail.com wrote:

  Hi everyone,
  few months back I decided to adopt python for my all sort of work
 including
  web programming...
  --
  http://mail.python.org/mailman/listinfo/python-list
 

 Pick Django or web2py. You'll be happy with either. (I have no experience
 with
 zope.)

 They're both full featured do-everything-you-ever-wanted frameworks with
 great
 communities and lots of documentation. You can buy books on either. I'd say
 web2py is a little more elegant and easier to get started with. (An
 admittedly
 subjective claim.) Django has a little larger community and has more third
 party stuff.

 If you just need to get it done and don't care about how it happens,
 they're
 both excellent. You'll meet deadlines with either of them. The communities
 are
 smart the docs are great. You can't really go wrong any way you slice it.
 There's more third party documentation and books for Django right now but
 that's just because Django came out first. Give it another couple years and
 there won't be much difference.

 Basically, flip a coin and just go with it.



 And now for the gritty details approach...

 The problem with web frameworks is they are magic, i.e. things just
 happen.
 It's the price we pay for using a high level abstraction. The higher the
 abstraction the more magic there is. Often times magic is good. It saves us
 time and money. However depending on your needs, other options are worth
 considering.

 If you are willing to invest a lot of time not being initially productive
 but
 learn a *ton* in exchange, you can use something like cherrypy. (Don't get
 me
 wrong, I love and often use cherrypy.) It's dirt simple and works. However,
 because it's so simple it doesn't do half of what you need for a
 non-trivial
 production site. Result? You'll have to fill in the tool chain gaps with
 other
 modules. This is what web frameworks do for you.

 If you go the cherrypy route you'll need to learn other things like like
 markup
 languages and some kind of way to talk to a database. Security is also
 entirely
 in your hands. You'll learn a ton about HTTP, SQL, markup languages, web
 security, encryption, etc. You'll be basically re-creating a web framework
 of
 your own brand. Again it's a time spent vs. knowledge gained trade off.

 For a template language I really liked wheezy.template but it's a little
 too
 new for me to feel comfortable using it on any big project. It has a very
 simple inheritance model, which is refreshing. I hope to use it more in the
 future.

 I usually use Mako for my templates. By 'template' I mean any template, not
 just HTML. I use mako for HTML, documentation, I even use mako to write SQL
 templates. The inheritance model of Mako takes a little more mental
 gymnastics
 to wrap your head around than the simpler (read nicer) wheezy.template
 model,
 but it's a more mature code base. (Not as mature as cheetah.) I had only
 minor
 experience with cheetah but found I preferred Mako. It was a matter of
 taste.
 There's nothing wrong with cheetah.

 As for database access: sqlalchemy is truly excellent and very flexible.
 For
 most things sqlalchemy is great. However for some projects it may contain
 too
 much magic. (Again we're going deeper.) Sometimes a backend-specific
 module is
 called for, in which case psycopg2 on postgresql is nice. The ability to
 use
 python context managers as transaction blocks is very clean.

 In short, how much do you want to learn? Do you prefer a top-down or
 bottom-up
 approach? Gritty details or elegant abstractions?

 -Modulok-

thanks a lot Rusi, Roy Smith, Surya and Modulok
I am sticking to django. In future I will touch web2py also
-- 
http://mail.python.org/mailman/listinfo/python-list


suggestion for a small addition to the Python 3 list class

2013-04-21 Thread Robert Yacobellis
Greetings,
 
I'm an instructor of Computer Science at Loyola University, Chicago, and I and 
Dr. Harrington (copied on this email) teach sections of COMP 150, Introduction 
to Computing, using Python 3.  One of the concepts we teach students is the str 
methods split() and join().  I have a suggestion for a small addition to the 
list class: add a join() method to lists.  It would work in a similar way to 
how join works for str's, except that the object and method parameter would be 
reversed: list object.join(str object).
 
Rationale: When I teach students about split(), I can intuitively tell them 
split() splits the string on its left on white space or a specified string.  
Explaining the current str join() method to them doesn't seem to make as much 
sense: use the string on the left to join the items in the list??  If the list 
class had a join method, it would be more intuitive to say join the items in 
the list using the specified string (the method's argument).  This is similar 
to Scala's List mkString() method.
 
I've attached a proposed implementation in Python code which is a little more 
general than what I've described.  In this implementation the list can contain 
elements of any type, and the separator can also be any data type, not just str.
 
I've noticed that the str join() method takes an iterable, so in the most 
general case I'm suggesting to add a join() method to every Python-provided 
iterable (however, for split() vs. join() it would be sufficient to just add a 
join() method to the list class).
 
Please let me know your ideas, reactions, and comments on this suggestion.
 
Thanks and regards,
Dr. Robert (Bob) Yacobellis


join.py
Description: Binary data


jointest.py
Description: Binary data
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: There must be a better way

2013-04-21 Thread Colin J. Williams

On 21/04/2013 9:39 AM, Jussi Piitulainen wrote:

Colin J. Williams writes:
...

It is not usual to have a name with preceding and following
udserscores,imn user code.

Presumably, there is a rationale for the change from csv.reader.next
to csv.reader.__next__.

...

I think the user code is supposed to be next(csv.reader). For example,
current documentation contains the following.

# csvreader.__next__()
# Return the next row of the reader’s iterable object as a list,
# parsed according to the current dialect. Usually you should call
# this as next(reader).


Thanks,

This works with both 2.7 and 3.3

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


Re: There must be a better way

2013-04-21 Thread Colin J. Williams

On 21/04/2013 9:43 AM, Peter Otten wrote:

Colin J. Williams wrote:


I was seeking some code that would be acceptable to both Python 2.7 and
3.3.

In the end, I used:

inData= csv.reader(inFile)

def main():
  if ver == '2':
  headerLine= inData.next()
  else:
  headerLine= inData.__next__()
  ...


I think it was mentioned before, but to be explicit:

def main():
 headerLine = next(inData)
 ...

works in Python 2.6, 2.7, and 3.x.



Yes, the penny dropped eventually.  I've used your statement

The Chris suggestion was slightly different:

Use the built-in next() function
(http://docs.python.org/2/library/functions.html#next ) instead:
headerLine = next(iter(inData))

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


Re: The type/object distinction and possible synthesis of OOP and imperative programming languages

2013-04-21 Thread rusi
On Apr 15, 8:48 am, Mark Janssen dreamingforw...@gmail.com wrote:
 That all being said, the thrust of this whole effort is to possibly
 advance Computer Science and language design, because in-between the
 purely concrete object architecture of the imperative programming
 languages and the purely abstract object architecture of
 object-oriented programming languages is a possible middle ground that
 could unite them all.

Just been poking around with eclipse.
And saw this: 
http://softwaresimplexity.blogspot.in/2013/02/where-java-fails.html

For context, the guy seems to be big in the java/eclipse community
[Or at least is well hyped -- he's finalist for eclipse' best
developer award]

This context is needed to underscore something he says in one of the
comments on that page:

OO just sucks…
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: itertools.groupby

2013-04-21 Thread Jason Friedman
#!/usr/bin/python3

 from itertools import groupby

 def get_lines_from_file(file_name):
 with open(file_name) as reader:
 for line in reader.readlines():
 yield(line.strip())

 counter = 0
 def key_func(x):
 if x.startswith(Starting a new group):
 global counter
 counter += 1
 return counter

 for key, group in groupby(get_lines_from_file(my_data), key_func):
 print(list(group)[1:])


Thank you for the responses!  Not sure yet which one I will pick.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: suggestion for a small addition to the Python 3 list class

2013-04-21 Thread Lele Gaifax
Robert Yacobellis ryacobel...@luc.edu writes:

 I've noticed that the str join() method takes an iterable, so in the
 most general case I'm suggesting to add a join() method to every
 Python-provided iterable (however, for split() vs. join() it would be
 sufficient to just add a join() method to the list class).

That's the reasoning behind the rejection: to be friendly enough, you'd
need to include the join method in the sequence protocol, and
implement it on every sequence-like object (be it some kind of
UserList, or a generator, or an interator...)

This question carries several references to the various threads on the
subject: 

http://stackoverflow.com/questions/493819/python-join-why-is-it-string-joinlist-instead-of-list-joinstring

ciao, lele.
-- 
nickname: Lele Gaifax | Quando vivrò di quello che ho pensato ieri
real: Emanuele Gaifas | comincerò ad aver paura di chi mi copia.
l...@metapensiero.it  | -- Fortunato Depero, 1929.

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


Remove some images from a mail message

2013-04-21 Thread Jason Friedman
I will be receiving email that contains, say, 10 images, and I want to
forward that message on after removing, say, 5 of those images.  I will
remove based on size, for example 1679 bytes.  I am aware that other images
besides the unwanted ones could be 1679 bytes but this is unlikely and the
impact of mistakes is small.

I have figured out how to compose and send an email message from parts:
 from, to, subject, and some images.  I was planning to read the incoming
message, write the images I want to keep to files, then use those files to
construct the outgoing message.

I cannot figure out how to read the incoming message and extract the images.

message_in = email.message_from_binary_file(open(file_name, rb))
for part in message_in.walk():
print(- * 80)
print(type:  + part.get_content_maintype())
for key, value in part.items():
print(key:  + key)
print(value:  + value)

-

type: multipart
key: Return-Path
value: jfried...@mycompany.com
key: X-Original-To
value: myuser@myhost

...

key: Content-Type
value: multipart/alternative;
boundary=_000_A9E5330AAB8D0D4E8F9372F872EE8504010458F671hostden_

--_000_A9E5330AAB8D0D4E8F9372F872EE85040104591ECChostden_--

--_010_A9E5330AAB8D0D4E8F9372F872EE85040104591ECChostden_
Content-Type: image/png; name=image001.png
Content-Description: image001.png
Content-Disposition: inline; filename=image001.png; size=9257;
creation-date=Mon, 15 Apr 2013 17:48:29 GMT;
modification-date=Mon, 15 Apr 2013 17:48:29 GMT
Content-ID: image001.png@01CE39DF.E9801A60
Content-Transfer-Encoding: base64

iVBORw0KGgoNSUhEUgAAANcwCAYAAACCPO+PGXRFWHRTb2Z0d2FyZQBBZG9iZSBJ
bWFnZVJlYWR5ccllPAAAI8tJREFUeNrsXQlYVdUW/u+Fey+TCqgJTqA4i4rzjDM4pGaZU449yxAM
Xy+bfY1WZpmZkpapZVpZmpmiKCqoOOGEGjmLI6AioMxcuO/f5+wLl0HFqVd59/ftz3sO+5yzzz7r

...

--

I'm guessing my image is in there, how do I get it out?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ask for note keeper tomboy's style

2013-04-21 Thread Michael Torrie
On 04/21/2013 12:20 AM, LordMax wrote:
 Hi to all.
 
 I am new to python and I was asked to implement a system of notes in
 tomboy's style for my company.
 
 As one of the requirements is the ability to synchronize notes
 between multiple PC (program level or through cloud-folder does not
 matter) I was wondering if there is something similar where I can
 work on.
 
 Do you have any suggestions?

TomBoy is written in C#, so why not start hacking on its code directly.
 True it uses GTK#, but that is available on Windows and OS X.

If you need to start from scratch, you will probably want to develop a
server system to keep all the notes.  You can use any python web
framework you want for that, and SQL of some kind for the data.  Just
develop an RPC api (using XMLRPC, SOAP, or REST) and then your clients
(be it browser-based or conventional apps) can interface with it over
that api.

You might also consider that there are numerous commercial packages that
already do most everything your company needs on a variety of platforms
including handhelds.  For example, Evernote.

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


Re: Porting 2.x to 3.3: BaseHTTPServer

2013-04-21 Thread Serhiy Storchaka

21.04.13 16:46, Chris Angelico написав(ла):

Also, it's expecting bytes everywhere, and I can't find a simple way
to declare an encoding and let self.wfile.write() accept str. Do I
have to explicitly encode everything that I write, or is there a
cleaner way?


io.TextIOWrapper


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


Re: suggestion for a small addition to the Python 3 list class

2013-04-21 Thread Steven D'Aprano
On Sun, 21 Apr 2013 09:09:20 -0500, Robert Yacobellis wrote:

 Greetings,
  
 I'm an instructor of Computer Science at Loyola University, Chicago, and
 I and Dr. Harrington (copied on this email) teach sections of COMP 150,
 Introduction to Computing, using Python 3.  One of the concepts we teach
 students is the str methods split() and join().  I have a suggestion for
 a small addition to the list class: add a join() method to lists.  It
 would work in a similar way to how join works for str's, except that the
 object and method parameter would be reversed: list object.join(str
 object).

That proposed interface doesn't make much sense to me. You're performing 
a string operation (make a new string, using this string as a 
separator) not a list operation, so it's not really appropriate as a 
list method. It makes much more sense as a string method.

It is also much more practical as a string method. This way, only two 
objects need a join method: strings, and bytes (or if you prefer, Unicode 
strings and byte strings). Otherwise, you would need to duplicate the 
method in every possible iterable object:

- lists
- tuples
- dicts
- OrderedDicts
- sets
- frozensets
- iterators
- generators
- every object that obeys the sequence protocol
- every object that obeys the iterator protocol

(with the exception of iterable objects such as range objects that cannot 
contain strings). Every object would have to contain code that does 
exactly the same thing in every detail: walk the iterable, checking that 
the item is a string, and build up a new string with the given separator:

class list: # also tuple, dict, set, frozenset, etc...
def join(self, separator):
...


Not only does that create a lot of duplicated code, but it also increases 
the burden on anyone creating an iterable class, including iterators and 
sequences. Anyone who writes their own iterable class has to write their 
own join method, which is actually trickier than it seems at first 
glance. (See below.)

Any half-decent programmer would recognise the duplicated code and factor 
it out into an external function that takes a separator and a iterable 
object:

def join(iterable, separator):
# common code goes here... it's *all* common code, every object's 
# join method is identical


That's exactly what Python already does, except it swaps the order of the 
arguments:

def join(separator, iterable):
...


and promotes it to a method on strings instead of a bare function.


 Rationale: When I teach students about split(), I can intuitively tell
 them split() splits the string on its left on white space or a specified
 string.  Explaining the current str join() method to them doesn't seem
 to make as much sense: use the string on the left to join the items in
 the list??

Yes, exactly. Makes perfect sense to me.


 If the list class had a join method, it would be more
 intuitive to say join the items in the list using the specified string
 (the method's argument).

You can still say that. You just have to move the parenthetical aside:

Join the items in the list (the method's argument) using the specified 
string.



 This is similar to Scala's List mkString() method.


This is one place where Scala gets it wrong. In my opinion, as a list 
method, mkString ought to operate on the entire list, not its individual 
items. The nearest equivalent in Python would be converting a list to a 
string using the repr() or str() functions:

py str([1, 2, 3])
'[1, 2, 3]'


(which of course call the special methods __repr__ or __str__ on the 
list).


 I've attached a proposed implementation in Python code which is a little
 more general than what I've described.  In this implementation the list
 can contain elements of any type, and the separator can also be any data
 type, not just str.

Just for the record, the implementation you provide will be O(N**2) due 
to the repeated string concatenation, which means it will be *horribly* 
slow for large enough lists. It's actually quite difficult to efficiently 
join a lot of strings without using the str.join method. Repeated string 
concatenation will, in general, be slow due to the repeated copying of 
intermediate results.

By shifting the burden of writing a join method onto everyone who creates 
a sequence type, we would end up with a lot of slow code.

If you must have a convenience (inconvenience?) method on lists, the 
right way to do it is like this:

class list2(list):
def join(self, sep=' '):
if isinstance(sep, (str, bytes)):
return sep.join(self)
raise TypeError





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


Re: Remove some images from a mail message

2013-04-21 Thread Dave Angel

On 04/21/2013 01:31 PM, Jason Friedman wrote:

I will be receiving email that contains, say, 10 images, and I want to
forward that message on after removing, say, 5 of those images.  I will
remove based on size, for example 1679 bytes.  I am aware that other images
besides the unwanted ones could be 1679 bytes but this is unlikely and the
impact of mistakes is small.

I have figured out how to compose and send an email message from parts:
  from, to, subject, and some images.  I was planning to read the incoming
message, write the images I want to keep to files, then use those files to
construct the outgoing message.

I cannot figure out how to read the incoming message and extract the images.

message_in = email.message_from_binary_file(open(file_name, rb))
for part in message_in.walk():
 print(- * 80)
 print(type:  + part.get_content_maintype())
 for key, value in part.items():
 print(key:  + key)
 print(value:  + value)

-

type: multipart
key: Return-Path
value: jfried...@mycompany.com
key: X-Original-To
value: myuser@myhost

...

key: Content-Type
value: multipart/alternative;
 boundary=_000_A9E5330AAB8D0D4E8F9372F872EE8504010458F671hostden_

--_000_A9E5330AAB8D0D4E8F9372F872EE85040104591ECChostden_--

--_010_A9E5330AAB8D0D4E8F9372F872EE85040104591ECChostden_
Content-Type: image/png; name=image001.png
Content-Description: image001.png
Content-Disposition: inline; filename=image001.png; size=9257;
 creation-date=Mon, 15 Apr 2013 17:48:29 GMT;
 modification-date=Mon, 15 Apr 2013 17:48:29 GMT
Content-ID: image001.png@01CE39DF.E9801A60
Content-Transfer-Encoding: base64

iVBORw0KGgoNSUhEUgAAANcwCAYAAACCPO+PGXRFWHRTb2Z0d2FyZQBBZG9iZSBJ
bWFnZVJlYWR5ccllPAAAI8tJREFUeNrsXQlYVdUW/u+Fey+TCqgJTqA4i4rzjDM4pGaZU449yxAM
Xy+bfY1WZpmZkpapZVpZmpmiKCqoOOGEGjmLI6AioMxcuO/f5+wLl0HFqVd59/ftz3sO+5yzzz7r

...

--

I'm guessing my image is in there, how do I get it out?





One possibility, see the base64 module:

http://docs.python.org/library/base64.html

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


Re: Preparing sqlite, dl and tkinter for Python installation (no admin rights)

2013-04-21 Thread James Jong
I see, just to be clear, do you mean that Python 2.7.4 (stable) is
incompatible with Tk 8.6 (stable)?

James


On Fri, Apr 19, 2013 at 12:27 PM, Serhiy Storchaka storch...@gmail.comwrote:

 18.04.13 19:24, James Jong написав(ла):

 The file libtk8.6.so http://libtk8.6.so  has 1.5M and is definitely
 there.


 So why did that compilation fail?


 LD_LIBRARY_PATH=/path_to_libtk

 However be careful. For now Python doesn't support Tk 8.6 (results of some
 functions changed in 8.6), this is a known bug (issue16809). You can build
 Python with Tk 8.6 and even run, but any real tkinter application likely
 will failed. Use Tk 8.5 instead.


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

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


Re: ask for note keeper tomboy's style

2013-04-21 Thread Walter Hurry
On Sun, 21 Apr 2013 11:42:06 -0600, Michael Torrie wrote:

 On 04/21/2013 12:20 AM, LordMax wrote:
 Hi to all.
 
 I am new to python and I was asked to implement a system of notes in
 tomboy's style for my company.
 
 As one of the requirements is the ability to synchronize notes between
 multiple PC (program level or through cloud-folder does not matter) I
 was wondering if there is something similar where I can work on.
 
 Do you have any suggestions?
 
 TomBoy is written in C#, so why not start hacking on its code directly.
  True it uses GTK#, but that is available on Windows and OS X.
 
 If you need to start from scratch, you will probably want to develop a
 server system to keep all the notes.  You can use any python web
 framework you want for that, and SQL of some kind for the data.  Just
 develop an RPC api (using XMLRPC, SOAP, or REST) and then your clients
 (be it browser-based or conventional apps) can interface with it over
 that api.
 
 You might also consider that there are numerous commercial packages that
 already do most everything your company needs on a variety of platforms
 including handhelds.  For example, Evernote.

Wake up. It's homework.
-- 
http://mail.python.org/mailman/listinfo/python-list


Weird behaviour?

2013-04-21 Thread jussij
Can someone please explain the following behaviour?

I downloaded and compiled the Python 2.7.2 code base.

I then created this simple c:\temp\test.py macro: 

import sys

def main():
print(Please Input 120: )
input = raw_input()

print(Value Inputed:  + input)

if str(input) == 120:
print(Yes)
else:
print(No)

main()

If I run the macro using the -u (flush buffers) option the if statement always 
fails:

C:\Temppython.exe -u c:\temp\test.py
Please Input 120:
120
Value Inputed: 120
No

If I run the macro without the -u option the if statement works as expected:

C:\Temppython.exe c:\temp\test.py
Please Input 120:
120
Value Inputed: 120
Yes

What's going on?

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


Re: Weird behaviour?

2013-04-21 Thread Chris Angelico
On Mon, Apr 22, 2013 at 10:37 AM,  jus...@zeusedit.com wrote:
 Can someone please explain the following behaviour?

 If I run the macro using the -u (flush buffers) option the if statement 
 always fails:

 C:\Temppython.exe -u c:\temp\test.py
 Please Input 120:
 120
 Value Inputed: 120
 No

Here's the essence of your program:

print(repr(raw_input()))

You can use that to verify what's going on. Try running that with and
without the -u option; note, by the way, that -u actually means
unbuffered, not flush buffers.

You're running this under Windows. The convention on Windows is for
end-of-line to be signalled with \r\n, but the convention inside
Python is to use just \n. With the normal use of buffered and parsed
input, this is all handled for you; with unbuffered input, that
translation also seems to be disabled, so your string actually
contains '120\r', as will be revealed by its repr().

By the way, raw_input() already returns a string. There's no need to
str() it. :)

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


Re: Weird behaviour?

2013-04-21 Thread Steven D'Aprano
On Sun, 21 Apr 2013 17:37:18 -0700, jussij wrote:

 Can someone please explain the following behaviour?
 
 I downloaded and compiled the Python 2.7.2 code base.
 
 I then created this simple c:\temp\test.py macro:
 
 import sys
 
 def main():
 print(Please Input 120: )
 input = raw_input()
 
 print(Value Inputed:  + input)
 
 if str(input) == 120:
 print(Yes)
 else:
 print(No)
 
 main()
 
 If I run the macro using the -u (flush buffers) option the if statement
 always fails:
 
 C:\Temppython.exe -u c:\temp\test.py Please Input 120:
 120
 Value Inputed: 120
 No


I cannot confirm that behaviour. It works fine for me.

Are you sure that the code you show above is *exactly* the code you're 
using? Actually, it cannot possibly be the exact code you are using, 
since it has been indented. What other changes did you make when retyping 
it in your message? Please copy and paste the actual code used, without 
retyping or making any modifications.

If the problem still persists, try printing repr(input) and see what it 
shows.

Also, a comment on your code: there is no need to call str(input), since 
input is already a string. If you replace the test:

str(input) == '120'

with just 

input == '120'

does the problem go away? If so, then there's something funny going on 
with the call to str(). Please print(str), and see what it shows.



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


Re: Weird behaviour?

2013-04-21 Thread jussij
On Monday, April 22, 2013 10:56:11 AM UTC+10, Chris Angelico wrote:

 so your string actually contains '120\r', as will be revealed 
 by its repr().

Thanks Chris. That makes sense.

Cheers Jussi

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


Re: Weird behaviour?

2013-04-21 Thread Chris Angelico
On Mon, Apr 22, 2013 at 11:05 AM, Steven D'Aprano
steve+comp.lang.pyt...@pearwood.info wrote:
 I cannot confirm that behaviour. It works fine for me.

I should mention: Under Linux, there's no \r, so -u or no -u, the
program will work fine.

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


Re: Weird behaviour?

2013-04-21 Thread Steven D'Aprano
On Mon, 22 Apr 2013 10:56:11 +1000, Chris Angelico wrote:

 You're running this under Windows. The convention on Windows is for
 end-of-line to be signalled with \r\n, but the convention inside Python
 is to use just \n. With the normal use of buffered and parsed input,
 this is all handled for you; with unbuffered input, that translation
 also seems to be disabled, so your string actually contains '120\r', as
 will be revealed by its repr().


If that's actually the case, then I would call that a bug in raw_input.

Actually, raw_input doesn't seem to cope well with embedded newlines even 
without the -u option. On Linux, I can embed a control character by 
typing Ctrl-V followed by Ctrl-char. E.g. Ctrl-V Ctrl-M to embed a 
carriage return, Ctrl-V Ctrl-J to embed a newline. So watch:


[steve@ando ~]$ python2.7 -c x = raw_input('Hello? '); print repr(x)
Hello? 120^M^Jabc
'120\r'

Everything after the newline is lost.


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


Re: Weird behaviour?

2013-04-21 Thread jussij
On Monday, April 22, 2013 11:05:11 AM UTC+10, Steven D'Aprano wrote:

 I cannot confirm that behaviour. It works fine for me.

As Chris pointed out there is a \r character at the end of the string and that 
is causing the if to fail. 

I can now see the \r :)

So this is *Windows only* behaviour. 

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


Re: suggestion for a small addition to the Python 3 list class

2013-04-21 Thread Terry Jan Reedy

On 4/21/2013 1:12 PM, Lele Gaifax wrote:

Robert Yacobellis ryacobel...@luc.edu writes:


I've noticed that the str join() method takes an iterable,


Specifically, it takes an iterable of strings. Any iterable can be made 
such iwth map(str, iterable) or map(repr, iterble).


 so in the

most general case I'm suggesting to add a join() method to every
Python-provided iterable (however, for split() vs. join()


.split *could* have been changed in 3.0 to return an iterator rather 
than a list, as done with map, filter, and others. An itersplit method 
*might* be added in the future.


 it would be

sufficient to just add a join() method to the list class).


That's the reasoning behind the rejection: to be friendly enough, you'd
need to include the join method in the sequence protocol, and
implement it on every sequence-like object (be it some kind of
UserList, or a generator, or an interator...)


Plus, only lists of strings can be joined, not generic lists.



This question carries several references to the various threads on the
subject:

http://stackoverflow.com/questions/493819/python-join-why-is-it-string-joinlist-instead-of-list-joinstring

ciao, lele.




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


Re: itertools.groupby

2013-04-21 Thread Joshua Landau
On 21 April 2013 01:13, Steven D'Aprano 
steve+comp.lang.pyt...@pearwood.info wrote:

 I wouldn't use groupby. It's a hammer, not every grouping job is a nail.

 Instead, use a simple accumulator:


 def group(lines):
 accum = []
 for line in lines:
 line = line.strip()
 if line == 'Starting a new group':
 if accum:  # Don't bother if there are no accumulated lines.
 yield accum
 accum = []
 else:
 accum.append(line)
 # Don't forget the last group of lines.
 if accum: yield accum


Whilst yours is the simplest bar Dennis Lee Bieber's and nicer in that it
yields, neither of yours work for empty groups properly.

I recommend the simple change:

def group(lines):
accum = None
for line in lines:
line = line.strip()
if line == 'Starting a new group':
if accum is not None:  # Don't bother if there are no
accumulated lines.
yield accum
accum = []
else:
accum.append(line)
# Don't forget the last group of lines.
yield accum

But will recommend my own small twist (because I think it is clever):

def group(lines):
lines = (line.strip() for line in lines)

if next(lines) != Starting a new group:
 raise ValueError(First line must be 'Starting a new group')

while True:
 acum = []

for line in lines:
if line == Starting a new group:
 break

acum.append(line)

else:
 yield acum
break

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


Re: Ubuntu package python3 does not include tkinter

2013-04-21 Thread Steven D'Aprano
On Sat, 20 Apr 2013 18:10:58 +0200, Sibylle Koczian wrote:

 Am 19.04.2013 19:42, schrieb lcrocker:
 I understand that for something like a server distribution, but Ubuntu
 is a user-focused desktop distribution. It has a GUI, always. The
 purpose of a distro like that is to give users a good experience. If I
 install Python on Windows, I get to use Python. On Ubuntu, I don't, and
 I think that will confuse some users. I recently recommended Python to
 a friend who wants to start learning programming. Hurdles like this
 don't help someone like him.
 
 It's _so_ easy to install an additional package on Ubuntu that that
 really shouldn't be called a 'hurdle'. Using tkinter or any other GUI
 toolkit is much more difficult for a beginner.

It's only easy to install a package on Ubuntu if you know that you have 
to, and can somehow work out the name of the package.



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


Re: Ubuntu package python3 does not include tkinter

2013-04-21 Thread rusi
On Apr 22, 8:57 am, Steven D'Aprano steve
+comp.lang.pyt...@pearwood.info wrote:
 On Sat, 20 Apr 2013 18:10:58 +0200, Sibylle Koczian wrote:
  Am 19.04.2013 19:42, schrieb lcrocker:
  I understand that for something like a server distribution, but Ubuntu
  is a user-focused desktop distribution. It has a GUI, always. The
  purpose of a distro like that is to give users a good experience. If I
  install Python on Windows, I get to use Python. On Ubuntu, I don't, and
  I think that will confuse some users. I recently recommended Python to
  a friend who wants to start learning programming. Hurdles like this
  don't help someone like him.

  It's _so_ easy to install an additional package on Ubuntu that that
  really shouldn't be called a 'hurdle'. Using tkinter or any other GUI
  toolkit is much more difficult for a beginner.

 It's only easy to install a package on Ubuntu if you know that you have
 to, and can somehow work out the name of the package.

 --
 Steven

Yes

There is some infrastructure in debian/ubuntu (not sure what/where/
how) which behaves something like so:
$peculiar_command
peculiar_command no found but exists in package FooBar

I believe that repackaged pythons (like debian's) should be able to
hook into this system and give better error messages than

ImportError: No module named Tkinter
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Ubuntu package python3 does not include tkinter

2013-04-21 Thread Andrew Berg
On 2013.04.21 22:57, Steven D'Aprano wrote:
 It's only easy to install a package on Ubuntu if you know that you have 
 to, and can somehow work out the name of the package.
I haven't worked with Ubuntu or apt-based packaging in ages, but isn't this 
kind of information in a description message or something
(especially in a GUI frontend)?

-- 
CPython 3.3.0 | Windows NT 6.2.9200 / FreeBSD 9.1
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Ubuntu package python3 does not include tkinter

2013-04-21 Thread rusi
On Apr 22, 9:24 am, Andrew Berg bahamutzero8...@gmail.com wrote:
 On 2013.04.21 22:57, Steven D'Aprano wrote: It's only easy to install a 
 package on Ubuntu if you know that you have
  to, and can somehow work out the name of the package.

 I haven't worked with Ubuntu or apt-based packaging in ages, but isn't this 
 kind of information in a description message or something
 (especially in a GUI frontend)?

Of course... If you know where to look. (I think that's Steven's point
in the 'you know that you have to')

For a noob getting the error
ImportError: No module named Tkinter

it may be that
- he has not installed tkinter
- he has misspelled tkinter
- he has misspelled the import statement (yeah then he'll get syntax
error or somesuch… being a noob he does not know)

I personally know that one can put 'python' in the search box in
synaptic and fish around.
The point is that the noob to python may be a noob to linux/apt also.
-- 
http://mail.python.org/mailman/listinfo/python-list


ANN: rom 0.10 - Redis object mapper for Python

2013-04-21 Thread Josiah Carlson
Hey everyone,

I know, it's been several years since I announced anything on these lists,
but I suspect that some of you may have uses for my new package, so here
you go.

The rom package is a Redis object mapper for Python. It sports an
interface similar to Django's ORM, SQLAlchemy + Elixir, or Appengine's
datastore.

This is the initial release, so there may be some rough edges. I've
included the basic intro for the package below. You can find the package at:
https://www.github.com/josiahcarlson/rom
https://pypi.python.org/pypi/rom

Please CC me on any replies if you have any questions or comments.

Thank you,
 - Josiah

What's new?
==

Everything

What


Rom is a package whose purpose is to offer active-record style data modeling
within Redis from Python, similar to the semantics of Django ORM,
SQLAlchemy +
Elixir, Google's Appengine datastore, and others.

Why
===

I was building a personal project, wanted to use Redis to store some of my
data, but didn't want to hack it poorly. I looked at the existing Redis
object
mappers available in Python, but didn't like the features and functionality
offered.

What is available
=

Data types:

* Strings, ints, floats, decimals
* Json columns (for nested structures)
* OneToMany and ManyToOne columns (for model references)

Indexes:

* Numeric range fetches, searches, and ordering
* Full-word text search (find me entries with col X having words A and B)

Other features:

* Per-thread entity cache (to minimize round-trips, easy saving of all
  entities)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Ubuntu package python3 does not include tkinter

2013-04-21 Thread Andrew Berg
On 2013.04.21 23:34, rusi wrote:
 On Apr 22, 9:24 am, Andrew Berg bahamutzero8...@gmail.com wrote:
 On 2013.04.21 22:57, Steven D'Aprano wrote: It's only easy to install a 
 package on Ubuntu if you know that you have
  to, and can somehow work out the name of the package.

 I haven't worked with Ubuntu or apt-based packaging in ages, but isn't this 
 kind of information in a description message or something
 (especially in a GUI frontend)?
 
 Of course... If you know where to look. (I think that's Steven's point
 in the 'you know that you have to')
I meant when installing it. I forgot for a moment that Ubuntu and many other 
Linux distros come with Python already installed.

-- 
CPython 3.3.1 | Windows NT 6.2.9200 / FreeBSD 9.1
-- 
http://mail.python.org/mailman/listinfo/python-list


How to get urllib2 HTTPConnection object, use httplib methods?

2013-04-21 Thread Brian Raymond
I have a httplib based application and in an effort to find a quick way to 
start leveraging urllib2, including NTLM authentication (via python-ntlm) I am 
hoping there is a way to utilize an HTTPConnection object opened by urllib2. 

The goal is to change the initial opener to use urllib2, after that continue to 
use httplib methods.

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


[issue15745] Numerous utime ns tests fail on FreeBSD w/ ZFS (update: and NetBSD w/ FFS, Solaris w/ UFS)

2013-04-21 Thread koobs

koobs added the comment:

There's some work that's been in the FreeBSD bleachers since Jul 2012 to add 
futimens() and utimensat(), with some recent activity:

RFC: futimens(2) and utimensat(2) - Jul 2012
http://lists.freebsd.org/pipermail/freebsd-arch/2012-February/012409.html 

RFC: futimens(2) and utimensat(2) - Jan 2013
http://lists.freebsd.org/pipermail/freebsd-arch/2013-January/013903.html 

I've also recently been made aware of a vfs.timestamp_precision sysctl and 
tested adjusting it from it's default of 0 - 3, without success:

sysctl -d vfs.timestamp_precision
vfs.timestamp_precision: File timestamp precision (0: seconds, 1: sec + ns 
accurate to 1/HZ, 2: sec + ns truncated to ms, 3+: sec + ns (max. precision))

I'll do my best at this end to encourage the above implementation to be 
committed and request merges to other branches of FreeBSD (likely just 9-STABLE)

In the meantime however, what can be done in the short-term to either tweak the 
tests so they pass or account for the difference in implementations?

The current test failures on the buildbots make it difficult at best to ensure 
core developers are being notified or exposed to other regressions and issues 
that have cropped up in recent months.

--
nosy: +koobs

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



[issue17810] Implement PEP 3154 (pickle protocol 4)

2013-04-21 Thread Alexandre Vassalotti

New submission from Alexandre Vassalotti:

I have restarted the work on PEP 3154. Stefan Mihaila had begun an 
implementation as part of the Google Summer of Code 2012. Unfortunately, he hit 
multiple roadblocks which prevented him to finish his work by the end of the 
summer. He previously shown interest in completing his implementation. However 
he got constrained by time and never resumed his work.

So I am taking over the implementation of the PEP. I have decided to go forward 
with a brand new code, using Stefan's work only as a guide. At the moment, I 
have completed about half of the PEP---missing only support for calling __new__ 
with keyword arguments and the use of new qualified name for referring objects.

Design-wise, there is still a few things that we should discuss. For example, I 
think Stefan's idea, which is not specified in the PEP, to eliminate PUT 
opcodes is interesting. His proposal was to emit an implicit PUT opcode after 
each object pickled and make the Pickler and Unpickler classes agree on the 
scheme. A drawback of this implicit scheme is we cannot be selective about 
which object we save in the memo during unpickling. That means, for example, we 
won't be able to make pickletools.optimize work with protocol 4 to reduce the 
memory footprint of the unpickling process. This scheme also alters the meaning 
of all previously defined opcodes because of the implicit PUTs, which is sort 
of okay because we are changing protocol. Alternatively, we could use an 
explicit scheme by defining new fat opcodes, for the built-in types we care 
about, which includes memoization. This scheme would a bit more flexible 
however it would also be slightly more involved implementation-wise. In any 
 case, I will run benchmarks to see if either schemes are worthwhile.

--
assignee: alexandre.vassalotti
components: Library (Lib)
hgrepos: 184
messages: 187496
nosy: alexandre.vassalotti, pitrou
priority: high
severity: normal
stage: needs patch
status: open
title: Implement PEP 3154 (pickle protocol 4)
type: enhancement
versions: Python 3.4

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



[issue15642] Integrate pickle protocol version 4 GSoC work by Stefan Mihaila

2013-04-21 Thread Alexandre Vassalotti

Alexandre Vassalotti added the comment:

I have started a new implementation of PEP 3154 since Stefan hasn't been active 
on his. Moving the discussion to Issue #17810.

--
dependencies:  -Unbinding of methods
resolution:  - out of date
stage: patch review - committed/rejected
status: open - closed
superseder:  - Implement PEP 3154 (pickle protocol 4)

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



[issue17810] Implement PEP 3154 (pickle protocol 4)

2013-04-21 Thread Alexandre Vassalotti

Changes by Alexandre Vassalotti alexan...@peadrop.com:


--
dependencies: +Unbinding of methods

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



[issue17807] Generator cleanup without tp_del

2013-04-21 Thread Phil Connell

Changes by Phil Connell pconn...@gmail.com:


--
nosy: +isoschiz, pconnell -pitrou

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



[issue17807] Generator cleanup without tp_del

2013-04-21 Thread Phil Connell

Changes by Phil Connell pconn...@gmail.com:


--
nosy: +pitrou

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



[issue17810] Implement PEP 3154 (pickle protocol 4)

2013-04-21 Thread Andrew Svetlov

Changes by Andrew Svetlov andrew.svet...@gmail.com:


--
nosy: +asvetlov

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



[issue17776] IDLE Internationalization

2013-04-21 Thread Damien Marié

Damien Marié added the comment:

Here is a new patch featuring:
_ a setting to disable idle i18n
_ a documentation

Things needed:
_ taking into account Windows (where IDLE is mainly used)
_ a much in-depth translation of the interface: Context-menu, dialogs, ...
_ unit-testing it

To test it by yourself without touching your /usr/share/local you can modify 
the binddomain() (in i18n.py) to another dir:
Like  gettext.bindtextdomain('idlelib',/home/you/your_trans_dir/) 

And put in this dir the en dir in the tar file.

The .mo generation is explained in the module documentation.

So, here is a tar archive with:
_ a screenshot of the patch in action
_ the patch
_ the trans dir to try it by yourself
_ the .po file (thanks to Olivier Berger)

--
Added file: http://bugs.python.org/file29965/patch.tar.gz

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



[issue17810] Implement PEP 3154 (pickle protocol 4)

2013-04-21 Thread Antoine Pitrou

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


--
keywords: +patch
Added file: http://bugs.python.org/file29966/9f1be171da08.diff

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



[issue17804] streaming struct unpacking

2013-04-21 Thread Mark Dickinson

Mark Dickinson added the comment:

This seems like an attractive idea.  There's definitely a need for repeated 
unpacking with the same pattern, and I agree that putting the repetition into 
the pattern is suboptimal (not least from the point of view of caching structs).

One thing that feels a bit unorthogonal is that this is doing two things at 
once:  both allowing for repetition of a pattern, and also adding the lazy 
iteration.  I'd guess that there's also a use-case for allowing repetition but 
not returning an iterator;  but then that's easily covered by list(iter_unpack).

+1 from me.

Hmm;  the name.  'iterunpack'?  'iter_unpack'?  'unpack_stream'?  'unpack_all'?

Would we want something similar for packing, too?  I guess that's effectively 
covered by b''.join(s.pack(item) for item in ...).

--

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



[issue17810] Implement PEP 3154 (pickle protocol 4)

2013-04-21 Thread Antoine Pitrou

Antoine Pitrou added the comment:

Thank you for reviving this :)
A couple of questions:
- why ADDITEM in addition to ADDITEMS? I don't think single-element sets are an 
important use case (as opposed to, say, single-element tuples)
- what is the purpose of STACK_GLOBAL? I would say memoization of common names 
but you pass memoize=False

 For example, I think Stefan's idea, which is not specified in the
 PEP, to eliminate PUT opcodes is interesting. His proposal was to
 emit an implicit PUT opcode after each object pickled and make the
 Pickler and Unpickler classes agree on the scheme.

Are the savings worth it?
I've tried pickletools.optimize() on two objects:

- a typical data dict (http.client.responses). The pickle length decreases from 
1155 to 1063 (8% shrink); unpickling is faster by 4%.

- a Logger object (logging.getLogger(foobar). The pickle length decreases 
from 427 to 389 (9% shrink); unpickling is faster by 2%.

--

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



[issue17808] No code example for Event object in threading module

2013-04-21 Thread Antoine Pitrou

Antoine Pitrou added the comment:

An example should generally show something interesting or non-obvious, which 
isn't the case here. IMHO an Event is simple enough to use that it doesn't need 
an example; furthermore, the example you are proposing doesn't really showcase 
anything interesting, functionally :-)

--
nosy: +pitrou

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



[issue17065] Fix sporadic buildbot failures for test_winreg

2013-04-21 Thread Jeremy Kloth

Jeremy Kloth added the comment:

Not to sound needy, but could the patch be looked into being integrated soon?  
This problem had only occurred once or twice a month however it has caused 
failures three times just in the last week.

--

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



[issue17670] Improve str.expandtabs() doc

2013-04-21 Thread Eli Bendersky

Eli Bendersky added the comment:

LGTM!

--

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



[issue9682] socket.create_connection error message for domain subpart with invalid length is very confusing

2013-04-21 Thread Mike Milkin

Mike Milkin added the comment:

Sure ill modify the patch, thanks for the feedback.

--

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



[issue17065] Fix sporadic buildbot failures for test_winreg

2013-04-21 Thread Roundup Robot

Roundup Robot added the comment:

New changeset 0882960fa6df by R David Murray in branch '3.3':
#17065: Use process-unique key for winreg test.
http://hg.python.org/cpython/rev/0882960fa6df

New changeset c7806d1b09eb by R David Murray in branch 'default':
Merge #17065: Use process-unique key for winreg test.
http://hg.python.org/cpython/rev/c7806d1b09eb

New changeset c0cb78bedc2b by R David Murray in branch '2.7':
#17065: Use process-unique key for winreg test.
http://hg.python.org/cpython/rev/c0cb78bedc2b

--
nosy: +python-dev

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



[issue17065] Fix sporadic buildbot failures for test_winreg

2013-04-21 Thread R. David Murray

R. David Murray added the comment:

Not being a windows dev I couldn't easily test the patch, so hopefully this 
commit won't break the buildbots :)

--
nosy: +r.david.murray
resolution:  - fixed
stage: patch review - committed/rejected
status: open - closed
versions:  -Python 3.2

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



[issue17065] Fix sporadic buildbot failures for test_winreg

2013-04-21 Thread Jeremy Kloth

Jeremy Kloth added the comment:

Thank you!  There are no failures due to the patch and now its just a wait and 
see if test_winreg will misbehave again.

--

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



[issue17810] Implement PEP 3154 (pickle protocol 4)

2013-04-21 Thread Serhiy Storchaka

Changes by Serhiy Storchaka storch...@gmail.com:


--
nosy: +serhiy.storchaka

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



[issue17804] streaming struct unpacking

2013-04-21 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

 Well, according to a quick benchmark, iter_unpack() is 3x to 6x faster than 
 the grouper() + unpack() recipe.
 (it's also a bit more user-friendly)

Yes, It's mainly because a grouper written on Python. When it will be 
implemented in C, the difference will be less. This function will be useful 
beside struct. Note that in my patch for issue17618 struct.Struct(!{}I) is 
not used.

As for extending Struct, what you think about a more powerful feature? About a 
method which returns not an iterator, but an iterable and indexable sequence. 
Here is a sample Python implementation.

--
Added file: http://bugs.python.org/file29967/struct_array_view.py

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



[issue17804] streaming struct unpacking

2013-04-21 Thread Antoine Pitrou

Antoine Pitrou added the comment:

 Yes, It's mainly because a grouper written on Python. When it will be
 implemented in C, the difference will be less. This function will be
 useful beside struct.

I'm not against adding useful C tools to itertools, but you may have to
convince Raymond ;)

 As for extending Struct, what you think about a more powerful feature?
 About a method which returns not an iterator, but an iterable and
 indexable sequence. Here is a sample Python implementation.

I'll take a look, but the question is how complex a C implementation
would be.

--

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



[issue17810] Implement PEP 3154 (pickle protocol 4)

2013-04-21 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Link to the previous attempt: issue15642.

--

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



[issue16231] pickle persistent_id return value

2013-04-21 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

It was fixed for Python 3 in 0ae50aa7d97c. Should it be fixed in 2.7 too or 
close the issue as won't fix? Note that cPickle tests the return value of 
persistent_id only for None.

--
nosy: +alexandre.vassalotti, pitrou, serhiy.storchaka

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



[issue17810] Implement PEP 3154 (pickle protocol 4)

2013-04-21 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

Memoization consumes memory during pickling. For now every memoized object 
requires memory for:

dict's entity;
an id() integer object;
a 2-element tuple;
a pickle's index (an integer object).

It's about 80 bytes on 32-bit platform (and twice as this on 64-bit). For data 
which contains a lot of floats it can be cumbersome.

--

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



[issue17348] Unicode - encoding seems to be lost for inputs of unicode chars

2013-04-21 Thread Tomoki Imai

Tomoki Imai added the comment:

NO,this thread should not be closed!
This is IDLE Bug.I found, IDLE has issue in using unicode literal.

In normal interpreter in console.
 uこんにちは
u'\u3053\u3093\u306b\u3061\u306f'

In IDLE.
 uこんにちは
u'\xe3\x81\x93\xe3\x82\x93\xe3\x81\xab\xe3\x81\xa1\xe3\x81\xaf'

I take a look IDLE codes, found bug in IDLE.
In idlelib/PyShell.py.

def runsource(self, source):
Extend base class method: Stuff the source in the line cache first
filename = self.stuffsource(source)
self.more = 0
self.save_warnings_filters = warnings.filters[:]
warnings.filterwarnings(action=error, category=SyntaxWarning)
print(source,len(source))

if isinstance(source, types.UnicodeType):
from idlelib import IOBinding
try:
source = source.encode(IOBinding.encoding)
except UnicodeError:
self.tkconsole.resetoutput()
self.write(Unsupported characters in input\n)
return
try:
print(source,len(source))
# InteractiveInterpreter.runsource() calls its runcode() method,
# which is overridden (see below)
return InteractiveInterpreter.runsource(self, source, filename)
finally:
if self.save_warnings_filters is not None:
warnings.filters[:] = self.save_warnings_filters
self.save_warnings_filters = None


This codes change uこんにちは to 
u'\xe3\x81\x93\xe3\x82\x93\xe3\x81\xab\xe3\x81\xa1\xe3\x81\xaf'
I commented out  following lines.

if isinstance(source, types.UnicodeType):
from idlelib import IOBinding
try:
source = source.encode(IOBinding.encoding)
except UnicodeError:
self.tkconsole.resetoutput()
self.write(Unsupported characters in input\n)
return

And now works.
Not well tested, I'll do unittest in GSoC (if I can).

--
components: +IDLE -Unicode
keywords: +patch
nosy: +Tomoki.Imai
type:  - behavior
Added file: http://bugs.python.org/file29968/PyShell.py.20130422.diff

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



[issue17618] base85 encoding

2013-04-21 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

As for interface, I think 'adobe' flag should be false by default. It makes 
encoder simpler. ascii85 encoder in Go's standard library doesn't wrap nor add 
Adobe's brackets. btoa/atob functions looks redundant as we can just use 
a85encode/a85decoder with appropriate options. Perhaps we should get rid from 
'adobe' flag in a85decode and autodetect it. And perhaps to do the same with 
other a85decode's options.

--

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



[issue17618] base85 encoding

2013-04-21 Thread Martin Morrison

Martin Morrison added the comment:

On 21 Apr 2013, at 17:38, Serhiy Storchaka rep...@bugs.python.org wrote:
 Serhiy Storchaka added the comment:
 
 As for interface, I think 'adobe' flag should be false by default. It makes 
 encoder simpler. ascii85 encoder in Go's standard library doesn't wrap nor 
 add Adobe's brackets. btoa/atob functions looks redundant as we can just use 
 a85encode/a85decoder with appropriate options. Perhaps we should get rid from 
 'adobe' flag in a85decode and autodetect it. And perhaps to do the same with 
 other a85decode's options.

The problem with autodetecting is that it makes it impossible for an 
application to use this library to verify that something is encoded in a 
specific way. Explicit is better than implicit. 

Otherwise, your changes look good to me.

--

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



[issue17810] Implement PEP 3154 (pickle protocol 4)

2013-04-21 Thread Antoine Pitrou

Antoine Pitrou added the comment:

 Memoization consumes memory during pickling. For now every memoized
 object requires memory for:
 
 dict's entity;
 an id() integer object;
 a 2-element tuple;
 a pickle's index (an integer object).
 
 It's about 80 bytes on 32-bit platform (and twice as this on 64-bit).

As far as I understand, Alexandre doesn't propose to suppress
memoization, only to make it implicit. Therefore the memory overhead
would be the same (but the pickle would have less opcodes).

 For data which contains a lot of floats it can be cumbersome.

Apparently, floats don't get memoized:

 pickletools.dis(pickle.dumps([1.0, 2.0]))
0: \x80 PROTO  3
2: ]EMPTY_LIST
3: qBINPUT 0
5: (MARK
6: GBINFLOAT   1.0
   15: GBINFLOAT   2.0
   24: eAPPENDS(MARK at 5)
   25: .STOP

--

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



[issue17764] Support http.server passing bind address via commend line argument

2013-04-21 Thread Malte Swart

Malte Swart added the comment:

I have updated the patch and added a paragraph for this option to the 
documentation. 

Shall I add this issue to the changelog list for python 3.4.0 alpha 1?

--
Added file: http://bugs.python.org/file29969/http-server-bind-arg2.patch

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



[issue17795] backwards-incompatible change in SysLogHandler with unix domain sockets

2013-04-21 Thread Vinay Sajip

Changes by Vinay Sajip vinay_sa...@yahoo.co.uk:


Added file: http://bugs.python.org/file29970/cd970801b061.diff

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



[issue17795] backwards-incompatible change in SysLogHandler with unix domain sockets

2013-04-21 Thread Vinay Sajip

Vinay Sajip added the comment:

Okay, I made the change to default socktype=None. Please try out the latest 
patch (ideally on all Python versions you can test with) to confirm it's OK. 
Then I can apply to 2.7/3.2/3.3/default. Thanks.

--

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



[issue17348] Unicode - encoding seems to be lost for inputs of unicode chars

2013-04-21 Thread R. David Murray

R. David Murray added the comment:

I believe you have indeed understood what the original poster was reporting.

However, those lines date back a long time (2002 or earlier).  They exist in 
Python2 only, and there they have a purpose, so they can't just be deleted.

My guess is the problem is a conflict between the locale setting and the 
encoding used when the character string is input into IDLE.

For me, if I cut and paste that string into the idle shell in python2, it shows 
up as the unicode escape characters (meaning IDLE is doing the correct 
conversion at input time on my system).  In Python3 it looks the same, except 
that the echoed output shows the expected glyphs instead of the unicode escapes 
as it does in Python2, which is as expected.

My only locale setting, by the way, is LC_CTYPE=en_US.UTF-8.  What is your 
setting?

I don't know if there is a better way for idle to behave in the modern era or 
not.  Perhaps it should be using utf-8 by default instead of the locale?  Do 
you know how (and in what charset) your system is generating the characters you 
type into idle?

--
nosy: +r.david.murray

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



[issue17348] Unicode - encoding seems to be lost for inputs of unicode chars in IDLE

2013-04-21 Thread R. David Murray

Changes by R. David Murray rdmur...@bitdance.com:


--
title: Unicode - encoding seems to be lost for inputs of unicode chars - 
Unicode - encoding seems to be lost for inputs of unicode chars in IDLE

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



[issue17670] Improve str.expandtabs() doc

2013-04-21 Thread Roundup Robot

Roundup Robot added the comment:

New changeset 6a02d2af814f by Ned Deily in branch '2.7':
Issue #17670: Provide an example of expandtabs() usage.
http://hg.python.org/cpython/rev/6a02d2af814f

New changeset 5b6ccab52a4d by Ned Deily in branch '3.3':
Issue #17670: Provide an example of expandtabs() usage.
http://hg.python.org/cpython/rev/5b6ccab52a4d

New changeset 1a6cb6d8591a by Ned Deily in branch 'default':
Issue #17670: merge from 3.3
http://hg.python.org/cpython/rev/1a6cb6d8591a

--
nosy: +python-dev

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



[issue17670] Improve str.expandtabs() doc

2013-04-21 Thread Ned Deily

Changes by Ned Deily n...@acm.org:


--
resolution:  - fixed
stage: commit review - committed/rejected
status: open - closed
type: enhancement - 

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



[issue17764] Support http.server passing bind address via commend line argument

2013-04-21 Thread R. David Murray

R. David Murray added the comment:

Thanks for proposing this and working on it Malte.  Could you please submit a 
contributor agreement? (http://www.python.org/psf/contrib).

We will add the Misc/NEWS entry when we commit the patch; that file changes so 
rapidly that any patch to it quickly becomes outdated.  You could add an entry 
to Doc/whatsnew/3.4, though, if you were so moved.  If not we'll add that too 
when we commit.

For the doc patch, I think the first sentence would be clearer if it said By 
default the server binds to all available interfaces.  I'll probably tweak a 
couple other words for better English phrasing when I commit it, as well.

--
nosy: +r.david.murray

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



[issue17742] Add _PyBytesWriter API

2013-04-21 Thread Antoine Pitrou

Antoine Pitrou added the comment:

The last patch increases the size of the code substantially. I'm still 
wondering what the benefits are.

$ hg di --stat
 Include/bytesobject.h  |   90 ++
 Misc/NEWS  |3 +
 Objects/bytesobject.c  |  144 ++
 Objects/stringlib/codecs.h |  109 
 Objects/unicodeobject.c|  267 -
 5 files changed, 368 insertions(+), 245 deletions(-)

--

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



[issue17403] Robotparser fails to parse some robots.txt

2013-04-21 Thread R. David Murray

R. David Murray added the comment:

Lucaz pointed out on IRC that the problem is that the current robotparser is 
implementing an outdated robots.txt standard.  He may work on fixing that.

--

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



[issue17403] Robotparser fails to parse some robots.txt

2013-04-21 Thread R. David Murray

Changes by R. David Murray rdmur...@bitdance.com:


--
keywords:  -easy

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



[issue15575] Tutorial is unclear on multiple imports of a module.

2013-04-21 Thread Roundup Robot

Roundup Robot added the comment:

New changeset 9df9931fae96 by R David Murray in branch '3.3':
#15575: Clarify tutorial description of when modules are executed.
http://hg.python.org/cpython/rev/9df9931fae96

New changeset dac847938326 by R David Murray in branch 'default':
#15575: Clarify tutorial description of when modules are executed.
http://hg.python.org/cpython/rev/dac847938326

New changeset a1421d28393b by R David Murray in branch '2.7':
#15575: Clarify tutorial description of when modules are executed.
http://hg.python.org/cpython/rev/a1421d28393b

--
nosy: +python-dev

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



[issue15575] Tutorial is unclear on multiple imports of a module.

2013-04-21 Thread R. David Murray

R. David Murray added the comment:

Thanks, James.  I wound up going with a different wording for the 
elaboration: since the concept of running a python file as a script is 
mentioned just a bit earlier, I added a parenthetical that the statements are 
also executed if the module is run as a script.

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

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



[issue17811] Improve os.readv() and os.writev() documentation and docstring

2013-04-21 Thread Nikolaus Rath

New submission from Nikolaus Rath:

The os.writev and os.readv functions are currently documented as:

os.writev(fd, buffers)

Write the contents of buffers to file descriptor fd, where buffers is an 
arbitrary sequence of buffers. Returns the total number of bytes written.

os.readv(fd, buffers)

Read from a file descriptor into a number of writable buffers. buffers is 
an arbitrary sequence of writable buffers. Returns the total number of bytes 
read.


This is rather confusing, mostly because it's not clear what can be passed as 
*buffer* (since buffer objects don't exist in Python 3 anymore), and (as a 
consequence) how the input will be distributed among the list of buffers.

Reading the code, it seems to me that any object that implements the buffer 
protocol would be fine, but that still doesn't help much in practice. From the 
memoryview documentation, I can infer that `bytes` implements the buffer 
protocol, but is also immutable, so how can something be written into it?

I'd be happy to write a patch to the documentation, but someone would need to 
explain to me first what kind of buffers are actually acceptable (and I suspect 
this will be different for readv and writev).

--
assignee: docs@python
components: Documentation
messages: 187526
nosy: Nikratio, docs@python
priority: normal
severity: normal
status: open
title: Improve os.readv() and os.writev() documentation and docstring
type: enhancement
versions: Python 3.3, Python 3.4, Python 3.5

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



[issue17812] Quadratic complexity in b32encode

2013-04-21 Thread Serhiy Storchaka

New submission from Serhiy Storchaka:

b32encode accumulates encoded data in a bytes object and this operation has 
quadratic complexity.

Here is a patch, which fixes this issue by accumulating in a list.

--
components: Library (Lib)
files: base32_fix.patch
keywords: patch
messages: 187527
nosy: pitrou, serhiy.storchaka
priority: normal
severity: normal
stage: patch review
status: open
title: Quadratic complexity in b32encode
type: performance
versions: Python 3.3, Python 3.4
Added file: http://bugs.python.org/file29971/base32_fix.patch

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



[issue17811] Improve os.readv() and os.writev() documentation and docstring

2013-04-21 Thread Nikolaus Rath

Nikolaus Rath added the comment:

Here's a first attempt at improvement based on my guess:

os.writev(fd, buffers)

Write the contents of buffers to file descriptor fd, where buffers is an 
arbitrary sequence of buffers. In this context, a buffer may be any Python 
object that provides a Memory View, i.e. that may be used to instantiate a 
`memoryview` object (e.g. a bytes or bytearray object). writev writes the 
contents of each memory view to the file descriptor and returns the total 
number of bytes written.

os.readv(fd, buffers)

Read from a file descriptor into a number of writable buffers. buffers is 
an arbitrary sequence of writable buffers. In this context, a buffer may be any 
Python object that provides a writeable Memory View, i.e. that may be used to 
instantiate a `memoryview` object whose `read_only` attribute is false (for 
example, a bytearray object). Writeable memory views have a fixed size, and 
readv will transfer data into each buffer until it is full and then move on to 
the next buffer in the sequence to hold the rest of the data. readv returns the 
total number of bytes read (which may be less than the total capacity of all 
the buffers).

--

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



[issue17812] Quadratic complexity in b32encode

2013-04-21 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

And here are other patch, which not only fixes an issue with quadratic 
complexity, but optimize b32encode and b32decode about 2.5 times.

Microbenchmarks:

./python -m timeit -r 1 -n 10 -s from base64 import b32encode as encode; data 
= open('python', 'rb').read(101)  encode(data)
./python -m timeit -r 1 -n 1 -s from base64 import b32encode as encode, 
b32decode as decode; data = encode(open('python', 'rb').read(101))  
decode(data)

Results:
   First patch  Second patch
b32encode1.25 sec 486 msec
b32decode2.08 sec 835 msec

--

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



[issue17812] Quadratic complexity in b32encode

2013-04-21 Thread Serhiy Storchaka

Changes by Serhiy Storchaka storch...@gmail.com:


Added file: http://bugs.python.org/file29972/base32_optimize.patch

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



[issue17811] Improve os.readv() and os.writev() documentation and docstring

2013-04-21 Thread R. David Murray

R. David Murray added the comment:

Well, the documentation is technically precise.  I'd even managed to forget 
that buffer objects existed in Python2 :)

As you observed, in Python3 a buffer is something that implements the buffer 
protocol.  What I would do is link the word 'buffer' to 
http://docs.python.org/3/c-api/buffer.html.  Perhaps mentioning bytes and 
bytearray as examples of read-only and writeable buffers would be worthwhile, 
but they are mentioned in the first paragraph of that section so it may not be 
necessary.

--
nosy: +r.david.murray

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



[issue17811] Improve os.readv() and os.writev() documentation and docstring

2013-04-21 Thread Nikolaus Rath

Nikolaus Rath added the comment:

What section do you mean? bytearray is not mentioned anywhere in
http://docs.python.org/3.4/library/os.html.

I think the problem with just linking to the C API section is that it doesn't 
help people that are only using pure Python. You can't look at a Python object 
and tell whether it implements the buffer protocol or not. Therefore, I think 
it would be important to give at least a reference to memoryview as the Python 
equivalent of the buffer protocol.

--

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



[issue17813] lzma and bz2 decompress methods lack max_size attribute

2013-04-21 Thread Nikolaus Rath

New submission from Nikolaus Rath:

The zlib Decompress.decompress has a max_length parameter that limits the size 
of the returned uncompressed data.

The lzma and bz2 decompress methods do not have such a parameter.

Therefore, it is not possible to decompress untrusted lzma or bz2 data without 
becoming susceptible to a DoS attack, as the attacker can force allocation of 
gigantic buffers by sending just a tiny amount of compressed data:

$ dd if=/dev/zero bs=128k count=10k | bzip2 -9  nasty.bz2
10240+0 records in
10240+0 records out
1342177280 bytes (1.3 GB) copied, 11.0892 s, 121 MB/s
$ dir nasty.bz2 
-rw-rw-r-- 1 nikratio nikratio 977 Apr 21 14:58 nasty.bz2


It would be great if the lzma and bz2 decompressor methods could also get a 
max_length parameters to make this situation less threatening.

--
components: Library (Lib)
messages: 187532
nosy: Nikratio
priority: normal
severity: normal
status: open
title: lzma and bz2 decompress methods lack max_size attribute
type: behavior
versions: Python 3.3, Python 3.4, Python 3.5

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



  1   2   >