Re: can't get utf8 / unicode strings from embedded python

2013-08-24 Thread David M. Cotter
 I see you are using Python 2
correct

 Firstly, in Python 2, the compiler assumes that the source code is encoded in 
 ASCII
gar, i must have been looking at doc for v3, as i thought it was all assumed to 
be utf8

 # -*- coding: utf-8 -*- 
okay, did that, still no change

 you need to use u ...  delimiters for Unicode, otherwise the results you 
 get are completely arbitrary and depend on the encoding of your terminal. 
okay, well, i'm on a mac, and not using terminal at all.  but if i were, it 
would be utf8
but it's still not flying :(

 For example, if I set my terminal encoding to IBM-850
okay how do you even do that?  this is not an interactive session, this is 
embedded python, within a C++ app, so there's no terminal.  

but that is a good question: all the docs say default encoding everywhere (as 
in If string is a Unicode object, this function computes the default encoding 
of string and operates on that), but fail to specify just HOW i can set the 
default encoding.  if i could just say hey, default encoding is utf8, i think 
i'd be done?

 So change the line of code to: 
 print ufrøânçïé 
okay, sure... 
but i get the exact same results

 Those two changes ought to fix the problem, but if they don't, try setting 
 your terminal encoding to UTF-8 as well
well, i'm not sure what you mean by that.  i don't have a terminal here.
i'm logging to a utf8 log file (when i print)


 but what it *actually* prints is this: 
 
print frøânçïé 
 -- frøânçïé 

It's hard to say what *exactly* is happening here, because you don't explain 
how the python print statement somehow gets into your C++ Log code. Do I guess 
right that it catches stdout?
yes, i'm redirecting stdout to my own custom print class, and then from that 
function i call into my embedded C++ print function

If so, then what I expect is happening is that Python has read in the source 
code of 

print ~ 

with ~ as a bunch of junk bytes, and then your terminal is displaying 
those junk bytes according to whatever encoding it happens to be using. 
Since you are seeing this: 

frøânçïé 

my guess is that you're using a Mac, and the encoding is set to the MacRoman 
encoding. Am I close?
you hit the nail on the head there, i think.  using that as a hint, i took this 
text frøânçïé and pasted that into a macRoman document, then 
*reinterpreted* it as UTF8, and voala: frøânçïé

so, it seems that i AM getting my utf8 bytes, but i'm getting them converted to 
macRoman.  huh?  where is macRoman specified, and how to i change that to utf8? 
 i think that's the missing golden ticket
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: can't get utf8 / unicode strings from embedded python

2013-08-24 Thread Dave Angel
David M. Cotter wrote:
 Steven wrote:
 I see you are using Python 2
 correct

It's hard to say what *exactly* is happening here, because you don't explain 
how the python print statement somehow gets into your C++ Log code. Do I 
guess right that it catches stdout?
 yes, i'm redirecting stdout to my own custom print class, and then from that 
 function i call into my embedded C++ print function


I don't know much about embedding Python, but each file object has an
encoding property.

Why not examine   sys.stdout.encoding ?  And change it to UTF-8 ?

print encoding is, sys.stdout.encoding

sys.stdout.encoding = UTF-8

-- 
DaveA



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


Re: Exception Handling Practices / Patterns

2013-08-24 Thread Dave Angel
snarf wrote:

 Greetings,

 As I tread through my journey of OO I am trying to determine if there is a 
 good approach for exception handling within classes.

 From my readings and gatherings - it seems I have found a common theme, but I 
 am trying to solicit from the experts.

 Here is what I have found (I may be restating the obvious so please forgive 
 me in advance):

 * Seems like exception handing within Classes is largely avoided and is 
 typically only used when calling external libraries.
 * Try/Except type statements seem to be used more within modules, main 
 functions, wrapper scripts.

Exceptions are used when useful.  I don't see any bias towards any one
location.

 * Classes should be coded in a way that exceptions 

You seem to be missing the last part of this sentence.

 * Better to never write your own exceptions (unless you absolutely have to).

If you mean to avoid writing exception classes, then I say nonsense. 
Just derive them from the closest meaningful exception class, so that a
user can combine handlers when reasonable.

 * Using Exception is typically a bad. More specific the better.

If you mean in an except statement, then I'd agree.

 * Exceptions should never fail silently. (Should exceptions always be logged?)

Exceptions should be caught if you can handle them, or if you need to
convert them to a different exception that someone further up the stack
can handle.  Sometimes handling means do nothing.


 Best site I have found for exceptions (hopefully this helps someone):
 * http://c2.com/cgi/wiki?ExceptionPatterns

But that's for Java.  java is not C++, and neither is it Python.  For
one thing, Python exception overhead is deliberately much less, and they
are used more freely.

Notice that exceptions are used to terminate for loops, and that's a
*normal* exit to the loop.  They also appear in other places under the
covers.  Don't be afraid of them.

-- 
DaveA


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


Re: Fast conversion of numbers to numerator/denominator pairs

2013-08-24 Thread Ian Kelly
On Fri, Aug 23, 2013 at 9:30 PM, Steven D'Aprano
steve+comp.lang.pyt...@pearwood.info wrote:
 Is there a fast way to convert a Decimal into a pair of numbers numerator/
 denominator? It *must* be exact, but it doesn't have to be simplest form.
 For example, Decimal(0.5) = (5, 10) would be okay, although (1, 2)
 would be preferred.


 I've tried this function:

 def convert(d):
 sign, digits, exp = d.as_tuple()
 num = int(''.join([str(digit) for digit in digits]))
 if sign: num = -num
 return num, 10**-exp


 which is faster, but not fast enough. Any suggestions?

I time this function at about 33% faster than your version for a
six-digit decimal, and almost 50% faster for a 12-digit decimal.  My
guess would be because it's not calling str() on every individual
digit.

def convert(d):
exp = d.as_tuple().exponent
num = int(d.scaleb(-exp))
return num, 10**-exp
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Fast conversion of numbers to numerator/denominator pairs

2013-08-24 Thread Ian Kelly
On Sat, Aug 24, 2013 at 1:37 AM, Ian Kelly ian.g.ke...@gmail.com wrote:

 I time this function at about 33% faster than your version for a
 six-digit decimal, and almost 50% faster for a 12-digit decimal.  My
 guess would be because it's not calling str() on every individual
 digit.

 def convert(d):
 exp = d.as_tuple().exponent
 num = int(d.scaleb(-exp))
 return num, 10**-exp

Although, you would need to be careful with handling the decimal
context for the scaleb operation to make sure the result is exact.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Running a command line program and reading the result as it runs

2013-08-24 Thread Ian Simcock

Peter Otten wrote:

Ian Simcock wrote:


Greetings all.

I'm using Python 2.7 under Windows and am trying to run a command line
program and process the programs output as it is running. A number of
web searches have indicated that the following code would work.

import subprocess

p = subprocess.Popen(D:\Python\Python27\Scripts\pip.exe list -o,
   stdout=subprocess.PIPE,
   stderr=subprocess.STDOUT,
   bufsize=1,
   universal_newlines=True,
   shell=False)
for line in p.stdout:
  print line

When I use this code I can see that the Popen works, any code between
the Popen and the for will run straight away, but as soon as it gets to
the for and tries to read p.stdout the code blocks until the command
line program completes, then all of the lines are returned.

Does anyone know how to get the results of the program without it
blocking?


The following works on my linux system:

import subprocess

p = subprocess.Popen(
 [ping, google.com],
 stdout=subprocess.PIPE)

instream = iter(p.stdout.readline, )

for line in instream:
 print line.rstrip()

I don't have Windows available to test, but if it works there, too, the
problem is the internal buffer used by Python's implementation of file
iteration rather than the OS.



Hmm... and so it comes full circle.

I thought that the inclusion of the iter call looked familiar so I 
checked my original code and found that it was there. I removed it when 
shrinking the code down to a minimal example for posting. Then, after 
removing it, which triggered the blocking, I changed the command to ping 
so that it's easier for anyone to test.


I've tried a copy of my original code using the ping command and it 
works fine.


So it looks like the python package manager pip must see that it's not 
going to a console and buffer the output, and my original code was not 
the problem.


So I can't do what I want, but it's interesting to know that for some 
reason the iter is required for the occasions when it can work.


Thanks to everyone who helped with this.

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


Re: Exception Handling Practices / Patterns

2013-08-24 Thread Steven D'Aprano
On Fri, 23 Aug 2013 22:25:55 -0700, snarf wrote:

[...]
 * Seems like exception handing within Classes is largely avoided and is
 typically only used when calling external libraries. 

There is certainly no rule avoid exceptions inside classes. Methods 
often raise exceptions to signal an error, e.g.:

My string.index(spam)


Less common, methods can raise exceptions as part of their flow control. 
The most obvious example is StopIteration, used by iterators and often by 
__iter__ or next methods.


 * Try/Except type
 statements seem to be used more within modules, main functions, wrapper
 scripts. 

It depends on whose code you are reading. I don't write a lot of classes, 
but when I do, I often use try...except inside them.

If try...except gets used more frequently in module's top level, it is 
because the sort of things that you do at the top level often needs 
exception handling. For example, you might have a fallback module:

try:
import this_module
except ImportError:
import that_module as this_module


You will very rarely see that inside a class, since you very rarely 
import modules inside a class.


 * Classes should be coded in a way that exceptions 

I think you forgot to finish the sentence.


 * Better to
 never write your own exceptions (unless you absolutely have to). 

That depends.

On the one hand, nobody wants a million different exception types. On the 
other hand, nobody wants just *one* exception type, and no way to 
distinguish between different kinds of errors. Somewhere between one and 
one million is an appropriate number of exception types.

The right answer is to be conservative about creating new exceptions, but 
don't be scared to create one when you need one.

But when you do, it is often better to subclass from an appropriate built-
in exception like ValueError or TypeError or similar, than to subclass 
from Exception itself.


 * Using
 Exception is typically a bad. More specific the better.

Yes, you should always try to catch the specific exceptions you care 
about:


# Best
except ValueError, OverflowError, ZeroDivisionError:


# Not so good
except Exception:


# Worst
except:


Don't use the last one, except maybe in the interactive interpreter, 
since it will catch *everything*, even exceptions that probably shouldn't 
be caught like KeyboardInterrupt.


 * Exceptions
 should never fail silently. (Should exceptions always be logged?)

Certainly not. Exceptions should fail silently if you don't care about 
them. For example, when connecting to a website, there are many temporary 
errors that can occur. The best way to handle them is to catch the 
exception, sleep for a little while, then try again. You need only care 
if repeated attempts to connect, with larger and larger sleeps, continue 
to fail.

Of course, you might have a debug mode that logs all of these, but if 
your web browser logged every single time a webpage was slow to respond, 
you would soon run out of disk space :-)

*Errors* should never fail silently, unless explicitly silenced. But an 
error isn't an error if you don't care about it, and an exception is not 
necessarily an error.

