§
    öÛgMA  ã                   óü  — d Z ddlZddlZddlZddlZddlZddlmZ ddl	m
Z ddl	mZ ddl	mZ ddl	mZ dd	l	mZ dd
lmZ ddlmZ ej        dv rddlmZ ej        Zd„ ZnddlZej        Zd„ Z G d„ dej        ¦  «        Z G d„ de¦  «        Z  G d„ de ¦  «        Z! G d„ de¦  «        Z" G d„ de¦  «        Z# G d„ de¦  «        Z$ G d„ dej%        ¦  «        Z&dZ'dZ(d Z)d!Z*d"d#d$d%œZ+ G d&„ d'ej,        ¦  «        Z,dS )(zÉ
Create, control, and destroy PostgreSQL clusters.

postgresql.cluster provides a programmer's interface to controlling a PostgreSQL
cluster. It provides direct access to proper signalling interfaces.
é    N©ÚNamedTemporaryFileé   )Úapi)Ú
configfile)Úinstallation)Ú
exceptions)Údriver)Úget_python_name)Ú	close_fds)Úwin32Úwin64)Úsignal1_mswc                 ó&   — t          dd| ¬¦  «        S )NFÚw)ÚdeleteÚmodeÚencodingr   ©r   s    úH/granary/edev/quantum/lib/python3.11/site-packages/postgresql/cluster.pyÚ	namedtempr      s   € Ý	 U°3ÀÐ	JÑ	JÔ	JÐJó    c                 ó$   — t          d| ¬¦  «        S )Nr   )r   r   r   r   s    r   r   r   !   s   € Ý	 3°Ð	:Ñ	:Ô	:Ð:r   c                   ó   — e Zd ZdZdZdZdS )ÚClusterErrorz
	General cluster error.
	z-C000ÚCLUSTERN©Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚcodeÚsource© r   r   r   r   $   s$   € € € € € ðð ð 	€Ø
€€€r   r   c                   ó   — e Zd ZdZdZdS )ÚClusterInitializationErrorz&General cluster initialization failurez-CiniN©r   r   r    r!   r"   r$   r   r   r&   r&   *   s   € € € € € Ø)Ð)Ø€€€r   r&   c                   ó   — e Zd ZdZdZdS )ÚInitDBErrorz4A non-zero result was returned by the initdb commandz-CidbNr'   r$   r   r   r)   r)   -   s   € € € € € Ø7Ð7Ø€€€r   r)   c                   ó   — e Zd ZdZdZdS )ÚClusterStartupErrorzCluster startup failedz-CbotNr'   r$   r   r   r+   r+   0   ó   € € € € € ØÐØ€€€r   r+   c                   ó   — e Zd ZdZdZdS )ÚClusterNotRunningErrorzCluster is not runningz-CdwnNr'   r$   r   r   r.   r.   3   r,   r   r.   c                   ó   — e Zd ZdZdZdS )ÚClusterTimeoutErrorzCluster operation timed outz-CoutNr'   r$   r   r   r0   r0   6   s   € € € € € ØÐØ€€€r   r0   c                   ó   — e Zd ZdZdZdZdS )ÚClusterWarningz$Warning issued by cluster operationsz-Cwrnr   Nr   r$   r   r   r2   r2   :   s   € € € € € Ø'Ð'Ø€Ø
€€€r   r2   úutf-8zpostgresql.confzpg_hba.confzpostmaster.pidz-Ez-Az-U)r   ÚauthenticationÚuserc                   ó”  — e Zd ZdZej        ZdZdZe	Z	e
Z
eZeZed„ ¦   «         Zd„ Zed„ ¦   «         Zd„ Zed„ ¦   «         Zed„ ¦   «         Zeej        j        fd	„¦   «         Z	 	 	 	 d0d„Zdj        fd„Zd„ Zd„ Z	 d1	 d2d„Zd„ Z	 	 d3	 	 	 d4d„Zd5d„Z d„ Z!d„ Z"d „ Z#d!„ Z$d"„ Z%d#„ Z&d$„ Z'd%„ Z(d&„ Z)d'„ Z*d(„ Z+	 	 d6	 	 	 d7d.„Z,	 	 d6	 	 	 d7d/„Z-dS )8ÚClusteraO  
	Interface to a PostgreSQL cluster.

	Provides mechanisms to start, stop, restart, kill, drop, and initalize a
	cluster(data directory).

	Cluster does not strive to be consistent with ``pg_ctl``. This is considered
	to be a base class for managing a cluster, and is intended to be extended to
	accommodate for a particular purpose.
	Nc                 ó~   — |                       ¦   «         rdS t          j                             | j        ¦  «        sdS dS )NÚrunningÚvoidÚstopped)r9   ÚosÚpathÚexistsÚdata_directory©Úselfs    r   ÚstatezCluster.state`   s:   € à	‡\‚\�^„^ð Ø
ˆ)Ý	Œ�Š˜Ô+Ñ	,Ô	,ð Ø
ˆ&Ø	ˆr   c              #   óV   K  — | j         }d d|z   dz   fV — |dk    rd| j         fV — d S d S )Nú[ú]r9   Úpid)rB   )rA   rB   s     r   Ú_e_metaszCluster._e_metash   sS   è è € Ø
Œ*€%Ø	ˆs�U‰{˜SÑ Ð!Ð!Ð!Ð!Ø
ˆiÒÐØ
�”Ð	ÐÐÐÐÐð Ðr   c                 ó2   — | j         j        p| j         j        S )z;
		Path to the executable to use to startup the cluster.
		)r   Ú
postmasterÚpostgresr@   s    r   Údaemon_pathzCluster.daemon_pathn   s   € ð
 
Ô	Ô	%Ð	C¨Ô):Ô)CÐCr   c                 óf  — 	 t           j                             | j        | j        ¦  «        }t          |¦  «        5 }t          |                     ¦   «         ¦  «        cddd¦  «         S # 1 swxY w Y   dS # t          $ r0}|j	        t          j
        t          j        fv rY d}~dS Y d}~dS d}~ww xY w)z3
		The current pid from the postmaster.pid file.
		N)r<   r=   Újoinr?   ÚDEFAULT_PID_FILENAMEÚopenÚintÚreadlineÚIOErrorÚerrnoÚEIOÚENOENT)rA   r=   ÚfÚes       r   Úget_pid_from_filezCluster.get_pid_from_fileu   sø   € ðÝ
Œ'�,Š,�tÔ*¨DÔ,EÑ
FÔ
F€4ÝˆT‰
Œ
ð �aÝˆq�zŠz‰|Œ|ÑÔðð ð ð ñ ô ð ð ð ð ð ð øøøð ð ð ð ð ð øå	ð ð ð Ø„g•%”)�Uœ\Ð*Ð*Ð*Øˆ4ˆ4ˆ4ˆ4ˆ4ð +Ð*Ð*Ð*Ð*Ð*øøøøðøøøs:   ‚9A6 »!A)ÁA6 Á)A-Á-A6 Á0A-Á1A6 Á6
B0Â B+Â+B0c                 óR   — |                       ¦   «         }|€| j        }|�|j        S |S )z;
		If we have the subprocess, use the pid on the object.
		)rX   Údaemon_processrF   )rA   rF   Úds      r   rF   zCluster.pid�   s3   € ð
 	×ÒÑ Ô €#Ø€[ØÔ€1Ø€mØŒ5€LØ	€*r   c                 ól   — t          | d¦  «        st          j        | j        ¦  «        | _        | j        S )NÚ	_settings)Úhasattrr   Ú
ConfigFileÚpgsql_dot_confr]   r@   s    r   ÚsettingszCluster.settings�   s1   € å	��{Ñ	#Ô	#ð ?ÝÔ)¨$Ô*=Ñ>Ô>€4„>Ø	ŒÐr   c                 ó`   — | j                              d || j        | j        ¦  «        ¦  «        S )z.
		The path to the HBA file of the cluster.
		Úhba_file)ra   Úgetr?   ÚDEFAULT_HBA_FILENAME)rA   rM   s     r   rc   zCluster.hba_file“   s6   € ð
 
