Re: Using pdb with greenlet?

2012-06-13 Thread Dieter Maurer
Salman Malik  writes:

> I am sort of a newbie to Python ( have just started to use pdb).
> My problem is that I am debugging an application that uses greenlets and when
> I encounter something in code that spawns the coroutines or wait for an event,
> I lose control over the application (I mean that after that point I can no
> longer do 'n' or 's' on the code). Can anyone of you tell me how to tame
> greenlet with pdb, so that I can see step-by-step as to what event does a
> coroutine sees and how does it respond to it.
> Any help would be highly appreciated.

Debugging works via the installation of a "tracehook" function. If such a
function is installed in a thread, the Python interpreter calles back
via the installed hook to report events relevant for debugging.
Usually the hook function is defined by a debugger which examines
whether the event is user relevant (e.g. if a breakpoint has been hit,
or code for a new line has been entered) and in this case imforms
the user and may give him control.

It is important that the trace hook installation is thread specific. Otherwise,
debugging in a multithreaded environment would be a nightmare - as
events from multiple threads may arrive and seriously confuse
the debugger as well as the user.


I do not know "greenlet". However, I expect that it uses threads
under the hood to implement coroutines. In such a case, it would
be natural that debugging one coroutine would not follow the
execution into a different coroutine.

To change this, "greenlet" would need to specially support
the "tracehook" feature: when control is transfered to a different
coroutine, the "tracehook" would need to be transfered as well.
Personally, I am not sure that this would be a good idea
(I sometimes experience debugging interaction from different threads --
and I can tell you that it is a really nasty experience).

However, you can set the "tracehook" youself in your each of your
coroutines: "import pdb; pdb.set_trace()". This is called a "code breakpoint".
It installs the debuggers "tracehook" function in the current thread
and gives control to the debugger (i.e. it works like a breakpoint).
I use this quite frequently to debug multithreaded web applications
and it works quite well (sometimes with nasty experiences).

"pdb" is not optimal to for multithread debugging because it expects
to interact with a single thread only. For a good experience,
a thread aware extension would be necessary.

--
Dieter


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


Re: [newbie] Equivalent to PHP?

2012-06-13 Thread Steven D'Aprano
On Tue, 12 Jun 2012 12:36:36 +0200, Gilles wrote:

> I enjoy writing scripts in Python much more than PHP, but with so many
> sites written in PHP, I need to know what major benefits there are in
> choosing Python (or Ruby, ie. not PHP).

The main benefit is that they are not PHP.

http://me.veekun.com/blog/2012/04/09/php-a-fractal-of-bad-design/

and especially lack PHP's security vulnerabilities.



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


Re: multiprocessing: excepthook not getting called

2012-06-13 Thread Philipp Hagemeister
multiprocessing just mimicks the threading module here, see
http://bugs.python.org/issue1230540 . Why do you need excepthook in the
first place?

You can perfectly simulate it by wrapping the root method (target in
your example) in a try .. catch:

import multiprocessing
import sys

def printErrors(func):
def wrapped(*args, **kwargs):
try:
func()
except:
print ('except: ', sys.exc_info())
return wrapped

@printErrors
def target():
raise ValueError()

if __name__ == '__main__':
p = multiprocessing.Process(target=target)
p.start()
p.join()
# try it here in main
target()


Cheers,

Philipp


On 06/12/2012 11:02 PM, Dave Cook wrote:
> Why doesn't my excepthook get called in the child process?
>
> import sys
> import multiprocessing as mp
>
> def target():
> name = mp.current_process().name
> def exceptHook(*args):
> print 'exceptHook:', name, args
> sys.excepthook = exceptHook
> raise ValueError
>
> if __name__=='__main__':
> p = mp.Process(target=target)
> p.start()
> p.join()
> # try it here in main
> target()
>
> Thanks,
> Dave Cook




signature.asc
Description: OpenPGP digital signature
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: multiprocessing: excepthook not getting called

2012-06-13 Thread Philipp Hagemeister


On 06/13/2012 11:00 AM, Dave Cook wrote:
> Originally, I was trying to send formatted
> tracebacks back to the main process on a queue.
You can still do that:

import multiprocessing
import sys

