
    0                         S r SSKJr  SSKJr  SSKJr  SSKrSSKrSSKJr  SSK	J
r
  SSKJr  S	rS
rSrSrSr " S S\
R$                  5      r " S S\5      r " S S\5      r " S S\5      rS rS rS rg)z(Utilities for gcloud ml vision commands.    )absolute_import)division)unicode_literalsN)apis)
exceptions)filesvisionv1z^(https{,1}?|gs)://zgs://([^/]+)/(.+)zgs://([^/]+)(/.*)*c                       \ rS rSrSrSrg)Error$   z$Error for gcloud ml vision commands. N__name__
__module____qualname____firstlineno____doc____static_attributes__r       0lib/googlecloudsdk/command_lib/ml/vision/util.pyr   r   $   s    ,r   r   c                       \ rS rSrSrSrg)ImagePathError(   z/Error if an image path is improperly formatted.r   Nr   r   r   r   r   r   (   s    7r   r   c                       \ rS rSrSrSrg)GcsSourceError,   z2Error if a gcsSource path is improperly formatted.r   Nr   r   r   r   r   r   ,   s    :r   r   c                       \ rS rSrSrSrg)GcsDestinationError0   z7Error if a gcsDestination path is improperly formatted.r   Nr   r   r   r   r   r   0   s    ?r   r   c                 d   [         R                  " [        [        5      nUR	                  5       n[
        R                  R                  U 5      (       a  [        R                  " U 5      Ul
        U$ [        R                  " [        U 5      (       a  UR                  U S9Ul        U$ [!        S5      e)a8  Builds an Image message from a path.

Args:
  path: the path arg given to the command.

Raises:
  ImagePathError: if the image path does not exist and does not seem to be
      a remote URI.

Returns:
  vision_v1_messages.Image: an image message containing information for the
      API on the image to analyze.
)imageUria  The image path does not exist locally or is not properly formatted. A URI for a remote image must be a Google Cloud Storage image URI, which must be in the form `gs://bucket_name/object_name`, or a publicly accessible image HTTP/HTTPS URL. Please double-check your input and try again.)r   GetMessagesModule
VISION_APIVISION_API_VERSIONImageospathisfiler   ReadBinaryFileContentscontentrematchIMAGE_URI_FORMATImageSourcesourcer   )r(   messagesimages      r   GetImageFromPathr3   4   s     ##J0BC(
..
%WW^^D006EM 
, 
xx $'''''6EL 
, 	   r   c                     [         R                  " [        [        5      nUR	                  5       n[
        R                  " [        U 5      (       a  Xl        U$ [        S5      e)a  Validate a Google Cloud Storage location to read the PDF/TIFF file from.

Args:
  input_file: the input file path arg given to the command.

Raises:
  GcsSourceError: if the file is not a Google Cloud Storage object.

Returns:
  vision_v1_messages.GcsSource: Google Cloud Storage URI for the input file.
  This must only be a Google Cloud Storage object.
  Wildcards are not currently supported.
zThe URI for the input file must be a Google Cloud Storage object, which must be in the form `gs://bucket_name/object_name.Please double-check your input and try again.)
r   r#   r$   r%   	GcsSourcer,   r-   FILE_URI_FORMATurir   )
input_filer1   
gcs_sources      r   GetGcsSourceFromPathr:   S   sW     ##J0BC(!!#*XXoz**N 
	 	89 9r   c                     [         R                  " [        [        5      nUR	                  5       n[
        R                  " [        U 5      (       a  Xl        U$ [        S5      e)a  Validate a Google Cloud Storage location to write the output to.

Args:
  path: the path arg given to the command.

Raises:
  GcsDestinationError: if the file is not a Google Cloud Storage object.

Returns:
  vision_v1_messages.GcsDestination:Google Cloud Storage URI prefix
  where the results will be stored.
  This must only be a Google Cloud Storage object.
  Wildcards are not currently supported.
zThe URI for the input file must be a Google Cloud Storage object, which must be in the File prefix format `gs://bucket_name/here/file_name_prefix.or directory prefix format `gs://bucket_name/some/location/. Please double-check your input and try again.)
r   r#   r$   r%   GcsDestinationr,   r-   FILE_PREFIXr7   r   )r(   r1   gcs_destinations      r   GetGcsDestinationFromPathr?   n   sX     ##J0BC(++-/XXk4   
 	89 9r   )r   
__future__r   r   r   r'   r,   googlecloudsdk.api_lib.utilr   googlecloudsdk.corer   googlecloudsdk.core.utilr   r$   r%   r.   r6   r=   r   r   r   r   r3   r:   r?   r   r   r   <module>rD      s     / &  ' 	 	 , * *
 ) &#-J -8U 8;U ;@% @>6r   