Re: Forcing Python to detect DocumentRoot

2013-01-17 Thread Ferrous Cranus
Document Root for me is /home/nikos/public_html
Is where Apache store the user www files.

How to tell it my using a variable? 

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


Re: Loading a PKCS#1 public key using M2Crypto

2013-01-17 Thread Marc Aymerich
On Thursday, January 17, 2013 1:32:25 AM UTC+1, Piet van Oostrum wrote:
> Marc Aymerich  writes:
> 
> 
> 
> > Hi, 
> 
> > I've been trying very, very hard to load an RSA key using M2Crypto but 
> > without any success.
> 
> >
> 
> > basically this is what I'm trying to do:
> 
>  from M2Crypto import BIO, RSA
> 
>  
> 
>  pubkey = """-BEGIN RSA PUBLIC KEY-
> 
> > ... MIIBCgKCAQEApwotnfHT9RAmxnuaGEMdI3lYPYE4aaqSD9v4KbTh1E7Le3GNJQb7
> 
> > ... wCpmDe8+n8S5Kp/gBEpWiYuvsVA/T4KseoX7NMcacP+DJMwjmNd9U58USn2vLz0Z
> 
> > ... TMtXpc/FUhW5PZdgCiuNzw6IFgGn9ZCCv85jjUIW3KD8fUNdrUfVSv4olDoL9NkR
> 
> > ... dTRg3Os/znC6l0gv/mqnLaqj2bJ/tx47kUmj6Oq13JuEq34T+DVmsUCFVundQnRp
> 
> > ... c/vVEqQot7Rvj9UmSvTi4WKt/qxiAnyZf3gXOdrXvxfVTGzD5I/Xg+By+a4C2JwB
> 
> > ... A5RGvZP3fyfhkCnnhFDpfws5lc20FA6ryQIDAQAB
> 
> > ... -END RSA PUBLIC KEY-"""
> 
>  
> 
>  bio = BIO.MemoryBuffer(pubkey.encode('ascii'))
> 
>  RSA.load_pub_key_bio(bio)
> 
> > Traceback (most recent call last):
> 
> >   File "", line 1, in 
> 
> >   File "/usr/lib/python2.7/dist-packages/M2Crypto/RSA.py", line 422, in 
> > load_pub_key_bio
> 
> > rsa_error()
> 
> >   File "/usr/lib/python2.7/dist-packages/M2Crypto/RSA.py", line 302, in 
> > rsa_error
> 
> > raise RSAError, m2.err_reason_error_string(m2.err_get_error())
> 
> > M2Crypto.RSA.RSAError: no start line
> 
> >
> 
> >
> 
> > Reading all whats in Internet about this problem it seems that my key is in 
> > PKCS#1 format but M2Crypto only reads X.501 RSA keys. 
> 
> >
> 
> > I know that python-crypto doesn't have any problem loading this key, but 
> > I'll prefer to stick with M2Crypto because I already have lots code using 
> > M2Crypto.
> 
> >
> 
> > So my question is, is there any way to load this key using M2Crypto? Can I 
> > convert somehow the key to X.501?
> 
> >
> 
> Converting to X.501 isn't difficult (assuming this is a 2048 bit key):
> 
> Get rid of the 'RSA' in header and trailer
> 
> Prepend X.501 header 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8A' to the data
> 
> Reformat the lines to 64 characters.
> 
> 
> 
> from M2Crypto import BIO, RSA
> 
> 
> 
> pubkey="""-BEGIN RSA PUBLIC KEY-
> 
> MIIBCgKCAQEApwotnfHT9RAmxnuaGEMdI3lYPYE4aaqSD9v4KbTh1E7Le3GNJQb7
> 
> wCpmDe8+n8S5Kp/gBEpWiYuvsVA/T4KseoX7NMcacP+DJMwjmNd9U58USn2vLz0Z
> 
> TMtXpc/FUhW5PZdgCiuNzw6IFgGn9ZCCv85jjUIW3KD8fUNdrUfVSv4olDoL9NkR
> 
> dTRg3Os/znC6l0gv/mqnLaqj2bJ/tx47kUmj6Oq13JuEq34T+DVmsUCFVundQnRp
> 
> c/vVEqQot7Rvj9UmSvTi4WKt/qxiAnyZf3gXOdrXvxfVTGzD5I/Xg+By+a4C2JwB
> 
> A5RGvZP3fyfhkCnnhFDpfws5lc20FA6ryQIDAQAB
> 
> -END RSA PUBLIC KEY-
> 
> """
> 
> 
> 
> pk = pubkey.split('\n')
> 
> pk = 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8A' + ''.join(pk[1:-2])
> 
> pk = [pk[i:i+64] for i in range(0, len(pk), 64)]
> 
> pk = '-BEGIN PUBLIC KEY-\n' + '\n'.join(pk) + '\n-END PUBLIC 
> KEY-'
> 
> 
> 
> bio = BIO.MemoryBuffer(pk) # pk is ASCII, don't encode
> 
> key = RSA.load_pub_key_bio(bio)
> 
> 


Piet, that was really awesome, it seems so easy to do now :) 
Thank you very, very much! really.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Importing Classes from child folders.

2013-01-17 Thread Tobias M.
On an import python looks for the module in the directories specified in 
sys.path.

The documentation on sys.path says:

"As initialized upon program startup, the first item of this list is the 
directory containing the script that was used to invoke the Python 
interpreter." [1]


