
    <i                         S SK r SSKJrJr  SSKJr  SSKJr  SSKJ	r	J
r
JrJr  SSKJr  SS jrS	 r\R"                  4S
 jr\R"                  4S jr\R"                  4S jr\R"                  4S jrg)    N   )registryversion)_DomainObject)DuplicateRegistrationError)ListPropertyObjectReferencePropertyReferenceProperty_validate_type)PREFIX_21_REGEXc                    U(       a  [         nO[        nU R                  5        H  u  p4UR                  SS5      S   nUS:X  a-  [	        XB5      (       d  [        U< SUR                  < S35      eUS:X  d  MU  [	        U[        5      (       a  [	        UR                  U5      (       a  M  [        U< SUR                  < S35      e   g	)
as  
Validate that reference properties contain an expected type.

Properties ending in "_ref/s" need to be instances of specific types to
meet the specification requirements. For 2.0 and 2.1 conformance, these
properties are expected to be implemented with `ReferenceProperty` (or a
subclass thereof), except for the special case of STIX 2.0 observables
which must be implemented with `ObjectReferenceProperty`.

Args:
    props_map (mapping): A mapping of STIX object properties to be checked.
    is_observable20 (bool): Flag for the STIX 2.0 observables special case.

Raises:
    ValueError: If the properties do not conform.
_r   refz= is named like a reference property but is not a subclass of .refsz^ is named like a reference list property but is not a 'ListProperty' containing a subclass of N)	r	   r
   itemsrsplit
isinstance
ValueError__name__r   	contained)	props_mapis_observable20ref_prop_type	prop_nameprop_objtails         L/home/james-whalen/.local/lib/python3.13/site-packages/stix2/registration.py_validate_ref_propsr       s    " /)(0	Q'+5=H!D!D-  !!.!7!7 :!=  V^x..8--}==-  ==J=S=S<VVWY   1    c                     US:w  aG  U R                  5        H3  u  p4[        R                  " [        U5      (       a  M'  [	        SU-  5      e   [        U 40 UD6  g)ak  
Validate that a map of properties is conformant for this STIX `version`.

Args:
    props_map (mapping): A mapping of STIX object properties to be checked.
    version (str): Which STIX2 version the properties must confirm to.
    kwargs (mapping): Arguments to pass on to specific property validators.

Raises:
    ValueError: If the properties do not conform.
2.0z6Property name '%s' must begin with an alpha character.N)r   rematchr   r   r    )r   r   kwargsr   
prop_values        r   _validate_propsr(   2   sR     %%.__%6!I88OY77 !Y\e!eff &7 	,V,r!   c                 `   [        U [        5      (       d  [        SU R                  -  5      eU(       d  UR                  n[        U R                  U5        [        R                  U   S   nU R                  UR                  5       ;   a  [        SU R                  5      eXU R                  '   g)a  Register a custom STIX Object type.

Args:
    new_type (class): A class to register in the Object map.
    version (str): Which STIX2 version to use. (e.g. "2.0", "2.1"). If
        None, use latest version.

Raises:
    ValueError: If the class being registered wasn't created with the
        @CustomObject decorator.
    DuplicateRegistrationError: If the class has already been registered.

z6'%s' must be created with the @CustomObject decorator.objectszSTIX ObjectN)
issubclassr   r   r   DEFAULT_VERSIONr(   _propertiesr   STIX2_OBJ_MAPS_typekeysr   )new_typer   OBJ_MAPs      r   _register_objectr3   G   s     h..D
 	

 ))H(('2%%g.y9G~~'(GG&HNNr!   c                     U(       d  UR                   nU R                  n[        X!5        [        U R                  U5        [
        R                  U   S   nX#R                  5       ;   a  [        SU5      eXU'   g)zRegister a custom STIX Marking Definition type.

Args:
    new_marking (class): A class to register in the Marking map.
    version (str): Which STIX2 version to use. (e.g. "2.0", "2.1"). If
        None, use latest version.

markingszSTIX MarkingN)	r,   r/   r   r(   r-   r   r.   r0   r   )new_markingr   	mark_typeOBJ_MAP_MARKINGs       r   _register_markingr9   g   sn     ))!!I9&K++W5--g6zBO((**(CC!,Ir!   c                 
   U(       d  UR                   n[        U R                  UUS:H  S9  [        R                  U   S   nU R
                  UR                  5       ;   a  [        SU R
                  5      eXU R
                  '   g)zRegister a custom STIX Cyber Observable type.

Args:
    new_observable (class): A class to register in the Observables map.
    version (str): Which STIX2 version to use. (e.g. "2.0", "2.1"). If
        None, use latest version.

r#   )r   observableszCyber ObservableN)r,   r(   r-   r   r.   r/   r0   r   )new_observabler   OBJ_MAP_OBSERVABLEs      r   _register_observabler>   }   s     ))""G E)
 "009-H16688();^=Q=QRR/=~++,r!   c                    U R                   n[        X!5        US:X  a:  UR                  S5      (       d$  UR                  S5      (       d  [	        SU-  5      e[        U SS5      n[        U R                  (       + USL=(       a    U(       + 45      (       a  [	        SU-   5      e[        U R                  40 U=(       d
    [        5       D6n[        XA5        [        R                  U   S   nX%;   a  [        S	U5      eXU'   g)
zRegister a custom extension to any STIX Object type.

Args:
    new_extension (class): A class to register in the Extensions map.
    version (str): Which STIX2 version to use. (e.g. "2.0", "2.1").
        Defaults to the latest supported version.

z2.1z-extzextension-definition--zdInvalid extension type name '%s': must end with '-ext' or start with 'extension-definition--<UUID>'._toplevel_propertiesNz6Invalid extension: must define at least one property: 
extensions	Extension)r/   r   endswith
startswithr   getattranyr-   dictr(   r   r.   r   )new_extensionr   ext_typetl_propscombined_propsEXT_MAPs         r   _register_extensionrM      s	    ""H8%%!!&))X-@-@AY-Z-Zv 
 }&<dCH

 %%%-X   D
 	

 -33L8JDFLNN,%%g.|<G(h??%Hr!   )F)r$    r   r   baser   
exceptionsr   
propertiesr   r	   r
   r   utilsr   r    r(   r,   r3   r9   r>   rM    r!   r   <module>rT      sl    	   2  ##L-* (/'>'> '@ ,3+B+B -, 291H1H >0 #22+&r!   