#1
  1. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69

    net-0.1 (Attached)


    I hate to toot my own horn, but if you do anything with CGI and Python then chances are you’ll find this pretty interesting and or hopefully useful .

    Some History:

    A little while ago I had an idea for a project kind of a Zope-WikiWiki-CGI half bread named Nickel. However I was reluctant to start on the project using Pythons current CGI modules (I don’t think I’m the only one who things Python is lagging behind the times in this respect), in particular ‘Cookies’; as it seemed to me that that the module itself has been mostly depreciated and in need of a serious update.

    So I sat down whipped up my own module to handle common CGI tasks the way I wanted them handled

    As of version 0.1 net supports:

    1.A uniquely easy to use, flexible, full-featured cookie interface with support for loading cookie data!

    2.Automatic form variables (net.form[‘key’]). Although this seems very stable it does need heavy testing. With the possibility of more features being added to the form parser.

    3.Simple, automatic error catching. This is just a formatted HTML version of Pythons standard error messages.

    4.Last but not least the module comes ready packaged to take advantage of Python 2.3’s ZIP import feature. All you have to do is move net.zip to you're site-packages directory and point a pth file at it!

    If you want to find out more about pth files check out the link below:

    http://www.python.org/doc/2.3.3/lib/module-site.html

    If you haven’t realised it yet… this is more or less everything you need to write web applications with Python and CGI!

    Tthere are no home page or docs right now although I’d be happy to post examples if you're is interest. Anyway, you have an interesting ideas/features that need adding? Let me know what you think .

    Mark.
    Attached Files
    programming language development: www.netytan.com Hula

  2. #2
  3. Mini me.
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Location
    Cambridge, UK
    Posts
    783
    Rep Power
    14
    Netytan- it looks . Going to test it out.

    Does this display all form values if it was the cgi called from a form page?
    Code:
    #!/usr/bin/env python
    #printform.py
    
    import net
    print 'Content-Type: text/html\n'
    for n in form.keys():
        print n,`form[n]`
    Grim
  4. #3
  5. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    Thanks Grim, actually what you want is more like this.

    Code:
    #!/usr/bn/env python
    
    import net
    
    print 'Content-Type: text/html\n'
    
    for field in net.form:
        pritn field, '=>', net.form[field]
    Mark.
    programming language development: www.netytan.com Hula

  6. #4
  7. Mini me.
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Location
    Cambridge, UK
    Posts
    783
    Rep Power
    14
    oops! forgot the module That will teach me to check my code before posting .

    Grim
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2004
    Posts
    84
    Rep Power
    11
    It looks pretty good to me mate, though it doesn't seem to provide a great deal of extra functionality over the current cgi module. maybe add a logging feature like there is in cgi.py, then start working on some nifty little features to show the current cgi module up

    Very interesting though, I'll see if I can think of anything to add.
  10. #6
  11. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    Ah the idea wasn't to fill the module with lots of useless stuff like multiple field storage classes .

    Although i plan to make the functions in module.py available in though 'net' for version 0.2 aswell as having cookies variables automatically loaded like forms.

    I'm trying to keep it as simple as i can, but make it more of an environment than a module... it actually does the job of cgi, Cookie and cgitb but much more elagantly! All you have to do is import the module and most common tasks are done for you...

    Which one looks cleaner?

    Code:
    #!/usr/bin/env python
    
    import net
    or

    Code:
    #!/usr/bin/env python
    
    import cgi, Cookies, cgitb
    cgitb.enable()
    form = cgi.FieldStorage()
    I was also considering a URL data type for manipulating URLs and or reading from a website. The log sounds cool though. i just don't like the idea of somone being able to load the error log though there browser. Seems like a bit of a security hole.

    Plus, in order to be of much use it would have to have all the power of Apache's error log.

    Mark.
    programming language development: www.netytan.com Hula

  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    217
    Rep Power
    0
    Cool stuff netytan . One question though: Is there any way to submit things like this, along with language extentions to the Python team for review or something? That way if a developer wrote something that had potential, it could have the chance to be included in the language or distribution.

    Oh, and it's well commented
    Last edited by XxChris; March 3rd, 2004 at 10:37 AM.
  14. #8
  15. No Profile Picture
    404 Error
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2002
    Location
    http://hester.dns2go.com
    Posts
    18
    Rep Power
    0
    Nice stuff! this could really help me because i just started web apps programming.

    but how do you use the cookie module?
  16. #9
  17. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    Thanks , i did go a little comment nuts i admit but. Not as far as i know Xx:

    I think if everyone is using the module or there is demand for the it in python then the Python team include it although not having anything in the standard lib myself i don't know the finer points... but it seems to be a populrity contenst .

    Having said that there are alot excelent 3rd party things that havn't yet made it in!

    So i surpose if you really wished to show of you're work you could always post it on the mailing list or email the Python guys directly at webmaster@python.org and see what comes back.

    Another good way to get you're code around would be to add it to the PyPI like Grim did with his excelent py2html module.

    http://www.python.org/pypi

    Mark.
    programming language development: www.netytan.com Hula

  18. #10
  19. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    217
    Rep Power
    0
    Ahh cool, thanks . I hope Python will have something like CPAN soon!
    Last edited by XxChris; March 3rd, 2004 at 11:12 AM.
  20. #11
  21. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2004
    Posts
    84
    Rep Power
    11
    netytan - I realise you're trying to make things cleaner rather than bloat the module, and that's cool. however, all the functionality your module provides is already achieveable with existing modules, so using it is purely for cosmetic reasons. I hope you don't take offense or anything, I like the idea and the implementation so far, I don't mean to come off as an ***

    To get it considered as a module to ship with the standard Python distro, you would probably need to suggest it in a PEP on the Python site and see what kind of support / criticism you get. If the idea is supported, you could get it added to the list of todo's. However, as the module doesn't provide any extra functionality and would be put into to use for "cleaning" purposes, it would probably be low on the list if supported.

    Your best bet would be to look into getting it on the "Sumo" distro of Python. I'm not sure on the status of this project, but it's basically a distro of Python with a whole heap of extra bells and whistles (in the form of third party modules etc). Worth looking into anyway
  22. #12
  23. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    No problem rebbit, critasism is as good as praise . Actually net suports loading cookies - a feature i am not aware of in the std-lib. And in version 0.2 a new encode, decode (URL encryption and decyption) and escape (an omproved version of cgi.escape; the only remotly useful function in there IMO) function are availble.

    I'm also thinking about replacing the 'form' variable with 'request' or 'namespace' like in PHP which will contain values from all input streams (currently - cookies and forms) instead of having seperate var names. I will also be adding a config file to give more controle over nets options.

    Ah. i dont wana get it in the std-lib. Or at least not yet , it has a long way to go before i'll be happy with it. But it usable, and whats morevery clean, and i'm a big fan of clean code .

    Mark.
    programming language development: www.netytan.com Hula


IMN logo majestic logo threadwatch logo seochat tools logo