Œ×	Ò	ØØ€4ˆÔ˜TÔ6Ñ7Ô7ñ
ô 
ð r   r   úinstallation objectr?   úpath to the data directoryc                 óÖ   — || _         t          j                             |¦  «        | _        t          j                             | j        | j        ¦  «        | _        d | _        d | _	        d S ©N)
r   r<   r=   Úabspathr?   rM   ÚDEFAULT_CONFIG_FILENAMEr`   rZ   Údaemon_command)rA   r   r?   s      r   Ú__init__zCluster.__init__�   s^   € ð #€$ÔÝœŸš¨Ñ7Ô7€$ÔÝœŸšØÔØÔñô €$Ôð €$ÔØ€$ÔÐÐr   z{mod}.{name}({ins!r}, {dir!r})c                 óz   —  |t          | ¦  «        j        t          | ¦  «        j        | j        | j        ¦  «        S ri   )Útyper   r   r   r?   )rA   Úformats     r   Ú__repr__zCluster.__repr__ª   s:   € Ø	ˆÝˆ�:„:ÔÝˆ�:„:ÔØÔØÔñ	
ô 
ð r   c                 óV   — |                       ¦   «          |                      ¦   «          | S )z3
		Start the cluster and wait for it to startup.
		)ÚstartÚwait_until_startedr@   s    r   Ú	__enter__zCluster.__enter__²   s(   € ð ‡*‚*�,„,€,Ø×ÒÑÔÐØ	€+r   c                 óV   — |                       ¦   «          |                      ¦   «          dS )z3
		Stop the cluster and wait for it to shutdown.
		N)ÚstopÚwait_until_stopped)rA   ÚtypÚvalÚtbs       r   Ú__exit__zCluster.__exit__º   s)   € ð ‡)‚)�+„+€+Ø×ÒÑÔÐÐÐr   Úpasswordú>Password to assign to the cluster's superuser(`user` keyword).c                 ój  — | j         j        }|€| j         j        df}n|f}d|v rt          dddi| ¬¦  «        ‚|                     d| j        ¦  «         g }|D ]]}|dv rŒ|t          vrt          d	|›�¦  «        ‚|                     t          |         ¦  «         |                     ||         ¦  «         Œ^| 	                    d
¦  «        pt          j        }t          d„ | 	                    dd¦  «        D ¦   «         ¦  «        }d}d}	d}
	 |�Wt          t          |d         ¦  «        ¬¦  «        }	|	                     |¦  «         |	                     ¦   «          d|	j        z   f}|d| j        fz   t          |¦  «        z   |z   |z   }t          j        |t(          dt          j        |t          j        ¬¦  «        }
|
j                             ¦   «          	 	 |
                     ¦   «         }	 |
j        �|
j                             ¦   «          nv# t2          $ r }|j        t4          j        k    r‚ Y d}~nd}~ww xY w	 |
j        �|
j                             ¦   «          n&# |
j        �|
j                             ¦   «          w w xY wŒ­|dk    r£|
j                             ¦   «                              ¦   «         }	 |                     d¦  «        }nK# t@          $ r> tB          j"         #                    d„ | $                    ¦   «         D ¦   «         ¦  «        }Y nw xY wtK          d|||dœ| ¬¦  «        ‚	 |
�-|
j        |
j        |
j        fD ]}|�|                     ¦   «          Œ|	�P|	j        }|	                     ¦   «          tB          j&         '                    |¦  «        rtC          j(        |¦  «         dS dS dS # |
�-|
j        |
j        |
j        fD ]}|�|                     ¦   «          Œ|	�O|	j        }|	                     ¦   «          tB          j&         '                    |¦  «        rtC          j(        |¦  «         w w w xY w)zÑ
		Create the cluster at the given `data_directory` using the
		provided keyword parameters as options to the command.

		`command_option_map` provides the mapping of keyword arguments
		to command options.
		NÚinitdbz4unable to find executable for cluster initializationÚdetailz4The installation does not have 'initdb' or 'pg_ctl'.©ÚdetailsÚcreatorr   )ÚlogfileÚextra_argumentsz#got an unexpected keyword argument r…   c                 ó,   — g | ]}t          |¦  «        ‘ŒS r$   )Ústr©Ú.0Úxs     r   ú
<listcomp>z Cluster.init.<locals>.<listcomp>ê   s+   € ð ð ð Ø…3€q�6„6ðð ð r   r†   r$   r   z	--pwfile=ú-Di   )r   ÚbufsizeÚstdinÚstdoutÚstderrTr   r3   c                 ó<   — g | ]}t          |¦  «        d d…         ‘ŒS )é   éÿÿÿÿ)Úreprr‰   s     r   rŒ   z Cluster.init.<locals>.<listcomp>  s3   € ð ð ð Ø…dˆ1�g„gˆa�ˆd„mðð ð r   z"initdb exited with non-zero status)Úcommandr‘   r�   ))r   r€   Úpg_ctlr&   Ú
setdefaultÚDEFAULT_CLUSTER_ENCODINGÚinitdb_option_mapÚ	TypeErrorÚappendrd   ÚspÚPIPEÚtupler   r   ÚwriteÚflushÚnamer?   ÚPopenr   r�   ÚcloseÚwaitr�   ÚOSErrorrS   ÚEINTRr‘   ÚreadÚstripÚdecodeÚUnicodeDecodeErrorr<   ÚlineseprM   Ú
splitlinesr)   r=   r>   Úunlink)rA   r}   Úkwr€   Úoptsr‹   r…   Ú
extra_argsÚ	supw_fileÚsupw_tmpÚpÚcmdÚrcrW   ÚrÚmsgÚns                    r   ÚinitzCluster.initÁ   sÆ  € ð ÔÔ#€&Ø€^ØÔÔ% xÐ1€6€6àˆI€6à	ˆV€^€^Ý	#Ø:àÐFðð ð
ñ 
ô 
ð ð ‡-‚-�
˜DÔ9Ñ:Ô:Ð:Ø	€$Øð ð €aØÐ)Ð)Ð)ØØÕ Ð Ð Ý
ˆ)¸a¸aÐAÑ
BÔ
BÐBØ‡;‚;Õ  Ô#Ñ$Ô$Ð$Ø‡;‚;ˆr�!ŒuÑÔÐÐØ�FŠF�9ÑÔÐ(¥¤€'Ýð ð Ø—6’6Ð+¨RÑ0Ô0ðñ ô ñ ô €*ð €)Ø€(Ø
€!ðCØÐå¥O°B°z´NÑ$CÔ$CÐDÑDÔD€HØ‡N‚N�8ÑÔÐØ‡N‚NÑÔÐØ˜xœ}Ñ,Ð.€Ià	�4˜Ô,Ð-Ñ	-ÝˆD�k„kñ
àñ
ð ñ
€3õ
 
„xØÝØÝŒGØåŒWðñ ô €1ð „7‡=‚=�?„?€?ð	ðØ
�&Š&‰(Œ(€RØ
ð
 	
ŒÐØ„h‡n‚nÑÔÐøøõ ð ð ð Ø	Œ•5”;ÒÐØð 	ÐÐÐÐøøøøðøøøØð 	
ŒÐØ„h‡n‚nÑÔÐøøð 	
ŒÐØ„h‡n‚nÑÔÐÐð 	øøøð	ð 	ˆA‚g€gð 	
Œ�Š‰Œ×ÒÑÔ€AðØ�8Š8�GÑÔ€S€SøÝð ð ð åŒ:�?Š?ð ð ØŸ\š\™^œ^ðñ ô ñ ô €S€S€Sðøøøõ
 Ø)àØØðð ð
 ðñ ô ð ð ð* €mØŒh˜œ ¤Ð*ð ð ˆØ	ˆØ‡g‚g�i„i€iøàÐØŒ€AØ‡N‚NÑÔÐå	„w‡~‚~�aÑÔð Ý„Yˆq�\„\€\€\€\ð Ððð øð €mØŒh˜œ ¤Ð*ð ð ˆØ	ˆØ‡g‚g�i„i€iøàÐØŒ€AØ‡N‚NÑÔÐå	„w‡~‚~�aÑÔð Ý„Yˆq�\„\€\€\ð ðøøøso   ÄCN/ ÇH
 Ç)!N/ È

H4ÈH/È*I È/H4È4I È8!N/ É#I<É<5N/ Ê2K ËN/ ËALÌN/ ÌLÌN/ Î/BP2c                 ó´  — |                       ¦   «         rš|                      ¦   «          	 |                      ¦   «          np# t          $ rc |                      ¦   «          	 |                      ¦   «          n6# t          $ r) t          dddi| ¬¦  «                             ¦   «          Y nw xY wY nw xY wt          j        | j	        d¬¦  «        D ]t\  }}}|D ]4}t          j
        t          j                             ||¦  «        ¦  «         Œ5|D ]4}t          j        t          j                             ||¦  «        ¦  «         Œ5Œut          j        | j	        ¦  «         dS )z8
		Stop the cluster and remove it from the filesystem
		z%cluster failed to shutdown after killÚhintz#Shared memory may have been leaked.r‚   F)ÚtopdownN)r9   Úshutdownrx   r0   Úkillr2   Úemitr<   Úwalkr?   Úremover=   rM   Úrmdir)rA   ÚrootÚdirsÚfilesr¢   s        r   ÚdropzCluster.drop6  sx  € ð 
‡\‚\�^„^ð Ø‡=‚=�?„?€?ðØ×ÒÑÔÐÐøÝ
ð 	ð 	ð 	Ø‡I‚I�K„K€KðØ	×ÒÑÔÐÐøÝð ð ð ÝØ-ØÐ?Ð@Øðñ ô ÷ ‚t�v„v€v€v€vðøøøøøð		øøøõ œ7 4Ô#6À%ÐHÑHÔHð 'ð 'Ñ€dˆD�%Øð (ð (€tÝ„I�bŒg�lŠl˜4 Ñ&Ô&Ñ'Ô'Ð'Ð'Øð 'ð '€tÝ„H�RŒW�\Š\˜$ Ñ%Ô%Ñ&Ô&Ð&Ð&ð'å„(ˆ4ÔÑÔÐÐÐs3   ª? ¿B,ÁA3Á2B,Á30B&Â#B,Â%B&Â&B,Â+B,r…   úWhere to send stderrra   úMapping of runtime parametersc                 óü  — |                       ¦   «         rdS | j        d| j        f}|�Qt          |¦  «                             ¦   «         D ]/\  }}|                     d                     ||¬¦  «        ¦  «         Œ0t          j        |t          d|€t          j
        n|t          j        t          j
        ¬¦  «        }|€|j                             ¦   «          |j                             ¦   «          || _        || _        dS )z
		Start the cluster.
		Nr�   z	--{k}={v})ÚkÚvi   )r   rŽ   r�   r‘   r�   )r9   rK   r?   ÚdictÚitemsrœ   rp   r�   r£   r   rž   ÚSTDOUTr�   r¤   r�   rZ   rl   )rA   r…   ra   rµ   rË   rÌ   r´   s          r   rs   zCluster.startP  sò   € ð 
‡\‚\�^„^ð 
Ø	€6Ø	Ô	˜4 Ô!4Ð5€#ØÐÝ�8‰nŒn×"Ò"Ñ$Ô$ð ,ð ,�s€qˆØ‡J‚Jˆ{×!Ò! A¨Ð!Ñ*Ô*Ñ+Ô+Ð+Ð+å„hØÝØà��BŒGˆG¨GÝŒIÝŒ7ðñ ô €!ð €_Ø„8‡>‚>ÑÔÐØ„'‡-‚-�/„/€/Ø€$ÔØ€$ÔÐÐr   é
   c                 ó&  — |                       ¦   «         r*|                      ¦   «          |                      |¬¦  «         |                       ¦   «         rt          d| ¬¦  «        ‚|                      ||¬¦  «         |                      |¬¦  «         dS )a  
		Restart the cluster gracefully.

		This provides a higher level interface to stopping then starting the
		cluster. It will perform the wait operations and block until the
		restart is complete.

		If waiting is not desired, .start() and .stop() should be used directly.
		)Útimeoutzfailed to shutdown cluster©r„   )r…   ra   N)r9   rw   rx   r   rs   rt   )rA   r…   ra   rÒ   s       r   ÚrestartzCluster.restartm  sš   € ð 
‡\‚\�^„^ð .Ø‡9‚9�;„;€;Ø×Ò WÐÑ-Ô-Ð-Ø	‡\‚\�^„^ð Ý	Ø Øð
ñ 
ô 
ð ð ‡*‚*�w¨8€*Ñ4Ô4Ð4Ø×Ò GÐÑ,Ô,Ð,Ð,Ð,r   c                 ó®   — | j         }|�K	 t          |t          j        ¦  «         dS # t          $ r!}|j        t
          j        k    r‚ Y d}~dS d}~ww xY wdS )z:
		Signal the cluster to reload its configuration file.
		N)rF   Úpg_killÚsignalÚSIGHUPr¦   rS   ÚESRCH©rA   rF   rW   s      r   ÚreloadzCluster.reload‚  óy   € ð 	Œ€#Ø€_ðÝˆC•”ÑÔÐÐÐøÝ
ð ð ð Ø„w•%”+ÒÐØ
ð ÐÐÐÐÐøøøøðøøøð €_ó   ‹' §
A±AÁAc                 ó®   — | j         }|�K	 t          |t          j        ¦  «         dS # t          $ r!}|j        t
          j        k    r‚ Y d}~dS d}~ww xY wdS )zM
		Stop the cluster gracefully waiting for clients to disconnect(SIGTERM).
		N)rF   rÖ   r×   ÚSIGTERMr¦   rS   rÙ   rÚ   s      r   rw   zCluster.stopŽ  sy   € ð 	Œ€#Ø€_ðÝˆC•”Ñ Ô Ð Ð Ð øÝ
ð ð ð Ø„w•%”+ÒÐØ
ð ÐÐÐÐÐøøøøðøøøð €_rÝ   c                 ó®   — | j         }|�K	 t          |t          j        ¦  «         dS # t          $ r!}|j        t
          j        k    r‚ Y d}~dS d}~ww xY wdS )zF
		Shutdown the cluster as soon as possible, disconnecting clients.
		N)rF   rÖ   r×   ÚSIGINTr¦   rS   rÙ   rÚ   s      r   r¾   zCluster.shutdownš  rÜ   rÝ   c                 ó®   — | j         }|�K	 t          |t          j        ¦  «         dS # t          $ r!}|j        t
          j        k    r‚ Y d}~dS d}~ww xY wdS )zM
		Stop the cluster immediately(SIGKILL).

		Does *not* wait for shutdown.
		N)rF   rÖ   r×   ÚSIGKILLr¦   rS   rÙ   rÚ   s      r   r¿   zCluster.kill¦  sy   € ð 	Œ€#Ø€_ðÝˆC•”Ñ Ô Ð Ð Ð øÝ
ð ð ð Ø„w•%”+ÒÐØ
ð ÐÐÐÐÐøøøøðøøøð €_rÝ   c                 ó  — t           j                             | j        ¦  «        rht           j                             | j        ¦  «        rDt           j                             t           j                             | j        d¦  «        ¦  «        rdS dS )zH
		Whether or not the data directory *appears* to be a valid cluster.
		ÚbaseTF)r<   r=   Úisdirr?   r>   r`   rM   r@   s    r   ÚinitializedzCluster.initializedµ  sk   € õ „W‡]‚]�4Ô&Ñ'Ô'ð Ý„'‡.‚.�Ô$Ñ%Ô%ðå„'‡-‚-•”—’˜TÔ0°&Ñ9Ô9Ñ:Ô:ðð ˆ$Ø	ˆr   c                 óx  — | j         �P| j                              ¦   «         }|�3|                      ¦   «         }|�d| _         |                      ¦   «         S dS dS |                      ¦   «         }|€dS 	 t	          |t
          j        ¦  «         n.# t          $ r!}|j        t          j	        k    r‚ Y d}~dS d}~ww xY wdS )zm
		Whether or not the postmaster is running.

		This does *not* mean the cluster is accepting connections.
		NFT)
