
    Vf:                     >   d dl Z d dlZd dlZd dlZd dlZd dlmZ d dlmZ d dlm	Z	m
Z
 d dlmZ d dlZddlmZ ddlmZ dd	lmZ dd
lmZ ddlmZ  e       Z e j2                         Zd Zd Zd Zd Zd Zd Z d Z!d Z"d Z#d Z$	 	 	 	 	 	 	 	 	 	 ddZ%d Z&d Z'd Z(y)    N)fnmatch)Path)isfilejoin)parse_qs   )	_validate)AttributeDict)get_relative_path)context_value)get_appc           	         t         j                  }g d}| j                  d      d   }g }t        j                  j                  |      r8t        j                  |      D cg c]  }t        t        ||            s| }}d}d}|D ]W  }|j                  d      \  }	}
}|j                         |v s+|	|k(  s|	|j                  dd      k(  r|c S |	dk(  r|}|	dk(  sV|}Y |r|S |S c c}w )	z
    Return:
    - A page specific image: `assets/<module>.<extension>` is used, e.g. `assets/weekly_analytics.png`
    - A generic app image at `assets/app.<extension>`
    - A logo at `assets/logo.<extension>`
    )apngavifgifjpegjpgpngsvgwebp.N_-applogo)CONFIGassets_foldersplitospathexistslistdirr   r   	partitionlowerreplace)moduler   valid_extensionspage_idfiles_in_assetsfapp_file	logo_filefnfn_without_extensionr   	extensions               T/var/www/html/software/conda/envs/catlas/lib/python3.12/site-packages/dash/_pages.py_infer_imager2      s     ((MSll3#GO	ww~~m$zz-0
F4q;Q4RA
 
 HI -/\\#->*a?? 00$/'7??3+DD	#u,#v-	 /
s   !C(<C(c                 f    | j                  d      d   j                  dd      j                         S )Nr   r   r    )r   r&   
capitalizemodule_names    r1   _module_name_to_page_namer8   ?   s.    S!"%--c37BBDD    c                    |t         j                  rot        t        t         j                        j                        }| j                  |      d   j                  dd      j                  dd      j                         }nH| j                  dd      j                  dd      j                         }nt        j                  dd|      }|j                  d      sd|z   }|S |}|S )Nr   r   r   r   /<.*?>none)r   pages_folderstrr   namer   r&   r%   resub
startswith)r7   templatepages_moduler!   s       r1   _infer_pathrF   C   s    tF$7$78==>L!!,/3c"c"	  &&sC088cBHHJD vvgvx0!__S13:DK 8<DKr9   c                     | t         j                  v xr3 t        t         j                  |    j                        j                  dk(  S )Nz__init__.py)sysmodulesr   __file__r@   r6   s    r1   _module_name_is_packagerK   W   s;    s{{" 	J[)22388MIr9   c                     t        |       j                  dd      j                  t        j                        j                  t        j                  d      S )N.py r   )r?   r&   stripr    sep)r!   s    r1   _path_to_module_namerQ   ^   s9    t9UB'--bff5==bffcJJr9   c                    | j                  t        j                        d   }t        |      }t        j
                  j                  t        j                        }t        j                  j                  |      rt        j                  t        |      d  }nt        j                  }t        |      }| d| }t        t        j                        rt        j                   d| }|S )Nr   r   )r   r   r>   rQ   flaskhelpersget_root_pathr@   rC   lenrK   )	page_pathrelative_pathr'   	proj_rootparent_pathparent_moduler7   s          r1   _infer_module_namer\   b   s    OOF$7$78<M!-0F++FKK8I%%i0))#i.*:;))(5M"O1VH-Kv{{+Q{m4r9   c                     | rt        |       dkD  r| d   dk(  r| dd  } ni S i }t        |       j                         D ]  \  }}t        |      dk(  r|d   n|}|||<   ! |S )Nr   ?r   )rV   r   items)search	parsed_qskvs       r1   _parse_query_stringrd   s   sv    #f+/fQi3&6	I6"((* AFaKAaDQ	! r9   c                 .   t        j                  dd|      }t        j                  dd|      }t        | |      syt        j                  d|      }t        j                  ||       }t	        |d   t
              r|d   n|}t        t        ||            S )z
    creates the dict of path variables passed to the layout
    e.g. path_template= "/asset/<asset_id>"
         if pathname provided by the browser is "/assets/a100"
         returns **{"asset_id": "a100"}
    r<   *z(.*)Nz<(.*?)>r   )rA   rB   r   findall
isinstancetupledictzip)pathnamepath_templatewildcard_patternvar_pattern	var_names	variabless         r1   _parse_path_variablesrr      s     vvgsM:&&&-8K 8-. 

9m4I 

