Re: bye bye mod_python, hello... what?
Luca Montecchiani <[email protected]> Wed, 10 Feb 2010 15:11:34 +0100
| Newsgroups | gmane.comp.python.mod_python |
|---|---|
| Message-ID | <[email protected]> |
That's great, can you post your code somewhere ? I've done the _psp part entirely in python using re. It's not 100% compatible with the original _psp module because we use psp just to place widgets, no complex code execution, no include etc.. but it works well and fast. Interested people can extend the attached code to be 100% compatible with the original psp mod_python module ;-) Thanks in advance, luca Martijn Moeling ha scritto: For people NOT using frameworks with lots of code I have a fake code compatible MOD_PYTHON module which runs on top of MOD_WSGI It works faster (No real benchmarks available, it feels much faster) and does not include support for publisher since I do not need it and don't even looked into it I do not even know what it is. Authorization is currently being developed, Session and Cookies work. It calls handler(req): end soon the AuthHandler(req), supports req.register_cleanup Basically it is WSGI API Bridge ..... Martijn On Jan 17, 2010, at 10:46 PM, Graham Dumpleton wrote: 2010/1/18 Samuel Hazelett <alertmaster-/[email protected]> : I am little disappointed in the Apache Software Foundation for having taken mod_python under its umbrella only to allow it to wither. The ASF is a volunteer organisation. You can't therefore blame the ASF. The problem is that users of mod_python (such as yourself), can't be bothered contributing to mod_python any more. If you, or anyone else, is truly passionate about mod_python then all you need to do is step up and volunteer to take over the project, albeit that any handover may be problematic due to inactivity of majority of prior developers. This though isn't insurmountable as that is where the ASF project management committees would step in and likely assist in delegating control over to new contributors. At least in my role as member of the ASF, if I didn't care, I would have removed myself from the mailing list over 2 years ago when I stopped being interested in mod_python. Instead I still hang around here and answer peoples questions. If mod_python is moribund, what will happen to [email protected] ? The modpython.org domain is not under the ownership of the ASF anyway, nor is the content on the site. Both are owned by the original primary author of mod_python and he is also missing in action. That they are owned by him and not the ASF is part of the problem. That is, it was always exceedingly difficult to get anything on that site updated. As a result, certain things related to the site have decayed over time and haven't been able to be fixed. What's to say the new-fangled API won't suffer a similar fate? Because it is described by a Python PEP. These are as close as you get to a standard in the Python world. See: http://www.python.org/dev/peps/pep-0333/ If, as you say Doug, WSGI API bridge is a better idea, then I shouldn't become/remain a Luddite and I "should get with the program". It certainly where the mindshare currently is. I had brought mod_python into my workplace because of a, perhaps outdated, recommedation that it should be coupled with Django. With respect to the workplace, I work in a secured lab that makes it a small nuisance to bring anything new within its perimeter. For this reason, I do most of my learning/experimenting with non-sensitive test data on my home desktop. Maybe I should drop the Django idea, too. I haven't invested much time in it, nor bought the book. Django is not bound to mod_python. If you had read any books on Django then maybe you would know this. The Django stack can quite happily run on top of WSGI hosting mechanisms such as mod_wsgi. I see mention of such related s/w as werkzeug, CherryPy, and pythonpaste. I'm barely a Python programmer, hand-jamming database connections and HTML reports. What's a newbie to do? Keep using Django since you have started with it already. Just read the hosting documentation for Django and understand that it can run on various hosting mechanisms. Other Python web frameworks are WSGI specific, but Django isn't. Graham ________________________________ From: Doug Epling <wdepli-eTB/42tb3KxWk0Htik3J/[email protected]> To: Samuel Hazelett <alertmaster-/[email protected]> Cc: [email protected] Sent: Sun, January 17, 2010 9:28:32 AM Subject: Re: [mod_python] bye bye mod_python, hello... what? Samuel Hazelett wrote: "unfortunately, mod_python is deprecated" What does this mean: deprecated Why? Does it mean there will be no future releases of mod_python? The "end of history!" I was just getting started. Woe is me/us. Yeah, I am the same way, especially, having worked with php some, with losing the concept of psp as well as the publisher handler. But from what I can tell the WSGI API bridge is a much better idea. mod_wsgi is designed to be to python what rails is to ruby. Except python is a standards based technology!;-) ________________________________ From: Graham Dumpleton <[email protected]> To: [email protected] Cc: [email protected] Sent: Tue, January 12, 2010 5:27:34 PM Subject: Re: [mod_python] bye bye mod_python, hello... what? 2010/1/13 Clodoaldo Neto <[email protected]> : 2010/1/12 mog <[email protected]> : So, the time has come. I need to start a new project and also migrate my old mod_python stuff to something else :( After all the sweat, blood and tears I put into learning about how Python web apps work, learning how to use mod_python, and how to put web apps together (using mod_python). It's really sad to think that a good portion of that effort seems lost because, unfortunately, mod_python is deprecated :( I looked at a few web frameworks but found they either simply didn't work, exhibited weird random unpredictable behaviour that was impossible to work with, or seemed to abstract so far away from real HTTP which made me feel uncomfortable. I finally settled on mod_python because it seemed to be a nice balance of powerful functionality and usefulness - oh, and it worked. With mod_python I felt as though I was working closely with the HTTP requests because I could use the request objects directly and, if I wanted (and I did), stick stuff in them to use in sessions. mod_python seemed pretty raw, but not so much so that I had to write my own request handlers and all the nitty gritty things like that (which, being new to web development, was and probably still is beyond my ability to do well and securely). I liked it because it also provided lots of in-built utilities making it really easy to do session handling, redirection and so on. I'm trying to avoid using one of the mainstream frameworks because I feel they overcomplicate things, bloat things up, and abstract too much away from what is really going on. Many of them annoyingly also end up requiring a bazillion dependencies to install. Personally I like to use small and compact programs that are really good at doing the small number of things I need them to, as opposed to installing some giant application (and all its dependencies) that can do everything under the sun I'll never use. With all this in mind. I was hoping someone would please be so kind as to recommend things that I could use instead of mod_python as a WSGI layer, but that hopefully works in a similar way to mod_python? You could start trying Werkzeug which calls itself "a simple collection of various utilities for WSGI applications". http://werkzeug.pocoo.org/ Then WebOb: http://pythonpaste.org/webob/ Regarding small and simple I think the two above are some of the best approaches but don't expect something like the mod_python's publisher handler. I'd second Werkzeug, but also add 'bobo' which uses Paste but gives some simple to use URL dispatch mechanisms. Neither have inbuilt session support however, so for that you would need to use Beaker. Graham _______________________________________________ Mod_python mailing list [email protected] http://mailman.modpython.org/mailman/listinfo/mod_python ________________________________ _______________________________________________ Mod_python mailing list [email protected] http://mailman.modpython.org/mailman/listinfo/mod_python _______________________________________________ Mod_python mailing list [email protected] http://mailman.modpython.org/mailman/listinfo/mod_python _______________________________________________ Mod_python mailing list [email protected] http://mailman.modpython.org/mailman/listinfo/mod_python _______________________________________________ Mod_python mailing list [email protected] http://mailman.modpython.org/mailman/listinfo/mod_python -- Luca Montecchiani Software Di Base TeamSystem S.p.a. ------------------------------------------------------------------------------------------ Informativa ai sensi del D. Lgs. 196-30/06/2003. Il contenuto di questa e.mail e degli eventuali allegati, deve essere nella disponibilità del solo destinatario. Se ricevete per errore questa e-mail siete pregati di informarci (rispedendola al mittente) e di provvedere alla sua rimozione. Possono essere presenti informazioni riservate e non corrette (parzialmente o totalmente). Le e-mail in partenza e in arrivo possono essere oggetto di monitoraggio da parte di Teamsystem spa. Del contenuto è responsabile il mittente della presente. Chiunque venga in possesso non autorizzato di questa e-mail è vincolato dalla Legge a non leggerne il contenuto, a non copiarla, a non diffonderla e a non usarla. Informiamo che per l' esercizio dei diritti di cui all'art. 7 del d.lgs.196/2003 ci si può rivolgere al Titolare del trattamento Teamsystem S.r.l. via Gagarin 205 61100 PESARO per posta o fax, indicando sulla busta o sul foglio la dicitura "Inerente alla Privacy", o inviando una e-mail all' indirizzo [email protected] . ------------------------------------------------------------------------------------------ _______________________________________________ Mod_python mailing list [email protected] http://mailman.modpython.org/mailman/listinfo/mod_python
_psplite.py
(text/x-python, 4 KB)
# coding=utf-8
# ---------------------------------------------------------------
# Project: TeamPortal
# Source : _psplite.py
# Date : Thu May 24 11:14:35 CEST 2009
# Author : TeamSystem Spa
# Contact: http://www.teamsystem.com
# License: see _libs/_licenses/
# ---------------------------------------------------------------
#
# Cache code from mod_python 3.3.1 -> psp.py :
#
# Copyright 2004 Apache Software Foundation
#
# Licensed under the Apache License, Version 2.0 (the "License"); you
# may not use this file except in compliance with the License. You
# may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied. See the License for the specific language governing
# permissions and limitations under the License.
#
# This file originally written by Sterling Hughes
#
# $Id: psp.py 472053 2006-11-07 10:11:01Z grahamd $
import os
import re
delimiter = re.compile(r"<%=(.*?)%>", re.DOTALL)
class PSP(object):
'''
PSP lite class
'''
def __init__(self,req,pspname,pspvars):
self.req = req
self.html = None
self.pspvars = dict(pspvars)
self.compile(pspname)
def compile(self,pspname):
if pspname.startswith('/str:'):
# da stringa
template = pspname[5:]
#in cache?
cached = mem_scache.get(template)
if cached:
self.code = cached
return
else:
# from file
mtime = os.path.getmtime(pspname)
# check cache
cached = mem_fcache.get(pspname, mtime)
if cached:
self.code = cached
return
template = file(pspname,'rb').read()
source = ''
for i, part in enumerate(delimiter.split(template)):
if i % 2 == 0:
if part:
source += "__write(%r);" % part
else:
source += "__write(str(%s));" % part.strip()
self.code = compile(source, '<string>', 'exec')
# store in cache
if pspname.startswith('/str:'):
mem_scache.store(template,self.code)
else:
mem_fcache.store(pspname, mtime, self.code)
def render(self):
if self.html is not None:
return
output = []
self.pspvars["__write"] = output.append
exec self.code in self.pspvars
self.html = ''.join(output)
return self.html
def run(self):
self.render()
# no flush
self.req.write(self.html,0)
class HitsCache:
def __init__(self, size=512):
self.cache = {}
self.size = size
def store(self, key, val):
self.cache[key] = (1, val)
if len(self.cache) > self.size:
self.clean()
def get(self, key):
if key in self.cache:
hits, val = self.cache[key]
self.cache[key] = (hits+1, val)
return val
else:
return None
def clean(self):
byhits = [(n[1], n[0]) for n in self.cache.items()]
byhits.sort()
# delete enough least hit entries to make cache 75% full
for item in byhits[:len(self.cache)-int(self.size*.75)]:
val, key = item
del self.cache[key]
mem_scache = HitsCache()
class FileCache(HitsCache):
def store(self, filename, mtime, code):
self.cache[filename] = (1, mtime, code)
if len(self.cache) > self.size:
self.clean()
def get(self, filename, mtime):
try:
hits, c_mtime, code = self.cache[filename]
if mtime != c_mtime:
del self.cache[filename]
return None
else:
self.cache[filename] = (hits+1, mtime, code)
return code
except KeyError:
return None
mem_fcache = FileCache()