rZ   ÚpollrX   r9   rÖ   r×   ÚSIG_DFLr¦   rS   rÙ   )rA   r·   rF   rW   s       r   r9   zCluster.running¿  sÖ   € ð 
ÔÐ$ØÔ×ÒÑ!Ô!€1Ø€mØ
×
 Ò
 Ñ
"Ô
"€CØ
€à€TÔØ�LŠL‰NŒNÐØˆ5àˆ4à	×	Ò	Ñ	!Ô	!€3Ø	€kØˆ5ðÝˆC•”Ñ Ô Ð Ð øÝ
ð ð ð Ø„w•%”+ÒÐØ
Øˆ5ˆ5ˆ5ˆ5ˆ5øøøøðøøøð ˆ$s   Á1B Â
B7ÂB2Â2B7c                 ób   — |                       ¦   «         \  }} | j        j        d|pd|pddœ|¤ŽS )z�
		Create a postgresql.driver connector based on the given keywords and
		listen_addresses and port configuration in settings.
		Ú	localhosti8  )ÚhostÚportr$   )Úaddressr
   Úfit)rA   r¯   rí   rî   s       r   Ú	connectorzCluster.connectorÜ  sP   € ð
 �|Š|‰~Œ~�*€$ˆØ	ˆŒŒð 
