10
10
import urllib
11
11
from xml .dom .minidom import parseString
12
12
from pastebin_options import OPTION_PASTE , OPTION_LIST , OPTION_TRENDS , OPTION_DELETE , OPTION_USER_DETAILS
13
- from pastebin_constants import PASTEBIN_API_POST_URL , PASTEBIN_API_LOGIN_URL
14
- from pastebin_exceptions import PastebinBadRequestException , PastebinNoPastesException , PastebinFileException
13
+ from pastebin_constants import PASTEBIN_API_POST_URL , PASTEBIN_API_LOGIN_URL , PASTEBIN_RAW_URL
14
+ from pastebin_exceptions import PastebinBadRequestException , PastebinNoPastesException , PastebinFileException , PastebinHTTPErrorException
15
15
16
16
class PastebinPython (object ):
17
17
"""This is the main class to be instantiated to use pastebin.com functionality
@@ -77,6 +77,7 @@ def createPaste(self, api_paste_code, api_paste_name='', api_paste_format='', ap
77
77
78
78
"""
79
79
api_user_key = self .api_user_key if self .api_user_key else ""
80
+ api_paste_code = api_paste_code .encode ('utf-8' ) if api_paste_code else ""
80
81
81
82
postData = {
82
83
'api_option' :OPTION_PASTE ,
@@ -348,4 +349,23 @@ def getUserInfos(self):
348
349
retData = self .__processPost (PASTEBIN_API_POST_URL , postData )
349
350
retData = self .__parseXML (retData , False )
350
351
351
- return retData
352
+ return retData
353
+
354
+ def getPasteRawOutput (self , api_paste_key ):
355
+ """This will get the raw output of the paste
356
+
357
+ :param api_paste_key: this is the paste key that which you can get in the :meth:`pastebin_python.pastebin.PastebinPython.listUserPastes` function
358
+ :type api_paste_key: str
359
+ :returns: str -- raw output of the paste
360
+ :raises: :exc:`pastebin_python.pastebin_exceptions.PastebinHTTPErrorException`
361
+
362
+ """
363
+
364
+ try :
365
+ request = urllib2 .urlopen ("%s%s" % (PASTEBIN_RAW_URL , api_paste_key ))
366
+ response = request .read ()
367
+ request .close ()
368
+ except urllib2 .HTTPError as e :
369
+ raise PastebinHTTPErrorException (str (e ))
370
+
371
+ return response .decode ('utf-8' )
0 commit comments