Source code to identify user through browser?

2013-06-05 Thread Gilles
Hello

I was wondering if some Python module were available to identify a
user through their browser, like it's done on the Panopticlick site:

http://panopticlick.eff.org/

I'd like to ban abusive users, and it seems like a good solution,
since few users will think of installing a different browser, and
there are few mainstream browsers anyway.

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


Simple Python script as SMTP server for outgoing e-mails?

2013-07-21 Thread Gilles
Hello

Every once in a while, my ISP's SMTP server refuses to send
perfectly legit e-mails because it considers them as SPAM.

So I'd like to install a dead-simple SMTP server on my XP computer
just to act as SMTP backup server.
All I'd need is to change the SMTP address in my e-mail client, and
off they go. No need for anything else like user authentication or
SPAM control.

Is there a no-brainer, ready-to-use solution in Python that I could
use for this?

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


Re: Simple Python script as SMTP server for outgoing e-mails?

2013-07-21 Thread Gilles
On Mon, 22 Jul 2013 00:48:29 +1000, Chris Angelico 
wrote:
>Rather than write something from scratch, I'd look at deploying
>something out-of-the-box - Postfix, for instance - which you will be
>able to configure much faster than writing your own. And then you
>could have it either send via your ISP or send directly to the
>receiving MTA, without much extra effort.

Thank you but precisely, I was looking for a "ready-to-use solution in
Python" so that I wouldn't have to write it myself.

Also, I don't need a full-fledged SMTP server, just a tiny script that
will let me send the occasional e-mails from my e-mail client that my
ISP wrongly considers as SPAM.

So, does someone know of a good, SMTP server just to send e-mails?

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


Re: Simple Python script as SMTP server for outgoing e-mails?

2013-07-21 Thread Gilles
On Sun, 21 Jul 2013 11:46:52 -0600, Michael Torrie 
wrote:
>What you're looking for is not an SMTP server but a Mail Transfer Agent,
>called an MTA.
>
>Pretty much all distros ship with an MTA by default, even if the SMTP
>server part of it isn't installed or running. And often the MTA is, for
>compatibility reasons, /usr/sbin/sendmail.
>
>http://stackoverflow.com/questions/73781/sending-mail-via-sendmail-from-python
>
>I'm sure there are MTA's implemented in python. Now that you know what
>they are called (not SMTP servers!) you can search for them.
>
>Dennis is correct, though, that most ISPs do block outbound port 25
>connections for security and spam reasons, and require you to use their
>SMTP server, which precludes the use of the local MTA.

Thanks for the infos. Ideally, I was looking for a simple Windows app
as MTA, but a Python script is OK.

I'm not sure my ISP blocks outbound port 25 connections. I'll
experiment with a small Linux box.

I wist they would use a smarter SPAM filter that wouldn't flag
perfectly legit-looking outgoing e-mails.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Simple Python script as SMTP server for outgoing e-mails?

2013-07-22 Thread Gilles
On Sun, 21 Jul 2013 18:28:27 -0600, Michael Torrie 
wrote:
>The Sendmail MTA has been ported to many platforms including windows.
>But...

Thanks for the tip. Since I couldn't find a good, basic, native
Windows app, I was indeed about to look at eg. Exim + Cygwin, and
resort to a Linux appliance if none footed the bill.

>> I'm not sure my ISP blocks outbound port 25 connections. I'll
>> experiment with a small Linux box.
>
>Having spent a long time managing e-mail servers, everything Ivan said
>in his reply is true as well.  I had forgotten a lot of that since I
>haven't been running my own mail server (MTA or server part) in a while.

Indeed, I had forgotten about some MTAs refusing incoming e-mails from
other ISP's customer hosts. I'll experiment.

>But then how would it know that legit-looking e-mails aren't in fact
>SPAM?

It generally does a good job, but every once in a while, some
perfectly good e-mail I'm sending is flagged as SPAM. To keep all my
e-mails in the same client, I'd rather use a local MTA than sending
the e-mail from Gmail.

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


Re: Simple Python script as SMTP server for outgoing e-mails?

2013-07-22 Thread Gilles
On Sun, 21 Jul 2013 21:01:09 + (UTC), Grant Edwards
 wrote:

>Unless you've got a static IP address, a domain name, and a valid MX
>record that will match up when they do a reverse DNS lookup, it's
>pretty unlikely that you're going to have much luck running an SMTP
>server.  Most other SMTP servers are probably going to ignore or
>reject your attempts to transfer mail from your own SMTP server.

I had forgotten about this. I'll give a try, and see how it goes.

>I'd recommend postfix or exim if I was going to try to do it, but I
>think they're Unix-only.

Thanks for the tip. Looks like Exim is available on Windows through
Cygwin
http://blogostuffivelearnt.blogspot.fr/2012/07/smtp-mail-server-with-windows.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Simple Python script as SMTP server for outgoing e-mails?

2013-07-22 Thread Gilles
On Sun, 21 Jul 2013 21:01:09 + (UTC), Grant Edwards
 wrote:
>Unless you've got a static IP address, a domain name, and a valid MX
>record that will match up when they do a reverse DNS lookup, it's
>pretty unlikely that you're going to have much luck running an SMTP
>server.  Most other SMTP servers are probably going to ignore or
>reject your attempts to transfer mail from your own SMTP server.

Incidently, how do ISP MTAs find whether the remote MTA is legit or
running on some regular user's computer?

1. Query Reverse DNS for IP
2. Find domain
3. Query DNS for MX
4. ?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Simple Python script as SMTP server for outgoing e-mails?

2013-07-22 Thread Gilles
On Mon, 22 Jul 2013 22:29:42 +1000, Chris Angelico 
wrote:
>One thing to check when you change how you send mail is your SPF
>record. I run the mail server for kepl.com.au and have set its SPF to:
>
>"v=spf1 ip4:122.107.147.136 ip4:203.214.67.43 ip4:192.168.0.0/16 -all"
>
>If your SPF is as strict as mine (and if it's not, please make it so,
>for the sake of the rest of the world!), you'll want to check it
>before you start sending mail directly from your own computer.
>Otherwise your mail _will_ be rejected as spam.

Thanks for the tip. I didn't know about SPF
http://en.wikipedia.org/wiki/Sender_Policy_Framework
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Simple Python script as SMTP server for outgoing e-mails?

2013-07-23 Thread Gilles
On Mon, 22 Jul 2013 08:54:11 -0400, "Eric S. Johansson"
 wrote:
>try http://emailrelay.sourceforge.net/

Thanks. I did find it, but it says it's not a full MTA:

"E-MailRelay is not a routing MTA. It forwards e-mail to a
pre-configured SMTP server, regardless of any message addressing or
DNS redirects."
http://emailrelay.sourceforge.net/userguide.html#SH_1_2

IOW, it'll just send outbound e-mails to my ISP's MTA, so I'm back at
square one.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Simple Python script as SMTP server for outgoing e-mails?

2013-07-23 Thread Gilles
On Mon, 22 Jul 2013 08:10:10 -0600, Michael Torrie 
wrote:
>Where did you look?  Here's one I found.  It's not the real sendmail
>program, but it implements the interface which is all you need:
>
>http://glob.com.au/sendmail/
>
>I just googled for sendmail win32

