
    ` IeIc                     X   d Z ddlmZ ddlmZ ddlZddlZddlmZm	Z	m
Z
mZmZmZmZmZmZmZ ddlmZmZmZmZmZ d Zd Zd	 Zd
 Zd Zd Zd Z ddl!Z!	 ddl"m#Z$ d Z%d Z&d Z'd#dZ(d Z)d$dZ*d Z+d%dZ,d$dZ-d Z.d Z/d Z0d&dZ1d Z2	 	 	 	 d'dZ3dZ4d  Z5d(d!Z6d(d"Z7y#  d Z$Y LxY w))z&
Utilities to build a namespace view.
    )print_function)isliceN)
NUMERIC_TYPES	INT_TYPES
TEXT_TYPESto_text_stringis_text_stringis_type_text_stringis_binary_stringPY2to_binary_string	iteritems)bs4
FakeObjectnumpypandasPILc                     t         j                  t         j                  t         j                  t         j                  t         j
                  t         j                  t         j                  t         j                  t         j                  t         j                  t         j                  t         j                  t         j                  t         j                  fS N)npint64int32int16int8uint64uint32uint16uint8float64float32float16	complex64
complex128bool_     =/usr/lib/python3/dist-packages/spyder_kernels/utils/nsview.pyget_numeric_numpy_typesr(       sc    HHbhh"''299biiIIrxxRZZLL"--3 3r&   c                    t         j                  t        urQ	 t        | t         j                        xs t        | t         j                        }|r	 | j                  j                  S yy# t
        $ r Y yw xY w# t        t        f$ r Y yw xY w)z
    Return Numpy data type associated to `obj`.

    Return None if Numpy is not available, if we get errors or if `obj` is not
    a Numpy array or scalar.
    N)
r   ndarrayr   
isinstancegeneric	ExceptiondtypetypeAttributeErrorRuntimeError)objscalar_or_arrays     r'   get_numpy_dtyper4   &   s     
zz#	3

+Jz#rzz/J  yy~~%  $  		 #L1  s#   6A) A8 )	A54A58B
	B
c                 X    t        |       }|t        | d      sy| j                  dk(  ryy)z+Get the type of a Numpy object as a string.sizeUnknown   ScalarArray)r4   hasattrr6   )valuenp_dtypes     r'   get_numpy_type_stringr>   D   s/    u%Hwuf5	qr&   c                     d| j                   j                  dt        t        |             j	                         j                  dd      dS )z:Return object address as a string: '<classname @ address>'<z @ Xx>)	__class____name__hexidupperreplace)r2   s    r'   addressrJ   R   s<    --00bg,,,.66sC@B Br&   c                 R    	 t        |       S # t        t        t        f$ r | cY S w xY w)zTry to eval value)eval	NameErrorSyntaxErrorImportError)r<   s    r'   try_to_evalrP   X   s,    E{{K0 s   
 &&c                    	 t        | d      rt        | j                  d      s"t        | d      rt        | j                  d      ryt        | d      rst        | j                  t        t
        j                  f      rI	 | j                  r;t        | j                  t              rt	        | j                        S | j                  S yt        | d      r7t        | j                  t        t
        j                  f      r	 | j                  S t        | d      rt        |       S y# t        $ r Y yw xY w# t        $ r Y yw xY w# t        $ r Y yw xY w)z2Return shape/size/len of an item of arbitrary typer6   computeshaper8   )rT   __len__)
r;   r6   rS   r+   tupler   integerRecursionErrorlenr-   items    r'   get_sizer\   `   s   *D&!gdii&CD'"wtzz9'E D'"tzzE2::#67 :: "$**e4$TZZ00::%  dF#499ubjj&9: yy  T9%t9 "    	  "     sf   AD? 6D? >:D! 9D! 6D? =D0 	D? !	D-*D? ,D--D? 0	D<9D? ;D<<D? ?	E
Ec                 ~    t        |       D cg c]  }|j                  d      r| }}|st        |       }|S c c}w )z[
    Get the attributes of an object using dir.

    This filters protected attributes
    __)dir
