how to use WSGI applications with apache

2009-10-07 Thread travis+ml-python
Hi folks,

I'm not quite sure where to ask this, but this is my closest guess.

I've written a web service based on the newf micro-framework and it uses
wsgiref.simple_server.  I'm noticing that it's not returning response
codes properly (after fixing a bug in newf).  Instead, it just
closes the TCP connection silently.

I am assuming that I need to run it with a more sophisticated server,
and I eventually want to run it under apache, but I can't seem to
figure out how to do this.  Someone once showed me how, and it was
a simple line in the apache config.  But I can't figure it out how
to do again.

Any help?
-- 
Obama Nation | My emails do not have attachments; it's a digital signature
that your mail program doesn't understand. | 
http://www.subspacefield.org/~travis/ 
If you are a spammer, please email j...@subspacefield.org to get blacklisted.


pgpJzDE6lo3nC.pgp
Description: PGP signature
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is Python a functional programming language?

2010-05-15 Thread travis+ml-python
On Mon, May 10, 2010 at 08:45:51PM +0100, Nobody wrote:
> On Tue, 11 May 2010 00:24:22 +1200, Samuel Williams wrote:
> > Is Python a functional programming language?
> Not in any meaningful sense of the term.

LOL

> > I heard that lambdas were limited to a single expression,
> 
> Yes. In a functional language that wouldn't be a problem, as there's no
> limit to the complexity of an expression. Python's expressions are far
> more limited, which restricts what can be done with a lambda.

One very annoying thing in Python is the distinction between
statements and expressions.

Ever since learning LISP (well, Scheme) in S&ICP I find myself
frequently annoyed by this pointless distinction, started by
C (or earlier), and propogated without much thought.

Often I'll want to write a lamda that, say, prints something, or
modifies a global variable, and find that, well, it's either
impossible or beyond my interest in figuring it out.

It appears there is finally a ternary operator (for making if/else
into "expressions"):
http://en.wikipedia.org/wiki/Ternary_operation#Python
Maybe it will grow on me - it makes sense in English, but on
first glance I thought the programmer suffered from dyslexia.

To be fair, it appears that Python's whitespace-sensitive syntax sort
of precludes the "make a complex function on one line" that is typical
of languages which don't have statement/expression distinctions, but
I'm not convinced it couldn't be solved, perhaps by allowing anonymous
functions to span multiple lines, just like named functions.

> > Finally, even if Python supports functional features, is this a model that
> > is used often in client/application code?
> 
> Not really. List comprehensions are probably the most common example of
> functional idioms, but again they're limited by Python's rather limited
> concept of an expression.

Map/reduce, lambda, apply, that kind of stuff... kinda similar to
functional languages.

But "statements lack any side effects"?  No way.

In fact, a common distinction you'll see observed, but not always, is
that "statements may have side effects, expressions do not".

For some definitions of "functional language", there are no
side-effects, so there is no need for a statement which doesn't
evaluate to a value, so there is no need for a statement/expression
distinction, so everything is an expression.

You may have seen Paul Graham's other article about Python and LISP:
http://www.paulgraham.com/icad.html

Upon re-skimming it, I find myself wondering if I got the
expression/statement annoyance from his pages, or from my own
experience.  I can't remember :-) Probably it was an annoyance that I
hadn't put my finger on until he spelled it out for me, like a
splinter in my mind :-)

He obliquely references my other pet peeve, the global/class/local
distinction, completely ignoring arbitrarily-nested lexical scoping.
From what I've read in this thread, there's a recent "nonlocal"
declaration that sounds like it might accomplish something useful in
this regard.

(I still haven't figured out how he managed to use lexical closures in
 his web server to allow one web page to use another to allow the user
 to select and return a value, like a color from a color wheel, unless
 he implemented his own web server in LISP, since HTTP is stateless).

I really like Scheme's clean syntax (never learned Common LISP, sorry,
too much to remember) but frankly, I've never looked at a problem and
said, "you know, Scheme would be perfect for this".  Maybe if I was
writing a program that did optimizing transformations on abstract
syntax trees, or something.  And since Scheme has never come in handy,
I never bothered with Common LISP.  I feel similarly about ML, OCAML
and Haskell... maybe one day when I'm bored, not today, not this
project.

So in the end, I find myself using python more than anything else,
fully acknowledging its warts.  I used to admire its simplicity, but
now with decorators, iterators, generators, metaclasses, and the
proliferation of special method names, I have to wonder if that still
holds true...  certainly I understand 90+% of python programs, but
do I understand that proportion of the constructs?

PS: Why do people call LISP object-oriented?  Are they smoking crack?
No classes, no methods, no member variables... WTF?
-- 
A Weapon of Mass Construction
My emails do not have attachments; it's a digital signature that your mail
program doesn't understand. | http://www.subspacefield.org/~travis/ 
If you are a spammer, please email j...@subspacefield.org to get blacklisted.


pgpYyYI8jLDVr.pgp
Description: PGP signature
-- 
http://mail.python.org/mailman/listinfo/python-list


pythonic web markup languages & templating systems & site generators

2010-06-05 Thread travis+ml-python
I started to review static blog-like HTML generators, and found myself
overwhelmed with how many there were.  I narrowed it down to pythonic
ones, and then realized I had to pick a markup language and templating
language, of which there are several pythonic implementations...

The results of my inquiry (still ongoing) are here:

http://www.subspacefield.org/~travis/static_blog_generators.html

It's a little disorganized, but does represent a fair amount of work,
and might be a nice intro for a python programmer who isn't up to
his neck in web authoring tools.

