Skip to content

Commit 8e03ce7

Browse files
committed
started documenting the functions
1 parent d8415e8 commit 8e03ce7

File tree

2 files changed

+90
-1
lines changed

2 files changed

+90
-1
lines changed

pastebin_python/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
"""A complete pastebin.com API wrapper for Python
2+
3+
.. moduleauthor:: Ferdinand Silva <[email protected]>
4+
5+
"""
16
from pastebin import PastebinPython
27

38
__version__ = "1.0"

pastebin_python/pastebin.py

Lines changed: 85 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
"""
2+
.. module:: pastebin
3+
:synopsis: This module contains the main class to be instantiated to use pastebin.com functionality
4+
5+
.. moduleauthor:: Ferdinand Silva <[email protected]>
6+
7+
"""
18
import re, urllib2, urllib
29
from xml.dom.minidom import parseString
310

@@ -10,23 +17,70 @@
1017
PastebinFileException
1118

1219
class PastebinPython(object):
20+
"""This is the main class to be instantiated to use pastebin.com functionality
21+
22+
"""
1323

1424
def __init__(self, **kwargs):
25+
"""You need to put your **API Key** when instantiating this class
26+
27+
:param kwargs: keyword arguments to set settings that can be use to call pastebin.com API function
28+
:type kwargs: dict
29+
:returns: class -- PastebinPython
30+
31+
===========
32+
Example:
33+
===========
34+
35+
>>> pasteBin = PastebinPython(api_dev_key='123456789')
36+
>>> print pasteBin.api_dev_key
37+
123456789
38+
39+
"""
1540

1641
self.api_dev_key = kwargs.get('api_dev_key','')
1742
self.__api_user_key = ""
1843
self.__api_user_paste_list = []
1944

2045
@property
2146
def api_user_key(self):
47+
"""This is where the api_user_key is stored after calling :func:`getUserKey`
48+
49+
:returns: str -- the api_user_key
50+
51+
"""
2252
return self.__api_user_key
2353

2454
@property
2555
def api_user_paste_list(self):
56+
"""This where the list of pastes of the current user is stored after calling :func:`listUserPastes`
57+
58+
:returns: list -- current user pastes list
59+
60+
"""
2661
return self.__api_user_paste_list
2762

2863
def createPaste(self, api_paste_code, api_paste_name='', api_paste_format='', api_paste_private='', api_paste_expire_date=''):
29-
64+
"""This will create a new paste
65+
66+
:param api_paste_code: this is the text that will be written inside your paste
67+
:type api_paste_code: str
68+
:param api_paste_name: this will be the name / title of your paste
69+
:type api_paste_name: str
70+
:param api_paste_format: this will be the syntax highlighting value, values to be assign can be found at :mod:`pastebin_python.pastebin_formats`
71+
:type api_paste_format: str
72+
:param api_paste_private: this makes a paste public or private, values to be assign can be found at :mod:`pastebin_python.pastebin_constants`
73+
:type api_paste_private: int
74+
:param api_paste_expire_date: this sets the expiration date of your paste, values to be assign can be found at :mod:`pastebin_python.pastebin_constants`
75+
:type api_paste_expire_date: str
76+
:returns: str -- pastebin.com paste URL
77+
:raises: PastebinBadRequestException
78+
79+
.. note::
80+
81+
*api_paste_code* is the only required parameter
82+
83+
"""
3084
api_user_key = self.api_user_key if self.api_user_key else ""
3185

3286
postData = {
@@ -43,6 +97,26 @@ def createPaste(self, api_paste_code, api_paste_name='', api_paste_format='', ap
4397
return self.__processPost(PASTEBIN_API_POST_URL, postData)
4498

4599
def createPasteFromFile(self, filename, api_paste_name='', api_paste_format='', api_paste_private='', api_paste_expire_date=''):
100+
"""Almost the same as :func:`createPaste` ,the only difference is that the value of *api_paste_code* came from the file you opened
101+
102+
:param filename: the full path of the file
103+
:type filename: str
104+
:param api_paste_name: this will be the name / title of your paste
105+
:type api_paste_name: str
106+
:param api_paste_format: this will be the syntax highlighting value, values to be assign can be found at :mod:`pastebin_python.pastebin_formats`
107+
:type api_paste_format: str
108+
:param api_paste_private: this makes a paste public or private, values to be assign can be found at :mod:`pastebin_python.pastebin_constants`
109+
:type api_paste_private: int
110+
:param api_paste_expire_date: this sets the expiration date of your paste, values to be assign can be found at :mod:`pastebin_python.pastebin_constants`
111+
:type api_paste_expire_date: str
112+
:returns: str -- pastebin.com paste URL
113+
:raises: PastebinFileException
114+
115+
.. note::
116+
117+
*filename* is the only required field
118+
119+
"""
46120

47121
try:
48122
fileToOpen = open(filename, 'r')
@@ -55,6 +129,16 @@ def createPasteFromFile(self, filename, api_paste_name='', api_paste_format='',
55129

56130

57131
def __processPost(self, url, data):
132+
"""A private function that is responsible of calling/executing the pastebin.com functionality
133+
134+
:param url: the url of the pastebin.com **API**
135+
:type url: str
136+
:param data: the data to be POSTed to the pastebin.com **API**
137+
:type data: dic
138+
:returns: str -- the successfull output of the pastebin.com **API** if no exception raised
139+
:raises: PastebinBadRequestException, PastebinNoPastesException
140+
141+
"""
58142

59143
request = urllib2.urlopen(url, urllib.urlencode(data))
60144
response = str(request.read())

0 commit comments

Comments
 (0)