def __init__(self, file_path_prefix,
               append_trailing_newlines=True,
               file_name_suffix='',
               num_shards=0,
               shard_name_template=None,
               validate=True,
               coder=coders.ToStringCoder()):
    """Initialize a TextSink.

    Args:
      file_path_prefix: The file path to write to. The files written will begin
        with this prefix, followed by a shard identifier (see num_shards), and
        end in a common extension, if given by file_name_suffix. In most cases,
        only this argument is specified and num_shards, shard_name_template, and
        file_name_suffix use default values.
      append_trailing_newlines: indicate whether this sink should write an
          additional newline char after writing each element.
      file_name_suffix: Suffix for the files written.
      num_shards: The number of files (shards) used for output. If not set, the
        service will decide on the optimal number of shards.
        Constraining the number of shards is likely to reduce
        the performance of a pipeline.  Setting this value is not recommended
        unless you require a specific number of output files.
      shard_name_template: A template string containing placeholders for
        the shard number and shard count. Currently only '' and
        '-SSSSS-of-NNNNN' are patterns accepted by the service.
        When constructing a filename for a particular shard number, the
        upper-case letters 'S' and 'N' are replaced with the 0-padded shard
        number and shard count respectively.  This argument can be '' in which
        case it behaves as if num_shards was set to 1 and only one file will be
        generated. The default pattern used is '-SSSSS-of-NNNNN'.
      validate: Enable path validation on pipeline creation.
      coder: Coder used to encode each line.

    Raises:
      TypeError: if file_path is not a string.
      ValueError: if shard_name_template is not of expected format.
    """
    if not isinstance(file_path_prefix, basestring):
      raise TypeError(
          '%s: file_path_prefix must be a string; got %r instead' %
          (self.__class__.__name__, file_path_prefix))
    if not isinstance(file_name_suffix, basestring):
      raise TypeError(
          '%s: file_name_suffix must be a string; got %r instead' %
          (self.__class__.__name__, file_name_suffix))

    # We initialize a file_path attribute containing just the prefix part for
    # local runner environment. For now, sharding is not supported in the local
    # runner and sharding options (template, num, suffix) are ignored.
    # The attribute is also used in the worker environment when we just write
    # to a specific file.
    # TODO(silviuc): Add support for file sharding in the local runner.
    self.file_path = file_path_prefix
    self.append_trailing_newlines = append_trailing_newlines
    self.coder = coder

    self.is_gcs_sink = self.file_path.startswith('gs://')

    self.file_name_prefix = file_path_prefix
    self.file_name_suffix = file_name_suffix
    self.num_shards = num_shards
    # TODO(silviuc): Update this when the service supports more patterns.
    if shard_name_template not in (None, '', '-SSSSS-of-NNNNN'):
      raise ValueError(
          'The shard_name_template argument must be an empty string or the '
          'pattern -SSSSS-of-NNNNN instead of %s' % shard_name_template)
    self.shard_name_template = (
        shard_name_template if shard_name_template is not None
        else '-SSSSS-of-NNNNN')
    # TODO(silviuc): Implement sink validation.
    self.validate = validate
dataset/ETHPy150Open GoogleCloudPlatform/DataflowPythonSDK/google/cloud/dataflow/io/fileio.py/TextFileSink.__init__/original