
    ܖi	                     f    d Z dgZddlmZ ddlmZ ddlmZ ddlm	Z	m
Z
 ddlmZmZ  G d	 d      Zy
)zComponent related buildersComponentBuilder    )sha1)exists)Optional   )HashAlgorithmHashType)	ComponentComponentTypec                   @    e Zd Zdedee   defdZededefd       Zy)r   absolute_file_pathnamereturnc          
          t        |      st        d|d      t        t        j                  |xs |t        t        j                  | j                  |            g      S )a  
        Helper method to create a :class:`cyclonedx.model.component.Component`
        that represents the provided local file as a Component.

        Args:
            absolute_file_path:
                Absolute path to the file you wish to represent
            name:
                Optionally, if supplied this is the name that will be used for the component.
                Defaults to arg ``absolute_file_path``.

        Returns:
            `Component` representing the supplied file
        zSupplied file path z does not exist)algcontent)typer   hashes)	r   FileExistsErrorr
   r   FILEr	   r   SHA_1_file_sha1sum)selfr   r   s      h/var/www/html/content-pipeline/venv/lib/python3.12/site-packages/cyclonedx/contrib/component/builders.pymake_for_filezComponentBuilder.make_for_file    sd      ()!$78J7M_"]^^##++]00$:L:LM_:`a
 	
    filenamec                     t               }t        | d      5 t        fdd      D ]  }|j                  |        	 ddd       |j	                         S # 1 sw Y   |j	                         S xY w)z
        Generate a SHA1 hash of the provided file.

        Args:
            filename:
                Absolute path to file to hash as `str`

        Returns:
            SHA-1 hash
        rbc                  &     j                  d      S )Ni   )read)fs   r   <lambda>z0ComponentBuilder._file_sha1sum.<locals>.<lambda>I   s    166$< r   r   N)r   openiterupdate	hexdigest)r   h
byte_blockr"   s      @r   r   zComponentBuilder._file_sha1sum;   sg     F(D! 	%Q"#7= %
$%	% {{}	% {{}s   &AA/N)	__name__
__module____qualname__strr   r
   r   staticmethodr    r   r   r   r      sD    
 
$SM
.7
6    r   N)__doc____all__hashlibr   os.pathr   typingr   modelr   r	   model.componentr
   r   r   r/   r   r   <module>r7      s+   $ !
    , 7- -r   