J.D. Main | 3 Apr 2010 18:32
Picon

IIS and Python CGI - how do I see more than just the form data?

Hi Folks,

I hope this question hasn't already been answered...

I'm using IIS 5 and calling a python script directly in the URL of a request.  
Something like:

http://someserver/myscript.py

or even

http://someserver/myscript.py?var1=something&var2=somthingelse

Using the CGI module, I can certainly see and act upon the variables that 
are passed as  GET or POST actions.  What I'm after is something more 
low level.  I want to see the entire HTTP request with everything inside it.

Does IIS actually pass that information to the CGI application or does it just 
pass the variables?

The intent is to write a "RESTFUL" CGI script.  I need to actually "see" the 
URI and the parameters of the incoming request to map the appropriate 
action.  Without short circuiting the IIS webserver, how would my python 
parse the following:

http://someserver/someapp/someuser/someupdate?var1=Charlie

Thanks in advance!

JDM
(Continue reading)

Aaron Watters | 5 Apr 2010 16:14
Picon
Favicon
Gravatar

Re: IIS and Python CGI - how do I see more than just the form data?

I think you should consider using the
WSGI interface.

The WSGI interface puts all the components of a request
into a request environment dictionary which is sent as a
parameter to the function generating the response.  
For example have a look at the test application

http://whiffdoc.appspot.com/tests/misc/testDebugDump?thisVar=thatValue&thisOtherVar=ThatOtherValue

