
    5i                     \   d Z ddlmZmZmZmZ ddlZddlmZm	Z	m
Z
mZmZmZ ddlmZmZ ddZd	 Z	 	 	 	 	 	 	 	 dd
Z	 	 	 	 	 	 	 ddZd Zd Z	 	 	 	 ddZ	 	 	 	 	 	 	 ddZ	 	 	 	 	 	 ddZ	 	 	 	 	 	 	 ddZd dZd dZd dZd dZd!dZd"dZ 	 	 d#dZ!	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZ"d$dZ#y)%a]  
This module provides methods for finding existing objects and entities in the
DNAnexus Platform. The :func:`~dxpy.bindings.search.find_data_objects` function
provides search functionality over all data objects in the system. The
:func:`~dxpy.bindings.search.find_jobs` function can be used to find jobs
(whether they are running, failed, or done).
    )print_functionunicode_literalsdivisionabsolute_importN   )DXAppletDXApp
DXWorkflow	DXProjectDXJob
DXAnalysis   )DXErrorDXSearchErrorc                 v   t        |t              r
|dk  s|dkD  rt        d      i }|r|j                  d|i       |r|j                  d|i       g }t	        dt        |       |      D ]L  }|j                  d| |||z    i       |j                  t        j                  j                  |      d          N |S )a  
    :param objects: Data object specifications, each with fields "name"
                    (required), "folder", and "project"
    :type objects: list of dictionaries
    :param project: ID of project context; a data object's project defaults
                    to this if not specified for that object
    :type project: string
    :param folder: Folder path within the project; a data object's folder
                   path defaults to this if not specified for that object
    :type folder: string
    :param batchsize: Number of objects to resolve in each batch call to
                      system_resolve_data_objects; defaults to 1000 and is
                      only used for testing (must be a positive integer not
                      exceeding 1000)
    :type batchsize: int
    :returns: List of results parallel to input objects, where each
              entry is a list containing 0 or more dicts, each corresponding
              to a resolved object
    :rtype: List of lists of dictionaries

    Each returned element is a list of dictionaries with keys "project" and
    "id". The number of dictionaries for each element may be 0, 1, or more.
    r     zPbatchsize for resolve_data_objects must be a positive integer not exceeding 1000projectfolderobjectsresults)

isinstanceint
ValueErrorupdaterangelenextenddxpyapisystem_resolve_data_objects)r   r   r   	batchsizeargsr   is          v/home/marpiech/ifpan-abm-pgxpred/analysis/marpiech-gwas-test/venv/lib/python3.12/site-packages/dxpy/bindings/search.pyresolve_data_objectsr%       s    0 i%a9t;KkllDY()Xv&'G 1c'lI. NY1Y; 89:txx;;DA)LMN N    c              +     
K   d}d|vr||d<   	  | |fi |}|j                  d      
|j                  d      
fd}|d   D ]  }	||k(  r y|dz  } ||	        |d	   |d	   |d
<   t        |d   dz  d      |d<   nyww)z Takes an API method handler (dxpy.api.find*) and calls it with *query*,
    and then wraps a generator around its output. Used by the methods below.

    Note that this function may only be used for /system/find* methods.
    r   limitbyParentdescribec                 l    r)t        j                  | d   | j                  d            } | fS | S )Nidr   )r   )r   get_handlerget)result	by_parentdescriptionsreturn_handlers    r$   format_resultz_find.<locals>.format_resultY   s=    ))&,

