
    \jX                         d Z ddlmZmZmZmZ ddlmZ ddlm	Z	m
Z
 ddlmZmZmZmZ dZdZ G d d	      Z G d
 d      Z G d d      Zg dZy)z
This submodule contains the :class:`Config` class for custom configuration of the SDK client.

Note that the same class can also be imported from the ``ldclient.client`` submodule.
    )OptionalCallableListSet)InMemoryFeatureStore)logvalidate_application_info)BigSegmentStoreEventProcessorFeatureStoreUpdateProcessorz/sdk/latest-flagsz/flagsc                       e Zd ZdZ	 	 	 	 	 	 	 ddee   dededee   dee   ded	efd
Ze	dee   fd       Z
e	defd       Ze	defd       Ze	defd       Ze	defd       Ze	defd       Ze	defd       Zy)BigSegmentsConfigaJ  Configuration options related to Big Segments.

    Big Segments are a specific type of segments. For more information, read the LaunchDarkly
    documentation: https://docs.launchdarkly.com/home/users/big-segments

    If your application uses Big Segments, you will need to create a ``BigSegmentsConfig`` that at a
    minimum specifies what database integration to use, and then pass the ``BigSegmentsConfig``
    object as the ``big_segments`` parameter when creating a :class:`Config`.

    This example shows Big Segments being configured to use Redis:
    ::

            from ldclient.config import Config, BigSegmentsConfig
            from ldclient.integrations import Redis
            store = Redis.new_big_segment_store(url='redis://localhost:6379')
            config = Config(big_segments=BigSegmentsConfig(store = store))
    Nstorecontext_cache_sizecontext_cache_timeuser_cache_sizeuser_cache_timestatus_poll_intervalstale_afterc                 Z    || _         ||n|| _        ||n|| _        || _        || _        y)a  
        :param store: the implementation of :class:`ldclient.interfaces.BigSegmentStore` that will
            be used to query the Big Segments database
        :param context_cache_size: the maximum number of contexts whose Big Segment state will be cached
            by the SDK at any given time
        :param context_cache_time: the maximum length of time (in seconds) that the Big Segment state
            for a context will be cached by the SDK
        :param user_cache_size: deprecated alias for `context_cache_size`
        :param user_cache_time: deprecated alias for `context_cache_time`
        :param status_poll_interval: the interval (in seconds) at which the SDK will poll the Big
            Segment store to make sure it is available and to determine how long ago it was updated
        :param stale_after: the maximum length of time between updates of the Big Segments data
            before the data is considered out of date
        N)_BigSegmentsConfig__store&_BigSegmentsConfig__context_cache_size&_BigSegmentsConfig__context_cache_time(_BigSegmentsConfig__status_poll_interval_BigSegmentsConfig__stale_after)selfr   r   r   r   r   r   r   s           9/root/env/lib/python3.12/site-packages/ldclient/config.py__init__zBigSegmentsConfig.__init__#   s@    , :I:Q$6Wf!:I:Q$6Wf!&:#(    returnc                     | j                   S N)r   r   s    r   r   zBigSegmentsConfig.store@   s    ||r    c                     | j                   S r#   )r   r$   s    r   r   z$BigSegmentsConfig.context_cache_sizeD       (((r    c                     | j                   S r#   )r   r$   s    r   r   z$BigSegmentsConfig.context_cache_timeH   r&   r    c                     | j                   S )z0Deprecated alias for :attr:`context_cache_size`.)r   r$   s    r   r   z!BigSegmentsConfig.user_cache_sizeL        &&&r    c                     | j                   S )z0Deprecated alias for :attr:`context_cache_time`.)r   r$   s    r   r   z!BigSegmentsConfig.user_cache_timeQ   r)   r    c                     | j                   S r#   )r   r$   s    r   r   z&BigSegmentsConfig.status_poll_intervalV   s    ***r    c                     | j                   S r#   )r   r$   s    r   r   zBigSegmentsConfig.stale_afterZ       !!!r    )N     NNr/   x   )__name__