Thanks, but I need an MTA, not just a command-line app, so I can send
e-mails from my e-mail client and just change the SMTP line in the
configuration.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Simple Python script as SMTP server for outgoing e-mails?

2013-07-23 Thread Gilles
On Mon, 22 Jul 2013 10:14:15 -0400, Kevin Walzer 
wrote:
>http://www.hmailserver.com

Thanks. hMailServer was one of the apps I checked, and I was just
making sure there weren't something simpler, considering my needs,
ideally something like Mongoose MTA.

Regardless, because of the SPAM anti-measures mentioned above, it
seems like I was over-optimistic about running an MTA and sending
e-mails from my home computer :-/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [newbie] Equivalent to PHP?

2012-06-21 Thread Gilles
On Tue, 12 Jun 2012 11:39:50 +0200, Gilles  wrote:
>I'm an amateur programmer, and would like to know what the main
>options are to build web applications in Python instead of PHP.

When I need to host my Python application (preferably in Europe since
my users will be located there), what are the options?

Do Python hosters provide a VM so that it's just like a remote Linux
server where I'm free to install whatever I want, or do they force
users to use specific versions of Python and specific frameworks eg.
Django?

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


Re: [newbie] Equivalent to PHP?

2012-06-21 Thread Gilles
On Thu, 21 Jun 2012 10:44:08 -0700, Paul Rubin
 wrote:
>There are both kinds.  The first kind is called a Virtual Private Server
>(VPS).  The second kind is called shared hosting.

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


Using a CMS for small site?

2012-07-04 Thread Gilles
Hello

Someone I know with no computer knowledge has a studio appartment to
rent in Paris and spent four months building a small site in Joomla to
find short-time renters.

The site is just...
- a few web pages that include text (in four languages) and pictures
displayed in a Flash slide show
- a calendar to show availability
- a form to send e-mail with anti-SPAM support
- (ASAP) online payment

Out of curiosity, are there CMS/frameworks in Python that can do this?
Django? Other?

Is a full-fledged CMS even needed for something like that?

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


Re: Using a CMS for small site?

2012-07-04 Thread Gilles
On Wed, 04 Jul 2012 06:28:09 -0400, Roy Smith  wrote:
>You probably want to look at https://www.django-cms.org/.  It's not 
>something that a person with "no computer knowledge" could set up, but 
>once it's set up, that person could use it to build pages.
>
>But, to be honest, for somebody who really doesn't know anything, some 
>much more pre-canned solution like WordPress might be what they're 
>looking for.

Thanks for the input. Considering that contents won't change, I was
wondering if a full-fledged CMS was even necessary.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Using a CMS for small site?

2012-07-04 Thread Gilles
On Wed, 04 Jul 2012 11:21:42 -0400, Roy Smith  wrote:
>This is really getting quite far afield for a Python group.  There are 
>better forums for these kinds of questions.

Probably. I'll keep that in mind while checking Python web frameworks.
Thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Using a CMS for small site?

2012-07-05 Thread Gilles
On Wed, 4 Jul 2012 17:09:40 -0700 (PDT), alex23 
wrote:
>Not necessarily! There are several static site generators written in
>Python :)
>
>One that I see being updating a lot is Nikola: http://nikola.ralsina.com.ar/

I'll check it out, thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Using a CMS for small site?

2012-07-05 Thread Gilles
On Thu, 05 Jul 2012 10:27:40 +0200, Dieter Maurer
 wrote:
>There is also "Plone" ("http://plone.org";) -- easy to set up.
>
>You likely need third party extensions for the "anti-SPAM" support
>and the onlie payment.

I'll see what extensions it offers. Thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list


Running Python web apps on shared ASO servers?

2012-08-11 Thread Gilles
Hello

I use A Small Orange (ASO) as my web provider. Asking the question in
their forum so far didn't work, so I figured I might have a faster
answer by asking here.

Support replied this in an old thread: "Just a CGI option. We don't
have enough users to justify adding mod_python support."
http://forums.asmallorange.com/topic/4672-python-support/page__hl__python
http://forums.asmallorange.com/topic/4918-python-fcgi-verses-mod-python/

Does it mean that ASO only supports writing Python web apps as
long-running processes (CGI, FCGI, WSGI, SCGI) instead of embedded
Python à la PHP?

If that's the case, which smallest tool would you recomment to write
basic apps, eg. handling forms, etc.?

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


Re: Running Python web apps on shared ASO servers?

2012-08-12 Thread Gilles
On Sun, 12 Aug 2012 07:56:26 +0200, Dieter Maurer
 wrote:
>You should probably read the mentioned forum resources to learn
>details about the Python support provided by your web site hoster.

Yup, but so far, no answer, so I figured someone here might now.

Those articles seem to indicate that CGI isn't a good solution when
mod_python isn't available, so it looks like I'll have to investigate
FastCGI, WSGI, etc.

http://docs.python.org/howto/webservers.html
http://stackoverflow.com/questions/219110/how-python-web-frameworks-wsgi-and-cgi-fit-together

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


Re: Running Python web apps on shared ASO servers?

2012-08-13 Thread Gilles
On Sun, 12 Aug 2012 22:26:19 +0100, Tim Golden 
wrote:
>Just to make a point: one person's "isn't a good solution" is another 
>person's "works perfectly well for me". Modern servers are really quite 
>quick: the cost of starting up a Python process and generating an HTML 
>page can be really quite low. I've certainly had low-traffic production 
>websites running for years on CGI without anyone complaining.

Thanks Tim for the input. I'll try the different solutions available
and see if CGI is good enough for my needs.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Running Python web apps on shared ASO servers?

2012-08-16 Thread Gilles
On Sun, 12 Aug 2012 02:03:33 +0200, Gilles  wrote:
>Does it mean that ASO only supports writing Python web apps as
>long-running processes (CGI, FCGI, WSGI, SCGI) instead of embedded
>Python à la PHP?

I need to get the big picture about the different solutions to run a
Python web application.

>From what I read, it seems like this is the way things involved over
the years:

CGI : original method. Slow because the server has to spawn a new
process to run the interpreter + script every time a script is run.

mod_python : Apache module alternative to CGI. The interpreter is
loaded once, and running a script means just handling the script

mod_wsgi : mod_python is no longer developped, and mod_wsgi is its new
reincarnation

FastCGI and SCGI: Faster alternativees to CGI; Run as independent
programs, and communicate with the web server through either a Unix
socket (located on the same host) or a TCP socket (remote  host)

Is this correct?

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


[CGI] Why is HTML not rendered?

2012-08-17 Thread Gilles
Hello

I'm learning how to call Python scripts through the different
solutions available.

For some reason, this CGI script that I found on Google displays the
contents of the variable but the HTML surrounding it is displayed
as-is by the browser instead of being rendered:

--
#!/usr/bin/env python
# -*- coding: UTF-8 -*-

# enable debugging
import cgitb
cgitb.enable()

import cgi
form = cgi.FieldStorage()

# get a value from the form
value = form.getvalue("dummy")

