Skip to content

Commit 8b3b93c

Browse files
committed
Finishing up
1 parent 4f19acf commit 8b3b93c

File tree

8 files changed

+146
-48
lines changed

8 files changed

+146
-48
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
telegram.ext.BasePersistence
2+
============================
3+
4+
.. autoclass:: telegram.ext.BasePersistence
5+
:members:
6+
:show-inheritance:
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
telegram.ext.PicklePersistence
2+
==============================
3+
4+
.. autoclass:: telegram.ext.PicklePersistence
5+
:members:
6+
:show-inheritance:

docs/source/telegram.ext.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,11 @@ Handlers
2929
telegram.ext.stringcommandhandler
3030
telegram.ext.stringregexhandler
3131
telegram.ext.typehandler
32+
33+
Persistence
34+
-----------
35+
36+
.. toctree::
37+
38+
telegram.ext.basepersistence
39+
telegram.ext.picklepersistence

telegram/ext/basepersistence.py

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,18 @@
2020

2121

2222
class BasePersistence(object):
23-
"""Example class for adding persistence to your bot.
23+
"""Interface class for adding persistence to your bot.
2424
Subclass this object for different implementations of a persistent bot.
2525
2626
All relevant methods must be overwritten. This means:
27-
* If :attr:`store_chat_data` is ``True`` you must overwrite :attr:`get_chat_data` and
28-
:attr:`update_chat_data`
29-
* If :attr:`store_user_data` is ``True`` you must overwrite :attr:`get_user_data` and
30-
:attr:`update_user_data`
31-
* If you want to store conversation data with :class:`telegram.ext.CanversationHandler`, you
32-
must overwrite :attr:`get_conversations` and :attr:`update_conversations`
33-
* :attr:`flush` will be called when the bot is shutdown, and must always be overwritten.
27+
28+
* If :attr:`store_chat_data` is ``True`` you must overwrite :meth:`get_chat_data` and
29+
:meth:`update_chat_data`.
30+
* If :attr:`store_user_data` is ``True`` you must overwrite :meth:`get_user_data` and
31+
:meth:`update_user_data`.
32+
* If you want to store conversation data with :class:`telegram.ext.ConversationHandler`, you
33+
must overwrite :meth:`get_conversations` and :meth:`update_conversations`.
34+
* :meth:`flush` will be called when the bot is shutdown, and must always be overwritten.
3435
3536
Attributes:
3637
store_user_data (:obj:`bool`): Optional, Whether user_data should be saved by this
@@ -55,7 +56,7 @@ def get_user_data(self):
5556
``defaultdict(dict)``.
5657
5758
Returns:
58-
:obj:'defaultdict`: The restored user data.
59+
:obj:`defaultdict`: The restored user data.
5960
"""
6061
raise NotImplementedError
6162

@@ -65,51 +66,51 @@ def get_chat_data(self):
6566
``defaultdict(dict)``.
6667
6768
Returns:
68-
:obj:'defaultdict`: The restored chat data.
69+
:obj:`defaultdict`: The restored chat data.
6970
"""
7071
raise NotImplementedError
7172

7273
def get_conversations(self, name):
7374
""""Will be called by :class:`telegram.ext.Dispatcher` when a
74-
:class:`telegram.ext.CanversationHandler` is added if
75+
:class:`telegram.ext.ConversationHandler` is added if
7576
:attr:`telegram.ext.ConversationHandler.persistent` is ``True``.
7677
It should return the conversations for the handler with `name` or an empty ``dict``
7778
7879
Args:
7980
name (:obj:`str`): The handlers name.
8081
8182
Returns:
82-
:obj:'dict`: The restored conversations for the handler.
83+
:obj:`dict`: The restored conversations for the handler.
8384
"""
8485
raise NotImplementedError
8586

