[go: up one dir, main page]

Menu

[r19]: / PastebinLib.py  Maximize  Restore  History

Download this file

206 lines (186 with data), 4.4 kB

  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
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
#!/usr/bin/python
# -*- coding: utf-8 -*-
import urllib
class Pastebin(object):
prefix_url = 'http://pastebin.com/'
subdomain_url = 'http://%s.pastebin.com/' # % paste_subdomain
api_url = 'http://pastebin.com/api_public.php'
paste_expire_date = ('N', '10M', '1H', '1D', '1M')
paste_format = (
'python',
'abap',
'actionscript',
'actionscript3',
'ada',
'apache',
'applescript',
'apt_sources',
'asm',
'asp',
'autoit',
'avisynth',
'bash',
'basic4gl',
'bibtex',
'blitzbasic',
'bnf',
'boo',
'bf',
'c',
'c_mac',
'cill',
'csharp',
'cpp',
'caddcl',
'cadlisp',
'cfdg',
'klonec',
'klonecpp',
'cmake',
'cobol',
'cfm',
'css',
'd',
'dcs',
'delphi',
'dff',
'div',
'dos',
'dot',
'eiffel',
'email',
'erlang',
'fo',
'fortran',
'freebasic',
'gml',
'genero',
'gettext',
'groovy',
'haskell',
'hq9plus',
'html4strict',
'idl',
'ini',
'inno',
'intercal',
'io',
'java',
'java5',
'javascript',
'kixtart',
'latex',
'lsl2',
'lisp',
'locobasic',
'lolcode',
'lotusformulas',
'lotusscript',
'lscript',
'lua',
'm68k',
'make',
'matlab',
'matlab',
'mirc',
'modula3',
'mpasm',
'mxml',
'mysql',
'text',
'nsis',
'oberon2',
'objc',
'ocaml-brief',
'ocaml',
'glsl',
'oobas',
'oracle11',
'oracle8',
'pascal',
'pawn',
'per',
'perl',
'php',
'php-brief',
'pic16',
'pixelbender',
'plsql',
'povray',
'powershell',
'progress',
'prolog',
'properties',
'providex',
'qbasic',
'rails',
'rebol',
'reg',
'robots',
'ruby',
'gnuplot',
'sas',
'scala',
'scheme',
'scilab',
'sdlbasic',
'smalltalk',
'smarty',
'sql',
'tsql',
'tcl',
'tcl',
'teraterm',
'thinbasic',
'typoscript',
'unreal',
'vbnet',
'verilog',
'vhdl',
'vim',
'visualprolog',
'vb',
'visualfoxpro',
'whitespace',
'whois',
'winbatch',
'xml',
'xorg_conf',
'xpp',
'z80',
)
@classmethod
def submit(cls, paste_code, paste_name=None, paste_subdomain=None,
paste_private=None, paste_expire_date=None, paste_format=None):
argv = {'paste_code': str(paste_code)}
if paste_name is not None:
argv['paste_name'] = str(paste_name)
if paste_subdomain is not None:
paste_subdomain = str(paste_subdomain).strip().lower()
argv['paste_subdomain'] = paste_subdomain
if paste_private is not None:
argv['paste_private'] = int(bool(int(paste_private)))
if paste_expire_date is not None:
paste_expire_date = str(paste_expire_date).strip().upper()
if not paste_expire_date in cls.paste_expire_date:
raise ValueError, "Bad expire date: %s" % \
paste_expire_date
if paste_format is not None:
paste_format = str(paste_format).strip().lower()
if not paste_format in cls.paste_format:
raise ValueError, "Bad format: %s" % paste_format
argv['paste_format'] = paste_format
fd = urllib.urlopen(cls.api_url, urllib.urlencode(argv))
try:
response = fd.read()
finally:
fd.close()
del fd
if argv.has_key('paste_subdomain'):
prefix = cls.subdomain_url % paste_subdomain
else:
prefix = cls.prefix_url
if not response.startswith(prefix):
return response
return response
Paste = Pastebin()