usr bin env python import os import sys import logging from optparse i

 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
#!/usr/bin/env python
import os
import sys
import logging
from optparse import OptionParser
import urllib
# 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(' ')
usage = 'usage: %prog [options] file'
parser = OptionParser(usage)
#parser.add_option('-f', '--file', help='filename for uploading')
parser.add_option('-l', '--lexer', type='choice', choices=lexers, default='text',
help='type of file')
parser.add_option('', '--lexers', action='store_true', default=False,
help='output the list of available lexers')
opts, args = parser.parse_args()
if opts.lexers:
print '\n'.join(lexers)
sys.exit()
if not len(args):
parser.print_usage()
sys.exit()
else:
filename = args[0]
code = file(filename).read()
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)
uri = 'http://dumpz.org/add/'
post = {'code': code, 'lexer': opts.lexer, 'tags': '', 'comment': ''}
opener = DumpzOpener()
opener.open(uri, urllib.urlencode(post))