<s> from __future__ import unicode_literals <EOL> from lib2to3 . fixer_base import BaseFix <EOL> from . utils import node_text <EOL> def get_previous_node ( node ) : <EOL> """<STR_LIT>""" <EOL> if node . prev_sibling : <EOL> return node . prev_sibling <EOL> if node . parent : <EOL> return get_previous_node ( node . parent ) <EOL> class FixWhitespaceBeforeInlineComment ( BaseFix ) : <EOL> '''<STR_LIT>''' <EOL> def match ( self , node ) : <EOL> if not node . prefix . count ( "<STR_LIT:#>" ) : <EOL> return False <EOL> if node . prefix . lstrip ( "<STR_LIT>" ) . startswith ( "<STR_LIT:\n>" ) : <EOL> return False <EOL> prev_node = get_previous_node ( node ) <EOL> if not prev_node : <EOL> return False <EOL> prev_node_text = node_text ( prev_node ) <EOL> if prev_node_text . endswith ( '<STR_LIT:\n>' ) : <EOL> return False <EOL> return True <EOL> def transform ( self , node , results ) : <EOL> position = node . prefix . find ( "<STR_LIT:#>" ) <EOL> if position > <NUM_LIT:2> : <EOL> whitespace_before , comment_after = node . prefix . split ( "<STR_LIT:#>" , <NUM_LIT:1> ) <EOL> new_prefix = "<STR_LIT>" % ( whitespace_before , comment_after . lstrip ( <EOL> ) ) <EOL> else : <EOL> new_prefix = "<STR_LIT>" % node . prefix . replace ( "<STR_LIT:#>" , "<STR_LIT>" , <NUM_LIT:1> ) . lstrip ( ) <EOL> if node . prefix != new_prefix : <EOL> node . prefix = new_prefix <EOL> node . changed ( ) </s>