def queueErrors(q):
def decorator(func):
def wrapped(*args, **kwargs):
try:
func()
except:
q.put((multiprocessing.current_process().name,
repr(sys.exc_info(
return wrapped
return decorator

q = multiprocessing.Queue()

@queueErrors(q)
def target():
raise ValueError()

if __name__ == '__main__':
p = multiprocessing.Process(target=target)
p.start()
p.join()
# try it here in main
while True:
pname,exc = q.get()
print('Caught error in process %r: %s' % (pname, exc))

It gets somewhat harder when you also want to catch termination of
threads, but you can just queue a special message.

- Philipp



signature.asc
Description: OpenPGP digital signature
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [newbie] Equivalent to PHP?

2012-06-13 Thread Gilles
On Wed, 13 Jun 2012 10:19:29 +1000, Chris Angelico 
wrote:
>It's far simpler to manage, it retains running state, and is easily
>enough encapsulated. It's the non-magic way of doing things. Also, it
>plays very nicely with the MUD style of process, which is something I
>do a lot with Pike. Plus, if you manage it right, you have a guarantee
>that you can never be in a half-updated state - that's somewhat tricky
>when you have inter-dependencies in PHP code and the file system
>itself manages things. What happens if a request comes in while you're
>half-way through uploading new code to the server? By default, you
>could use half old code and half new code. Keeping everything in
>memory makes it easier to prevent that.

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


Re: [newbie] Equivalent to PHP?

2012-06-13 Thread Gilles
On 13 Jun 2012 08:29:05 GMT, Steven D'Aprano
 wrote:
>http://me.veekun.com/blog/2012/04/09/php-a-fractal-of-bad-design/
>
>and especially lack PHP's security vulnerabilities.

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


Re: [newbie] Equivalent to PHP?

2012-06-13 Thread Gilles
On Tue, 12 Jun 2012 16:48:27 +0200, Matej Cepl 
wrote:
>I don't think it is a proper description of the situation (please, 
>somebody correct my mistakes, I am not 100% sure about it myself). WSGI 
>applications (which is basically all web applications in Python) could 
>run in the hosted servers (using for example mod_wsgi for Apache), and I 
>would expect that it is the situation with most production uses.

I have a couple more questions:

1. Today what is the recommended way to connect a long-running Python
web application with a web server running in the front? FastCGI? WSGI?
Other?

2. Which solid web server is recommended to connect to Python web
applications in the back?

3. What Python web framework would you recommend to get started, and
possibly more heavy duty framework in case I need something bigger
later?

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


Re: [newbie] Equivalent to PHP?

2012-06-13 Thread Chris Angelico
On Wed, Jun 13, 2012 at 7:25 PM, Gilles  wrote:
> I have a couple more questions:
>
> 1. Today what is the recommended way to connect a long-running Python
> web application with a web server running in the front? FastCGI? WSGI?
> Other?
>
> 2. Which solid web server is recommended to connect to Python web
> applications in the back?
>
> 3. What Python web framework would you recommend to get started, and
> possibly more heavy duty framework in case I need something bigger
> later?

There are quite a few Python web frameworks, but I've never used any.
What I have done, though, is subclass
BaseHTTPServer.BaseHTTPRequestHandler, override do_GET(self), and run
a core loop with a single line of code (well, there's a little more so
the server can be halted cleanly with Ctrl-C, but close enough). And
it runs beautifully on Windows and Linux, and would probably run on
any other platform with a Python, if anyone felt like trying.it.
However, there are times when you need a little more organization, and
I don't know how easy it is to minimize downtime when you need to
update code (with this particular example, I just restart it and have
a couple of minutes' outage, which isn't an issue).

For high-availability servers, I can't speak for Python, as I've never
done that there; but it seems likely that there's good facilities. My
personal preference is Pike, but that's off-topic for this list. :)
But the simple answer for simple tasks is: Don't bother with
frameworks, run an HTTP server.

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


Re: [newbie] Equivalent to PHP?

2012-06-13 Thread Gilles
On Wed, 13 Jun 2012 19:41:41 +1000, Chris Angelico 
wrote:
>For high-availability servers, I can't speak for Python, as I've never
>done that there; but it seems likely that there's good facilities. My
>personal preference is Pike, but that's off-topic for this list. :)
>But the simple answer for simple tasks is: Don't bother with
>frameworks, run an HTTP server.

Thanks. What do you mean with "Don't bother with frameworks, run an
HTTP server"? Subclassing BaseHTTPServer?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [newbie] Equivalent to PHP?

2012-06-13 Thread Chris Angelico
On Wed, Jun 13, 2012 at 7:49 PM, Gilles  wrote:
> On Wed, 13 Jun 2012 19:41:41 +1000, Chris Angelico 
> wrote:
>>For high-availability servers, I can't speak for Python, as I've never
>>done that there; but it seems likely that there's good facilities. My
>>personal preference is Pike, but that's off-topic for this list. :)
>>But the simple answer for simple tasks is: Don't bother with
>>frameworks, run an HTTP server.
>
> Thanks. What do you mean with "Don't bother with frameworks, run an
> HTTP server"? Subclassing BaseHTTPServer?

Apache is a web server, by which one technically means an HTTP server.
HTTP is the protocol (HyperText Transfer Protocol) by which web
servers and browsers communicate. Basically, you listen on a TCP/IP
socket, usually port 80, and respond to requests.

One way to achieve that is to let somebody else do the whole
listen-on-80 bit and then call upon you to generate a block of text.
That's what happens with Apache and PHP - your PHP script doesn't
think about sockets, listening, and so on, it just gets a request and
deals with it.

The other obvious option is to write your own code using the basic BSD
socket functions, and do the whole job yourself. That's a good thing
to do once in a while, just to get to know how it all fits together,
but unless you're working in C, there's no particular reason to go to
that much hassle.

Half way in between is where BaseHTTPServer puts you. All the
grunt-work is done for you, but your program is still 100% in control.
You call on somebody else's code (the Python standard library) to
handle all the socket basics, and your code gets called to generate a
page. But you can do more than just generate a page, if you so desire.

Most high level languages probably have some sort of HTTP server
available. Some make it trivially easy to plug some code in and start
serving. Python is advertised as "batteries included", and one of its
packets of batteries is a fairly full-featured set of internet
protocol handlers.

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


validating XML

2012-06-13 Thread andrea crotti
Hello Python friends, I have to validate some xml files against some xsd
schema files, but I can't use any cool library as libxml unfortunately.

A Python-only validator might be also fine, but all the projects I've
seen are partial or seem dead..

So since we define the schema ourselves, I was allowed to only implement
the parts of the huge XML definition that we actually need.

Now I'm not quite sure how to do the validation myself, any suggestions?

I thought that I could first parse and store in memory the schema, then
iterate over the XML I need to validate and do the needed sanity checks
there.

So I might use or minidom.parse or ElementTree.parse, which both look
fine even if I'm not sure which one is more suitable.

Another thing is that I would like to be able that if the schema changes
my validation is still correct, so I would need some sort of meta-schema
that declares all the XML constructs that I'm allowed to use.

Anyone did something like this?
Thanks,
Andrea
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [newbie] Equivalent to PHP?

2012-06-13 Thread Gilles
On Wed, 13 Jun 2012 20:00:59 +1000, Chris Angelico 
wrote:
>Most high level languages probably have some sort of HTTP server
>available. Some make it trivially easy to plug some code in and start
>serving. Python is advertised as "batteries included", and one of its
>packets of batteries is a fairly full-featured set of internet
>protocol handlers.

Thanks for the longer explanation. With so many frameworks, I'd like
to know what benefits they offer as compared to writing an application
from scratch, and if they do offer obvious benefits, which one to pick
:-/

http://wiki.python.org/moin/WebFrameworks
-- 
http://mail.python.org/mailman/listinfo/python-list


network protocols

2012-06-13 Thread Tarek Ziadé

Hey

I was surprised not to find any way to list all protocol names listed in 
/etc/protocols in Python


We have

socket.getprotobyname(NAME)

But there's no way to get the list of names

Any ideas if this is available in the stdlib somehwere ?

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


Re: Pythonic cross-platform GUI desingers à la Interface Builder (Re: what gui designer is everyone using)

2012-06-13 Thread Wolfgang Keller
> > * Domain experts in fact who would need to implement loads of
> > software to help them get their work done but can't. And since
> > there's no budget for external developers, nothing get's ever done
> > about this.
> Well, typically or at least very often sooner or later something
> gets done about this as someone finds out that all could be solved
> using MS Excel and some macros / VBA programming.

MS Excel is unusable for any kind of serious work, due its serious
design deficiences. But that's off-topic here.

VB(A) is unusable for everyday office automation because it doesn't
offer an interactive commandline interpreter.

Besides, both only run^H^H^Hlimp on a pathologic non-operating system
that's just as unsuitable for any productive work. But that's
off-topic, too.

> I would prefer people to invest the same time into a Python based
> solution.
> But then we're back to the initial point: As long as there's no GUI
> builder for Python, most people will stick to Excel / VBA / VB.

There are quite a few GUI builders out there for Python. The point is
that they are not very "pythonic" imho, i.e. they don't really show
what the advantage of Python is for GUIs over those other languages. And
imho these GUI builders, just like the frameworks that they generate
code for are not very suitable for someone who's not a software
developer by profession. Because they require way too much "glue code".

And unfortunately the origin of this problem seems to be the
open-source development model itself: Since developers of open source
development tools (GUI frameworks, GUI builders etc.) usually
implement these for their own use, and since these people are typically
software developers by profession who come from a C++-dominated
background, they don't see the necessity and they don't have any
motivation to implement anything that would help all those potential
Python users out there who just can't devote the time and effort
required to get over that pretty huge step in the learning curve of
those frameworks and tools.

Please note that this is not meant as criticism to open-source
developers, but as a hint that there might be a business opportunity
for someone here to develop and sell something for money. ;-)

Sincerely,

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


Re: Pythonic cross-platform GUI desingers à la Interface Builder (Re: what gui designer is everyone using)

2012-06-13 Thread Wolfgang Keller
> > Tkinter is imho honestly the very best "argument" if you want to
> > make potential new users turn their backs away from Python for
> > good. Just show them one GUI implemented with it and, hey, wait,
> > where are you running to...
> 
> Yes, Tkinter GUI's are very ugly.
> 
> http://www.codebykevin.com/phynchronicity-running.png
> 
> http://www.codebykevin.com/quickwho-main.png

OK, so after what - one and a half decades? - Tkinter now finally has
caught up with wxPython and PyQt (concerning the look). Which can be
used in an as interactive way from the commandline interpreter as
Tkinter. Argument against Tkinter withdrawn from my side.

But there's afaik still no interactive GUI builder out there for any of
these frameworks, nor a higher level framework that requires less glue
code between bare naked "event handling" and the domain-specific code.
"Event handling" - that term already raises my hair because it stinks
like bulkloads of clumsy, error-prone diligence work that has nothing
to do with the problem I need to get solved.

Sincerely,

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


Re: Pythonic cross-platform GUI desingers à la Interface Builder (Re: what gui designer is everyone using)

2012-06-13 Thread Wolfgang Keller
> No matter how cool it may seem to create simple GUIs manually or to
> write business letters using LaTeX: just try to persuade people to
> move from Word to LaTeX for business letters...

Good example.

I have done nearly exactly this* - but it was only possible thanks to
LyX.

Sincerely,

Wolfgang

*I moved not from Wugh, but from other software to LyX/LaTeX for all my
document processing.
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: network protocols

2012-06-13 Thread John Sutterfield

Tarek, 

There doesn't appear to be a function in stdlib to cover that particular case. 

Doug Hellman has a nice section on finding service info here: 

http://www.doughellmann.com/PyMOTW/socket/addressing.html

It wouldn't be "built-in", but it looks like it would be pretty simple to get 
the info you need. 

Best regards, 

JS

> Date: Wed, 13 Jun 2012 13:41:25 +0200
> From: ta...@ziade.org
> To: python-list@python.org
> Subject: network protocols
> 
> Hey
> 
> I was surprised not to find any way to list all protocol names listed in 
> /etc/protocols in Python
> 
> We have
> 
> socket.getprotobyname(NAME)
> 
> But there's no way to get the list of names
> 
> Any ideas if this is available in the stdlib somehwere ?
> 
> Thx
> Tarek
> -- 
> http://mail.python.org/mailman/listinfo/python-list
  -- 
http://mail.python.org/mailman/listinfo/python-list


Re: Ann: New Stackless Website

2012-06-13 Thread Peter Funk
Christian Tismer wrote on monday, 11.06.2012 at 19:01:
...
> Stackless Python has a New Website
...
> Due to a great effort of the Nagare people:
> 
> http://www.nagare.org/
> 
> and namely by the tremendous work of Alain Pourier,
> 
> Stackless Python has now a new website!
> 
> This is no longer Plone based, but a nicely configured Trac site.

I'm only another user of Plone and I'm only curious:
Would you or someone else care to explain what made you
move away from Plone?  
I think especially the Plone community might also be interested.

Viele Grüße (Best Regards), Peter Funk
-- 
Peter Funk
mobile:+49-179-640-8878 phone:+49-421-20419-0 
office: ArtCom GmbH, ✉Haferwende 2, D-28357 Bremen, Germany
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: network protocols

2012-06-13 Thread Verde Denim
On 6/13/12, John Sutterfield  wrote:
>
> Tarek,
>
> There doesn't appear to be a function in stdlib to cover that particular
> case.
>
> Doug Hellman has a nice section on finding service info here:
>
> http://www.doughellmann.com/PyMOTW/socket/addressing.html
>
> It wouldn't be "built-in", but it looks like it would be pretty simple to
> get the info you need.
>
> Best regards,
>
> JS
>
JS
Very nice link! Great information here.

-- Jack

>> Date: Wed, 13 Jun 2012 13:41:25 +0200
>> From: ta...@ziade.org
>> To: python-list@python.org
>> Subject: network protocols
>>
>> Hey
>>
>> I was surprised not to find any way to list all protocol names listed in
>> /etc/protocols in Python
>>
>> We have
>>
>> socket.getprotobyname(NAME)
>>
>> But there's no way to get the list of names
>>
>> Any ideas if this is available in the stdlib somehwere ?
>>
>> Thx
>> Tarek
>> --
>> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: network protocols

2012-06-13 Thread Christian Heimes
Am 13.06.2012 13:41, schrieb Tarek Ziadé:
> Hey
> 
> I was surprised not to find any way to list all protocol names listed in
> /etc/protocols in Python
> 
> We have
> 
> socket.getprotobyname(NAME)
> 
> But there's no way to get the list of names
> 
> Any ideas if this is available in the stdlib somehwere ?

No, I can't find any reference to the relevant NSS APIs in the Python
code. You can easily roll your own with ctypes:


from ctypes import *
libc = CDLL("libc.so.6")

class protoent(Structure):
_fields_ = [("p_name", c_char_p),
("p_aliases", POINTER(c_char_p)),
("p_proto", c_int)]

libc.getprotoent.restype = POINTER(protoent)

# open database
libc.setprotoent(0)

while True:
pr = libc.getprotoent()
if not pr:
break
r = pr[0]
print r.p_name, r.p_proto

# close database
libc.endprotoent()

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


Re: [newbie] Equivalent to PHP?

2012-06-13 Thread Christian Heimes
Am 12.06.2012 11:39, schrieb Gilles:
> I notice that Python-based solutions are usually built as long-running
> processes with their own web server (or can run in the back with eg.
> Nginx and be reached through eg. FastCGI/WSGI ) while PHP is simply a
> language to write scripts and requires a web server (short running
> processes).

A long running process has lots of benefits that makes design and
development easier and makes your app faster.

* Don't underestimate the costs of process creation. It doesn't scale
unless you fork() childs which is more complex and still doesn't scale
as well as a long running process.

* you can do all costly and time consuming operations on startup like
loading all configuration files and databases like i18n stuff.

* performance tweaks like database connection pool works only with a
long running process.

* in-process caching is usually easier to implement and faster. In some
cases only in-process works.

* you can have background tasks without the requirement of an outside
service like cron + wget.

* async server based on a select()-like reactor are only possible when a
single process handles the incoming connections.


A long running process is more powerful and the 'enterprise' way of
doing it right. All important and large scale Python and Java solutions
are using long running processes instead of a CGI-like model.

PHP's way is a poor man's solution to compensate for bad design and
memory holes. PHP's ancestor PHTML still bleeds through and makes you
suffer for mistakes of the past.

Christian

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


Re: Internationalized domain names not working with URLopen

2012-06-13 Thread Hemanth H.M
Well not really! does not work with '☃.net'

Traceback (most recent call last):
  File "", line 1, in 
  File "/usr/lib/python2.6/urllib2.py", line 126, in urlopen
return _opener.open(url, data, timeout)
  File "/usr/lib/python2.6/urllib2.py", line 391, in open
response = self._open(req, data)
  File "/usr/lib/python2.6/urllib2.py", line 409, in _open
'_open', req)
  File "/usr/lib/python2.6/urllib2.py", line 369, in _call_chain
result = func(*args)
  File "/usr/lib/python2.6/urllib2.py", line 1170, in http_open
return self.do_open(httplib.HTTPConnection, req)
  File "/usr/lib/python2.6/urllib2.py", line 1116, in do_open
h = http_class(host, timeout=req.timeout) # will parse host:port
  File "/usr/lib/python2.6/httplib.py", line 661, in __init__
self._set_hostport(host, port)
  File "/usr/lib/python2.6/httplib.py", line 686, in _set_hostport
raise InvalidURL("nonnumeric port: '%s'" % host[i+1:])
httplib.InvalidURL: nonnumeric port:


On Wed, Jun 13, 2012 at 12:17 PM, Виталий Волков  wrote:

> Answer in this topic should help you to solve issue.
>
>
> http://stackoverflow.com/questions/8152161/open-persian-url-domains-with-urllib2?answertab=active#tab-top
>
>
> Regards.
>
>
> 2012/6/13 John Nagle 
>
>> I'm trying to open
>>
>> http://пример.испытание 
>>
>> with
>>
>> urllib2.urlopen(s1)
>>
>> in Python 2.7 on Windows 7. This produces a Unicode exception:
>>
>> >>> s1
>> u'http://\u043f\u0440\u0438\**u043c\u0435\u0440.\u0438\**
>> u0441\u043f\u044b\u0442\u0430\**u043d\u0438\u0435'
>> >>> fd = urllib2.urlopen(s1)
>> Traceback (most recent call last):
>>  File "", line 1, in 
>>  File "C:\python27\lib\urllib2.py", line 126, in urlopen
>>return _opener.open(url, data, timeout)
>>  File "C:\python27\lib\urllib2.py", line 394, in open
>>response = self._open(req, data)
>>  File "C:\python27\lib\urllib2.py", line 412, in _open
>>'_open', req)
>>  File "C:\python27\lib\urllib2.py", line 372, in _call_chain
>>result = func(*args)
>>  File "C:\python27\lib\urllib2.py", line 1199, in http_open
>>return self.do_open(httplib.**HTTPConnection, req)
>>  File "C:\python27\lib\urllib2.py", line 1168, in do_open
>>h.request(req.get_method(), req.get_selector(), req.data, headers)
>>  File "C:\python27\lib\httplib.py", line 955, in request
>>self._send_request(method, url, body, headers)
>>  File "C:\python27\lib\httplib.py", line 988, in _send_request
>>self.putheader(hdr, value)
>>  File "C:\python27\lib\httplib.py", line 935, in putheader
>>hdr = '%s: %s' % (header, '\r\n\t'.join([str(v) for v in values]))
>> UnicodeEncodeError: 'ascii' codec can't encode characters in position
>> 0-5: ordinal not in range(128)
>> >>>
>>
>> The HTTP library is trying to put the URL in the header as ASCII.  Why
>> isn't "urllib2" handling that?
>>
>> What does "urllib2" want?  Percent escapes?  Punycode?
>>
>>John Nagle
>> --
>> http://mail.python.org/**mailman/listinfo/python-list
>>
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>


