<s> """<STR_LIT>""" <EOL> import re <EOL> import param <EOL> from param . ipython import ParamPager <EOL> from holoviews . core . util import group_sanitizer , label_sanitizer <EOL> class ParamFilter ( param . ParameterizedFunction ) : <EOL> """<STR_LIT>""" <EOL> def __call__ ( self , obj , filter_fn = None ) : <EOL> if filter_fn is None : <EOL> return obj <EOL> name = obj . __name__ if isinstance ( obj , type ) else obj . __class__ . __name__ <EOL> class_proxy = type ( name , ( param . Parameterized , ) , <EOL> { k : v for k , v in obj . params ( ) . items ( ) if filter_fn ( k , v ) } ) <EOL> if isinstance ( obj , type ) : <EOL> return class_proxy <EOL> else : <EOL> instance_params = obj . get_param_values ( ) <EOL> obj_proxy = class_proxy ( ) <EOL> filtered = { k : v for k , v in instance_params <EOL> if ( k in obj_proxy . params ( ) ) <EOL> and not obj_proxy . params ( k ) . constant } <EOL> obj_proxy . set_param ( ** filtered ) <EOL> return obj_proxy <EOL> @ param . parameterized . bothmethod <EOL> def regexp_filter ( self_or_cls , pattern ) : <EOL> """<STR_LIT>""" <EOL> def inner_filter ( name , p ) : <EOL> name_match = re . search ( pattern , name ) <EOL> if name_match is not None : <EOL> return True <EOL> doc_match = re . search ( pattern , p . doc ) <EOL> if doc_match is not None : <EOL> return True <EOL> return False <EOL> return inner_filter <EOL> class InfoPrinter ( object ) : <EOL> """<STR_LIT>""" <EOL> headings = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> ansi_escape = re . compile ( r'<STR_LIT>' ) <EOL> ppager = ParamPager ( ) <EOL> store = None <EOL> @ classmethod <EOL> def get_parameter_info ( cls , obj , ansi = False , show_values = True , <EOL> pattern = None , max_col_len = <NUM_LIT> ) : <EOL> """<STR_LIT>""" <EOL> if cls . ppager is None : return '<STR_LIT>' <EOL> if pattern is not None : <EOL> obj = ParamFilter ( obj , ParamFilter . regexp_filter ( pattern ) ) <EOL> if len ( obj . params ( ) ) <= <NUM_LIT:1> : <EOL> return None <EOL> param_info = cls . ppager . get_param_info ( obj ) <EOL> param_list = cls . ppager . param_docstrings ( param_info ) <EOL> if not show_values : <EOL> retval = cls . ansi_escape . sub ( '<STR_LIT>' , param_list ) if not ansi else param_list <EOL> return cls . highlight ( pattern , retval ) <EOL> else : <EOL> info = cls . ppager ( obj ) <EOL> if ansi is False : <EOL> info = cls . ansi_escape . sub ( '<STR_LIT>' , info ) <EOL> return cls . highlight ( pattern , info ) <EOL> @ classmethod <EOL> def heading ( cls , heading_text , char = '<STR_LIT:=>' , level = <NUM_LIT:0> , ansi = False ) : <EOL> """<STR_LIT>""" <EOL> heading_color = cls . headings [ level ] if ansi else '<STR_LIT:%s>' <EOL> if char is None : <EOL> return heading_color % '<STR_LIT>' % heading_text <EOL> else : <EOL> heading_ul = char * len ( heading_text ) <EOL> return heading_color % '<STR_LIT>' % ( heading_ul , heading_text , heading_ul ) <EOL> @ classmethod <EOL> def highlight ( cls , pattern , string ) : <EOL> if pattern is None : return string <EOL> return re . sub ( pattern , '<STR_LIT>' , <EOL> string , flags = re . IGNORECASE ) <EOL> @ classmethod <EOL> def info ( cls , obj , ansi = False , backend = '<STR_LIT>' , visualization = True , pattern = None ) : <EOL> """<STR_LIT>""" <EOL> ansi_escape = re . compile ( r'<STR_LIT>' ) <EOL> isclass = isinstance ( obj , type ) <EOL> name = obj . __name__ if isclass else obj . __class__ . __name__ <EOL> plot_class = cls . store . registry [ backend ] . get ( obj if isclass else type ( obj ) , None ) <EOL> if hasattr ( plot_class , '<STR_LIT>' ) : <EOL> plot_class = list ( plot_class . plot_classes . values ( ) ) [ <NUM_LIT:0> ] <EOL> if visualization is False or plot_class is None : <EOL> if pattern is not None : <EOL> obj = ParamFilter ( obj , ParamFilter . regexp_filter ( pattern ) ) <EOL> if len ( obj . params ( ) ) <= <NUM_LIT:1> : <EOL> return ( '<STR_LIT>' <EOL> % ( name , pattern ) ) <EOL> info = param . ipython . ParamPager ( ) ( obj ) <EOL> if ansi is False : <EOL> info = ansi_escape . sub ( '<STR_LIT>' , info ) <EOL> return cls . highlight ( pattern , info ) <EOL> heading = name if isclass else '<STR_LIT>' . format ( name = name , <EOL> group = obj . group , <EOL> label = obj . label ) <EOL> prefix = heading <EOL> lines = [ prefix , cls . object_info ( obj , name , ansi = ansi ) ] <EOL> if not isclass : <EOL> lines += [ '<STR_LIT>' , cls . target_info ( obj , ansi = ansi ) ] <EOL> if plot_class is not None : <EOL> lines += [ '<STR_LIT>' , cls . options_info ( plot_class , ansi , pattern = pattern ) ] <EOL> return "<STR_LIT:\n>" . join ( lines ) <EOL> @ classmethod <EOL> def get_target ( cls , obj ) : <EOL> objtype = obj . __class__ . __name__ <EOL> group = group_sanitizer ( obj . group ) <EOL> label = ( '<STR_LIT:.>' + label_sanitizer ( obj . label ) if obj . label else '<STR_LIT>' ) <EOL> target = '<STR_LIT>' . format ( objtype = objtype , <EOL> group = group , <EOL> label = label ) <EOL> return ( None , target ) if hasattr ( obj , '<STR_LIT>' ) else ( target , None ) <EOL> @ classmethod <EOL> def target_info ( cls , obj , ansi = False ) : <EOL> if isinstance ( obj , type ) : return '<STR_LIT>' <EOL> targets = obj . traverse ( cls . get_target ) <EOL> elements , containers = zip ( * targets ) <EOL> element_set = set ( el for el in elements if el is not None ) <EOL> container_set = set ( c for c in containers if c is not None ) <EOL> element_info = None <EOL> if len ( element_set ) == <NUM_LIT:1> : <EOL> element_info = '<STR_LIT>' % list ( element_set ) [ <NUM_LIT:0> ] <EOL> elif len ( element_set ) > <NUM_LIT:1> : <EOL> element_info = '<STR_LIT>' % '<STR_LIT>' . join ( sorted ( element_set ) ) <EOL> container_info = None <EOL> if len ( container_set ) == <NUM_LIT:1> : <EOL> container_info = '<STR_LIT>' % list ( container_set ) [ <NUM_LIT:0> ] <EOL> elif len ( container_set ) > <NUM_LIT:1> : <EOL> container_info = '<STR_LIT>' % '<STR_LIT>' . join ( sorted ( container_set ) ) <EOL> heading = cls . heading ( '<STR_LIT>' , ansi = ansi , char = "<STR_LIT:->" ) <EOL> target_header = '<STR_LIT>' <EOL> if element_info and container_info : <EOL> target_info = '<STR_LIT>' % ( element_info , container_info ) <EOL> else : <EOL> target_info = element_info if element_info else container_info <EOL> target_footer = ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> return '<STR_LIT:\n>' . join ( [ heading , target_header , target_info , target_footer ] ) <EOL> @ classmethod <EOL> def object_info ( cls , obj , name , ansi = False ) : <EOL> element = not getattr ( obj , '<STR_LIT>' , False ) <EOL> url = ( '<STR_LIT>' <EOL> if element else '<STR_LIT>' ) <EOL> link = url . format ( obj = name ) <EOL> msg = ( "<STR_LIT>" <EOL> + "<STR_LIT>" <EOL> + "<STR_LIT>" ) <EOL> return '<STR_LIT:\n>' . join ( [ msg . format ( obj = name , <EOL> lower = name . lower ( ) , <EOL> link = link ) ] ) <EOL> @ classmethod <EOL> def options_info ( cls , plot_class , ansi = False , pattern = None ) : <EOL> if plot_class . style_opts : <EOL> backend_name = plot_class . renderer . backend <EOL> style_info = ( "<STR_LIT>" % backend_name ) <EOL> style_keywords = '<STR_LIT>' % '<STR_LIT:U+002CU+0020>' . join ( plot_class . style_opts ) <EOL> style_msg = '<STR_LIT>' % ( style_keywords , style_info ) <EOL> else : <EOL> style_msg = '<STR_LIT>' <EOL> param_info = cls . get_parameter_info ( plot_class , ansi = ansi , pattern = pattern ) <EOL> lines = [ cls . heading ( '<STR_LIT>' , ansi = ansi , char = "<STR_LIT:->" ) , '<STR_LIT>' , <EOL> style_msg , '<STR_LIT>' , <EOL> cls . heading ( '<STR_LIT>' , ansi = ansi , char = "<STR_LIT:->" ) , '<STR_LIT>' ] <EOL> if param_info is not None : <EOL> lines += [ "<STR_LIT>" , <EOL> param_info ] <EOL> elif pattern is not None : <EOL> lines += [ '<STR_LIT>' <EOL> % ( plot_class . __name__ , pattern ) ] <EOL> else : <EOL> lines += [ '<STR_LIT>' % plot_class . __name__ ] <EOL> return '<STR_LIT:\n>' . join ( lines ) <EOL> class PrettyPrinter ( object ) : <EOL> """<STR_LIT>""" <EOL> tab = '<STR_LIT:U+0020>' <EOL> type_formatter = '<STR_LIT>' <EOL> @ classmethod <EOL> def pprint ( cls , node ) : <EOL> return cls . serialize ( cls . recurse ( node ) ) <EOL> @ classmethod <EOL> def serialize ( cls , lines ) : <EOL> accumulator = [ ] <EOL> for level , line in lines : <EOL> accumulator . append ( ( level * cls . tab ) + line ) <EOL> return "<STR_LIT:\n>" . join ( accumulator ) <EOL> @ classmethod <EOL> def shift ( cls , lines , shift = <NUM_LIT:0> ) : <EOL> return [ ( lvl + shift , line ) for ( lvl , line ) in lines ] <EOL> @ classmethod <EOL> def padding ( cls , items ) : <EOL> return max ( len ( p ) for p in items ) if len ( items ) > <NUM_LIT:1> else len ( items [ <NUM_LIT:0> ] ) <EOL> @ classmethod <EOL> def component_type ( cls , node ) : <EOL> "<STR_LIT>" <EOL> if node is None : return '<STR_LIT>' <EOL> return cls . type_formatter . format ( type = str ( type ( node ) . __name__ ) ) <EOL> @ classmethod <EOL> def recurse ( cls , node , attrpath = None , attrpaths = [ ] , siblings = [ ] , level = <NUM_LIT:0> , value_dims = True ) : <EOL> """<STR_LIT>""" <EOL> level , lines = cls . node_info ( node , attrpath , attrpaths , siblings , level , value_dims ) <EOL> attrpaths = [ '<STR_LIT:.>' . join ( k ) for k in node . keys ( ) ] if hasattr ( node , '<STR_LIT>' ) else [ ] <EOL> siblings = [ node . get ( child ) for child in attrpaths ] <EOL> for index , attrpath in enumerate ( attrpaths ) : <EOL> lines += cls . recurse ( node . get ( attrpath ) , attrpath , attrpaths = attrpaths , <EOL> siblings = siblings , level = level + <NUM_LIT:1> , value_dims = value_dims ) <EOL> return lines <EOL> @ classmethod <EOL> def node_info ( cls , node , attrpath , attrpaths , siblings , level , value_dims ) : <EOL> """<STR_LIT>""" <EOL> if hasattr ( node , '<STR_LIT>' ) : <EOL> ( lvl , lines ) = ( level , [ ( level , cls . component_type ( node ) ) ] ) <EOL> elif hasattr ( node , '<STR_LIT>' ) : <EOL> ( lvl , lines ) = cls . adjointlayout_info ( node , siblings , level , value_dims ) <EOL> elif getattr ( node , '<STR_LIT>' , False ) : <EOL> ( lvl , lines ) = cls . ndmapping_info ( node , siblings , level , value_dims ) <EOL> elif hasattr ( node , '<STR_LIT>' ) : <EOL> ( lvl , lines ) = level , [ ( level , repr ( node ) ) ] <EOL> else : <EOL> ( lvl , lines ) = cls . element_info ( node , siblings , level , value_dims ) <EOL> if attrpath is not None : <EOL> padding = cls . padding ( attrpaths ) <EOL> ( fst_lvl , fst_line ) = lines [ <NUM_LIT:0> ] <EOL> lines [ <NUM_LIT:0> ] = ( fst_lvl , '<STR_LIT:.>' + attrpath . ljust ( padding ) + '<STR_LIT:U+0020>' + fst_line ) <EOL> return ( lvl , lines ) <EOL> @ classmethod <EOL> def element_info ( cls , node , siblings , level , value_dims ) : <EOL> """<STR_LIT>""" <EOL> info = cls . component_type ( node ) <EOL> if siblings : <EOL> padding = cls . padding ( [ cls . component_type ( el ) for el in siblings ] ) <EOL> info . ljust ( padding ) <EOL> if len ( node . kdims ) >= <NUM_LIT:1> : <EOL> info += cls . tab + '<STR_LIT>' % '<STR_LIT:U+002C>' . join ( d . name for d in node . kdims ) <EOL> if value_dims and len ( node . vdims ) >= <NUM_LIT:1> : <EOL> info += cls . tab + '<STR_LIT>' % '<STR_LIT:U+002C>' . join ( d . name for d in node . vdims ) <EOL> return level , [ ( level , info ) ] <EOL> @ classmethod <EOL> def adjointlayout_info ( cls , node , siblings , level , value_dims ) : <EOL> first_line = cls . component_type ( node ) <EOL> lines = [ ( level , first_line ) ] <EOL> additional_lines = [ ] <EOL> for component in list ( node . data . values ( ) ) : <EOL> additional_lines += cls . recurse ( component , level = level ) <EOL> lines += cls . shift ( additional_lines , <NUM_LIT:1> ) <EOL> return level , lines <EOL> @ classmethod <EOL> def ndmapping_info ( cls , node , siblings , level , value_dims ) : <EOL> key_dim_info = '<STR_LIT>' % '<STR_LIT:U+002C>' . join ( d . name for d in node . kdims ) <EOL> first_line = cls . component_type ( node ) + cls . tab + key_dim_info <EOL> lines = [ ( level , first_line ) ] <EOL> additional_lines = [ ] <EOL> if len ( node . data ) == <NUM_LIT:0> : <EOL> return level , lines <EOL> last = list ( node . data . values ( ) ) [ - <NUM_LIT:1> ] <EOL> if hasattr ( last , '<STR_LIT>' ) : <EOL> additional_lines = cls . recurse ( last , level = level ) <EOL> elif last is not None and getattr ( last , '<STR_LIT>' ) : <EOL> level , additional_lines = cls . ndmapping_info ( last , [ ] , level , value_dims ) <EOL> else : <EOL> _ , additional_lines = cls . element_info ( last , siblings , level , value_dims ) <EOL> lines += cls . shift ( additional_lines , <NUM_LIT:1> ) <EOL> return level , lines <EOL> __all__ = [ '<STR_LIT>' , '<STR_LIT>' ] </s>