8687
def update_conversations(self, name, conversations):
87-
""""Will be called when a :attr:`telegram.ext.ConversationHandler.update_state`
88+
"""Will be called when a :attr:`telegram.ext.ConversationHandler.update_state`
8889
is called. this allows the storeage of the new state in the persistence.
8990
9091
Args:
9192
name (:obj:`str`): The handlers name.
92-
conversations (:obj:'dict`): The :attr:`telegram.ext.ConversationHandler.conversations`
93+
conversations (:obj:`dict`): The :attr:`telegram.ext.ConversationHandler.conversations`
9394
dict to store.
9495
"""
9596
raise NotImplementedError
9697

9798
def update_user_data(self, user_data):
98-
""""Will be calle by the :class:`telegram.ext.Dispatcher` after a handler has
99+
"""Will be called by the :class:`telegram.ext.Dispatcher` after a handler has
99100
handled an update. It will be the :attr:`telegram.ext.Dispatcher.user_data` defaultdict.
100101
101102
Args:
102-
user_data (:obj:'defaultdict`): The :attr:`telegram.ext.dispatcher.user_data`
103+
user_data (:obj:`defaultdict`): The :attr:`telegram.ext.dispatcher.user_data`
103104
defaultdict to store.
104105
"""
105106
raise NotImplementedError
106107

107108
def update_chat_data(self, chat_data):
108-
""""Will be calle by the :class:`telegram.ext.Dispatcher` after a handler has
109+
"""Will be called by the :class:`telegram.ext.Dispatcher` after a handler has
109110
handled an update. It will be the :attr:`telegram.ext.Dispatcher.chat_data` defaultdict.
110111
111112
Args:
112-
chat_data (:obj:'defaultdict`): The :attr:`telegram.ext.dispatcher.chat_data`
113+
chat_data (:obj:`defaultdict`): The :attr:`telegram.ext.dispatcher.chat_data`
113114
defaultdict to store.
114115
"""
115116
raise NotImplementedError

telegram/ext/conversationhandler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class ConversationHandler(Handler):
7979
name (:obj:`str`): Optional. The name for this conversationhandler. Required for
8080
persistence
8181
persistent (:obj:`bool`): Optional. If the conversations dict for this handler should be
82-
saved. Name is required and persistence has to be set in :class:`Updater`
82+
saved. Name is required and persistence has to be set in :class:`telegram.ext.Updater`
8383
8484
Args:
8585
entry_points (List[:class:`telegram.ext.Handler`]): A list of ``Handler`` objects that can
@@ -114,7 +114,7 @@ class ConversationHandler(Handler):
114114
name (:obj:`str`, optional): The name for this conversationhandler. Required for
115115
persistence
116116
persistent (:obj:`bool`, optional): If the conversations dict for this handler should be
117-
saved. Name is required and persistence has to be set in :class:`Updater`
117+
saved. Name is required and persistence has to be set in :class:`telegram.ext.Updater`
118118
119119
Raises:
120120
ValueError

telegram/ext/picklepersistence.py

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@
2020
import pickle
2121
from collections import defaultdict
2222

23+
from telegram.ext import BasePersistence
2324

24-
class PicklePersistence(object):
25+
26+
class PicklePersistence(BasePersistence):
2527
"""Using python's builtin pickle for making you bot persistent.
2628
2729
Attributes:
@@ -34,8 +36,8 @@ class PicklePersistence(object):
3436
single_file (:obj:`bool`): Optional. When ``False`` will store 3 sperate files of
3537
`filename_user_data`, `filename_chat_data` and `filename_conversations`. Default is
3638
``True``.
37-
on_flush (:obj:`bool`): Optional. When ``True` will only save to file when :attr:`flush` is
38-
called and keep data in memory until that happens. When False will store data on any
39+
on_flush (:obj:`bool`): Optional. When ``True`` will only save to file when :meth:`flush`
40+
is called and keep data in memory until that happens. When False will store data on any
3941
transaction. Default is ``False``.
4042
4143
Args:
@@ -48,8 +50,8 @@ class PicklePersistence(object):
4850
single_file (:obj:`bool`, optional): When ``False`` will store 3 sperate files of
4951
`filename_user_data`, `filename_chat_data` and `filename_conversations`. Default is
5052
``True``.
51-
on_flush (:obj:`bool`, optional): When ``True` will only save to file when :attr:`flush` is
52-
called and keep data in memory until that happens. When False will store data on any
53+
on_flush (:obj:`bool`, optional): When ``True`` will only save to file when :meth:`flush`
54+
is called and keep data in memory until that happens. When False will store data on any
5355
transaction. Default is ``False``.
5456
"""
5557

@@ -99,10 +101,10 @@ def dump_file(self, filename, data):
99101
pickle.dump(data, f)
100102

101103
def get_user_data(self):
102-
""""Returns the user_data from the pickle file if it exsists or an empty defaultdict.
104+
"""Returns the user_data from the pickle file if it exsists or an empty defaultdict.
103105
104106
Returns:
105-
:obj:'defaultdict`: The restored user data.
107+
:obj:`defaultdict`: The restored user data.
106108
"""
107109
if self.user_data:
108110
pass
@@ -119,10 +121,10 @@ def get_user_data(self):
119121
return self.user_data.copy()
120122

121123
def get_chat_data(self):
122-
""""Returns the chat_data from the pickle file if it exsists or an empty defaultdict.
124+
"""Returns the chat_data from the pickle file if it exsists or an empty defaultdict.
123125
124126
Returns:
125-
:obj:'defaultdict`: The restored chat data.
127+
:obj:`defaultdict`: The restored chat data.
126128
"""
127129
if self.chat_data:
128130
pass
@@ -139,13 +141,13 @@ def get_chat_data(self):
139141
return self.chat_data.copy()
140142

141143
def get_conversations(self, name):
142-
""""Returns the conversations from the pickle file if it exsists or an empty defaultdict.
144+
"""Returns the conversations from the pickle file if it exsists or an empty defaultdict.
143145
144146
Args:
145147
name (:obj:`str`): The handlers name.
146148
147149
Returns:
148-
:obj:'dict`: The restored conversations for the handler.
150+
:obj:`dict`: The restored conversations for the handler.
149151
"""
150152
if self.conversations:
151153
pass
@@ -165,7 +167,7 @@ def update_conversations(self, name, conversations):
165167
166168
Args:
167169
name (:obj:`str`): The handlers name.
168-
conversations (:obj:'dict`): The :attr:`telegram.ext.ConversationHandler.conversations`
170+
conversations (:obj:`dict`): The :attr:`telegram.ext.ConversationHandler.conversations`
169171
dict to store.
170172
"""
171173
if self.conversations[name] == conversations:
@@ -179,11 +181,11 @@ def update_conversations(self, name, conversations):
179181
self.dump_singlefile()
180182

181183
def update_user_data(self, user_data):
182-
""""Will update the user_data (if changed) and depending on :attr:`on_flush` save the
184+
"""Will update the user_data (if changed) and depending on :attr:`on_flush` save the
183185
pickle file.
184186
185187
Args:
186-
user_data (:obj:'defaultdict`): The :attr:`telegram.ext.dispatcher.user_data`
188+
user_data (:obj:`defaultdict`): The :attr:`telegram.ext.Dispatcher.user_data`
187189
defaultdict to store.
188190
"""
189191
if self.user_data == user_data:
@@ -197,11 +199,11 @@ def update_user_data(self, user_data):
197199
self.dump_singlefile()
198200

199201
def update_chat_data(self, chat_data):
200-
""""Will update the chat_data (if changed) and depending on :attr:`on_flush` save the
202+
"""Will update the chat_data (if changed) and depending on :attr:`on_flush` save the
201203
pickle file.
202204
203205
Args:
204-
chat_data (:obj:'defaultdict`): The :attr:`telegram.ext.dispatcher.chat_data`
206+
chat_data (:obj:`defaultdict`): The :attr:`telegram.ext.Dispatcher.chat_data`
205207
defaultdict to store.
206208
"""
207209
if self.chat_data == chat_data:

telegram/ext/updater.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class Updater(object):
7777
request_kwargs are very useful for the advanced users who would like to control the
7878
default timeouts and/or control the proxy used for http communication.
7979
persistence (:class:`telegram.ext.BasePersistence`, optional): The persistence class to
80-
store data that should be persistent over restarts
80+
store data that should be persistent over restarts.
8181
8282
Note:
8383
You must supply either a :attr:`bot` or a :attr:`token` argument.

0 commit comments

Comments
 (0)