-- 
*'I am what I am because of who we all are'*
h3manth.com 
*-- Hemanth HM *
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Internationalized domain names not working with URLopen

2012-06-13 Thread Hemanth H.M
My bad, it worked; need to avoid http:// along with snowman, before encode.

On Wed, Jun 13, 2012 at 9:02 PM, Hemanth H.M  wrote:

> Well not really! does not work with '☃.net'
>
> Traceback (most recent call last):
>   File "", line 1, in 
>   File "/usr/lib/python2.6/urllib2.py", line 126, in urlopen
> return _opener.open(url, data, timeout)
>   File "/usr/lib/python2.6/urllib2.py", line 391, in open
> response = self._open(req, data)
>   File "/usr/lib/python2.6/urllib2.py", line 409, in _open
> '_open', req)
>   File "/usr/lib/python2.6/urllib2.py", line 369, in _call_chain
> result = func(*args)
>   File "/usr/lib/python2.6/urllib2.py", line 1170, in http_open
> return self.do_open(httplib.HTTPConnection, req)
>   File "/usr/lib/python2.6/urllib2.py", line 1116, in do_open
> h = http_class(host, timeout=req.timeout) # will parse host:port
>   File "/usr/lib/python2.6/httplib.py", line 661, in __init__
> self._set_hostport(host, port)
>   File "/usr/lib/python2.6/httplib.py", line 686, in _set_hostport
> raise InvalidURL("nonnumeric port: '%s'" % host[i+1:])
> httplib.InvalidURL: nonnumeric port:
>
>
> On Wed, Jun 13, 2012 at 12:17 PM, Виталий Волков wrote:
>
>> Answer in this topic should help you to solve issue.
>>
>>
>> http://stackoverflow.com/questions/8152161/open-persian-url-domains-with-urllib2?answertab=active#tab-top
>>
>>
>> Regards.
>>
>>
>> 2012/6/13 John Nagle 
>>
>>> I'm trying to open
>>>
>>> http://пример.испытание 
>>>
>>> with
>>>
>>> urllib2.urlopen(s1)
>>>
>>> in Python 2.7 on Windows 7. This produces a Unicode exception:
>>>
>>> >>> s1
>>> u'http://\u043f\u0440\u0438\**u043c\u0435\u0440.\u0438\**
>>> u0441\u043f\u044b\u0442\u0430\**u043d\u0438\u0435'
>>> >>> fd = urllib2.urlopen(s1)
>>> Traceback (most recent call last):
>>>  File "", line 1, in 
>>>  File "C:\python27\lib\urllib2.py", line 126, in urlopen
>>>return _opener.open(url, data, timeout)
>>>  File "C:\python27\lib\urllib2.py", line 394, in open
>>>response = self._open(req, data)
>>>  File "C:\python27\lib\urllib2.py", line 412, in _open
>>>'_open', req)
>>>  File "C:\python27\lib\urllib2.py", line 372, in _call_chain
>>>result = func(*args)
>>>  File "C:\python27\lib\urllib2.py", line 1199, in http_open
>>>return self.do_open(httplib.**HTTPConnection, req)
>>>  File "C:\python27\lib\urllib2.py", line 1168, in do_open
>>>h.request(req.get_method(), req.get_selector(), req.data, headers)
>>>  File "C:\python27\lib\httplib.py", line 955, in request
>>>self._send_request(method, url, body, headers)
>>>  File "C:\python27\lib\httplib.py", line 988, in _send_request
>>>self.putheader(hdr, value)
>>>  File "C:\python27\lib\httplib.py", line 935, in putheader
>>>hdr = '%s: %s' % (header, '\r\n\t'.join([str(v) for v in values]))
>>> UnicodeEncodeError: 'ascii' codec can't encode characters in position
>>> 0-5: ordinal not in range(128)
>>> >>>
>>>
>>> The HTTP library is trying to put the URL in the header as ASCII.  Why
>>> isn't "urllib2" handling that?
>>>
>>> What does "urllib2" want?  Percent escapes?  Punycode?
>>>
>>>John Nagle
>>> --
>>> http://mail.python.org/**mailman/listinfo/python-list
>>>
>>
>>
>> --
>> http://mail.python.org/mailman/listinfo/python-list
>>
>>
>
>
> --
> *'I am what I am because of who we all are'*
> h3manth.com 
> *-- Hemanth HM *
>



