Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions sdks/python/apache_beam/io/filesystemio.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
20 changes: 0 additions & 20 deletions sdks/python/apache_beam/io/gcp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 3 additions & 1 deletion sdks/python/apache_beam/io/gcp/gcsfilesystem_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading