2626#############################################################################
2727
2828
29- __ALL__ = ['delete_paste' , 'user_details' , 'trending' , 'pastes_by_user' ,
30- 'generate_user_key' , 'legacy_paste' , 'paste' , 'Pastebin' ,
31- 'PastebinError' ]
29+ __all__ = ['delete_paste' , 'user_details' , 'trending' , 'pastes_by_user' ,
30+ 'generate_user_key' , 'paste' , 'PastebinAPI' , 'PastebinError' ]
3231
3332import sys
3433import urllib
@@ -47,9 +46,6 @@ class PastebinAPI(object):
4746 paste -- Pastes a user-specified file or string using the new API-key POST
4847 method.
4948
50- legacy_paste -- Pastes a user-specified file or string using the old
51- anonymous POST method.
52-
5349 generate_user_key -- Generates a session-key that is required for other
5450 functions.
5551
@@ -81,9 +77,6 @@ class PastebinAPI(object):
8177 # URL to the POST API
8278 _api_url = 'http://%s/api/api_post.php' % _base_domain
8379
84- # URL to the login POST API
85- _api_login_url = 'http://%s/api/api_login.php' % _base_domain
86-
8780 # Valid paste_expire_date values (Never, 10 minutes, 1 Hour, 1 Day, 1 Month)
8881 paste_expire_date = ('N' , '10M' , '1H' , '1D' , '1M' )
8982
@@ -699,104 +692,13 @@ def paste(self, api_dev_key, api_paste_code,
699692 return response
700693
701694
702- def legacy_paste (self , paste_code ,
703- paste_name = None , paste_private = None ,
704- paste_expire_date = None , paste_format = None ):
705- """Unofficial python interface to the Pastebin legacy API.
706-
707- Unlike the official API, this one doesn't require an API key, so it's
708- virtually anonymous.
709-
710-
711- Usage Example::
712- >>> from pastebin import PastebinAPI
713- >>> x = PastebinAPI()
714- >>> url = x.legacy_paste('Snippet of code to paste goes here',
715- ... paste_name = 'title of paste',
716- ... paste_private = 'unlisted',
717- ... paste_expire_date = '10M',
718- ... paste_format = 'python')
719- >>> print url
720- http://pastebin.com/tawPUgqY
721-
722-
723- @type paste_code: string
724- @param paste_code: The file or string to paste to body of the U{http://pastebin.com} paste.
725-
726- @type paste_name: string
727- @param paste_name: (Optional) Title of the paste.
728- Default is to paste with no title.
729-
730- @type paste_private: string
731- @param paste_private: (Optional) C{'public'} if the paste is public (visible
732- by everyone), C{'unlisted'} if it's public but not searchable.
733- C{'private'} if the paste is private and not searchable or indexed.
734- The Pastebin FAQ (U{http://pastebin.com/faq}) claims
735- private pastes are not indexed by search engines (aka Google).
736-
737- @type paste_expire_date: string
738- @param paste_expire_date: (Optional) Expiration date for the paste.
739- Once past this date the paste is deleted automatically. Valid
740- values are found in the L{PastebinAPI.paste_expire_date} class member.
741- If not provided, the paste never expires.
742-
743- @type paste_format: string
744- @param paste_format: (Optional) Programming language of the code being
745- pasted. This enables syntax highlighting when reading the code in
746- U{http://pastebin.com}. Default is no syntax highlighting (text is
747- just text and not source code).
748-
749- @rtype: string
750- @return: Returns the URL to the newly created paste.
751- """
752-
753- # Code snippet to submit
754- argv = { 'paste_code' : str (paste_code ) }
755-
756- # Name of the poster
757- if paste_name is not None :
758- argv ['paste_name' ] = str (paste_name )
759-
760- # Is the snippet private?
761- if paste_private is not None :
762- argv ['paste_private' ] = int (bool (int (paste_private )))
763-
764- # Expiration for the snippet
765- if paste_expire_date is not None :
766- paste_expire_date = str (paste_expire_date ).strip ().upper ()
767- argv ['paste_expire_date' ] = paste_expire_date
768-
769- # Syntax highlighting
770- if paste_format is not None :
771- paste_format = str (paste_format ).strip ().lower ()
772- argv ['paste_format' ] = paste_format
773-
774- # lets try to read the URL that we've just built.
775- request_string = urllib .urlopen (self ._legacy_api_url , urllib .urlencode (argv ))
776- response = request_string .read ()
777-
778- # do some basic error checking here so we can gracefully handle any
779- # errors we are likely to encounter
780- if response .startswith (self ._bad_request ):
781- raise PastebinError (response )
782- elif not response .startswith (self ._prefix_url ):
783- raise PastebinError (response )
784-
785- return response
786-
787-
788-
789-
790-
791-
792695######################################################
793696
794697delete_paste = PastebinAPI .delete_paste
795698user_details = PastebinAPI .user_details
796699trending = PastebinAPI .trending
797700pastes_by_user = PastebinAPI .pastes_by_user
798701generate_user_key = PastebinAPI .generate_user_key
799- legacy_paste = PastebinAPI .legacy_paste
800702paste = PastebinAPI .paste
801703
802704######################################################
0 commit comments