This is an error, because converting a number to uppercase cannot 
possibly mean anything:

mystring = 42
mystring.upper()


This is not necessarily an error, since the list is empty could be a 
legitimate situation:

mylist = []
first = mylist[0]

In this case, it may be appropriate to catch the exception, and either 
silently swallow it, or do something else.


 Best site I have found for exceptions (hopefully this helps someone): *
 http://c2.com/cgi/wiki?ExceptionPatterns

I haven't read that page for a long time, but as I recall the c2.com 
website, a lot of the ideas there are better suited to Java and C/C++ 
(and occasionally Lisp) rather than Python. But still, a valuable (if 
often confusing) resource.



 I'd be interested in hearing others thoughts on this topic with regards
 to best practices for when to use exceptions, and when to avoid using
 exceptions.

The try part of a try...except is *very* fast to set up. It's about as 
fast as a pass (do nothing), so it has little overhead.

On the other hand, actually *catching* an exception is quite heavy. So 
code that catches lots and lots of exceptions may be slow. In that case, 
it may be faster to look before you leap and test ahead of time:

# this is faster if most lists are not empty
try:
process(mylist[0])
except IndexError:
handle_empty_list()

# this is faster if many lists are empty
if mylist:
process(mylist[0])
else:
handle_empty_list()


Only profiling your data can tell you which you should use.


On the other hand, here you should *always* use try...except:

try:
myfile = open(name)
except IOError:
handle_error()


Because this code is wrong:

if os.path.exists(name):
myfile = open(name)
else:
handle_error()


It's wrong for a couple of reasons:

- just because the file exists, doesn't mean you can open it;


Help regarding urllib

2013-08-24 Thread malhar vora
Hello All,


I am simply fetching data from robots.txt of a url. Below is my code.

siteurl = siteurl.rstrip(/)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Help regarding urllib

2013-08-24 Thread malhar vora
On Saturday, August 24, 2013 4:15:01 PM UTC+5:30, malhar vora wrote:
 Hello All,
 
 
 
 
 
 I am simply fetching data from robots.txt of a url. Below is my code.
 
 
 
 siteurl = siteurl.rstrip(/)

Sorry for last complete. It was sent by mistake.

Here is my code.

siteurl = siteurl.rstrip(/)
roboturl = siteurl + r'/robots.txt'
robotdata = urllib.urlopen(roboturl).read() # Reading robots.txt of given url
print robotdata

In above code siteurl is fetched simply from local text file.


Whenever I run above code. In place of / before robots.txt, it writes \\ in 
url as I found in error. The error is given below.

This is main function
Main URL : www.bestrecipes.com.au
$$:www.bestrecipes.com.au
###--www.bestrecipes.com.au/robots.txt
Traceback (most recent call last):
  File dataintegrator.py, line 104, in module
main()
  File dataintegrator.py, line 81, in main
print Sitemap Url :  + getSiteMapUrl(i)
  File D:\Malhar Data\Projects\Data Parsing\My Code\Final Part\libs\datareader.
py, line 50, in getSiteMapUrl
robotdata = urllib.urlopen(roboturl).read() # Reading robots.txt of given ur
l
  File C:\Python26\lib\urllib.py, line 87, in urlopen
return opener.open(url)
  File C:\Python26\lib\urllib.py, line 203, in open
return getattr(self, name)(url)
  File C:\Python26\lib\urllib.py, line 461, in open_file
return self.open_local_file(url)
  File C:\Python26\lib\urllib.py, line 475, in open_local_file
raise IOError(e.errno, e.strerror, e.filename)
IOError: [Errno 2] The system cannot find the path specified: 'www.bestrecipes.c
om.au\\robots.txt'

I am new to Python and not able to figure out this problem. Please help me.

Thank you,

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


Re: Python variable as a string

2013-08-24 Thread Jake Angulo
Thank you all for the reply.

Actually yes this was a confusing question, and borne out of trying to make
a shortcut.
I didnt ask to convert the contents of var into a string.
All I needed was to get the literal equivalent var because I needed to
use it in another dict object - whose keys i named the same (eg 'var') for
convenience.  Instead i ended up complicating stuff.

I resolved this by doing things differently with (if - elif - else).

Sorry for the confusion - but thanks all for answering - i can use a code
or two of what you have shared!



On Fri, Aug 23, 2013 at 11:23 PM, Neil Cerutti ne...@norwich.edu wrote:

 On 2013-08-23, Jake Angulo jake.ang...@gmail.com wrote:
  I have a list *var* which after some evaluation I need to refer
  to *var* as a string.

 You must make a str version of var.

  Pseudocode:
 
  var = ['a', 'b' , 'c' , 'd']
  adict = dict(var='string', anothervar='anotherstring')
  anotherdict = dict()
  if condition:
  anotherdict[akey] = adict['var']

 anotherdict[akey] = adict[str(var)]

 Will actually work, though you might prefer:

 anotherdict[akey] = adict[''.join(var)]

 Try them out and see.

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

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


Re: How to send broadcast IP address to network?

2013-08-24 Thread Irmen de Jong
On 23-8-2013 14:32, lightai...@gmail.com wrote:
 I want to send a broadcast packet to all the computers connected to my home 
 router. 
 
 The following 2 lines of code do not work;
 host=192.168.0.102
 s.connect((host, port))
 
 Can someone advise?
 
 Thank you.
 

Use UDP (datagram) sockets. Use sendto() and not connect(), because UDP is
connectionless. This should work:

import socket
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
sock.sendto(bthedata, 0, (broadcast, ))#  = port
sock.close()


Irmen

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


Re: Fast conversion of numbers to numerator/denominator pairs

2013-08-24 Thread Peter Otten
Steven D'Aprano wrote:

 I have a need to convert arbitrary non-complex numbers into numerator/
 denominator pairs. Numbers could be ints, floats, Fractions or Decimals.
 For example:
 
 2 = (2, 1)
 0.25 = (1, 4)
 Fraction(2, 3) = (2, 3)
 Decimal(0.5) = (1, 2)
 
 
 The first three cases are easy and fast:
 
 # ints and Fractions
 number.numerator, number.denominator
 
 # floats are a little slower
 number.as_integer_ratio()
 
 
 But Decimals are unfortunately slower. MUCH slower, about 40 times slower
 than Fractions in Python 3.3:
 
 tmp = Fraction.from_decimal(number)
 (tmp.numerator, tmp.denominator)
 
 
 This ends up being the bottleneck in my code: once you include the
 scaffolding code to select the right conversion method, processing a
 large list of Decimals is about fifty times slower than large lists of
 floats or fractions.
 
 Is there a fast way to convert a Decimal into a pair of numbers numerator/
 denominator? It *must* be exact, but it doesn't have to be simplest form.
 For example, Decimal(0.5) = (5, 10) would be okay, although (1, 2)
 would be preferred.
 
 
 I've tried this function:
 
 def convert(d):
 sign, digits, exp = d.as_tuple()
 num = int(''.join([str(digit) for digit in digits]))
 if sign: num = -num
 return num, 10**-exp
 
 
 which is faster, but not fast enough. Any suggestions?

Maybe these micro-optimisations will be sufficient:

_trans = bytes.maketrans(bytes(range(10)), b0123456789)

def convert(d):
sign, digits, exp = d.as_tuple()
num = int(bytes(digits).translate(_trans))

if sign:
num = -num
return num, 10**-exp

You can get the simplest form with co-prime numerator and denominator by 
dividing by fractions.gcd(), but that will of course slow down things.

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


Re: Help regarding urllib

2013-08-24 Thread Dave Angel
malhar vora wrote:

 On Saturday, August 24, 2013 4:15:01 PM UTC+5:30, malhar vora wrote:
 Hello All,
 
 
 
 
 
 I am simply fetching data from robots.txt of a url. Below is my code.
 
 
 
 siteurl = siteurl.rstrip(/)

 Sorry for last complete. It was sent by mistake.

 Here is my code.

 siteurl = siteurl.rstrip(/)
 roboturl = siteurl + r'/robots.txt'
 robotdata = urllib.urlopen(roboturl).read() # Reading robots.txt of given url
 print robotdata

 In above code siteurl is fetched simply from local text file.

Why aren't you showing us what is in that local text file?   Or more
specifically what siteurl turns out to be?  I suspect it's missing the
http://  prefix

snip
 IOError: [Errno 2] The system cannot find the path specified: 
 'www.bestrecipes.c
 om.au\\robots.txt'


Looks to me like it decided this url referred to a file.  That's the
default behavior when you don't specify the scheme identifier (eg. 
'http)

Also it might well have been necessary to specify what Python version
and OS you're running this on.  For example, the single backslash
character is specific to Windows.  (The doubling presumably is an
artifact of how the error message is displayed, eg. look at how repr()
displays strings)


-- 
DaveA


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


Re: can't get utf8 / unicode strings from embedded python

2013-08-24 Thread random832
On Sat, Aug 24, 2013, at 2:45, David M. Cotter wrote:
  you need to use u ...  delimiters for Unicode, otherwise the results you 
  get are completely arbitrary and depend on the encoding of your terminal. 
 okay, well, i'm on a mac, and not using terminal at all.  but if i
 were, it would be utf8
 but it's still not flying :(

 so, it seems that i AM getting my utf8 bytes, but i'm getting them
 converted to macRoman.  huh?  where is macRoman specified, and how to i
 change that to utf8?  i think that's the missing golden ticket

You say you're not using terminal. What _are_ you using?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python interface to iMacros

2013-08-24 Thread Michael Torrie
On 08/23/2013 09:13 AM, inq1ltd wrote:
 Python help,
 
 I am running iMacros from linux/firefox 
 and doing most of what I want.
 
 But, there are times when I want to do 
 something of the net and then back 
 to the iMacros script.   
 
 Are there any projects out there
 that will connect python to imacros,
 something on the order of pexpect?

I have no idea really, but you can drive Firefox using a thing called
selenium.  http://docs.seleniumhq.org/

There is a python library for interfacing with selenium, and from that
you can drive firefox from python.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Exception Handling Practices / Patterns

2013-08-24 Thread MRAB

On 24/08/2013 11:27, Steven D'Aprano wrote:

On Fri, 23 Aug 2013 22:25:55 -0700, snarf wrote:

[snip]

* Using
Exception is typically a bad. More specific the better.


Yes, you should always try to catch the specific exceptions you care
about:


# Best
except ValueError, OverflowError, ZeroDivisionError:


That should be:

except (ValueError, OverflowError, ZeroDivisionError):



# Not so good
except Exception:


# Worst
except:


[snip]

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


Re: can't get utf8 / unicode strings from embedded python

2013-08-24 Thread David M. Cotter
 What _are_ you using? 
i have scripts in a file, that i am invoking into my embedded python within a 
C++ program.  there is no terminal involved.  the print statement has been 
redirected (via sys.stdout) to my custom print class, which does not specify 
encoding, so i tried the suggestion above to set it:

static const char *s_RedirectScript = 
import  kEmbeddedModuleName \n
import sys\n
\n
class CustomPrintClass:\n
   def write(self, stuff):\n
kEmbeddedModuleName . kCustomPrint (stuff)\n
class CustomErrClass:\n
   def write(self, stuff):\n
kEmbeddedModuleName . kCustomErr (stuff)\n
sys.stdout = CustomPrintClass()\n
sys.stderr = CustomErrClass()\n
sys.stdout.encoding = 'UTF-8'\n
sys.stderr.encoding = 'UTF-8'\n;


but it didn't help.

I'm still getting back a string that is a utf-8 string of characters that, if 
converted to macRoman and then interpreted as UTF8, shows the original, 
correct string.  who is specifying macRoman, and where, and how do i tell 
whoever that is that i really *really* want utf8?
-- 
http://mail.python.org/mailman/listinfo/python-list


how to read mixed from multiple csv file

2013-08-24 Thread Jia Hu
Hi,

My 20 csv files has string header,  and first two columns are string (e.g.,
1999-01-02,  01:00:00) among the 50 columns. Other columns store numerical
values (int, or float)

I need to do data analysis for these data. For example, extract the each
month data from each of the  cvs files (each csv file stores 1 year data)
and there are 20 year data.

in addition, I want to store the data in disk so that I can retrieve data
quickly, just like save and load in Matlab.

Currently, I use structured array

data = []
i = 0
for s in range(1991, 2011):
fileName = folder +_{_sY}0101_{_sY}1231_725300.csv.format(_sY=s)
data.append(np.genfromtxt(fileName, delimiter=,, dtype=None,
names=True))
i += 1

np.save(alldata, data)



However, when I load data np.load(alldata.npy), it is becomes 0-d array
which is different from original one.


My question is that

(1) How to store or save the data?
(2) as you can see, I use list to store all the 20 ndarrays, I do not feel
it is a good way.  Is there any suggestion for the data structure I should
use?

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


Re: can't get utf8 / unicode strings from embedded python

2013-08-24 Thread wxjmfauth
Le samedi 24 août 2013 18:47:19 UTC+2, David M. Cotter a écrit :
  What _are_ you using? 
 
 i have scripts in a file, that i am invoking into my embedded python within a 
 C++ program.  there is no terminal involved.  the print statement has been 
 redirected (via sys.stdout) to my custom print class, which does not specify 
 encoding, so i tried the suggestion above to set it:
 
 
 
 static const char *s_RedirectScript = 
 
   import  kEmbeddedModuleName \n
 
   import sys\n
 
   \n
 
   class CustomPrintClass:\n
 
  def write(self, stuff):\n
 
   kEmbeddedModuleName . kCustomPrint (stuff)\n
 
   class CustomErrClass:\n
 
  def write(self, stuff):\n
 
   kEmbeddedModuleName . kCustomErr (stuff)\n
 
   sys.stdout = CustomPrintClass()\n
 
   sys.stderr = CustomErrClass()\n
 
   sys.stdout.encoding = 'UTF-8'\n
 
   sys.stderr.encoding = 'UTF-8'\n;
 
 
 
 
 
 but it didn't help.
 
 
 
 I'm still getting back a string that is a utf-8 string of characters that, if 
 converted to macRoman and then interpreted as UTF8, shows the original, 
 correct string.  who is specifying macRoman, and where, and how do i tell 
 whoever that is that i really *really* want utf8?



Always encode a unicode into the coding of the system
which will host it.

Adapting the hosting system to your unicode (encoded
unicode) is not a valid solution. A non sense.

sys.std***.encodings do nothing. They only give you
information about the coding of the hosting system.

The system can be anything, a db, a terminal, a gui, ...

Shortly, your writer should encode your stuff
to your host in a adequate way. It is up to you to
manage coherence. If your passive writer support only one
coding, adapt stuff, if stuff lives in its own coding
(due to c++ ?) adapt your writer.



Example from my interactive interpreter. It is in Python 3,
not important, basically the job is the same in Python 2.
This interpreter has the capability to support many codings,
and the coding of this host system can be changed on the
fly.

A commented session.

By default, a string, type str, is a unicode. The
host accepts unicode. So, by default the sys.stdout
coding is 'unicode'. 

 sys.stdout.encoding = 'unicode'
 print(frøânçïé)
frøânçïé
 

Setting the host to utf-8 and printing the above string gives
something, but encoding into utf-8 works fine.

 sys.stdout.encoding = 'utf-8'
 sys.stdout.encoding
'utf-8'
 print(frøânçïé)
frøânçïé
 print(frøânçïé.encode('utf-8'))
'frøânçïé'

Setting the host to 'mac-roman' works fine too,
as long it is properly encoded!

 sys.stdout.encoding = 'mac-roman'
 print(frøânçïé.encode('mac-roman'))
'frøânçïé'

But

 print(frøânçïé.encode('utf-8'))
'frøânçïé'

Ditto for cp850

 sys.stdout.encoding = 'cp850'
 print(frøânçïé.encode('cp850'))
'frøânçïé'

If the repertoire of characters of a coding scheme does not
contain the characters - replace

 sys.stdout.encoding = 'cp437'
 print(frøânçïé.encode('cp437'))
Traceback (most recent call last):
  File eta last command, line 1, in module
  File c:\python32\lib\encodings\cp437.py, line 12, in encode
return codecs.charmap_encode(input,errors,encoding_map)
UnicodeEncodeError: 'charmap' codec can't encode character '\xf8' in position 
2: character maps to
undefined
 print(frøânçïé.encode('cp437', 'replace'))
'fr?ânçïé'


Curiousities

 sys.stdout.encoding = 'utf-16-be'
 print(frøânçïé)
 f r ø â n ç ï é 
 print(frøânçïé.encode('utf-16-be'))
'frøânçïé' 
 sys.stdout.encoding = 'utf-32-be'
 print(frøânçïé.encode('utf-32-be'))
'frøânçïé'


jmf


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


Re: python interface to iMacros

2013-08-24 Thread inq1ltd

 On 08/23/2013 09:13 AM, inq1ltd wrote:
  Python help,
  
  I am running iMacros from
  linux/firefox and doing most of
  what I want.
  
  But, there are times when I want to
  do something of the net and then
  back to the iMacros script.
  
  Are there any projects out there
  that will connect python to imacros,
  something on the order of pexpect?
 
 I have no idea really, but you can
 drive Firefox using a thing called
 selenium. 
 http://docs.seleniumhq.org/
 
 There is a python library for
 interfacing with selenium, and from
 that you can drive firefox from
 python.

I've looked at the site.  Sounds like something I'll try.  Thanks for the reply.

jimonlinux








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


Re: can't get utf8 / unicode strings from embedded python

2013-08-24 Thread Benjamin Kaplan
On Sat, Aug 24, 2013 at 9:47 AM, David M. Cotter m...@davecotter.com wrote:

  What _are_ you using?
 i have scripts in a file, that i am invoking into my embedded python within a 
 C++ program.  there is no terminal involved.  the print statement has been 
 redirected (via sys.stdout) to my custom print class, which does not specify 
 encoding, so i tried the suggestion above to set it:

 static const char *s_RedirectScript =
 import  kEmbeddedModuleName \n
 import sys\n
 \n
 class CustomPrintClass:\n
def write(self, stuff):\n
 kEmbeddedModuleName . kCustomPrint (stuff)\n
 class CustomErrClass:\n
def write(self, stuff):\n
 kEmbeddedModuleName . kCustomErr (stuff)\n
 sys.stdout = CustomPrintClass()\n
 sys.stderr = CustomErrClass()\n
 sys.stdout.encoding = 'UTF-8'\n
 sys.stderr.encoding = 'UTF-8'\n;


 but it didn't help.

 I'm still getting back a string that is a utf-8 string of characters that, if 
 converted to macRoman and then interpreted as UTF8, shows the original, 
 correct string.  who is specifying macRoman, and where, and how do i tell 
 whoever that is that i really *really* want utf8?
 --

If you're running this from a C++ program, then you aren't getting
back characters. You're getting back bytes. If you treat them as
UTF-8, they'll work properly. The only thing wrong is the text editor
you're using to open the file afterwards- since you aren't specifying
an encoding, it's assuming MacRoman. You can try putting the UTF-8 BOM
(it's not really a BOM) at the front of the file- the bytes 0xEF 0xBB
0xBF are used by some editors to identify a file as UTF-8.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Exception Handling Practices / Patterns

2013-08-24 Thread Terry Reedy

On 8/24/2013 6:27 AM, Steven D'Aprano wrote:

On Fri, 23 Aug 2013 22:25:55 -0700, snarf wrote:

[...]

* Seems like exception handing within Classes is largely avoided and is
typically only used when calling external libraries.


There is certainly no rule avoid exceptions inside classes. Methods
often raise exceptions to signal an error, e.g.:

My string.index(spam)


The rule only makes sense if it referring to try: except: in top-level 
class code, outside of def statements. Even then, it is wrong.


...

# Worst
except:

Don't use the last one, except maybe in the interactive interpreter,


Stick with never. except: means the same thing as except 
BaseException:, except that the latter indicates a deliberate choice 
rather than an indication of carelessness or laziness.


A bare except: is a disservice to the next maintainer of the code.


since it will catch *everything*, even exceptions that probably shouldn't
be caught like KeyboardInterrupt.


In Idle, when you type 'expression(' and hesitate, Idle tries to 
evaluate 'expression' to a function, behind the scenes, in order to 
provide a calltip with the function signature. Any error in 
'eval(expression)' should be caught and ignored so the user can continue 
typing.


This is one place where the original authors were too specific. They 
only caught NameError and AttributeError, when those were not the only 
possible eval errors in practice. The result was that people would 
occasionally type '(' and see idle quit.


idlelib .py files have about 20 bare 'except:'s, which I will try to 
fill out when I have reviewed the try part and understand what should be 
caught. It would be easier for me to read the code if the original 
authors had added their best guess as to what should be expected and caught.


--
Terry Jan Reedy

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


Re: Using PyQT with QT Designer

2013-08-24 Thread tausciam
Thanks. I probably will do exactly like you suggested later on. But, those two 
lines have solved the problem I had and I can work on the actual program now. I 
can come back to the GUI later.

Here is what it looks like now: http://i.imgur.com/sLiSU6M.png

On Friday, August 23, 2013 7:35:53 PM UTC-5, Lee Harr wrote:
  That's the problem though. It is exactly how I want it in designer. It's
  perfect as it is in designer when I preview it. Here is a screenshot of the
  preview: http://i.imgur.com/ULRolq8.png
 
 That's not a preview. That's just the regular design view.
 (you can tell by the little dots in the background)
 
 You need to go to Form - Preview... to see the actual preview.
 
 That said...
 
 1.) You may want to ask your question on the PyQt mailing list. Though
 you are talking with the undisputed PyQt expert in Phil, there are more
 people on the other list who are familiar with PyQt and who may be willing
 to look more closely at your specific code.
 
 2.) It may be that the examples you are looking at are not sufficient to
 help you with the situation you are in. For instance, I've written several
 programs using Designer and PyQt and I would recommend against
 using the pyuic method.
 
 When I first started with PyQt I also used pyuic and eventually I found
 the PyQt4.uic method works better for me.
 
 3.) Layouts. You have to use them with Qt or you're going to have a
 bad time.
 
 Looking at your design, I would do something like ...
 
 - select the two buttons on the left and click Lay Out Vertically
 - select the two large white boxes and click Lay Out Vertically
 - put a vertical spacer underneath the red X button
 - select the red button and the spacer and click Lay Out Vertically
 - at this point you may need to resize and rearrange your three vertical
    layouts so that they don't overlap and are in approximately the positions
    that you want, then
 - select the main window and click Lay Out Horizontally
 
 Something along those lines would get you about to where you want
 to be. The form may not look _exactly_ the way you have it there, but
 it will be a more flexible design and nothing will be overlapping.

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