startswith)r2   kattrss      r'   get_object_attrsrc      s<     C;1T(:Q;E;CL <s   ::)parsec           
      r    t        j                   t        t        t        | j	                  d                   S )z#Just for 'year, month, day' strings,)datetimelistmapintsplit)datestrs    r'   	dateparserm      s(      4Cs1C(D#EGGr&   c                 d    | j                  d      dz   }t        | |d       }t        | d|       |S )N(r8   rT   z-->)rfindrm   print)r<   rpvs      r'   datestr_to_datetimert      s6    	S	!	B%2,A	%Hr&   c                     t        j                  d|       }|st        d      |j                  d      j	                  d      D cg c]  }t        |j                                }}t        j                  | S c c}w )a  Convert a string to a datetime.timedelta value.

    The following strings are accepted:

        - 'datetime.timedelta(1, 5, 12345)'
        - 'timedelta(1, 5, 12345)'
        - '(1, 5, 12345)'
        - '1, 5, 12345'
        - '1'

    if there are less then three parameters, the missing parameters are
    assumed to be 0. Variations in the spacing of the parameters are allowed.

    Raises:
        ValueError for strings not matching the above criterion.

    z,^(?:(?:datetime\.)?timedelta)?\(?([^)]*)\)?$z%Invalid string for datetime.timedeltar8   rf   )	rematch
ValueErrorgrouprk   rj   striprg   	timedelta)r<   maargss       r'   str_to_timedeltar      ss    $ 	   	!A @AA$%GGAJ$4$4S$9:qC	N:D:t$$ ;s    A:c                     t        |       syg d}t        |       |vr4t        | t        j                        st        |       }|t        | d      syy)z
    Return True if data type is editable with a standard GUI-based editor,
    like CollectionsEditor, ArrayEditor, QDateEdit or a simple QLineEdit.
    F)boolrj   longfloatcomplexrh   setdictrV   strunicodeNDArrayMaskedArrayMatrix	DataFrameSerieszPIL.Image.Imagezdatetime.datezdatetime.timedeltar6   T)is_known_typeget_type_stringr+   pdIndexr4   r;   )r<   supported_typesr=   s      r'   is_editable_typer      sR    
 
 E"/9ubhh/&u-Hwuf'=r&   c                     d }nfd}	 t        t        ||       ||      D cg c]  \  }}|	 c}}S c c}}w #  | cY S xY w)z
    Arrange items of list1 in the same order as sorted(list2).

    In other words, apply to list1 the permutation which takes list2 
    to sorted(list2, reverse).
    c                     | d   S Nr   r%   )rB   s    r'   <lambda>zsort_against.<locals>.<lambda>   s
    ! r&   c                      | d         S r   r%   )rB   sort_keys    r'   r   zsort_against.<locals>.<lambda>   s    1 r&   )keyreverse)sortedzip)list1list2r   r   r   _r[   s      `   r'   sort_againstr      sZ     &s5%(c7CED E 	E Es   ? 9? ? Ac                 *    t        t        |             S )z=Removes duplicates from lista neglecting its initial ordering)rh   r   )listas    r'   unsorted_uniquer      s    E
r&   c                     t        |       }	 |j                  }|j                  }|dk(  rd}|r)|dk(  r| j                  dz   S |dk(  r|dz   S |dz   |z   dz   S |S # t        $ r t	        |      }|dd	 cY S w xY w)
z$Default display for unknown objects.r/   classmodulez modulebuiltinsz objectz object of r8   rT   )r/   rE   
__module__r-   r   )r<   with_moduleobject_typenamer   type_strs         r'   default_displayr     s    u+K##'' 6>Dx~~	11#i''-'&09<< !+."~s#   4A 	A 
A A A54A5c           	         t        | t              }t        | t              }|rt        |       }n| }d}|dk(  r&t	        |       dkD  r|s|rt        |d      n| dd }d}n*|dk(  r%t	        |       dkD  r|s|rt        |d      n| dd }d}|dk  r{|r:t        |      D cg c]#  \  }}t        ||      d	z   t        ||      z   % }}}n|D 	cg c]  }	t        |	|       }}	|r|j                  d
       dj                  |      }