Ø
Ð
�+Ø
ˆ,�$ð
ð 
ð ð
ð 
ð r   c                 ó,   —   | j         di |¤Ž¦   «         S )zD
		Create a connection object to the cluster, but do not connect.
		r$   )rñ   )rA   r¯   s     r   Ú
connectionzCluster.connectionè  s$   € ð 
ˆˆŒÐ	Ð	˜"Ð	Ð	Ñ	Ô	Ðr   c                 ó’   — |                       ¦   «         st          d| ¬¦  «        ‚ | j        di |¤Ž}|                     ¦   «          |S )zV
		Create an established connection from the connector.

		Cluster must be running.
		z(cannot connect if cluster is not runningrÓ   r$   )r9   r.   ró   Úconnect)rA   r¯   r‹   s      r   rõ   zCluster.connectî  s\   € ð 
�Š‰Œð Ý	Ø.Øð
ñ 
ô 
ð ð €d„oÐÐ˜ÐÐ€!Ø‡)‚)�+„+€+Ø	
€(r   c                 óJ  — | j                              d¦  «        }|                     d¦  «        �\|                     d¦  «                             ¦   «                              d¦  «        }d|v sd|v rd}nd|v rd}nd|v rd}n|d	         }nd}||                     d
¦  «        fS )z4
		Get the host-port pair from the configuration.
		)Úlisten_addressesrî   r÷   Nú,rì   Ú*z	127.0.0.1z::1r   rî   )ra   Úgetsetrd   ÚlowerÚsplit)rA   r[   Úaddrsrí   s       r   rï   zCluster.addressý  sÄ   € ð „m×Òð ñ ô €!ð ‡U‚UÐÑÔÐ*ð �5Š5Ð#Ñ$Ô$×*Ò*Ñ,Ô,×2Ò2°3Ñ7Ô7€5Ø�UÐÐ˜c U˜l˜lØ€D€DØ�uÐÐØ€D€DØ�ˆˆØ€D€Dà�Œ8€D€Dà
€4Ø
�—’�f‘”Ð	Ðr   c                 ó¨  — |                       ¦   «         sdS d}|                      ¦   «         \  }} | j                             d||dd¬¦  «        ¦   «         }	 |                     ¦   «          ná# t
          j        $ rÏ}|j        j        D ]¶}|j	        }| j
        j        dd…         dk     r.t          |t
          j        t
          j        f¦  «        r Y d}~d	S n!t          |t
          j        ¦  «        r Y d}~d	S t          |t
          j        t
          j        f¦  «        r|‚t          |t
          j        ¦  «        r|} nŒ·|}Y d}~nd}~ww xY w|�|nd	S )
