usr bin env python import os import sys import logging import urllib f

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env python
import os
import sys
import logging
import urllib
from optparse import OptionParser
# curl http://dumpz.org/ | grep option | sed 's/.*option value="\([^"]*\)".*/\1/' | fmt
LEXERS = """apacheconf bash bat bbcode befunge boo brainfuck c cpp csharp css
css+django css+erb css+genshitext css+mako css+myghty css+php css+smarty
d delphi diff django dylan erb genshi genshitext groff haskell html
html+django html+genshi html+mako html+myghty html+php html+smarty ini
irc java js js+django js+erb js+genshitext js+mako js+myghty js+php
js+smarty jsp lua make mako minid mupad myghty objective-c ocaml perl
php pycon pytb python raw rb rbcon redcode rhtml rst scheme smarty
sourceslist sql tex text trac-wiki vb.net vim xml xml+django xml+erb
xml+mako xml+myghty xml+php xml+smarty""".split()
URI = 'http://dumpz.org/add/'
class DumpzOpener(urllib.URLopener):
def http_error_default(self, uri, socket, code, status, msg, *args, **kwargs):
if code == 302:
print msg.getheader('Location')
else:
super(DumpzOpener, self).http_error_default(uri, socket, code, status, msg, *args, **kwargs)
def perform(filename, lexer, comment):
data = file(filename).read()
post = {'code': data, 'lexer': opts.lexer, 'tags': '', 'comment': comment}
opener = DumpzOpener()
opener.open(URI, urllib.urlencode(post))
def print_lexers(*args):
print '\n'.join(LEXERS)
sys.exit()
if __name__ == '__main__':
usage = 'usage: %prog [options] file'
parser = OptionParser(usage)
parser.add_option('', '--lexers', action='callback', callback=print_lexers,
help='output the list of available lexers')
parser.add_option('-l', '--lexer', type='choice', choices=LEXERS, default='text',
help='type of file')
parser.add_option('-m', '--message', default='',
help='comment of dump')
opts, args = parser.parse_args()
if not len(args):
parser.print_usage()
sys.exit()
perform(args[0], opts.lexer, opts.message)