
    <iS              	          S r SSKrSSKrSSKrSSKrSSKrSSKrSSKrSSK	r	SSK
Jr  SSKJrJrJrJrJrJrJrJrJr  SSKJr  SSKJr  SSKJr  SS	KJrJrJr  SS
K J!r!J"r"J#r#  SSK$J%r&  SSK$J'r(  Sr)\RT                  " S5      r+S r, " S S\RZ                  R\                  5      r/ " S S\/\5      r0 " S S\/\5      r1 " S S\/5      r2 " S S\/5      r3S r4S r5S r6\Rn                  " S5      r8SSS S!S"S#S$S%S&.r9S' r:g)(z7Base classes for type definitions in the STIX2 library.    N)canonicalize   )	AtLeastOnePropertyErrorDependentPropertiesErrorExtraPropertiesErrorImmutableErrorInvalidObjRefErrorInvalidValueErrorMissingPropertiesError MutuallyExclusivePropertiesError	STIXError)_MarkingsMixin)validate)class_for_type)STIXJSONEncoderfp_serialize	serialize)NOWPREFIX_21_REGEXget_timestamp)new_version)revokez){type} must have {property}='{expected}'.z$00abedb4-aa42-466c-9c01-fed23315a9b7c                 0    S U R                  5        5       $ )Nc              3   P   #    U  H  u  pUR                   (       d  M  Uv   M     g 7fN)required).0kvs      D/home/james-whalen/.local/lib/python3.13/site-packages/stix2/base.py	<genexpr>*get_required_properties.<locals>.<genexpr>!   s     ;,$!