z~
		If the daemon is running, and is not in startup mode.

		This only works for clusters configured for TCP/IP connections.
		FNz -*- ping -*- Ú	template1Údisable)r5   rí   rî   ÚdatabaseÚsslmoder“   )é   r   T)r9   rï   r
   rð   rõ   Úpg_excÚClientCannotConnectErrorr  ÚfailuresÚerrorr   Úversion_infoÚ
isinstanceÚUndefinedObjectErrorÚ AuthenticationSpecificationErrorÚCFErrorÚProtocolErrorÚServerNotReadyError)rA   rW   rí   rî   ró   ÚerrÚattemptr‹   s           r   Úready_for_connectionszCluster.ready_for_connections  s˜  € ð 
�Š‰Œð Ø
ˆ%Ø
€!Ø�|Š|‰~Œ~�*€$ˆðˆtŒ{�ŠØ
Ø
�tØØð	 ñ ô ñ ô €*ðØ×ÒÑÔÐÐøÝ	Ô	(ð ð ð Ø”,Ô'ð ð €wØŒ€AØÔÔ% b q bÔ)¨EÒ1Ð1Ý�1ÝÔ!ÝÔ-ðñ 	ô 	ð ð
 ˆTˆTˆTˆTˆTˆTðõ 	�1•fÔ=Ñ>Ô>ð ØˆTˆTˆTˆTˆTˆTå�!•f”n¥fÔ&:Ð;Ñ<Ô<ð Ø€WÝ�!•VÔ/Ñ0Ô0ð Ø	
€QØ
€Uðð 	€Aøøøøøøøøøð)øøøð. ˆmˆˆ Ð%s&   ÁA- Á-EÁ<AEÃEÃ8A	EÅEçš™™™™™©?rÒ   ú4how long to wait before throwing a timeout exceptionÚdelayú#how long to sleep before re-testingc                 óÞ  — t          j         ¦   «         }|}	 |                      ¦   «         sA| j        �)| j        j        }|�t	          d|| j        dœ| ¬¦  «        ‚nt          d| ¬¦  «        ‚|                      ¦   «         }t          j         ¦   «         }|du rdS ||z
  |k    r8|�t          |t          j
        ¦  «        r|‚t          d| ¬¦  «        }|d	vr||‚|‚t          j        |¦  «         ŒØ)
