
    (iV                        d Z ddlZddlZddlZddlmZmZmZ ddlZ ej                         Z
e
j                  ddd       e
j                  dd	d
       e
j                         Z e ej                               d   Zej"                  ZereneZ ej(                  e        ej*                  e        ej,                   ej.                               D  cg c]  } | j1                  d      s|  c} Zej4                  ZeregneZdedeeef   fdZ	 ddeeeeef   f   dededeeef   fdZi Z dee   ddfdZ! e!e        ejD                  d ej.                                 yc c} w )a  
Arguments for the script are:
    -v or --version         Solidity version to be used to compile the contracts. If
                            blank, the script uses the latest hard-coded version
                            specified within the script.

    -f or --filename        If left blank, all .sol files will be compiled and the
                            respective contract data will be generated. Pass in a
                            specific ``.sol`` filename here to compile just one file.


To run the script, you will need the ``py-solc-x`` library for compiling the files
as well as ``black`` for linting. You can install those independently or install the
full ``[dev]`` package extra as shown below.

.. code:: sh

    $ pip install "web3[dev]"

The following example compiles all the contracts and generates their respective
contract data that is used across our test files for the test suites. This data gets
generated within the ``contract_data`` subdirectory within the ``contract_sources``
folder.

.. code-block:: bash

    $ cd ../web3.py/web3/_utils/contract_sources
    $ python compile_contracts.py -v 0.8.17
    Compiling OffchainLookup
    ...
    ...
    reformatted ...

To compile and generate contract data for only one ``.sol`` file, specify using the
filename with the ``-f`` (or ``--filename``) argument flag.

.. code-block:: bash

    $ cd ../web3.py/web3/_utils/contract_sources
    $ python compile_contracts.py -v 0.8.17 -f OffchainLookup.sol
    Compiling OffchainLookup.sol
    reformatted ...
    N)AnyDictListz-vz	--versionz)Solidity version for compiling contracts.)helpz-fz
--filenamezo(optional) The filename if only one file is to be compiled - otherwise all .sol files will be compiled at once..soldot_sol_filenamereturnc                 @    t        j                  d|  gg d      }|S )Nz./)abibinbin-runtime)output_values)solcxcompile_files)r	   compileds     _/var/www/br/venv/lib/python3.12/site-packages/web3/_utils/contract_sources/compile_contracts.py_compile_dot_sol_filesr   U   s+    ""	 !3H O    sol_file_outputcontract_namec                     |s|j                  dd      }d }| j                         D ]  }d| |v s| |   } |st        d|       d|d    |d<   d|d    |d<   |S )Nr    :z+Could not find compiled data for contract: 0xr   r   )replacekeys	Exception)r   r	   r   contract_datakeys        r   _get_compiled_contract_datar!   ]   s    
 (00<M##% 1}o#%+C0M1 Em_UVVe 456M%%'m(D'E#FM- r   	file_listc           	         | D ]  }t        t        j                  j                  t        j                         |            5 }|j                         }d d d        g }D ]f  t        fddD              sdvsj                  d      t        d      z   }|d  j                  d      |z   }|| }|j                  |       h |t        |<    t        j                         D ]g  }|j                  dd      }	t        j                  d|	      D 
cg c]  }
|
s|
j                          }}
d	j                  |       d
}t        j                  j                  t        j                         d|      }	 t        j                   |       t%        d|        t'        |      }t        |d      5 }|j)                  dt        j                  j+                  t,               d       |j)                  dt.         d       t        |   D ]6  }t        j                  d|      D 
cg c]  }
|
s|
j1                          }}
d	j                  |      }t3        |||      }d| d| }t        |      dkD  r|dz  }|j)                  | d       |j)                  | d|d    d       |j)                  | d|d    d       |j)                  | d|d    d       |j)                  |dz          |j)                  d | d!       |j)                  d"| d#       |j)                  d$| d%       |j)                  d&       9 	 d d d        j y # 1 sw Y   xY wc c}
w # t"        $ r Y w xY wc c}
w # 1 sw Y   xY w)'Nc              3   &   K   | ]  }|v  
 y wN ).0_lines     r   	<genexpr>z compile_files.<locals>.<genexpr>}   s     8198s   )contract{abstractz	contract  r   r   z([A-Z][a-z]*)r(   z.pyr   z
compiling wz"""
Generated by `z
` script.
zCompiled with Solidity vz.
"""

z([A-Z0-9][a-z0-9]*)z'# source: web3/_utils/contract_sources/r   X   z  # noqa: E501
z_BYTECODE = "r   z"  # noqa: E501
z_RUNTIME = "r   z_ABI = r   z
_DATA = {
z    "bytecode": z_BYTECODE,
z    "bytecode_runtime": z
_RUNTIME,
z    "abi": z_ABI,
z}


)openospathjoingetcwd	readlinesallfindlenappendcontracts_in_filer   r   resplitlowerremoveFileNotFoundErrorprintr   writebasename__file__solidity_versionupperr!   )r"   filenamefdot_sol_filecontract_namesstart_index	end_indexr   r	   filename_no_extensionisplit_and_lowercasepython_filenamepython_file_pathcompiled_dot_sol_datacc_name_split_and_uppercasecontract_upperc_datacontract_sourcer)   s                       @r   r   r   u   s    5"'',,ryy{H56 	)!;;=L	)   	5D8&788Zt=S"ii4s;7GG .33C8;F	 $[ ;%%m4	5 '5(#5 .224 .# 0 8 8 D!xx(8:OP
TUAGGI
 
 !XX&9:;3?77<<		_oV	II&' 	
+,-. 67G H"C(  	#AGG)"''*:*:8*D)E[QRGG./?.@
KL&'78 #')xx0F'J."#aAGGI.* . "%*D!E4)+;Q
 >>N=OqQRPST   '",#'77O?+2./%&mF5M?BST %&l6-3H2IIZ[ >*'&-CD67*>*:,GH2>2B+NO+n%5W=>	"9#	 	#  	#.#	) 	) 
 ! 		. 	#  	#sP   MM M 9M%3A5M:(M5
0M5
DM:M	%	M21M25M::N	zblack r%   )#__doc__argparser3   r=   typingr   r   r   r   ArgumentParser
arg_parseradd_argument
parse_args	user_argssortedget_compilable_solc_versions!LATEST_AVAILABLE_SOLIDITY_VERSIONversionuser_sol_versionrF   install_solcset_solc_versionlistdirr6   endswithall_dot_sol_filesrH   user_filenamefiles_to_compilestrr   r!   r<   r   system)rI   s   0r   <module>ro      s  *X  	 	  $X$$&
 
  +G     
9   !!#	$*+M5+M+M+O$PQS$T !$$  ).O    # $   ' ( !+

9299; 7N11::f;MQN ""&3M?9J S T#s(^  #tCH~-.  
#s(^	*  >#T#Y >#4 >#B   			F9299;-
  !O Os   E.0E.