Re: [Webware-devel] Filters for Webware

2006-09-18 Thread Dan Milstein

Chris,

Thanks for the quick response -- I didn't expect to go in 0.9.2 -- no  
worries about that.


Two things:

 1) I *did* screw up the tabs/spaces in one of the files -  
FilterChain.py.


I've attached a fixed version.  Sorry.  I've got Emacs set up to use  
spaces by default, and going back and forth is, um, tricky.  Here's  
hoping (but not expecting) that this is the last such mistake.



 2) Attached is the start of a tutorial/how-to style doc on using  
filters


I'm attaching it in rough form to a) give a teaser for folks on this  
list who want to try filters out, and b) get feedback on whether or  
not this is a useful kind of doc.  I'll keep working on this one, but  
if people are feeling like it's too simple, or would work better as  
part of a general Webware tutorial, let me know.


-Dan

from Common import *


class FilterChain(Object):
	

	A FilterChain holds the specific, ordered list of Filters which are
	found to apply to a given request.	They participate in transactions.
	
	XXX NOT IMPLEMENTED YET XXX
	It is intended that FilterChains can be created once, then used and
	destroyed, or they may be reused several times over (it's up to the
	server). 

	Objects that participate in a transaction include:
	
	* Application
	* Request
	* Transaction
	* Session
	* Servlet
	* Response
	* FilterChain

	The awake(), respond() and sleep() methods form a message
	sandwich. Each is passed an instance of Transaction which gives further
	access to all the objects involved.
	

	## Init ##
	
	def __init__(self):
		 Subclasses must invoke super. 
		Object.__init__(self)
		self._serverSidePath = None
		self._filters = []


	## Access ##
	
	def name(self):
		 Returns the name which is simple the name of the class.
		Subclasses should *not* override this method. It is used for
		logging and debugging. 
		return self.__class__.__name__


	## Filter Creation ##
	def addFilter(self, filter):
		self._filters.append(filter)

	## Request-response cycles ##

	def awake(self, trans):
		 This message is sent to all objects that participate in the
		request-response cycle in a top-down fashion, prior to respond().
		self._transaction = trans
		for f in self._filters:
			f.awake(trans)

	def respond(self, trans):
		filters = self._filters
		next = Next(filters)
		first = filters[0]
		first.filter(trans, next)

	def sleep(self, trans):
		for f in self._filters:
			f.sleep(trans)
		#del self._filters


	## Abilities ##

	def canBeThreaded(self):
		 Returns 0 or 1 to indicate if the servlet can be multithreaded. This value should not change during the lifetime of the object. The default implementation returns 0. Note: This is not currently used. 
		return 0

	def canBeReused(self):
		 Returns 0 or 1 to indicate if a single servlet instance can be
		reused. The default is 1, but subclasses con override to return
		0. Keep in mind that performance may seriously be degraded if
		instances can't be reused. Also, there's no known good reasons not
		to reuse and instance. Remember the awake() and sleep() methods are
		invoked for every transaction. But just in case, your servlet can
		refuse to be reused.
		return 1


	## Server side filesystem ##

	def serverSidePath(self, path=None):
		 Returns the filesystem path of the page on the server. 
		if self._serverSidePath is None:
			if hasattr(self, _request) and self._request is not None:
self._serverSidePath = self._request.serverSidePath()
			else:
self._serverSidePath = self._transaction.request().serverSidePath()
		if path:
			return os.path.normpath(os.path.join(os.path.dirname(self._serverSidePath), path))
		else:
			return self._serverSidePath


	## Cleanup ##
	
	def clearTransaction(self):
		del self._transaction



class Next(Object):

	def __init__(self, chain, curIdx = 0):
		Object.__init__(self)
		self._chain = chain
		self._curIdx = curIdx

	def __call__(self, trans):
		nextIdx = self._curIdx + 1
		chain = self._chain
		if nextIdx  len(chain):
			raise Exception(next called past end of FilterChain: %s % chain)
		nextFilter = chain[nextIdx]
		nextNext = Next(chain, nextIdx)
		nextFilter.filter(trans, nextNext)
	
 
 

Filters in Webware
Dan Milstein


Overview
Filters give you a simple, clean way to specify your own path-based
   request-handling pipeline.  They are useful for authorization, for URL
   manipulation, for logging, and for many other situations.


An Authorization example:
Let's say the specification for overall, site-wide authorization looks
   something like the following:


 Users have to log in in order to view the site...


 

 ...except for content rooted at /public, which is openly accessible


 

 If a user has logged in, there will be a user_id stored in the session


 

 If a non-logged in user attempts to access a non-public page, they should
  be redirected to /Login


 

 After logging in, such a user should be taken to the page they originally
  requested


 


The Code

 Create an AuthorizerFilter module with a class 

Re: [Webware-devel] Filters for Webware

2006-09-18 Thread John Dickinson
I like the idea of these filters, and I can definitely see how they 
could be useful. Having only looked at your examples and the doc you 
provided, though, I do have a couple of questions/suggestions.

One, according to the documentation, you set up filters in 
Application.config. Would it be possible to use them in a per-servlet 
way? In other words, instead of setting the filters per instance in the 
config file, could I define a filter chain in the __init__ or awake() of 
an application's base class (some SitePage)?

Two, although I'm sure I could figure it out by actually using the 
filters, you documentation does not quite tie all of the pieces together 
for me. For example, the first thing I though of when reading The Code 
section is Where does the import go? Where do I import the 
AuthorizerFilter that you set up in the config? I'd like to see a 
complete (but simple) example. I know that the docs are only 
preliminary, but that's my $.02USD.