9@UV$y,66r&   r   Nr   nextstartingr   r   )r.   min)
api_methodqueryr(   r2   first_page_sizekwargsnum_resultsrespr3   r#   r0   r1   s      `      @@r$   _findr=   I   s      Ke(g
%*6*HHZ(	xx
+	 i 	#Ae#1K""		# <# $VE* w!148E'N1 s   BB	c                    i }| | |d<   |||d<   |||d<   |0|dk(  r||d<   n%|dk(  rd|i|d<   n|dk(  rd|i|d<   nt        d      |||d	<   |||d
<   ||t        d      |||d<   |d|i|d<   |	|	|d<   |
d|
i|d<   |||d   d<   |R||d   d<   nI||Et        j                  *dt        j                  i|d<   |||d   d<   |||d   d<   nt        d      ||Si |d<   |%t        j                  j	                  |      |d   d<   |%t        j                  j	                  |      |d   d<   ||Si |d<   |%t        j                  j	                  |      |d   d<   |%t        j                  j	                  |      |d   d<   |	|dur||d<   |||d<   |||d<   |||d<   |||d<   t        t        j                  j                  ||||fi |S )aX  
    :param classname:
        Class with which to restrict the search, i.e. one of "record",
        "file", "applet", "workflow", "database"
    :type classname: string
    :param state: State of the object ("open", "closing", "closed", "any")
    :type state: string
    :param visibility: Visibility of the object ("hidden", "visible", "either")
    :type visibility: string
    :param name: Name of the object (also see *name_mode*)
    :type name: string
    :param name_mode: Method by which to interpret the *name* field ("exact": exact match, "glob": use "*" and "?" as wildcards, "regexp": interpret as a regular expression)
    :type name_mode: string
    :param properties: Properties (key-value pairs) that each result must have (use value True to require the property key and allow any value)
    :type properties: dict
    :param typename: Type constraint that each result must conform to
    :type typename: string or dict
    :param tag: Tag that each result must be tagged with (deprecated in favor of *tags*)
    :type tag: string
    :param tags: List of tags that each result must have ALL of
    :type tags: list of strings
    :param link: ID of an object that each result must link to
    :type link: string
    :param project: ID of a project in which each result must appear
    :type project: string
    :param folder: If *project* is given, full path to a folder in which each result must belong (default is the root folder)
    :type folder: string
    :param recurse: If *project* is given, whether to look in subfolders of *folder* as well (default is True)
    :type recurse: boolean
    :param modified_after: Timestamp after which each result was last modified (see note below for interpretation)
    :type modified_after: int or string
    :param modified_before: Timestamp before which each result was last modified (see note below for interpretation)
    :type modified_before: int or string
    :param created_after: Timestamp after which each result was last created (see note below for interpretation)
    :type created_after: int or string
    :param created_before: Timestamp before which each result was last created (see note below for interpretation)
    :type created_before: int or string
    :param describe: Controls whether to also return the output of
        calling describe() on each object. Supply False to omit describe
        output, True to obtain the default describe output, or a dict to
        be supplied as the describe call input (which may, among other
        things, be used to customize the set of fields that is returned)
    :type describe: bool or dict
    :param level: The minimum permissions level for which results should be returned (one of "VIEW", "UPLOAD", "CONTRIBUTE", or "ADMINISTER")
    :type level: string
    :param region: Filter on result set by the given region(s).
    :type region: string or list of strings
    :param archival_state: Filter by the given archival state (one of "archived", "live", "archival", "unarchiving", or "any"). Requires classname="file", project, and folder arguments to be provided.
    :type archival_state: string 
    :param limit: The maximum number of results to be returned (if not specified, the number of results is unlimited)
    :type limit: int
    :param first_page_size: The number of results that the initial API call will return. Subsequent calls will raise this by multiplying by 2 up to a maximum of 1000.
    :type first_page_size: int
    :param return_handler: If True, yields results as dxpy object handlers (otherwise, yields each result as a dict with keys "id" and "project")
    :type return_handler: boolean
    :rtype: generator

    Returns a generator that yields all data objects matching the query,
    up to *limit* objects. It transparently handles paging through the
    result set if necessary. For all parameters that are omitted, the
    search is not restricted by the corresponding field.

    .. note:: All timestamps must be supplied as one of the following:

       * A nonnegative integer, interpreted as milliseconds since the Epoch
       * A negative integer, interpreted as an offset in milliseconds relative
         to the current time
       * A string containing a negative integer with one of the suffixes
         "s", "m", "d", "w", or "y" (for seconds, minutes, days, weeks,
         or years), interpreted as an offset from the current time.

       The following examples both find all items that were created more
       than 1 week ago::

           items1 = list(find_data_objects(created_before="-1w"))
           items2 = list(find_data_objects(created_before=-7*24*60*60*1000))

    This example iterates through all files with property
    "project" set to "cancer project" and prints their object IDs:

      for result in find_data_objects(classname="file", properties={"project": "cancer project"}):
          print "Found a file with object id " + result["id"]

    classstate
visibilityexactnameglobregexpz@find_data_objects: Unexpected value found for argument name_mode
propertiestypezEfind_data_objects: Arguments "tag" and "tags" cannot both be providedtag$andtagslinkr   scoper   recursezFCannot search within a folder or recurse if a project is not specifiedmodifiedafterbeforecreatedFr*   levelregionarchivalStater(   )r   r   WORKSPACE_IDutilsnormalize_time_inputr=   r   system_find_data_objects)	classnamer@   rA   rC   	name_moderF   typenamerH   rJ   rK   r   r   rM   modified_aftermodified_beforecreated_aftercreated_beforer*   r(   rR   rS   archival_stater2   r9   r:   r8   s                             r$   find_data_objectsra   n   s   | E"gg(l E&M& #TNE&M("%t,E&M\]](l f
4+]^^
eff#W-g'-E'N8$(/E'N9%		w2('):):;E'N!+1gx(",3gy)bcc!_%@j%)-)H)H)XE*g&&*.***I*I/*ZE*h' N$>i$(,