Help in Nltk

2013-08-24 Thread projectfack

Can anyone help me for the tasks below in nltk 


1. The  system  mustdemonstrate false   positiveand false   
negativeexamples
using   any stemmer (Task 1.1)
2. The  system  mustdemonstrate the differences between 
successive  layers  of  
the Porter  stemmer through a   couple  of  examples.   (Task   
1.2).
3. The  system  mustbe  ableto  automatically   detect  whether 
a   textis  in  French  
or  English and stemit  in  the detected
language.   The stemmer for French  
willonlybe  removingplurals.(Tasks  2   
and 3).
4. The  system  mustdemonstrate the use of  the Brill   
Tagger  (Task   4.2).   
5. The  system  mustdemonstrate the use of  POS tags
for information
extraction  to  extract all types   of  fishand all 
types   of  trees   mentioned   on  the 
Wikipedia   pages   for Fishand Tree (Task  6)
6. The  system  mustdemonstrate the use of  WordNet to  
expand  nouns   with
their   synonymsand their   hypernyms   (Task   9)
-- 
http://mail.python.org/mailman/listinfo/python-list


New way of writing socket servers in #Linux kernel 3.9 (and in #Python too)

2013-08-24 Thread vasudevram

This may be of interest to readers of this newsgroup:

Original article:
 
http://lnkd.in/taAFNt

Content (without links):

A new way of writing socket servers has been introduced with the Linux kernel 
3.9.

It involves the ability to bind multiple listening sockets to the same port on 
the same host, by unrelated processes or threads. The socket option is called 
SO_REUSEPORT.

Article about SO_REUSEPORT.

The above article includes a demo of how to use the feature in Python, using 
the example of a simple echo server and netcat.

Another article about SO_REUSEPORT on LWN.net by Michael Kerrisk.

Hacker News thread about SO_REUSEPORT.

About Michael Kerrisk. He has worked at DEC (Digital Equipment Corporation) and 
Google in the past.

Coincidentally, I happened to have come across Michael Kerrisk's Unix and Linux 
work some months earlier and had emailed him with a few questions about it, 
which he was kind enough to answer.

Kerrisk is the author of the book The Linux Programming Interface, which seems 
like an interesting and useful book.



From the web site for the The Linux Programming Interface book:

[ The Linux Programming Interface (published in October 2010, No Starch Press, 
ISBN 978-1-59327-220-3) is a detailed guide and reference for Linux and UNIX 
system programming.

With 1552 pages, 115 diagrams, 88 tables, nearly 200 example programs, and over 
200 exercises, TLPI is the most comprehensive description of Linux and UNIX 
system programming available. The author, Michael Kerrisk, is the maintainer of 
the Linux man-pages project, which documents the Linux kernel and glibc APIs. 
He has long been active in the documentation, testing, and design review of 
Linux kernel-userspace interfaces. ]

And if you want to write command-line programs in Linux using C (an area 
closely related to the topic of the TLPI book), you may wish to check out my 
article on the subject, written for IBM developerWorks:

Developing a Linux command-line utility.

I have not yet tried out the SO_REUSEPORT option, because I need to get Linux 
kernel 3.9 first, but it seems like a useful technique for increasing 
performance of socket servers. Note that there are various other issues 
involved, so you may not get increased performance just by using this option in 
your code. As always with performance tuning, you have to profile your code, 
identify hotspots, and then only work on improving certain parts of it that 
seem to be the bottlenecks. And in this case, even before all that, you may 
need to evaluate whether this socket option is relevant to your application at 
all. So, caveat lector :-)


- Vasudev Ram - Dancing Bison Enterprises
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Fast conversion of numbers to numerator/denominator pairs

2013-08-24 Thread Tim Delaney
On 24 August 2013 13:30, Steven D'Aprano 
steve+comp.lang.pyt...@pearwood.info wrote:


 def convert(d):
 sign, digits, exp = d.as_tuple()
 num = int(''.join([str(digit) for digit in digits]))
 if sign: num = -num
 return num, 10**-exp

 which is faster, but not fast enough. Any suggestions?


Straightforward multiply and add takes about 60% of the time for a single
digit on my machine compared to the above, and 55% for 19 digits (so
reasonably consistent). It's about 10x slower than fractions.

def convert_muladd(d, _trans=_trans, bytes=bytes):
sign, digits, exp = d.as_tuple()
num = 0

for digit in digits:
num *= 10
num += digit

if sign:
num = -num

return num, 10**-exp

Breakdown of the above (for 19 digits):

d.as_tuple() takes about 35% of the time.

The multiply and add takes about 55% of the time.

The exponentiation takes about 10% of the time.

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


Re: Fast conversion of numbers to numerator/denominator pairs

2013-08-24 Thread Tim Delaney
On 25 August 2013 07:59, Tim Delaney timothy.c.dela...@gmail.com wrote:

 Breakdown of the above (for 19 digits):

 d.as_tuple() takes about 35% of the time.

 The multiply and add takes about 55% of the time.

 The exponentiation takes about 10% of the time.


Bah - sent before complete.

Since the multiply and add takes such a significant proportion of the time,
compiling the above with Cython should gain you a big win as well. Or find
some other way to turn that loop into native code.

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


Re: Exception Handling Practices / Patterns

2013-08-24 Thread Steven D'Aprano
On Sat, 24 Aug 2013 15:57:55 -0400, Terry Reedy wrote:

 # Worst
 except:

 Don't use the last one, except maybe in the interactive interpreter,
 
 Stick with never. except: means the same thing as except
 BaseException:, except that the latter indicates a deliberate choice
 rather than an indication of carelessness or laziness.
 
 A bare except: is a disservice to the next maintainer of the code.

Do you know anyone who maintains code typed in the interactive 
interpreter?

:-)



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


Re: Exception Handling Practices / Patterns

2013-08-24 Thread frank . ruiz
Hi Steven,

Yea this is great. Thanks for the feedback.

On Saturday, August 24, 2013 3:27:45 AM UTC-7, Steven D'Aprano wrote:
 On Fri, 23 Aug 2013 22:25:55 -0700, snarf wrote:
 
 
 
 [...]
 
  * Seems like exception handing within Classes is largely avoided and is
 
  typically only used when calling external libraries. 
 
 
 
 There is certainly no rule avoid exceptions inside classes. Methods 
 
 often raise exceptions to signal an error, e.g.:
 
 
 
 My string.index(spam)
 
 
 
 
 
 Less common, methods can raise exceptions as part of their flow control. 
 
 The most obvious example is StopIteration, used by iterators and often by 
 
 __iter__ or next methods.
 
 
 
 
 
  * Try/Except type
 
  statements seem to be used more within modules, main functions, wrapper
 
  scripts. 
 
 
 
 It depends on whose code you are reading. I don't write a lot of classes, 
 
 but when I do, I often use try...except inside them.
 
 
 
 If try...except gets used more frequently in module's top level, it is 
 
 because the sort of things that you do at the top level often needs 
 
 exception handling. For example, you might have a fallback module:
 
 
 
 try:
 
 import this_module
 
 except ImportError:
 
 import that_module as this_module
 
 
 
 
 
 You will very rarely see that inside a class, since you very rarely 
 
 import modules inside a class.
 
 
 
 
 
  * Classes should be coded in a way that exceptions 
 
 
 
 I think you forgot to finish the sentence.
 
 
 
 
 
  * Better to
 
  never write your own exceptions (unless you absolutely have to). 
 
 
 
 That depends.
 
 
 
 On the one hand, nobody wants a million different exception types. On the 
 
 other hand, nobody wants just *one* exception type, and no way to 
 
 distinguish between different kinds of errors. Somewhere between one and 
 
 one million is an appropriate number of exception types.
 
 
 
 The right answer is to be conservative about creating new exceptions, but 
 
 don't be scared to create one when you need one.
 
 
 
 But when you do, it is often better to subclass from an appropriate built-
 
 in exception like ValueError or TypeError or similar, than to subclass 
 
 from Exception itself.
 
 
 
 
 
  * Using
 
  Exception is typically a bad. More specific the better.
 
 
 
 Yes, you should always try to catch the specific exceptions you care 
 
 about:
 
 
 
 
 
 # Best
 
 except ValueError, OverflowError, ZeroDivisionError:
 
 
 
 
 
 # Not so good
 
 except Exception:
 
 
 
 
 
 # Worst
 
 except:
 
 
 
 
 
 Don't use the last one, except maybe in the interactive interpreter, 
 
 since it will catch *everything*, even exceptions that probably shouldn't 
 
 be caught like KeyboardInterrupt.
 
 
 
 
 
  * Exceptions
 
  should never fail silently. (Should exceptions always be logged?)
 
 
 
 Certainly not. Exceptions should fail silently if you don't care about 
 
 them. For example, when connecting to a website, there are many temporary 
 
 errors that can occur. The best way to handle them is to catch the 
 
 exception, sleep for a little while, then try again. You need only care 
 
 if repeated attempts to connect, with larger and larger sleeps, continue 
 
 to fail.
 
 
 
 Of course, you might have a debug mode that logs all of these, but if 
 
 your web browser logged every single time a webpage was slow to respond, 
 
 you would soon run out of disk space :-)
 
 
 
 *Errors* should never fail silently, unless explicitly silenced. But an 
 
 error isn't an error if you don't care about it, and an exception is not 
 
 necessarily an error.
 
 
 
 This is an error, because converting a number to uppercase cannot 
 
 possibly mean anything:
 
 
 
 mystring = 42
 
 mystring.upper()
 
 
 
 
 
 This is not necessarily an error, since the list is empty could be a 
 
 legitimate situation:
 
 
 
 mylist = []
 
 first = mylist[0]
 
 
 
 In this case, it may be appropriate to catch the exception, and either 
 
 silently swallow it, or do something else.
 
 
 
 
 
  Best site I have found for exceptions (hopefully this helps someone): *
 
  http://c2.com/cgi/wiki?ExceptionPatterns
 
 
 
 I haven't read that page for a long time, but as I recall the c2.com 
 
 website, a lot of the ideas there are better suited to Java and C/C++ 
 
 (and occasionally Lisp) rather than Python. But still, a valuable (if 
 
 often confusing) resource.
 
 
 
 
 
 
 
  I'd be interested in hearing others thoughts on this topic with regards
 
  to best practices for when to use exceptions, and when to avoid using
 
  exceptions.
 
 
 
 The try part of a try...except is *very* fast to set up. It's about as 
 
 fast as a pass (do nothing), so it has little overhead.
 
 
 
 On the other hand, actually *catching* an exception is quite heavy. So 
 
 code that catches lots and lots of exceptions may be slow. In that case, 
 
 it may be faster to look before you leap and test ahead of time:
 
 
 
 # this is faster if most lists are not empty
 
 try:
 
 