AA,s   &	&)items)
propertiess    r    get_required_propertiesr%       s    ;***,;;    c                      ^  \ rS rSrSrS rSS jrSS jrS rS r	SS jr
S	 rS
 rS rS rU 4S jrS rS rS rS r\S 5       rS rS rS rS rSrU =r$ )	_STIXBase$   z Base class for STIX object typesc                 B   X;  a;  [        US5      (       a*  UR                  5       nU[        :X  a  U R                  nXSU'   SnX;   a   UR	                  X1   U5      u  X1'   nU$ U$ ! [
         a    e [         a$  n[        U R                  U[        U5      S9UeS nAff = f)NdefaultFreason)	hasattrr+   r   _STIXBase__nowcleanr
   	Exception	__class__str)self	prop_namepropkwargsallow_customvalue
has_customexcs           r    _check_property_STIXBase._check_property'   s    "tY''C< JJE$)y!
04

%|1-!: z %   'NNIc#hs   	A& &B:BBc                     U R                  5       n[        [        U5      R                  U5      5      nUS:  d  U(       a  US:X  a  [	        U R
                  U5      eg g )Nr   r   )properties_populatedlensetintersectionr   r2   )r4   list_of_propertiesat_least_onecurrent_propertiescounts        r    $_check_mutually_exclusive_properties._STIXBase._check_mutually_exclusive_propertiesB   sU    !668C*+889KLM19%1*24>>CUVV +5r&   c                 4   Uc>  SS1n[        U [        5      (       a  U1 Sk-  nU R                  R                  5       U-
  nO [        U[        5      (       d  [	        U5      nU(       a0  XR                  5       -  nU(       d  [        U R                  U5      egg)a}  
Check whether one or more of the given properties are present.

:param properties_checked: An iterable of the names of the properties
    of interest, or None to check against a default list.  The default
    list includes all properties defined on the object, with some
    hard-coded exceptions.
:raises AtLeastOnePropertyError: If none of the given properties are
    present.
N
extensionstype>   iddefangedspec_version)
isinstance_Observable_propertieskeysrA   r   r2   )r4   properties_checkedproperty_exceptionsproperties_checked_assigneds       r    _check_at_least_one_property&_STIXBase._check_at_least_one_propertyI   s     %#/"8$,,#'II#!%!1!1!6!6!8;N!N.44!$%7!8*<yy{*J'.-NN$6  / r&   c                     / nU HN  nU HE  nU R                  U5      (       a  M  U R                  U5      (       d  M3  UR                  XE45        MG     MP     U(       a  [        U R                  U5      eg r   )getappendr   r2   )r4   rC   list_of_dependent_propertiesfailed_dependency_pairspdps         r    _check_properties_dependency&_STIXBase._check_properties_dependencyf   sa    "$#A2xx{{txx||+22A7; 3 $ #*4>>;RSS #r&   c                 j    U R                  S/ 5       H  n[        XR                  S5      5        M     g )Ngranular_markings	selectors)rY   r   )r4   ms     r    _check_object_constraints#_STIXBase._check_object_constraintso   s)    -r2AT55-. 3r&   c                    U R                   n[        5       U l        UR                  S0 5      nU(       a   [	        U[
        5      (       d  [        S5      eUR                  S5      n0 nSnU(       ac  UR                  5        HO  u  pU	R                  S5      S:X  d  M  [        USS5      n
U
(       a  UR                  U
R                  5        MM  SnMQ     U(       a  [        5       nO<UR                  5       U R                  R                  5       -
  UR                  5       -
  nU(       a  U(       d  [        X;5      eU(       a  SnXR                  5       -  U R                  R                  5       -
  nU(       aj  [	        U [         R"                  R$                  5      (       dA  U H;  n[&        R(                  " [*        U5      (       a  M%  [-        U R                   US	U-  S
9e   [.        R0                  " U R                  U5      n[.        R0                  " X$5      nUR                  5       UR                  5       U R                  R                  5       -
  U-
  -  n[2        R4                  " U R                  U[7        U5      5      n0 n[9        U5      nU HZ  nUR                  U5      nUS / 4;  a  UUU'   UR                  U5      nU(       d  M;  U R;                  UUUU5      nU=(       d    UnM\     [        [=        U5      5      nUUR                  5       -
  nU(       a  [?        UU5      e/ nUR                  5        HW  u  nn UR@                  (       d?  [C        US5      (       d,  URE                  5       UU   :X  a  URG                  U5        MS  MU  MW  MY     UU l&        UU l'        U RQ                  5         U(       a  UU l)        g U(       a  [U        S5      eSU l)        g ! [H        [J        4 a     M  f = f)Ncustom_propertiesz('custom_properties' must be a dictionaryrJ   Fextension_typeztoplevel-property-extensionz2.1Tz6Property name '%s' must begin with an alpha character.r,   _fixed_valuezMInternal error: a clean() method did not properly enforce allow_custom=False!)+r2   r   r/   poprO   dict
ValueErrorrY   r#   r   update_toplevel_propertiesrA   rR   rQ   r   stix2v20_STIXBase20rematchr   r
   collectionsChainMap	itertoolschainsortedboolr<   r%   r   r   r.   r+   rZ   AttributeErrorKeyError_defaulted_optional_properties_innerre   _STIXBase__has_customr   )r4   r8   r7   clscustom_propsrJ   #registered_toplevel_extension_props#has_unregistered_toplevel_extensionext_idextregistered_ext_classcustom_kwargsall_custom_prop_namesr5   defined_propertiesassigned_propertiestoplevel_extension_propsproperty_ordersetting_kwargsr:   prop_valr6   temp_customrequired_propertiesmissing_kwargs	defaultednames                              r    __init___STIXBase.__init__s   s   nn #_
zz"5r:
< > >GHH ZZ-
.0+.3+)//177+,0MM+9|,( ,;BB0EE ?C;  2 /EM #KKMD,<,<,A,A,CC5::<=M &s::L!.1B1B1D!D!!#!$ dEII$9$9::!6I88OY??/ NNI#[^g#g  "7 )11A
 *226H $G#K#K#M{{}t//4466F$H "$()
 /0
'I*..y9Hbz),4y)%)))4Dt"22t^\ (6;
 ( "#$67
 -~/B/B/DD(n== 	,224JD$gdN.K.KLLNnT&::$$T* ; /L 5 /8+$&&( *D * 
 !&D- #H- s   A
OO21O2c                      U R                   U   $ r   )r~   )r4   keys     r    __getitem___STIXBase.__getitem__   s    {{3r&   c                 ,    [        U R                  5      $ r   )iterr~   r4   s    r    __iter___STIXBase.__iter__   s    DKK  r&   c                 ,    [        U R                  5      $ r   )r@   r~   r   s    r    __len___STIXBase.__len__   s    4;;r&   c                     SU R                   ;  nU(       d  X;   a  U R                  U5      $ [        SU R                  R                  < SU< S35      e)Nr~   'z' object has no attribute ')__dict__r   r{   r2   __name__)r4   r   
unpicklings      r    __getattr___STIXBase.__getattr__  sK     T]]2
dl##D))^^$$d,
 	
r&   c                    > UR                  S5      (       d  [        U R                  U5      e[        [        U ]  X5        g )N_)
startswithr   r2   superr(   __setattr__)r4   r   r9   r2   s      r    r   _STIXBase.__setattr__  s2    s## 66i*47r&   c                 "    U R                  5       $ r   r   r   s    r    __str___STIXBase.__str__  s    ~~r&   c           	          SR                  U  Vs/ s H  o SX   < 3PM     sn5      nU R                  R                   SU S3$ s  snf )Nz, =())joinr2   r   )r4   r   propss      r    __repr___STIXBase.__repr__  sM    		t<t!S$'-t<=..))*!E7!44 =s   Ac                     [         R                  " U R                  U5      n[        U 5      n[	        U [
        5      (       a  SS0US'   U" SSS0UD6$ )N*_valid_refsr8   T )copydeepcopyr~   rK   rO   rP   )r4   memo	new_innerr   s       r    __deepcopy___STIXBase.__deepcopy__  sM    MM$++t4	4jdK(((+SzIm$22	22r&   c                 H    [        U R                  R                  5       5      $ r   )listr~   rR   r   s    r    r?   _STIXBase.properties_populated(  s    DKK$$&''r&   c                     U R                   $ r   )r   r   s    r    r:   _STIXBase.has_custom+  s       r&   c                     [        U 40 UD6$ r   )_new_version)r4   r7   s     r    r   _STIXBase.new_version1  s    D+F++r&   c                     [        U 5      $ r   )_revoker   s    r    r   _STIXBase.revoke4  s    t}r&   c                      [        U /UQ70 UD6$ )a  
Serialize a STIX object.

Examples:
    >>> import stix2
    >>> identity = stix2.Identity(name='Example Corp.', identity_class='organization')
    >>> print(identity.serialize(sort_keys=True))
    {"created": "2018-06-08T19:03:54.066Z", ... "name": "Example Corp.", "type": "identity"}
    >>> print(identity.serialize(sort_keys=True, indent=4))
    {
        "created": "2018-06-08T19:03:54.066Z",
        "id": "identity--d7f3e25a-ba1c-447a-ab71-6434b092b05e",
        "identity_class": "organization",
        "modified": "2018-06-08T19:03:54.066Z",
        "name": "Example Corp.",
        "type": "identity"
    }

Returns:
    str: The serialized JSON object.

See Also:
    ``stix2.serialization.serialize`` for options.
r   r4   argsr7   s      r    r   _STIXBase.serialize7  s    2 ////r&   c                 "    [        U /UQ70 UD6  g)am  
Serialize a STIX object to ``fp`` (a text stream file-like supporting object).

Examples:
    >>> import stix2
    >>> identity = stix2.Identity(name='Example Corp.', identity_class='organization')
    >>> print(identity.serialize(sort_keys=True))
    {"created": "2018-06-08T19:03:54.066Z", ... "name": "Example Corp.", "type": "identity"}
    >>> print(identity.serialize(sort_keys=True, indent=4))
    {
        "created": "2018-06-08T19:03:54.066Z",
        "id": "identity--d7f3e25a-ba1c-447a-ab71-6434b092b05e",
        "identity_class": "organization",
        "modified": "2018-06-08T19:03:54.066Z",
        "name": "Example Corp.",
        "type": "identity"
    }
    >>> with open("example.json", mode="w", encoding="utf-8") as f:
    >>>     identity.fp_serialize(f, pretty=True)

Returns:
    None

See Also:
    ``stix2.serialization.fp_serialize`` for options.
N)r   r   s      r    r   _STIXBase.fp_serializeR  s    6 	T+D+F+r&   )__has_custom__nowr}   r~   )Tr   )F)r   
__module____qualname____firstlineno____doc__r<   rG   rV   r_   re   r   r   r   r   r   r   r   r   r   r?   propertyr:   r   r   r   r   __static_attributes____classcell__r2   s   @r    r(   r(   $   s    *6W:T/E&N ! 
8
 53( ! !
,06, ,r&   r(   c                       \ rS rSrSrg)_DomainObjectip  r   Nr   r   r   r   r   r   r&   r    r   r   p      r&   r   c                       \ rS rSrSrg)_RelationshipObjectit  r   Nr   r   r&   r    r   r   t  r   r&   r   c                   @   ^  \ rS rSrU 4S jrS rU 4S jrS rSrU =r	$ )rP   ix  c                 \   > UR                  S/ 5      U l        [        [        U ]  " S0 UD6  g )Nr   r   )rk   _STIXBase__valid_refsr   rP   r   )r4   r7   r2   s     r    r   _Observable.__init__z  s(    %+ZZr%B"k4)3F3r&   c           	         SU R                   ;   a  gXR                   ;  a  [        U R                  USU-  5      e UR                  R                  n  U R                   U   R                  nU(       a&  XT;  a   [        U R                  USU< SU< S35      egg! [
         a    UR                  n Naf = f! [
         a    U R                   U   n Nef = f! [         a#    [        SU R                  R                  -  5      ef = f)zd
Only for checking `*_ref` or `*_refs` properties in spec_version 2.0
STIX Cyber Observables (SCOs)
r   Nz)'%s' is not a valid object in local scopez<'%s' must be created with _valid_refs as a dict, not a list.zobject reference 'z' is of an invalid type 'r   )
r   r	   r2   	containedvalid_typesr{   rK   	TypeErrorrm   r   )r4   refr6   r5   allowed_typesref_types         r    
_check_ref_Observable._check_ref  s    $,,,000$T^^Y@knq@qrr	- NN66M	w;55c:?? ,(z}  @H  EI  J  J -   	- ,,M	- " ;55c:; 	w[^b^l^l^u^uuvv	ws5   B B7 B43B47CC CC -Dc                 ^  > [         [        U ]  XX45      nX;   a  SSKJn  UR                  S5      (       a(  [        X&5      (       a  X1   nU R                  XrU5        U$ UR                  S5      (       a8  [        UR                  U5      (       a  X1    H  nU R                  XrU5        M     U$ )Nr   )ObjectReferenceProperty_ref_refs)	r   rP   r<   r$   r   endswithrO   r   r   )	r4   r5   r6   r7   r8   r:   r   r   r2   s	           r    r<   _Observable._check_property  s    ;=ivd
;!!&))d<< +COOCy9  ##G,,dnn.EFF%09=  1 r&   c                 L   Sn0 nU R                    H>  nX0;   d  M
  X   nUS:X  a  [        U5      nUc  [        XS5      eO[        U5      nXRU'   M@     U(       aJ  [	        USS9n[
        R                  " [        U5      nSR                  U R                  [        U5      5      nU$ )z
Generate a UUIDv5 for this observable, using its "ID contributing
properties".

:return: The ID, or None if no ID contributing properties are set
NhasheszNo hashes givenF)utf8z{}--{})_id_contributing_properties_choose_one_hashr
   _make_json_serializabler   uuiduuid5SCO_DET_ID_NAMESPACEformat_typer3   )r4   id_json_serializable_objectr   	obj_valueserializable_valuedatauuid_s           r    _generate_id_Observable._generate_id  s     #% 33C{ I	(?)9))D&)1/ '8  2 *A)K&0B-! 4$ $ 8uEDJJ3T:E//$**c%j9C
r&   )r   )
r   r   r   r   r   r   r<   r
  r   r   r   s   @r    rP   rP   x  s    4
J: # #r&   rP   c                   (   ^  \ rS rSrU 4S jrSrU =r$ )
_Extensioni  c                 J   > [         [        U ]  5         U R                  5         g r   )r   r  re   rV   )r4   r2   s    r    re   $_Extension._check_object_constraints  s    j$9;))+r&   r   )r   r   r   r   re   r   r   r   s   @r    r  r    s    , ,r&   r  c                     SU ;   a  SU S   0$ SU ;   a  SU S   0$ SU ;   a  SU S   0$ SU ;   a  SU S   0$ [        [        U 5      S 5      nUb  XU   0$ g )NMD5zSHA-1zSHA-256zSHA-512)nextr   )	hash_dictr   s     r    r   r     s    	y'((	I	7+,,	i	9Y/00	i	9Y/00i$'=|$$r&   c                     [        U S[        R                  5      [        R                  La  U R                  " U40 UD6  g g )Nr   )getattrobjectr   )r   objr7   s      r    	_cls_initr    s2    sJ0GS#F# Hr&   c                 .   U c  [        S5      eU n[        U [        R                  R                  5      (       a0  U R                  5        VVs0 s H  u  p#U[        U5      _M     nnnU$ [        U [        5      (       a  U  Vs/ s H  n[        U5      PM     nnU$ [        U [        [        [        [        45      (       dI  [        R                  " U S[        S9n[        U5      S:  a   US   S:X  a  US   S:X  a  [!        USS 5      nU$ s  snnf s  snf )	a$  
Make the given value JSON-serializable; required for the JSON canonicalizer
to work.  This recurses into lists/dicts, converts stix objects to dicts,
etc.  "Convenience" types this library uses as property values are
JSON-serialized to produce a JSON-serializable value.  (So you will always
get strings for those.)

The conversion will not affect the passed in value.

:param value: The value to make JSON-serializable.
:return: The JSON-serializable value.
:raises ValueError: If value is None (since nulls are not allowed in STIX
    objects).
z)Illegal null value found in a STIX objectF)ensure_asciir      r   "r   )rm   rO   ru   abcMappingr#   r   r   intfloatr3   rz   jsondumpsr   r@   _un_json_escape)r9   
json_valuer   r   s       r    r   r     s    }DEEJ%0011 
% &q))% 	 
4 + 
E4	 	  
 $A& 	 
(  UC677 ZZEO

 z?a1$B3)>(Ab)9:J5

s   DDz\\.r  \/
	)r  r&  r'  bfnrtc                 6    S n[         R                  X5      nU$ )a^  
Removes JSON string literal escapes.  We should undo these things Python's
serializer does, so we can ensure they're done canonically.  The
canonicalizer should be in charge of everything, as much as is feasible.

:param json_string: String literal output of Python's JSON serializer,
    minus the surrounding quotes.
:return: The unescaped string
c                     [         R                  U R                  S5      S   5      nUc  [        SU R                  S5      -   5      eU$ )Nr   r   zUnrecognized JSON escape: )_JSON_ESCAPE_MAPrY   grouprm   )rd   replacements     r    replace _un_json_escape.<locals>.replace@  sC    &**1771:a=99AGGAJFGGr&   )_JSON_ESCAPE_REsub)json_stringr7  results      r    r$  r$  5  s       6FMr&   );r   ru   collections.abcr   rw   rs   r   
simplejsonr"  rp   #stix2.canonicalization.Canonicalizer   
exceptionsr   r   r   r   r	   r
   r   r   r   markingsr   markings.utilsr   registryr   serializationr   r   r   utilsr   r   r   
versioningr   r   r   r   DEFAULT_ERRORUUIDr  r%   r  r  r(   r   r   rP   r  r   r  r   compiler9  r4  r$  r   r&   r    <module>rJ     s    =     	    <  
 % $ $ C C 6 6 3 );yy!GH <I,'' I,X
	I~ 		)^ 	W) Wt, ,"$
/d **V$ 

							 r&   