__module____qualname____doc__r   r
   intfloatr   propertyr   r   r   r   r   r   r    r    r   r   r      s4   $ 59)-+,0426-.$' 1%( &+ #+3-	
 #+5/ (- $: x0   )C ) ) )E ) ) ' ' ' ' ' ' +e + + "U " "r    r   c                       e Zd ZdZ	 	 	 	 	 	 ddededee   dee   dee   defd	Ze	d
efd       Z
e	d
efd       Ze	d
ee   fd       Ze	d
ee   fd       Ze	d
ee   fd       Ze	d
efd       Zy)
HTTPConfigaU  Advanced HTTP configuration options for the SDK client.

    This class groups together HTTP/HTTPS-related configuration properties that rarely need to be changed.
    If you need to set these, construct an ``HTTPConfig`` instance and pass it as the ``http`` parameter when
    you construct the main :class:`Config` for the SDK client.
    Nconnect_timeoutread_timeout
http_proxyca_certs	cert_filedisable_ssl_verificationc                 X    || _         || _        || _        || _        || _        || _        y)a  
        :param connect_timeout: The connect timeout for network connections in seconds.
        :param read_timeout: The read timeout for network connections in seconds.
        :param http_proxy: Use a proxy when connecting to LaunchDarkly. This is the full URI of the
          proxy; for example: http://my-proxy.com:1234. Note that unlike the standard ``http_proxy`` environment
          variable, this is used regardless of whether the target URI is HTTP or HTTPS (the actual LaunchDarkly
          service uses HTTPS, but a Relay Proxy instance could use HTTP). Setting this Config parameter will
          override any proxy specified by an environment variable, but only for LaunchDarkly SDK connections.
        :param ca_certs: If using a custom certificate authority, set this to the file path of the
          certificate bundle.
        :param cert_file: If using a custom client certificate, set this to the file path of the
          certificate.
        :param disable_ssl_verification: If true, completely disables SSL verification and certificate
          verification for secure requests. This is unsafe and should not be used in a production environment;
          instead, use a self-signed certificate and set ``ca_certs``.
        N)_HTTPConfig__connect_timeout_HTTPConfig__read_timeout_HTTPConfig__http_proxy_HTTPConfig__ca_certs_HTTPConfig__cert_file%_HTTPConfig__disable_ssl_verification)r   r;   r<   r=   r>   r?   r@   s          r   r   zHTTPConfig.__init__e   s3    . "1*&"$*B'r    r!   c                     | j                   S r#   )rB   r$   s    r   r;   zHTTPConfig.connect_timeout       %%%r    c                     | j                   S r#   )rC   r$   s    r   r<   zHTTPConfig.read_timeout       """r    c                     | j                   S r#   )rD   r$   s    r   r=   zHTTPConfig.http_proxy          r    c                     | j                   S r#   )rE   r$   s    r   r>   zHTTPConfig.ca_certs       r    c                     | j                   S r#   )rF   r$   s    r   r?   zHTTPConfig.cert_file   s    r    c                     | j                   S r#   )rG   r$   s    r   r@   z#HTTPConfig.disable_ssl_verification   s    ...r    )
      NNNF)r1   r2   r3   r4   r6   r   strboolr   r7   r;   r<   r=   r>   r?   r@   r8   r    r   r:   r:   ^   s    )+%'+/)-*.05C"'C$C &c]C $C=	C
 %SMC ,0C< & & & #e # # !HSM ! ! (3-    8C=     /$ / /r    r:   c            >       d   e Zd ZdZdddddddi d	d	d