Re: Exception Handling Practices / Patterns

2013-08-24 Thread frank . ruiz
Appreciate the feedback. I was hoping to get as much perspective as possible. 

On Saturday, August 24, 2013 12:18:59 AM UTC-7, Dave Angel wrote:
 snarf wrote:
 
 
 
  Greetings,
 
 
 
  As I tread through my journey of OO I am trying to determine if there is a 
  good approach for exception handling within classes.
 
 
 
  From my readings and gatherings - it seems I have found a common theme, but 
  I am trying to solicit from the experts.
 
 
 
  Here is what I have found (I may be restating the obvious so please forgive 
  me in advance):
 
 
 
  * Seems like exception handing within Classes is largely avoided and is 
  typically only used when calling external libraries.
 
  * Try/Except type statements seem to be used more within modules, main 
  functions, wrapper scripts.
 
 
 
 Exceptions are used when useful.  I don't see any bias towards any one
 
 location.
 
 
 
  * Classes should be coded in a way that exceptions 
 
 
 
 You seem to be missing the last part of this sentence.
 
 
 
  * Better to never write your own exceptions (unless you absolutely have to).
 
 
 
 If you mean to avoid writing exception classes, then I say nonsense. 
 
 Just derive them from the closest meaningful exception class, so that a
 
 user can combine handlers when reasonable.
 
 
 
  * Using Exception is typically a bad. More specific the better.
 
 
 
 If you mean in an except statement, then I'd agree.
 
 
 
  * Exceptions should never fail silently. (Should exceptions always be 
  logged?)
 
 
 
 Exceptions should be caught if you can handle them, or if you need to
 
 convert them to a different exception that someone further up the stack
 
 can handle.  Sometimes handling means do nothing.
 
 
 
 
 
  Best site I have found for exceptions (hopefully this helps someone):
 
  * http://c2.com/cgi/wiki?ExceptionPatterns
 
 
 
 But that's for Java.  java is not C++, and neither is it Python.  For
 
 one thing, Python exception overhead is deliberately much less, and they
 
 are used more freely.
 
 
 
 Notice that exceptions are used to terminate for loops, and that's a
 
 *normal* exit to the loop.  They also appear in other places under the
 
 covers.  Don't be afraid of them.
 
 
 
 -- 
 
 DaveA

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


Re: Lambda function Turing completeness

2013-08-24 Thread Piet van Oostrum
Musical Notation musicdenotat...@gmail.com writes:

 Is it possible to write a Turing-complete lambda function (which does
 not depend on named functions) in Python?

The wording of this question is questionable. Turing completeness is not
an attribute of a function, but of a system (for example a programming
language or a machine). It means that for every Turing machine you can
write a program in that language or program the machine in such a way
that it emulates that Turing machine.

So you could ask if the subset of the Python programs consisting only of
a lambda expression is Turing complete. Or alternatively if for every
Turing machine you can write a lambda expression that emulates that
Turing machine.

It has been proven that the λ calculus is equivalent to Turing machines,
so if the lambda calculus can be emulated with Python's lambda
expressions the answer is yes. In the lambda calculus you can define
lambda expressions and apply functions to parameters. The parameters may
be functions (in fact in the pure λ calculus there is nothing else), so
functions must be first class citizens. Fortunately in Python this is
the case. So we suspect it can be done.

An important result in the λ calculus is that every expression can be
expressed in three functions S, K and I with only function application.
So we are going to try to do these in Python and see if it works.

The definitions in the λ calculus are:

S = λ x y z. (x z) (y z)
K = λ x y. x
I = λ x. x

The dot is used where Python uses :, function application is written as
juxtaposition: f x and λ x y is an abbreviation of λ x. λ y

So we are going to translate these in python. We have to explicitely
write the lambda's (each one with a single parameter) and add
parentheses around the function arguments if not already there.

 S = lambda x: lambda y: lambda z: x(z) (y(z))
 K = lambda x: lambda y: x
 I = lambda x: x

Now there is a theorem that SKK == I (I is the identity), so we are
going to test that:

 S(K)(K)('test')
'test'

a few more tests:

 for x in range(100):
... if S(K)(K)(x) != I(x):
... print('Not equal for x = %s' % x)
... 

All seem to be equal.

Of course we still have used names for the functions, but this is not
essential. We can just replace each of S, K, and I with their
definition:

 print((lambda x: lambda y: lambda z: x(z) (y(z))) # S
... (lambda x: lambda y: x)   # (K)
...   (lambda x: lambda y: x)('test'))# (K) ('test')
test

 for x in 'ABCDEFGHIJKLMNOPQRSTUVWXYZ':
... if ((lambda x: lambda y: lambda z: x(z) (y(z)))
... (lambda x: lambda y: x)
... (lambda x: lambda y: x)(x)) != (lambda x: x)(x):
...   print('Not equal for x = %s' % x)
... 
Success!

Now the pure λ lambda calculus has to express inter=gers, booleans etc.
also as lambda expressions and this makes it really unwieldy. However,
you can add some standard functions or expressions for these and that
doesn't diminish the expressiveness of the calculus. So I suppose that
you want to allow the use of all standard Python functions and
expressions.

Modern Pythons have conditional expressions, so this helps. We don't
have to emulate booleans and conditions with weird lambda expressions.
In Python's lambda expressions you can not use statements, only
expressions, so without conditional expressiosn Python's booleans
wouldn't be very useful.

The remaining problem is how to use loops or recursion. I'll do that in
a separate posting.
-- 
Piet van Oostrum p...@vanoostrum.org
WWW: http://pietvanoostrum.com/
PGP key: [8DAE142BE17999C4]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: can't get utf8 / unicode strings from embedded python

2013-08-24 Thread random832
On Sat, Aug 24, 2013, at 12:47, David M. Cotter wrote:
  What _are_ you using? 
 i have scripts in a file, that i am invoking into my embedded python
 within a C++ program.  there is no terminal involved.  the print
 statement has been redirected (via sys.stdout) to my custom print class,
 which does not specify encoding, so i tried the suggestion above to set
 it:

That doesn't answer my real question. What does your custom print
class do with the text?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Lambda function Turing completeness

