Module pastebin
[hide private]
[frames] | no frames]

Source Code for Module pastebin

  1  #!/usr/bin/env python
 
  2  
 
  3  #############################################################################
 
  4  #    Pastebin.py - Python 3.2 Pastebin API.
 
  5  #    Copyright (C) 2012  Ian Havelock
 
  6  #
 
  7  #    This program is free software: you can redistribute it and/or modify
 
  8  #    it under the terms of the GNU General Public License as published by
 
  9  #    the Free Software Foundation, either version 3 of the License, or
 
 10  #    (at your option) any later version.
 
 11  #
 
 12  #    This program is distributed in the hope that it will be useful,
 
 13  #    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
 14  #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
 15  #    GNU General Public License for more details.
 
 16  #
 
 17  #    You should have received a copy of the GNU General Public License
 
 18  #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 19  #
 
 20  
 
 21  #############################################################################
 
 22  
 
 23  # This software is a derivative work of:
 
 24  # http://winappdbg.sourceforge.net/blog/pastebin.py
 
 25  
 
 26  #############################################################################
 
 27  
 
 28  
 
 29  __all__ = ['delete_paste', 'user_details', 'trending', 'pastes_by_user', 'generate_user_key',
 
 30    'legacy_paste', 'paste', 'Pastebin', 'PastebinError'] 
 31  
 
 32  import sys 
 33  import urllib 
 34  
 