All-in-all, though, good job. It looks like a really handy tool to have.

--John


  2) Attached is the start of a tutorial/how-to style doc on using filters

 I'm attaching it in rough form to a) give a teaser for folks on this 
 list who want to try filters out, and b) get feedback on whether or 
 not this is a useful kind of doc.  I'll keep working on this one, but 
 if people are feeling like it's too simple, or would work better as 
 part of a general Webware tutorial, let me know.

 -Dan

-
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT  business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV
___
Webware-devel mailing list
Webware-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/webware-devel


Re: [Webware-devel] Filters for Webware

2006-09-18 Thread Dan Milstein
Thanks much for the response.  Questions:

 One, according to the documentation, you set up filters in
 Application.config. Would it be possible to use them in a per-servlet
 way? In other words, instead of setting the filters per instance in  
 the
 config file, could I define a filter chain in the __init__ or awake 
 () of
 an application's base class (some SitePage)?

I'm not sure if I fully understand this (and I'd like to).  What  
would it mean for them to be per-servlet?  Would that mean that the  
chain could depend on which servlet was actually called, rather than  
on which filters matched the URL?

One of the strengths of the way it works now is it's actually  
important/useful to define behavior on the pattern of the URL.   
That's sort of the big win.

Or am I misunderstanding?  Could you talk out how you'd imagine using  
it in a per-servlet manner?


 Two, although I'm sure I could figure it out by actually using the
 filters, you documentation does not quite tie all of the pieces  
 together
 for me. For example, the first thing I though of when reading The  
 Code
 section is Where does the import go? Where do I import the
 AuthorizerFilter that you set up in the config? I'd like to see a
 complete (but simple) example. I know that the docs are only
 preliminary, but that's my $.02USD.

Very helpful.  Thanks.  I'll take a pass at writing a small, complete  
application.

In answer to your question: you don't ever have to import  
AuthorizerFilter -- Webware does so for you (so to speak) when it  
builds a chain which needs it.  Your servlet code doesn't import or  
interact with the filter code directly.  A filter can communicate  
with/influence servlet code, but only via the web data: a filter can  
modify the data in the request, or change the path, or store things  
in the session, or, if it wanted to do something really devious,  
could replace response/request objects in the transaction  
altogether.  You could look at it as -- the filter can help set up  
the environment in which the servlet then executes.

I'll try to make this all clearer in the docs.

Thanks again -- very useful feedback.

-Dan

-
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT  business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV
___
Webware-devel mailing list
Webware-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/webware-devel


Re: [Webware-devel] Filters for Webware

2006-09-18 Thread John Dickinson
In my initial excitement of the idea, I got a little ahead of myself. I 
see where you are coming from now, and why you define the filters in the 
config file. The big problem with putting a filter in a sevlet is that 
that same servlet might not have been accessed based on it's own filter. 
But the filter wouldn't have been called if you never loaded the 
servlet. Catch-22.

However, I do think that there is value in being able to define a filter 
per-servlet. By this I mean that each sevlet could define behavior on 
it's own based on the path so far, with filters defined in 
Application.config serving as a default. Also, the filters could be 
processed down through the inheritance hierarchy. So the SitePage's 
filters would fire, then the MiddlePage's, and finally, assuming the 
filters allowed the request to get this far, the ChildPage's filter 
would be processed. But if I want that, maybe I should just use CherryPy 
;-). They have (IMHO) a nice URL parsing system that seems very similar 
to this (at least functionally).

I still like the idea of these filters in Webware (even if it's not 
per-servlet).

--John
 I'm not sure if I fully understand this (and I'd like to).  What  
 would it mean for them to be per-servlet?  Would that mean that the  
 chain could depend on which servlet was actually called, rather than  
 on which filters matched the URL?

 One of the strengths of the way it works now is it's actually  
 important/useful to define behavior on the pattern of the URL.   
 That's sort of the big win.

 Or am I misunderstanding?  Could you talk out how you'd imagine using  
 it in a per-servlet manner?
   

-
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT  business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV
___
Webware-devel mailing list
Webware-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/webware-devel


[Webware-devel] Webware/Apache Threading Problem, Take II

2006-09-18 Thread Dan Milstein
So: I was having problems with large file uploads in my dev  
environment (OS X 10.4, Apache 2), and not in my production  
environment (Linux something, Apache 2).

I have a bit more story, and I've resolved the problem.  Here's the  
scoop, if you're interested:

  - I upgraded my apache install from 2.0.52 to 2.0.55 (using fink),  
and the problem went away

No idea what random bug was fixed in apache which made this so, but  
things are working now.

Just so everyone can know...
-Dan 

-
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT  business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV
___
Webware-devel mailing list
Webware-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/webware-devel


Re: [Webware-devel] Webware/Apache Threading Problem, Take II

2006-09-18 Thread Mark Phillips
On Sep 18, 2006, at 1:43 PM, Dan Milstein wrote:

 So: I was having problems with large file uploads in my dev
 environment (OS X 10.4, Apache 2), and not in my production
 environment (Linux something, Apache 2).

 I have a bit more story, and I've resolved the problem.  Here's the
 scoop, if you're interested:

   - I upgraded my apache install from 2.0.52 to 2.0.55 (using fink),
 and the problem went away

 No idea what random bug was fixed in apache which made this so, but
 things are working now.

Even with the remaining mystery, that makes for a happy Monday, eh?

  - Mark


-
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT  business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.phpp=sourceforgeCID=DEVDEV
___
Webware-devel mailing list
Webware-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/webware-devel