zê
		After the `start` method is used, this can be ran in order to block
		until the cluster is ready for use.

		This method loops until `ready_for_connections` returns `True` in
		order to make sure that the cluster is actually up.
		TNzpostgres daemon terminated)ÚRESULTÚCOMMANDr‚   z$postgres daemon has not been startedrÓ   ztimeout on startup)TF)Útimer9   rZ   Ú
returncoder+   rl   r.   r  r	  r  r  r0   Úsleep)rA   rÒ   r  rs   Ú
checkpointr·   rW   s          r   rt   zCluster.wait_until_started?  s:  € õ Œ)‰+Œ+€%Ø€*ð%Ø
�,Š,‰.Œ.ð ØÔÐ&Ø	Ô	Ô	'€QØ	ˆÝØ#àØÔ'ð	ð 	ð ðñ ô ð ð 	õ "Ø,Øðñ ô ð ð ×!Ò!Ñ#Ô#€1å”	‘”€:Øˆ4€i€iØ	€Eà�5Ñ˜GÒ#Ð#ð 	€}� A¥vÔ'AÑBÔB€}Ø€WÝØØð	ñ 	ô 	€Að 	�ÐÐØ�!€^Ø
€GÝ„:ˆeÑÔÐðK%r   c                 ó   — t          j         ¦   «         }|                      ¦   «         du r¤| j        �| j                             ¦   «         | _        n't          |                      ¦   «         d¦  «        | _        t          j         ¦   «         |z
  |k    rt          d| ¬¦  «        ‚t          j        |¦  «         |                      ¦   «         du °¢dS dS )a  
		After the `stop` method is used, this can be ran in order to block until
		the cluster is shutdown.

		Additionally, catching `ClusterTimeoutError` exceptions would be a
		starting point for making decisions about whether or not to issue a kill
		to the daemon.
		TNr   ztimeout on shutdownrÓ   )	r  r9   rZ   ré   Úlast_exit_coderÖ   rX   r0   r  )rA   rÒ   r  rs   s       r   rx   zCluster.wait_until_stoppeds  sÉ   € õ Œ)‰+Œ+€%Ø�Š‰Œ˜$ÐÐà
