<s> from __future__ import ( unicode_literals , division , absolute_import , print_function ) <EOL> import sys <EOL> import codecs <EOL> try : <EOL> import vim <EOL> except ImportError : <EOL> vim = object ( ) <EOL> from powerline . lib . unicode import unicode <EOL> if ( <EOL> hasattr ( vim , '<STR_LIT>' ) <EOL> and hasattr ( vim , '<STR_LIT>' ) <EOL> and vim . vvars [ '<STR_LIT:version>' ] > <NUM_LIT> <EOL> ) : <EOL> if sys . version_info < ( <NUM_LIT:3> , ) : <EOL> def get_vim_encoding ( ) : <EOL> return vim . options [ '<STR_LIT>' ] or '<STR_LIT:ascii>' <EOL> else : <EOL> def get_vim_encoding ( ) : <EOL> return vim . options [ '<STR_LIT>' ] . decode ( '<STR_LIT:ascii>' ) or '<STR_LIT:ascii>' <EOL> elif hasattr ( vim , '<STR_LIT>' ) : <EOL> def get_vim_encoding ( ) : <EOL> return vim . eval ( '<STR_LIT>' ) or '<STR_LIT:ascii>' <EOL> else : <EOL> def get_vim_encoding ( ) : <EOL> return '<STR_LIT:utf-8>' <EOL> get_vim_encoding . __doc__ = ( <EOL> '''<STR_LIT>''' <EOL> ) <EOL> vim_encoding = get_vim_encoding ( ) <EOL> python_to_vim_types = { <EOL> unicode : ( <EOL> lambda o : b'<STR_LIT>' + ( o . translate ( { <EOL> ord ( '<STR_LIT>' ) : '<STR_LIT>' , <EOL> } ) . encode ( vim_encoding ) ) + b'<STR_LIT>' <EOL> ) , <EOL> list : ( <EOL> lambda o : b'<STR_LIT:[>' + ( <EOL> b'<STR_LIT:U+002C>' . join ( ( python_to_vim ( i ) for i in o ) ) <EOL> ) + b'<STR_LIT:]>' <EOL> ) , <EOL> bytes : ( lambda o : b'<STR_LIT>' + o . replace ( b'<STR_LIT>' , b'<STR_LIT>' ) + b'<STR_LIT>' ) , <EOL> int : ( str if str is bytes else ( lambda o : unicode ( o ) . encode ( '<STR_LIT:ascii>' ) ) ) , <EOL> } <EOL> python_to_vim_types [ float ] = python_to_vim_types [ int ] <EOL> def python_to_vim ( o ) : <EOL> return python_to_vim_types [ type ( o ) ] ( o ) <EOL> if sys . version_info < ( <NUM_LIT:3> , ) : <EOL> def str_to_bytes ( s ) : <EOL> return s <EOL> def unicode_eval ( expr ) : <EOL> ret = vim . eval ( expr ) <EOL> return ret . decode ( vim_encoding , '<STR_LIT>' ) <EOL> else : <EOL> def str_to_bytes ( s ) : <EOL> return s . encode ( vim_encoding ) <EOL> def unicode_eval ( expr ) : <EOL> return vim . eval ( expr ) <EOL> def safe_bytes_eval ( expr ) : <EOL> return bytes ( bytearray ( ( <EOL> int ( chunk ) for chunk in ( <EOL> vim . eval ( <EOL> b'<STR_LIT>' + expr + b'<STR_LIT:U+002CU+0020>' + <EOL> b'<STR_LIT>' + <EOL> b'<STR_LIT>' <EOL> ) . split ( ) <EOL> ) <EOL> ) ) ) <EOL> def eval_bytes ( expr ) : <EOL> try : <EOL> return str_to_bytes ( vim . eval ( expr ) ) <EOL> except UnicodeDecodeError : <EOL> return safe_bytes_eval ( expr ) <EOL> def eval_unicode ( expr ) : <EOL> try : <EOL> return unicode_eval ( expr ) <EOL> except UnicodeDecodeError : <EOL> return safe_bytes_eval ( expr ) . decode ( vim_encoding , '<STR_LIT>' ) <EOL> if hasattr ( vim , '<STR_LIT>' ) : <EOL> rettype_func = { <EOL> None : lambda f : f , <EOL> '<STR_LIT>' : ( <EOL> lambda f : ( <EOL> lambda * args , ** kwargs : ( <EOL> f ( * args , ** kwargs ) . decode ( <EOL> vim_encoding , '<STR_LIT>' <EOL> ) ) ) ) <EOL> } <EOL> rettype_func [ '<STR_LIT:int>' ] = rettype_func [ '<STR_LIT>' ] = rettype_func [ None ] <EOL> rettype_func [ '<STR_LIT:str>' ] = rettype_func [ '<STR_LIT>' ] if str is bytes else rettype_func [ '<STR_LIT>' ] <EOL> def vim_get_func ( f , rettype = None ) : <EOL> '''<STR_LIT>''' <EOL> try : <EOL> func = vim . bindeval ( '<STR_LIT>' + f + '<STR_LIT>' ) <EOL> except vim . error : <EOL> return None <EOL> else : <EOL> return rettype_func [ rettype ] ( func ) <EOL> else : <EOL> rettype_eval = { <EOL> None : getattr ( vim , '<STR_LIT>' , None ) , <EOL> '<STR_LIT:int>' : lambda expr : int ( vim . eval ( expr ) ) , <EOL> '<STR_LIT>' : eval_bytes , <EOL> '<STR_LIT>' : eval_unicode , <EOL> } <EOL> rettype_eval [ '<STR_LIT:str>' ] = rettype_eval [ None ] <EOL> class VimFunc ( object ) : <EOL> '''<STR_LIT>''' <EOL> __slots__ = ( '<STR_LIT:f>' , '<STR_LIT>' ) <EOL> def __init__ ( self , f , rettype = None ) : <EOL> self . f = f . encode ( '<STR_LIT:utf-8>' ) <EOL> self . eval = rettype_eval [ rettype ] <EOL> def __call__ ( self , * args ) : <EOL> return self . eval ( self . f + b'<STR_LIT:(>' + ( b'<STR_LIT:U+002C>' . join ( ( <EOL> python_to_vim ( o ) for o in args <EOL> ) ) ) + b'<STR_LIT:)>' ) <EOL> vim_get_func = VimFunc <EOL> def vim_get_autoload_func ( f , rettype = None ) : <EOL> func = vim_get_func ( f ) <EOL> if not func : <EOL> vim . command ( '<STR_LIT>' + f . replace ( '<STR_LIT:#>' , '<STR_LIT:/>' ) [ : f . rindex ( '<STR_LIT:#>' ) ] + '<STR_LIT>' ) <EOL> func = vim_get_func ( f ) <EOL> return func <EOL> if hasattr ( vim , '<STR_LIT>' ) : <EOL> def vim_func_exists ( f ) : <EOL> try : <EOL> vim . Function ( f ) <EOL> except ValueError : <EOL> return False <EOL> else : <EOL> return True <EOL> else : <EOL> def vim_func_exists ( f ) : <EOL> try : <EOL> return bool ( int ( vim . eval ( '<STR_LIT>' . format ( f ) ) ) ) <EOL> except vim . error : <EOL> return False <EOL> if type ( vim ) is object : <EOL> vim_get_func = lambda * args , ** kwargs : None <EOL> _getbufvar = vim_get_func ( '<STR_LIT>' ) <EOL> _vim_exists = vim_get_func ( '<STR_LIT>' , rettype = '<STR_LIT:int>' ) <EOL> if hasattr ( vim , '<STR_LIT>' ) and vim . vvars [ str ( '<STR_LIT:version>' ) ] > <NUM_LIT> : <EOL> _vim_to_python_types = { <EOL> getattr ( vim , '<STR_LIT>' , None ) or type ( vim . bindeval ( '<STR_LIT:{}>' ) ) : <EOL> lambda value : dict ( ( <EOL> ( _vim_to_python ( k ) , _vim_to_python ( v ) ) <EOL> for k , v in value . items ( ) <EOL> ) ) , <EOL> getattr ( vim , '<STR_LIT>' , None ) or type ( vim . bindeval ( '<STR_LIT>' ) ) : <EOL> lambda value : [ _vim_to_python ( item ) for item in value ] , <EOL> getattr ( vim , '<STR_LIT>' , None ) or type ( vim . bindeval ( '<STR_LIT>' ) ) : <EOL> lambda _ : None , <EOL> } <EOL> def vim_getvar ( varname ) : <EOL> return _vim_to_python ( vim . vars [ str ( varname ) ] ) <EOL> def bufvar_exists ( buffer , varname ) : <EOL> buffer = buffer or vim . current . buffer <EOL> return varname in buffer . vars <EOL> def vim_getwinvar ( segment_info , varname ) : <EOL> return _vim_to_python ( segment_info [ '<STR_LIT>' ] . vars [ str ( varname ) ] ) <EOL> def vim_global_exists ( name ) : <EOL> try : <EOL> vim . vars [ name ] <EOL> except KeyError : <EOL> return False <EOL> else : <EOL> return True <EOL> else : <EOL> _vim_to_python_types = { <EOL> dict : ( lambda value : dict ( ( ( k , _vim_to_python ( v ) ) for k , v in value . items ( ) ) ) ) , <EOL> list : ( lambda value : [ _vim_to_python ( i ) for i in value ] ) , <EOL> } <EOL> def vim_getvar ( varname ) : <EOL> varname = '<STR_LIT>' + varname <EOL> if _vim_exists ( varname ) : <EOL> return vim . eval ( varname ) <EOL> else : <EOL> raise KeyError ( varname ) <EOL> def bufvar_exists ( buffer , varname ) : <EOL> if not buffer or buffer . number == vim . current . buffer . number : <EOL> return int ( vim . eval ( '<STR_LIT>' . format ( varname ) ) ) <EOL> else : <EOL> return int ( vim . eval ( <EOL> '<STR_LIT>' . format ( buffer . number , varname ) <EOL> ) ) <EOL> def vim_getwinvar ( segment_info , varname ) : <EOL> result = vim . eval ( '<STR_LIT>' . format ( segment_info [ '<STR_LIT>' ] , varname ) ) <EOL> if result == '<STR_LIT>' : <EOL> if not int ( vim . eval ( '<STR_LIT>' . format ( segment_info [ '<STR_LIT>' ] , varname ) ) ) : <EOL> raise KeyError ( varname ) <EOL> return result <EOL> def vim_global_exists ( name ) : <EOL> return int ( vim . eval ( '<STR_LIT>' + name + '<STR_LIT>' ) ) <EOL> def vim_command_exists ( name ) : <EOL> return _vim_exists ( '<STR_LIT::>' + name ) <EOL> if sys . version_info < ( <NUM_LIT:3> , ) : <EOL> getbufvar = _getbufvar <EOL> else : <EOL> _vim_to_python_types [ bytes ] = lambda value : value . decode ( vim_encoding ) <EOL> def getbufvar ( * args ) : <EOL> return _vim_to_python ( _getbufvar ( * args ) ) <EOL> _id = lambda value : value <EOL> def _vim_to_python ( value ) : <EOL> return _vim_to_python_types . get ( type ( value ) , _id ) ( value ) <EOL> if hasattr ( vim , '<STR_LIT>' ) : <EOL> def vim_getbufoption ( info , option ) : <EOL> return _vim_to_python ( info [ '<STR_LIT>' ] . options [ str ( option ) ] ) <EOL> def vim_getoption ( option ) : <EOL> return vim . options [ str ( option ) ] <EOL> def vim_setoption ( option , value ) : <EOL> vim . options [ str ( option ) ] = value <EOL> else : <EOL> def vim_getbufoption ( info , option ) : <EOL> return getbufvar ( info [ '<STR_LIT>' ] , '<STR_LIT:&>' + option ) <EOL> def vim_getoption ( option ) : <EOL> return vim . eval ( '<STR_LIT>' + option ) <EOL> def vim_setoption ( option , value ) : <EOL> vim . command ( '<STR_LIT>' . format ( <EOL> option = option , value = python_to_vim ( value ) ) ) <EOL> if hasattr ( vim , '<STR_LIT>' ) : <EOL> current_tabpage = lambda : vim . current . tabpage <EOL> list_tabpages = lambda : vim . tabpages <EOL> def list_tabpage_buffers_segment_info ( segment_info ) : <EOL> return ( <EOL> { '<STR_LIT>' : window . buffer , '<STR_LIT>' : window . buffer . number } <EOL> for window in segment_info [ '<STR_LIT>' ] . windows <EOL> ) <EOL> else : <EOL> class FalseObject ( object ) : <EOL> @ staticmethod <EOL> def __nonzero__ ( ) : <EOL> return False <EOL> __bool__ = __nonzero__ <EOL> def get_buffer ( number ) : <EOL> for buffer in vim . buffers : <EOL> if buffer . number == number : <EOL> return buffer <EOL> raise KeyError ( number ) <EOL> class WindowVars ( object ) : <EOL> __slots__ = ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> def __init__ ( self , window ) : <EOL> self . tabnr = window . tabnr <EOL> self . winnr = window . number <EOL> def __getitem__ ( self , key ) : <EOL> has_key = vim . eval ( '<STR_LIT>' . format ( self . tabnr , self . winnr , key ) ) <EOL> if has_key == '<STR_LIT:0>' : <EOL> raise KeyError <EOL> return vim . eval ( '<STR_LIT>' . format ( self . tabnr , self . winnr , key ) ) <EOL> def get ( self , key , default = None ) : <EOL> try : <EOL> return self [ key ] <EOL> except KeyError : <EOL> return default <EOL> class Window ( FalseObject ) : <EOL> __slots__ = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> def __init__ ( self , tabnr , number ) : <EOL> self . tabnr = tabnr <EOL> self . number = number <EOL> self . vars = WindowVars ( self ) <EOL> @ property <EOL> def buffer ( self ) : <EOL> return get_buffer ( int ( vim . eval ( '<STR_LIT>' . format ( self . tabnr , self . number - <NUM_LIT:1> ) ) ) ) <EOL> class Tabpage ( FalseObject ) : <EOL> __slots__ = ( '<STR_LIT>' , ) <EOL> def __init__ ( self , number ) : <EOL> self . number = number <EOL> def __eq__ ( self , tabpage ) : <EOL> if not isinstance ( tabpage , Tabpage ) : <EOL> raise NotImplementedError <EOL> return self . number == tabpage . number <EOL> @ property <EOL> def window ( self ) : <EOL> return Window ( self . number , int ( vim . eval ( '<STR_LIT>' . format ( self . number ) ) ) ) <EOL> def _last_tab_nr ( ) : <EOL> return int ( vim . eval ( '<STR_LIT>' ) ) <EOL> def current_tabpage ( ) : <EOL> return Tabpage ( int ( vim . eval ( '<STR_LIT>' ) ) ) <EOL> def list_tabpages ( ) : <EOL> return [ Tabpage ( nr ) for nr in range ( <NUM_LIT:1> , _last_tab_nr ( ) + <NUM_LIT:1> ) ] <EOL> class TabBufSegmentInfo ( dict ) : <EOL> def __getitem__ ( self , key ) : <EOL> try : <EOL> return super ( TabBufSegmentInfo , self ) . __getitem__ ( key ) <EOL> except KeyError : <EOL> if key != '<STR_LIT>' : <EOL> raise <EOL> else : <EOL> buffer = get_buffer ( super ( TabBufSegmentInfo , self ) . __getitem__ ( '<STR_LIT>' ) ) <EOL> self [ '<STR_LIT>' ] = buffer <EOL> return buffer <EOL> def list_tabpage_buffers_segment_info ( segment_info ) : <EOL> return ( <EOL> TabBufSegmentInfo ( bufnr = int ( bufnrstr ) ) <EOL> for bufnrstr in vim . eval ( '<STR_LIT>' . format ( segment_info [ '<STR_LIT>' ] ) ) <EOL> ) <EOL> class VimEnviron ( object ) : <EOL> @ staticmethod <EOL> def __getitem__ ( key ) : <EOL> return vim . eval ( '<STR_LIT:$>' + key ) <EOL> @ staticmethod <EOL> def get ( key , default = None ) : <EOL> return vim . eval ( '<STR_LIT:$>' + key ) or default <EOL> @ staticmethod <EOL> def __setitem__ ( key , value ) : <EOL> return vim . command ( <EOL> '<STR_LIT>' . format ( <EOL> key , <EOL> value . replace ( '<STR_LIT:">' , '<STR_LIT>' ) <EOL> . replace ( '<STR_LIT:\\>' , '<STR_LIT>' ) <EOL> . replace ( '<STR_LIT:\n>' , '<STR_LIT>' ) <EOL> . replace ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> ) <EOL> ) <EOL> if sys . version_info < ( <NUM_LIT:3> , ) : <EOL> def buffer_name ( segment_info ) : <EOL> return segment_info [ '<STR_LIT>' ] . name <EOL> else : <EOL> vim_bufname = vim_get_func ( '<STR_LIT>' , rettype = '<STR_LIT>' ) <EOL> def buffer_name ( segment_info ) : <EOL> try : <EOL> name = segment_info [ '<STR_LIT>' ] . name <EOL> except UnicodeDecodeError : <EOL> return vim_bufname ( segment_info [ '<STR_LIT>' ] ) <EOL> else : <EOL> return name . encode ( segment_info [ '<STR_LIT>' ] ) if name else None <EOL> vim_strtrans = vim_get_func ( '<STR_LIT>' , rettype = '<STR_LIT>' ) <EOL> def powerline_vim_strtrans_error ( e ) : <EOL> if not isinstance ( e , UnicodeDecodeError ) : <EOL> raise NotImplementedError <EOL> text = vim_strtrans ( e . object [ e . start : e . end ] ) <EOL> return ( text , e . end ) <EOL> codecs . register_error ( '<STR_LIT>' , powerline_vim_strtrans_error ) <EOL> did_autocmd = False <EOL> buffer_caches = [ ] <EOL> def register_buffer_cache ( cachedict ) : <EOL> global did_autocmd <EOL> global buffer_caches <EOL> from powerline . vim import get_default_pycmd , pycmd <EOL> if not did_autocmd : <EOL> import __main__ <EOL> __main__ . powerline_on_bwipe = on_bwipe <EOL> vim . command ( '<STR_LIT>' ) <EOL> vim . command ( '<STR_LIT>' . format ( <EOL> pycmd = ( pycmd or get_default_pycmd ( ) ) ) ) <EOL> vim . command ( '<STR_LIT>' ) <EOL> did_autocmd = True <EOL> buffer_caches . append ( cachedict ) <EOL> return cachedict <EOL> def on_bwipe ( ) : <EOL> global buffer_caches <EOL> bufnr = int ( vim . eval ( '<STR_LIT>' ) ) <EOL> for cachedict in buffer_caches : <EOL> cachedict . pop ( bufnr , None ) <EOL> environ = VimEnviron ( ) <EOL> def create_ruby_dpowerline ( ) : <EOL> vim . command ( ( <EOL> '''<STR_LIT>''' <EOL> ) ) </s>
