@@ -166,19 +166,27 @@ def __init__(self, value, *args):
166166
167167
168168class LimitExcept (Container ):
169- name = 'limit_except'
169+ def __init__ (self , value , * args ):
170+ super (LimitExcept , self ).__init__ (value , * args )
171+ self .name = 'limit_except'
170172
171173
172174class Types (Container ):
173- name = 'types'
175+ def __init__ (self , value , * args ):
176+ super (Types , self ).__init__ (value , * args )
177+ self .name = 'types'
174178
175179
176180class If (Container ):
177- name = 'if'
181+ def __init__ (self , value , * args ):
182+ super (If , self ).__init__ (value , * args )
183+ self .name = 'if'
178184
179185
180186class Upstream (Container ):
181- name = 'upstream'
187+ def __init__ (self , value , * args ):
188+ super (Upstream , self ).__init__ (value , * args )
189+ self .name = 'upstream'
182190
183191
184192class Key (object ):
@@ -201,11 +209,15 @@ def loads(data):
201209 s = Server ()
202210 lopen .insert (0 , s )
203211 if re .match ('\s*location.*{' , line ):
204- lpath = re .match ('\s*location\s*(.*)\s*{' , line ).group (1 )
212+ lpath = re .match ('\s*location\s*(.*\S+ )\s*{' , line ).group (1 )
205213 l = Location (lpath )
206214 lopen .insert (0 , l )
215+ if re .match ('\s*upstream.*{' , line ):
216+ ups = re .match ('\s*upstream\s*(.*\S+)\s*{' , line ).group (1 )
217+ u = Upstream (ups )
218+ lopen .insert (0 , u )
207219 if re .match ('.*;' , line ):
208- kname , kval = re .match ('.*(?:^|{\s*)(\S+)\s(.+);' , line ).group (1 , 2 )
220+ kname , kval = re .match ('.*(?:^|^\s*| {\s*)(\S+)\s(.+);' , line ).group (1 , 2 )
209221 k = Key (kname , kval )
210222 lopen [0 ].add (k )
211223 if re .match ('.*}' , line ):
@@ -214,10 +226,13 @@ def loads(data):
214226 if isinstance (lopen [0 ], Server ):
215227 f .add (lopen [0 ])
216228 lopen .pop (0 )
217- elif isinstance (lopen [0 ], Location ):
218- l = lopen [0 ]
229+ elif isinstance (lopen [0 ], Container ):
230+ c = lopen [0 ]
219231 lopen .pop (0 )
220- lopen [0 ].add (l )
232+ if lopen :
233+ lopen [0 ].add (c )
234+ else :
235+ f .add (c )
221236 closenum = closenum - 1
222237 if re .match ('\s*#\s*' , line ):
223238 c = Comment (re .match ('\s*#\s*(.*)$' , line ).group (1 ))
0 commit comments