-- 
*'I am what I am because of who we all are'*
h3manth.com 
*-- Hemanth HM *
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: validating XML

2012-06-13 Thread andrea crotti
So as far as I understood what I should do is the following.
Go through my own XML keeping track of the full path of everything for
example





and so on, then for every entry found in this iteration, check the schema
to make sure that that particular construct is allowed
on that level of the tree.

I have something like this for example that creates a dictionary from an
element tree element...
Does it make sense or am I going in the wrong direction?


def etree_to_dict(xml_file):
"""Takes the root node from the XML and generates a dictionary
"""
dic = {}
etree = ElementTree.parse(open(xml_file))
root = list(etree.iter())[0]
queue = [root]

while queue:
el = queue.pop()
childs = el.getchildren()
queue += childs
dic[el] = childs

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


Re: validating XML

2012-06-13 Thread Dieter Maurer
andrea crotti  writes:

> Hello Python friends, I have to validate some xml files against some xsd
> schema files, but I can't use any cool library as libxml unfortunately.

Why?
It seems not very rational to implement a complex task (such as
XML-Schema validation) when there are ready solutions around.

> A Python-only validator might be also fine, but all the projects I've
> seen are partial or seem dead..
> So since we define the schema ourselves, I was allowed to only implement
> the parts of the huge XML definition that we actually need.
> Now I'm not quite sure how to do the validation myself, any suggestions?

I would look for a command line tool available
on your platform which performs the validation and
call this from Python.

--
Dieter

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


Re: Pythonic cross-platform GUI desingers à la Interface Builder (Re: what gui designer is everyone using)

2012-06-13 Thread rdsteph
> I think this is the wave of the furture for deploying simple programs
> to many users. It is almost 100% cross platform (can be used on
> desktop, smartphone, tablet, windows, linux, mac etc) and is very easy
> to do, even for casual "non-programmers" who do a little programming
> (such as many engineers).
>
> I think efforts to make a better, and more definitive, "GUI builder"
> for Python should focus on makigng an easy to use "IDE" for creating
> these kinds of Python-HTMl-Javascript front ends for applications.
>
> *That* would really help Python's popularity to take off and expode.
>
> Ron Stephens

Replying to myself, to add this note: I just read the link
likehacker.com/learn-to-code/
about Google's "Blockly" a drag and drop tool for building apps that
outputs Python or Javascript code (among others) and it might be
usable along these lines...I'm sure serious programmers would not use
it but maybe engineers looking to make web front ends
for data acquisition or data base apps might use it...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: validating XML

2012-06-13 Thread Stefan Behnel
andrea crotti, 13.06.2012 12:06:
> Hello Python friends, I have to validate some xml files against some xsd
> schema files, but I can't use any cool library as libxml unfortunately.

Any reason for that? Because the canonical answer to your question would be
lxml, which uses libxml2.

Stefan

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


Re: [newbie] Equivalent to PHP?

2012-06-13 Thread Grant Edwards
On 2012-06-13, Steven D'Aprano  wrote:
> On Tue, 12 Jun 2012 12:36:36 +0200, Gilles wrote:
>
>> I enjoy writing scripts in Python much more than PHP, but with so many
>> sites written in PHP, I need to know what major benefits there are in
>> choosing Python (or Ruby, ie. not PHP).
>
> The main benefit is that they are not PHP.
>
> http://me.veekun.com/blog/2012/04/09/php-a-fractal-of-bad-design/

I just started learning PHP about a week ago in order to do some work
on an embedded device's web site implementation my employer contracted
out.  I've done a fair bit of web stuff using CGI in shell, C, and
Python as well as server-side Javascript.  I've done a lot of normal
application programming in C and Python and have used a smattering of
other languages (Smalltalk, Scheme, Modula, FORTRAN, BASIC, assembly
for a variety of processors, and even Prolog).

I must say that I agree with the assessement of PHP linked above. 
It's not that the language has a design that's not to my taste -- it's
that it has no design at all.  It seems to be a mass of miscellaneous
bits and bobs from other languages that have accreted over the years
via some sort of random-walk process.

