<s> import sys <EOL> from collections import defaultdict <EOL> import time <EOL> import vim <EOL> try : <EOL> from . common import shared as G <EOL> from . common import msg <EOL> except ( ImportError , ValueError ) : <EOL> import common . shared as G <EOL> from common import msg <EOL> timeouts = defaultdict ( list ) <EOL> top_timeout_id = <NUM_LIT:0> <EOL> cancelled_timeouts = set ( ) <EOL> calling_timeouts = False <EOL> line_endings = "<STR_LIT:\n>" <EOL> welcome_text = '<STR_LIT>' <EOL> NEW_ACCOUNT_TXT = '<STR_LIT>' <EOL> LINKED_ACCOUNT_TXT = """<STR_LIT>""" <EOL> def name ( ) : <EOL> if sys . version_info < ( <NUM_LIT:3> , <NUM_LIT:0> ) : <EOL> py_version = <NUM_LIT:2> <EOL> else : <EOL> py_version = <NUM_LIT:3> <EOL> return '<STR_LIT>' % py_version <EOL> def codename ( ) : <EOL> return '<STR_LIT>' <EOL> def windows ( * args , ** kwargs ) : <EOL> return [ ] <EOL> def set_timeout ( func , timeout , * args , ** kwargs ) : <EOL> global top_timeout_id <EOL> timeout_id = top_timeout_id <EOL> top_timeout_id + <NUM_LIT:1> <EOL> if top_timeout_id > <NUM_LIT> : <EOL> top_timeout_id = <NUM_LIT:0> <EOL> def timeout_func ( ) : <EOL> if timeout_id in cancelled_timeouts : <EOL> cancelled_timeouts . remove ( timeout_id ) <EOL> return <EOL> func ( * args , ** kwargs ) <EOL> then = time . time ( ) + ( timeout / <NUM_LIT> ) <EOL> timeouts [ then ] . append ( timeout_func ) <EOL> return timeout_id <EOL> def cancel_timeout ( timeout_id ) : <EOL> if timeout_id in timeouts : <EOL> cancelled_timeouts . add ( timeout_id ) <EOL> def call_timeouts ( ) : <EOL> global calling_timeouts <EOL> if calling_timeouts : <EOL> return <EOL> calling_timeouts = True <EOL> now = time . time ( ) <EOL> to_remove = [ ] <EOL> for t , tos in timeouts . items ( ) : <EOL> if now >= t : <EOL> for timeout in tos : <EOL> timeout ( ) <EOL> to_remove . append ( t ) <EOL> for k in to_remove : <EOL> del timeouts [ k ] <EOL> calling_timeouts = False <EOL> def error_message ( * args , ** kwargs ) : <EOL> editor = getattr ( G , '<STR_LIT>' , None ) <EOL> if editor : <EOL> editor . error_message ( * args , ** kwargs ) <EOL> else : <EOL> print ( args , kwargs ) <EOL> def status_message ( msg ) : <EOL> editor = getattr ( G , '<STR_LIT>' , None ) <EOL> if editor : <EOL> editor . status_message ( msg ) <EOL> else : <EOL> print ( msg ) <EOL> def message_dialog ( message ) : <EOL> msg . log ( message ) <EOL> def vim_choice ( prompt , default , choices ) : <EOL> default = choices . index ( default ) + <NUM_LIT:1> <EOL> choices_str = '<STR_LIT:\n>' . join ( [ '<STR_LIT>' % choice for choice in choices ] ) <EOL> try : <EOL> choice = int ( vim . eval ( '<STR_LIT>' % ( prompt , choices_str , default ) ) ) <EOL> except KeyboardInterrupt : <EOL> return None <EOL> if choice == <NUM_LIT:0> : <EOL> return None <EOL> return choices [ choice - <NUM_LIT:1> ] <EOL> def ok_cancel_dialog ( prompt ) : <EOL> choice = vim_choice ( prompt , '<STR_LIT>' , [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> return choice == '<STR_LIT>' <EOL> def open_file ( filename ) : <EOL> current_buffer = vim . eval ( '<STR_LIT>' ) <EOL> if current_buffer != filename : <EOL> vim . command ( '<STR_LIT>' % filename ) <EOL> def platform ( ) : <EOL> return sys . platform <EOL> def get_line_endings ( path = None ) : <EOL> return line_endings </s>