;1I *9Q< ?	!YIIy)**r9   c                       fd}|S )Nc                  2    t        j                   d      S )Ni-  )code)rS   redirect)redirect_tos   r1   rv   z+_create_redirect_function.<locals>.redirect   s    ~~k44r9    )rw   rv   s   ` r1   _create_redirect_functionry      s    5 Or9   c           
          t               }| rZt        |       rN| D ]H  }|j                  |      }|j                  j	                  ||t        |j                  |                   J y y y )N)r   rV   r   serveradd_url_rulery   )redirect_fromr!   r   rv   fullnames        r1   _set_redirectr      sd    
)C]+% 	H,,X6HJJ##)#*?*?*EF	 ,}r9   c           
         t        j                         j                  d      ryt        j                  t               t        t        j                  |       ||||nt        | |      |||n
t        |             }|j                  |||n|d           |j                  d|r|nd|||
d| |j                  |||n
t        |       |       |j                  t        |	|d	         
       |t        | <   |d   rt        j                  |d          |
|
t        |    d<   t        d t        j                         D              }t        j                         D ]'  }|d	   dk(  r|sdn|d   |d<   t!        |d	         |d<   ) t#        t        j                         d       D ]  }t        j%                  |d           y)a  
    Assigns the variables to `dash.page_registry` as an `OrderedDict`
    (ordered by `order`).

    `dash.page_registry` is used by `pages_plugin` to set up the layouts as
    a multi-page Dash app. This includes the URL routing callbacks
    (using `dcc.Location`) and the HTML templates to include title,
    meta description, and the meta description image.

    `dash.page_registry` can also be used by Dash developers to create the
    page navigation links or by template authors.

    - `module`:
       The module path where this page's `layout` is defined. Often `__name__`.

    - `path`:
       URL Path, e.g. `/` or `/home-page`.
       If not supplied, will be inferred from the `path_template` or `module`,
       e.g. based on path_template: `/asset/<asset_id` to `/asset/none`
       e.g. based on module: `pages.weekly_analytics` to `/weekly-analytics`

    - `relative_path`:
        The path with `requests_pathname_prefix` prefixed before it.
        Use this path when specifying local URL paths that will work
        in environments regardless of what `requests_pathname_prefix` is.
        In some deployment environments, like Dash Enterprise,
        `requests_pathname_prefix` is set to the application name,
        e.g. `my-dash-app`.
        When working locally, `requests_pathname_prefix` might be unset and
        so a relative URL like `/page-2` can just be `/page-2`.
        However, when the app is deployed to a URL like `/my-dash-app`, then
        `relative_path` will be `/my-dash-app/page-2`.

    - `path_template`:
       Add variables to a URL by marking sections with <variable_name>. The layout function
       then receives the <variable_name> as a keyword argument.
       e.g. path_template= "/asset/<asset_id>"
            then if pathname in browser is "/assets/a100" then layout will receive **{"asset_id":"a100"}

    - `name`:
       The name of the link.
       If not supplied, will be inferred from `module`,
       e.g. `pages.weekly_analytics` to `Weekly analytics`

    - `order`:
       The order of the pages in `page_registry`.
       If not supplied, then the filename is used and the page with path `/` has
       order `0`

    - `title`:
       (string or function) The name of the page <title>. That is, what appears in the browser title.
       If not supplied, will use the supplied `name` or will be inferred by module,
       e.g. `pages.weekly_analytics` to `Weekly analytics`

    - `description`:
       (string or function) The <meta type="description"></meta>.
       If not supplied, then nothing is supplied.

    - `image`:
       The meta description image used by social media platforms.
       If not supplied, then it looks for the following images in `assets/`:
        - A page specific image: `assets/<module>.<extension>` is used, e.g. `assets/weekly_analytics.png`
        - A generic app image at `assets/app.<extension>`
        - A logo at `assets/logo.<extension>`
        When inferring the image file, it will look for the following extensions:
        APNG, AVIF, GIF, JPEG, JPG, PNG, SVG, WebP.

    -  `image_url`:
       Overrides the image property and sets the `<image>` meta tag to the provided image URL.

    - `redirect_from`:
       A list of paths that should redirect to this page.
       For example: `redirect_from=['/v2', '/v3']`

    - `layout`:
       The layout function or component for this page.
       If not supplied, then looks for `layout` from within the supplied `module`.

    - `**kwargs`:
       Arbitrary keyword arguments that can be stored

    ***

    `page_registry` stores the original property that was passed in under
    `supplied_<property>` and the coerced property under `<property>`.
    For example, if this was called:
    ```
    register_page(
        'pages.historical_outlook',
        name='Our historical view',
        custom_key='custom value'
    )
    ```
    Then this will appear in `page_registry`:
    ```
    OrderedDict([
        (
            'pages.historical_outlook',
            dict(
                module='pages.historical_outlook',

                supplied_path=None,
                path='/historical-outlook',

                supplied_name='Our historical view',
                name='Our historical view',

                supplied_title=None,
                title='Our historical view'

                supplied_layout=None,
                layout=<function pages.historical_outlook.layout>,

                custom_key='custom value'
            )
        ),
    ])
    ```
    ignore_register_pageN)r'   supplied_pathrm   r!   supplied_namer@   r@   )supplied_titletitlerN   )descriptionordersupplied_ordersupplied_layout)supplied_imageimage	image_urlr!   )r}   rm   layoutc              3   *   K   | ]  }|d    du  yw)r   Nrx   ).0ps     r1   	<genexpr>z register_page.<locals>.<genexpr>\  s       ,-
4's   r;   r   r   r   rX   c                     | d   d u t        | d   t        t        f      r| d   n
t        d      t        | d         | d   fS )Nr   infr'   )rh   intfloatr?   )is    r1   <lambda>zregister_page.<locals>.<lambda>j  sE    gJ$$QwZ#u>AgJE%L'
OhK	
 r9   )keyr'   rx   )r   getr	   validate_use_pagesr   rj   validate_module_namerF   r8   updater2   r   PAGE_REGISTRYvalidate_templateanyvaluesr   sortedmove_to_end)r'   r!   rm   r@   r   r   r   r   r   r}   r   kwargspageorder_suppliedr   s                  r1   register_pager      s   J 56  (--f5#%T;v}+M%T+DV+LD 	KK)utF|   DKK #.KB	
  	KK)u|F/C  
 	KKmM4<HKI M&O##D$9:*0fh'  1>1E1E1G N !!# :6c!.Aa@P>Q 	
'
 /qy9/	: 
 	2 	!!$x.1	2r9   c                     d }t         j                         D ]L  }|d   r(|d   j                  d      }t        | |      }|r||fc S | |d   j                  d      k(  sH||fc S  i d fS )Nrm   r;   r!   )r   r   rO   rr   )path_idpath_variablesr   template_ids       r1   _path_to_pager   t  s    N$$& ( /55c:K27KHN^++d6l((--''( t8Or9   c                    t        t        j                  j                  j	                  d            \  }}|j                  dd      }|r| j                  |      }|r:dj                  t        j                  j                  |j                  d      g      nd }|j                  d      }|r|n|}|j                  d| j                        }t        |      r|r |di |n |       }|j                  dd      }t        |      r|r |di |n |       }d|ddd	d
dt        j                  j                  d
d|d
d|d
d|xs dd
d|d
ddd
d|d
d|xs dd
g
S )Nr;   r   rN   r   r   r   )r@   contentztwitter:cardsummary_large_image)propertyr   ztwitter:urlztwitter:titleztwitter:descriptionztwitter:imagezog:titlezog:typewebsitezog:descriptionzog:imagerx   )r   rS   requestr!   rO   r   get_asset_urlr   url_rootlstripr   callableurl)	r   
start_pager   r   assets_image_urlsupplied_image_urlr   r   r   s	            r1   _page_meta_tagsr     s\   !.u}}/A/A/G/G/L!MJ NN7B'E!!%(@E''c):;<4  $4&8">NINN7CII.E+9''uw..3K7Ek3N3;= ;7#0EF"u}}/@/@A$7*{C$bAE295%+>IO< r9   c                 p   t        j                  |       D ]  \  }}}|D cg c](  }|j                  d      r|j                  d      r'|* c}|d d  |D ]H  }|j                  d      s"|j                  d      s|j                  d      s8t         j                  j                  ||      }t        |d      5 }|j                         }d|vr
	 d d d        	 d d d        t        |      }	t        j                  j                  |	|      }
t        j                  j                  |
      }|
j                  j                  |       |t        j                   |	<   |	t"        v st"        |	   d   rt%        j&                  |	|       t)        |d      t"        |	   d<   K  y c c}w # 1 sw Y   xY w)	Nr   r   rM   zutf-8)encodingr   r   r   )r    walkrC   endswithr!   r   openreadr\   	importlibutilspec_from_file_locationmodule_from_specloaderexec_modulerH   rI   r   r	   validate_pages_layoutgetattr)r>   rootdirsfilesdfilerW   r+   r   r7   specpage_modules               r1   _import_layouts_from_pagesr     st   WW\2 VdE"V!,,s*;ALLQTDU1VQ 	VDs#ts';4==QVCWT40Ii'2 a&&("'1 1
 -Y7K>>99+yQD#..99$?KKK##K0'2CKK$ },%k23DE//[I7>{H7Uk*84)	VVV
 s   F'F'F'<F,,F5)
NNNNNNNNNN))collectionsr   r    rA   rH   r   pathlibr   os.pathr   r   urllib.parser   rS   rN   r	   _utilsr
   
_get_pathsr   _callback_contextr   _get_appr   r   OrderedDictr   r2   r8   rF   rK   rQ   r\   rd   rr   ry   r   r   r   r   r   rx   r9   r1   <module>r      s      	 	 
     !   ! ) ,  
''')$NE(K"
+6	 
	


C2L
 FVr9   