(G(G(VE)W%%)-)H)H)XE)X& 5$jg h!!/og22E5.Ralekllr&   c                    i }| | |d<   |||d<   |4t        |t        t        t        f      r|j	                         |d<   n||d<   |)t        |t
              r|j	                         |d<   n||d<   |||d<   |)t        |t              r|j	                         |d<   n||d<   |B|rt        d      |d	k(  rd|d
<   n1t        |t              r|j	                         |d
<   n||d
<   n|rd|d
<   |B|	rt        d      |d	k(  rd|d<   n1t        |t              r|j	                         |d<   n||d<   n|	rd|d<   |
/t        |
t        t        f      r|
j	                         |d<   n|
|d<   ||Si |d<   |%t        j                  j                  |      |d   d<   |%t        j                  j                  |      |d   d<   |	|dur||d<   |0|dk(  r||d<   n%|dk(  rd|i|d<   n|dk(  rd|i|d<   nt        d      |d|i|d<   |||d<   |dur||d<   |||d<   |||d<   t        t        j                  j                  ||||fi |S )a  
    :param classname:
        Class with which to restrict the search, i.e. one of "job",
        "analysis"
    :type classname: string
    :param launched_by: User ID of the user who launched the execution's origin execution
    :type launched_by: string
    :param executable: ID of the applet or app that spawned this execution, or a corresponding remote object handler
    :type executable: string or a DXApp/DXApplet/DXWorkflow instance
    :param project: ID of the project context for the execution
    :type project: string
    :param state: State of the execution (e.g. "failed", "done")
    :type state: string
    :param origin_job: ID of the original job that eventually spawned this execution (possibly by way of other executions)
    :type origin_job: string
    :param parent_job: ID of the parent job (deprecated: use the string 'none' to indicate it should have no parent job; use *no_parent_job* instead)
    :type parent_job: string
    :param no_parent_job: Indicate results should have no parent job; cannot be set to True with *parent_job* set to a string
    :type no_parent_job: boolean
    :param parent_analysis: ID of the parent analysis (deprecated: use the string 'none' to indicate it should have no parent analysis; use *no_parent_analysis* instead)
    :type parent_analysis: string
    :param no_parent_analysis: Indicate results should have no parent analysis; cannot be set to True with *parent_analysis* set to a string
    :type no_parent_job: boolean
    :param root_execution: ID of the top-level (user-initiated) execution (job or analysis) that eventually spawned this execution (possibly by way of other executions)
    :type root_execution: string
    :param created_after: Timestamp after which each result was last created (see note accompanying :meth:`find_data_objects()` for interpretation)
    :type created_after: int or string
    :param created_before: Timestamp before which each result was last created (see note accompanying :meth:`find_data_objects()` for interpretation)
    :type created_before: int or string
    :param describe: Controls whether to also return the output of
        calling describe() on each execution. Supply False to omit
        describe output, True to obtain the default describe output, or
        a dict to be supplied as the describe call input (which may be
        used to customize the set of fields that is to be returned; for
        example, you can supply {"io": False} to suppress detailed
        information about the execution's inputs and outputs)
    :type describe: bool or dict
    :param name: Name of the job or analysis to search by (also see *name_mode*)
    :type name: string
    :param name_mode: Method by which to interpret the *name* field ("exact": exact match, "glob": use "*" and "?" as wildcards, "regexp": interpret as a regular expression)
    :type name_mode: string
    :param tags: List of tags that each result must have ALL of
    :type tags: list of strings
    :param properties: Properties (key-value pairs) that each result must have (use value True to require the property key and allow any value)
    :type properties: dict
    :param limit: The maximum number of results to be returned (if not specified, the number of results is unlimited)
    :type limit: int
    :param first_page_size: The number of results that the initial API call will return. Subsequent calls will raise this by multiplying by 2 up to a maximum of 1000.
    :type first_page_size: int
    :param return_handler: If True, yields results as dxpy object handlers (otherwise, yields each result as a dict with keys "id" and "project")
    :type return_handler: boolean
    :param include_subjobs: If False, no subjobs will be returned by the API
    :type include_subjobs: boolean
    :param include_restarted: If True, API response will include restarted jobs and job trees rooted in restarted jobs
    :type include_restarted: boolean
    :rtype: generator

    Returns a generator that yields all executions (jobs or analyses) that match the query. It transparently handles
    paging through the result set if necessary. For all parameters that are omitted, the search is not restricted by
    the corresponding field.

    The following example iterates through all finished jobs and analyses in a
    particular project that were launched in the last two days::

      for result in find_executions(state="done", project=proj_id, created_after="-2d"):
          print "Found job or analysis with object id " + result["id"]

    Nr?   
launchedBy
executabler   r@   	originJobzHfind_executions: Cannot provide parent_job and set no_parent_job to Truenone	parentJobzRfind_executions: Cannot provide parent_analysis and set no_parent_analysis to TrueparentAnalysisrootExecutionrQ   rO   rP   Fr*   rB   rC   rD   rE   z>find_executions: Unexpected value found for argument name_moderI   rJ   rF   TincludeSubjobsincludeRestartedr(   )r   r   r	   r
   get_idr   r   r   r   r   rV   rW   r=   r   system_find_executions)rY   launched_byrd   r   r@   
origin_job
parent_jobno_parent_jobparent_analysisno_parent_analysisroot_executionr^   r_   r*   rC   rZ   rJ   rF   r(   r9   r2   include_subjobsinclude_restartedr:   r8   s                            r$   find_executionsrw     s   X E"g)lj8UJ"?@","3"3"5E,",E,gy)&~~/E)&E)gj%(!+!2!2!4E+!+E+dee!%E+
E*!+!2!2!4E+!+E+	!k"noof$&*E"#4&5&<&<&>E"#&5E"#	"&!nuj&9:%3%:%:%<E/"%3E/" N$>i$(,

(G(G(VE)W%%)-)H)H)XE)X& 5$j E&M& #TNE&M("%t,E&MZ[[f(ld""1$$5 !g00%P_jcijjr&   c                  "    d|d<   t        | i |S )zg
    This method is identical to :meth:`find_executions()` with the class constraint set to "job".
    jobrY   rw   r"   r:   s     r$   	find_jobsr|     s      F;D+F++r&   c                  "    d|d<   t        | i |S )zl
    This method is identical to :meth:`find_executions()` with the class constraint set to "analysis".
    analysisrY   rz   r{   s     r$   find_analysesr     s     %F;D+F++r&   c                    i }| 0|dk(  r| |d<   n%|dk(  rd| i|d<   n|dk(  rd| i|d<   nt        d      |||d<   |d|i|d<   |||d	<   |	|d
ur||d<   |||d<   |||d<   |	|
Si |d<   |	%t        j                  j                  |	      |d   d<   |
%t        j                  j                  |
      |d   d<   |||d<   |||d<   |||d<   |||d<   |||d<   t	        t        j
                  j                  ||||fi |S )a  
    :param name: Name of the project (also see *name_mode*)
    :type name: string
    :param name_mode: Method by which to interpret the *name* field ("exact": exact match, "glob": use "*" and "?" as wildcards, "regexp": interpret as a regular expression)
    :type name_mode: string
    :param properties: Properties (key-value pairs) that each result must have (use value True to require the property key and allow any value)
    :type properties: dict
    :param tags: Tags that each result must have
    :type tags: list of strings
    :param level: One of "VIEW", "UPLOAD", "CONTRIBUTE", or "ADMINSTER". If specified, only returns projects where the current user has at least the specified permission level.
        If not specified the default value is "CONTRIBUTE" for the API method /system/findProjects
    :type level: string
    :param describe: Controls whether to also return the output of
        calling describe() on each project. Supply False to omit
        describe output, True to obtain the default describe output, or
        a dict to be supplied as the describe call input (which may be
        used to customize the set of fields that is returned)
    :type describe: bool or dict
    :param explicit_perms: Filter on presence of an explicit permision. If True, matching projects must have an explicit permission (any permission granted directly to the user or an organization to which the user belongs). If False, matching projects must not have any explicit permissions for the user. (default is None, for no filter)
    :type explicit_perms: boolean or None
    :param region: If specified, only returns projects where the project is in the given region.
    :type region: string
    :param public: Filter on the project being public. If True, matching projects must be public. If False, matching projects must not be public. (default is None, for no filter)
    :type public: boolean or None
    :param created_after: Timestamp after which each result was created
        (see note accompanying :meth:`find_data_objects()` for interpretation)
    :type created_after: int or string
    :param created_before: Timestamp before which each result was created
        (see note accompanying :meth:`find_data_objects()` for interpretation)
    :type created_before: int or string
    :param billed_to: Entity ID (user or organization) that pays for the project's storage costs
    :type billed_to: string
    :param limit: The maximum number of results to be returned (if not specified, the number of results is unlimited)
    :type limit: int
    :param first_page_size: The number of results that the initial API call will return. Subsequent calls will raise this by multiplying by 2 up to a maximum of 1000.
    :type first_page_size: int
    :param return_handler: If True, yields results as dxpy object handlers (otherwise, yields each result as a dict with keys "id" and "project")
    :type return_handler: boolean
    :param containsPHI: If set to true, only returns projects that contain PHI.
        If set to false, only returns projects that do not contain PHI.
    :type containsPHI: boolean
    :param externalUploadRestricted: If set to true, only returns projects with externalUploadRestricted enabled. 
        If set to false, only returns projects that do not have externalUploadRestricted enabled. 
    :type externalUploadRestricted: boolean
    :rtype: generator

    Returns a generator that yields all projects that match the query.
    It transparently handles paging through the result set if necessary.
    For all parameters that are omitted, the search is not restricted by
    the corresponding field.

    You can use the *level* parameter to find projects that the user has
    at least a specific level of access to (e.g. "CONTRIBUTE").

    rB   rC   rD   rE   z<find_projects: Unexpected value found for argument name_moderF   rI   rJ   rR   Fr*   explicitPermissionpublicrQ   rO   rP   rS   billTor(   containsPHIexternalUploadRestricted)r   r   rV   rW   r=   r   system_find_projects)rC   rZ   rF   rJ   rR   r*   explicit_permsrS   r   r^   r_   	billed_tor(   r2   r9   r   r   r:   r8   s                      r$   find_projectsr     s   v E E&M& #TNE&M("%t,E&MXYY(lfg 5$j!&4"# h N$>i$(,

(G(G(VE)W%%)-)H)H)XE)X& h#hg*m+,D()..unohaghhr&   c                 ^   i }|0|dk(  r||d<   n%|dk(  rd|i|d<   n|dk(  rd|i|d<   nt        d      |||d<   |||d<   |||d<   |||d	<   |||d
<   |||d<   ||Si |d<   |%t        j                  j                  |      |d   d<   |%t        j                  j                  |      |d   d<   |	|
Si |d<   |	%t        j                  j                  |	      |d   d<   |
%t        j                  j                  |
      |d   d<   |	|dur||d<   |||d<   t	        | ||||fi |S )a  
    :param method: Name of the API method used to find the global executable (app or a global workflow).
    :type name: function
    :param name: Name of the app or a global workflow (also see *name_mode*)
    :type name: string
    :param name_mode: Method by which to interpret the *name* field ("exact": exact match, "glob": use "*" and "?" as wildcards, "regexp": interpret as a regular expression)
    :type name_mode: string
    :param category: If specified, only returns executables that are in the specified category
    :type category: string
    :param all_versions: Whether to return all versions of each app/global workflow or just the version tagged "default"
    :type all_versions: boolean
    :param published: If specified, only returns results that have the specified publish status (True for published apps/global workflows, False for unpublished ones)
    :type published: boolean
    :param billed_to: Entity ID (user or organization) that pays for the storage costs of the app/global workflow
    :type billed_to: string
    :param created_by: If specified, only returns versions that were created by the specified user (of the form "user-USERNAME")
    :type created_by: string
    :param developer: If specified, only returns apps or global workflows for which the specified user (of the form "user-USERNAME") is a developer
    :type developer: string
    :param created_after: Timestamp after which each result was last created (see note accompanying :meth:`find_data_objects()` for interpretation)
    :type created_after: int or string
    :param created_before: Timestamp before which each result was last created (see note accompanying :meth:`find_data_objects()` for interpretation)
    :type created_before: int or string
    :param modified_after: Timestamp after which each result was last modified (see note accompanying :meth:`find_data_objects()` for interpretation)
    :type modified_after: int or string
    :param modified_before: Timestamp before which each result was last modified (see note accompanying :meth:`find_data_objects()` for interpretation)
    :type modified_before: int or string
    :param describe: Controls whether to also return the output of
        calling describe() on each executable. Supply False to omit describe
        output, True to obtain the default describe output, or a dict to
        be supplied as the describe call input (which may be used to
        customize the set of fields that is returned)
    :type describe: bool or dict
    :param limit: The maximum number of results to be returned (if not specified, the number of results is unlimited)
    :type limit: int
    :param first_page_size: The number of results that the initial API call will return. Subsequent calls will raise this by multiplying by 2 up to a maximum of 1000.
    :type first_page_size: int
    :param return_handler: If True, yields results as dxpy object handlers (otherwise, yields each result as a dict with keys "id" and "project")
    :type return_handler: boolean
    :rtype: generator

    Returns a generator that yields all global executables (either apps or
    global workflows) that match the query. It transparently handles paging through
    the result set if necessary. For all parameters that are omitted, the search is
    not restricted by the corresponding field.

    rB   rC   rD   rE   zFfind_global_executables: Unexpected value found for argument name_modecategoryallVersions	publishedr   	createdBy	developerrN   rO   rP   rQ   Fr*   r(   )r   r   rV   rW   r=   )methodrC   rZ   r   all_versionsr   r   
