We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Raise exception with helpful error on Client pickle.
Based on the discussion in #3191, raise an exception with a helpful error stating that `Client` classes are not pickleable.

Note to self: We probably want this in GAX also.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `core/google/cloud/client.py`
Content:
```
1 # Copyright 2015 Google Inc.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #     http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 
15 """Base classes for client used to interact with Google Cloud APIs."""
16 
17 import google.auth.credentials
18 from google.oauth2 import service_account
19 import google_auth_httplib2
20 import six
21 
22 from google.cloud._helpers import _determine_default_project
23 from google.cloud.credentials import get_credentials
24 
25 
26 _GOOGLE_AUTH_CREDENTIALS_HELP = (
27     'This library only supports credentials from google-auth-library-python. '
28     'See https://google-cloud-python.readthedocs.io/en/latest/'
29     'google-cloud-auth.html for help on authentication with this library.'
30 )
31 
32 
33 class _ClientFactoryMixin(object):
34     """Mixin to allow factories that create credentials.
35 
36     .. note::
37 
38         This class is virtual.
39     """
40 
41     @classmethod
42     def from_service_account_json(cls, json_credentials_path, *args, **kwargs):
43         """Factory to retrieve JSON credentials while creating client.
44 
45         :type json_credentials_path: str
46         :param json_credentials_path: The path to a private key file (this file
47                                       was given to you when you created the
48                                       service account). This file must contain
49                                       a JSON object with a private key and
50                                       other credentials information (downloaded
51                                       from the Google APIs console).
52 
53         :type args: tuple
54         :param args: Remaining positional arguments to pass to constructor.
55 
56         :type kwargs: dict
57         :param kwargs: Remaining keyword arguments to pass to constructor.
58 
59         :rtype: :class:`google.cloud.pubsub.client.Client`
60         :returns: The client created with the retrieved JSON credentials.
61         :raises: :class:`TypeError` if there is a conflict with the kwargs
62                  and the credentials created by the factory.
63         """
64         if 'credentials' in kwargs:
65             raise TypeError('credentials must not be in keyword arguments')
66         credentials = service_account.Credentials.from_service_account_file(
67             json_credentials_path)
68         kwargs['credentials'] = credentials
69         return cls(*args, **kwargs)
70 
71 
72 class Client(_ClientFactoryMixin):
73     """Client to bundle configuration needed for API requests.
74 
75     Stores ``credentials`` and ``http`` object so that subclasses
76     can pass them along to a connection class.
77 
78     If no value is passed in for ``http``, a :class:`httplib2.Http` object
79     will be created and authorized with the ``credentials``. If not, the
80     ``credentials`` and ``http`` need not be related.
81 
82     Callers and subclasses may seek to use the private key from
83     ``credentials`` to sign data.
84 
85     A custom (non-``httplib2``) HTTP object must have a ``request`` method
86     which accepts the following arguments:
87 
88     * ``uri``
89     * ``method``
90     * ``body``
91     * ``headers``
92 
93     In addition, ``redirections`` and ``connection_type`` may be used.
94 
95     A custom ``http`` object will also need to be able to add a bearer token
96     to API requests and handle token refresh on 401 errors.
97 
98     :type credentials: :class:`~google.auth.credentials.Credentials`
99     :param credentials: (Optional) The OAuth2 Credentials to use for this
100                         client. If not passed (and if no ``http`` object is
101                         passed), falls back to the default inferred from the
102                         environment.
103 
104     :type http: :class:`~httplib2.Http`
105     :param http: (Optional) HTTP object to make requests. Can be any object
106                  that defines ``request()`` with the same interface as
107                  :meth:`~httplib2.Http.request`. If not passed, an
108                  ``http`` object is created that is bound to the
109                  ``credentials`` for the current object.
110     """
111 
112     SCOPE = None
113     """The scopes required for authenticating with a service.
114 
115     Needs to be set by subclasses.
116     """
117 
118     def __init__(self, credentials=None, http=None):
119         if (credentials is not None and
120                 not isinstance(
121                     credentials, google.auth.credentials.Credentials)):
122             raise ValueError(_GOOGLE_AUTH_CREDENTIALS_HELP)
123         if credentials is None and http is None:
124             credentials = get_credentials()
125         self._credentials = google.auth.credentials.with_scopes_if_required(
126             credentials, self.SCOPE)
127         self._http_internal = http
128 
129     @property
130     def _http(self):
131         """Getter for object used for HTTP transport.
132 
133         :rtype: :class:`~httplib2.Http`
134         :returns: An HTTP object.
135         """
136         if self._http_internal is None:
137             self._http_internal = google_auth_httplib2.AuthorizedHttp(
138                 self._credentials)
139         return self._http_internal
140 
141 
142 class _ClientProjectMixin(object):
143     """Mixin to allow setting the project on the client.
144 
145     :type project: str
146     :param project: the project which the client acts on behalf of. If not
147                     passed falls back to the default inferred from the
148                     environment.
149 
150     :raises: :class:`EnvironmentError` if the project is neither passed in nor
151              set in the environment. :class:`ValueError` if the project value
152              is invalid.
153     """
154 
155     def __init__(self, project=None):
156         project = self._determine_default(project)
157         if project is None:
158             raise EnvironmentError('Project was not passed and could not be '
159                                    'determined from the environment.')
160         if isinstance(project, six.binary_type):
161             project = project.decode('utf-8')
162         if not isinstance(project, six.string_types):
163             raise ValueError('Project must be a string.')
164         self.project = project
165 
166     @staticmethod
167     def _determine_default(project):
168         """Helper:  use default project detection."""
169         return _determine_default_project(project)
170 
171 
172 class ClientWithProject(Client, _ClientProjectMixin):
173     """Client that also stores a project.
174 
175     :type project: str
176     :param project: the project which the client acts on behalf of. If not
177                     passed falls back to the default inferred from the
178                     environment.
179 
180     :type credentials: :class:`~google.auth.credentials.Credentials`
181     :param credentials: (Optional) The OAuth2 Credentials to use for this
182                         client. If not passed (and if no ``http`` object is
183                         passed), falls back to the default inferred from the
184                         environment.
185 
186     :type http: :class:`~httplib2.Http`
187     :param http: (Optional) HTTP object to make requests. Can be any object
188                  that defines ``request()`` with the same interface as
189                  :meth:`~httplib2.Http.request`. If not passed, an
190                  ``http`` object is created that is bound to the
191                  ``credentials`` for the current object.
192 
193     :raises: :class:`ValueError` if the project is neither passed in nor
194              set in the environment.
195     """
196 
197     def __init__(self, project=None, credentials=None, http=None):
198         _ClientProjectMixin.__init__(self, project=project)
199         Client.__init__(self, credentials=credentials, http=http)
200
```
--- 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/core/google/cloud/client.py b/core/google/cloud/client.py
--- a/core/google/cloud/client.py
+++ b/core/google/cloud/client.py
@@ -14,6 +14,8 @@
 
 """Base classes for client used to interact with Google Cloud APIs."""
 