PHP seems to encourage (if not require) bad practices such as
returning values from functions via global or instance variables.

-- 
Grant Edwards   grant.b.edwardsYow! !  I'm in a very
  at   clever and adorable INSANE
  gmail.comASYLUM!!
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: [newbie] Equivalent to PHP?

2012-06-13 Thread Prasad, Ramit
> Thanks for the longer explanation. With so many frameworks, I'd like
> to know what benefits they offer as compared to writing an application
> from scratch, and if they do offer obvious benefits, which one to pick

I am going to state up front that I have never tried any of the 
frameworks so take my recommendation with a *lot* of salt! :)

I would recommend Django as it seems to scale up nicely and I know
that it has an active community which can be a godsend for getting
help as a "newbie". That being said it does have a bit of a learning
curve compared to some of the lighter frameworks, but not so much
of one as to counteract the advantage of scalability. Again, this
is all based on opinions that I have read (and remember) and not 
on any facts.

Maybe this article will help you 
http://www.infoworld.com/d/application-development/pillars-python-six-python-web-frameworks-compared-169442
The comments on /. should round out anything missing from the article (I hope)
http://developers.slashdot.org/story/11/08/10/2111203/six-python-web-frameworks-compared


Ramit


Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
712 Main Street | Houston, TX 77002
work phone: 713 - 216 - 5423

--
This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: which one do you prefer? python with C# or java?

2012-06-13 Thread Tomasz Rola
On Tue, 12 Jun 2012, Tim Johnson wrote:

>   I concur, I worked in C and C++ for 12 years. I added C++ later in
>   my programming life. I don't recommend C++ for single programmers.
>   - that is to say - 1 coder for 1 codebase. One can do good enough
>   OOP in ansi C believe it or not, I learned to.
> 
>   It is interesting to note that most of linux is written in C,
>   rather than C++ and is not python as well?

You are right, I remember this was explicitly stated somewhere on usenet 
that Linux kernel was written in object oriented style and AFAIK this is 
true (based on my own lurking into the source).

But I think C++ could and should be used by solo programmers. I just 
suspect once we get past trivial stuff (defining class hierarchies, using 
iostreams, containers and STL and the like), things get a little tricky 
but I cannot say for sure because I am yet to go there.

I probably agree C++ should not be used by solo progs writing very big 
programs, if this is what you mean. I am still researching alternatives, 
but for such endeavour I would rather choose Haskell or CL.

However, I notice, for example, Boost C++ Library and their attempt to 
recreate some aspects of functional language. This gives me idea about 
what can be done in C++ - basically, the stuff is so powerfull it seems to 
almost reach into CL-reserved realms. With limitations, because it's 
different language, but still impressive for me.

http://en.wikipedia.org/wiki/Boost_(C%2B%2B_libraries)

http://www.boost.org/doc/libs/1_49_0/?view=category_Function-objects

http://www.boost.org/doc/libs/1_49_0/doc/html/lambda.html

http://www.boost.org/doc/libs/1_49_0/libs/bind/bind.html

OTOH, I guess there are performance penalties. So, it boils down to 
individual's decision about pricing his own time or machine's time higher 
than another. Like, hand writing specially optimised versions of some 
functions or trying to lure compiler into generating them automatically 
(with templates).

But, compilers are improving. In algorithmic contests, C++ is used quite a 
lot, from what I could see (and some people use Pascal, compile with Free 
Pascal Compiler, nice thing).

BTW, Java folks trie(d|s) to go this way (templates etc) too, but I don't 
trace their efforts much, so cannot say how they fare(d).

> > - Common Lisp - "nice industrial standard" (depends on one's preferred 
> > definition of "nice", of course, as well as "industrial" and "standard")
>   I took a hard look at Common Lisp at one time. I got the
>   impression that the "Common Lisp" is not to Lisp what Ansi C is to
>   C. 
>   
>   IOWS, there does remain incompatibilities between different
>   Common Lisp implementations.

Interesting. I play with CL for some time but haven't rammed this 
particular wall yet. Do you remember more about it? If you can't be 
specific, perhaps some hint will do.

Regards,
Tomasz Rola

--
** A C programmer asked whether computer had Buddha's nature.  **
** As the answer, master did "rm -rif" on the programmer's home**
** directory. And then the C programmer became enlightened...  **
** **
** Tomasz Rola  mailto:tomasz_r...@bigfoot.com **
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: network protocols

2012-06-13 Thread Christian Heimes
Am 13.06.2012 16:56, schrieb Christian Heimes:
> Am 13.06.2012 13:41, schrieb Tarek Ziadé:
>> Hey
>>
>> I was surprised not to find any way to list all protocol names listed in
>> /etc/protocols in Python
>>
>> We have
>>
>> socket.getprotobyname(NAME)
>>
>> But there's no way to get the list of names
>>
>> Any ideas if this is available in the stdlib somehwere ?
> 
> No, I can't find any reference to the relevant NSS APIs in the Python
> code. You can easily roll your own with ctypes:

PS: You can also parse the output of "getent protocols". As for all name
services you shouldn't parse the file as other sources (ldap, dns, nis,
databases) can provide additional information. See man nsswitch.conf

Christian

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


Re: network protocols

2012-06-13 Thread Tarek Ziadé

On 6/13/12 8:33 PM, Christian Heimes wrote:

Am 13.06.2012 16:56, schrieb Christian Heimes:

Am 13.06.2012 13:41, schrieb Tarek Ziadé:

Hey

I was surprised not to find any way to list all protocol names listed in
/etc/protocols in Python

We have

socket.getprotobyname(NAME)

But there's no way to get the list of names

Any ideas if this is available in the stdlib somehwere ?

No, I can't find any reference to the relevant NSS APIs in the Python
code. You can easily roll your own with ctypes:

PS: You can also parse the output of "getent protocols". As for all name
services you shouldn't parse the file as other sources (ldap, dns, nis,
databases) can provide additional information. See man nsswitch.conf

Christian

Thanks for the pointers -- I was going to 
open('etc/protocols').readlines() :)

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


Re: [newbie] Equivalent to PHP?

2012-06-13 Thread Gilles
On Wed, 13 Jun 2012 18:01:23 +, "Prasad, Ramit"
 wrote:
>Maybe this article will help you 
>http://www.infoworld.com/d/application-development/pillars-python-six-python-web-frameworks-compared-169442
>The comments on /. should round out anything missing from the article (I hope)
>http://developers.slashdot.org/story/11/08/10/2111203/six-python-web-frameworks-compared

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


Re: [newbie] Equivalent to PHP?

2012-06-13 Thread Gilles
On Wed, 13 Jun 2012 17:27:21 +0200, Christian Heimes
 wrote:
>A long running process has lots of benefits that makes design and
>development easier and makes your app faster.

Thanks much for the infos. Makes you wonder why commercial companies
still choose PHP to write their web site.
-- 
http://mail.python.org/mailman/listinfo/python-list


Pytz error: unpack requires a string argument of length 44

2012-06-13 Thread bringa
Hi!

I'm trying to get a handle on pytz (http://pytz.sourceforge.net/). I don't have 
root on the system I'll be running my script on, so I need to go for a local 
installation. I copied pytz into a folder in my sys.path and am importing from 
there. That part seems to work. I downloaded the tarball on 
http://pypi.python.org/pypi/pytz/#downloads

So now I'm walking through the examples on 
http://pytz.sourceforge.net/#example-usage. This is what happens:

Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on 
win32
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from datetime import datetime, timedelta
>>> from pytz import timezone
>>> import pytz
>>> utc = pytz.utc
>>> utc.zone
'UTC'
>>> eastern = timezone('US/Eastern')
Traceback (most recent call last):
  File "", line 1, in 
  File "C:\code\SoF\serversonfire\pytz\__init__.py", line 181, in timezone
_tzinfo_cache[zone] = build_tzinfo(zone, fp)
  File "C:\code\SoF\serversonfire\pytz\tzfile.py", line 30, in build_tzinfo
typecnt, charcnt) =  unpack(head_fmt, fp.read(head_size))
error: unpack requires a string argument of length 44


Can anyone explain to me why that call fails?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [newbie] Equivalent to PHP?