created_byr   r^   r_   r\   r]   r*   r(   r2   r9   r:   r8   s                      r$   find_global_executablesr     s   n E E&M& #TNE&M("%t,E&Mbcc$j+m&k#h'k&k!_%@j%)-)H)H)XE*g&&*.***I*I/*ZE*h' N$>i$(,

(G(G(VE)W%%)-)H)H)XE)X& 5$jg~Q&QQr&   c                     t        t        j                  j                  fi d| d|d|d|d|d|d|d|d	|d
|	d|
d|d|d|d|d||S )z
    This method is identical to :meth:`find_global_executables()` with the API method
    used: :meth:`system_find_apps()`.
    rC   rZ   r   r   r   r   r   r   r^   r_   r\   r]   r*   r(   r2   r9   )r   r   r   system_find_appsrC   rZ   r   r   r   r   r   r   r^   r_   r\   r]   r*   r(   r2   r9   r:   s                    r$   	find_appsr   ~  s     #488#<#< N(,N8ANLTN0<NHQN .7N DNN ZcN 2?	N P^	N
 3AN
 SbN -5N =BN SaN 4CfN Nr&   c                     t        t        j                  j                  fi d| d|d|d|d|d|d|d|d	|d
|	d|
d|d|d|d|d||S )z
    This method is identical to :meth:`find_global_executables()` with the API method
    used: :meth:`system_find_global_workflows()`.
    rC   rZ   r   r   r   r   r   r   r^   r_   r\   r]   r*   r(   r2   r9   )r   r   r   system_find_global_workflowsr   s                    r$   find_global_workflowsr     s     #488#H#H M'+M7@MKSM/;MGPM -6M CMM YbM 1>	M O]	M
 2@M
 RaM ,4M <AM R`M 3BVM Mr&   c                     t        |t              st        d      |rdnd|d<    | di |}t        |d       }||ry t	        dt        |      z         |s%t        |d       }|t	        dt        |      z         |S )NzK_find_one: Unexpected value found for argument zero_ok, it should be a boolr   r   r(   z%Expected one result, but found none: z%Expected one result, but found more:  )r   boolr   r4   r   str)r   zero_okmore_okr:   responser/   result2s          r$   	_find_oner     s    gt$cdd"aF7OH(D!F~ GF STTx& GF STTMr&   c                 (    t        t        f| |d|S )a  
    :param zero_ok:
        If False (default), :class:`~dxpy.exceptions.DXSearchError` is
        raised if the search has 0 results; if True, returns None if the
        search has 0 results
        If not boolean, :class:`~dxpy.exceptions.DXError` is raised
    :type zero_ok: bool
    :param more_ok:
        If False, :class:`~dxpy.exceptions.DXSearchError` is raised if
        the search has 2 or more results
    :type more_ok: bool

    Returns one data object that satisfies the supplied constraints, or
    None if none exist (provided *zero_ok* is True). Supports all search
    constraint arguments supported by :meth:`find_data_objects()`.

    r   r   )r   ra   r   r   r:   s      r$   find_one_data_objectr     s    $ &SSFSSr&   c                 (    t        t        f| |d|S )a  
    :param zero_ok:
        If False (default), :class:`~dxpy.exceptions.DXSearchError` is
        raised if the search has 0 results; if True, returns None if the
        search has 0 results
        If not boolean, :class:`~dxpy.exceptions.DXError` is raised
    :type zero_ok: bool
    :param more_ok:
        If False, :class:`~dxpy.exceptions.DXSearchError` is raised if
        the search has 2 or more results
    :type more_ok: bool

    Returns one project that satisfies the supplied constraints, or None
    if none exist (provided *zero_ok* is True). Supports all search
    constraint arguments supported by :meth:`find_projects()`.

    r   )r   r   r   s      r$   find_one_projectr     s    $ ]OGWOOOr&   c                 (    t        t        f| |d|S )a  
    :param zero_ok:
        If False (default), :class:`~dxpy.exceptions.DXSearchError` is
        raised if the search has 0 results; if True, returns None if the
        search has 0 results
        If not boolean, :class:`~dxpy.exceptions.DXError` is raised
    :type zero_ok: bool
    :param more_ok:
        If False, :class:`~dxpy.exceptions.DXSearchError` is raised if
        the search has 2 or more results
    :type more_ok: bool

    Returns one app that satisfies the supplied constraints, or None if
    none exist (provided *zero_ok* is True). Supports all search
    constraint arguments supported by :meth:`find_apps()`.

    r   )r   r   r   s      r$   find_one_appr     s    $ YKKFKKr&   c              #      K   d|vrt        |d      |d<   	  | ||      }|d   D ]  }|  |d   |d   |d<   t        |d   dz  d      |d<   ny<w)aX  
    Takes an API method handler ``dxpy.api.org_find...`` and calls it with
    *org_id* and *query*, then wraps a generator around its output. Used by
    :meth:`org_find_members` and :meth:`org_find_projects` below.

    :param first_page_size: The number of results that the initial API call will return.
    :type first_page_size: int

    r(   r   r   r4   Nr5   r   )r6   )r7   org_idr8   r9   r<   r/   s         r$   	_org_findr     s      e_d3g
&%(9o 	FL	 <# $VE* w!!3T:E'N s   AAc                 h    i }|||d<   ||d<   t        t        j                  j                  | |      S )a  
    :param org_id: ID of the organization
    :type org_id: string
    :param level: The membership level in the org that each member in the result set must have (one of "MEMBER" or
        "ADMIN")
    :type level: string
    :param describe: Whether or not to return the response of ``dxpy.api.user_describe`` for each result. False omits
        the describe response; True includes it; a dict will be used as the input to ``dxpy.api.user_describe`` (to
        customize the desired set of fields in the describe response).
    :type describe: bool or dict

    Returns a generator that yields all org members that match the query formed by intersecting all specified
    constraints. The search is not restricted by any parameters that were unspecified.
    rR   r*   )r   r   r   org_find_members)r   rR   r*   r8   s       r$   r   r     s;     Eg E*TXX..>>r&   c                    i }|0|dk(  r||d<   n%|dk(  rd|i|d<   n|dk(  rd|i|d<   nt        d      |||d<   |Lt        |j                               dk(  r||d<   n*d	|j                         D cg c]	  \  }}||i c}}i|d<   |t        |      dk(  r	|d
   |d<   nd	|i|d<   ||d<   |||d<   ||	Si |d<   |%t        j
                  j                  |      |d   d<   |	%t        j
                  j                  |	      |d   d<   |
|
|d<   |||d<   t        t        j                  j                  | |      S c c}}w )a  
    :param org_id: ID of the organization
    :type org_id: string
    :param name: Name that each result must have (also see *name_mode* param)
    :type name: string
    :param name_mode: Method by which to interpret the *name* param ("exact": exact match,
        "glob": use "*" and "?" as wildcards, "regexp": interpret as a regular expression)
    :type name_mode: string
    :param ids: List of project IDs. Each result must have a project ID that was specified in this list.
    :type ids: array of strings
    :param properties: Properties (key-value pairs) that each result must have
        (use value True to require the property key and allow any value)
    :type properties: dict
    :param tags: Tags that each result must have
    :type tags: list of strings
    :param describe: Whether or not to return the response of ``dxpy.api.project_describe`` for each result. False
        omits the describe response; True includes it; a dict will be used as the input to
        ``dxpy.api.project_describe`` (to customize the desired set of fields in the describe response).
    :type describe: bool or dict
    :param public: True indicates that each result must be public; False indicates that each result must be private;
        None indicates that both public and private projects will be returned in the result set.
    :type public: boolean or None
    :param created_after: Timestamp after which each result was created
        (see note accompanying :meth:`find_data_objects()` for interpretation)
    :type created_after: int or string
    :param created_before: Timestamp before which each result was created
        (see note accompanying :meth:`find_data_objects()` for interpretation)
    :type created_before: int or string
    :param region: If specified, only returns projects where the project is in the given region.
    :type region: string
    :param containsPHI: If set to true, only returns projects that contain PHI.
        If set to false, only returns projects that do not contain PHI.
    :type containsPHI: boolean
    :rtype: generator

    Returns a generator that yields all projects that match the query formed by intersecting all specified
    constraints. The search is not restricted by any parameters that were unspecified.

    rB   rC   rD   rE   z@org_find_projects: Unexpected value found for argument name_moder,   r   rF   rI   r   rJ   r*   r   rQ   rO   rP   rS   r   )
r   r   keysitemsr   rV   rW   r   r   org_find_projects)r   rC   rZ   idsrF   rJ   r*   r   r^   r_   rS   r   r8   kvs                  r$   r   r   (  s   R E E&M& #TNE&M("%t,E&M\]]
dz !Q&",E,#)AQAQAS+Tv1QF+T"UE,t9> GE&M#TNE&M E* h N$>i$(,

(G(G(VE)W%%)-)H)H)XE)X& h*mTXX//??) ,Us   4E c                    i }|0|dk(  r||d<   n%|dk(  rd|i|d<   n|dk(  rd|i|d<   nt        d      |||d<   |||d<   |||d<   |||d	<   |||d
<   |||d<   ||Si |d<   |%t        j                  j                  |      |d   d<   |%t        j                  j                  |      |d   d<   |	|
Si |d<   |	%t        j                  j                  |	      |d   d<   |
%t        j                  j                  |
      |d   d<   |	|dur||d<   |||d<   t	        t        j
                  j                  | |      S )a  
    :param name: Name of the app (also see *name_mode*)
    :type name: string
    :param name_mode: Method by which to interpret the *name* field
        "exact": exact match,
        "glob": use "*" and "?" as wildcards,
        "regexp": interpret as a regular expression
    :type name_mode: string
    :param category: If specified, only returns apps that are in the specified category
    :type category: string
    :param all_versions: Whether to return all versions of each app or just the version tagged "default"
    :type all_versions: boolean
    :param published: If specified, only returns results that have the specified publish status
        True for published apps,
        False for unpublished apps
    :type published: boolean
    :param created_by: If specified, only returns app versions that were created by the specified user
        (of the form "user-USERNAME")
    :type created_by: string
    :param developer: If specified, only returns apps for which the specified user (of the form "user-USERNAME")
        is a developer
    :type developer: string
    :param authorized_user: If specified, only returns apps for which the specified user (either a user ID, org ID,
        or the string "PUBLIC") appears in the app's list of authorized users
    :type authorized_user: string
    :param created_after: Timestamp after which each result was last created (see note accompanying
        :meth:`find_data_objects()` for interpretation)
    :type created_after: int or string
    :param created_before: Timestamp before which each result was last created (see note accompanying
        :meth:`find_data_objects()` for interpretation)
    :type created_before: int or string
    :param modified_after: Timestamp after which each result was last modified (see note accompanying
        :meth:`find_data_objects()` for interpretation)
    :type modified_after: int or string
    :param modified_before: Timestamp before which each result was last modified (see note accompanying
        :meth:`find_data_objects()` for interpretation)
    :type modified_before: int or string
    :param describe: Controls whether to also return the output of
        calling describe() on each app. Supply False to omit describe
        output, True to obtain the default describe output, or a dict to
        be supplied as the describe call input (which may be used to
        customize the set of fields that is returned)
    :type describe: bool or dict
    :param limit: The maximum number of results to be returned (if not specified, the number of results is unlimited)
    :type limit: int
    :param first_page_size: The number of results that the initial API call will return. Subsequent calls will raise
        this by multiplying by 2 up to a maximum of 1000.
    :type first_page_size: int
    :param return_handler: If True, yields results as dxpy object handlers (otherwise, yields each result as a dict
        with keys "id" and "project")
    :type return_handler: boolean
    :rtype: generator

    Returns a generator that yields all apps that match the query. It
    transparently handles paging through the result set if necessary.
    For all parameters that are omitted, the search is not restricted by
    the corresponding field.

    rB   rC   rD   rE   z8find_apps: Unexpected value found for argument name_moder   r   r   r   r   authorizedUserrN   rO   rP   rQ   Fr*   r(   )r   r   rV   rW   r   r   org_find_apps)r   rC   rZ   r   r   r   r   r   authorized_userr^   r_   r\   r]   r*   r(   r2   r9   r:   r8   s                      r$   r   r   x  s   \ E E&M& #TNE&M("%t,E&MTUU$j+m&k'k&k""1!_%@j%)-)H)H)XE*g&&*.***I*I/*ZE*h' N$>i$(,

(G(G(VE)W%%)-)H)H)XE)X& 5$jgTXX++VU;;r&   c                 R    t        t        j                  j                  | dd|      S )a  
    :param query: The input to the /system/findOrgs API method.
    :type query: dict

    :param first_page_size: The number of results that the initial
        /system/findOrgs API call will return; default 10, max 1000. Subsequent
        calls will raise the number of returned results exponentially up to a
        max of 1000.
    :type first_page_size: int

    :rtype: generator

    Returns a generator that yields all orgs matching the specified query. Will
    transparently handle pagination as necessary.
    NF)r(   r2   r9   )r=   r   r   system_find_orgs)r8   r9   s     r$   	find_orgsr     s(      **E %H Hr&   )NNr   )NNNNrB   NNNNNNNNNNNNFNNNNFd   )NNNNNNNFNFNNNFNrB   NNNr   FTN)NrB   NNNFNNNNNNNFr   NN)NrB   NNNNNNNNNNFNFr   )FT)r   )NNF)NNrB   NNNFNNNNN)
   )$__doc__
__future__r   r   r   r   r    r   r	   r
   r   r   r   
exceptionsr   r   r%   r=   ra   rw   r|   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r&   r$   <module>r      s]  " S R  G G /&R#J >B?C48DH;?9=EIQT`mF PTPUSWFKTXOS&*Ykv,, GKJNRVtxbiH LP9=GK?CAEGL,/^R@ 6:+/9=1537PSN& BF7;EI=A?CEJ*-M(&T*P*L*4?. qveiM@b ## ! "& $!%!%"& !&"%!u<nHr&   