So it`s important that the script you execute by passing it to the 
python interpreter is in your root folder ("ProjectX").

If this script is Controller.py, you might want to check the path there by:

import sys
print(sys.path)

There should be an entry with a empty string ("") standing for the 
current directory.


Note: This is just what I suggest according to my knowledge (I'm also a 
newbie in python).


References:
[1] http://docs.python.org/3.3/library/sys.html#sys.path

On 17.01.2013 08:37, monosij.for...@gmail.com wrote:

Trying to do some OO Python with files in different directories.
I have a blank __init__.py in each directory.
It is my assumption that having an __init__.py marks the directory as a module.
I am trying to run Controller.py from the command line.

I would assume this has already been solved but could not find in forum
I am somewhat new to Python. Using Python3 under Ubuntu.
...
So I have a project structure as follows:
...
ProjectX (root folder)
__init__.py
Controller.py
+ service (folder under ProjectX)
   __init__.py
   SystemSetup.py (has a class SystemSetup)
+ model (folder under ProjectX)
   __init__.py
   Directory.py (has a class Directory)

In Controller.py if I want to use SystemSetup class, I do:
from service.SystemSetup import SystemSetup
...
and in Controller Class I have:
def main():
 systemSetup = SystemSetup()

I get error:
   File "Controller.py", line 4, in 
   from service.SystemSetup import SystemSetup
ImportError: cannot import name SystemSetup

What am I doing wrong? I am running from the command line.
Do I need to set the project in PYTHONPATH first?

But if SystemSetup and Directory are in same directory as Controller I have no 
problems.

Your help would be highly appreciated.
...
Btw I also tried:
import sys, os.path
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), 
os.path.pardir)))
from service.SystemSetup import SystemSetup
...
No luck.

Thank you again.

Monosij


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


Big girl pleasuring herself

2013-01-17 Thread Constantine
Big girl pleasuring herself  
http://ninelirowaytu.blogspot.com/2013/01/big-girl-pleasuring-herself.html 
-- 
http://mail.python.org/mailman/listinfo/python-list


iterating over the lines of a file - difference between Python 2.7 and 3?

2013-01-17 Thread Wolfgang Maier
I just came across an unexpected behavior in Python 3.3, which has to do
with file iterators and their interplay with other methods of file/IO class
methods, like readline() and tell(): Basically, I got used to the fact that
it is a bad idea to mix them because the iterator would use that hidden
read-ahead buffer, so what you got with subsequent calls to readline() or
tell() was what was beyond that buffer, but not the next thing after what
the iterator just returned.

Example:

in_file_object=open(‘some_file’,’rb’)

for line in in_file_object:

print (line)

if in_file_object.tell() > 300:

   # assuming that individual lines are shorter

   break

 

This wouldn´t print anything in Python 2.7 since next(in_file_object) would
read ahead beyond the 300 position immediately, as evidenced by a subsequent
call to in_file_object.tell() (returning 8192 on my system).

However, I find that under Python 3.3 this same code works: it prints some
lines from my file and after completing in_file_object.tell() returns a
quite reasonable 314 as the current position in the file.

I couldn´t find this difference anywhere in the documentation. Is the 3.3
behavior official, and if so, when was it introduced and how is it
implemented? I assume the read-ahead buffer still exists?

 

By the way, the 3.3 behavior only works in binary mode. In text mode, the
code will raise an OSError:  telling position disabled by next() call. In
Python 2.7 there was no difference between the binary and text mode
behavior. Could not find this documented either.

 

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


Re: iterating over the lines of a file - difference between Python 2.7 and 3?

2013-01-17 Thread Peter Otten
Wolfgang Maier wrote:

> I just came across an unexpected behavior in Python 3.3, which has to do
> with file iterators and their interplay with other methods of file/IO
> class methods, like readline() and tell(): Basically, I got used to the
> fact that it is a bad idea to mix them because the iterator would use that
> hidden read-ahead buffer, so what you got with subsequent calls to
> readline() or tell() was what was beyond that buffer, but not the next
> thing after what the iterator just returned.
> 
> Example:
> 
> in_file_object=open(‘some_file’,’rb’)
> 
> for line in in_file_object:
> 
> print (line)
> 
> if in_file_object.tell() > 300:
> 
># assuming that individual lines are
># shorter
> 
>break
> 
>  
> 
> This wouldn´t print anything in Python 2.7 since next(in_file_object)
> would read ahead beyond the 300 position immediately, as evidenced by a
> subsequent call to in_file_object.tell() (returning 8192 on my system).
> 
> However, I find that under Python 3.3 this same code works: it prints some
> lines from my file and after completing in_file_object.tell() returns a
> quite reasonable 314 as the current position in the file.
> 
> I couldn´t find this difference anywhere in the documentation. Is the 3.3
> behavior official, and if so, when was it introduced and how is it
> implemented? I assume the read-ahead buffer still exists?

You can get the Python 3 behaviour with io.open() in Python 2.7. There is an 
implementation in Python in _pyio.py:

def tell(self):
return _BufferedIOMixin.tell(self) - len(self._read_buf) + 
self._read_pos


> By the way, the 3.3 behavior only works in binary mode. In text mode, the
> code will raise an OSError:  telling position disabled by next() call. In
> Python 2.7 there was no difference between the binary and text mode
> behavior. Could not find this documented either.


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


[ANN] Salut à Toi 0.3: Python social XMPP client

2013-01-17 Thread Goffi
G'day everybody,

I've released the 0.3 version of Salut à Toi, a python XMPP client, which is 
multi-frontends (desktop, web, console, cli).
You can see a live demo on http://www.libervia.org .

SàT is made using Twisted/Wokkel, and Pyjamas for the web frontend. It 
offers features such as microblogging (with access restriction), games, pipe 
over XMPP or collective radio, and there is a social contract ( which can be 
seen on http://sat.goffi.org ). It's a free software (AGPL v3+)

I'm looking for people who would like to help on this project, and looking 
for alternative to websites like fb or g+.

Here is the release announce: 
http://www.goffi.org/post/2013/01/11/Salut-%C3%A0-Toi-version-0.3.0-%28with-
demo-online-%21%29

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


Re: iterating over the lines of a file - difference between Python 2.7 and 3?

2013-01-17 Thread Terry Reedy

On 1/17/2013 7:04 AM, Peter Otten wrote:

Wolfgang Maier wrote:


I just came across an unexpected behavior in Python 3.3, which has to do
with file iterators and their interplay with other methods of file/IO
class methods, like readline() and tell(): Basically, I got used to the
fact that it is a bad idea to mix them because the iterator would use that
hidden read-ahead buffer, so what you got with subsequent calls to
readline() or tell() was what was beyond that buffer, but not the next
thing after what the iterator just returned.

Example:

in_file_object=open(‘some_file’,’rb’)

for line in in_file_object:

 print (line)

 if in_file_object.tell() > 300:

# assuming that individual lines are
# shorter

break



This wouldn´t print anything in Python 2.7 since next(in_file_object)
would read ahead beyond the 300 position immediately, as evidenced by a
subsequent call to in_file_object.tell() (returning 8192 on my system).

However, I find that under Python 3.3 this same code works: it prints some
lines from my file and after completing in_file_object.tell() returns a
quite reasonable 314 as the current position in the file.

I couldn´t find this difference anywhere in the documentation. Is the 3.3
behavior official, and if so, when was it introduced and how is it
implemented? I assume the read-ahead buffer still exists?


You can get the Python 3 behaviour with io.open() in Python 2.7. There is an
implementation in Python in _pyio.py:

 def tell(self):
 return _BufferedIOMixin.tell(self) - len(self._read_buf) +
self._read_pos


In 2.7, open returns file object, which is a thin wrapper of the 
particular (proprietary) C compiler stdio library. They vary because the 
C standard leaves some things implementation-defined, and people 
interpret differently (no official test suite, at least not originally), 
and people make mistakes. The io module is intended to bring more 
uniformity, and there is a test suite for other implementations to match 
actual behavior to.


--
Terry Jan Reedy


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


Re: Forcing Python to detect DocumentRoot

2013-01-17 Thread rusi
On Jan 16, 6:51 pm, Ferrous Cranus  wrote:
> When trying to open an html template within Python script i use a relative 
> path to say go one folder back and open index.html
>
> f = open( '../' + page )
>
> How to say the same thing in an absolute way by forcing Python to detect 
> DocumentRoot by itself?

Is this what you want?
import os
os.getcwd()
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Forcing Python to detect DocumentRoot

2013-01-17 Thread Roy Smith
In article <339d9d6d-b000-4cf3-8534-375e0c44b...@googlegroups.com>,
 Ferrous Cranus  wrote:

> When trying to open an html template within Python script i use a relative 
> path to say go one folder back and open index.html
> 
> f = open( '../' + page )
> 
> How to say the same thing in an absolute way by forcing Python to detect 
> DocumentRoot by itself?

Can you give us more details of what you're doing.  Is there some web 
framework you're using?  Can you post some code that's not working for 
you?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: SimpleAI, Artificial Intelligence with Python - [released]

2013-01-17 Thread fisadev
On Wednesday, January 16, 2013 9:38:12 PM UTC-3, alex23 wrote:
> On Jan 17, 8:01 am, Elias Andrawos  wrote:
> 
> > SimpleAI is an easy to use lib implementing in python many of the
> 
> > artificial intelligence algorithms described on the book "Artificial
> 
> > Intelligence, a Modern Approach"
> 
> 
> 
> Thanks for this, it looks great. One question: I couldn't find any
> 
> mention of what Python versions are supported? 2 only? Late 2? 3?
> 
> 
> 
> Cheers!

Hi!

We currently support "late 2" versions of python (we have tested it under 2.7). 
But there are plans to make it compatible with python 3, it shouldn't be very 
difficult :)

--
fisa - Juan Pedro Fisanotti
-- 
http://mail.python.org/mailman/listinfo/python-list


Param decorator - can you suggest improvements

2013-01-17 Thread Mark Carter
I thought it would be interesting to try to implement Scheme SRFI 39 (Parameter 
objects) in Python.

The idea is that you define a function that returns a default value. If you 
call that function with no arguments, it returns the current default. If you 
call it with an argument, it resets the default to the value passed in. Here's 
a working implementation:

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

from functools import wraps

class Param(object):
def __init__(self, default):
self.default = default
#self.func = func

def __call__(self, func, *args):
@wraps(func)
def wrapper(*args):
#print 'calling hi'
if len(args) >0:
self.default = args[0]
#print len(args),  ' ', args
return self.default # self.func(*args)
return wrapper


@Param(42)
def hi(newval):
pass

print hi() # 42
print hi(12) # 12
print hi() # 12
hi(13) # sets it to 13
print hi() # 13


Can anyone suggest a better implementation?
-- 
http://mail.python.org/mailman/listinfo/python-list


python sys.stdout and C++ iostreams::cout

2013-01-17 Thread Utpal Sarkar
Hi,

I was assuming that sys.stdout would be referencing the same physical stream as 
iostreams::cout running in the same process, but this doesn't seem to be the 
case.
The following code, which makes a call to a C++ function with a python wrapper 
called "write", that writes to cout:

from cStringIO import StringIO
import sys
orig_stdout = sys.stdout
sys.stdout = stringout = StringIO()
write("cout") # wrapped C++ function that writes to cout
print "-" * 40
print "stdout"
sys.stdout = orig_stdout
print stringout.getvalue()

immediately writes "cout" to the console, then the separator "---...", and 
finally, as the return value of stringout.getvalue(), the string "stdout".
My intention was to capture in stringout also the string written to cout from 
C++.
Does anyone know what is going on, and if so, how I can capture what is written 
to cout in a python string?

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


Re: Forcing Python to detect DocumentRoot

2013-01-17 Thread Joel Goldstick
On Thu, Jan 17, 2013 at 9:09 AM, Roy Smith  wrote:

> In article <339d9d6d-b000-4cf3-8534-375e0c44b...@googlegroups.com>,
>  Ferrous Cranus  wrote:
>
> > When trying to open an html template within Python script i use a
> relative
> > path to say go one folder back and open index.html
> >
> > f = open( '../' + page )
> >
> > How to say the same thing in an absolute way by forcing Python to detect
> > DocumentRoot by itself?
>
> Can you give us more details of what you're doing.  Is there some web
> framework you're using?  Can you post some code that's not working for
> you?
> --
> http://mail.python.org/mailman/listinfo/python-list
>

Import os

Then read os.environ['HOME']

This will give you the home directory of the user.  in my case:

>>> os.environ['HOME']
'/home/jcg'
>>>

This is probably linux only, but that seems to be the environment you are
working in .



-- 
Joel Goldstick
http://joelgoldstick.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Param decorator - can you suggest improvements

2013-01-17 Thread Steven D'Aprano
On Thu, 17 Jan 2013 06:35:29 -0800, Mark Carter wrote:

> I thought it would be interesting to try to implement Scheme SRFI 39
> (Parameter objects) in Python.
> 
> The idea is that you define a function that returns a default value. If
> you call that function with no arguments, it returns the current
> default. If you call it with an argument, it resets the default to the
> value passed in. Here's a working implementation:
[...]
> Can anyone suggest a better implementation?

I don't like the decorator version, because it requires creating a do-
nothing function that just gets thrown away. He's my version, a factory 
function that takes two arguments, the default value and an optional 
function name, and returns a Param function:

def param(default, name=None):
SENTINEL = object()
default = [default]
def param(arg=SENTINEL):
if arg is SENTINEL:
return default[0]
else:
default[0] = arg
return arg
if name is not None:
param.__name__ = name
return param


In Python 3, it's even nicer, although no shorter:

def param(default, name=None):
SENTINEL = object()
def param(arg=SENTINEL):
nonlocal default
if arg is SENTINEL:
return default
else:
default = arg
return arg
if name is not None:
param.__name__ = name
return param



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


Thorough Python 2.7.3 Windows Build Documentation?

2013-01-17 Thread Leonard, Arah
Hello fellow Python programmers,

I'm building a 32-bit CPython 2.7.3 distro for Windows using the MS Visual 
Studio Professional 2008 SP1 (and all hotfixes) MSVC 9 compiler.  My build 
works, technically, but it also happens to benchmark over 30% slower than the 
precompiled binaries in the distributed Python 2.7.3 MSI.  Can anyone point me 
in the direction of some thoroughly detailed build documentation so that I can 
figure out how to get that 30% back with my build?  The only documentation that 
I can find just says MSVC 9, period.  There's no mention of SP1 or not, 
hotfixes, nor of any specific compiler/linker optimizations used to build the 
official distro.  Something, somewhere, has to be significantly different 
between our builds for a 30% performance difference, and it'd probably be handy 
for the Python community to know how to avoid the same pitfall that cost me 
performance so that we can all get the most out of Python.  Any and all help 
will be greatly appreciated.  Thanks.

Sincerely,
Arah Leonard

Arah Leonard
Software Development Engineer



Bruker AXS Inc.
5465 East Cheryl Parkway
Madison, WI 53711
US   Phone: +1 608-276-3812
 Phone: +1 800-234-XRAY(9729)
 Fax:


  arah.leon...@bruker-axs.com
  www.bruker.com



The information contained in this email is confidential. It is intended solely 
for the addressee. Access to this email by anyone else is unauthorized. If you 
are not the intended recipient, any form of disclosure, reproduction, 
distribution or any action taken or refrained from in reliance on it, is 
prohibited and may be unlawful. Please notify the sender immediately.


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


Re: python sys.stdout and C++ iostreams::cout

2013-01-17 Thread Nobody
On Thu, 17 Jan 2013 07:02:24 -0800, Utpal Sarkar wrote:

> I was assuming that sys.stdout would be referencing the same physical
> stream as iostreams::cout running in the same process, but this doesn't
> seem to be the case.

At startup, it refers to the same FILE* as C's stdout. This initially
shares a buffer with C++'s std::cout, but that can be changed via
std::ios_base::sync_with_stdio().

However ...

> The following code, which makes a call to a C++
> function with a python wrapper called "write", that writes to cout:
> 
> from cStringIO import StringIO
> import sys
> orig_stdout = sys.stdout
> sys.stdout = stringout = StringIO()
> write("cout") # wrapped C++ function that writes to cout print "-" * 40
> print "stdout"
> sys.stdout = orig_stdout
> print stringout.getvalue()

This code changes sys.stdout so that it refers to something other than C's
stdout. C's stdout is still the same FILE*, C++'s std::count is still the
same std::ostream, and the synchronisation between the two hasn't changed.

> immediately writes "cout" to the console, then the separator "---...", and
> finally, as the return value of stringout.getvalue(), the string "stdout".
> My intention was to capture in stringout also the string written to cout
> from C++. Does anyone know what is going on, and if so, how I can capture
> what is written to cout in a python string?

Changing sys.stdout doesn't (and cannot) have any effect upon how C or C++
code behaves. sys.stdout is just a Python variable.

If you want to capture output from C or C++ code, you'll have to do so via
other means, e.g. freopen() or dup2().

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


Re: python sys.stdout and C++ iostreams::cout

2013-01-17 Thread Chris Angelico
On Fri, Jan 18, 2013 at 2:02 AM, Utpal Sarkar  wrote:
> I was assuming that sys.stdout would be referencing the same physical stream 
> as iostreams::cout running in the same process, but this doesn't seem to be 
> the case.

That's more-or-less true, but there will likely be separate buffering,
so even without redirection you might see some oddities. But the
problem with your code is that you're not actually redirecting stdout
in any way; you're catching, at a fairly high level, everything that
Python would otherwise have sent there.

Is there any way that you can get the C++ code to offer a way to
redirect its output? Otherwise, you're going to have to fiddle around
with the usual mess of I/O redirection (with dup2), and you can only
send it to what the OS sees as a file (so, no StringIO buffer). So to
achieve your goal, you may need either a temporary physical file, or
some sort of pipe (and worry about reading from it before it fills up,
etc, etc). There may be alternatives, but in any case, the easiest way
is going to be with some assistance from the C++ function.

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


Re: python sys.stdout and C++ iostreams::cout

2013-01-17 Thread Utpal Sarkar
Thanks a lot Chris and Nobody! I'll have a look at dup2 for a start.

> > I was assuming that sys.stdout would be referencing the same physical 
> > stream as iostreams::cout running in the same process, but this doesn't 
> > seem to be the case.
> 
> 
> 
> That's more-or-less true, but there will likely be separate buffering,
> 
> so even without redirection you might see some oddities. But the
> 
> problem with your code is that you're not actually redirecting stdout
> 
> in any way; you're catching, at a fairly high level, everything that
> 
> Python would otherwise have sent there.
> 
> 
> 
> Is there any way that you can get the C++ code to offer a way to
> 
> redirect its output? Otherwise, you're going to have to fiddle around
> 
> with the usual mess of I/O redirection (with dup2), and you can only
> 
> send it to what the OS sees as a file (so, no StringIO buffer). So to
> 
> achieve your goal, you may need either a temporary physical file, or
> 
> some sort of pipe (and worry about reading from it before it fills up,
> 
> etc, etc). There may be alternatives, but in any case, the easiest way
> 
> is going to be with some assistance from the C++ function.
> 
> 
> 
> ChrisA

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


Re: python sys.stdout and C++ iostreams::cout

2013-01-17 Thread Chris Angelico
On Fri, Jan 18, 2013 at 2:51 AM, Utpal Sarkar  wrote:
> Thanks a lot Chris and Nobody! I'll have a look at dup2 for a start.

Okay. Look for code that redirects the standard I/O streams and then
exec()s another process (possibly after fork()ing); you're going to be
doing pretty much the same thing. Good luck, have fun. It's a LOT
messier than simply assigning to sys.stdout, unfortunately.

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


Re: Thorough Python 2.7.3 Windows Build Documentation?

2013-01-17 Thread Terry Reedy

On 1/17/2013 10:29 AM, Leonard, Arah wrote:

Hello fellow Python programmers,

I’m building a 32-bit CPython 2.7.3 distro for Windows using the MS
Visual Studio Professional 2008 SP1 (and all hotfixes) MSVC 9 compiler.
My build works, technically, but it also happens to benchmark over 30%
slower than the precompiled binaries in the distributed Python 2.7.3
MSI.  Can anyone point me in the direction of some thoroughly detailed
build documentation so that I can figure out how to get that 30% back
with my build?  The only documentation that I can find just says MSVC 9,
period.  There’s no mention of SP1 or not, hotfixes, nor of any specific
compiler/linker optimizations used to build the official distro.
Something, somewhere, has to be significantly different between our
builds for a 30% performance difference, and it’d probably be handy for
the Python community to know how to avoid the same pitfall that cost me
performance so that we can all get the most out of Python.  Any and all
help will be greatly appreciated.  Thanks.


The 'documentation' of how we build Python on Windows is the PCBuild 
directory in the source tree.


--
Terry Jan Reedy


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


Re: Thorough Python 2.7.3 Windows Build Documentation?

2013-01-17 Thread Stefan Krah
Leonard, Arah  wrote:
> I?m building a 32-bit CPython 2.7.3 distro for Windows using the MS Visual
> Studio Professional 2008 SP1 (and all hotfixes) MSVC 9 compiler.  My build
> works, technically, but it also happens to benchmark over 30% slower than the
> precompiled binaries in the distributed Python 2.7.3 MSI.  Can anyone point me
> in the direction of some thoroughly detailed build documentation so that I can
> figure out how to get that 30% back with my build?

I think the official binaries use the PGO build. Be sure to run all tests
thoroughly, we've had problems in with the PGO build in 3.3.


Stefan Krah


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


RE: iterating over the lines of a file - difference between Python 2.7 and 3?

2013-01-17 Thread Wolfgang Maier
Thanks Peter,
for this very helpful reply and for pointing out _pyio.py to me!
It's great to be able to check implementation details sometimes. So, if I 
understand you correctly, I can simply
import io
and open files with io.open() - instead of open and although this is a bit a 
detour in Python3 - and this will ensure version-independent behavior of my 
code? That´s cool!
What will my IO object return then when I read from it in Python 2.7? str where 
Python3 gives bytes, and unicode instead of str ? This is what I understood 
from the Python 2.7 io module doc.


-Original Message-
From: Peter Otten [mailto:__pete...@web.de] 
Sent: Thursday, January 17, 2013 1:04 PM
To: python-list@python.org
Subject: Re: iterating over the lines of a file - difference between Python 2.7 
and 3?

You can get the Python 3 behaviour with io.open() in Python 2.7. There is an 
implementation in Python in _pyio.py:

def tell(self):
return _BufferedIOMixin.tell(self) - len(self._read_buf) + 
self._read_pos



Wolfgang Maier wrote:

> I just came across an unexpected behavior in Python 3.3, which has to 
> do with file iterators and their interplay with other methods of 
> file/IO class methods, like readline() and tell(): Basically, I got 
> used to the fact that it is a bad idea to mix them because the 
> iterator would use that hidden read-ahead buffer, so what you got with 
> subsequent calls to
> readline() or tell() was what was beyond that buffer, but not the next 
> thing after what the iterator just returned.
> 
> Example:
> 
> in_file_object=open(‘some_file’,’rb’)
> 
> for line in in_file_object:
> 
> print (line)
> 
> if in_file_object.tell() > 300:
> 
># assuming that individual lines are
># shorter
> 
>break
> 
>  
> 
> This wouldn´t print anything in Python 2.7 since next(in_file_object) 
> would read ahead beyond the 300 position immediately, as evidenced by 
> a subsequent call to in_file_object.tell() (returning 8192 on my system).
> 
> However, I find that under Python 3.3 this same code works: it prints 
> some lines from my file and after completing in_file_object.tell() 
> returns a quite reasonable 314 as the current position in the file.
> 
> I couldn´t find this difference anywhere in the documentation. Is the 
> 3.3 behavior official, and if so, when was it introduced and how is it 
> implemented? I assume the read-ahead buffer still exists?
>
> By the way, the 3.3 behavior only works in binary mode. In text mode, the
> code will raise an OSError:  telling position disabled by next() call. In
> Python 2.7 there was no difference between the binary and text mode
> behavior. Could not find this documented either.




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


Re: Loading a PKCS#1 public key using M2Crypto

2013-01-17 Thread Piet van Oostrum
Piet van Oostrum  wrote:

> Converting to X.501 isn't difficult (assuming this is a 2048 bit key):
> Get rid of the 'RSA' in header and trailer
> Prepend X.501 header 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8A' to the data
> Reformat the lines to 64 characters.

This solution is a bit restricted as it only works if the key is 2048
bits and uses an exponent of 65537 (which is the default). Otherwise it
fails.

Here is a robust solution that works for all PKCS#1 keys. Instead of
using a fixed X.501 header it calculates the header. We could do a
complete ASN.1 encoding, but most of the parts are fixed. The only
variable parts are two length fields. So I just plug these into the
fixed stuff. This saves using one of the ASN.1 libraries. We do have to
work in binary (DER format) instead of base64, however.

from M2Crypto import BIO, RSA
import base64

def der_length(length):
"""DER encoding of a length"""
if length < 128:
return chr(length)
prefix = 0x80
result = ''
while length > 0:
result = chr(length & 0xff) + result
length >>= 8
prefix += 1
return chr(prefix) + result

pubkey="""-BEGIN RSA PUBLIC KEY-
MIIBCgKCAQEApwotnfHT9RAmxnuaGEMdI3lYPYE4aaqSD9v4KbTh1E7Le3GNJQb7
wCpmDe8+n8S5Kp/gBEpWiYuvsVA/T4KseoX7NMcacP+DJMwjmNd9U58USn2vLz0Z
TMtXpc/FUhW5PZdgCiuNzw6IFgGn9ZCCv85jjUIW3KD8fUNdrUfVSv4olDoL9NkR
dTRg3Os/znC6l0gv/mqnLaqj2bJ/tx47kUmj6Oq13JuEq34T+DVmsUCFVundQnRp
c/vVEqQot7Rvj9UmSvTi4WKt/qxiAnyZf3gXOdrXvxfVTGzD5I/Xg+By+a4C2JwB
A5RGvZP3fyfhkCnnhFDpfws5lc20FA6ryQIDAQAB
-END RSA PUBLIC KEY-
"""

pk = pubkey.split('\n')
pk = '\0' + base64.decodestring("".join(pk[1:-2]))
pk = '\x30\x0d\x06\x09\x2a\x86\x48\x86\xf7\x0d\x01\x01\x01\x05\x00\x03' + \
 der_length(len(pk)) + pk
pk = '\x30' + der_length(len(pk)) + pk
pk = '-BEGIN PUBLIC KEY-\n' + base64.encodestring(pk) + '-END 
PUBLIC KEY-'

bio = BIO.MemoryBuffer(pk)
key = RSA.load_pub_key_bio(bio)

-- 
Piet van Oostrum 
WWW: http://pietvanoostrum.com/
PGP key: [8DAE142BE17999C4]
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Thorough Python 2.7.3 Windows Build Documentation?

2013-01-17 Thread Leonard, Arah
> I think the official binaries use the PGO build. Be sure to run all tests 
> thoroughly, we've had problems in with the PGO build in 3.3.

Thanks Stefan.  I hope that's not the case.   PGO seems something of an 
anathema from well-documented builds.  Unless I'm missing something, if PGO is 
used it means that without knowing the specific CPU of the build machine there 
would be no way to reliably duplicate the build except by accident.  Even with 
knowing, unless you have the same CPU...

But after benchmarking a PGO build made by running the build_pgo.bat it 
turns out that it made no difference whatsoever to my performance loss.  Within 
an acceptable statistical variation in the benchmark tool itself my PGO build 
performed identically to my regular build.  Which means that I'm still running 
30% slower than the precompiled binaries somehow even though I'm theoretically 
using the right compiler.  And which also means that I can neither confirm nor 
deny if the released precompiled binaries are PGO builds or not.

It's one of those days I guess.  But thanks anyway.  I appreciate the 
useful input.  And yes, absolutely thorough testing is on the agenda.  :)

Sincerely,
Arah Leonard
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Loading a PKCS#1 public key using M2Crypto

2013-01-17 Thread Marc Aymerich
On Thursday, January 17, 2013 5:39:57 PM UTC+1, Piet van Oostrum wrote:

> > Converting to X.501 isn't difficult (assuming this is a 2048 bit key):
> 
> > Get rid of the 'RSA' in header and trailer
> 
> > Prepend X.501 header 'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8A' to the data
> 
> > Reformat the lines to 64 characters.
> 
> 
> 
> This solution is a bit restricted as it only works if the key is 2048
> 
> bits and uses an exponent of 65537 (which is the default). Otherwise it
> 
> fails.
> 
> 
> 
> Here is a robust solution that works for all PKCS#1 keys. Instead of
> 
> using a fixed X.501 header it calculates the header. We could do a
> 
> complete ASN.1 encoding, but most of the parts are fixed. The only
> 
> variable parts are two length fields. So I just plug these into the
> 
> fixed stuff. This saves using one of the ASN.1 libraries. We do have to
> 
> work in binary (DER format) instead of base64, however.
> 

Thank you very much Piet, 
I'm just starting to grasp these cryptography related concepts and your code is 
helping me a lot to understand how to handle these keys in a low level.

I'm updating my code incorporating your new contribution!

Just to let you know, during my previous research I had found a python-Crypto 
related solution that also uses DER and ASN.1 [1], but it uses a different 
approach (I guess). I suspect that this approach is also possible with M2Crypto 
because it has a method for constructing RSA keys [2]. 

[1] http://stackoverflow.com/a/10574723
[2] 
http://www.heikkitoivonen.net/m2crypto/api/M2Crypto.RSA-module.html#new_pub_key


Thanks again!
Marc

PS: Sorry for my email format, I'm using google groups and it seems to ignore 
any mailing best practice. 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Thorough Python 2.7.3 Windows Build Documentation?

2013-01-17 Thread Stefan Krah
Leonard, Arah  wrote:
>   But after benchmarking a PGO build made by running the build_pgo.bat it 
> turns out that it made no difference whatsoever to my performance loss.  
> Within an acceptable statistical variation in the benchmark tool itself my 
> PGO build performed identically to my regular build.  Which means that I'm 
> still running 30% slower than the precompiled binaries somehow even though 
> I'm theoretically using the right compiler.  And which also means that I can 
> neither confirm nor deny if the released precompiled binaries are PGO builds 
> or not.

I remember that some versions of Visual Studio silently completed the PGO build
without actually having PGO capabilities. :)

I think for VS 2008 at least "Professional" is needed, for VS 2010 "Ultimate".


Stefan Krah



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


Re: Thorough Python 2.7.3 Windows Build Documentation?

2013-01-17 Thread donarb
On Jan 17, 7:29 am, "Leonard, Arah" 
wrote:
> Hello fellow Python programmers,
>
> I'm building a 32-bit CPython 2.7.3 distro for Windows using the MS Visual 
> Studio Professional 2008 SP1 (and all hotfixes) MSVC 9 compiler.  My build 
> works, technically, but it also happens to benchmark over 30% slower than the 
> precompiled binaries in the distributed Python 2.7.3 MSI.  Can anyone point 
> me in the direction of some thoroughly detailed build documentation so that I 
> can figure out how to get that 30% back with my build?  The only 
> documentation that I can find just says MSVC 9, period.  There's no mention 
> of SP1 or not, hotfixes, nor of any specific compiler/linker optimizations 
> used to build the official distro.  Something, somewhere, has to be 
> significantly different between our builds for a 30% performance difference, 
> and it'd probably be handy for the Python community to know how to avoid the 
> same pitfall that cost me performance so that we can all get the most out of 
> Python.  Any and all help will be greatly appreciated.  Thanks.
>
> Sincerely,
> Arah Leonard
>
> Arah Leonard
> Software Development Engineer
>
> Bruker AXS Inc.
> 5465 East Cheryl Parkway
> Madison, WI 53711
> US       Phone: +1 608-276-3812
>  Phone: +1 800-234-XRAY(9729)
>  Fax:
>
>   arah.leon...@bruker-axs.com
>  www.bruker.com
>
> 
>
> The information contained in this email is confidential. It is intended 
> solely for the addressee. Access to this email by anyone else is 
> unauthorized. If you are not the intended recipient, any form of disclosure, 
> reproduction, distribution or any action taken or refrained from in reliance 
> on it, is prohibited and may be unlawful. Please notify the sender 
> immediately.

Try dumping the build configuration parameters:

   >>> import pprint, sysconfig
   >>> pprint.pprint(sysconfig.get_config_vars())

Then you can compare the existing version with yours.
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Thorough Python 2.7.3 Windows Build Documentation?

2013-01-17 Thread Leonard, Arah
> I remember that some versions of Visual Studio silently completed the PGO 
> build without actually having PGO capabilities. :)

> I think for VS 2008 at least "Professional" is needed, for VS 2010 "Ultimate".

Well, that certainly sounds like Microsoft.  Fortunately I'm using VS 2008 
Professional, so I guess that's not it.  :(  But thanks!

By the way, do you happen to know how tricky it is to get Python 2.7.3 to build 
with VS 2010?  Or have any tips there?  It doesn't seem to be officially 
supported, but it sure would be nice to get out of the dark ages of MS 
compilers and be only one version behind the latest.

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


RE: iterating over the lines of a file - difference between Python 2.7 and 3?

2013-01-17 Thread Peter Otten
Wolfgang Maier wrote:

> What will my IO object return then when I read from it in Python 2.7? str
> where Python3 gives bytes, and unicode instead of str ? This is what I
> understood from the Python 2.7 io module doc.

You can always double-check in the interpreter:
 
>>> with open("tmp.txt", "w") as f: f.write("let's try\n")
... 
>>> import io
>>> with io.open("tmp.txt", "r") as f: print type(f.read())
... 

>>> with io.open("tmp.txt", "rb") as f: print type(f.read())
... 


So yes. Also:

>>> str is bytes
True


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


ANN: A new version (0.3.2) of the Python module which wraps GnuPG has been released.

2013-01-17 Thread Vinay Sajip
A new version of the Python module which wraps GnuPG has been
released.

What Changed?
=
This is a minor enhancement and bug-fix release. See the project
website ( http://code.google.com/p/python-gnupg/ ) for more
information. Summary:

Improved support for status messages from GnuPG.
Fixed key generation to skip empty values.
Fixed list_keys to handle escaped characters.
Removed doctests which required interactive entry of passwords.

The current version passes all tests on Windows (CPython 2.4, 2.5,
2.6, 3.1, 2.7 and Jython 2.5.1) and Ubuntu (CPython 2.4, 2.5, 2.6,
2.7, 3.0, 3.1, 3.2). On Windows, GnuPG 1.4.11 has been used for the
tests. Tests also pass under CPython 2.5 and CPython 2.6 on OS X.

What Does It Do?

The gnupg module allows Python programs to make use of the
functionality provided by the Gnu Privacy Guard (abbreviated GPG or
GnuPG). Using this module, Python programs can encrypt and decrypt
data, digitally sign documents and verify digital signatures, manage
(generate, list and delete) encryption keys, using proven Public Key
Infrastructure (PKI) encryption technology based on OpenPGP.

This module is expected to be used with Python versions >= 2.4, as it
makes use of the subprocess module which appeared in that version of
Python. This module is a newer version derived from earlier work by
Andrew Kuchling, Richard Jones and Steve Traugott.

A test suite using unittest is included with the source distribution.

Simple usage:

>>> import gnupg
>>> gpg = gnupg.GPG(gnupghome='/path/to/keyring/directory')
>>> gpg.list_keys()
[{
  ...
  'fingerprint': 'F819EE7705497D73E3CCEE65197D5DAC68F1AAB2',
  'keyid': '197D5DAC68F1AAB2',
  'length': '1024',
  'type': 'pub',
  'uids': ['', 'Gary Gross (A test user) ']},
 {
  ...
  'fingerprint': '37F24DD4B918CC264D4F31D60C5FEFA7A921FC4A',
  'keyid': '0C5FEFA7A921FC4A',
  'length': '1024',
  ...
  'uids': ['', 'Danny Davis (A test user) ']}]
>>> encrypted = gpg.encrypt("Hello, world!", ['0C5FEFA7A921FC4A'])
>>> str(encrypted)
'-BEGIN PGP MESSAGE-\nVersion: GnuPG v1.4.9 (GNU/Linux)\n
\nhQIOA/6NHMDTXUwcEAf
...
-END PGP MESSAGE-\n'
>>> decrypted = gpg.decrypt(str(encrypted), passphrase='secret')
>>> str(decrypted)
'Hello, world!'
>>> signed = gpg.sign("Goodbye, world!", passphrase='secret')
>>> verified = gpg.verify(str(signed))
>>> print "Verified" if verified else "Not verified"
'Verified'

For more information, visit http://code.google.com/p/python-gnupg/ -
as always, your feedback is most welcome (especially bug reports,
patches and suggestions for improvement). Enjoy!

Cheers

Vinay Sajip
Red Dove Consultants Ltd.
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Thorough Python 2.7.3 Windows Build Documentation?

2013-01-17 Thread Leonard, Arah
>Try dumping the build configuration parameters:
>
>   >>> import pprint, sysconfig
>   >>> pprint.pprint(sysconfig.get_config_vars())
>
>Then you can compare the existing version with yours.

I would absolutely love to be able to do that and have it work.  Most 
unfortunately that only works on *nix OSes.  The Python sysconfig module's 
config vars are almost non-existent on Windows with a really tiny and almost 
useless subset.  :(  I really wish someone would fix that, but hey, it's free 
so I'm not complaining.  Just wishing.  In case anyone else didn't know that, 
here's the results containing the complete and total list of config vars on 
Windows:

>>> import pprint, sysconfig
>>> pprint.pprint(sysconfig.get_config_vars())
{'BINDIR': 'C:\\Python27',
 'BINLIBDEST': 'C:\\Python27\\Lib',
 'EXE': '.exe',
 'INCLUDEPY': 'C:\\Python27\\Include',
 'LIBDEST': 'C:\\Python27\\Lib',
 'SO': '.pyd',
 'VERSION': '27',
 'base': 'C:\\Python27',
 'exec_prefix': 'C:\\Python27',
 'platbase': 'C:\\Python27',
 'prefix': 'C:\\Python27',
 'projectbase': 'C:\\Python27',
 'py_version': '2.7.3',
 'py_version_nodot': '27',
 'py_version_short': '2.7',
 'srcdir': 'C:\\Python27',
 'userbase': 'C:\\Documents and Settings\\Administrator\\Application 
Data\\Python'}

That's it.  It's actually also a common cause of problems in distutils and the 
likes when people write their module installers for Linux and never test those 
scriptlets on Windows, not realizing that in Python on Windows the sysconfig / 
distutils.sysconfig config vars are hamstrung like that.
-- 
http://mail.python.org/mailman/listinfo/python-list


Islam In Brief

2013-01-17 Thread BV BV
Islam In Brief


Islam in Brief is the first part of The Fog is Lifting series of
documentaries

 challenging your knowledge about the Islamic faith and

traditions


http://www.youtube.com/profile?user=IslamInBrief#g/p


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


Re: Thorough Python 2.7.3 Windows Build Documentation?

2013-01-17 Thread Stefan Krah
Leonard, Arah  wrote:
> By the way, do you happen to know how tricky it is to get Python 2.7.3 to 
> build with VS 2010?  Or have any tips there?  It doesn't seem to be 
> officially supported, but it sure would be nice to get out of the dark ages 
> of MS compilers and be only one version behind the latest.

I wouldn't attempt it. For Python 3.3 the conversion has been done and the diff
was enormous.


Stefan Krah


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


Have You Ever Used Evernote API?

2013-01-17 Thread Jillian
Hey Guys,

Im with User Research and we're currently doing a National Research Study for 
Devs who have used the Evernote API.  The study is just a 90 minute phone call 
and all participants will receive their choice of technical software, hardware, 
or videogames.  If you're interested in participating, please feel free to 
email me Jillian at ucco...@microsoft.com

This study is for residents of the US only at this time. Thanks!

Jillian
User Research
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: Thorough Python 2.7.3 Windows Build Documentation?

2013-01-17 Thread Leonard, Arah
Hello Python programmers,

Here's an update on my conundrum:  When compiling and building CPython 
2.7.3 for Win32 from source I see a 30% performance loss from the precompiled 
binaries in the Python 2.7.3 MSI.  Everything that I do gets the same results.  
I've tried a standard release build.  I've tried a PGO build by running 
build_pgo.bat.  I've tried changing every compile and link optimization flag 
manually.  I've tried VS 2008 Professional with SP1 and hotfixes applied, and 
then without.  I've even tried building on two different PCs just in case.  I 
always get the same results: 30% less performance than the precompiled 
binaries.  Frankly, I'm out of things to try.  All that I can imagine at this 
point is that maybe a different edition of VS 2008 creates a 30% faster 
executable than the Professional edition I have access to?  If anyone has 
specific knowledge of the exact build machine hardware and compiler version 
used to create the Win32 Python 2.7.3 precompiled binaries I would greatly 
appreciate knowin
 g how to duplicate that verbatim.  Thanks.

Sincerely,
Arah Leonard
-- 
http://mail.python.org/mailman/listinfo/python-list


Warning for users of the Python and Jython wiki

2013-01-17 Thread Steven D'Aprano
Hello all,

Some time recently, the wiki at http://wiki.python.org/ was hacked. The 
vandal who broke in deleted all the wiki data. However, it is possible 
that before destroying the data, he may have gained access to user 
passwords.

If you had an account on the wiki, and use the same password elsewhere, 
then you should change that password immediately.

In general, you should not use the same password for multiple systems, 
and naturally once a password has been (potentially) compromised, never 
use it, or trivial modifications of it, again.

http://thehackernews.com/2013/01/official-debian-and-python-wiki-servers.html#_



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


Re: Loading a PKCS#1 public key using M2Crypto

2013-01-17 Thread Piet van Oostrum
Marc Aymerich  writes:

> Thank you very much Piet, 
> I'm just starting to grasp these cryptography related concepts and your code 
> is helping me a lot to understand how to handle these keys in a low level.
>
> I'm updating my code incorporating your new contribution!
>
> Just to let you know, during my previous research I had found a python-Crypto 
> related solution that also uses DER and ASN.1 [1], but it uses a different 
> approach (I guess). I suspect that this approach is also possible with 
> M2Crypto because it has a method for constructing RSA keys [2]. 
>
> [1] http://stackoverflow.com/a/10574723
> [2] 
> http://www.heikkitoivonen.net/m2crypto/api/M2Crypto.RSA-module.html#new_pub_key
>
new_pub_key could be used but then you would have to do an ASN.1 parse
of the DER format of your key to get the n and e values. AFAICT M2Crypto
doesn't have methods to do this, so you would need to use one of the
python ASN.1 libraries (or write that part yourself).
-- 
Piet van Oostrum 
WWW: http://pietvanoostrum.com/
PGP key: [8DAE142BE17999C4]
-- 
http://mail.python.org/mailman/listinfo/python-list


College Physics 9th edition by Sears, Zemansky

2013-01-17 Thread kalvinmanual1
I have solutions manuals to all problems and exercises in these textbooks. To 
get one in an electronic format contact me at: kalvinmanual(at)gmail(dot)com 
and let me know its title, author and edition. Please this service is NOT free.

solutions manual :: CALCULO VECTORIAL 7th Ed. by Louis Leithold
solutions manual :: Calculus  8th Edition by Varberg, Purcell, Rigdon
solutions manual :: Calculus - Early Transcendentals, 6th E, by Anton, Bivens, 
Davis
solutions manual :: Calculus - Early Transcendentals, 7E, by Anton, Bivens, 
Davis
solutions manual :: Calculus - Late Transcendentals Single Variable, 8th Ed by 
Anton, Bivens, Davis
solutions manual :: Calculus ( 9th Ed., Dale Varberg, Edwin Purcell & Steve 
Rigdon)
solutions manual :: Calculus 2nd edition-M. Spivak
solutions manual :: Calculus 3rd Ed by Michael Spivak
solutions manual :: Calculus 6th ed by James Stewart
solutions manual :: Calculus 8th Ed by Ron Larson, Robert P. Hostetler, Bruce 
H. Edwards
solutions manual :: Calculus A Complete Course 6th Edition by by R.A. Adams
solutions manual :: CALCULUS An Intuitive and Physical Approach 2nd ed by 
Morris Kline
solutions manual :: Calculus and its Applications (11th Ed., Larry J Goldstein, 
Schneider, Lay &  Asmar)
solutions manual :: Calculus by Gilbert Strang
solutions manual :: Calculus early transcendentals  8th Ed, by Anton Bivens 
Davis
solutions manual :: Calculus Early Transcendentals, 5th Edition, JAMES STEWART
solutions manual :: Calculus George Thomas 10th ed  Vol 1
solutions manual :: Calculus of Variations MA 4311 LECTURE NOTES ( Russak )
solutions manual :: Calculus On Manifolds by Spivak
solutions manual :: Calculus One & Several Variables 8e by S Salas
solutions manual :: Calculus Vol 2 by Apostol
solutions manual :: CALCULUS VOL.1 , 2nd edition by Tom M. Apostol
solutions manual :: Calculus Volume 1 by J. Marsden, A. Weinstein
solutions manual :: Calculus With Analytic Geometry 4th ( Henry Edwards & David 
E. Penney)
solutions manual :: Calculus with Applications 8 Edition by Lial, Greenwell,  
Ritchey
solutions manual :: Calculus, 4th edition stewart
solutions manual :: Calculus, An Applied Approach, 7E, by Larson
solutions manual :: Calculus, Early Transcendentals 7 Ed by Edwards & Penney
solutions manual :: Calculus, Single and Multivariable, 4E.,Vol 1& Vol 2 by 
Hughes-Hallett,McCallum
solutions manual :: Calculus, Single Variable, 3E by Hughes-Hallett,McCallum
solutions manual :: Chemical and Engineering Thermodynamics 3Ed by Stanley I. 
Sandler
solutions manual :: Chemical Engineering Design (Coulson & Richardson's 
Chemical Engineering - Volume 6) - (4th Ed., Sinnott)
solutions manual :: Chemical Engineering Volume 1, 6th Edition, by Richardson, 
Coulson,Backhurst, Harker
solutions manual :: Chemical, Biochemical, and Engineering Thermodynamics, 4th 
Ed by Sandler
solutions manual :: Chemistry 2nd Edition Vol.1 by Julia Burdge
solutions manual :: Chemistry, 10th Ed by Chang
solutions manual :: Chip Design for Submicron VLSI CMOS Layout and Simulation, 
John P. Uyemura
solutions manual :: Cisco Technical Solution Series IP Telephony Solution Guide 
Version 2.0
solutions manual :: Classical Dynamics of Particles and Systems, 5th Ed, by 
Marion, Thornton
solutions manual :: Classical Dynamics, A Contemporary Approach (Jorge V. Jose)
solutions manual :: Classical Electrodynamics 2nd edition by John David Jackson
solutions manual :: Classical Electrodynamics by John David Jackson
solutions manual :: Classical Electrodynamics by Kasper Van Wijk
solutions manual :: Classical Mechanics (Douglas Gregory)
solutions manual :: Classical Mechanics 2nd Ed by Goldstein
solutions manual :: CMOS Analog Circuit Design, 2ed by Phillip E. Allen, 
Douglas R. Holberg
solutions manual :: CMOS- Circuit Design, Layout, and Simulation, Revised 2nd 
Ed by R. Jacob Baker
solutions manual :: Cmos Digital Integrated Circuits , Sung-Mo Kang,Yusuf 
Leblebici
solutions manual :: CMOS Mixed-Signal Circuit Design, 2nd Ed by  R. Jacob Baker
solutions manual :: CMOS VLSI Design Circuit & Design Perspective 3rd Ed by 
Haris & West
solutions manual :: College Algebra 8th Ed by Michael Sullivan
solutions manual :: COLLEGE ALGEBRA AND TRIGONOMETRY 6th E  by Aufmann, Barker, 
Verity
solutions manual :: College Geometry A Discovery Approach 2nd E by David Kay
solutions manual :: College Physics 8 ED by Serway, Faughn, Vuille
solutions manual :: College Physics 9 ED by Serway, Faughn, Vuille
solutions manual :: College Physics 9th edition by Sears, Zemansky
solutions manual :: Communication Networks, 2e, Alberto Leon-Garcia, Indra 
Widjaja
solutions manual :: Communication Systems (4th Ed., Simon Haykin)
solutions manual :: Communication Systems An Introduction to Signals and Noise 
in Electrical Communication, 4E, A. Bruce Carlson
solutions manual :: Communication Systems Engineering (2nd Ed., John G. Proakis 
& Masoud Salehi)
solutions manual :: Complex Variables and Applications 7 ed by JW Brown RV 
Churchill
sol

[HELP!] a doubt about entering password in python

2013-01-17 Thread douxin

Hi all:

   i have some doubts in doing python programming

   i wanted to execute a command "su -c 'fdisk -l'",and it needed a
   password
   so i wanted to write a python script to get this done.

   i knew 'pexpect' would work fine,but i had to set a certain timeout
   to take care of the real delay time which i probably didn't know

   i tried to use 'subprocess' to do this,however,it did not work
   well,and came the problem

   i use Popen to execute "su -c 'fdisk -l'" in sub process,and
   assigned subprocess.PIPE to stdin,stdout
   i tried to enter password by doing "stdin.write("password"+"\n")"
   and i expected i could get the output of "fdisk -l" by doing
   "stdout.read()"
   it didn't work.

   will somebody tell me what is going on with that?
   i'll appreciate i can learn from you

   Dou

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


Re: [HELP!] a doubt about entering password in python

2013-01-17 Thread Steven D'Aprano
On Fri, 18 Jan 2013 10:49:30 +0800, douxin wrote:

> i use Popen to execute "su -c 'fdisk -l'" in sub process,and
> assigned subprocess.PIPE to stdin,stdout i tried to enter password
> by doing "stdin.write("password"+"\n")" and i expected i could get
> the output of "fdisk -l" by doing "stdout.read()"
> it didn't work.
> 
> will somebody tell me what is going on with that?

Would you like us to guess what happened? I love guessing games!

My guess is that it output "su: incorrect password", which means you have 
the wrong password. Is that it?

If not, my guess is that it output "fdisk: command not found", in which 
case your system is broken and the fdisk binary is missing or not on the 
PATH. Am I close?

Last guess: you got a Python traceback with an error:

NameError: name 'subprocess' is not defined

You need to import the subprocess first.


If none of my guesses are correct, could we have some hints? Perhaps show 
us the actual code you are using, and the actual results, copied and 
pasted exactly.

Thank you.


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


Re: Param decorator - can you suggest improvements

2013-01-17 Thread Dan Sommers
On Thu, 17 Jan 2013 15:21:08 +, Steven D'Aprano wrote:

> On Thu, 17 Jan 2013 06:35:29 -0800, Mark Carter wrote:
> 
>> I thought it would be interesting to try to implement Scheme SRFI 39
>> (Parameter objects) in Python.
>> 
>> The idea is that you define a function that returns a default value. If
>> you call that function with no arguments, it returns the current
>> default. If you call it with an argument, it resets the default to the
>> value passed in. Here's a working implementation:
> [...]
>> Can anyone suggest a better implementation?
> 
> I don't like the decorator version, because it requires creating a do-
> nothing function that just gets thrown away. He's my version, a factory 
> function that takes two arguments, the default value and an optional 
> function name, and returns a Param function:
> [...]

This, or something like this, is very old:

sentinel = object()
class Magic:
def __init__(self, value):
self.value = value
def __call__(self, value=sentinel):
if value != sentinel:
self.value = value
return self.value

It's not a function, nor a decorator, but it behaves like a function.  
I'm pretty sure that it's from Alex Martelli, and ended up as an 
ActiveState recipe at some point, but I can't find it now (I didn't look 
very hard).  It may have been called Magic, or it may have been called 
Pocket.  And the sentinel may have been None, but then you can't set the 
value to None (at least not through the apparent API).

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


Re: [HELP!] a doubt about entering password in python

2013-01-17 Thread MRAB

On 2013-01-18 03:12, Steven D'Aprano wrote:

On Fri, 18 Jan 2013 10:49:30 +0800, douxin wrote:


i use Popen to execute "su -c 'fdisk -l'" in sub process,and
assigned subprocess.PIPE to stdin,stdout i tried to enter password
by doing "stdin.write("password"+"\n")" and i expected i could get
the output of "fdisk -l" by doing "stdout.read()"
it didn't work.

will somebody tell me what is going on with that?


Would you like us to guess what happened? I love guessing games!

My guess is that it output "su: incorrect password", which means you have
the wrong password. Is that it?

If not, my guess is that it output "fdisk: command not found", in which
case your system is broken and the fdisk binary is missing or not on the
PATH. Am I close?

Last guess: you got a Python traceback with an error:

NameError: name 'subprocess' is not defined

You need to import the subprocess first.


If none of my guesses are correct, could we have some hints? Perhaps show
us the actual code you are using, and the actual results, copied and
pasted exactly.

It may, of course, be that for security reasons it won't accept a 
password from
whatever happens to be connected to stdin, but instead insists that it's 
entered

directly from the keyboard, if you see what I mean.
--
http://mail.python.org/mailman/listinfo/python-list


Re: [HELP!] a doubt about entering password in python

2013-01-17 Thread Ramchandra Apte
On Friday, January 18, 2013 9:30:29 AM UTC+5:30, MRAB wrote:
> On 2013-01-18 03:12, Steven D'Aprano wrote:
> 
> > On Fri, 18 Jan 2013 10:49:30 +0800, douxin wrote:
> 
> >
> 
> >> i use Popen to execute "su -c 'fdisk -l'" in sub process,and
> 
> >> assigned subprocess.PIPE to stdin,stdout i tried to enter password
> 
> >> by doing "stdin.write("password"+"\n")" and i expected i could get
> 
> >> the output of "fdisk -l" by doing "stdout.read()"
> 
> >> it didn't work.
> 
> >>
> 
> >> will somebody tell me what is going on with that?
> 
> >
> 
> > Would you like us to guess what happened? I love guessing games!
> 
> >
> 
> > My guess is that it output "su: incorrect password", which means you have
> 
> > the wrong password. Is that it?
> 
> >
> 
> > If not, my guess is that it output "fdisk: command not found", in which
> 
> > case your system is broken and the fdisk binary is missing or not on the
> 
> > PATH. Am I close?
> 
> >
> 
> > Last guess: you got a Python traceback with an error:
> 
> >
> 
> > NameError: name 'subprocess' is not defined
> 
> >
> 
> > You need to import the subprocess first.
> 
> >
> 
> >
> 
> > If none of my guesses are correct, could we have some hints? Perhaps show
> 
> > us the actual code you are using, and the actual results, copied and
> 
> > pasted exactly.
> 
> >
> 
> It may, of course, be that for security reasons it won't accept a 
> 
> password from
> 
> whatever happens to be connected to stdin, but instead insists that it's 
> 
> entered
> 
> directly from the keyboard, if you see what I mean.

I think you are correct - su uses some tty magic to stop ECHO and probably 
doesn't read the password from stdin.
-- 
http://mail.python.org/mailman/listinfo/python-list


Parent module adsite.adsiteviews.mainhanlder does not exist

2013-01-17 Thread Nick Dong
I created a django project using django 1.4.2. There is one 'app'(adsite) in 
this project. And It works. But when I copied some 'py' files into the 'app' 
folder, I got "Parent module adsite.adsiteviews.mainhanlder does not exist." 
Should I register the new files to __init__ in the 'app'? Did new coped files 
break the "import" rules?

views.py

from django.http import HttpResponse
from django.template import Context, loader
from adsite.models import UserInfo

def showusers(request):
userlist = UserInfo.objects.all()
c = Context({
'userlist':userlist,
})
t = loader.get_template('users.html')

return HttpResponse(t.render(c))

copied file: adsiteviews.py

class mainhanlder(TemplateView)
def get(self):
""" """
variables = {
'user': self.get_current_user(),
'mchosts' : MCHOSTS, 
'servers' : servers}

index_templ = tmpl_lookup.get_template("index.html")
body = index_templ.render(**variables)
self.write(body)

urls.py

urlpatterns = patterns('',
# Examples:
url(r'^$', 'adsite.adsiteviews.mainhandler.as_View()'),
url(r'^users/$', 'adsite.views.showusers'),

I have no clues about this problem. any suggestions would be appreciated. thx 
for your time.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [HELP!] a doubt about entering password in python

2013-01-17 Thread Chris Angelico
On Fri, Jan 18, 2013 at 3:45 PM, Ramchandra Apte  wrote:
> I think you are correct - su uses some tty magic to stop ECHO and probably 
> doesn't read the password from stdin.

I believe that's right, but the 'sudo' command - at least on my Debian
and Ubuntu systems - accepts a -S parameter to read from stdin instead
of the terminal. Actually, sudo might be better suited to the OP's
task anyway, if it's available.

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


Re: python sys.stdout and C++ iostreams::cout

2013-01-17 Thread Lie Ryan

On 18/01/13 02:02, Utpal Sarkar wrote:

Hi,

I was assuming that sys.stdout would be referencing the same physical stream as 
iostreams::cout running in the same process, but this doesn't seem to be the 
case.
The following code, which makes a call to a C++ function with a python wrapper called 
"write", that writes to cout:

from cStringIO import StringIO
import sys
orig_stdout = sys.stdout
sys.stdout = stringout = StringIO()
write("cout") # wrapped C++ function that writes to cout
print "-" * 40
print "stdout"
sys.stdout = orig_stdout
print stringout.getvalue()

immediately writes "cout" to the console, then the separator "---...", and finally, as 
the return value of stringout.getvalue(), the string "stdout".
My intention was to capture in stringout also the string written to cout from 
C++.
Does anyone know what is going on, and if so, how I can capture what is written 
to cout in a python string?

Thanks in advance.



You might have a better luck if you check std::ios::rdbuf 
(http://www.cplusplus.com/reference/ios/ios/rdbuf/)


Using std::ios::rdbuf() you can get the cout's streambuf, which is a 
filebuf for the stdout and then use std::ios::rdbuf(streambuf*) to 
replace cout's internal streambuf and replace it with your own 
implementation that captures everything written using cout before 
passing it back to the original streambuf.


This is essentially similar to assigning to sys.stdout in python.

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


Re: To make a method or attribute private

2013-01-17 Thread Lie Ryan

On 17/01/13 11:34, iMath wrote:

To make a method or attribute private (inaccessible from the outside),
simply start its name with two underscores

《Beginning Python From Novice to Professional》

but there is another saying goes:
Beginning a variable name with a single underscore indicates that the
variable should be treated as ‘private’.

I test both these 2 rules ,it seems only names that start with two
underscores are REAL private methods or attributes .


Python does not have a REAL private methods/attributes. The double 
leading underscore is meant to trigger name mangling to avoid naming 
collisions with subclasses, the method/attribute is still accessible 
using the mangled name:


>>> ap._A__a
'__a'

You generally only use double leading underscores when your private 
method/attribute is in a very high risk of having naming clashes with 
superclasses/subclasses.


> so what is your opinion about single leading underscore and private
> methods or attributes?

We're all consenting adults. Use methods/attributes with single or 
double leading underscore at your own risk.


Most programming languages do not actually have a private attribute that 
is totally inaccessible from outside, there are usually ways work around 
access restrictions, usually using reflections or pointers. Python only 
makes it easy to do so by making private variables only a convention.


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