2012-06-13 Thread Christian Heimes
Am 13.06.2012 22:48, schrieb Gilles:
> On Wed, 13 Jun 2012 17:27:21 +0200, Christian Heimes
>  wrote:
>> A long running process has lots of benefits that makes design and
>> development easier and makes your app faster.
> 
> Thanks much for the infos. Makes you wonder why commercial companies
> still choose PHP to write their web site.

PHP was developed for non-developers. (see
http://me.veekun.com/blog/2012/04/09/php-a-fractal-of-bad-design/ ).
It's much easier and also cheaper to find bad coders and non-developers
than code people. The outcome is bad performance and lots of security
issues.

Christian

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


Re: Pytz error: unpack requires a string argument of length 44

2012-06-13 Thread Terry Reedy

On 6/13/2012 4:55 PM, bri...@gmail.com wrote:

Hi!

I'm trying to get a handle on pytz (http://pytz.sourceforge.net/). I don't have 
root on the system I'll be running my script on, so I need to go for a local 
installation. I copied pytz into a folder in my sys.path and am importing from 
there. That part seems to work. I downloaded the tarball on 
http://pypi.python.org/pypi/pytz/#downloads

So now I'm walking through the examples on 
http://pytz.sourceforge.net/#example-usage. This is what happens:

Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on 
win32
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)

from datetime import datetime, timedelta
from pytz import timezone
import pytz
utc = pytz.utc
utc.zone

'UTC'

eastern = timezone('US/Eastern')

Traceback (most recent call last):
   File "", line 1, in
   File "C:\code\SoF\serversonfire\pytz\__init__.py", line 181, in timezone
 _tzinfo_cache[zone] = build_tzinfo(zone, fp)
   File "C:\code\SoF\serversonfire\pytz\tzfile.py", line 30, in build_tzinfo
 typecnt, charcnt) =  unpack(head_fmt, fp.read(head_size))
error: unpack requires a string argument of length 44


Can anyone explain to me why that call fails?


1. Either pytz has a bug, it was not installed correctly, or it does not 
work on windows.


2. If you read the module struct section of the fine manual, which you 
can easily find by typing 'unpack' on the Index tab of the Windows help 
version of the manual, it will tell you the following. Unpack takes two 
arguments, a format defining character fields of specifics lengths and a 
string whose length must be the sum of those lengths. (The contents of 
each field must also match the format spec, but you never got that far.) 
If there is a length mismatch, you get the message above.


3. In the specific case, we may presume that head_size is the sum of 
field lengths for head_fmt. (You could check; if not, that is a bug.) 
Since fp.read cannot read too many bytes, it must have read too little. 
("Read up to n bytes from the object and return them.")


You could look in
C:\code\SoF\serversonfire\pytz\__init__.py
and see what file fp is supposed to be and then take a look at the file. 
Is it empty? Is anything read before the statement that failer?


--
Terry Jan Reedy

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


Re: Pytz error: unpack requires a string argument of length 44

2012-06-13 Thread bringa
Thanks Terry! 

There indeed seems to be something wrong with my installation of pytz. I had a 
look around the zoneinfo dir, which is where build_tzinfo polls its info from, 
and a whole bunch of files are 0 bytes. Whenever I try to instantiate a 
timezone whose corresponding file is 0 bytes I get that error (it's trying to 
read the head of the tzinfo file to make sure the right magic bytes are in 
there, and reading 44 bytes out of a 0 byte file isn't going to work).

So I guess I'll poke around to find some specific help with pytz or a 
non-broken zoneinfo dir.

On Wednesday, June 13, 2012 10:43:46 PM UTC+1, Terry Reedy wrote:
> On 6/13/2012 4:55 PM, I wrote:
> > Hi!
> >
> > I'm trying to get a handle on pytz (http://pytz.sourceforge.net/). I don't 
> > have root on the system I'll be running my script on, so I need to go for a 
> > local installation. I copied pytz into a folder in my sys.path and am 
> > importing from there. That part seems to work. I downloaded the tarball on 
> > http://pypi.python.org/pypi/pytz/#downloads
> >
> > So now I'm walking through the examples on 
> > http://pytz.sourceforge.net/#example-usage. This is what happens:
> >
> > Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] 
> > on win32
> > Type "help", "copyright", "credits" or "license" for more information.
> > (InteractiveConsole)
>  from datetime import datetime, timedelta
>  from pytz import timezone
>  import pytz
>  utc = pytz.utc
>  utc.zone
> > 'UTC'
>  eastern = timezone('US/Eastern')
> > Traceback (most recent call last):
> >File "", line 1, in
> >File "C:\code\SoF\serversonfire\pytz\__init__.py", line 181, in timezone
> >  _tzinfo_cache[zone] = build_tzinfo(zone, fp)
> >File "C:\code\SoF\serversonfire\pytz\tzfile.py", line 30, in build_tzinfo
> >  typecnt, charcnt) =  unpack(head_fmt, fp.read(head_size))
> > error: unpack requires a string argument of length 44
> >
> >
> > Can anyone explain to me why that call fails?
> 
> 1. Either pytz has a bug, it was not installed correctly, or it does not 
> work on windows.
> 
> 2. If you read the module struct section of the fine manual, which you 
> can easily find by typing 'unpack' on the Index tab of the Windows help 
> version of the manual, it will tell you the following. Unpack takes two 
> arguments, a format defining character fields of specifics lengths and a 
> string whose length must be the sum of those lengths. (The contents of 
> each field must also match the format spec, but you never got that far.) 
> If there is a length mismatch, you get the message above.
> 
> 3. In the specific case, we may presume that head_size is the sum of 
> field lengths for head_fmt. (You could check; if not, that is a bug.) 
> Since fp.read cannot read too many bytes, it must have read too little. 
> ("Read up to n bytes from the object and return them.")
> 
> You could look in
> C:\code\SoF\serversonfire\pytz\__init__.py
> and see what file fp is supposed to be and then take a look at the file. 
> Is it empty? Is anything read before the statement that failer?
> 
> -- 
> Terry Jan Reedy

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


Re: [newbie] Equivalent to PHP?

2012-06-13 Thread Steven D'Aprano
On Wed, 13 Jun 2012 12:17:12 +0200, Gilles wrote:

> Thanks for the longer explanation. With so many frameworks, I'd like to
> know what benefits they offer as compared to writing an application from
> scratch

Surely the obvious answer is that a framework offers the benefit that you 
don't have to write the application from scratch.

Why write in Python instead of creating your application from scratch 
written in assembly? Because you get the benefit of 40+ years of 
collective programming language design experience, 10+ years of 
collective Python experience, tens or hundreds of thousands of lines of 
carefully debugged and tuned code, and a large community of users with 
experience in the language, books, training courses, etc. whom you can 
call on for advice (free or paid consulting) and as a pool of would-be 
employees if you need to hire developers.

You wouldn't (or at least shouldn't) even *consider* writing your own 
language unless you had really good reason, and no other existing 
language would do.

Web frameworks are similar: you get tens or hundreds of thousands of 
lines of carefully debugged and tuned code, and a community of users, 
books, etc. Unless your needs are minuscule, writing your application 
from scratch will end up duplicating much of the framework, only (let's 
be realistic here) badly. By the time your application is as stable, 
debugged and tuned as as existing framework, you will have spent probably 
in excess of ten person-years.

At which point, you have a community of one, yourself. (Or possibly you 
and a handful of your fellow project members.)

For anything but the smallest web applications, where no framework is 
necessary, and the very largest, if no existing framework will do, why 
would you even consider reinventing the wheel?



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


RE: Pytz error: unpack requires a string argument of length 44