which dumps out the WSGI environment (with WHIFF extensions)
to the response.  All the information you need is somewhere inside
the environment dictionary (but it's not always easy to find).

You could also look at WHIFF which helps combine some of the
features of the CGI module with the WSGI interface.

http://whiffdoc.appspot.com/

Hope that helps,  -- Aaron Watters

===
% man less
less is more.

--- On Sat, 4/3/10, J.D. Main <jdmain@...> wrote:

> From: J.D. Main <jdmain@...>
> Subject: [Web-SIG] IIS and Python CGI - how do I see more than just the form data?
> To: web-sig@...
(Continue reading)

Randy Syring | 6 Apr 2010 22:37

SQLAlchemy Queries & HTML Data Grid

I am planning on building a library that will facilitate creation of custom queries and html display of resulting datasets from SQLAlechemy queries.  I have some basic work done here:

https://svn.rcslocal.com:8443/svn/pysmvt/pysapp/branches/0.1/pysapp/modules/datagrid/

But I don't like the API and I don't want the library to be dependent on pysapp.  Furthermore, I would like to have a more verbose querying ability akin to Redmine:

http://www.redmine.org/projects/redmine/issues

Including:
  • Filters
  • Column Selection
  • Grouping (multiple levels)
  • Sorting (multiple columns)
  • some kind of query saving/loading mechanism with a flexible backend
I have done some basic table generation work here:

https://svn.rcslocal.com:8443/svn/pysmvt/pysdatagrid/trunk/

with the tests being the best place to get an idea of how it works:

https://svn.rcslocal.com:8443/svn/pysmvt/pysdatagrid/trunk/pysdatagrid/tests/test_render.py

Looking for comments, pointers to other projects, and/or possibly interest in helping with a project like this.  I am currently working in SVN but will most likely move to hg/git if there are others who are interested.
-- -------------------------------------- Randy Syring Intelicom 502-644-4776 "Whether, then, you eat or drink or whatever you do, do all to the glory of God." 1 Cor 10:31
_______________________________________________
Web-SIG mailing list
Web-SIG@...
Web SIG: http://www.python.org/sigs/web-sig
Unsubscribe: http://mail.python.org/mailman/options/web-sig/gcpw-web-sig%40m.gmane.org
J.D. Main | 7 Apr 2010 03:25
Picon

Re: IIS and Python CGI - how do I see more than just the form data?

Thanks Aaron,

I think I will explore the WSGI interface.  However, I did learn a trick using 
the OS Module:

import cgi, os

formfields = cgi.FieldStorage()
http_stuff = os.environ

print "Content-type: text/html"
print
print "<html>"
print "<head>"
print "<title>Raw HTTP Test</title>"
print "</head>"
print "<body>"

print formfields
print http_stuff

print "</body>"
print "</html>"

The os.environ variable is a big dictionary containing most (if not all) of the 
values inside the original http GET or POST.

Best Regards,

JDM

I think you should consider using the
WSGI interface.

The WSGI interface puts all the components of a request
into a request environment dictionary which is sent as a
parameter to the function generating the response.  
For example have a look at the test application

http://whiffdoc.appspot.com/tests/misc/testDebugDump?thisVar=thatValue&
thisOtherVar=ThatOtherValue

which dumps out the WSGI environment (with WHIFF extensions)
to the response.  All the information you need is somewhere inside
the environment dictionary (but it's not always easy to find).

You could also look at WHIFF which helps combine some of the
features of the CGI module with the WSGI interface.

http://whiffdoc.appspot.com/

Hope that helps,  -- Aaron Watters

===
% man less
less is more.

--- On Sat, 4/3/10, J.D. Main <jdmain@...> wrote:

> From: J.D. Main <jdmain@...>
> Subject: [Web-SIG] IIS and Python CGI - how do I see more than just the form data?
> To: web-sig@...
> Date: Saturday, April 3, 2010, 12:32 PM
> Hi Folks,
> 
> I hope this question hasn't already been answered...
> 
> I'm using IIS 5 and calling a python script directly in the
> URL of a request.  
> Something like:
> 
> http://someserver/myscript.py
> 
> or even
> 
> http://someserver/myscript.py?var1=something&var2=somthingelse
> 
> Using the CGI module, I can certainly see and act upon the
> variables that 
> are passed as  GET or POST actions.  What I'm
> after is something more 
> low level.  I want to see the entire HTTP request with
> everything inside it.
> 
> Does IIS actually pass that information to the CGI
> application or does it just 
> pass the variables?
> 
> The intent is to write a "RESTFUL" CGI script.  I need
> to actually "see" the 
> URI and the parameters of the incoming request to map the
> appropriate 
> action.  Without short circuiting the IIS webserver,
> how would my python 
> parse the following:
> 
> http://someserver/someapp/someuser/someupdate?var1=Charlie
> 
> Thanks in advance!
> 
> JDM
> 
> 
> _______________________________________________
> Web-SIG mailing list
> Web-SIG@...
> Web SIG: http://www.python.org/sigs/web-sig
> Unsubscribe: http://mail.python.org/mailman/options/web-sig/arw1961%40yahoo.com
> 
_______________________________________________
Web-SIG mailing list
Web-SIG@...
Web SIG: http://www.python.org/sigs/web-sig
Unsubscribe: http://mail.python.org/mailman/options/web-sig/gcpw-web-sig%40m.gmane.org

Aaron Watters | 7 Apr 2010 16:03
Picon
Favicon
Gravatar

Re: SQLAlchemy Queries & HTML Data Grid


Thanks Randy, very interesting.

My initial reaction is that you are building a stack on top of a stack.
It's not clear to me what problem you want to solve
and your requirements are.  It's possible that
you could find it easier to abstract directly on top of SQL or alternatively
you could consider using another sort of data model like mongodb.
Building an abstraction on top of SQLAlchemy which hasn't even reached
1.0 strikes me as dubious.

Thanks again,  -- Aaron Watters

--- On Tue, 4/6/10, Randy Syring <rsyring-KjVcCr55iNUxpvK4C0GaPQ@public.gmane.org> wrote:

From: Randy Syring <rsyring-KjVcCr55iNUxpvK4C0GaPQ@public.gmane.org>
Subject: [Web-SIG] SQLAlchemy Queries & HTML Data Grid
To: web-sig-+ZN9ApsXKcEdnm+yROfE0A@public.gmane.org
Date: Tuesday, April 6, 2010, 4:37 PM

I am planning on building a library that will facilitate creation of custom queries and html display of resulting datasets from SQLAlechemy queries.  I have some basic work done here:

https://svn.rcslocal.com:8443/svn/pysmvt/pysapp/branches/0.1/pysapp/modules/datagrid/

But I don't like the API and I don't want the library to be dependent on pysapp.  Furthermore, I would like to have a more verbose querying ability akin to Redmine:

http://www.redmine.org/projects/redmine/issues

Including:
  • Filters
  • Column Selection
  • Grouping (multiple levels)
  • Sorting (multiple columns)
  • some kind of query saving/loading mechanism with a flexible backend
I have done some basic table generation work here:

https://svn.rcslocal.com:8443/svn/pysmvt/pysdatagrid/trunk/

with the tests being the best place to get an idea of how it works:

https://svn.rcslocal.com:8443/svn/pysmvt/pysdatagrid/trunk/pysdatagrid/tests/test_render.py

Looking for comments, pointers to other projects, and/or possibly interest in helping with a project like this.  I am currently working in SVN but will most likely move to hg/git if there are others who are interested.
--
--------------------------------------
Randy Syring
Intelicom
502-644-4776

"Whether, then, you eat or drink or
whatever you do, do all to the glory
of God." 1 Cor 10:31

-----Inline Attachment Follows-----

_______________________________________________
Web-SIG mailing list
Web-SIG@...
Web SIG: http://www.python.org/sigs/web-sig
Unsubscribe: http://mail.python.org/mailman/options/web-sig/gcpw-web-sig%40m.gmane.org
Aaron Watters | 7 Apr 2010 16:06
Picon
Favicon
Gravatar

Re: IIS and Python CGI - how do I see more than just the form data?


--- On Tue, 4/6/10, J.D. Main <jdmain@...> wrote:

> From: J.D. Main <jdmain@...>
> Subject: Re: [Web-SIG] IIS and Python CGI - how do I see more than just the form data?
> To: web-sig@...
> Date: Tuesday, April 6, 2010, 9:25 PM
> Thanks Aaron,
> 
> I think I will explore the WSGI interface.  However, I
> did learn a trick using 
> the OS Module:
> 
> import cgi, os
> 
> formfields = cgi.FieldStorage()
> http_stuff = os.environ .....

Yes, that will work too.  In fact the CGI interface to WSGI
works like this.  The advantage to using WSGI is that it
makes it possible to move your application to other configurations
more easily (in theory) and it's just a tiny bit more high level.

Best regards,  -- Aaron Watters

_______________________________________________
Web-SIG mailing list
Web-SIG@...
Web SIG: http://www.python.org/sigs/web-sig
Unsubscribe: http://mail.python.org/mailman/options/web-sig/gcpw-web-sig%40m.gmane.org

Randy Syring | 7 Apr 2010 19:37

Re: SQLAlchemy Queries & HTML Data Grid

Aaron,

Sorry, I must not really have explained clearly.  This isn't an abstraction layer, but more like a UI component or widgit that facilities basic reporting.  Look at these pages:

http://www.redmine.org/issues
http://trac.edgewall.org/query

Both pages have a similar structure:
  • UI Controls
    • filtering
    • grouping
    • column selection
    • sorting
  • Paged/Sortable Recordset Display
The library would do the heavy lifting and allow any application using SQLAlchemy to easily create such query/recordset interfaces to underlying data.

You would need to:
  • Instantiate the DataGrid class
  • Create a base SQLAlchemy query to be used for the data
  • Define the filter types associated with the columns (i.e. TextFieldFilter, OptionsFilter('low','medium', 'high'), DateSpanFilter, etc.)
  • Limit sorting, grouping to appropriate columns
  • choose which columns of the dataset to show by defaults
The library would then:
  • parse GET/POST for filter/column/sort/page settings &/or use defaults
  • compose SQLALchemy query to satisfy the request
  • execute the query and get the database results
  • put results into an HTML table
  • return the HTML form needed for the controls and the recordset table including necessary CSS and JS
Obviously, the library should be easily customizable and the rendering of HTML should be flexible.  It should also be flexible enough to work with the different WSGI libraries out there.

I hope that makes better sense.  If you or anyone else is interested, I can give you some code I have working from the pysapp project which does some basic filtering, paging, and sorting.  The API is awful, but I think it might give you a better idea of what I am talking about.

-------------------------------------- Randy Syring Intelicom 502-644-4776 "Whether, then, you eat or drink or whatever you do, do all to the glory of God." 1 Cor 10:31

Aaron Watters wrote:

Thanks Randy, very interesting.

My initial reaction is that you are building a stack on top of a stack.
It's not clear to me what problem you want to solve
and your requirements are.  It's possible that
you could find it easier to abstract directly on top of SQL or alternatively
you could consider using another sort of data model like mongodb.
Building an abstraction on top of SQLAlchemy which hasn't even reached
1.0 strikes me as dubious.

Thanks again,  -- Aaron Watters

--- On Tue, 4/6/10, Randy Syring <rsyring-KjVcCr55iNUxpvK4C0GaPQ@public.gmane.org> wrote:

From: Randy Syring <rsyring-KjVcCr55iNUxpvK4C0GaPQ@public.gmane.org>
Subject: [Web-SIG] SQLAlchemy Queries & HTML Data Grid
To: web-sig-+ZN9ApsXKcEdnm+yROfE0A@public.gmane.org
Date: Tuesday, April 6, 2010, 4:37 PM

I am planning on building a library that will facilitate creation of custom queries and html display of resulting datasets from SQLAlechemy queries.  I have some basic work done here:

https://svn.rcslocal.com:8443/svn/pysmvt/pysapp/branches/0.1/pysapp/modules/datagrid/

But I don't like the API and I don't want the library to be dependent on pysapp.  Furthermore, I would like to have a more verbose querying ability akin to Redmine:

http://www.redmine.org/projects/redmine/issues

Including:
  • Filters
  • Column Selection
  • Grouping (multiple levels)
  • Sorting (multiple columns)
  • some kind of query saving/loading mechanism with a flexible backend
I have done some basic table generation work here:

https://svn.rcslocal.com:8443/svn/pysmvt/pysdatagrid/trunk/

with the tests being the best place to get an idea of how it works:

https://svn.rcslocal.com:8443/svn/pysmvt/pysdatagrid/trunk/pysdatagrid/tests/test_render.py

Looking for comments, pointers to other projects, and/or possibly interest in helping with a project like this.  I am currently working in SVN but will most likely move to hg/git if there are others who are interested.
-- -------------------------------------- Randy Syring Intelicom 502-644-4776 "Whether, then, you eat or drink or whatever you do, do all to the glory of God." 1 Cor 10:31

-----Inline Attachment Follows-----

_______________________________________________
Web-SIG mailing list
Web-SIG@...
Web SIG: http://www.python.org/sigs/web-sig
Unsubscribe: http://mail.python.org/mailman/options/web-sig/gcpw-web-sig%40m.gmane.org
Aaron Watters | 7 Apr 2010 20:54
Picon
Favicon
Gravatar

Re: SQLAlchemy Queries & HTML Data Grid


Randy:

It seems you want a sortable HTML table that talks to a back end
query engine.  I don't see why this needs to be specific to SQLAlchemy.

Here is a WHIFF middleware which does some of what you are talking
about (the demo formatting is basic/ugly for simplicity purposes).

Demo

  http://whiffdoc.appspot.com/tests/misc/testSortTable

Demo source

   http://whiffdoc.appspot.com/tests/showText?path=./misc/testSortTable

The documentation

 http://whiffdoc.appspot.com/docs/W1200_1400.stdMiddleware#Header83

is not extensive, but here is the source for the
core middleware widget.

  http://aaron.oirt.rutgers.edu/cgi-bin/whiffRepo.cgi/file/8c031c68a5a0/whiff/middleware/sortTable.py

As written it requires the whole table as a list of dictionaries and then does
paging from the full list.  It certainly needs generalization but maybe it's
a start.  Let me know if you have questions or comments.

   -- Aaron Watters

--- On Wed, 4/7/10, Randy Syring <rsyring-KjVcCr55iNUxpvK4C0GaPQ@public.gmane.org> wrote:

From: Randy Syring <rsyring-KjVcCr55iNUxpvK4C0GaPQ@public.gmane.org>
Subject: Re: [Web-SIG] SQLAlchemy Queries & HTML Data Grid
To: "Aaron Watters" <arw1961-/E1597aS9LQAvxtiuMwx3w@public.gmane.org>
Cc: web-sig-+ZN9ApsXKcEdnm+yROfE0A@public.gmane.org
Date: Wednesday, April 7, 2010, 1:37 PM

Aaron,

Sorry, I must not really have explained clearly.  This isn't an abstraction layer, but more like a UI component or widgit that facilities basic reporting.  Look at these pages:

http://www.redmine.org/issues
http://trac.edgewall.org/query]
....
_______________________________________________
Web-SIG mailing list
Web-SIG@...
Web SIG: http://www.python.org/sigs/web-sig
Unsubscribe: http://mail.python.org/mailman/options/web-sig/gcpw-web-sig%40m.gmane.org
Randy Syring | 7 Apr 2010 21:07

Re: SQLAlchemy Queries & HTML Data Grid

> It seems you want a sortable HTML table that talks to a back end
> query engine.  I don't see why this needs to be specific to SQLAlchemy.
Well...not just sorting though.  Sorting, filtering, grouping, column 
selection, and paging.  You are right that the backend does not need to 
be SQLAlchemy specific, but since that is what I use, that is what I was 
going to start with.  Ideally, the library would be both sql framework 
and wsgi framework agnostic.

The main point of the library would be to save the time/hassle in 
creating the HTML/CSS/JS for the query controls.

--------------------------------------
Randy Syring
Intelicom
502-644-4776

"Whether, then, you eat or drink or 
whatever you do, do all to the glory
of God." 1 Cor 10:31

_______________________________________________
Web-SIG mailing list
Web-SIG@...
Web SIG: http://www.python.org/sigs/web-sig
Unsubscribe: http://mail.python.org/mailman/options/web-sig/gcpw-web-sig%40m.gmane.org

Manlio Perillo | 8 Apr 2010 16:08
Picon
Favicon

WSGI and start_response

Hi.

Some time ago I objected the decision to remove start_response function
from next version WSGI, using as rationale the fact that without
start_callable, asynchronous extension are impossible to support.

Now I have found that removing start_response will also make impossible
to support coroutines (or, at least, some coroutines usage).

Here is an example (this is the same example I posted few days ago):
http://paste.pocoo.org/show/199202/

Forgetting about the write callable, the problem is that the application
starts to yield data when tmpl.render_unicode function is called.

Please note that this has *nothing* to do with asynchronus applications.
The code should work with *all* WSGI implementations.

In the pasted example, the Mako render_unicode function is "turned" into
a generator, with a simple function that allows to flush the current buffer.

Can someone else confirm that this code is impossible to support in WSGI
2.0?

If my suspect is true, I once again object against removing start_response.

WSGI 1.0 is really a well designed protocol, since it is able to support
both asynchonous application (with a custom extension) and coroutines,
*even* if this was not considered during protocol design.

Thanks  Manlio
_______________________________________________
Web-SIG mailing list
Web-SIG@...
Web SIG: http://www.python.org/sigs/web-sig
Unsubscribe: http://mail.python.org/mailman/options/web-sig/gcpw-web-sig%40m.gmane.org


Gmane