@@ -101,12 +101,38 @@ def formatSyntaxTransf(match):
101101 inside a format specifier string.
102102 """
103103 groups = match .groupdict ()
104+ if groups ['convers' ] == 'n' :
105+ # Means platform-specific line separator
106+ return '\\ n' # Py converts \n to os.linesep
107+
104108 result = '{'
105- # TODO: add flags, width and precision
109+ thous_sep = ''
110+
106111 if (groups ['idx' ]):
107112 idx = int (groups ['idx' ][:- 1 ])
108113 result += str (idx - 1 ) # Py starts count from 0
109- result += ':' + groups ['convers' ] + '}'
114+ result += ':'
115+
116+ if (groups ['flags' ]):
117+ if ',' in groups ['flags' ]:
118+ thous_sep = ','
119+ if '+' in groups ['flags' ]:
120+ result += '+'
121+ elif ' ' in groups ['flags' ]:
122+ result += ' '
123+ if '#' in groups ['flags' ]:
124+ result += '#'
125+ if '0' in groups ['flags' ]:
126+ result += '0'
127+
128+ if (groups ['width' ]):
129+ result += groups ['width' ]
130+ result += thous_sep
131+
132+ if (groups ['precision' ]):
133+ result += groups ['precision' ]
134+
135+ result += groups ['convers' ] + '}'
110136
111137 return result
112138
@@ -124,7 +150,7 @@ def formatString(node, config):
124150 format = call_args [0 ].firstChildOfType (tokens .STRING_LITERAL )
125151 if format :
126152 format .token .text = \
127- re .sub (r'%(?P<idx>\d+\$)?(?P<convers>[scdoxefg ])' ,
153+ re .sub (r'%(?P<idx>\d+\$)?(?P<flags>[-+# 0,]+)?(?P<width>[0-9]+)?(?P<precision>\.[0-9]+)?(?P< convers>[scdoxefgn ])' ,
128154 formatSyntaxTransf ,
129155 format .token .text ,
130156 flags = re .IGNORECASE )
0 commit comments