nd
}
|r
d|
z   dz   }
|
S t        | t              r
d|
z   dz   }
|
S t        | t              r
d|
z   dz   }
|
S d|
z   dz   }
|
S c c}}w c c}	w )z9Display for collections (i.e. list, set, tuple and dict).Fr8   
   NT      )level:z..., {}[]ro   ))
r+   r   r   r   rY   r   rh   value_to_displayappendjoin)r<   r   is_dictis_setelementstruncatera   rs   displaysedisplays              r'   collections_displayr     s   %Gs#F U# Hzc%j2o+2f6(B'%*	!E
Q*1V6(A&r z '+8n6"Q )%83>(%89 6H 6
 "*+ )%8 +H +OOE"))H% -#% N 
E4	 -#% N 
E3	-#% N -#%N-6+s   (EEc                 
   t         }t               }	 t        j                  t         ur*t        j                         }t        j
                  d       t        | t        j                        r+|dk(  r"| j                  }ddj                  |      z   }nbd}n^t        | t        j                  j                        rd}n6t        | t        j                        rc|dk(  rZ|r&d| j                         d	| j                         }n| j                   j"                  |v rt%        |       }nt'        |       }nd
}nt)        t*        t,        t.        t0        fD cg c]  }t#        |       |k(   c}      rt3        | |dz         }not        | t4        j6                  j6                        r%|dk(  rt9        |       d| j:                  }n*d}n&t        | t<        j>                        r|dk(  r| j@                  }tB        r@tE        |      dkD  r2	 tG        |d   d      }	|	g|dd D 
cg c]  }
tG        |
       c}
z   }n|D 
cg c]  }
tG        |
       }}
ddj                  t+        |            z   }n~d}nzt        | tH        jJ                  jL                        rtG        |       }|dkD  rEd|z   dz   }n;t        | t<        jN                        r|dk(  r	 | jQ                         }n	d}ntW        |       r2tY        |       r	 tG        | d      }|dkD  rd|z   dz   }nt'        |       }nt[        |       r'tY        |       r| }|dkD  rd|z   dz   }nt'        |       }nt        | t\        j^                        st        | t\        j`                        rt%        |       }nVt        | tb              st        | td              st        | |      rtg        |       }n|dk(  rt'        |       }nt'        | d      }tE        |      dkD  r&tW        |      rd}nd}|dd jk                         |z   }|t         urt        j
                  di | |S # t        t        f$ r2 | j                   j"                  |v rt%        |       }nt'        |       }Y w xY wc c}w #  tG        |d         }	Y xY wc c}
w c c}
w # tR        $ r | jU                         }Y w xY w#  | }|dkD  rd|z   dz   }Y xY w# th        $ r t'        |       }Y w xY w)z!Convert value for display purposer   )	thresholdr   zField names: r   RecarrayzMasked arrayzMin: z
Max: zNumpy arrayr8   z  Mode: Imagez	utf-8-sig)encodingNzColumn names: 	Dataframe'r   utf8   'F)r   F   s    ...z ...r%   )6r   r(   r   r*   get_printoptionsset_printoptionsr+   recarraynamesr   mar   minmax	TypeErrorrx   r.   r/   r   r   anyrh   r   rV   r   r   r   r   rJ   moder   r   columnsr   rY   r   r   elementNavigableStringr   _summaryr0   summaryr   r
   r	   rg   dater{   r   r   reprr-   rstrip)r<   minmaxr   np_printoptionsnumeric_numpy_typesfieldsr   tcolsini_colcellipsess               r'   r   r   I  sA    !O13j)::Z' 113O "-eR[[)z)DIIf,==$ruu001$Grzz*z=8=		UYY["Q [[%%)<<!%jG-e4G'T3t,DEq$u+"EF)%q9Gsyy/z,3ENEJJG!r||,z}}3t9q=:"0a;"O $948'Laq(9'LLD7;<!N1-<D<*TYYtDz-BB%s{{::;$U+Gqy.4/rxx(z.#nn.G "e$ #5)8,UF;Gqy"&.4"7 *%0E" #5)19"Wnt3G)%0. 2 23%jG.% 345kGz)%0)%UC 7|bG$HH#2,%%'(2 j(
.o.NK &z2 = ;;++/BB&)%jG&5e&<G	= F$:"0a"9'L< & .#mmoG.8#Gqy"&.4"70  )!%()s   CS&  $Q AS& R.B S& R 	S& (R':
S& R,BS& R1 *S& S  CS& >R	S& R		S& R$!S& 1S
S& SS& S#!S& &S>=S>c                    ddl m}  || t              } 	 t        |      }t	        |t
              r	 t        t        |             } | S |4dt        t        |            v r |t        |             } | S  ||       } 	 | S t        |      rt        | d      } | S t        |      rt        |       } | S t	        |t              rt        |       } | S t	        |t              rt        |       } | S t	        |t              r	 t        |       } | S t	        |t         j                         rt#        |       } | S t	        |t         j$                        rt#        |       j%                         } | S t	        |t         j&                        rt)        |       } | S |rt+        |       } | S t-        |       } 	 | S # t        $ r | j                         dk(  } Y | S w xY w# t        $ r t        |       } Y | S w xY w# t        t.        f$ r |rt+        |       } Y | S |cY S w xY w)zConvert back to valuer   )from_qvarianttruer   r   )qtpy.compatr   r   r4   r+   r   r   rx   lowerr   r/   r   r   r   r	   rj   rg   rt   r   r{   r   rP   rL   rN   )r<   default_valueignore_errorsr   r=   s        r'   display_to_valuer     s,   )%0E)!"=1mT*0U5\*H LC !C] 344 0> L; !: L9 m,$UF3E6 L5 M*"5)E2 L1 w/ENE. L- u-%LE* L) s+%E