2012-06-13 Thread Prasad, Ramit
> There indeed seems to be something wrong with my installation of pytz. I had a
> look around the zoneinfo dir, which is where build_tzinfo polls its info from,
> and a whole bunch of files are 0 bytes. Whenever I try to instantiate a
> timezone whose corresponding file is 0 bytes I get that error (it's trying to
> read the head of the tzinfo file to make sure the right magic bytes are in
> there, and reading 44 bytes out of a 0 byte file isn't going to work).
> 
> So I guess I'll poke around to find some specific help with pytz or a non-
> broken zoneinfo dir.

Did you follow the installation instructions located on the front page?

I would unpack the tarball (not in a Python directory) and then do 
`python setup.py install` (use the full path to the executable you want
the module installed to if you have more than one version of Python installed)
from the directory with the unpacked contents of the tarball. I did not need 
admin rights to manually install on Windows, but that might depend on 
where your Python is installed.

Ramit


Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
712 Main Street | Houston, TX 77002
work phone: 713 - 216 - 5423

--
This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.  
-- 
http://mail.python.org/mailman/listinfo/python-list


When adding my application to Windows right-click menu

2012-06-13 Thread Yesterday Paid
I made a cipher app but to make easy, I want to make it Windows
rightclick menu can execute it
I found the way with dealing with Registry


[HKEY_CLASSES_ROOT\Directory\Background\shell\app]
 [HKEY_CLASSES_ROOT\Directory\Background\shell\app\command]
 @="C;\myapp filelocation"


but I don't know how to automatically get filelocation
Can I get the address of file that I right_clicked(it's not a proper
expression maybe)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [newbie] Equivalent to PHP?

2012-06-13 Thread Gilles
On 13 Jun 2012 22:16:51 GMT, Steven D'Aprano
 wrote:
>Surely the obvious answer is that a framework offers the benefit that you 
>don't have to write the application from scratch.

Yes, but between receiving the query and sending the response, what
features do frameworks offer that I'd have to write myself otherwise?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [newbie] Equivalent to PHP?

2012-06-13 Thread Gilles
On Wed, 13 Jun 2012 23:16:31 +0200, Christian Heimes
 wrote:
>PHP was developed for non-developers. (see
>http://me.veekun.com/blog/2012/04/09/php-a-fractal-of-bad-design/ ).
>It's much easier and also cheaper to find bad coders and non-developers
>than code people. The outcome is bad performance and lots of security
>issues.

And as to why Facebook chose PHP...
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: [newbie] Equivalent to PHP?

2012-06-13 Thread Prasad, Ramit
> >PHP was developed for non-developers. (see
> >http://me.veekun.com/blog/2012/04/09/php-a-fractal-of-bad-design/ ).
> >It's much easier and also cheaper to find bad coders and non-developers
> >than code people. The outcome is bad performance and lots of security
> >issues.
> 
> And as to why Facebook chose PHP...

You are not Facebook (at least yet).

They also choose to transform PHP into C++ for performance reasons. Not 
something the average large website would want to do.
http://www.sdtimes.com/blog/post/2010/01/30/Facebook-rewrites-PHP-runtime.aspx
http://www.datacenterknowledge.com/the-facebook-data-center-faq-page-2/ 


The real question is would they use it again if they were to start over?
http://www.quora.com/Quora-Infrastructure/Why-did-Quora-choose-Python-for-its-development


These decisions are influenced by a multitude of factors 
1. familiarity/popularity of a framework 
2. support
3. what someone thinks is "best" for specifications
4. cost
Notice only 1 of those factors was what was actually "best".


Also remember you asked this on a *Python* mailing list. I am sure you 
will get different responses on a PHP mailing list.

Ramit


Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
712 Main Street | Houston, TX 77002
work phone: 713 - 216 - 5423

--
This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.  
-- 
http://mail.python.org/mailman/listinfo/python-list


RE: When adding my application to Windows right-click menu

2012-06-13 Thread Prasad, Ramit
> I made a cipher app but to make easy, I want to make it Windows
> rightclick menu can execute it
> I found the way with dealing with Registry
> 
> 
> [HKEY_CLASSES_ROOT\Directory\Background\shell\app]
>  [HKEY_CLASSES_ROOT\Directory\Background\shell\app\command]
>  @="C;\myapp filelocation"
> 
> 
> but I don't know how to automatically get filelocation
> Can I get the address of file that I right_clicked(it's not a proper
> expression maybe)

This is not a Python question...

This might help 
http://www.velocityreviews.com/forums/t229799-how-to-add-a-program-to-the-open-with-right-click-menu.html

There is a way to do it via registry but I cannot find the link, but 
essentially it should have a string like 
c:\Python\python.exe %1 
where %1 is the file being currently selected (cipher app module). 


Ramit


Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
712 Main Street | Houston, TX 77002
work phone: 713 - 216 - 5423

--
This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [newbie] Equivalent to PHP?

2012-06-13 Thread Gilles
On Wed, 13 Jun 2012 23:12:37 +, "Prasad, Ramit"
 wrote:
>You are not Facebook (at least yet).

Indeed, but with so much criticism about PHP, it's odd that they would
still choose it.

Anyway, thanks much for the infos. I'll look at the web frameworks and
how to connect the Python app to a front-end web server.
-- 
http://mail.python.org/mailman/listinfo/python-list


consecutive node sequence and pathlength problem using networkx graph

2012-06-13 Thread bob
 Let say,I have a conjugated cyclic polygon and its nodes are given
by the list:
   list_p=[a,b,c,d,e,f,g,a,a,b,d,d,d,d,d,c,c,e,e,a,d,d,g]. If X & Y
are any elements in
   a   list_p except d, and Z is also an element of list_p but has
value only d, i.e,
   Z=d. Now,I want to compute the number of  paths with sequence X-Z-
Y consecutive nodes,
   example: a-d-d-e,a-d-d-a, a-d-d-d-g, etc. Consecutive path length
of Z can be 1,2,3,4 or 5.

   To generalize: Find total number of paths with consecutive X-Z-Y
sequence for path length of
   z within range(1,6): or
   (i) X-Z-Y for len(Z)=1
   (ii) X-Z-Y for len(Z)=2
   (iii)X-Z-Y for len(Z)=3
   (iv) X-Z-Y for len(Z)=4
   (v) X-Z-Y for  len(Z)=5

 Is there any easy way to program this using python networkx or
igraph?

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


Re: [newbie] Equivalent to PHP?

2012-06-13 Thread Steven D'Aprano
On Thu, 14 Jun 2012 00:44:23 +0200, Gilles wrote:

> On 13 Jun 2012 22:16:51 GMT, Steven D'Aprano
>  wrote:
>>Surely the obvious answer is that a framework offers the benefit that
>>you don't have to write the application from scratch.
> 
> Yes, but between receiving the query and sending the response, what
> features do frameworks offer that I'd have to write myself otherwise?

What, google broken for you? *wink*

Copied and pasted from http://cherrypy.org/

  FEATURES
  A fast, HTTP/1.1-compliant, WSGI thread-pooled webserver.
  Easy to run multiple HTTP servers (e.g. on multiple ports) at once.
  A powerful configuration system for developers and deployers alike.
  A flexible plugin system.
  Built-in tools for caching, encoding, sessions, authorization, static
  content, and many more.
  Swappable and customizable...everything.
  Built-in profiling, coverage, and testing support.
  Runs on Python 2.5+, 3.1+, Jython and Android.


Plus you have a whole community of people working on the framework, 
fixing bugs and writing documentation, and you don't have to pay them a 
cent.

http://duckduckgo.com/?q=cherrypy+features

Repeat as needed for any other framework you are interested in.

Essentially, using a framework means you get to concentrate on the actual 
problem your application is meant to solve instead of spending most of 
your time worrying about building the infrastructure (the framework!) to 
hold your application.


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


RE: [newbie] Equivalent to PHP?

2012-06-13 Thread Prasad, Ramit
> Indeed, but with so much criticism about PHP, it's odd that they would
> still choose it.

Could be a familiarity/ease issue as it was originally started by a 
college student (and college students seldom have meaningful real 
world experience) before it exploded in size. Also do not forget
that it was developed nearly a decade ago and technology has
changed (hopefully improved) a lot since then. 
Ramit


Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
712 Main Street | Houston, TX 77002
work phone: 713 - 216 - 5423

--



This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.  
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pytz error: unpack requires a string argument of length 44

2012-06-13 Thread Daniel Klein
The windows box is my development box, it's not where the script will be 
running in the end. It'll be running on a Linux box where I don't have root so 
python setup.py install isn't an option (to my understanding).

So what happened is that 7zip didn't unzip the .tar.gz2 properly, but it does 
fine with the .zip from the Python Package Index. Using the zoneinfo from the 
properly unzipped file everything works.

Thanks everyone, consider this solved.

On Wednesday, June 13, 2012 11:25:28 PM UTC+1, Prasad, Ramit wrote:
> > There indeed seems to be something wrong with my installation of pytz. I 
> > had a
> > look around the zoneinfo dir, which is where build_tzinfo polls its info 
> > from,
> > and a whole bunch of files are 0 bytes. Whenever I try to instantiate a
> > timezone whose corresponding file is 0 bytes I get that error (it's trying 
> > to
> > read the head of the tzinfo file to make sure the right magic bytes are in
> > there, and reading 44 bytes out of a 0 byte file isn't going to work).
> > 
> > So I guess I'll poke around to find some specific help with pytz or a non-
> > broken zoneinfo dir.
> 
> Did you follow the installation instructions located on the front page?
> 
> I would unpack the tarball (not in a Python directory) and then do 
> `python setup.py install` (use the full path to the executable you want
> the module installed to if you have more than one version of Python installed)
> from the directory with the unpacked contents of the tarball. I did not need 
> admin rights to manually install on Windows, but that might depend on 
> where your Python is installed.
> 
> Ramit
> 
> 
> Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
> 712 Main Street | Houston, TX 77002
> work phone: 713 - 216 - 5423
> 
> --
> This email is confidential and subject to important disclaimers and
> conditions including on offers for the purchase or sale of
> securities, accuracy and completeness of information, viruses,
> confidentiality, legal privilege, and legal entity disclaimers,
> available at http://www.jpmorgan.com/pages/disclosures/email.

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


Re: [newbie] Equivalent to PHP?

2012-06-13 Thread Tim Chase
On 06/13/12 17:44, Gilles wrote:
> On 13 Jun 2012 22:16:51 GMT, Steven D'Aprano
>  wrote:
>> Surely the obvious answer is that a framework offers the benefit that you 
>> don't have to write the application from scratch.
> 
> Yes, but between receiving the query and sending the response, what
> features do frameworks offer that I'd have to write myself otherwise?

Let's see

- CRSF protection
- keeping things DRY
- templating (or you could use many others)
- user management
- administrative interface
- database creation/introspection
- i18n
- an ecosystem of pluggable add-on apps
- URL routing
- view decorators
- easily swappable back-ends
- active development across multiple lines of business
- GIS support
- abstracted ORM (or you could use SQLObject or its kin) to allow
you mobility between DB back-ends should you want to

That's just my off-the-top-of-my-head list of things that you'd have
to come up with that Django happens to give you out-of-the-box.

-tkc


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


Re: string to list

2012-06-13 Thread Chris Rebert
n Wed, Jun 13, 2012 at 7:29 PM, bruce g  wrote:
> What is the best way to parse a CSV string to a list?

Use the `csv` module:
http://docs.python.org/library/csv.html
http://www.doughellmann.com/PyMOTW/csv/

The `StringIO` module can be used to wrap your string as a file-like
object for consumption by the `csv` module:
http://docs.python.org/library/stringio.html

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


Re: [newbie] Equivalent to PHP?

2012-06-13 Thread Terry Reedy

On 6/13/2012 6:45 PM, Gilles wrote:

On Wed, 13 Jun 2012 23:16:31 +0200, Christian Heimes
  wrote:

PHP was developed for non-developers. (see
http://me.veekun.com/blog/2012/04/09/php-a-fractal-of-bad-design/ ).
It's much easier and also cheaper to find bad coders and non-developers
than code people. The outcome is bad performance and lots of security
issues.


And as to why Facebook chose PHP...


*When* did 'Facebook' choose it? (My brief search did not reveal this.) 
Facebook started as a quick hack (Facemash) by student Mark Zuckerberg 
in Nov 2003. If he used PHP (1995) then or for his next site or for the 
initial Facebook a few months later, that would suggest an answer.


--
Terry Jan Reedy

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


Re: string to list

2012-06-13 Thread Jose H. Martinez
string.split(',') will give you an array.

Example:

'AAA,",,",EEE,FFF,GGG '.split(',')

['AAA', '"', '', '"', 'EEE', 'FFF', 'GGG']

On Wed, Jun 13, 2012 at 10:53 PM, Chris Rebert  wrote:

> n Wed, Jun 13, 2012 at 7:29 PM, bruce g  wrote:
> > What is the best way to parse a CSV string to a list?
>
> Use the `csv` module:
> http://docs.python.org/library/csv.html
> http://www.doughellmann.com/PyMOTW/csv/
>
> The `StringIO` module can be used to wrap your string as a file-like
> object for consumption by the `csv` module:
> http://docs.python.org/library/stringio.html
>
> Cheers,
> Chris
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Internationalized domain names not working with URLopen

2012-06-13 Thread John Nagle

On 6/12/2012 11:42 PM, Andrew Berg wrote:

On 6/13/2012 1:17 AM, John Nagle wrote:

What does "urllib2" want?  Percent escapes?  Punycode?

Looks like Punycode is the correct answer:
https://en.wikipedia.org/wiki/Internationalized_domain_name#ToASCII_and_ToUnicode

I haven't tried it, though.


   This is Python bug #9679:

http://bugs.python.org/issue9679

It's been open for years, and the maintainers offer elaborate
excuses for not fixing the problem.

The socket module accepts Unicode domains, as does httplib.
But urllib2, which is a front end to both, is still broken.
It's failing when it constructs the HTTP headers.  Domains
in HTTP headers have to be in punycode.

The code in stackoverflow doesn't really work right.  Only
the domain part of a URL should be converted to punycode.
Path, port, and query parameters need to be converted to
percent-encoding.  (Unclear if urllib2 or httplib does this
already.  The documentation doesn't say.)

While HTTP content can be in various character sets, the
headers are currently required to be ASCII only, since the
header has to be processed to determine the character code.
(http://lists.w3.org/Archives/Public/ietf-http-wg/2011OctDec/0155.html)

Here's a workaround, for the domain part only.


#
#   idnaurlworkaround  --  workaround for Python defect 9679
#
PYTHONDEFECT9679FIXED = False # Python defect #9679 - change when fixed

def idnaurlworkaround(url) :
"""
Convert a URL to a form the currently broken urllib2 will accept.
Converts the domain to "punycode" if necessary.
This is a workaround for Python defect #9679.
"""
if PYTHONDEFECT9679FIXED :  # if defect fixed
return(url)   # use unmodified URL
url = unicode(url)  # force to Unicode
(scheme, accesshost, path, params,
query, fragment) = urlparse.urlparse(url)# parse URL
if scheme == '' and accesshost == '' and path != '' : # bare domain
accesshost = path # use path as access host
path = '' # no path
labels = accesshost.split('.') # split domain into sections ("labels")
labels = [encodings.idna.ToASCII(w) for w in labels]# convert each 
label to punycode if necessary

accesshost = '.'.join(labels) # reassemble domain
url = urlparse.urlunparse((scheme, accesshost, path, params, query, 
fragment))  # reassemble url

return(url) # return complete URL with punycode domain

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


Re: string to list

2012-06-13 Thread Ian Kelly
On Wed, Jun 13, 2012 at 10:06 PM, Jose H. Martinez
 wrote:
> string.split(',') will give you an array.
>
> Example:
>
> 'AAA,",,",EEE,FFF,GGG '.split(',')
>
> ['AAA', '"', '', '"', 'EEE', 'FFF', 'GGG']

But it incorrectly splits the quoted part.  A proper CSV parser (like
the csv module) should leave that part as a single string, even though
it contains commas.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Pytz error: unpack requires a string argument of length 44

2012-06-13 Thread Kushal Kumaran
On Thu, Jun 14, 2012 at 6:35 AM, Daniel Klein  wrote:
> The windows box is my development box, it's not where the script will be 
> running in the end. It'll be running on a Linux box where I don't have root 
> so python setup.py install isn't an option (to my understanding).
>

You might want to use virtualenv for this:
http://pypi.python.org/pypi/virtualenv

> So what happened is that 7zip didn't unzip the .tar.gz2 properly, but it does 
> fine with the .zip from the Python Package Index. Using the zoneinfo from the 
> properly unzipped file everything works.
>

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