|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
Markup CGI - please test
In quiet moments I've been working on a python CGI script to do code markup. If you are interested enough to test it, here it is:
Markup CGI Key features are: 1. User control over format and colour 2. Line numbering. 3. Cookies to remember settings. Here's a sample: Code:
[001] #Replace this code with your own
[002]
[003] def Hello(name="World"):
[004] """A simple function"""
[005] print "Hello "+name #Classic
[006] a =1+1
[007] b=(6+7)-2
[008] if a < b :
[009] print "a=%s, b=%s"%(a,b)
[010]
[011] Hello("you")
[012] Hello()
[013] Hello("The Universe")
[014]
[015]
You don't have to like my colours ![]() grim ![]()
__________________
*** Experimental Python Markup CGI V2 *** Last edited by Grim Archon : October 17th, 2004 at 09:22 AM. Reason: numbering changed |
|
#2
|
|||
|
|||
|
that's really nice but I did get this error:
Code:
KeyError Python 2.2.3: /usr/bin/python
Fri Oct 15 10:27:32 2004
A problem occurred in a Python script. Here is the sequence of function calls leading up to the error, in the order they occurred.
/home/pharsc2/public_html/cgi-bin/syntax.py
622 oblock= cgi.escape(makeBlock(data),True)
623 #oblock=oblock%items
624 print html1%items,
625 fname = str(time.time()+random.random())
626 tf = file(os.sep+"tmp"+os.sep+fname,"w")
html1 = '\n <head>\n <meta http-equiv="Conten...tle>\n </head>\n <body>\n <hr>\n ', items = {'com': 'Red', 'entity': '1', 'key': 'BLACK', 'markup': 'vbmarkup', 'num': 'BLACK', 'op': 'BLACK', 'reformat': '1', 'str': 'Green'}
KeyError: res
__doc__ = 'Mapping key not found.'
__getitem__ = <bound method KeyError.__getitem__ of <exceptions.KeyError instance>>
__init__ = <bound method KeyError.__init__ of <exceptions.KeyError instance>>
__module__ = 'exceptions'
__str__ = <bound method KeyError.__str__ of <exceptions.KeyError instance>>
args = ('res',)
|
|
#3
|
|||
|
|||
|
line 624 ^^^
|
|
#4
|
||||
|
||||
|
Weird, learning something about cookies - should have realised it is stateless and you can't guarantee that if one is received then they are all received.
Hopefully, now fixed with an update to a default dictionary. grim ![]() |
|
#5
|
||||
|
||||
|
Tested it with normal Python code and code copied from the shell and it works perfectly
. If you havn't posted a link to this in the tips and tricks thread do it already .Keep it up Paul, Mark. |
|
#6
|
||||
|
||||
|
Mark,
Thanks for that ![]() I think I'll allow a little more testing before suggesting it for everyday use tho - I just changed it so line numbers start from a more logical 1. I haven't used cookies directly before so the bug that jimmy2k1 reported is a bit of a funny to me. I patched it by having defaults that get updated by whatever cookies are returned but I'm not happy with that. Anyone have any ideas? I might change it so that one cookie has all settings which is probably tidier anyway. grim ![]() |
|
#7
|
||||
|
||||
|
Nice stuff
. One error I noticed was, when I enter something like this:Code:
#!/usr/bin/env python x = "foo" + "bar" + "baz" the output is colourized, but the spaces between the + symbols are removed in the output. Code:
#!/usr/bin/env python x = "foo"+"bar"+"baz" Also, your VBcode output has a space before the #!/usr/bin/env python line
__________________
Up the Irons What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home. "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest Down with Sharon Osbourne Puzzle of the Month solved by Keath and KevinADC, superior perl programmers of the month |
|
#8
|
||||
|
||||
|
You can fix the first example by selecting "No" in the reformat section
. Not sure about the second though. |
|
#9
|
||||
|
||||
|
Yep Scorp, you got bit by formatting
![]() Reformat: No - means (hopefully) don't make any change to layout. Reformat: Style 1 Tries to impose some PEP 8 style guidelines to the code. This means ignoring spaces/tabs and putting them back in where guidelines suggest they should go. The rules are fairly simplistic but try to make the code layout consistent. (Looks like I need to modify the comment handling slightly for when it's at the beginning of a line.) I put it in because my code gets a little sloppy after editing and I wanted something to tidy it up. 9/10 times it does okay. Reformat Style 2 Is an alternative that some may prefer. (suck it an see) ![]() The mark-up decisions are made by the tokenizer module so it should be compatible with IDLE and other packages that use it. This might lead to funny colouration when marking up none-python code but seems to work for C/C++ okay as a lot of the reserved words are common. grim ![]() |
|
#10
|
||||
|
||||
|
Fixed spurious space insertion when comment was in column 0 and Style 1 is used.
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Python Programming > Markup CGI - please test |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|