diff --git a/sdks/python/apache_beam/io/filesystemio.py b/sdks/python/apache_beam/io/filesystemio.py index 571d1f2d2699..daa02e586012 100644 --- a/sdks/python/apache_beam/io/filesystemio.py +++ b/sdks/python/apache_beam/io/filesystemio.py @@ -284,9 +284,8 @@ def tell(self): return self.position def seek(self, offset, whence=os.SEEK_SET): - # The apitools library used by the gcsio.Uploader class insists on seeking - # to the end of a stream to do a check before completing an upload, so we - # must have this no-op method here in that case. + # Certain upload stream implementations seek to the end of a stream to check + # length before completing an upload, so we support a no-op seek(0, SEEK_END). if whence == os.SEEK_END and offset == 0: return elif whence == os.SEEK_SET: diff --git a/sdks/python/apache_beam/io/gcp/__init__.py b/sdks/python/apache_beam/io/gcp/__init__.py index 861a39f5c75d..cce3acad34a4 100644 --- a/sdks/python/apache_beam/io/gcp/__init__.py +++ b/sdks/python/apache_beam/io/gcp/__init__.py @@ -14,23 +14,3 @@ # See the License for the specific language governing permissions and # limitations under the License. # - -# Important: the MIME library in the Python 3.x standard library used by -# apitools causes uploads containing '\r\n' to be corrupted, unless we -# patch the BytesGenerator class to write contents verbatim. -try: - # pylint: disable=wrong-import-order, wrong-import-position - # pylint: disable=ungrouped-imports - import email.generator as email_generator - - from apitools.base.py import transfer - - class _WrapperNamespace(object): - class BytesGenerator(email_generator.BytesGenerator): - def _write_lines(self, lines): - self.write(lines) - - transfer.email_generator = _WrapperNamespace -except ImportError: - # We may not have the GCP dependencies installed, so we pass in this case. - pass diff --git a/sdks/python/apache_beam/io/gcp/gcsfilesystem_test.py b/sdks/python/apache_beam/io/gcp/gcsfilesystem_test.py index 08fdd6302887..0ab8c4c48f8a 100644 --- a/sdks/python/apache_beam/io/gcp/gcsfilesystem_test.py +++ b/sdks/python/apache_beam/io/gcp/gcsfilesystem_test.py @@ -29,9 +29,11 @@ from apache_beam.io.filesystem import FileMetadata from apache_beam.options.pipeline_options import PipelineOptions -# Protect against environments where apitools library is not available. +# Protect against environments where GCP storage library is not available. # pylint: disable=wrong-import-order, wrong-import-position try: + from google.cloud import storage # pylint: disable=unused-import + from apache_beam.io.gcp import gcsfilesystem except ImportError: gcsfilesystem = None # type: ignore