$ L x'8'89'.E L x}}5'.335E L x'9'9:$U+E L &E L KE LG  0/D LG0$  %e  L#% $ !&E L ! 	!s   G$ F& )G$ 2G$ =G$ G$ .G$ G$ (G$ 9G	 %G$ -3G$ "%G$ 	G$ G$ &GG$ GG$ 	G!G$  G!!G$ $HHHc                    	 t        | t        j                  j                        ryt        | t        j                        ryt        | t        j
                        ryt        | t        j                        ryt        | t        j                        rt        |       j                  S t        | t        j                        ry	 t        j                  dt        t        |                   }|r|d   dk(  ry	|d   S y
# t        $ r Y Dw xY w)z Return type string of an object.r   r   r   r   r   z<(?:type|class) '(\S*)'>r   r/   r   r7   )r+   r   r   r   matrixr*   r   r   r   r/   rE   r   r-   rv   findallr   )r[   founds     r'   r   r     s    dBEE--. dBII&dBJJ' dBLL)dBHH%:&&&dBII& '
 JJ2%d4j13E8vQx  s.   $C< C< C< C< 8.C< 'C< <	DDc                 j    t        | t        j                  j                        xs t	        |       dk7  S )z&Return True if object has a known typer7   )r+   r   r   r   r   rZ   s    r'   r   r     s/     tRUU../ /D!Y.0r&   c                 J   	 t        | t        j                  t        j                  j                  f      rd| j
                  j                  z   S t        | t        j                  j                        ryt        |       }||j                  d      dz   d S # t        $ r Y yw xY w)z,Return human-readable type string of an itemz	Array of r   .r8   Nr7   )r+   r   r*   r   r   r.   r   r   r   r   findr-   )r[   texts     r'   get_human_readable_typer   &  s    	dRZZ):):;<$**//11ciioo."4(D		#q()** s   AB $B 4!B 	B"!B"c                    |J | yt        |       ryt        |       syt        | |      sy|rt        | t        t        t
        f      r)d}| D ]  }t        |||      r|dz  }|r |dkD  S  |dkD  S t        | t              rCt        | j                               D ]'  \  }}t        |||      rt        |||      s y|r' y y)z3Return True if value is supported, False otherwise.TFr   )filtersiterater8   )	is_callable_or_moduler   r+   rh   rV   r   is_supportedr   items)r<   	check_allr   r   valid_countvalr   s          r'   r  r  9  s    }U#e$w'	edE3/0K WiH1$K ?"
 ?"t$ / S#C)L&sG/8:   r&   c                 p    	 t        |       xs t        j                  |       }|S # t        $ r d}Y |S w xY w)z>Return True if value is a callable or module, False otherwise.F)callableinspectismoduler-   )r<   callable_or_modules     r'   r   r   X  sF    #%e_G0@0@0G   #"#s   "& 55c	                    i }	t         }