print "Content-Type: text/plain;charset=utf-8"
print

# print a document
print "You typed: %s" % (
cgi.escape(value),
)
--

Here's the output:
--
You typed: test
--

Could this be due to the script itself, or some server configuration?

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


Re: [CGI] Why is HTML not rendered?

2012-08-17 Thread Gilles
On Fri, 17 Aug 2012 14:44:37 +0100, Robert Kern
 wrote:
>> For some reason, this CGI script that I found on Google displays the
>> contents of the variable but the HTML surrounding it is displayed
>> as-is by the browser instead of being rendered

Thanks all. I (obviously) combined two scripts but didn't notice that
I had to change the "Content-Type" line to output HTML.
-- 
http://mail.python.org/mailman/listinfo/python-list


[CGI] Basic newbie error or server configuration error?

2012-08-20 Thread Gilles
Hello

Apache fails running this basic CGI script that I found on the Net:

www.acme.com/cgi-bin/test.py?name=myname
===
#!/usr/bin/env python

# Import modules for CGI handling
import cgi, cgitb

cgitb.enable()

# Create instance of FieldStorage
form = cgi.FieldStorage()

# Get data from field 'name'
#name = form['name'].value
name = form.getvalue('name')
===

This is what I get:
===
"Internal Server Error

The server encountered an internal error or misconfiguration and was
unable to complete your request.

Additionally, a 404 Not Found error was encountered while trying to
use an ErrorDocument to handle the request."
===

FWIW, the script lives in www/cgi-bin/ where it should, was chmoded to
755, and I put the following .htaccess file:
===
Options +ExecCGI
AddHandler cgi-script .py
===

I'm not sure where to look for an error. Could it be some non-printed,
bad characters that prevent Python from compiling the source code?

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


Re: [CGI] Basic newbie error or server configuration error?

2012-08-20 Thread Gilles
Found it: The script MUST return something to the browser. I was
missing this:


print "Content-Type: text/html;charset=utf-8"
print

# print a document
print "Name is %s" % ( cgi.escape(name), )


Sorry about that.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [CGI] Basic newbie error or server configuration error?

2012-08-20 Thread Gilles
On Mon, 20 Aug 2012 07:59:39 -0400, Rod Person
 wrote:
>Check the Apache error log, there should be more information there.

It's a shared account, so I only have access to what's in cPanel,
which didn't display anything. Problem solved.

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


Re: [CGI] Basic newbie error or server configuration error?

2012-08-20 Thread Gilles
On Mon, 20 Aug 2012 16:56:14 +0200, Hans Mulder 
wrote:
>Most such panels have a button to show the error log for your own site.
>
>If you can't find it, ask the help desk of the web hosting company.
>
>If there really is no way for you to see the error log, ask the help
>desk to mail you the error message.

Thanks. the cPanel at my provider only has a Logs > Error Log icon,
but the error I was having didn't result in anything in the log file.

I'll set up a Linux host at home and test Python scripts before
uploading them to my ISP.

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


[2.5.1] Read each line from txt file, replace, and save?

2012-09-02 Thread Gilles
Hello

This is a newbie question.

I need to read a text file into a variable, loop through each line and
use a regex to substitute some items within the line, and save the
whole variable into a new text file.

This triggers an error when I save the modified variable that contains
all the lines:
==
import re,sys

f = open("C:\\input.txt", "r")
textlines = f.readlines()
f.close()

for line in textlines:
#edit each line
line = "just a test"

#rewrite data to new file
log = open('output.sub','w')
#ERROR: argument 1 must be string or read-only character buffer, not
list
log.write(textlines)
log.close()
==

Should I use another way to read the file, edit each line, and save
the data into a new file?

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


Re: [2.5.1] Read each line from txt file, replace, and save?

2012-09-02 Thread Gilles
On Sun, 02 Sep 2012 12:19:02 +0200, Gilles  wrote:
(snip)

Found it:

#rewrite lines to new file
output = open('output.txt','w')

for line in textlines:
#edit each line
line = "just a test"
output.write("%s" % line)

output.close()
-- 
http://mail.python.org/mailman/listinfo/python-list


[web] Long-running process: FCGI? SCGI? WSGI?

2012-09-05 Thread Gilles
Hello

To write a long-running web application, I'd like to some feedback
about which option to choose.

Apparently, the choice boilds down to this:
- FastCGI
- SCGI
- WSGI

It seems like FCGI and SCGI are language-neutral, while WSGI is
Python-specific.

Besides that, how to make an informed choice about which option to
choose?

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


Re: [2.5.1] Read each line from txt file, replace, and save?

2012-09-05 Thread Gilles
On Sun, 02 Sep 2012 14:04:29 -0400, Terry Reedy 
wrote:
>If you process each line separately, there is no reason to read them all 
>at once. Use the file as an iterator directly. Since line is already a 
>string, there is no reason to copy it into a new string. Combining these 
>two changes with Mark's suggestion to use with and we have the following 
>simple code:

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


[WSGI] FCGID + Flup vs. mod_wsgi?

2012-09-21 Thread Gilles
Hello

The shared host I intend to use to run a small Python web app only
supports mod_fcgid on its Apache server.

If I understood what I read on the Net, the ideal solution would be to
have mod_wsgi installed and have it run either as a module within
Apache or a stand-alone process to talk to the Python app, but it's
N.A. so that's out.

As for FCGID, am I correct in understanding that this is the way
things work:

Apache <-> mod_fcgid <-> Flup (or some other wrapper) <-> WSGI
application?

www.stackoverflow.com/questions/1747266/is-there-a-speed-difference-between-wsgi-and-fcgi

Would I miss a lot by using the mod_fcgid+Flup solution instead of
mod_wsgi?

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


"#!/usr/bin/env python" vs. "#!/usr/bin/python"?

2012-09-28 Thread Gilles
Hello

I've seen both shebang lines to run a Python script on a *nix host:

#!/usr/bin/env python
#!/usr/bin/python

What's the difference?

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


Re: "#!/usr/bin/env python" vs. "#!/usr/bin/python"?

2012-09-28 Thread Gilles
On Fri, 28 Sep 2012 06:57:28 -0400, Roy Smith  wrote:
>The first one looks through your PATH to find the right python 
>interpreter to run.  The second one is hard-wired to run /usr/bin/python.
>
>If you only have a single copy of python installed, it doesn't really 
>matter which you use.  But, you might as well get into the habit of 
>using the /usr/bin/env flavor because it's more flexible.

Thanks guys. I suspected that's what the difference was.
-- 
http://mail.python.org/mailman/listinfo/python-list


How to investigate web script not running?

2012-09-28 Thread Gilles
Hello

I'm trying to run my very first FastCGI script on an Apache shared
host that relies on mod_fcgid:
==
#!/usr/bin/python
from fcgi import WSGIServer
import cgitb

# enable debugging
cgitb.enable()

def myapp(environ, start_response):
start_response('200 OK', [('Content-Type', 'text/plain')])
return ['Hello World!\n']

WSGIServer(myapp).run()
==

After following a tutorial, Apache complains with the following when I
call my script:
==
Internal Server Error