+from pickle import PicklingError
+
 import google.auth.credentials
 from google.oauth2 import service_account
 import google_auth_httplib2
@@ -126,6 +128,13 @@
             credentials, self.SCOPE)
         self._http_internal = http
 
+    def __getstate__(self):
+        """Explicitly state that clients are not pickleable."""
+        raise PicklingError('\n'.join([
+            'Pickling client objects is explicitly not supported.',
+            'Clients have non-trivial state that is local and unpickleable.',
+        ]))
+
     @property
     def _http(self):
         """Getter for object used for HTTP transport.

{"golden_diff": "diff --git a/core/google/cloud/client.py b/core/google/cloud/client.py\n--- a/core/google/cloud/client.py\n+++ b/core/google/cloud/client.py\n@@ -14,6 +14,8 @@\n \n \"\"\"Base classes for client used to interact with Google Cloud APIs.\"\"\"\n \n+from pickle import PicklingError\n+\n import google.auth.credentials\n from google.oauth2 import service_account\n import google_auth_httplib2\n@@ -126,6 +128,13 @@\n             credentials, self.SCOPE)\n         self._http_internal = http\n \n+    def __getstate__(self):\n+        \"\"\"Explicitly state that clients are not pickleable.\"\"\"\n+        raise PicklingError('\\n'.join([\n+            'Pickling client objects is explicitly not supported.',\n+            'Clients have non-trivial state that is local and unpickleable.',\n+        ]))\n+\n     @property\n     def _http(self):\n         \"\"\"Getter for object used for HTTP transport.\n", "issue": "Raise exception with helpful error on Client pickle.\nBased on the discussion in #3191, raise an exception with a helpful error stating that `Client` classes are not pickleable.\r\n\r\nNote to self: We probably want this in GAX also.\n", "before_files": [{"content": "# Copyright 2015 Google Inc.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#     http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\n\"\"\"Base classes for client used to interact with Google Cloud APIs.\"\"\"\n\nimport google.auth.credentials\nfrom google.oauth2 import service_account\nimport google_auth_httplib2\nimport six\n\nfrom google.cloud._helpers import _determine_default_project\nfrom google.cloud.credentials import get_credentials\n\n\n_GOOGLE_AUTH_CREDENTIALS_HELP = (\n    'This library only supports credentials from google-auth-library-python. '\n    'See https://google-cloud-python.readthedocs.io/en/latest/'\n    'google-cloud-auth.html for help on authentication with this library.'\n)\n\n\nclass _ClientFactoryMixin(object):\n    \"\"\"Mixin to allow factories that create credentials.\n\n    .. note::\n\n        This class is virtual.\n    \"\"\"\n\n    @classmethod\n    def from_service_account_json(cls, json_credentials_path, *args, **kwargs):\n        \"\"\"Factory to retrieve JSON credentials while creating client.\n\n        :type json_credentials_path: str\n        :param json_credentials_path: The path to a private key file (this file\n                                      was given to you when you created the\n                                      service account). This file must contain\n                                      a JSON object with a private key and\n                                      other credentials information (downloaded\n                                      from the Google APIs console).\n\n        :type args: tuple\n        :param args: Remaining positional arguments to pass to constructor.\n\n        :type kwargs: dict\n        :param kwargs: Remaining keyword arguments to pass to constructor.\n\n        :rtype: :class:`google.cloud.pubsub.client.Client`\n        :returns: The client created with the retrieved JSON credentials.\n        :raises: :class:`TypeError` if there is a conflict with the kwargs\n                 and the credentials created by the factory.\n        \"\"\"\n        if 'credentials' in kwargs:\n            raise TypeError('credentials must not be in keyword arguments')\n        credentials = service_account.Credentials.from_service_account_file(\n            json_credentials_path)\n        kwargs['credentials'] = credentials\n        return cls(*args, **kwargs)\n\n\nclass Client(_ClientFactoryMixin):\n    \"\"\"Client to bundle configuration needed for API requests.\n\n    Stores ``credentials`` and ``http`` object so that subclasses\n    can pass them along to a connection class.\n\n    If no value is passed in for ``http``, a :class:`httplib2.Http` object\n    will be created and authorized with the ``credentials``. If not, the\n    ``credentials`` and ``http`` need not be related.\n\n    Callers and subclasses may seek to use the private key from\n    ``credentials`` to sign data.\n\n    A custom (non-``httplib2``) HTTP object must have a ``request`` method\n    which accepts the following arguments:\n\n    * ``uri``\n    * ``method``\n    * ``body``\n    * ``headers``\n\n    In addition, ``redirections`` and ``connection_type`` may be used.\n\n    A custom ``http`` object will also need to be able to add a bearer token\n    to API requests and handle token refresh on 401 errors.\n\n    :type credentials: :class:`~google.auth.credentials.Credentials`\n    :param credentials: (Optional) The OAuth2 Credentials to use for this\n                        client. If not passed (and if no ``http`` object is\n                        passed), falls back to the default inferred from the\n                        environment.\n\n    :type http: :class:`~httplib2.Http`\n    :param http: (Optional) HTTP object to make requests. Can be any object\n                 that defines ``request()`` with the same interface as\n                 :meth:`~httplib2.Http.request`. If not passed, an\n                 ``http`` object is created that is bound to the\n                 ``credentials`` for the current object.\n    \"\"\"\n\n    SCOPE = None\n    \"\"\"The scopes required for authenticating with a service.\n\n    Needs to be set by subclasses.\n    \"\"\"\n\n    def __init__(self, credentials=None, http=None):\n        if (credentials is not None and\n                not isinstance(\n                    credentials, google.auth.credentials.Credentials)):\n            raise ValueError(_GOOGLE_AUTH_CREDENTIALS_HELP)\n        if credentials is None and http is None:\n            credentials = get_credentials()\n        self._credentials = google.auth.credentials.with_scopes_if_required(\n            credentials, self.SCOPE)\n        self._http_internal = http\n\n    @property\n    def _http(self):\n        \"\"\"Getter for object used for HTTP transport.\n\n        :rtype: :class:`~httplib2.Http`\n        :returns: An HTTP object.\n        \"\"\"\n        if self._http_internal is None:\n            self._http_internal = google_auth_httplib2.AuthorizedHttp(\n                self._credentials)\n        return self._http_internal\n\n\nclass _ClientProjectMixin(object):\n    \"\"\"Mixin to allow setting the project on the client.\n\n    :type project: str\n    :param project: the project which the client acts on behalf of. If not\n                    passed falls back to the default inferred from the\n                    environment.\n\n    :raises: :class:`EnvironmentError` if the project is neither passed in nor\n             set in the environment. :class:`ValueError` if the project value\n             is invalid.\n    \"\"\"\n\n    def __init__(self, project=None):\n        project = self._determine_default(project)\n        if project is None:\n            raise EnvironmentError('Project was not passed and could not be '\n                                   'determined from the environment.')\n        if isinstance(project, six.binary_type):\n            project = project.decode('utf-8')\n        if not isinstance(project, six.string_types):\n            raise ValueError('Project must be a string.')\n        self.project = project\n\n    @staticmethod\n    def _determine_default(project):\n        \"\"\"Helper:  use default project detection.\"\"\"\n        return _determine_default_project(project)\n\n\nclass ClientWithProject(Client, _ClientProjectMixin):\n    \"\"\"Client that also stores a project.\n\n    :type project: str\n    :param project: the project which the client acts on behalf of. If not\n                    passed falls back to the default inferred from the\n                    environment.\n\n    :type credentials: :class:`~google.auth.credentials.Credentials`\n    :param credentials: (Optional) The OAuth2 Credentials to use for this\n                        client. If not passed (and if no ``http`` object is\n                        passed), falls back to the default inferred from the\n                        environment.\n\n    :type http: :class:`~httplib2.Http`\n    :param http: (Optional) HTTP object to make requests. Can be any object\n                 that defines ``request()`` with the same interface as\n                 :meth:`~httplib2.Http.request`. If not passed, an\n                 ``http`` object is created that is bound to the\n                 ``credentials`` for the current object.\n\n    :raises: :class:`ValueError` if the project is neither passed in nor\n             set in the environment.\n    \"\"\"\n\n    def __init__(self, project=None, credentials=None, http=None):\n        _ClientProjectMixin.__init__(self, project=project)\n        Client.__init__(self, credentials=credentials, http=http)\n", "path": "core/google/cloud/client.py"}], "after_files": [{"content": "# Copyright 2015 Google Inc.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#     http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\n\"\"\"Base classes for client used to interact with Google Cloud APIs.\"\"\"\n\nfrom pickle import PicklingError\n\nimport google.auth.credentials\nfrom google.oauth2 import service_account\nimport google_auth_httplib2\nimport six\n\nfrom google.cloud._helpers import _determine_default_project\nfrom google.cloud.credentials import get_credentials\n\n\n_GOOGLE_AUTH_CREDENTIALS_HELP = (\n    'This library only supports credentials from google-auth-library-python. '\n    'See https://google-cloud-python.readthedocs.io/en/latest/'\n    'google-cloud-auth.html for help on authentication with this library.'\n)\n\n\nclass _ClientFactoryMixin(object):\n    \"\"\"Mixin to allow factories that create credentials.\n\n    .. note::\n\n        This class is virtual.\n    \"\"\"\n\n    @classmethod\n    def from_service_account_json(cls, json_credentials_path, *args, **kwargs):\n        \"\"\"Factory to retrieve JSON credentials while creating client.\n\n        :type json_credentials_path: str\n        :param json_credentials_path: The path to a private key file (this file\n                                      was given to you when you created the\n                                      service account). This file must contain\n                                      a JSON object with a private key and\n                                      other credentials information (downloaded\n                                      from the Google APIs console).\n\n        :type args: tuple\n        :param args: Remaining positional arguments to pass to constructor.\n\n        :type kwargs: dict\n        :param kwargs: Remaining keyword arguments to pass to constructor.\n\n        :rtype: :class:`google.cloud.pubsub.client.Client`\n        :returns: The client created with the retrieved JSON credentials.\n        :raises: :class:`TypeError` if there is a conflict with the kwargs\n                 and the credentials created by the factory.\n        \"\"\"\n        if 'credentials' in kwargs:\n            raise TypeError('credentials must not be in keyword arguments')\n        credentials = service_account.Credentials.from_service_account_file(\n            json_credentials_path)\n        kwargs['credentials'] = credentials\n        return cls(*args, **kwargs)\n\n\nclass Client(_ClientFactoryMixin):\n    \"\"\"Client to bundle configuration needed for API requests.\n\n    Stores ``credentials`` and ``http`` object so that subclasses\n    can pass them along to a connection class.\n\n    If no value is passed in for ``http``, a :class:`httplib2.Http` object\n    will be created and authorized with the ``credentials``. If not, the\n    ``credentials`` and ``http`` need not be related.\n\n    Callers and subclasses may seek to use the private key from\n    ``credentials`` to sign data.\n\n    A custom (non-``httplib2``) HTTP object must have a ``request`` method\n    which accepts the following arguments:\n\n    * ``uri``\n    * ``method``\n    * ``body``\n    * ``headers``\n\n    In addition, ``redirections`` and ``connection_type`` may be used.\n\n    A custom ``http`` object will also need to be able to add a bearer token\n    to API requests and handle token refresh on 401 errors.\n\n    :type credentials: :class:`~google.auth.credentials.Credentials`\n    :param credentials: (Optional) The OAuth2 Credentials to use for this\n                        client. If not passed (and if no ``http`` object is\n                        passed), falls back to the default inferred from the\n                        environment.\n\n    :type http: :class:`~httplib2.Http`\n    :param http: (Optional) HTTP object to make requests. Can be any object\n                 that defines ``request()`` with the same interface as\n                 :meth:`~httplib2.Http.request`. If not passed, an\n                 ``http`` object is created that is bound to the\n                 ``credentials`` for the current object.\n    \"\"\"\n\n    SCOPE = None\n    \"\"\"The scopes required for authenticating with a service.\n\n    Needs to be set by subclasses.\n    \"\"\"\n\n    def __init__(self, credentials=None, http=None):\n        if (credentials is not None and\n                not isinstance(\n                    credentials, google.auth.credentials.Credentials)):\n            raise ValueError(_GOOGLE_AUTH_CREDENTIALS_HELP)\n        if credentials is None and http is None:\n            credentials = get_credentials()\n        self._credentials = google.auth.credentials.with_scopes_if_required(\n            credentials, self.SCOPE)\n        self._http_internal = http\n\n    def __getstate__(self):\n        \"\"\"Explicitly state that clients are not pickleable.\"\"\"\n        raise PicklingError('\\n'.join([\n            'Pickling client objects is explicitly not supported.',\n            'Clients have non-trivial state that is local and unpickleable.',\n        ]))\n\n    @property\n    def _http(self):\n        \"\"\"Getter for object used for HTTP transport.\n\n        :rtype: :class:`~httplib2.Http`\n        :returns: An HTTP object.\n        \"\"\"\n        if self._http_internal is None:\n            self._http_internal = google_auth_httplib2.AuthorizedHttp(\n                self._credentials)\n        return self._http_internal\n\n\nclass _ClientProjectMixin(object):\n    \"\"\"Mixin to allow setting the project on the client.\n\n    :type project: str\n    :param project: the project which the client acts on behalf of. If not\n                    passed falls back to the default inferred from the\n                    environment.\n\n    :raises: :class:`EnvironmentError` if the project is neither passed in nor\n             set in the environment. :class:`ValueError` if the project value\n             is invalid.\n    \"\"\"\n\n    def __init__(self, project=None):\n        project = self._determine_default(project)\n        if project is None:\n            raise EnvironmentError('Project was not passed and could not be '\n                                   'determined from the environment.')\n        if isinstance(project, six.binary_type):\n            project = project.decode('utf-8')\n        if not isinstance(project, six.string_types):\n            raise ValueError('Project must be a string.')\n        self.project = project\n\n    @staticmethod\n    def _determine_default(project):\n        \"\"\"Helper:  use default project detection.\"\"\"\n        return _determine_default_project(project)\n\n\nclass ClientWithProject(Client, _ClientProjectMixin):\n    \"\"\"Client that also stores a project.\n\n    :type project: str\n    :param project: the project which the client acts on behalf of. If not\n                    passed falls back to the default inferred from the\n                    environment.\n\n    :type credentials: :class:`~google.auth.credentials.Credentials`\n    :param credentials: (Optional) The OAuth2 Credentials to use for this\n                        client. If not passed (and if no ``http`` object is\n                        passed), falls back to the default inferred from the\n                        environment.\n\n    :type http: :class:`~httplib2.Http`\n    :param http: (Optional) HTTP object to make requests. Can be any object\n                 that defines ``request()`` with the same interface as\n                 :meth:`~httplib2.Http.request`. If not passed, an\n                 ``http`` object is created that is bound to the\n                 ``credentials`` for the current object.\n\n    :raises: :class:`ValueError` if the project is neither passed in nor\n             set in the environment.\n    \"\"\"\n\n    def __init__(self, project=None, credentials=None, http=None):\n        _ClientProjectMixin.__init__(self, project=project)\n        Client.__init__(self, credentials=credentials, http=http)\n", "path": "core/google/cloud/client.py"}]}