Suggestions on how to organize it are welcome.  Of course, while
writing it, I was struck by how much I actually needed one of these
systems to write the reviews of the systems :-) writing raw HTML
is teh suck.
-- 
A Weapon of Mass Construction
My emails do not have attachments; it's a digital signature that your mail
program doesn't understand. | http://www.subspacefield.org/~travis/ 
If you are a spammer, please email j...@subspacefield.org to get blacklisted.


pgpnVFtgT60rk.pgp
Description: PGP signature
-- 
http://mail.python.org/mailman/listinfo/python-list


proposal: add setresuid() system call to python

2009-07-17 Thread travis+ml-python
Hello,

Historically, I have used scripting languages like python for typical
uses, but they tend to not fare very well at system programming; for
close interfacing with the operating system, I'm often forced to use a
language like C.  This is undesirable to me.

I do not think this has to be the case; I see no reason why a
scripting language can't implement more of the system call API, at the
risk of having some OS-dependent modules.  I would actually like to
see more network servers written in scripting languages, as they
neatly avoid buffer overflow and integer overflow issues with no extra
effort.

One BIG roadblock to doing this is when they can't manage to drop
permissions properly.

I am suggesting that the setresuid function be added to python,
perhaps in the OS module, because it has the clearest semantics for
manipulating user ids.  The reason why is best described in the
following paper:

http://www.eecs.berkeley.edu/~daw/papers/setuid-usenix02.pdf

One argument against this is that it is not specified by POSIX, and
thus might be dismissed as "implementation dependent".

However, as the paper above demonstrates, even though the setuid
system call is defined by POSIX, it already has system-dependent
behavior.  POSIX provides for at least two different behaviors of the
setuid call, and even more if you consider that it leaves what
constitutes "appropriate privileges" up to the OS kernel.

I humbly propose that python implement all the routines necessary to
securely drop privileges, to enable construction of network daemons
that might need to drop privileges from root to some non-root userid
(e.g. mail transfer agents, or POP/IMAP servers).

Furthermore, where there are multiple system calls to achieve this
effect, it should implement the ones with the clearest semantics, and
setresuid fits that bill.  To see what an utter mess the uid-manipulation
routines are in, I refer you once again to this paper, as the situation
is too complicated to describe in this email:

http://www.eecs.berkeley.edu/~daw/papers/setuid-usenix02.pdf

Opinions?

Best,
Travis
-- 
Obama Nation | My emails do not have attachments; it's a digital signature
that your mail program doesn't understand. | 
http://www.subspacefield.org/~travis/ 
If you are a spammer, please email j...@subspacefield.org to get blacklisted.


pgpVyRpXxMRRP.pgp
Description: PGP signature
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: proposal: add setresuid() system call to python

2009-08-21 Thread travis+ml-python
On Mon, Jul 20, 2009 at 04:10:35PM +0200, Hrvoje Niksic wrote:
> To emulate the os-module-type calls, it's better to raise exceptions
> than return negative values:
> 
> > def setresuid(ruid, euid, suid):
> > return _setresuid(__uid_t(ruid), __uid_t(euid), __uid_t(suid))
> 
> def setresuid(ruid, euid, suid):
> res = _setresuid(__uid_t(ruid), __uid_t(euid), __uid_t(suid))
> if res < 0:
> raise OSError('[Errno %d] %s' % (os.errno, errno.strerror(os.errno)))

I am working on a module to implement all of this, but that raise command
won't work in Python 2.6.1; it turns out that os.errno is a module, not
an integer.  Does anyone know how to do what I want (that is, how to access
the errno set in C functions)?
-- 
Obama Nation | My emails do not have attachments; it's a digital signature
that your mail program doesn't understand. | 
http://www.subspacefield.org/~travis/ 
If you are a spammer, please email j...@subspacefield.org to get blacklisted.


pgpCAmvYfWNJs.pgp
Description: PGP signature
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: proposal: add setresuid() system call to python

2009-08-25 Thread travis+ml-python
On Fri, Aug 21, 2009 at 03:13:12PM -0500, tra...@subspacefield.org wrote:
> Since the authors of the paper (Wagner et. al.) are proposing a new
> set of APIs to make all of this clearer, I'm thinking that I will
> create a module specifically for dropping permissions.

I've created the module here:

http://www.subspacefield.org/~travis/python/privilege/

I could sure use any comments people had on my python style.

PyPi link:
http://pypi.python.org/pypi/privilege/1.0
-- 
Obama Nation | My emails do not have attachments; it's a digital signature
that your mail program doesn't understand. | 
http://www.subspacefield.org/~travis/ 
If you are a spammer, please email j...@subspacefield.org to get blacklisted.


pgpPM2rX9bRlM.pgp
Description: PGP signature
-- 
http://mail.python.org/mailman/listinfo/python-list


run-time inclusion of files

2009-09-05 Thread travis+ml-python
Hello,

I was wondering if there was something like Perl's "require" that allows
you to import a file whose name is specified at run-time.  So far I've only
seen imports of modules that are put in the standard module include path.

I'm interested in three seperate problems:

1) being able to import a file that isn't in the standard module include path

2) being able to import a file whose name is specified in a python string

3) being able to reload the file if it changes on disk

I'm pretty sure that the Pylons web framework does all this, and I'm also
pretty sure that there's a simple solution, I am just not aware of what
it is.
-- 
Obama Nation | My emails do not have attachments; it's a digital signature
that your mail program doesn't understand. | 
http://www.subspacefield.org/~travis/ 
If you are a spammer, please email j...@subspacefield.org to get blacklisted.


pgpPfqVqghzQh.pgp
Description: PGP signature
-- 
http://mail.python.org/mailman/listinfo/python-list