dd	d	d	 e        e       ddddd	d	ddd	d	 e       d	d	fdedededededede	dede
dee	   deeed egef      dede	dee   ded gef   dee   dee   d e	d!e	d"ed#ed$ee   d%ee   d&e	d'ed(ee   d)ee   d*ed+ee   d,ee
   f<d-Zd.ed/d fd0Zd1 Zed/ee   fd2       Zed/efd3       Zed4        Zed5        Zed6        Zed7        Zed8        Zed/eeed egef      fd9       Zed/e	fd:       Zed/efd;       Zed/efd<       Z ed/e	fd=       Z!ed/efd>       Z"ed/eed gef      fd?       Z#ed/efd@       Z$ed/e	fdA       Z%ed/efdB       Z&ed/efdC       Z'ed/e(e   fdD       Z)ed/e(e   fdE       Z*ed/e	fdF       Z+ed/e	fdG       Z,ed/efdH       Z-ed/efdI       Z.ed/efdJ       Z/ed/efdK       Z0ed/e	fdL       Z1ed/efdM       Z2ed/ee   fdN       Z3ed/ee   fdO       Z4ed/efdP       Z5ed/efdQ       Z6ed/e
fdR       Z7dS Z8y	)TConfiga  Advanced configuration options for the SDK client.

    To use these options, create an instance of ``Config`` and pass it to either :func:`ldclient.set_config()`
    if you are using the singleton client, or the :class:`ldclient.client.LDClient` constructor otherwise.
    zhttps://app.launchdarkly.comzhttps://events.launchdarkly.comi'  r/   zhttps://stream.launchdarkly.comT   N   Fr.   i,  i  sdk_keybase_uri
events_urievents_max_pendingflush_interval
stream_uristreaminitial_reconnect_delaydefaultssend_eventsupdate_processor_classpoll_intervaluse_lddfeature_storeevent_processor_classprivate_attributesprivate_attribute_namesall_attributes_privateofflinecontext_keys_capacitycontext_keys_flush_intervaluser_keys_capacityuser_keys_flush_intervaldiagnostic_opt_outdiagnostic_recording_intervalwrapper_namewrapper_versionhttpbig_segmentsapplicationc                     || _         |j                  d      | _        |j                  d      | _        |j                  d      | _        || _        || _        || _        t        |d      | _	        || _
        |s