35 -class PastebinError(RuntimeError):
36 """Pastebin API error. 37 38 The error message returned by the web application is stored as the Python exception message."""
39
40 -class PastebinAPI(object):
41 """Pastebin API interaction object. 42 43 Public functions: 44 45 paste -- Pastes a user-specified file or string using the new API-key POST method. 46 47 legacy_paste -- Pastes a user-specified file or string using the old anonymous POST method. 48 49 generate_user_key -- Generates a session-key that is required for other functions. 50 51 pastes_by_user -- Returns all public pastes submitted by the specified login credentials. 52 53 trending -- Returns the top trending paste. 54 55 user_details -- Returns details about the user for the specified API user key. 56 57 delete_paste -- Adds two numbers together and returns the result.""" 58 59 # String to determine bad API requests 60 _bad_request = 'Bad API request' 61 62 # Base domain name 63 _base_domain = 'pastebin.com' 64 65 # Valid Pastebin URLs begin with this string (kinda bvious) 66 _prefix_url = 'http://%s/' % _base_domain 67 68 # Valid Pastebin URLs with a custom subdomain begin with this string 69 _subdomain_url = 'http://%%s.%s/' % _base_domain 70 71 # URL to the LEGACY POST API 72 _legacy_api_url= 'http://%s/api_public.php' % _base_domain 73 74 # URL to the POST API 75 _api_url= 'http://%s/api/api_post.php' % _base_domain 76 77 # URL to the login POST API 78 _api_login_url= 'http://%s/api/api_login.php' % _base_domain 79 80 # Valid paste_expire_date values (Never, 10 minutes, 1 Hour, 1 Day, 1 Month) 81 paste_expire_date = ('N', '10M', '1H', '1D', '1M') 82 83 # Valid paste_expire_date values (0 = public, 1 = unlisted, 2 = private) 84 paste_private = ('public', 'unlisted', 'private') 85 86 # Valid parse_format values 87 paste_format = ( 88 '4cs', # 4CS 89 '6502acme', # 6502 ACME Cross Assembler 90 '6502kickass', # 6502 Kick Assembler 91 '6502tasm', # 6502 TASM/64TASS 92 'abap', # ABAP 93 'actionscript', # ActionScript 94 'actionscript3', # ActionScript 3 95 'ada', # Ada 96 'algol68', # ALGOL 68 97 'apache', # Apache Log 98 'applescript', # AppleScript 99 'apt_sources', # APT Sources 100 'asm', # ASM (NASM) 101 'asp', # ASP 102 'autoconf', # autoconf 103 'autohotkey', # Autohotkey 104 'autoit', # AutoIt 105 'avisynth', # Avisynth 106 'awk', # Awk 107 'bascomavr', # BASCOM AVR 108 'bash', # Bash 109 'basic4gl', # Basic4GL 110 'bibtex', # BibTeX 111 'blitzbasic', # Blitz Basic 112 'bnf', # BNF 113 'boo', # BOO 114 'bf', # BrainFuck 115 'c', # C 116 'c_mac', # C for Macs 117 'cil', # C Intermediate Language 118 'csharp', # C# 119 'cpp', # C++ 120 'cpp-qt', # C++ (with QT extensions) 121 'c_loadrunner', # C: Loadrunner 122 'caddcl', # CAD DCL 123 'cadlisp', # CAD Lisp 124 'cfdg', # CFDG 125 'chaiscript', # ChaiScript 126 'clojure', # Clojure 127 'klonec', # Clone C 128 'klonecpp', # Clone C++ 129 'cmake', # CMake 130 'cobol', # COBOL 131 'coffeescript', # CoffeeScript 132 'cfm', # ColdFusion 133 'css', # CSS 134 'cuesheet', # Cuesheet 135 'd', # D 136 'dcs', # DCS 137 'delphi', # Delphi 138 'oxygene', # Delphi Prism (Oxygene) 139 'diff', # Diff 140 'div', # DIV 141 'dos', # DOS 142 'dot', # DOT 143 'e', # E 144 'ecmascript', # ECMAScript 145 'eiffel', # Eiffel 146 'email', # Email 147 'epc', # EPC 148 'erlang', # Erlang 149 'fsharp', # F# 150 'falcon', # Falcon 151 'fo', # FO Language 152 'f1', # Formula One 153 'fortran', # Fortran 154 'freebasic', # FreeBasic 155 'freeswitch', # FreeSWITCH 156 'gambas', # GAMBAS 157 'gml', # Game Maker 158 'gdb', # GDB 159 'genero', # Genero 160 'genie', # Genie 161 'gettext', # GetText 162 'go', # Go 163 'groovy', # Groovy 164 'gwbasic', # GwBasic 165 'haskell', # Haskell 166 'hicest', # HicEst 167 'hq9plus', # HQ9 Plus 168 'html4strict', # HTML 169 'html5', # HTML 5 170 'icon', # Icon 171 'idl', # IDL 172 'ini', # INI file 173 'inno', # Inno Script 174 'intercal', # INTERCAL 175 'io', # IO 176 'j', # J 177 'java', # Java 178 'java5', # Java 5 179 'javascript', # JavaScript 180 'jquery', # jQuery 181 'kixtart', # KiXtart 182 'latex', # Latex 183 'lb', # Liberty BASIC 184 'lsl2', # Linden Scripting 185 'lisp', # Lisp 186 'llvm', # LLVM 187 'locobasic', # Loco Basic 188 'logtalk', # Logtalk 189 'lolcode', # LOL Code 190 'lotusformulas', # Lotus Formulas 191 'lotusscript', # Lotus Script 192 'lscript', # LScript 193 'lua', # Lua 194 'm68k', # M68000 Assembler 195 'magiksf', # MagikSF 196 'make', # Make 197 'mapbasic', # MapBasic 198 'matlab', # MatLab 199 'mirc', # mIRC 200 'mmix', # MIX Assembler 201 'modula2', # Modula 2 202 'modula3', # Modula 3 203 '68000devpac', # Motorola 68000 HiSoft Dev 204 'mpasm', # MPASM 205 'mxml', # MXML 206 'mysql', # MySQL 207 'newlisp', # newLISP 208 'text', # None 209 'nsis', # NullSoft Installer 210 'oberon2', # Oberon 2 211 'objeck', # Objeck Programming Langua 212 'objc', # Objective C 213 'ocaml-brief', # OCalm Brief 214 'ocaml', # OCaml 215 'pf', # OpenBSD PACKET FILTER 216 'glsl', # OpenGL Shading 217 'oobas', # Openoffice BASIC 218 'oracle11', # Oracle 11 219 'oracle8', # Oracle 8 220 'oz', # Oz 221 'pascal', # Pascal 222 'pawn', # PAWN 223 'pcre', # PCRE 224 'per', # Per 225 'perl', # Perl 226 'perl6', # Perl 6 227 'php', # PHP 228 'php-brief', # PHP Brief 229 'pic16', # Pic 16 230 'pike', # Pike 231 'pixelbender', # Pixel Bender 232 'plsql', # PL/SQL 233 'postgresql', # PostgreSQL 234 'povray', # POV-Ray 235 'powershell', # Power Shell 236 'powerbuilder', # PowerBuilder 237 'proftpd', # ProFTPd 238 'progress', # Progress 239 'prolog', # Prolog 240 'properties', # Properties 241 'providex', # ProvideX 242 'purebasic', # PureBasic 243 'pycon', # PyCon 244 'python', # Python 245 'q', # q/kdb+ 246 'qbasic', # QBasic 247 'rsplus', # R 248 'rails', # Rails 249 'rebol', # REBOL 250 'reg', # REG 251 'robots', # Robots 252 'rpmspec', # RPM Spec 253 'ruby', # Ruby 254 'gnuplot', # Ruby Gnuplot 255 'sas', # SAS 256 'scala', # Scala 257 'scheme', # Scheme 258 'scilab', # Scilab 259 'sdlbasic', # SdlBasic 260 'smalltalk', # Smalltalk 261 'smarty', # Smarty 262 'sql', # SQL 263 'systemverilog', # SystemVerilog 264 'tsql', # T-SQL 265 'tcl', # TCL 266 'teraterm', # Tera Term 267 'thinbasic', # thinBasic 268 'typoscript', # TypoScript 269 'unicon', # Unicon 270 'uscript', # UnrealScript 271 'vala', # Vala 272 'vbnet', # VB.NET 273 'verilog', # VeriLog 274 'vhdl', # VHDL 275 'vim', # VIM 276 'visualprolog', # Visual Pro Log 277 'vb', # VisualBasic 278 'visualfoxpro', # VisualFoxPro 279 'whitespace', # WhiteSpace 280 'whois', # WHOIS 281 'winbatch', # Winbatch 282 'xbasic', # XBasic 283 'xml', # XML 284 'xorg_conf', # Xorg Config 285 'xpp', # XPP 286 'yaml', # YAML 287 'z80', # Z80 Assembler 288 'zxbasic', # ZXBasic 289 ) 290
291 - def __init__(self):
292 pass
293 294
295 - def delete_paste(self, api_dev_key, api_user_key, api_paste_key):
296 """Delete the paste specified by the api_paste_key. 297 298 299 Usage Example:: 300 >>> from pastebin import PastebinAPI 301 >>> x = PastebinAPI() 302 >>> paste_to_delete = x.delete_paste('453a994e0e2f1efae07f8759e59e075b', 303 ... 'c57a18e6c0ae228cd4bd16fe36da381a', 304 ... 'WkgcTFtv') 305 >>> print paste_to_delete 306 Paste Removed 307 308 309 @type api_dev_key: string 310 @param api_dev_key: The API Developer Key of a registered U{http://pastebin.com} account. 311 312 @type api_user_key: string 313 @param api_user_key: The API User Key of a U{http://pastebin.com} registered user. 314 315 @type api_paste_key: string 316 @param api_paste_key: The Paste Key of the paste to be deleted (string after final / in U{http://pastebin.com} URL). 317 318 @rtype: String 319 @returns: A successful deletion returns 'Paste Removed'. 320 """ 321 322 # Valid api developer key 323 argv = {'api_dev_key' : str(api_dev_key) } 324 325 # Requires pre-registered account 326 if api_user_key is not None: 327 argv['api_user_key'] = str(api_user_key) 328 329 # Key of the paste to be deleted. 330 if api_paste_key is not None: 331 argv['api_paste_key'] = str(api_paste_key) 332 333 # Valid API option - 'user_details' in this instance 334 argv['api_option'] = str('delete') 335 336 337 # lets try to read the URL that we've just built. 338 request = urllib.urlopen(self._api_url, urllib.urlencode(argv)) 339 response = self._submit_paste(request) 340 341 return response
342 343
344 - def user_details(self, api_dev_key, api_user_key):
345 """Return user details of the user specified by the api_user_key. 346 347 348 Usage Example:: 349 >>> from pastebin import PastebinAPI 350 >>> x = PastebinAPI() 351 >>> details = x.user_details('453a994e0e2f1efae07f8759e59e075b', 352 ... 'c57a18e6c0ae228cd4bd16fe36da381a') 353 >>> print details 354 <user> 355 <user_name>MonkeyPuzzle</user_name> 356 <user_format_short>python</user_format_short> 357 <user_expiration>N</user_expiration> 358 <user_avatar_url>http://pastebin.com/i/guest.gif</user_avatar_url> 359 <user_private>0</user_private> 360 <user_website></user_website> 361 <user_email>user@email.com</user_email> 362 <user_location></user_location> 363 <user_account_type>0</user_account_type> 364 </user> 365 366 367 @type api_dev_key: string 368 @param api_dev_key: The API Developer Key of a registered U{http://pastebin.com} account. 369 370 @type api_user_key: string 371 @param api_user_key: The API User Key of a U{http://pastebin.com} registered user. 372 373 @rtype: string 374 @returns: Returns an XML string containing user information. 375 """ 376 377 # Valid api developer key 378 argv = {'api_dev_key' : str(api_dev_key) } 379 380 # Requires pre-registered account to generate an api_user_key (see generate_user_key) 381 if api_user_key is not None: 382 argv['api_user_key'] = str(api_user_key) 383 384 # Valid API option - 'user_details' in this instance 385 argv['api_option'] = str('userdetails') 386 387 # lets try to read the URL that we've just built. 388 request_string = urllib.urlopen(self._api_url, urllib.urlencode(argv)) 389 response = request_string.read() 390 391 # do some basic error checking here so we can gracefully handle any errors we are likely to encounter 392 if response.startswith(self._bad_request): 393 raise PastebinError(response) 394 395 elif not response.startswith('<user>'): 396 raise PastebinError(response) 397 398 return response
399 400
401 - def trending(self, api_dev_key):
402 """Returns the top trending paste details. 403 404 405 Usage Example:: 406 >>> from pastebin import PastebinAPI 407 >>> x = PastebinAPI() 408 >>> details = x.trending('453a994e0e2f1efae07f8759e59e075b') 409 >>> print details 410 <paste> 411 <paste_key>jjMRFDH6</paste_key> 412 <paste_date>1333230838</paste_date> 413 <paste_title></paste_title> 414 <paste_size>6416</paste_size> 415 <paste_expire_date>0</paste_expire_date> 416 <paste_private>0</paste_private> 417 <paste_format_long>None</paste_format_long> 418 <paste_format_short>text</paste_format_short> 419 <paste_url>http://pastebin.com/jjMRFDH6</paste_url> 420 <paste_hits>6384</paste_hits> 421 </paste> 422 423 Note: Returns multiple trending pastes, not just 1. 424 425 426 @type api_dev_key: string 427 @param api_dev_key: The API Developer Key of a registered U{http://pastebin.com} account. 428 429 430 @rtype: string 431 @return: Returns the string (XML formatted) containing the top trending pastes. 432 """ 433 434 # Valid api developer key 435 argv = {'api_dev_key' : str(api_dev_key) } 436 437 # Valid API option - 'trends' is returns trending pastes 438 argv['api_option'] = str('trends') 439 440 # lets try to read the URL that we've just built. 441 request_string = urllib.urlopen(self._api_url, urllib.urlencode(argv)) 442 response = request_string.read() 443 444 # do some basic error checking here so we can gracefully handle any errors we are likely to encounter 445 if response.startswith(self._bad_request): 446 raise PastebinError(response) 447 448 elif not response.startswith('<paste>'): 449 raise PastebinError(response) 450 451 return response
452 453
454 - def pastes_by_user(self, api_dev_key, api_user_key, results_limit = None):
455 """Returns all pastes for the provided api_user_key. 456 457 458 Usage Example:: 459 >>> from pastebin import PastebinAPI 460 >>> x = PastebinAPI() 461 >>> details = x.user_details('453a994e0e2f1efae07f8759e59e075b', 462 ... 'c57a18e6c0ae228cd4bd16fe36da381a', 463 ... 100) 464 >>> print details 465 <paste> 466 <paste_key>DLiSspYT</paste_key> 467 <paste_date>1332714730</paste_date> 468 <paste_title>Pastebin.py - Python 3.2 Pastebin.com API</paste_title> 469 <paste_size>25300</paste_size> 470 <paste_expire_date>0</paste_expire_date> 471 <paste_private>0</paste_private> 472 <paste_format_long>Python</paste_format_long> 473 <paste_format_short>python</paste_format_short> 474 <paste_url>http://pastebin.com/DLiSspYT</paste_url> 475 <paste_hits>70</paste_hits> 476 </paste> 477 478 Note: Returns multiple pastes, not just 1. 479 480 481 @type api_dev_key: string 482 @param api_dev_key: The API Developer Key of a registered U{http://pastebin.com} account. 483 484 @type api_user_key: string 485 @param api_user_key: The API User Key of a U{http://pastebin.com} registered user. 486 487 @type results_limit: number 488 @param results_limit: The number of pastes to return between 1 - 1000. 489 490 @rtype: string 491 @returns: Returns an XML string containing number of specified pastes by user. 492 """ 493 494 # Valid api developer key 495 argv = {'api_dev_key' : str(api_dev_key) } 496 497 # Requires pre-registered account 498 if api_user_key is not None: 499 argv['api_user_key'] = str(api_user_key) 500 501 # Number of results to return - between 1 & 1000, default = 50 502 if results_limit is None: 503 argv['api_results_limit'] = 50 504 505 if results_limit is not None: 506 if results_limit < 1: 507 argv['api_results_limit'] = 50 508 elif results_limit > 1000: 509 argv['api_results_limit'] = 1000 510 else: 511 argv['api_results_limit'] = int(results_limit) 512 513 # Valid API option - 'paste' is default for new paste 514 argv['api_option'] = str('list') 515 516 # lets try to read the URL that we've just built. 517 request_string = urllib.urlopen(self._api_url, urllib.urlencode(argv)) 518 response = request_string.read() 519 520 # do some basic error checking here so we can gracefully handle any errors we are likely to encounter 521 if response.startswith(self._bad_request): 522 raise PastebinError(response) 523 524 elif not response.startswith('<paste>'): 525 raise PastebinError(response) 526 527 return response
528 529
530 - def generate_user_key(self, api_dev_key, username, password):
531 """Generate a user session key - needed for other functions. 532 533 534 Usage Example:: 535 >>> from pastebin import PastebinAPI 536 >>> x = PastebinAPI() 537 >>> my_key = x.generate_user_key('453a994e0e2f1efae07f8759e59e075b', 538 ... 'MonkeyPuzzle', 539 ... '12345678') 540 >>> print my_key 541 c57a18e6c0ae228cd4bd16fe36da381a 542 543 544 @type api_dev_key: string 545 @param api_dev_key: The API Developer Key of a registered U{http://pastebin.com} account. 546 547 @type username: string 548 @param username: The username of a registered U{http://pastebin.com} account. 549 550 @type password: string 551 @param password: The password of a registered U{http://pastebin.com} account. 552 553 @rtype: string 554 @returns: Session key (api_user_key) to allow authenticated interaction to the API. 555 556 """ 557 # Valid api developer key 558 argv = {'api_dev_key' : str(api_dev_key) } 559 560 # Requires pre-registered pastebin account 561 if username is not None: 562 argv['api_user_name'] = str(username) 563 564 # Requires pre-registered pastebin account 565 if password is not None: 566 argv['api_user_password'] = str(password) 567 568 # lets try to read the URL that we've just built. 569 request_string = urllib.urlopen(self._api_url, urllib.urlencode(argv)) 570 response = request_string.read() 571 572 # do some basic error checking here so we can gracefully handle any errors we are likely to encounter 573 if response.startswith(self._bad_request): 574 raise PastebinError(response) 575 576 return response
577 578
579 - def paste(self, api_dev_key, api_paste_code, 580 api_user_key = None, paste_name = None, paste_format = None, 581 paste_private = None, paste_expire_date = None):
582 583 """Submit a code snippet to Pastebin using the new API. 584 585 586 Usage Example:: 587 >>> from pastebin import PastebinAPI 588 >>> x = PastebinAPI() 589 >>> url = x.paste('453a994e0e2f1efae07f8759e59e075b' , 590 ... 'Snippet of code to paste goes here', 591 ... paste_name = 'title of paste', 592 ... api_user_key = 'c57a18e6c0ae228cd4bd16fe36da381a', 593 ... paste_format = 'python', 594 ... paste_private = 'unlisted', 595 ... paste_expire_date = '10M') 596 >>> print url 597 http://pastebin.com/tawPUgqY 598 599 600 @type api_dev_key: string 601 @param api_dev_key: The API Developer Key of a registered U{http://pastebin.com} account. 602 603 @type api_paste_code: string 604 @param api_paste_code: The file or string to paste to body of the U{http://pastebin.com} paste. 605 606 @type api_user_key: string 607 @param api_user_key: The API User Key of a U{http://pastebin.com} registered user. 608 If none specified, paste is made as a guest. 609 610 @type paste_name: string 611 @param paste_name: (Optional) Title of the paste. 612 Default is to paste anonymously. 613 614 @type paste_format: string 615 @param paste_format: (Optional) Programming language of the code being 616 pasted. This enables syntax highlighting when reading the code in 617 U{http://pastebin.com}. Default is no syntax highlighting (text is 618 just text and not source code). 619 620 @type paste_private: string 621 @param paste_private: (Optional) C{'public'} if the paste is public (visible 622 by everyone), C{'unlisted'} if it's public but not searchable. 623 C{'private'} if the paste is private and not searchable or indexed. 624 The Pastebin FAQ (U{http://pastebin.com/faq}) claims 625 private pastes are not indexed by search engines (aka Google). 626 627 @type paste_expire_date: str 628 @param paste_expire_date: (Optional) Expiration date for the paste. 629 Once past this date the paste is deleted automatically. Valid 630 values are found in the L{PastebinAPI.paste_expire_date} class member. 631 If not provided, the paste never expires. 632 633 @rtype: string 634 @return: Returns the URL to the newly created paste. 635 """ 636 637 638 # Valid api developer key 639 argv = {'api_dev_key' : str(api_dev_key) } 640 641 # Code snippet to submit 642 if paste_code is not None: 643 argv['api_paste_code'] = str(api_paste_code) 644 645 # Valid API option - 'paste' is default for new paste 646 argv['api_option'] = str('paste') 647 648 # API User Key 649 if api_user_key is not None: 650 argv['api_user_key'] = str(api_user_key) 651 elif api_user_key is None: 652 argv['api_user_key'] = str('') 653 654 # Name of the poster 655 if paste_name is not None: 656 argv['api_paste_name'] = str(paste_name) 657 658 # Syntax highlighting 659 if paste_format is not None: 660 paste_format = str(paste_format).strip().lower() 661 argv['api_paste_format'] = paste_format 662 663 # Is the snippet private? 664 if paste_private is not None: 665 if paste_private == 'public': 666 argv['api_paste_private'] = int(0) 667 elif paste_private == 'unlisted': 668 argv['api_paste_private'] = int(1) 669 elif paste_private == 'private': 670 argv['api_paste_private'] = int(2) 671 672 # Expiration for the snippet 673 if paste_expire_date is not None: 674 paste_expire_date = str(paste_expire_date).strip().upper() 675 argv['api_paste_expire_date'] = paste_expire_date 676 677 # lets try to read the URL that we've just built. 678 request_string = urllib.urlopen(self._api_url, urllib.urlencode(argv)) 679 response = request_string.read() 680 681 # do some basic error checking here so we can gracefully handle any errors we are likely to encounter 682 if response.startswith(self._bad_request): 683 raise PastebinError(response) 684 elif not response.startswith(self._prefix_url): 685 raise PastebinError(response) 686 687 return response
688 689
690 - def legacy_paste(self, paste_code, 691 paste_name = None, paste_private = None, 692 paste_expire_date = None, paste_format = None):
693 """Unofficial python interface to the Pastebin legacy API. 694 695 Unlike the official API, this one doesn't require an API key, so it's 696 virtually anonymous. 697 698 699 Usage Example:: 700 >>> from pastebin import PastebinAPI 701 >>> x = PastebinAPI() 702 >>> url = x.legacy_paste('Snippet of code to paste goes here', 703 ... paste_name = 'title of paste', 704 ... paste_private = 'unlisted', 705 ... paste_expire_date = '10M', 706 ... paste_format = 'python') 707 >>> print url 708 http://pastebin.com/tawPUgqY 709 710 711 @type paste_code: string 712 @param paste_code: The file or string to paste to body of the U{http://pastebin.com} paste. 713 714 @type paste_name: string 715 @param paste_name: (Optional) Title of the paste. 716 Default is to paste with no title. 717 718 @type paste_private: string 719 @param paste_private: (Optional) C{'public'} if the paste is public (visible 720 by everyone), C{'unlisted'} if it's public but not searchable. 721 C{'private'} if the paste is private and not searchable or indexed. 722 The Pastebin FAQ (U{http://pastebin.com/faq}) claims 723 private pastes are not indexed by search engines (aka Google). 724 725 @type paste_expire_date: string 726 @param paste_expire_date: (Optional) Expiration date for the paste. 727 Once past this date the paste is deleted automatically. Valid 728 values are found in the L{PastebinAPI.paste_expire_date} class member. 729 If not provided, the paste never expires. 730 731 @type paste_format: string 732 @param paste_format: (Optional) Programming language of the code being 733 pasted. This enables syntax highlighting when reading the code in 734 U{http://pastebin.com}. Default is no syntax highlighting (text is 735 just text and not source code). 736 737 @rtype: string 738 @return: Returns the URL to the newly created paste. 739 """ 740 741 # Code snippet to submit 742 argv = { 'paste_code' : str(paste_code) } 743 744 # Name of the poster 745 if paste_name is not None: 746 argv['paste_name'] = str(paste_name) 747 748 # Is the snippet private? 749 if paste_private is not None: 750 argv['paste_private'] = int(bool(int(paste_private))) 751 752 # Expiration for the snippet 753 if paste_expire_date is not None: 754 paste_expire_date = str(paste_expire_date).strip().upper() 755 argv['paste_expire_date'] = paste_expire_date 756 757 # Syntax highlighting 758 if paste_format is not None: 759 paste_format = str(paste_format).strip().lower() 760 argv['paste_format'] = paste_format 761 762 # lets try to read the URL that we've just built. 763 request_string = urllib.urlopen(self._api_url, urllib.urlencode(argv)) 764 response = request_string.read() 765 766 # do some basic error checking here so we can gracefully handle any errors we are likely to encounter 767 if response.startswith(self._bad_request): 768 raise PastebinError(response) 769 elif not response.startswith(self._prefix_url): 770 raise PastebinError(response) 771 772 return response
773 774 775 776 777 778 779 ###################################################### 780 781 delete_paste = PastebinAPI.delete_paste 782 user_details = PastebinAPI.user_details 783 trending = PastebinAPI.trending 784 pastes_by_user = PastebinAPI.pastes_by_user 785 generate_user_key = PastebinAPI.generate_user_key 786 legacy_paste = PastebinAPI.legacy_paste 787 paste = PastebinAPI.paste 788 789 ###################################################### 790 791 if __name__ == "__main__": 792 main() 793