2013-08-24 Thread Piet van Oostrum
This is the second part of my posting on the Turing completeness of
Python's lambda expressions. This time I am going to define a recursive
function as a lambda expression (I use lambda when I am talking about
Python's lambda expressions, and λ for the theory – λ calculus.)

Now of course it is easy to define a recursive function if you can use
its function name inside the body. But the question of the OP was if you
can do it without named functions. The pure λ calculus only works with
unnamed λ expressions. Therefore we need a special operator to define
recursive functions. This is the so called Y combinator, or Y
operator[1].

The defining characteristic of Y is:

Y(f)  = f(Y(f)) for all functions f.
 
There are several possible definitions of this operator, but some of
them work only for programming languages with lazy evaluation or call by
name. For Python's call by valye the following one will work:

Y = λf.(λx.f (λv.((x x) v))) (λx.f (λv.((x x) v)))

Translated in Python:

 Y = lambda f: (lambda x: f (lambda v: ((x (x)) (v \
... (lambda x: f (lambda v: ((x (x)) (v

We are going to define a lambda expression for the factorial function.
We need a helper function for this. The idea is to have the final
recursive function as a parameter of the helper function. See [1].

def fact_helper(f, n):
if n == 0:
return 1
else:
return n * f(n-1)

No we have to rewrite this to get a proper lambda expression. We split
the two parameters and give each of them a lambda, and we replace the if
statement with a conditional expression.

 fact_helper = lambda f: lambda n: (1 if n == 0 else n * f(n-1))

Now we apply the Y combinator to fact_helper to get the recursive fact
function and check it:

 fact = Y (fact_helper)
 fact(5)
120

Of course to get pure we have to get rid of the names of the functions.
So we replace each of Y, fact and fact_helper with their definition:

 (lambda f: (lambda x: f (lambda v: ((x (x)) (v \
...(lambda x: f (lambda v: ((x (x)) (v) \
...(lambda f: lambda n: (1 if n == 0 else n * f(n-1))) (5)
120

Lo and behold! We have the right answer.

Now writing a universal Turing machine as a single Python lambda
expression is left as an exercise for the reader.

BTW. If you use Python 3 you can have print inside a lambda expression,
so this makes all this even nicer.
--
[1] http://en.wikipedia.org/wiki/Fixed-point_combinator#Y_combinator
-- 
Piet van Oostrum p...@vanoostrum.org
WWW: http://pietvanoostrum.com/
PGP key: [8DAE142BE17999C4]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Setting the value of True

2013-08-24 Thread Gregory Ewing

Steven D'Aprano wrote:
As for why None, True and False are treated differently than built-ins, 
if I remember the reason why, it is because they are considered 
fundamental to the inner workings of Python, unlike mere builtins like 
len, map, etc. and therefore should be protected.


It's probably more to permit optimisation. Treating them
as constants avoids a name lookup every time they're used.

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


Re: New way of writing socket servers in #Linux kernel 3.9 (and in #Python too)

2013-08-24 Thread Michael Torrie
#Linux, #Python?  This this hash tag stuff is getting out of hand, don't
you think?
-- 
http://mail.python.org/mailman/listinfo/python-list


List getting extended when assigned to itself

2013-08-24 Thread Krishnan Shankar
Hi Python Friends,

I came across an example which is as below,

 var = [1, 12, 123, 1234]
 var
[1, 12, 123, 1234]
 var[:0]
[]
 var[:0] = var
 var
[1, 12, 123, 1234, 1, 12, 123, 1234]


Here in var[:0] = var we are assigning an entire list to the beginning of
itself. So shouldn't it be something like,

[[1, 12, 123, 1234], 1, 12, 123, 1234]

It happens when we do the below,

 var = [1, 12, 123, 1234]
 var[0] = var
 var
[[...], 12, 123, 1234]


Literally var[0] = var and var[:0] = var almost meens the same. But why is
the difference in output? Can anyone explain what happens when
slicing assignment and direct assignment.

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


Re: List getting extended when assigned to itself

2013-08-24 Thread Benjamin Kaplan
On Sat, Aug 24, 2013 at 8:52 PM, Krishnan Shankar
i.am.song...@gmail.com wrote:
 Hi Python Friends,

 I came across an example which is as below,

 var = [1, 12, 123, 1234]
 var
 [1, 12, 123, 1234]
 var[:0]
 []
 var[:0] = var
 var
 [1, 12, 123, 1234, 1, 12, 123, 1234]


 Here in var[:0] = var we are assigning an entire list to the beginning of
 itself. So shouldn't it be something like,

 [[1, 12, 123, 1234], 1, 12, 123, 1234]

 It happens when we do the below,

 var = [1, 12, 123, 1234]
 var[0] = var
 var
 [[...], 12, 123, 1234]


 Literally var[0] = var and var[:0] = var almost meens the same. But why is
 the difference in output? Can anyone explain what happens when slicing
 assignment and direct assignment.

Are you sure they're almost the same?

 var[0]
1
 var[:0]
[]

One's a list and one is an integer. It's hard for them to be any more
different. var[0] means that you should be setting an element of the
list. var[:0] says you want to update a piece of the list, not an
element inside it.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: New way of writing socket servers in #Linux kernel 3.9 (and in #Python too)

2013-08-24 Thread Benjamin Kaplan
On Sat, Aug 24, 2013 at 7:08 PM, Michael Torrie torr...@gmail.com wrote:
 #Linux, #Python?  This this hash tag stuff is getting out of hand, don't
 you think?

Didn't you hear? In an effort to redefine itself for the modern
Internet, Usenet is adding support for hash tags and limiting posts to
140 characters because kids these days just don't want to read
anything longer.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: New way of writing socket servers in #Linux kernel 3.9 (and in #Python too)

2013-08-24 Thread Michael Torrie
On 08/24/2013 10:06 PM, Benjamin Kaplan wrote:
 On Sat, Aug 24, 2013 at 7:08 PM, Michael Torrie torr...@gmail.com wrote:
 #Linux, #Python?  This this hash tag stuff is getting out of hand, don't
 you think?
 
 Didn't you hear? In an effort to redefine itself for the modern
 Internet, Usenet is adding support for hash tags and limiting posts to
 140 characters because kids these days just don't want to read
 anything longer.

Sweet.  And here I thought it was irc channels.

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


Re: List getting extended when assigned to itself

2013-08-24 Thread Steven D'Aprano
On Sun, 25 Aug 2013 09:22:27 +0530, Krishnan Shankar wrote:

 Hi Python Friends,
 
 I came across an example which is as below,
 
 var = [1, 12, 123, 1234]
 var
 [1, 12, 123, 1234]
 var[:0]
 []
 var[:0] = var
 var
 [1, 12, 123, 1234, 1, 12, 123, 1234]


 Here in var[:0] = var we are assigning an entire list to the beginning
 of itself. So shouldn't it be something like,
 
 [[1, 12, 123, 1234], 1, 12, 123, 1234]

No, you have misunderstood how slicing works. When you assign to a slice, 
you *replace* the existing slice with items from the other list:


py L = [1, 2, 3, 4, 5]
py L[2:4] = [None, None, None]
py L
[1, 2, None, None, None, 5]


Notice that it does not insert the list [None, None, None] as a single 
item.

If the slice you replace is empty, this is equivalent to inserting the 
items:

py L = [1, 2, 3, 4, 5]
py L[2:2] = [None, None, None]
py L
[1, 2, None, None, None, 3, 4, 5]

The beginning of the list is just an empty slice: L[:0] means all the 
items, starting at the beginning of the list, and finishing *before* 
index zero. So that makes it an empty slice, and items are inserted 
after the start of the list but before index zero:


py L = [1, 2, 3, 4, 5]
py L[:0] = [None, None, None]
py L
[None, None, None, 1, 2, 3, 4, 5]


So assigning to a slice *always* extends. If you try to assign a single 
value, not inside a list or other iterable, it fails:

py L = [1, 2, 3, 4, 5]
py L[:0] = None
Traceback (most recent call last):
  File stdin, line 1, in module
TypeError: can only assign an iterable


Remember that indexes in Python are *before* the item, so when slicing, 
Python cuts at the vertical lines | as shown below:

| a | b | c | d | e | f | g |

The vertical lines are numbered 0 through 7, and the slice [2:5] cuts as 
shown:

| a | b | c | d | e | f | g |
0---1---2---3---4---5---6---7

[2:5] = | c | d | e |



 It happens when we do the below,
 
 var = [1, 12, 123, 1234]
 var[0] = var
 var
 [[...], 12, 123, 1234]


Here you are *not* assigning to a slice, but setting a single item. The 
item at position 0 is replaced with the contents of var, which happens to 
be the same list, but that is just a distraction. It is more clear when 
you use a different value:

py L = [1, 2, 3, 4, 5]
py L[0] = something
py L
['something', 2, 3, 4, 5]


 Literally var[0] = var and var[:0] = var almost meens the same. 

No, they are very different.

Even though the difference is a single character, var[:index] and 
var[index] are very different, no matter what the value of index. The 
first is a slice ending at index, the second is a single item at index.

The same naturally applies to var[index:] as well, which is a slice 
starting at index.

If you wish to insert a sequence as a single object, you have two 
choices: you can use the list insert() method, or you can wrap the 
sequence in a list, and then use slice assignment:


py L = [1, 2, 3, 4, 5]
py L[2:4] = [L]
py L
[1, 2, [...], 5]


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


Checking homogeneity of Array using List in Python

2013-08-24 Thread sahil301290
I am unable to check homogeneity of Array.
I have take Array type Int to be default for my code.

Instead of getting Error on NON-INT Values.
I want to take input as string.
Then check if all input is in (0-9) form, I typecast it into int and Accept.
Else, I would like to skip that input.

eg. my input is ['1', ' ', 'asdasd231231', '1213asasd', '43242']
I want it to be interpreted as:
[1, [None], [None], [None], 43242]

NOTE: NO INBUILT FUNCTION BE USED. Thank you in advance.
-- 
http://mail.python.org/mailman/listinfo/python-list


[issue15125] argparse: positional arguments containing - in name not handled well

2013-08-24 Thread Martin Panter

Changes by Martin Panter vadmium...@gmail.com:


--
nosy: +vadmium

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



[issue17974] Migrate unittest to argparse

2013-08-24 Thread Martin Panter

Changes by Martin Panter vadmium...@gmail.com:


--
nosy: +vadmium

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



[issue17741] event-driven XML parser

2013-08-24 Thread Nick Coghlan

Nick Coghlan added the comment:

Using tulip-inspired method names (when tulip hasn't landed) to duplicate 
existing data input functionality (feed() and close()) seems a rather dubious 
design decision to me.

Given how popular lxml.etree is as an alternative to the standard library's 
etree implementation, we shouldn't dismiss Stefan's design concerns lightly.

--
nosy: +ncoghlan

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



[issue5876] __repr__ returning unicode doesn't work when called implicitly

2013-08-24 Thread Armin Rigo

Armin Rigo added the comment:

@Serhiy: it's a behavior change and as such not an option for a micro release.  
For example, the following legal code would behave differently: it would 
compute s = '\\u1234' instead of s = 'UTF8:\xe1\x88\xb4'.

try:
s = repr(x)
except UnicodeEncodeError:
s = 'UTF8:' + x.value.encode('utf-8')

I think I agree that a working repr() is generally better, but in this case it 
should point to the programmer that they should rather have __repr__() return 
something sensible and avoid the trick above...

--

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



[issue15112] argparse: nargs='*' positional argument doesn't accept any items if preceded by an option and another positional

2013-08-24 Thread Martin Panter

Martin Panter added the comment:

I was surprised to discover that “option straddling” doesn’t work this way with 
nargs=*. It seems to work fine with most other kinds of positional arguments 
I have tried, and I imagine that this was by design rather than accident. Many 
Gnu CLI programs also tend to support it as well (e.g. “cp file1 file2 
--verbose dir/”).

I assumed nargs=argparse.REMAINDER was intended to override the “option 
straddling”. Otherwise, by just going off the documentation it sounds like 
nargs=argparse.REMAINDER is much the same as nargs=*.

--
nosy: +vadmium

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



[issue14191] argparse doesn't allow optionals within positionals

2013-08-24 Thread Martin Panter

Martin Panter added the comment:

It sounds like this bug might cover Issue 15112, which is only concerned with 
options between different positional parameters.

--
nosy: +vadmium

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



[issue17410] Generator-based HTMLParser

2013-08-24 Thread Ezio Melotti

Changes by Ezio Melotti ezio.melo...@gmail.com:


--
nosy: +scoder

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



[issue18643] implement socketpair() on Windows

2013-08-24 Thread Charles-François Natali

Charles-François Natali added the comment:

Here's a patch.

Note that I'm still not sure whether it belong to the socket module or 
test.support.

--
keywords: +needs review, patch
stage: needs patch - patch review
versions: +Python 3.4
Added file: http://bugs.python.org/file31452/socketpair.diff

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



[issue18538] `python -m dis ` should use argparse

2013-08-24 Thread Michele Orrù

Michele Orrù added the comment:

Ping.

--

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



[issue18643] implement socketpair() on Windows

2013-08-24 Thread STINNER Victor

STINNER Victor added the comment:

On Linux, many tests of test_socket are failing with the pure Python 
implementation.

--

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



[issue18643] implement socketpair() on Windows

2013-08-24 Thread Charles-François Natali

Charles-François Natali added the comment:

 On Linux, many tests of test_socket are failing with the pure Python
 implementation.

The only failing tests I see are due to the fact that the Python
implementation uses AF_INET instead of AF_UNIX, which is normal since
Windows doesn't have AF_UNIX.
Do you see other failures?

--

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



[issue18824] Adding LogRecord attribute traceback

2013-08-24 Thread Sworddragon

New submission from Sworddragon:

On configuring a logger with logging.basicConfig() and using 
logging.exception() the traceback is always written implicitly to the end. This 
makes it not possible to create a formation that writes something beyond the 
traceback. For example it could be something like that: 
logging.basicConfig(filename = '/tmp/python.log', format = 
'%(asctime)s\n%(traceback)s\nSome_text_or_LogRecords_after_the_traceback', 
datefmt = '%Y-%m-%d %H:%M:%S')

--
components: Library (Lib)
messages: 196072
nosy: Sworddragon
priority: normal
severity: normal
status: open
title: Adding LogRecord attribute traceback
type: enhancement
versions: Python 3.3

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



[issue18825] Making msg optional on logging.exception() and similar variants

2013-08-24 Thread Sworddragon

New submission from Sworddragon:

For logging.exception() and similar variants the msg argument must be passed 
but on a formation the LogRecord message is not mandatory. In this case 
wouldn't it be better to make the msg argument optional? At default it could be 
None or ''.

--
components: Library (Lib)
messages: 196073
nosy: Sworddragon
priority: normal
severity: normal
status: open
title: Making msg optional on logging.exception() and similar variants
type: enhancement
versions: Python 3.3

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



[issue14019] Unify tests for str.format and string.Formatter

2013-08-24 Thread Francisco Freire

Francisco Freire added the comment:

Thanks for the review. I corrected some issues in my code. Here is the new 
patch.

--
Added file: http://bugs.python.org/file31453/mywork2.patch

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



[issue16853] add a Selector to the select module

2013-08-24 Thread Charles-François Natali

Charles-François Natali added the comment:

Alright, I've updated the patch to have a distinct selectors module,
and with Guido's comments.

Before I post it for final review, I have three more questions:
1) In the documentation, I don't know how to best refer to files
object registered: is file descriptor OK, or is it too low-level?
Otherwise I'd be tempted to use just file, but then this doesn't
include sockets, pipes, etc. Or maybe file object/file-like
object?

2) currently, the select() method returns a list of
(file, event, data)

But the opaque data object is optional, which means that many user
might end up doing:

for file, event, data in selector.select():
if event  READ_EVENT:
file.recv(1024)
# don't use data

i.e. have to unpack it for no reason.

Would it make sense to return (key, event) instead?
This way the user has all the interesting information, and can do:

for key, event in selector.select():
if event  READ_EVENT:
key.file.recv(1024)
or
os.read(key.fd, 1024)

3) Concerning get_info(): right now the signature is:
get_info(): fileobj - (events, data)

Wouldn't it be better to just return the whole key instead, which
contains all the relevant information (events, data, fd and fileobj).
Then we should probably also rename the method to get_key()?

--

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



[issue18808] Thread.join returns before PyThreadState is destroyed

2013-08-24 Thread Tamas K

Tamas K added the comment:

After a quick glance, I can't see how this patch would fix the problem. It 
still depends on threading's Thread.join, which is affected by the race 
condition in __bootstrap_inner.

We already did a Thread.join before calling Py_EndInterpreter and still got 
bitten by the race.

--

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



[issue18808] Thread.join returns before PyThreadState is destroyed

2013-08-24 Thread Antoine Pitrou

Antoine Pitrou added the comment:

Well, that's a good point. It does bring in line subinterpreters with the main 
interpreter when it comes to automatically joining non-daemon threads, but it 
doesn't solve the race condition you talked about. I forgot a bit too fast 
about it :-)

--

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



[issue18643] implement socketpair() on Windows

2013-08-24 Thread STINNER Victor

STINNER Victor added the comment:

 Do you see other failures?

I applied your patch and I just replace the hasattr with:
hasattr(_socket, Xsocketpair). test_socket failures:

==
FAIL: test_sendall_interrupted (test.test_socket.GeneralModuleTests)
--
Traceback (most recent call last):
  File /home/haypo/prog/python/default/Lib/test/test_socket.py, line
1259, in test_sendall_interrupted
self.check_sendall_interrupted(False)
  File /home/haypo/prog/python/default/Lib/test/test_socket.py, line
1248, in check_sendall_interrupted
c.sendall(bx * (1024**2))
AssertionError: ZeroDivisionError not raised

==
FAIL: test_sendall_interrupted_with_timeout
(test.test_socket.GeneralModuleTests)
--
Traceback (most recent call last):
  File /home/haypo/prog/python/default/Lib/test/test_socket.py, line
1262, in test_sendall_interrupted_with_timeout
self.check_sendall_interrupted(True)
  File /home/haypo/prog/python/default/Lib/test/test_socket.py, line
1248, in check_sendall_interrupted
c.sendall(bx * (1024**2))
AssertionError: ZeroDivisionError not raised

==
FAIL: testDefaults (test.test_socket.BasicSocketPairTest)
--
Traceback (most recent call last):
  File /home/haypo/prog/python/default/Lib/test/test_socket.py, line
3640, in testDefaults
self._check_defaults(self.serv)
  File /home/haypo/prog/python/default/Lib/test/test_socket.py, line
3630, in _check_defaults
self.assertEqual(sock.family, socket.AF_UNIX)
AssertionError: 2 != 1

==
FAIL: testDefaults (test.test_socket.BasicSocketPairTest)
--
Traceback (most recent call last):
  File /home/haypo/prog/python/default/Lib/test/test_socket.py, line
261, in _tearDown
raise exc
  File /home/haypo/prog/python/default/Lib/test/test_socket.py, line
273, in clientRun
test_func()
  File /home/haypo/prog/python/default/Lib/test/test_socket.py, line
3637, in _testDefaults
self._check_defaults(self.cli)
  File /home/haypo/prog/python/default/Lib/test/test_socket.py, line
3630, in _check_defaults
self.assertEqual(sock.family, socket.AF_UNIX)
AssertionError: 2 != 1

--

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



[issue17741] event-driven XML parser

2013-08-24 Thread Nick Coghlan

Nick Coghlan added the comment:

Reopening this as per discussion on python-dev. I haven't reverted anything at 
this point, as subsequent changes mean a simple hg backout is no longer 
sufficient.

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

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



[issue18538] `python -m dis ` should use argparse

2013-08-24 Thread Roundup Robot

Roundup Robot added the comment:

New changeset 59f98b96607e by Nick Coghlan in branch 'default':
Close #18538: ``python -m dis`` now uses argparse.
http://hg.python.org/cpython/rev/59f98b96607e

--
nosy: +python-dev
resolution:  - fixed
stage:  - committed/rejected
status: open - closed

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



[issue17400] ipaddress should make it easy to identify rfc6598 addresses

2013-08-24 Thread Nick Coghlan

Nick Coghlan added the comment:

Reopening this - rewording the issue title to cover the problem to be solved 
(i.e. accounting for RFC 6598 addresses) rather than a specific solution (which 
isn't appropriate, since the RFC *explicitly* states that shared addresses and 
private addresses aren't the same thing)

It seems to me that the simplest solution would be to use the terminology from 
RFC 6598 and add a new is_shared attribute to addresses.

--
resolution: rejected - 
status: closed - open
title: ipaddress.is_private needs to take into account of rfc6598 - ipaddress 
should make it easy to identify rfc6598 addresses

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



[issue18803] Fix more typos in .py files

2013-08-24 Thread Févry Thibault

Févry Thibault added the comment:

Ezio : Yes, I was just following Reddy's advice from another bug report (issue 
18466) 

Terry : Yes, looks like I was tired while doing that...

 Should be fixed in the updated patch

--
Added file: http://bugs.python.org/file31454/more_typos.diff

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



[issue18756] os.urandom() fails under high load

2013-08-24 Thread Charles-François Natali

Charles-François Natali added the comment:

 New changeset fe949918616c by Antoine Pitrou in branch 'default':
 Issue #18756: Improve error reporting in os.urandom() when the failure is due 
 to something else than /dev/urandom not existing.
 http://hg.python.org/cpython/rev/fe949918616c

Antoine, this changeset broke Tiger buildbots badly:

==
ERROR: test_urandom_failure (test.test_os.URandomTests)
--
Traceback (most recent call last):
  File /Users/db3l/buildarea/3.x.bolen-tiger/build/Lib/test/test_os.py,
line 1033, in test_urandom_failure
ValueError: not allowed to raise maximum limit


http://buildbot.python.org/all/builders/x86%20Tiger%203.x/builds/6826/steps/test/logs/stdio


1030 # We restore the old limit as soon as possible. If doing it
1031 # using addCleanup(), code running in between would fail
1032 # creating any file descriptor.
1033 resource.setrlimit(resource.RLIMIT_NOFILE, (soft_limit, hard_limit))


The code trying to reset RLIMIT_NOFILE to its previous value fails,
and as a consequence, all subsequent FDs creation fail (since the soft
limit it 1)...

It looks like Tiger getrlimit() return a nonsensical value (maybe -1),
which means that you can't do setrlimit(getrlimit()), or yet another
OS X bug (TM).
See e.g. http://www.couchbase.com/issues/browse/MB-3064

I'd suggest two things:
- skip it on Tiger (using support.requires_mac_vers() decorator)
- run the test in a subprocess (using the test in your latest patch
would be fine), to be more robust against this

--

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



[issue18756] os.urandom() fails under high load

2013-08-24 Thread Charles-François Natali

Charles-François Natali added the comment:

Or more precisely, just run the test in a subprocess. That should fix
the OS X failure if we don't restore the RLIMIT_NOFILE limits, and
will make the test more robust (but you can't reuse the new test,
since it won't work with lazy-opening).

--

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



[issue18808] Thread.join returns before PyThreadState is destroyed

2013-08-24 Thread Antoine Pitrou

Antoine Pitrou added the comment:

Here is a patch to remove the race condition. The patch is sufficiently 
delicate that I'd rather reserve this for 3.4, though.

--
nosy: +neologix
Added file: http://bugs.python.org/file31455/threadstate_join.patch

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



[issue18756] os.urandom() fails under high load

2013-08-24 Thread Roundup Robot

Roundup Robot added the comment:

New changeset b9e62929460e by Antoine Pitrou in branch '3.3':
Issue #18756: make test_urandom_failure more robust by executing its code in a 
subprocess
http://hg.python.org/cpython/rev/b9e62929460e

New changeset 68ff013b194c by Antoine Pitrou in branch 'default':
Issue #18756: make test_urandom_failure more robust by executing its code in a 
subprocess
http://hg.python.org/cpython/rev/68ff013b194c

New changeset 869df611c138 by Antoine Pitrou in branch '2.7':
Issue #18756: make test_urandom_failure more robust by executing its code in a 
subprocess
http://hg.python.org/cpython/rev/869df611c138

--

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



[issue18756] os.urandom() fails under high load

2013-08-24 Thread Antoine Pitrou

Antoine Pitrou added the comment:

Ok, the tiger should feel better now :-)

--

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



[issue18772] Fix gdb plugin for new sets dummy object

2013-08-24 Thread Antoine Pitrou

Antoine Pitrou added the comment:

Since nobody seems to object to the patch, I'm commit it :)

--

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



[issue18772] Fix gdb plugin for new sets dummy object

2013-08-24 Thread Roundup Robot

Roundup Robot added the comment:

New changeset 2f1bac39565a by Antoine Pitrou in branch 'default':
Issue #18772: fix the gdb plugin after the set implementation changes
http://hg.python.org/cpython/rev/2f1bac39565a

--

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



[issue18772] Fix gdb plugin for new sets dummy object

2013-08-24 Thread Antoine Pitrou

Antoine Pitrou added the comment:

Well, it should be ok now (at least now the test passes here).

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

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



[issue18826] reversed() requires a sequence - Could work on any iterator?

2013-08-24 Thread Donald Stufft

New submission from Donald Stufft:

I noticed today that the builtin reversed() requires an explicit sequence and 
won't work with an iterator instead it throws a TypeError like:

 reversed(x for x in [1, 2, 3])
TypeError: argument to reversed() must be a sequence

It would be really great if reversed() worked on iterators too. Currently it 
requires an explicit list() before you can sent it back into reversed() which 
seems like it hurts readability.

For what it's worth I discovered this when trying to reverse the output of 
itertools.dropwhile.

--
messages: 196090
nosy: dstufft
priority: normal
severity: normal
status: open
title: reversed() requires a sequence - Could work on any iterator?

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



[issue18826] reversed() requires a sequence - Could work on any iterator?

2013-08-24 Thread Antoine Pitrou

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


--
nosy: +rhettinger

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



[issue16853] add a Selector to the select module

2013-08-24 Thread Antoine Pitrou

Antoine Pitrou added the comment:

 Alright, I've updated the patch to have a distinct selectors module,
 and with Guido's comments.

Didn't you forget to upload it?

--

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



[issue18826] reversed() requires a sequence - Could work on any iterator?

2013-08-24 Thread Donald Stufft

Donald Stufft added the comment:

As an additional note this works how I would expect it to work if you're using 
sorted() instead of reversed() which I think is a stronger point in the favor 
of making reversed() work this way as well.

 sorted(x for x in [1, 2, 3])
[1, 2, 3]

--

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



[issue18756] os.urandom() fails under high load

2013-08-24 Thread Antoine Pitrou

Antoine Pitrou added the comment:

So, to come back to the original topic, is everyone sold on the idea of caching 
the urandom fd lazily?

--

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



[issue18756] os.urandom() fails under high load

2013-08-24 Thread Donald Stufft

Donald Stufft added the comment:

Lazily opening urandom and holding it open sounds like a sane thing to do to me 
+1

--

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



[issue18746] test_threading.test_finalize_with_trace() fails on FreeBSD buildbot

2013-08-24 Thread STINNER Victor

STINNER Victor added the comment:

It may be related to #18408 (changeset 5bd9db528aed) and #18664.

--

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



[issue18664] occasional test_threading failure

2013-08-24 Thread STINNER Victor

STINNER Victor added the comment:

See also issue #18746.

--

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



[issue16853] add a Selector to the select module

2013-08-24 Thread Charles-François Natali

Charles-François Natali added the comment:

 Didn't you forget to upload it?

I wanted to have answer to my questions first :-):

 Before I post it for final review, I have three more questions:

--

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



[issue16853] add a Selector to the select module

2013-08-24 Thread Antoine Pitrou

Antoine Pitrou added the comment:

  Didn't you forget to upload it?
 
 I wanted to have answer to my questions first :-):

Ah, indeed, sorry!

 1) In the documentation, I don't know how to best refer to files
 object registered: is file descriptor OK, or is it too low-level?
 Otherwise I'd be tempted to use just file, but then this doesn't
 include sockets, pipes, etc. Or maybe file object/file-like
 object?

file object and file-like object are the convention used in the
docs:
http://docs.python.org/dev/glossary.html#term-file-object

That said, if the APIs also accept file descriptors, it must be
mentioned.

 i.e. have to unpack it for no reason.

That doesn't seem much of a concern, does it?
Perhaps there can be two separate methods, select() and
select_with_data(), but that sounds a bit overkill.

 3) Concerning get_info(): right now the signature is:
 get_info(): fileobj - (events, data)
 
 Wouldn't it be better to just return the whole key instead [...]

No opinion :-)

--

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



[issue15112] argparse: nargs='*' positional argument doesn't accept any items if preceded by an option and another positional

2013-08-24 Thread paul j3

Changes by paul j3 ajipa...@gmail.com:


--
nosy: +paul.j3

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



[issue18827] mistake in the timedelta.total_seconds docstring

2013-08-24 Thread Alexander Schier

New submission from Alexander Schier:

 Return the total number of seconds contained in the duration. Equivalent to 
 (td.microseconds + (td.seconds + td.days * 24 * 3600) * 10**6) / 10**6 
 computed with true division enabled.

Should be
 Return the total number of seconds contained in the duration. Equivalent to 
 (td.microseconds / 10**6 + (td.seconds + td.days * 24 * 3600) * 10**6) 
 computed with true division enabled.

At least i hope, the bug is only in the docs and not in the function ;).

--
assignee: docs@python
components: Documentation
messages: 196100
nosy: allo, docs@python
priority: normal
severity: normal
status: open
title: mistake in the timedelta.total_seconds docstring
type: behavior
versions: Python 2.7

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



[issue18827] mistake in the timedelta.total_seconds docstring

2013-08-24 Thread Tim Peters

Tim Peters added the comment:

The docs look correct to me.  For example,

 from datetime import *
 td = datetime.now() - datetime(1,1,1)
 td
datetime.timedelta(735103, 61756, 484000)
 td.total_seconds()
63512960956.484
^
What the docs say match that output:

 (td.microseconds + (td.seconds + td.days * 24 * 3600) * 10**6) / 1e6
63512960956.484

Your suggestion's output:

 (td.microseconds / 1e6 + (td.seconds + td.days * 24 * 3600) * 10**6)
6.3512960956e+16

You're multiplying the number seconds by a million - not a good idea ;-)

--
nosy: +tim.peters

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



[issue18582] PBKDF2 support

2013-08-24 Thread Donald Stufft

Changes by Donald Stufft donald.stu...@gmail.com:


--
nosy: +dstufft

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



[issue17134] Use Windows' certificate store for CA certs

2013-08-24 Thread Donald Stufft

Changes by Donald Stufft donald.stu...@gmail.com:


--
nosy: +dstufft

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



[issue18827] mistake in the timedelta.total_seconds docstring

2013-08-24 Thread Alexander Schier

Alexander Schier added the comment:

Err, sorry my fault. Too late in the evening ;).

I saw the division by one million, but not the multiplation by one million 
before. Additionally i was confused, because i expected that seconds are added 
to each other in the parenthesis.

closing.

--
resolution:  - invalid
status: open - closed

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



[issue9146] Segfault in hashlib in OpenSSL FIPS mode using non-FIPS-compliant hashes, if ssl imported before hashlib

2013-08-24 Thread Donald Stufft

Changes by Donald Stufft donald.stu...@gmail.com:


--
nosy: +dstufft

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



[issue17128] OS X system openssl deprecated - installer should build local libssl

2013-08-24 Thread Donald Stufft

Changes by Donald Stufft donald.stu...@gmail.com:


--
nosy: +dstufft

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



[issue18233] SSLSocket.getpeercertchain()

2013-08-24 Thread Donald Stufft

Changes by Donald Stufft donald.stu...@gmail.com:


--
nosy: +dstufft

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



[issue14518] Add bcrypt $2a$ to crypt.py

2013-08-24 Thread Donald Stufft

Changes by Donald Stufft donald.stu...@gmail.com:


--
nosy: +dstufft

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



[issue18454] distutils crashes when uploading to PyPI having only the username (no pw) defined

2013-08-24 Thread Donald Stufft

Changes by Donald Stufft donald.stu...@gmail.com:


--
nosy: +dstufft

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



[issue18643] implement socketpair() on Windows

2013-08-24 Thread Charles-François Natali

Charles-François Natali added the comment:

 self.assertEqual(sock.family, socket.AF_UNIX)
 AssertionError: 2 != 1

This is normal.

==
 FAIL: test_sendall_interrupted (test.test_socket.GeneralModuleTests)
 --
 Traceback (most recent call last):
   File /home/haypo/prog/python/default/Lib/test/test_socket.py, line
 1259, in test_sendall_interrupted
 self.check_sendall_interrupted(False)
   File /home/haypo/prog/python/default/Lib/test/test_socket.py, line
 1248, in check_sendall_interrupted
 c.sendall(bx * (1024**2))
 AssertionError: ZeroDivisionError not raised

Not this one.
I can't reproduce it on my Linux box, could you post the result of:

$ strace -ttTf ./python -m test -v -m test_sendall_interrupted test_socket

--

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



[issue8813] SSLContext doesn't support loading a CRL

2013-08-24 Thread Donald Stufft

Changes by Donald Stufft donald.stu...@gmail.com:


--
nosy: +dstufft

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



[issue13655] Python SSL stack doesn't have a default CA Store

2013-08-24 Thread Donald Stufft

Changes by Donald Stufft donald.stu...@gmail.com:


--
nosy: +dstufft

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



[issue16113] Add SHA-3 (Keccak) support

2013-08-24 Thread Donald Stufft

Changes by Donald Stufft don...@stufft.io:


--
nosy: +dstufft

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



[issue8106] SSL session management

2013-08-24 Thread Donald Stufft

Changes by Donald Stufft don...@stufft.io:


--
nosy: +dstufft

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



[issue18807] Allow venv to create copies, even when symlinks are supported

2013-08-24 Thread Roundup Robot

Roundup Robot added the comment:

New changeset ffb01a6c0960 by Vinay Sajip in branch 'default':
Closes #18807: pyvenv now takes a --copies argument allowing copies instead of 
symlinks even where symlinks are available and the default.
http://hg.python.org/cpython/rev/ffb01a6c0960

--
nosy: +python-dev
resolution:  - fixed
stage:  - committed/rejected
status: open - closed

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



[issue17741] event-driven XML parser

2013-08-24 Thread Eli Bendersky

Eli Bendersky added the comment:

I like the idea of having .events() in a special target passed to a XMLParser, 
which already has feed() and close(). I read through Stefan's proposal and 
there are a couple of issues I wanted to raise:

1. Why have the event builder wrap a tree builder? Can't it just be a 
separate target?
2. Instead of the stock XMLParser recognizing the event builder via isinstance 
and giving it special treatment, would it not be better to still have a 
separate class that implements the XMLParser interface (it can derive from it 
or just use duck typing)?

Note that (2) brings us closer to Antoine's original design, albeit with 
different method names and somewhat different underlying implementation.

Also, Stefan, could you clearly explain the specific implementation issue you 
ran into with your partial patch. You mentioned an unrelated bug that 
can/should be solved before such an implementation can work. Can you provide 
more details?

--

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



[issue16611] Cookie.py does not parse httponly or secure cookie flags

2013-08-24 Thread Julien Phalip

Julien Phalip added the comment:

Thanks for the review and new patch, David! Your approach makes sense and the 
patch looks good to me.

However, regarding backwards-compatibility, is that really a concern?

Currently the deserialization process systematically 1) Adds the 'httponly' and 
'secure' dict keys to the cookie object and 2) Puts an empty string value for 
those keys, regardless of whether those flags are present or not in the loaded 
string. So currently nobody's code could possibly rely on any particular state 
or behavior in the cookie object to determine if those flags were originally 
present in the loaded string.

I guess I'm wondering what could possibly break in people's code if we now 
implemented a fully logical fix for this. What do you think?

--

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



  1   2   >