t               n|| _        || _        || _        || _        || _        |	| _        |du rd}
|
dn|
| _        |xs || _        || _        || _        ||n|| _        ||n|| _        || _        t        |d      | _        || _        || _        || _        |s
t;               n|| _        t?        |xs i t@              | _!        y)a  
        :param sdk_key: The SDK key for your LaunchDarkly account. This is always required.
        :param base_uri: The base URL for the LaunchDarkly server. Most users should use the default
          value.
        :param events_uri: The URL for the LaunchDarkly events server. Most users should use the
          default value.
        :param events_max_pending: The capacity of the events buffer. The client buffers up to this many
          events in memory before flushing. If the capacity is exceeded before the buffer is flushed, events
          will be discarded.
        :param flush_interval: The number of seconds in between flushes of the events buffer. Decreasing
          the flush interval means that the event buffer is less likely to reach capacity.
        :param stream_uri: The URL for the LaunchDarkly streaming events server. Most users should
          use the default value.
        :param stream: Whether or not the streaming API should be used to receive flag updates. By
          default, it is enabled. Streaming should only be disabled on the advice of LaunchDarkly support.
        :param initial_reconnect_delay: The initial reconnect delay (in seconds) for the streaming
          connection. The streaming service uses a backoff algorithm (with jitter) every time the connection needs
          to be reestablished. The delay for the first reconnection will start near this value, and then
          increase exponentially for any subsequent connection failures.
        :param send_events: Whether or not to send events back to LaunchDarkly. This differs from
          ``offline`` in that it affects only the sending of client-side events, not streaming or polling for
          events from the server. By default, events will be sent.
        :param offline: Whether the client should be initialized in offline mode. In offline mode,
          default values are returned for all flags and no remote network requests are made. By default,
          this is false.
        :param poll_interval: The number of seconds between polls for flag updates if streaming is off.
        :param use_ldd: Whether you are using the LaunchDarkly Relay Proxy in daemon mode. In this
          configuration, the client will not use a streaming connection to listen for updates, but instead
          will get feature state from a Redis instance. The ``stream`` and ``poll_interval`` options will be
          ignored if this option is set to true. By default, this is false.
          For more information, read the LaunchDarkly
          documentation: https://docs.launchdarkly.com/home/relay-proxy/using#using-daemon-mode
        :param array private_attributes: Marks a set of attributes private. Any users sent to LaunchDarkly
          with this configuration active will have these attributes removed. Each item can be either the
          name of an attribute ("email"), or a slash-delimited path ("/address/street") to mark a
          property within a JSON object value as private.
        :param array private_attribute_names: Deprecated alias for ``private_attributes`` ("names" is no longer
          strictly accurate because these could also be attribute reference paths).
        :param all_attributes_private: If true, all user attributes (other than the key) will be
          private, not just the attributes specified in ``private_attributes``.
        :param feature_store: A FeatureStore implementation
        :param context_keys_capacity: The number of context keys that the event processor can remember at any
          one time, so that duplicate context details will not be sent in analytics events.
        :param context_keys_flush_interval: The interval in seconds at which the event processor will
          reset its set of known context keys.
        :param user_keys_capacity: Deprecated alias for ``context_keys_capacity``.
        :param user_keys_flush_interval: Deprecated alias for ``context_keys_flush_interval``.
        :param feature_requester_class: A factory for a FeatureRequester implementation taking the sdk key and config
        :param event_processor_class: A factory for an EventProcessor implementation taking the config
        :param update_processor_class: A factory for an UpdateProcessor implementation taking the sdk key,
          config, and FeatureStore implementation
        :param diagnostic_opt_out: Unless this field is set to True, the client will send
          some diagnostics data to the LaunchDarkly servers in order to assist in the development of future SDK
          improvements. These diagnostics consist of an initial payload containing some details of SDK in use,
          the SDK's configuration, and the platform the SDK is being run on, as well as periodic information
          on irregular occurrences such as dropped events.
        :param diagnostic_recording_interval: The interval in seconds at which periodic diagnostic data is
          sent. The default is 900 seconds (every 15 minutes) and the minimum value is 60 seconds.
        :param wrapper_name: For use by wrapper libraries to set an identifying name for the wrapper
          being used. This will be sent in HTTP headers during requests to the LaunchDarkly servers to allow
          recording metrics on the usage of these wrapper libraries.
        :param wrapper_version: For use by wrapper libraries to report the version of the library in
          use. If ``wrapper_name`` is not set, this field will be ignored. Otherwise the version string will
          be included in the HTTP headers along with the ``wrapper_name`` during requests to the LaunchDarkly
          servers.
        :param http: Optional properties for customizing the client's HTTP/HTTPS behavior. See
          :class:`HTTPConfig`.
        :param application: Optional properties for setting application metadata. See :py:attr:`~application`
        /g      >@TFN<   )"_Config__sdk_keyrstrip_Config__base_uri_Config__events_uri_Config__stream_uri_Config__update_processor_class_Config__stream _Config__initial_reconnect_delaymax_Config__poll_interval_Config__use_lddr   _Config__feature_store_Config__event_processor_class _Config__feature_requester_class_Config__events_max_pending_Config__flush_interval_Config__defaults_Config__send_events_Config__private_attributes_Config__all_attributes_private_Config__offline_Config__context_keys_capacity$_Config__context_keys_flush_interval_Config__diagnostic_opt_out&_Config__diagnostic_recording_interval_Config__wrapper_name_Config__wrapper_version_Config__httpr   _Config__big_segmentsr	   r   _Config__application) r   rZ   r[   r\   r]   r^   r_   r`   ra   rb   rc   rd   re   rf   rg   feature_requester_classrh   ri   rj   rk   rl   rm   rn   ro   rp   rq   rr   rs   rt   ru   rv   rw   s                                    r   r   zConfig.__init__   sY   J !"//#.&--c2&--c2(>%)@&"=$7 =J35P]'<$)@&$6! ."d?K%0%8Tk$6$Q:Q!(>% @R@Z'<`r$LdLl-H  sK*$6!/23PRT/U,*!09E/1<6{7Hb#Nr    new_sdk_keyr!   c                    t        di d|d| j                  d| j                  d| j                  d| j                  d| j
                  d| j                  d| j                  d	| j                  d
