We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Typo in PicklePersistence ctor arguments
https://github.com/python-telegram-bot/python-telegram-bot/blob/2c92c356b8e3b07f20dcffa5b10fecc62b67e906/telegram/ext/picklepersistence.py#L59
`singe_file` should be `single_file`.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `telegram/ext/picklepersistence.py`
Content:
```
1 #!/usr/bin/env python
2 #
3 # A library that provides a Python interface to the Telegram Bot API
4 # Copyright (C) 2015-2018
5 # Leandro Toledo de Souza <devs@python-telegram-bot.org>
6 #
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Lesser 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 Lesser Public License for more details.
16 #
17 # You should have received a copy of the GNU Lesser Public License
18 # along with this program.  If not, see [http://www.gnu.org/licenses/].
19 """This module contains the PicklePersistence class."""
20 import pickle
21 from collections import defaultdict
22 from copy import deepcopy
23 
24 from telegram.ext import BasePersistence
25 
26 
27 class PicklePersistence(BasePersistence):
28     """Using python's builtin pickle for making you bot persistent.
29 
30     Attributes:
31         filename (:obj:`str`): The filename for storing the pickle files. When :attr:`single_file`
32             is false this will be used as a prefix.
33         store_user_data (:obj:`bool`): Optional. Whether user_data should be saved by this
34             persistence class.
35         store_chat_data (:obj:`bool`): Optional. Whether user_data should be saved by this
36             persistence class.
37         single_file (:obj:`bool`): Optional. When ``False`` will store 3 sperate files of
38             `filename_user_data`, `filename_chat_data` and `filename_conversations`. Default is
39             ``True``.
40         on_flush (:obj:`bool`, optional): When ``True`` will only save to file when :meth:`flush`
41             is called and keep data in memory until that happens. When ``False`` will store data
42             on any transaction *and* on call fo :meth:`flush`. Default is ``False``.
43 
44     Args:
45         filename (:obj:`str`): The filename for storing the pickle files. When :attr:`single_file`
46             is false this will be used as a prefix.
47         store_user_data (:obj:`bool`, optional): Whether user_data should be saved by this
48             persistence class. Default is ``True``.
49         store_chat_data (:obj:`bool`, optional): Whether user_data should be saved by this
50             persistence class. Default is ``True``.
51         single_file (:obj:`bool`, optional): When ``False`` will store 3 sperate files of
52             `filename_user_data`, `filename_chat_data` and `filename_conversations`. Default is
53             ``True``.
54         on_flush (:obj:`bool`, optional): When ``True`` will only save to file when :meth:`flush`
55             is called and keep data in memory until that happens. When ``False`` will store data
56             on any transaction *and* on call fo :meth:`flush`. Default is ``False``.
57     """
58 
59     def __init__(self, filename, store_user_data=True, store_chat_data=True, singe_file=True,
60                  on_flush=False):
61         self.filename = filename
62         self.store_user_data = store_user_data
63         self.store_chat_data = store_chat_data
64         self.single_file = singe_file
65         self.on_flush = on_flush
66         self.user_data = None
67         self.chat_data = None
68         self.conversations = None
69 
70     def load_singlefile(self):
71         try:
72             filename = self.filename
73             with open(self.filename, "rb") as f:
74                 all = pickle.load(f)
75                 self.user_data = defaultdict(dict, all['user_data'])
76                 self.chat_data = defaultdict(dict, all['chat_data'])
77                 self.conversations = all['conversations']
78         except IOError:
79             self.conversations = {}
80             self.user_data = defaultdict(dict)
81             self.chat_data = defaultdict(dict)
82         except pickle.UnpicklingError:
83             raise TypeError("File {} does not contain valid pickle data".format(filename))
84         except Exception:
85             raise TypeError("Something went wrong unpickling {}".format(filename))
86 
87     def load_file(self, filename):
88         try:
89             with open(filename, "rb") as f:
90                 return pickle.load(f)
91         except IOError:
92             return None
93         except pickle.UnpicklingError:
94             raise TypeError("File {} does not contain valid pickle data".format(filename))
95         except Exception:
96             raise TypeError("Something went wrong unpickling {}".format(filename))
97 
98     def dump_singlefile(self):
99         with open(self.filename, "wb") as f:
100             all = {'conversations': self.conversations, 'user_data': self.user_data,
101                    'chat_data': self.chat_data}
102             pickle.dump(all, f)
103 
104     def dump_file(self, filename, data):
105         with open(filename, "wb") as f:
106             pickle.dump(data, f)
107 
108     def get_user_data(self):
109         """Returns the user_data from the pickle file if it exsists or an empty defaultdict.
110 
111         Returns:
112             :obj:`defaultdict`: The restored user data.
113         """
114         if self.user_data:
115             pass
116         elif not self.single_file:
117             filename = "{}_user_data".format(self.filename)
118             data = self.load_file(filename)
119             if not data:
120                 data = defaultdict(dict)
121             else:
122                 data = defaultdict(dict, data)
123             self.user_data = data
124         else:
125             self.load_singlefile()
126         return deepcopy(self.user_data)
127 
128     def get_chat_data(self):
129         """Returns the chat_data from the pickle file if it exsists or an empty defaultdict.
130 
131         Returns:
132             :obj:`defaultdict`: The restored chat data.
133         """
134         if self.chat_data:
135             pass
136         elif not self.single_file:
137             filename = "{}_chat_data".format(self.filename)
138             data = self.load_file(filename)
139             if not data:
140                 data = defaultdict(dict)
141             else:
142                 data = defaultdict(dict, data)
143             self.chat_data = data
144         else:
145             self.load_singlefile()
146         return deepcopy(self.chat_data)
147 
148     def get_conversations(self, name):
149         """Returns the conversations from the pickle file if it exsists or an empty defaultdict.
150 
151         Args:
152             name (:obj:`str`): The handlers name.
153 
154         Returns:
155             :obj:`dict`: The restored conversations for the handler.
156         """
157         if self.conversations:
158             pass
159         elif not self.single_file:
160             filename = "{}_conversations".format(self.filename)
161             data = self.load_file(filename)
162             if not data:
163                 data = {name: {}}
164             self.conversations = data
165         else:
166             self.load_singlefile()
167         return self.conversations.get(name, {}).copy()
168 
169     def update_conversation(self, name, key, new_state):
170         """Will update the conversations for the given handler and depending on :attr:`on_flush`
171         save the pickle file.
172 
173         Args:
174             name (:obj:`str`): The handlers name.
175             key (:obj:`tuple`): The key the state is changed for.
176             new_state (:obj:`tuple` | :obj:`any`): The new state for the given key.
177         """
178         if self.conversations.setdefault(name, {}).get(key) == new_state:
179             return
180         self.conversations[name][key] = new_state
181         if not self.on_flush:
182             if not self.single_file:
183                 filename = "{}_conversations".format(self.filename)
184                 self.dump_file(filename, self.conversations)
185             else:
186                 self.dump_singlefile()
187 
188     def update_user_data(self, user_id, data):
189         """Will update the user_data (if changed) and depending on :attr:`on_flush` save the
190         pickle file.
191 
192         Args:
193             user_id (:obj:`int`): The user the data might have been changed for.
194             data (:obj:`dict`): The :attr:`telegram.ext.dispatcher.user_data` [user_id].
195         """
196         if self.user_data.get(user_id) == data:
197             return
198         self.user_data[user_id] = data
199         if not self.on_flush:
200             if not self.single_file:
201                 filename = "{}_user_data".format(self.filename)
202                 self.dump_file(filename, self.user_data)
203             else:
204                 self.dump_singlefile()
205 
206     def update_chat_data(self, chat_id, data):
207         """Will update the chat_data (if changed) and depending on :attr:`on_flush` save the
208         pickle file.
209 
210         Args:
211             chat_id (:obj:`int`): The chat the data might have been changed for.
212             data (:obj:`dict`): The :attr:`telegram.ext.dispatcher.chat_data` [chat_id].
213         """
214         if self.chat_data.get(chat_id) == data:
215             return
216         self.chat_data[chat_id] = data
217         if not self.on_flush:
218             if not self.single_file:
219                 filename = "{}_chat_data".format(self.filename)
220                 self.dump_file(filename, self.chat_data)
221             else:
222                 self.dump_singlefile()
223 
224     def flush(self):
225         """ Will save all data in memory to pickle file(s).
226         """
227         if self.single_file:
228             if self.user_data or self.chat_data or self.conversations:
229                 self.dump_singlefile()
230         else:
231             if self.user_data:
232                 self.dump_file("{}_user_data".format(self.filename), self.user_data)
233             if self.chat_data:
234                 self.dump_file("{}_chat_data".format(self.filename), self.chat_data)
235             if self.conversations:
236                 self.dump_file("{}_conversations".format(self.filename), self.conversations)
237
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/telegram/ext/picklepersistence.py b/telegram/ext/picklepersistence.py
--- a/telegram/ext/picklepersistence.py
+++ b/telegram/ext/picklepersistence.py
@@ -56,12 +56,12 @@
             on any transaction *and* on call fo :meth:`flush`. Default is ``False``.
     """
 
-    def __init__(self, filename, store_user_data=True, store_chat_data=True, singe_file=True,
+    def __init__(self, filename, store_user_data=True, store_chat_data=True, single_file=True,
                  on_flush=False):
         self.filename = filename
         self.store_user_data = store_user_data
         self.store_chat_data = store_chat_data
-        self.single_file = singe_file
+        self.single_file = single_file
         self.on_flush = on_flush
         self.user_data = None
         self.chat_data = None

{"golden_diff": "diff --git a/telegram/ext/picklepersistence.py b/telegram/ext/picklepersistence.py\n--- a/telegram/ext/picklepersistence.py\n+++ b/telegram/ext/picklepersistence.py\n@@ -56,12 +56,12 @@\n             on any transaction *and* on call fo :meth:`flush`. Default is ``False``.\n     \"\"\"\n \n-    def __init__(self, filename, store_user_data=True, store_chat_data=True, singe_file=True,\n+    def __init__(self, filename, store_user_data=True, store_chat_data=True, single_file=True,\n                  on_flush=False):\n         self.filename = filename\n         self.store_user_data = store_user_data\n         self.store_chat_data = store_chat_data\n-        self.single_file = singe_file\n+        self.single_file = single_file\n         self.on_flush = on_flush\n         self.user_data = None\n         self.chat_data = None\n", "issue": "Typo in PicklePersistence ctor arguments\nhttps://github.com/python-telegram-bot/python-telegram-bot/blob/2c92c356b8e3b07f20dcffa5b10fecc62b67e906/telegram/ext/picklepersistence.py#L59\r\n`singe_file` should be `single_file`.\n", "before_files": [{"content": "#!/usr/bin/env python\n#\n# A library that provides a Python interface to the Telegram Bot API\n# Copyright (C) 2015-2018\n# Leandro Toledo de Souza <devs@python-telegram-bot.org>\n#\n# This program is free software: you can redistribute it and/or modify\n# it under the terms of the GNU Lesser Public License as published by\n# the Free Software Foundation, either version 3 of the License, or\n# (at your option) any later version.\n#\n# This program is distributed in the hope that it will be useful,\n# but WITHOUT ANY WARRANTY; without even the implied warranty of\n# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n# GNU Lesser Public License for more details.\n#\n# You should have received a copy of the GNU Lesser Public License\n# along with this program.  If not, see [http://www.gnu.org/licenses/].\n\"\"\"This module contains the PicklePersistence class.\"\"\"\nimport pickle\nfrom collections import defaultdict\nfrom copy import deepcopy\n\nfrom telegram.ext import BasePersistence\n\n\nclass PicklePersistence(BasePersistence):\n    \"\"\"Using python's builtin pickle for making you bot persistent.\n\n    Attributes:\n        filename (:obj:`str`): The filename for storing the pickle files. When :attr:`single_file`\n            is false this will be used as a prefix.\n        store_user_data (:obj:`bool`): Optional. Whether user_data should be saved by this\n            persistence class.\n        store_chat_data (:obj:`bool`): Optional. Whether user_data should be saved by this\n            persistence class.\n        single_file (:obj:`bool`): Optional. When ``False`` will store 3 sperate files of\n            `filename_user_data`, `filename_chat_data` and `filename_conversations`. Default is\n            ``True``.\n        on_flush (:obj:`bool`, optional): When ``True`` will only save to file when :meth:`flush`\n            is called and keep data in memory until that happens. When ``False`` will store data\n            on any transaction *and* on call fo :meth:`flush`. Default is ``False``.\n\n    Args:\n        filename (:obj:`str`): The filename for storing the pickle files. When :attr:`single_file`\n            is false this will be used as a prefix.\n        store_user_data (:obj:`bool`, optional): Whether user_data should be saved by this\n            persistence class. Default is ``True``.\n        store_chat_data (:obj:`bool`, optional): Whether user_data should be saved by this\n            persistence class. Default is ``True``.\n        single_file (:obj:`bool`, optional): When ``False`` will store 3 sperate files of\n            `filename_user_data`, `filename_chat_data` and `filename_conversations`. Default is\n            ``True``.\n        on_flush (:obj:`bool`, optional): When ``True`` will only save to file when :meth:`flush`\n            is called and keep data in memory until that happens. When ``False`` will store data\n            on any transaction *and* on call fo :meth:`flush`. Default is ``False``.\n    \"\"\"\n\n    def __init__(self, filename, store_user_data=True, store_chat_data=True, singe_file=True,\n                 on_flush=False):\n        self.filename = filename\n        self.store_user_data = store_user_data\n        self.store_chat_data = store_chat_data\n        self.single_file = singe_file\n        self.on_flush = on_flush\n        self.user_data = None\n        self.chat_data = None\n        self.conversations = None\n\n    def load_singlefile(self):\n        try:\n            filename = self.filename\n            with open(self.filename, \"rb\") as f:\n                all = pickle.load(f)\n                self.user_data = defaultdict(dict, all['user_data'])\n                self.chat_data = defaultdict(dict, all['chat_data'])\n                self.conversations = all['conversations']\n        except IOError:\n            self.conversations = {}\n            self.user_data = defaultdict(dict)\n            self.chat_data = defaultdict(dict)\n        except pickle.UnpicklingError:\n            raise TypeError(\"File {} does not contain valid pickle data\".format(filename))\n        except Exception:\n            raise TypeError(\"Something went wrong unpickling {}\".format(filename))\n\n    def load_file(self, filename):\n        try:\n            with open(filename, \"rb\") as f:\n                return pickle.load(f)\n        except IOError:\n            return None\n        except pickle.UnpicklingError:\n            raise TypeError(\"File {} does not contain valid pickle data\".format(filename))\n        except Exception:\n            raise TypeError(\"Something went wrong unpickling {}\".format(filename))\n\n    def dump_singlefile(self):\n        with open(self.filename, \"wb\") as f:\n            all = {'conversations': self.conversations, 'user_data': self.user_data,\n                   'chat_data': self.chat_data}\n            pickle.dump(all, f)\n\n    def dump_file(self, filename, data):\n        with open(filename, \"wb\") as f:\n            pickle.dump(data, f)\n\n    def get_user_data(self):\n        \"\"\"Returns the user_data from the pickle file if it exsists or an empty defaultdict.\n\n        Returns:\n            :obj:`defaultdict`: The restored user data.\n        \"\"\"\n        if self.user_data:\n            pass\n        elif not self.single_file:\n            filename = \"{}_user_data\".format(self.filename)\n            data = self.load_file(filename)\n            if not data:\n                data = defaultdict(dict)\n            else:\n                data = defaultdict(dict, data)\n            self.user_data = data\n        else:\n            self.load_singlefile()\n        return deepcopy(self.user_data)\n\n    def get_chat_data(self):\n        \"\"\"Returns the chat_data from the pickle file if it exsists or an empty defaultdict.\n\n        Returns:\n            :obj:`defaultdict`: The restored chat data.\n        \"\"\"\n        if self.chat_data:\n            pass\n        elif not self.single_file:\n            filename = \"{}_chat_data\".format(self.filename)\n            data = self.load_file(filename)\n            if not data:\n                data = defaultdict(dict)\n            else:\n                data = defaultdict(dict, data)\n            self.chat_data = data\n        else:\n            self.load_singlefile()\n        return deepcopy(self.chat_data)\n\n    def get_conversations(self, name):\n        \"\"\"Returns the conversations from the pickle file if it exsists or an empty defaultdict.\n\n        Args:\n            name (:obj:`str`): The handlers name.\n\n        Returns:\n            :obj:`dict`: The restored conversations for the handler.\n        \"\"\"\n        if self.conversations:\n            pass\n        elif not self.single_file:\n            filename = \"{}_conversations\".format(self.filename)\n            data = self.load_file(filename)\n            if not data:\n                data = {name: {}}\n            self.conversations = data\n        else:\n            self.load_singlefile()\n        return self.conversations.get(name, {}).copy()\n\n    def update_conversation(self, name, key, new_state):\n        \"\"\"Will update the conversations for the given handler and depending on :attr:`on_flush`\n        save the pickle file.\n\n        Args:\n            name (:obj:`str`): The handlers name.\n            key (:obj:`tuple`): The key the state is changed for.\n            new_state (:obj:`tuple` | :obj:`any`): The new state for the given key.\n        \"\"\"\n        if self.conversations.setdefault(name, {}).get(key) == new_state:\n            return\n        self.conversations[name][key] = new_state\n        if not self.on_flush:\n            if not self.single_file:\n                filename = \"{}_conversations\".format(self.filename)\n                self.dump_file(filename, self.conversations)\n            else:\n                self.dump_singlefile()\n\n    def update_user_data(self, user_id, data):\n        \"\"\"Will update the user_data (if changed) and depending on :attr:`on_flush` save the\n        pickle file.\n\n        Args:\n            user_id (:obj:`int`): The user the data might have been changed for.\n            data (:obj:`dict`): The :attr:`telegram.ext.dispatcher.user_data` [user_id].\n        \"\"\"\n        if self.user_data.get(user_id) == data:\n            return\n        self.user_data[user_id] = data\n        if not self.on_flush:\n            if not self.single_file:\n                filename = \"{}_user_data\".format(self.filename)\n                self.dump_file(filename, self.user_data)\n            else:\n                self.dump_singlefile()\n\n    def update_chat_data(self, chat_id, data):\n        \"\"\"Will update the chat_data (if changed) and depending on :attr:`on_flush` save the\n        pickle file.\n\n        Args:\n            chat_id (:obj:`int`): The chat the data might have been changed for.\n            data (:obj:`dict`): The :attr:`telegram.ext.dispatcher.chat_data` [chat_id].\n        \"\"\"\n        if self.chat_data.get(chat_id) == data:\n            return\n        self.chat_data[chat_id] = data\n        if not self.on_flush:\n            if not self.single_file:\n                filename = \"{}_chat_data\".format(self.filename)\n                self.dump_file(filename, self.chat_data)\n            else:\n                self.dump_singlefile()\n\n    def flush(self):\n        \"\"\" Will save all data in memory to pickle file(s).\n        \"\"\"\n        if self.single_file:\n            if self.user_data or self.chat_data or self.conversations:\n                self.dump_singlefile()\n        else:\n            if self.user_data:\n                self.dump_file(\"{}_user_data\".format(self.filename), self.user_data)\n            if self.chat_data:\n                self.dump_file(\"{}_chat_data\".format(self.filename), self.chat_data)\n            if self.conversations:\n                self.dump_file(\"{}_conversations\".format(self.filename), self.conversations)\n", "path": "telegram/ext/picklepersistence.py"}], "after_files": [{"content": "#!/usr/bin/env python\n#\n# A library that provides a Python interface to the Telegram Bot API\n# Copyright (C) 2015-2018\n# Leandro Toledo de Souza <devs@python-telegram-bot.org>\n#\n# This program is free software: you can redistribute it and/or modify\n# it under the terms of the GNU Lesser Public License as published by\n# the Free Software Foundation, either version 3 of the License, or\n# (at your option) any later version.\n#\n# This program is distributed in the hope that it will be useful,\n# but WITHOUT ANY WARRANTY; without even the implied warranty of\n# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n# GNU Lesser Public License for more details.\n#\n# You should have received a copy of the GNU Lesser Public License\n# along with this program.  If not, see [http://www.gnu.org/licenses/].\n\"\"\"This module contains the PicklePersistence class.\"\"\"\nimport pickle\nfrom collections import defaultdict\nfrom copy import deepcopy\n\nfrom telegram.ext import BasePersistence\n\n\nclass PicklePersistence(BasePersistence):\n    \"\"\"Using python's builtin pickle for making you bot persistent.\n\n    Attributes:\n        filename (:obj:`str`): The filename for storing the pickle files. When :attr:`single_file`\n            is false this will be used as a prefix.\n        store_user_data (:obj:`bool`): Optional. Whether user_data should be saved by this\n            persistence class.\n        store_chat_data (:obj:`bool`): Optional. Whether user_data should be saved by this\n            persistence class.\n        single_file (:obj:`bool`): Optional. When ``False`` will store 3 sperate files of\n            `filename_user_data`, `filename_chat_data` and `filename_conversations`. Default is\n            ``True``.\n        on_flush (:obj:`bool`, optional): When ``True`` will only save to file when :meth:`flush`\n            is called and keep data in memory until that happens. When ``False`` will store data\n            on any transaction *and* on call fo :meth:`flush`. Default is ``False``.\n\n    Args:\n        filename (:obj:`str`): The filename for storing the pickle files. When :attr:`single_file`\n            is false this will be used as a prefix.\n        store_user_data (:obj:`bool`, optional): Whether user_data should be saved by this\n            persistence class. Default is ``True``.\n        store_chat_data (:obj:`bool`, optional): Whether user_data should be saved by this\n            persistence class. Default is ``True``.\n        single_file (:obj:`bool`, optional): When ``False`` will store 3 sperate files of\n            `filename_user_data`, `filename_chat_data` and `filename_conversations`. Default is\n            ``True``.\n        on_flush (:obj:`bool`, optional): When ``True`` will only save to file when :meth:`flush`\n            is called and keep data in memory until that happens. When ``False`` will store data\n            on any transaction *and* on call fo :meth:`flush`. Default is ``False``.\n    \"\"\"\n\n    def __init__(self, filename, store_user_data=True, store_chat_data=True, single_file=True,\n                 on_flush=False):\n        self.filename = filename\n        self.store_user_data = store_user_data\n        self.store_chat_data = store_chat_data\n        self.single_file = single_file\n        self.on_flush = on_flush\n        self.user_data = None\n        self.chat_data = None\n        self.conversations = None\n\n    def load_singlefile(self):\n        try:\n            filename = self.filename\n            with open(self.filename, \"rb\") as f:\n                all = pickle.load(f)\n                self.user_data = defaultdict(dict, all['user_data'])\n                self.chat_data = defaultdict(dict, all['chat_data'])\n                self.conversations = all['conversations']\n        except IOError:\n            self.conversations = {}\n            self.user_data = defaultdict(dict)\n            self.chat_data = defaultdict(dict)\n        except pickle.UnpicklingError:\n            raise TypeError(\"File {} does not contain valid pickle data\".format(filename))\n        except Exception:\n            raise TypeError(\"Something went wrong unpickling {}\".format(filename))\n\n    def load_file(self, filename):\n        try:\n            with open(filename, \"rb\") as f:\n                return pickle.load(f)\n        except IOError:\n            return None\n        except pickle.UnpicklingError:\n            raise TypeError(\"File {} does not contain valid pickle data\".format(filename))\n        except Exception:\n            raise TypeError(\"Something went wrong unpickling {}\".format(filename))\n\n    def dump_singlefile(self):\n        with open(self.filename, \"wb\") as f:\n            all = {'conversations': self.conversations, 'user_data': self.user_data,\n                   'chat_data': self.chat_data}\n            pickle.dump(all, f)\n\n    def dump_file(self, filename, data):\n        with open(filename, \"wb\") as f:\n            pickle.dump(data, f)\n\n    def get_user_data(self):\n        \"\"\"Returns the user_data from the pickle file if it exsists or an empty defaultdict.\n\n        Returns:\n            :obj:`defaultdict`: The restored user data.\n        \"\"\"\n        if self.user_data:\n            pass\n        elif not self.single_file:\n            filename = \"{}_user_data\".format(self.filename)\n            data = self.load_file(filename)\n            if not data:\n                data = defaultdict(dict)\n            else:\n                data = defaultdict(dict, data)\n            self.user_data = data\n        else:\n            self.load_singlefile()\n        return deepcopy(self.user_data)\n\n    def get_chat_data(self):\n        \"\"\"Returns the chat_data from the pickle file if it exsists or an empty defaultdict.\n\n        Returns:\n            :obj:`defaultdict`: The restored chat data.\n        \"\"\"\n        if self.chat_data:\n            pass\n        elif not self.single_file:\n            filename = \"{}_chat_data\".format(self.filename)\n            data = self.load_file(filename)\n            if not data:\n                data = defaultdict(dict)\n            else:\n                data = defaultdict(dict, data)\n            self.chat_data = data\n        else:\n            self.load_singlefile()\n        return deepcopy(self.chat_data)\n\n    def get_conversations(self, name):\n        \"\"\"Returns the conversations from the pickle file if it exsists or an empty defaultdict.\n\n        Args:\n            name (:obj:`str`): The handlers name.\n\n        Returns:\n            :obj:`dict`: The restored conversations for the handler.\n        \"\"\"\n        if self.conversations:\n            pass\n        elif not self.single_file:\n            filename = \"{}_conversations\".format(self.filename)\n            data = self.load_file(filename)\n            if not data:\n                data = {name: {}}\n            self.conversations = data\n        else:\n            self.load_singlefile()\n        return self.conversations.get(name, {}).copy()\n\n    def update_conversation(self, name, key, new_state):\n        \"\"\"Will update the conversations for the given handler and depending on :attr:`on_flush`\n        save the pickle file.\n\n        Args:\n            name (:obj:`str`): The handlers name.\n            key (:obj:`tuple`): The key the state is changed for.\n            new_state (:obj:`tuple` | :obj:`any`): The new state for the given key.\n        \"\"\"\n        if self.conversations.setdefault(name, {}).get(key) == new_state:\n            return\n        self.conversations[name][key] = new_state\n        if not self.on_flush:\n            if not self.single_file:\n                filename = \"{}_conversations\".format(self.filename)\n                self.dump_file(filename, self.conversations)\n            else:\n                self.dump_singlefile()\n\n    def update_user_data(self, user_id, data):\n        \"\"\"Will update the user_data (if changed) and depending on :attr:`on_flush` save the\n        pickle file.\n\n        Args:\n            user_id (:obj:`int`): The user the data might have been changed for.\n            data (:obj:`dict`): The :attr:`telegram.ext.dispatcher.user_data` [user_id].\n        \"\"\"\n        if self.user_data.get(user_id) == data:\n            return\n        self.user_data[user_id] = data\n        if not self.on_flush:\n            if not self.single_file:\n                filename = \"{}_user_data\".format(self.filename)\n                self.dump_file(filename, self.user_data)\n            else:\n                self.dump_singlefile()\n\n    def update_chat_data(self, chat_id, data):\n        \"\"\"Will update the chat_data (if changed) and depending on :attr:`on_flush` save the\n        pickle file.\n\n        Args:\n            chat_id (:obj:`int`): The chat the data might have been changed for.\n            data (:obj:`dict`): The :attr:`telegram.ext.dispatcher.chat_data` [chat_id].\n        \"\"\"\n        if self.chat_data.get(chat_id) == data:\n            return\n        self.chat_data[chat_id] = data\n        if not self.on_flush:\n            if not self.single_file:\n                filename = \"{}_chat_data\".format(self.filename)\n                self.dump_file(filename, self.chat_data)\n            else:\n                self.dump_singlefile()\n\n    def flush(self):\n        \"\"\" Will save all data in memory to pickle file(s).\n        \"\"\"\n        if self.single_file:\n            if self.user_data or self.chat_data or self.conversations:\n                self.dump_singlefile()\n        else:\n            if self.user_data:\n                self.dump_file(\"{}_user_data\".format(self.filename), self.user_data)\n            if self.chat_data:\n                self.dump_file(\"{}_chat_data\".format(self.filename), self.chat_data)\n            if self.conversations:\n                self.dump_file(\"{}_conversations\".format(self.filename), self.conversations)\n", "path": "telegram/ext/picklepersistence.py"}]}