t        | j                               D ]  \  }}|xr  |
|      xr |j                  d      xs |xr  |
|      xr |d   j	                         xsp |xr@  |
|      xr6 |j	                         xr$ t        |      dkD  xr |dd j                          xs* ||v xs$ |xr t        |      xs |xr t        |||       }|r||	|<    |	S )z?Keep objects in namespace view according to different criteria.r   r   r8   N)r  r   )	r
   rh   r  r`   isupperrY   isdigitr   r  )
input_dictr  r   exclude_privateexclude_capitalizedexclude_uppercaseexclude_unsupportedexcluded_namesexclude_callables_and_modulesoutput_dict
_is_stringr   r<   excludeds                 r'   globalsfilterr  a  s   
 K$J:++-. %
UHCHS^^C5H L IZ_IQ9IL 4:c? 4s{{} 4X\4"%ab'//"33L N"	L
 +K/DU/KL ! Key'JJ 	 $K% r&   )
r  r  r  r  r  r  r   show_callable_attributesshow_special_attributesr  c            	      ~   ddl m} m} t        t        t
        t        t        t        t        | |g	t        t              z   t        t              z   }	 ddlm}m}m} ||||gz  }	 ddlm}m}m} ||||gz  }|dd }		 ddlm}
 |j-                  |
j*                         t        |	|      S #  Y KxY w#  Y ?xY w#  Y xY w)z
    Return a dictionnary containing types lists supported by the
    namespace browser.

    Note:
    If you update this list, don't forget to update variablexplorer.rst
    in spyder-docs
    r   )r   r{   )r*   r   r,   )r   r   r   N)r   )	picklableeditable)rg   r   r{   rj   r   r   rh   r   r   rV   r   r   r   r*   r   r,   r   r   r   r   r   r   r   )r   r{   editable_typesr*   r   r,   r   r   r   picklable_typesr   s              r'   get_supported_typesr     s     )5'4dE4!#'
#346:9oFN227FG44339fe44 %Q'Oekk* /NCC
s$   B* $B1 <!B8 *B.1B58B<c                     t               }|t        |j                               v sJ t        |d         }|||z  }t        | |d   t	        ||         |d   |d   |d   |d   |d   |	      S )	a%  
    Return globals according to filter described in *settings*:
        * data: data to be filtered (dictionary)
        * settings: variable explorer settings (dictionary)
        * mode (string): 'editable' or 'picklable'
        * more_excluded_names: additional excluded names (list)
    r  r  r  r  r  r  r  )r  r   r  r  r  r  r  r  )r   rh   keysr  rV   )datasettingsr   more_excluded_namesr   r  s         r'   get_remote_datar&    s     *+O4,,.////(#345N&--;'od+, !23"#67$%:;$%:;&./N&O%	' 	'r&   c                     t        | |d|      } i }t        | j                               D ]D  \  }}t        ||d         }t	        |      t        |      |t        |      t        |      d||<   F |S )zI
    Make a remote view of dictionary *data*
    -> globals explorer
    r  )r   r%  r   )r   )r/   r6   viewpython_type
numpy_type)r&  rh   r  r   r   r\   r   r>   )r#  r$  r%  remoter   r<   r(  s          r'   make_remote_viewr,    s    
 4
/BDDF4::<( 

Uhx.@A,U3e_*51/6
s
 Mr&   )FN)T)Fr   )FNF)FNNNNNNNr   )8__doc__
__future__r   	itertoolsr   r  rv   spyder_kernels.py3compatr   r   r   r   r	   r
   r   r   r   r    spyder_kernels.utils.lazymodulesr   r   r   r   r   r   r   r(   r4   r>   rJ   rP   r\   rc   rg   dateutil.parserrd   rm   rt   r   r   r   r   r   r   r   r   r   r   r   r  r   r  REMOTE_SETTINGSr   r&  r,  r%   r&   r'   <module>r4     s    &   	C C C
5 53<B,^	 H2%>4$.-`D.h@0&> 8<<@>BEI6OD>'2qHHs   B" "B)