| j                  d| j                  d| j                  d| j                  d| j                  d| j                  d| j                  d| j                   d| j"                  d| j$                  d| j&                  d| j(                  d| j*                  d| j,                  d| j.                  d| j0                  d| j2                  d| j4                  S )zReturns a new ``Config`` instance that is the same as this one, except for having a different SDK key.

        :param new_sdk_key: the new SDK key
        rZ   r[   r\   r]   r^   r_   r`   ra   rb   rc   rd   re   rf   rg   r   rh   ri   rk   rl   rm   rn   rq   rr   rs   rt   ru   rv   r8   )rW   r}   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )r   r   s     r   copy_with_new_sdk_keyzConfig.copy_with_new_sdk_key&  s   
  8k 8#8!%!2!28 *.)B)B8 &*%:%:	8
 "&!2!28 "]]8 /3.L.L8  $8 #'"4"48 .2-J-J8 %)$8$88 #nn8 %)$8$88 /3.L.L8 -1,H,H8  *.)B)B!8" .2-J-J#8$ #nn%8& -1,H,H'8( 372T2T)8* *.)B)B+8, 594X4X-8. $(#6#6/80 '+&<&<182  ;;384 $(#6#658 	8r    c                 @    || j                   vr|S | j                   |   S r#   )r   )r   keydefaults      r   get_defaultzConfig.get_defaultH  s!    T__4wN$//#:NNr    c                     | j                   S r#   )r{   r$   s    r   rZ   zConfig.sdk_keyK      ~~r    c                     | j                   S r#   )r}   r$   s    r   r[   zConfig.base_uriO  rO   r    c                 (    | j                   t        z   S r#   )r}   GET_LATEST_FEATURES_PATHr$   s    r   get_latest_flags_urizConfig.get_latest_flags_uriT  s    !999r    c                     | j                   S r#   r~   r$   s    r   events_base_urizConfig.events_base_uriY  rM   r    c                      | j                   dz   S )Nz/bulkr   r$   s    r   r\   zConfig.events_uri^  s      7**r    c                     | j                   S r#   )r   r$   s    r   stream_base_urizConfig.stream_base_uric  rM   r    c                 (    | j                   t        z   S r#   )r   STREAM_FLAGS_PATHr$   s    r   r_   zConfig.stream_urih  s      #444r    c                     | j                   S r#   )r   r$   s    r   rd   zConfig.update_processor_classl      ,,,r    c                     | j                   S r#   )r   r$   s    r   r`   zConfig.streamp  s    }}r    c                     | j                   S r#   )r   r$   s    r   ra   zConfig.initial_reconnect_delayt      ---r    c                     | j                   S r#   )r   r$   s    r   re   zConfig.poll_intervalw      ###r    c                     | j                   S r#   )r   r$   s    r   rf   zConfig.use_ldd{  r   r    c                     | j                   S r#   )r   r$   s    r   rg   zConfig.feature_store  r   r    c                     | j                   S r#   )r   r$   s    r   rh   zConfig.event_processor_class      +++r    c                     | j                   S r#   )r   r$   s    r   r   zConfig.feature_requester_class  r   r    c                     | j                   S r#   )r   r$   s    r   rc   zConfig.send_events  r-   r    c                     | j                   S r#   )r   r$   s    r   r]   zConfig.events_max_pending  r&   r    c                     | j                   S r#   )r   r$   s    r   r^   zConfig.flush_interval  s    $$$r    c                 ,    t        | j                        S r#   )listr   r$   s    r   ri   zConfig.private_attributes  s    D--..r    c                     | j                   S r#   )ri   r$   s    r   rj   zConfig.private_attribute_names  s    &&&r    c                     | j                   S r#   )r   r$   s    r   rk   zConfig.all_attributes_private  r   r    c                     | j                   S r#   )r   r$   s    r   rl   zConfig.offline  r   r    c                     | j                   S r#   )r   r$   s    r   rm   zConfig.context_keys_capacity  r   r    c                     | j                   S r#   )r   r$   s    r   rn   z"Config.context_keys_flush_interval  s    111r    c                     | j                   S )z2Deprecated name for :attr:`context_keys_capacity`.)rm   r$   s    r   ro   zConfig.user_keys_capacity  s     )))r    c                     | j                   S )z8Deprecated name for :attr:`context_keys_flush_interval`.)rn   r$   s    r   rp   zConfig.user_keys_flush_interval  s     ///r    c                     | j                   S r#   )r   r$   s    r   rq   zConfig.diagnostic_opt_out  r&   r    c                     | j                   S r#   )r   r$   s    r   rr   z$Config.diagnostic_recording_interval  s    333r    c                     | j                   S r#   )r   r$   s    r   rs   zConfig.wrapper_name  rK   r    c                     | j                   S r#   )r   r$   s    r   rt   zConfig.wrapper_version  rI   r    c                     | j                   S r#   )r   r$   s    r   ru   zConfig.http  s    {{r    c                     | j                   S r#   )r   r$   s    r   rv   zConfig.big_segments  rK   r    c                     | j                   S )au  
        An object that allows configuration of application metadata.

        Application metadata may be used in LaunchDarkly analytics or other
        product features, but does not affect feature flag evaluations.

        If you want to set non-default values for any of these fields, provide
        the appropriately configured dict to the {Config} object.
        )r   r$   s    r   rw   zConfig.application  s     !!!r    c                     | j                   du r| j                  | j                  dk(  rt        j                  d       y y )NF zMissing or blank sdk_key.)rl   rZ   r   warningr$   s    r   	_validatezConfig._validate  s5    <<5 T\\%9T\\R=OKK34 >Pr    )9r1   r2   r3   r4   setr:   rT   r5   r6   rU   dictr   r   r   r   r   r   r   r   r   r   r7   rZ   r[   r   r   r\   r   r_   rd   r`   ra   re   rf   rg   rh   r   rc   r]   r^   r   ri   rj   rk   rl   rm   rn   ro   rp   rq   rr   rs   rt   ru   rv   rw   r   r8   r    r   rW   rW      s     >!B).'(!B"01 "-1lp&($7;)-MQ.1e365.3$,04759=A*/47-104",,;?-1?COCOCO !CO &)	CO
 "'CO !CO CO +0CO  CO 'tnCO *2(C<;XZi;i2j)kCO !&CO CO !) 6CO  )1(^1K(L!CO" &)X#CO$ +.c(%CO& *.'CO( )CO* ),+CO, /4-CO. &.c]/CO0 ,4E?1CO2 &*3CO4 145CO6  (}7CO8 #+3-9CO: ";CO<  ((9:=CO> 'tn?COJ8 8 8DO #   #   : : ! ! + + ! ! 5 5 -3,:WYh:h1i(j - -    . . .$u $ $    $| $ $ ,x(^9S0T'U , , . . . "T " " )C ) ) % % % /DI / / 'c ' ' - - -    ,s , , 2U 2 2 *C * * 0% 0 0 )D ) ) 4s 4 4 #hsm # # &# & & j   #/ # # 
"T 
" 
"5r    rW   )rW   r   r:   N)r4   typingr   r   r   r   ldclient.feature_storer   ldclient.impl.utilr   r	   ldclient.interfacesr
   r   r   r   r   r   r   r:   rW   __all__r8   r    r   <module>r      sV    1 0 7 = ^ ^.  K" K"Z;/ ;/zE5 E5N
 8r    