# Path: gslib/storage_url.py
# def StorageUrlFromString(url_str):
#   """Static factory function for creating a StorageUrl from a string."""
# 
#   scheme = GetSchemeFromUrlString(url_str)
# 
#   if not IsKnownUrlScheme(scheme):
#     raise InvalidUrlError('Unrecognized scheme "%s"' % scheme)
#   if scheme == 'file':
#     path = _GetPathFromUrlString(url_str)
#     is_stream = (path == '-')
#     is_fifo = False
#     try:
#       is_fifo = stat.S_ISFIFO(os.stat(path).st_mode)
#     except OSError:
#       pass
#     return _FileUrl(url_str, is_stream=is_stream, is_fifo=is_fifo)
#   return _CloudUrl(url_str)
# 
# Path: gslib/exception.py
# class InvalidUrlError(Exception):
#   """Exception raised when URL is invalid."""
# 
#   def __init__(self, message):
#     Exception.__init__(self, message)
#     self.message = message
# 
#   def __repr__(self):
#     return str(self)
# 
#   def __str__(self):
#     return 'InvalidUrlError: %s' % self.message


import six
import sys
import gslib
from gslib.utils import system_util
from gslib.storage_url import StorageUrlFromString
from gslib.exception import InvalidUrlError
# limitations under the License.
"""Contains helper for appending user agent information."""



def GetUserAgent(args, metrics_off=True):
  """Using the command arguments return a suffix for the UserAgent string.

  Args:
    args: str[], parsed set of arguments entered in the CLI.
    metrics_off: boolean, whether the MetricsCollector is disabled.

  Returns:
    str, A string value that can be appended to an existing UserAgent.
  """
  user_agent = ' gsutil/%s' % gslib.VERSION
  user_agent += ' (%s)' % sys.platform
  user_agent += ' analytics/%s' % ('disabled' if metrics_off else 'enabled')
  user_agent += ' interactive/%s' % system_util.IsRunningInteractively()

  if len(args) > 0:
    user_agent += ' command/%s' % args[0]

    if len(args) > 2:
      if args[0] in ['cp', 'mv', 'rsync']:
        # Any cp, mv or rsync commands that use daisy chain mode should be noted
        # as that represents a unique use case that may be better served by the
        # storage transfer service.
        try:
          src = StorageUrlFromString(six.ensure_text(args[-2]))

# Path: gslib/storage_url.py
# def StorageUrlFromString(url_str):
#   """Static factory function for creating a StorageUrl from a string."""
# 
#   scheme = GetSchemeFromUrlString(url_str)
# 
#   if not IsKnownUrlScheme(scheme):
#     raise InvalidUrlError('Unrecognized scheme "%s"' % scheme)
#   if scheme == 'file':
#     path = _GetPathFromUrlString(url_str)
#     is_stream = (path == '-')
#     is_fifo = False
#     try:
#       is_fifo = stat.S_ISFIFO(os.stat(path).st_mode)
#     except OSError:
#       pass
#     return _FileUrl(url_str, is_stream=is_stream, is_fifo=is_fifo)
#   return _CloudUrl(url_str)
# 
# Path: gslib/exception.py
# class InvalidUrlError(Exception):
#   """Exception raised when URL is invalid."""
# 
#   def __init__(self, message):
#     Exception.__init__(self, message)
#     self.message = message
# 
#   def __repr__(self):
#     return str(self)
# 
#   def __str__(self):
#     return 'InvalidUrlError: %s' % self.message


# Path: gslib/utils/user_agent_helper.py
import six
import sys
import gslib
from gslib.utils import system_util
from gslib.storage_url import StorageUrlFromString
from gslib.exception import InvalidUrlError

# limitations under the License.
"""Contains helper for appending user agent information."""



def GetUserAgent(args, metrics_off=True):
  """Using the command arguments return a suffix for the UserAgent string.

  Args:
    args: str[], parsed set of arguments entered in the CLI.
    metrics_off: boolean, whether the MetricsCollector is disabled.

  Returns:
    str, A string value that can be appended to an existing UserAgent.
  """
  user_agent = ' gsutil/%s' % gslib.VERSION
  user_agent += ' (%s)' % sys.platform
  user_agent += ' analytics/%s' % ('disabled' if metrics_off else 'enabled')
  user_agent += ' interactive/%s' % system_util.IsRunningInteractively()

  if len(args) > 0:
    user_agent += ' command/%s' % args[0]

    if len(args) > 2:
      if args[0] in ['cp', 'mv', 'rsync']:
        # Any cp, mv or rsync commands that use daisy chain mode should be noted
        # as that represents a unique use case that may be better served by the
        # storage transfer service.
        try:
          src = StorageUrlFromString(six.ensure_text(args[-2]))

          dst = StorageUrlFromString(six.ensure_text(args[-1]))