The server encountered an internal error or misconfiguration and was
unable to complete your request.
==

Generally speaking, what tools are available to investigate issues
when running a Python web app?

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


Re: How to investigate web script not running?

2012-09-28 Thread Gilles
On Fri, 28 Sep 2012 13:37:36 +0200, Gilles  wrote:

>==
>Internal Server Error
>
>The server encountered an internal error or misconfiguration and was
>unable to complete your request.
>==

Looks like fcgi.py doesn't support WSGI:

Traceback (most recent call last):
File "hello.fcgi", line 2, in ?
from fcgi import WSGIServer
ImportError: cannot import name WSGIServer
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to investigate web script not running?

2012-09-28 Thread Gilles
On Fri, 28 Sep 2012 14:16:22 +0200, "Michael Ross" 
wrote:
>Do it the other way around:
>
># cgitb before anything else
>import cgitb
>cgitb.enable()
>
># so this error will be caught
> from fcgi import WSGIServer

Thanks much for the tip. The error isn't displayed when calling the
script from a web browser but it is when running the script on a shell
account.

It looks like that newer version of fcgi.py doesn't include support
for WSGI, and I need some extra (Flup?) software to sit between
mod_fcgid and a WSGI Python application.

Definitely not plug 'n play :-/
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: "#!/usr/bin/env python" vs. "#!/usr/bin/python"?

2012-09-28 Thread Gilles
On Fri, 28 Sep 2012 09:19:54 -0400, D'Arcy Cain 
wrote:
>Not just flexible but portable.  On various systems I have Python
>in /usr/bin, /usr/local/bin and /usr/pkg/bin.  "#!/usr/bin/env python"
>finds it in each case so I only need one version of the script.

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


[fcgi.py] Force cache upgrade?

2012-09-28 Thread Gilles
Hello

Does someone know if something must be done after editing a FastCGI +
WSGI script so that the changes will show in the browser immediately
instead of having to wait X minutes?

===
#!/usr/bin/env python2.6

def myapp(environ, start_response):
start_response('200 OK', [('Content-Type', 'text/plain')])
return ['I CHANGED THIS\n']

if __name__ == '__main__':
from flup.server.fcgi import WSGIServer
WSGIServer(myapp).run()
===

I guess the FastCGI server (Flup) only updates its cache every so
often. Do I need to type a command to force Flup to recompile the
Python script?

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


Re: [fcgi.py] Force cache upgrade?

2012-09-28 Thread Gilles
On Fri, 28 Sep 2012 23:57:14 +0200, Gilles  wrote:
>I guess the FastCGI server (Flup) only updates its cache every so
>often. Do I need to type a command to force Flup to recompile the
>Python script?

Turns out that, yes, mod_fcgid is configured to reload a script only
after some time or some number of hits, and yes, mod_fcgid settings
are off-limit on a shared host.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to investigate web script not running?

2012-09-30 Thread Gilles
On Sat, 29 Sep 2012 10:05:25 -0700 (PDT), Ramchandra Apte
 wrote:
>> Definitely not plug 'n play :-/
>
>Well the plug and play standard is superseded by USB practically.

Indeed ;-)

Anyway, Support finally got back to me, and it turns out that they
have Flup alreay installed on shared hosts, so I just have to provide
a WSGI script. OTOH, mod_fcgid is confured to wait 5mn or so before
checking if the script was edited, so I'll have to use a test host for
development and only use the shared host for deployment.

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


[2.5.1 + CGI] Which interpreter and files?

2012-10-19 Thread Gilles
Hello

I'd like to use the Mongoose basic web server with Python which can
call scripts through CGI.

I have a coupole of questions:

1. Mongoose must be told in the shebang file where to locate the
interpreter, but ActivePython 2.5.1 comes with fours files that look
like the interpreter (actually, two files, since the other two have
the same size so they are probably left overs):

01/05/2007  18:0124.064 python.exe
01/05/2007  18:0124.064 python25.exe
01/05/2007  18:0124.576 pythonw.exe
01/05/2007  18:0124.576 pythonw25.exe


2. Which files and directories do I really need and must provide, and
which can I do without?

Directory of C:\Python25

20/07/2007  02:38  DLLs
20/07/2007  02:38  include
02/09/2012  11:47  Lib
20/07/2007  02:38  libs
18/07/2007  15:33   348.160 msvcr71.dll
28/10/2009  12:31 2.017 psyco-wininst.log
05/04/2008  03:17 9.226 py2exe-wininst.log
20/11/2008  15:13 4.218 pysqlite-wininst.log
01/05/2007  18:0124.064 python.exe
01/05/2007  18:0124.064 python25.exe
01/05/2007  18:0124.576 pythonw.exe
01/05/2007  18:0124.576 pythonw25.exe
03/05/2010  12:0161.440 Removeapsw.exe
28/10/2009  12:3161.440 Removepsyco.exe
05/04/2008  03:1761.440 Removepy2exe.exe
20/11/2008  15:1361.440 Removepysqlite.exe
14/11/2008  18:2261.440 Removesetuptools.exe
07/07/2010  14:43  Scripts
14/11/2008  18:24 9.859 setuptools-wininst.log
20/07/2007  02:39  tcl
20/07/2007  02:39  Tools
01/05/2007  18:01 4.608 w9xpopen.exe


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


Re: [2.5.1 + CGI] Which interpreter and files?

2012-10-19 Thread Gilles
On Fri, 19 Oct 2012 21:09:55 +1100, Chris Angelico 
wrote:
>The ones with the -w tag are designed for Windows apps that are going
>to bring up a GUI and don't want a console. The python[w]25.exe ones
>will be in case you have multiple Pythons installed and want to
>explicitly call for version 2.5. You probably want python.exe, but
>python25.exe will work too.

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


Re: python scripts for web

2012-10-19 Thread Gilles
On Thu, 18 Oct 2012 23:05:48 -0700 (PDT), chip9m...@gmail.com wrote:
>these scripts will do a lot of calculation on a big dataset, and it is 
>possible that there will be many requests in a short period of time.

In that case, are you sure a web script is a good idea? If you're
thinking web to make it easy for people to upload data, click on a
button, and get the results back, you might want to write the UI in
Python but write the number crunching part in a compiled language.
-- 
http://mail.python.org/mailman/listinfo/python-list


Question about long-running web scripts

2012-10-25 Thread Gilles
Hello

I'd like to check something about running Python web applications.

Generally speaking, the reason scripts run faster when called through
FastCGI or the mod_* modules, is because the interpreter is already up
and running.
But when running PHP scripts, this does nothing about fetching the
file from disk, recompiling, rerunning it, and usually reconnecting to
the database.

OTOH, Python web scripts can be written as long-running scripts: In
this case, what is the added-value of using FastCGI? Why can't the web
server simply call the Python script directly, just like CGI?

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


Re: Question about long-running web scripts

2012-10-25 Thread Gilles
On Thu, 25 Oct 2012 13:03:14 +0100, Tim Golden 
wrote:
>(Your question is a little confused at the end. I'm choosing to
>understand: why can't we just run Python one-shot, like CGI? The likely
>alternative meaning is: why can't the incoming request be routed to an
>already-running Python program -- which is not, of course, what CGI
>generally does. Hence my confusion).

Yes indeed. Sorry about the confusion.

But actually, I didn't mean one-shot scripts, where the Python
interpreter + script must be loaded each time, but rather: If I leave
a Python running in an endless loop, why not just use either CGI or
some other basic way to call the script instead of FastCGI?

In the case of PHP, FastCGI makes sense, but I don't see the benefit
for long-running Python scripts.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Question about long-running web scripts

2012-10-26 Thread Gilles
On Thu, 25 Oct 2012 08:53:11 -0400, David Hutto
 wrote:
>>> OTOH, Python web scripts can be written as long-running scripts: In
>>> this case, what is the added-value of using FastCGI? Why can't the
>>> web server simply call the Python script directly, just like CGI?
>
>The server should call a the script, or script.sleep()
>
>There are also server options to setup when a script is run, other
>than a cron jo for php.

Thanks. Does it mean that Python scripts that rely on either fcgi.py
or WSGI really have some endless loop somewhere and will keep running
once they're launched by FastCGI?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Question about long-running web scripts

2012-10-26 Thread Gilles
On Thu, 25 Oct 2012 14:24:16 +0100, Tim Golden 
wrote:
>> But actually, I didn't mean one-shot scripts, where the Python
>> interpreter + script must be loaded each time, but rather: If I leave
>> a Python running in an endless loop, why not just use either CGI or
>> some other basic way to call the script instead of FastCGI?
>
>In essence, you're describing FastCGI. A Python program (or, indeed, any
>program) which uses FastCGI runs continuously and waits for the incoming
>request on a TCP socket (instead of as a sys.stdin stream + env vars
>immediately after process startup).

Thanks for the clarification.

Since, unlike PHP, the Python interpreter is not available in a
FastCGI-capable version, this explains why the www server must be told
which specific Python script to run through FastCGI.

The reason I ask for all this, is that I want to understand how things
work under the hood before relying on a Python framework to handle the
nitty-gritty.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Question about long-running web scripts

2012-10-26 Thread Gilles
On Fri, 26 Oct 2012 12:00:17 +0100, Tim Golden 
wrote:
>Certainly there are Python equivalents (mod_python, mod_wsgi, etc.)
>which can run in effectively the same way as mod_php, and they could be
>configured to run an fcgi frontend script, I presume. There's always a
>certain confusion here because you can often one mechanisms (say,
>mod_wsgi) to act as another (say legacy one-shot CGI) and because some
>things are both mechanism and protocol and it's not always easy to tease
>the two apart.

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


[newbie] Equivalent to PHP?

2012-06-12 Thread Gilles
Hello

I'm an amateur programmer, and would like to know what the main
options are to build web applications in Python instead of PHP.

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).

Since web scripts are usually very short anyway (user sends query,
server handles request, sends response, and closes the port) because
the user is waiting and browsers usually give up after 30 seconds
anyway... why did Python solutions go for long-running processes while
PHP was built from the start as short-running processes?

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


Re: [newbie] Equivalent to PHP?

2012-06-12 Thread Gilles
On Tue, 12 Jun 2012 12:12:55 +0200, Alain Ketterlin
 wrote:
>You misunderstand the problem here. It's not about the duration of the
>actions, it's about the latency it takes to read/parse/execute the
>script. HTTP is stateless anyway, so if the same "interpreter" handles
>several requests, what you save by keeping the interpreter alive is the
>load/parse phase. If you relaunch an interpreter for every HTTP request,
>you pay the same price again and again for something which is not even
>related to your scripts' execution.

Thanks for the input.

But I read that PHP-based heavy-duty web servers compile the scripts
once and keep them in a cache, so they don't have to be
read/parsed/executed with each new query.

In that case, what is the benefit of using a long-running process in
Python?

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).

Apparently, very few people use Python à la PHP, ie. Python code
embedded in web pages?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [newbie] Equivalent to PHP?

2012-06-12 Thread Gilles
On Tue, 12 Jun 2012 07:42:56 -0400, D'Arcy Cain 
wrote:
>I guess I am in the minority then.  I do plan to turn one of my larger
>projects into a standalone web server some day but so far writing
>simple Python CGI scripts has served me fine.  I even do some embedding
>by using server side scripting.

Out of curiosity, why did you choose to write CGI scripts or embedded
server-side scripting while standalone web servers are usually
presented as _the_ solution for Python (Django, Pylons, etc.)?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [newbie] Equivalent to PHP?

2012-06-12 Thread Gilles
On Tue, 12 Jun 2012 22:01:10 +1000, Chris Angelico 
wrote:
>Apache's mod_php partially evens out the difference, but not
>completely, and of course, it's perfectly possible to write a dispatch
>loop in PHP, as Octavian said.

It looks like mod_php and equivalents for web servers other than
Apache are anecdotal compared to solutions based on standalone web
servers. Is that the case? Why is that?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [newbie] Equivalent to PHP?

2012-06-12 Thread Gilles
On Tue, 12 Jun 2012 20:18:21 +1000, Chris Angelico 
wrote:
>Think of it as Apache + PHP versus Python. Apache keeps running, it's
>only your PHP script that starts and stops. With a long-running
>process, you keep everything all in together, which IMHO is simpler
>and better.

Why is a long-running process better?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [newbie] Equivalent to PHP?

2012-06-12 Thread Gilles
On Tue, 12 Jun 2012 14:28:22 +0300, "Octavian Rasnita"
 wrote:
>Otherwise... if you want you can also create a web app using PHP and 
>CodeIgniter web framework and run it with fastcgi...

Thanks for the infos.
-- 
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 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 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


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


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 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


Re: [newbie] Equivalent to PHP?

2012-06-14 Thread Gilles
On Wed, 13 Jun 2012 19:03:29 -0500, Tim Chase
 wrote:
>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.

Thanks much. So the next step will have to find a framework that's
right for a given application.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Simple Python script as SMTP server for outgoing e-mails?

2013-08-01 Thread Gilles
On Wed, 24 Jul 2013 10:38:52 -0400, Kevin Walzer 
wrote:
>> Thanks. hMailServer was one of the apps I checked, and I was just
>> making sure there weren't something simpler, considering my needs,
>> ideally something like Mongoose MTA.
>>
>> Regardless, because of the SPAM anti-measures mentioned above, it
>> seems like I was over-optimistic about running an MTA and sending
>> e-mails from my home computer :-/
>>
>
>The reason I mentioned hMailServer is that I host my own mail server for 
>my business--I have a static IP address, and correctly configured 
>DNS--and so I'm able to send out large batches of e-mails to customers 
>from my network without being blocked by my ISP. I'm running a Mac 
>server so my mail system is the typical Unix setup (Postfix, etc.), but 
>hMailServer was the closest thing I've found for Windows.
>
>Configuring your own server isn't cheap in terms of time even if you use 
>FOSS components, and your ISP may charge more for a static IP, so I 
>completely understand if you don't want to go that route.

Thanks for the infos. Indeed, it seems like hMailServer is one of the
few good MTAs for Windows.

I already have a static IP, so the issue is more that remote MTAs
might not accept connections from MTAs running on users' PC instead of
ISP's.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Source code to identify user through browser?

2013-08-06 Thread Gilles
On Wed, 05 Jun 2013 15:08:54 +0200, Gilles  wrote:
>I was wondering if some Python module were available to identify a
>user through their browser, like it's done on the Panopticlick site:
>
>http://panopticlick.eff.org/

It appears that flash cookies is a better solution to keep most trolls
away from a forum/blog:

www.stackoverflow.com/questions/216542/

Still, I wish there a browser that could run in real incognito mode,
ie. would only send the minimum amount of infos to the server.
-- 
http://mail.python.org/mailman/listinfo/python-list


[GUI] Good frameworks for Windows/Mac?

2013-08-06 Thread Gilles
Hello

I need to write a small GUI application that should run on Windows and
Mac.

What open-source framework would you recommend? I just need basic
widgets (button, listbox, etc.) and would rather a solution that can
get me up and running fast.

I know about wxWidgets and Qt: Are there other good options I should
know about?

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


Re: Simple Python script as SMTP server for outgoing e-mails?

2013-08-06 Thread Gilles
On Sat, 3 Aug 2013 06:47:07 -0500 (CDT), Wayne Werner
 wrote:
>Have you checked Kenneth Rietz's inbox.py[1]? It's fairly simple to 
>use/extend and might fit your modest needs.
>
>
>-W
>
>[1]:https://crate.io/packages/inbox/

Thanks. I'll check it out.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Simple Python script as SMTP server for outgoing e-mails?

2013-08-06 Thread Gilles
On Sat, 03 Aug 2013 21:41:16 -0400, Kevin Walzer 
wrote:
>For what it's worth, that hasn't been my experience.

Thanks for the feedback. I'll experiment and see how it goes.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Can someone suggest better resources for learning sqlite3? I wanted to use the Python library but I don't know sql.

2013-08-06 Thread Gilles
On Sat, 3 Aug 2013 10:57:32 -0700 (PDT), Aseem Bansal
 wrote:
>I found Python3's sqlite3 library. I found that I needed sql commands for 
>using it.
>
>I have tried sql.learncodethehardway but it isn't complete yet. I tired 
>looking on stackoverflow's  sql tag also but nothing much there.

It'll be easier to read tutorials specifically meant to use Sqlite
with Python:

www.google.com/search?q=python+sqlite+examples
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [GUI] Good frameworks for Windows/Mac?

2013-08-06 Thread Gilles
On Tue, 6 Aug 2013 13:22:01 +0200, Vlastimil Brom
 wrote:
>I mostly use wxPython myself, but if you just need some basic widgets
>and not some very complex or non-standard layouts, the tkinter -
>available in the standard library - might be perfectly viable.
>http://docs.python.org/3.3/library/tk.html
>The more recent versions of python also support ttk and Tix which has
>further possibilities, styling etc.
>There is further e.g. Python GUI
>http://www.cosc.canterbury.ac.nz/greg.ewing/python_gui/
>
>and several others
>http://wiki.python.org/moin/GuiProgramming

Thanks for the links. I'll play with Tkinter, and if it's not good
enough, check the alternatives.
-- 
http://mail.python.org/mailman/listinfo/python-list


[ActivePython] Upgrading fails

2013-08-06 Thread Gilles
Hello,

I already posted in their forum, but got no reply and figured some
people here might have experienced this too.

I'm currently running ActivePython 2.5.1.1 on my XP Pro host.

After downloading and running the installer to 2.7.2.5, I get the
following error message:

"Windows Installer: The Windows Installer Service could not be
accessed. This can occur if the Windows Installer is not correctly
installed."

Has someone seen this, and knows what to do?

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


Re: [GUI] Good frameworks for Windows/Mac?

2013-08-08 Thread Gilles
On Thu, 8 Aug 2013 01:47:21 -0700 (PDT), sagar varule
 wrote:
>Pyside is also Good. It has a Designer which can be helpful.

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


[ActivePython] Add Qt/PyQt and wxWidgets/wxPython?

2013-08-08 Thread Gilles
Hello

I upgraded to ActivePython 2.7.2.5, and would like to get started
learning about Qt and wxWidgets in Python.

I have a couple of question:

1. Are there obvious reasons to choose either QT/PyQt or
wxWidgets/wxPython? I have the impression that Qt is a richer GUI than
wxWidgets, but it could just be an impression.

2. Is there a no-brainer article that explains how to add Qt and
wxWidgets to ActivePython community edition, since they're only
included in the Business and Enterprise editions?

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


[2.4.3/Newbie] Web script doesn't run

2013-02-11 Thread Gilles
Hello

I have a couple of newbie questions about using Python in a FastCGI
+ Flup context on a shared CentOS server:

1. The following script runs fine...
=
#!/usr/bin/env python2.6

def myapp(environ, start_response):
start_response('200 OK', [('Content-Type', 'text/plain')])
return ['Done!\n']

if __name__ == '__main__':
from flup.server.fcgi import WSGIServer
WSGIServer(myapp).run()
=

... while this triggers an error:
=
#!/usr/bin/env python2.6
# -*- coding: UTF-8 -*-

from cgi import escape
import sys, os

def app(environ, start_response):
start_response('200 OK', [('Content-Type', 'text/html')])

yield 'FastCGI Environment'
yield ''
for k, v in sorted(environ.items()):
 yield '%s%s' % (escape(k),
escape(v))
yield ''

if __name__ == '__main__':
from flup.server.fcgi import WSGIServer
WSGIServer(app).run()
=

"Internal Server Error: The server encountered an internal error or
misconfiguration and was unable to complete your request. [...]
Additionally, a 404 Not Found error was encountered while trying to
use an ErrorDocument to handle the request."

2. Generally speaking, what is the right way to investigate an error
in a Python web script? FWIW I have access to the shared server
through SSH.

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


Re: [2.4.3/Newbie] Web script doesn't run

2013-02-11 Thread Gilles
On Mon, 11 Feb 2013 10:30:01 +0100, Gilles  wrote:
>   I have a couple of newbie questions about using Python in a FastCGI
>+ Flup context on a shared CentOS server:

Please ignore the thread. I found the error, and a way to catch
compile-time errors (log on through SSH, and run "python
./myscript.py").
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: [2.4.3/Newbie] Web script doesn't run

2013-02-11 Thread Gilles
On Mon, 11 Feb 2013 21:30:12 +1100, Chris Angelico 
wrote:
>That'll catch some forms of error, but not everything. You may also
>want to consider looking for your server's error log - that may be
>getting the actual traceback. I don't know what your server setup is,
>but there's likely to be one somewhere.

Good to know.

>A question though. You say "2.4.3" in your subject line, but your
>shebang says python2.6 - which version are you actually running?

I didn't pay attention to this. Support says that I should use 2.6,
but running "python -V" through SSH says 2.4.3. I'll ask support which
to use.

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


Re: [2.4.3/Newbie] Web script doesn't run

2013-02-11 Thread Gilles
On Mon, 11 Feb 2013 22:30:45 +1100, Chris Angelico 
wrote:
>Try running python2.6 -V
>
>Your shebang line says that it's looking for a program named
>"python2.6", which is quite probably not the same as the one named
>just "python".

Indeed, they have two versions of Python installed:

# python2.6 -V
Python 2.6.4

# python -V
Python 2.4.3

I'll make sure to use 2.6.

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


Re: [2.4.3/Newbie] Web script doesn't run

2013-02-11 Thread Gilles
On Mon, 11 Feb 2013 22:42:50 +1100, Chris Angelico 
wrote:
>It's entirely possible you have a third Python, a 3.x, as well.
>Different Pythons coexist quite happily on a system.

Thank for the help. I'm on my way to figure out how mod_fcgid, Flup,
and Python scripts work together.
-- 
http://mail.python.org/mailman/listinfo/python-list


Installing Apache 2 and mod_wsgi on CentOS?

2013-02-12 Thread Gilles
Hello

Before I go ahead, I'd like to make sure I'm doing it the right away:

1. yum install httpd mod_wsgi

2. Edit /etc/sysconfig/httpd to uncomment this line to get Apache to
run as worker MPM:
"#HTTPD=/usr/sbin/httpd.worker"

3. Edit mod_wsgi

4. Build a test WSGI Python script

5. Start Apache, and launch a browser

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


[WSGI] Tell Python to listen to LAN interface?

2013-03-26 Thread Gilles
Hello

I'm following this tutorial to learn about writing Python apps in
WSGI:

http://webpython.codepoint.net/wsgi_tutorial

On a Linux host with Python 2.6.6 installed, I launched the
"Environment dictionary" sample, but can't connect to it from my
remote Windows host since the application only accepts local queries:

# netstat -tunlp
...
tcp0  0 127.0.0.1:8051  0.0.0.0:* LISTEN
13110/python

How can I tell the Python interpreter to listen on 0.0.0.0 or at least
192.168.0.0/24?

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


Re: [WSGI] Tell Python to listen to LAN interface?

2013-03-26 Thread Gilles
On Tue, 26 Mar 2013 23:50:36 +1100, Chris Angelico 
wrote:
>According to the docstring, the first argument to make_server() is the
>host name to bind to. Using "localhost" means you're bound to
>127.0.0.1, as you see. Use your LAN IP address there, or "" to bind to
>all local addresses - or possibly "::" to bind to all IPv6 addresses
>(try it and see - some systems work with one or the other, others work
>happily with both together).

Thanks Chris. I was thinking it was due to how Python was configured,
and didn't first check that it could be some instruction in the script
itself. It works fine now.
-- 
http://mail.python.org/mailman/listinfo/python-list


What web server for WSGI? Recommended book?

2013-03-27 Thread Gilles
Hello

After going through multiple articles about the advantage of using
WSGI instead of FastCGI + Flup to run Python web apps, I have a couple
of questions:

1. Which server + WSGI module would you recommend? I know about Apache
and Graham Dumpleton's mod_wsgi, but what about Lighttpd and Nginx? I
read that Nginx's mod_wsgi written by Manlio Perillo is not
recommended.

2. At this point, is there a recommended book to learn how to write
web applications in Python, preferably one that would first show the
underlying mechanics before showing the main frameworks (web.py,
Pylons, TurboGears, Django, etc.) so that I understand what's going on
under the hood.

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


Cross-compiling Python for ARM?

2013-04-15 Thread Gilles
Hello

I tried running uWSGI on an ARM-based appliance, but it fails. 

Apparently, it could be due to the official Python 2.6.6 interpreter
in the depot not being compiled the way uWSGI expects it to be:

./configure --enable-shared; make; make install;
www.raspberrypi.org/phpBB3/viewtopic.php?f=32&t=15370

I see Python mentioned in /usr/lib and /usr/share, and was wondering
if all it'd take to solve this issue, is just to cross-compile the
interpreter and the rest is just CPU-agnostic Python scripts.

Just in case, here's the output:
www.pastebin.com/wJHjBrfn

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


Re: Cross-compiling Python for ARM?

2013-04-20 Thread Gilles
On Tue, 16 Apr 2013 17:22:55 +0300, Anssi Saari  wrote:
>In any case, cross compiling Python shouldn't be that hard. I
>just recently built 2.7.3 for my OpenWRT router since the packaged
>Python didn't have readline support (some long standing linking issue
>with readline and ncurses and uClibc).

Thanks guys. Turns out the error was not due to Python, so the ARM
version available in the Debian depot is fine.
-- 
http://mail.python.org/mailman/listinfo/python-list


Iterating over files of a huge directory

2012-12-17 Thread Gilles Lenfant
Hi,

I have googled but did not find an efficient solution to my problem. My 
customer provides a directory with a hge list of files (flat, potentially 
10+) and I cannot reasonably use os.listdir(this_path) unless creating a 
big memory footprint.

So I'm looking for an iterator that yields the file names of a directory and 
does not make a giant list of what's in.

i.e :

for filename in enumerate_files(some_directory):
# My cooking...

Many thanks by advance.
-- 
Gilles Lenfant
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Iterating over files of a huge directory

2012-12-17 Thread Gilles Lenfant
Le lundi 17 décembre 2012 16:52:19 UTC+1, Oscar Benjamin a écrit :
> On 17 December 2012 15:28, Gilles Lenfant <...> wrote:
> 
> 
> In the last couple of months there has been a lot of discussion (on
> 
> python-list or python-dev - not sure) about creating a library to more
> 
> efficiently iterate over the files in a directory. The result so far
> 
> is this library on github:
> 
> https://github.com/benhoyt/betterwalk
> 
> 
> 
> It says there that
> 
> """
> 
> Somewhat relatedly, many people have also asked for a version of
> 
> os.listdir() that yields filenames as it iterates instead of returning
> 
> them as one big list.
> 
> 
> 
> So as well as a faster walk(), BetterWalk adds iterdir_stat() and
> 
> iterdir(). They're pretty easy to use, but see below for the full API
> 
> docs.
> 
> """
> 
> 
> 
> Does that code work for you? If so, I imagine the author would be
> 
> interested to get some feedback on how well it works.
> 
> 
> 
> Alternatively, perhaps consider calling an external utility.
> 

Many thanks for this pointer Oscar.

"betterwalk" is exactly what I was looking for. More particularly iterdir(...) 
and iterdir_stat(...)
I'll get a deeper look at betterwalk and provide (hopefully successful) 
feedback.

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


[2.5.1] Script to download and rename bunch of files?

2011-04-08 Thread Gilles Ganault
Hello,

Before I go ahead and learn how to write this, I was wondering if
someone knew of some source code I could use to download and rename a
bunch of files, ie. the equivalent of wget's -O switch?

I would provide a two-column list where column 1 would contain the
full URL, and column 2 would contain the name to use to rename the
file once downloaded.

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


Re: [2.5.1] Script to download and rename bunch of files?

2011-04-08 Thread Gilles Ganault
On Fri, 08 Apr 2011 15:14:27 +0200, Laurent Claessens
 wrote:
>The following puts in the string `a` the code of the page urlBase :
>
>a = urllib.urlopen(urlBase).read()
>
>Then you have to write `a` in a file.
>
>There could be better way.

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


wxPython & Cygwin

2005-10-13 Thread Gilles DRIDI
Does someone has installed wxPython on the Cygwin platform, environment ?

Thank you
Gilles DRIDI
http://cdridi.club.fr 


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


"bad argument type for built-in operation"

2005-01-24 Thread Gilles Arnaud
Hello,
I've got a nasty bug and no idea to deal with :
here is the method :

def denormer(self, var) :
" denorme un vecteur d'entree "
try:
#a = map(self.decerner, self.param, var)
#a = [self.decerner(x, y) for x, y in map(None, 
self.param, var)]
a = []
print 'in', None, self.param, var, len(self.param), 
len(var), str(self.decerner)
#return map(undoc, self.param, var)
print map(None, var)
print map(None, self.param)
#print zip(var, var)
#print zip(self.param, self.param)
#print map(lambda x, y: (x,y), self.param, var)
#print zip(self.param, var)
b = []
print '$',
ii = range(len(var))
print ii, '$',
for i in ii :
print '%',
b.append((self.param[i], var[i]))
print b, '/',
print '$',
print b
for x,y in b :
print x, y
z = undoc(x, y)
print z
a.append(z)
except TypeError, c :
print 'E', str(self.decerner), self.param, var
print 'E2', str(c)
raise
return a

in fact the method was initially reduce to

return map(self.decerner, self.param, var)

all the commented line produced the same exception raised

this method unnormalize an input vector (var)
and the trace

in None [(-2.0, 2.0), (-2.0, 2.0)] [0.1385039192456847, 
0.87787941093093491] 2 2 
[0.1385039192456847, 0.87787941093093491]
[(-2.0, 2.0), (-2.0, 2.0)]
$ [0, 1] $ % [((-2.0, 2.0), 0.1385039192456847)] / % [((-2.0, 
2.0), 0.1385039192456847), ((-2.0, 2.0), 0.87787941093093491)] / $ 
[((-2.0, 2.0), 0.1385039192456847), ((-2.0, 2.0), 
0.87787941093093491)]
(-2.0, 2.0) 0.138503919246
% 0.277007838491
(-2.0, 2.0) 0.877879410931
% 1.75575882186
in None [(-2.0, 2.0), (-2.0, 2.0)] [0.38111874838950943, 
0.74880175070169164] 2
2 
[0.38111874838950943, 0.74880175070169164]
[(-2.0, 2.0), (-2.0, 2.0)]
$ [0, 1] $ % [((-2.0, 2.0), 0.38111874838950943)] / % [((-2.0, 
2.0), 0.38111874838950943), ((-2.0, 2.0), 0.74880175070169164)] / 
E 
[(-2.0, 2.0), (-2.0, 2.0)] [0.38111874838950943, 0.74880175070169164]
E2 bad argument type for built-in operation

[...]

the first call of the methode succeed
all following call failed.
I've got different scenario which call this low level methode,
many succeed, some failed this way.
what's happened ?
If someone got an idea ?
what can raise this exception ?
My program is written partially in python and partially in C.
the top level is in python which call a C optimisation routine
which use a callback (PyObject_CallMethod) to evaluate the cost in
python again.
--
http://mail.python.org/mailman/listinfo/python-list


Re: how to pass attribute name via sys.argv

2005-01-27 Thread Gilles Lenfant
Felix Hebeler a écrit :
Hi all,
I am doing some Python scripting for a while, but I'm not too deep into 
it yet. So I have a problem I can't solve.

I need to call an object attribute:
value = object.attrName[0]
the problem is, that the attribute name can only be specified at runtime.
So what I have is something like
 >>> attrName = sys.argv[1]
 >>> attrName
'cellsize'
and I need to pass it on so I can call
value = object.cellsize[0]
Can this be done using Python?
Thanks for any hints
Cheers
Felix
The builtin "setattr" is your friend.
"object" is now a reserved (builtin) name, use "objekt" instead.
class Foo(object):
pass
objekt = Foo()
attrName = sys.argv[1]
values = ['foo', 'bar', 'whatever']
setattr(objekt, attrName, values)
HTH
--
Gilles
--
http://mail.python.org/mailman/listinfo/python-list


Linux/Python -> SQL*Server Connexion chain

2005-09-22 Thread Gilles Lenfant
Hi,

Have you guys any good experience on connecting a Python (Zope) app 
running on Linux to a Windoze SQL*Server ?

Many thanks by advance to report your success, failure, pitfalls (...) 
and used products.

Even reports using commercial solutions are welcome.

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


Using PyOpenGL what should I use for a GUI ?

2005-02-26 Thread Gilles Leblanc
Hi I have started a small project with PyOpenGL. I am wondering what
are the options for a GUI. So far I checked PyUI but it has some
problems with 3d rendering outside the Windows platform.

I know of WxPython but I don't know if I can create a WxPython window,
use gl rendering code in it and then put widgets on top of that...

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


Stopping a wsgiref server programmatically

2014-01-14 Thread Gilles Lenfant
Hi,

I made a small / minimal wsgiref HTTP server dedicated to unittest stubs 
(testing custom REST client and other likes) that works pretty good in a 
separate thread.

https://gist.github.com/glenfant/7369894

Feel free to reuse it in your own unittest stubs/mocks.

But it only works like a charm in an Unix box, due to the use of a control pipe 
( https://gist.github.com/glenfant/7369894#file-pipetestserver-py-L118 ) that's 
checked with select.select ( 
https://gist.github.com/glenfant/7369894#file-pipetestserver-py-L133 ) and can 
be stopped on request when writing in that pipe ( 
https://gist.github.com/glenfant/7369894#file-pipetestserver-py-L173 ).

Is there a volunteer with a Windows box for helping me to get it fixed. Note: I 
have no windows box to experiment alternate.

Many thanks by advance.
-- 
Gilles Lenfant
-- 
https://mail.python.org/mailman/listinfo/python-list


Skipping decorators in unit tests

2013-10-10 Thread Gilles Lenfant
Hi,

(explaining the title) : my app has functions and methods (and maybe classes in 
the future) that are decorated by decorators provided by the standard library 
or 3rd party packages.

But I need to test "undecorated" functions and methods in my unit tests, 
preferably without adding "special stuffs" in my target tested modules.

Can someone point out good practices or dedicated tools that "remove 
temporarily" the decorations.

I pasted a small example of what I heed at http://pastebin.com/20CmHQ7Y

Many thanks in advance
-- 
Gilles Lenfant
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Skipping decorators in unit tests

2013-10-11 Thread Gilles Lenfant
Cameron, Steven, Ben, Ned, Terry, Roy. Many thanks for this interesting 
discussion.

I ended up... mixing some solutions provided by your hints :

* Adding an "__original__" attribute to the wrapper func in the decorators of 
my own
* Playing with "func_closure" to test functions/methods provided by 3rd party 
tools

Cheers and thanks again for taking time to help me.

-- 
Gilles Lenfant
-- 
https://mail.python.org/mailman/listinfo/python-list


  1   2   3   >