ÔÐ%ØÔ-×2Ò2Ñ4Ô4€DÔÐå! $×"8Ò"8Ñ":Ô":¸AÑ>Ô>€DÔÝ
„i�k„k�EÑ˜WÒ$Ð$Ý
ØØðñ ô ð õ „:ˆeÑÔÐð 	�Š‰Œ˜$ÐÐÐÐÐÐr   )r   rf   r?   rg   ri   )r}   r~   )NN)r…   rÈ   ra   rÉ   )NNrÐ   )rÐ   r  )rÒ   r  r  r  ).r   r   r    r!   Ú	pg_driverÚdefaultr
   r   r?   r™   rk   rN   re   ÚpropertyrB   rG   rK   rX   rF   ra   r<   r=   rM   rc   rm   rp   rq   ru   r|   rº   rÇ   rs   rÔ   rÛ   rw   r¾   r¿   rç   r9   rñ   ró   rõ   rï   r  rt   rx   r$   r   r   r7   r7   M   sÕ  € € € € € ð	ð 	ð Ô
€Ø€Ø€Ø4ÐØ2ÐØ,ÐØ,Ðà
ðð ñ „(ððð ð ð ðDð Dñ „(ðDð
ð 
ð 
ð ð	ð 	ñ „(ð	ð ðð ñ „(ðð
 Øœ7œ<ð ð ð ñ „(ððØ&ðà/ðð ð ð ð >ÔDð ð ð ð ðð ð ðð ð ð -1ðsð*ðsð sð sð sðj ð  ð  ð6 &*Ø/3ðØ"ðà,ðð ð ð ð:-ð -ð -ð -ð*
ð 
ð 
ð
ð 
ð 
ð
ð 
ð 
ðð ð ðð ð ðð ð ð:
ð 
ð 
ð ð  ð  ðð ð ðð ð ð.)&ð )&ð )&ðX FHØ26ð2ØBð2à
/ð2ð 2ð 2ð 2ðj FHØ26ðØBðà
/ðð ð ð ð ð r   r7   )-r!   Úsysr<   rS   r  Ú
subprocessr�   Útempfiler   Ú r   Úpg_apir   r   Úpg_innr	   r  r
   r  Úencodings.aliasesr   Ú	python.osr   Úplatformrî   r   r×   r¿   rÖ   r   ÚErrorr   r&   r)   r+   r.   r0   ÚWarningr2   r™   rk   re   rN   rš   r7   r$   r   r   ú<module>r-     sÎ  ððð ð €
€
€
Ø 	€	€	€	Ø €€€Ø €€€Ø Ð Ð Ð Ø 'Ð 'Ð 'Ð 'Ð 'Ð 'à Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð Ø $Ð $Ð $Ð $Ð $Ð $Ø "Ð "Ð "Ð "Ð "Ð "Ø !Ð !Ð !Ð !Ð !Ð !Ø .Ð .Ð .Ð .Ð .Ð .Ø  Ð  Ð  Ð  Ð  Ð  à„<Ð%Ð%Ð%Ø(Ð(Ð(Ð(Ð(Ð(ØŒ;€ðKð Kð Kð Kð €€€ØŒ7€ð;ð ;ð ;ðð ð ð ð �6”<ñ ô ð ðð ð ð ð  ñ ô ð ðð ð ð ð Ð,ñ ô ð ðð ð ð ð ˜,ñ ô ð ðð ð ð ð ˜\ñ ô ð ðð ð ð ð ˜,ñ ô ð ðð ð ð ð �V”^ñ ô ð ð
 #Ð Ø+Ð Ø$Ð Ø'Ð ð ØØ
ðð Ð ð~ð ~ð ~ð ~ð ~ˆfŒnñ ~ô ~ð ~ð ~ð ~r   