<s> """<STR_LIT>""" <EOL> from __future__ import print_function <EOL> import os <EOL> import re <EOL> import sys <EOL> from . utils import RunControl , NotSpecified , apiname , ensure_apiname <EOL> from . plugins import Plugin <EOL> if sys . version_info [ <NUM_LIT:0> ] >= <NUM_LIT:3> : <EOL> basestring = str <EOL> upperfirst = lambda s : s if <NUM_LIT:0> == len ( s ) else s [ <NUM_LIT:0> ] . upper ( ) + s [ <NUM_LIT:1> : ] <EOL> HAS_UPPER_RE = re . compile ( '<STR_LIT>' ) <EOL> HAS_UNDERSCORE_RE = re . compile ( '<STR_LIT>' ) <EOL> UPPER_DIGIT_RE = re . compile ( '<STR_LIT>' ) <EOL> WORD_RE = re . compile ( '<STR_LIT>' ) <EOL> UNDERSCORE_WORD_RE = re . compile ( '<STR_LIT>' ) <EOL> UNDERSCORE_DIGIT_RE = re . compile ( '<STR_LIT>' ) <EOL> def _upperrepl ( m ) : <EOL> g1low = m . group ( <NUM_LIT:1> ) . lower ( ) <EOL> g1start = m . start ( <NUM_LIT:1> ) <EOL> if <NUM_LIT:0> == g1start : <EOL> return g1low <EOL> else : <EOL> return '<STR_LIT:_>' + g1low <EOL> def _underscorerepl ( m ) : <EOL> g1 = m . group ( <NUM_LIT:1> ) <EOL> g1start = m . start ( <NUM_LIT:1> ) <EOL> if <NUM_LIT:0> == g1start : <EOL> g1s = g1 . split ( '<STR_LIT:_>' ) <EOL> g1snew = [ ] <EOL> seennonempty = False <EOL> for s in g1s : <EOL> slen = len ( s ) <EOL> if <NUM_LIT:0> == slen : <EOL> if seennonempty : <EOL> continue <EOL> else : <EOL> s = '<STR_LIT:_>' <EOL> else : <EOL> seennonempty = True <EOL> g1snew . append ( s ) <EOL> print ( g1snew ) <EOL> return '<STR_LIT>' . join ( map ( upperfirst , g1snew ) ) <EOL> else : <EOL> return upperfirst ( g1 . replace ( '<STR_LIT:_>' , '<STR_LIT>' ) ) <EOL> def _usdgrepl ( m ) : <EOL> g1 = m . group ( <NUM_LIT:1> ) <EOL> return g1 . replace ( '<STR_LIT:_>' , '<STR_LIT>' ) <EOL> def pep8func ( name ) : <EOL> """<STR_LIT>""" <EOL> if HAS_UPPER_RE . search ( name ) is not None : <EOL> name = UPPER_DIGIT_RE . sub ( _upperrepl , name ) <EOL> if UNDERSCORE_DIGIT_RE . search ( name [ <NUM_LIT:1> : ] ) is not None : <EOL> name = name [ <NUM_LIT:0> ] + UNDERSCORE_DIGIT_RE . sub ( _usdgrepl , name [ <NUM_LIT:1> : ] ) <EOL> return name <EOL> pep8var = pep8func <EOL> def pep8class ( name ) : <EOL> """<STR_LIT>""" <EOL> name = upperfirst ( name ) <EOL> if HAS_UNDERSCORE_RE . search ( name ) is not None : <EOL> new = UNDERSCORE_WORD_RE . sub ( _underscorerepl , name ) <EOL> while new . startswith ( '<STR_LIT:_>' ) and not name . startswith ( '<STR_LIT:_>' ) : <EOL> new = new [ <NUM_LIT:1> : ] <EOL> name = new <EOL> return name <EOL> def ensure_pep8name ( name , kind ) : <EOL> """<STR_LIT>""" <EOL> name = ensure_apiname ( name ) <EOL> tarname = name . tarname <EOL> old = tarname if isinstance ( tarname , basestring ) else tarname [ <NUM_LIT:0> ] <EOL> if kind == '<STR_LIT:class>' : <EOL> new = pep8class ( old ) <EOL> elif kind == '<STR_LIT>' : <EOL> new = pep8func ( old ) <EOL> elif kind == '<STR_LIT>' : <EOL> new = pep8var ( old ) <EOL> else : <EOL> raise ValueError ( '<STR_LIT>' . format ( kind ) ) <EOL> if old != new : <EOL> new = new if isinstance ( tarname , basestring ) else ( new , ) + tarname [ <NUM_LIT:1> : ] <EOL> name = name . _replace ( tarname = new ) <EOL> return name <EOL> class XDressPlugin ( Plugin ) : <EOL> """<STR_LIT>""" <EOL> def setup ( self , rc ) : <EOL> for i , var in enumerate ( rc . variables ) : <EOL> rc . variables [ i ] = ensure_pep8name ( var , '<STR_LIT>' ) <EOL> for i , fnc in enumerate ( rc . functions ) : <EOL> rc . functions [ i ] = ensure_pep8name ( fnc , '<STR_LIT>' ) <EOL> for i , cls in enumerate ( rc . classes ) : <EOL> rc . classes [ i ] = ensure_pep8name ( cls , '<STR_LIT:class>' ) </s>
