Skip to content

Commit 48b98e0

Browse files
author
jacook
committed
fixes
1 parent 208fa8f commit 48b98e0

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

main.py

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -166,19 +166,27 @@ def __init__(self, value, *args):
166166

167167

168168
class 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

172174
class Types(Container):
173-
name = 'types'
175+
def __init__(self, value, *args):
176+
super(Types, self).__init__(value, *args)
177+
self.name = 'types'
174178

175179

176180
class If(Container):
177-
name = 'if'
181+
def __init__(self, value, *args):
182+
super(If, self).__init__(value, *args)
183+
self.name = 'if'
178184

179185

180186
class Upstream(Container):
181-
name = 'upstream'
187+
def __init__(self, value, *args):
188+
super(Upstream, self).__init__(value, *args)
189+
self.name = 'upstream'
182190

183191

184192
class 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))

test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ def test():
77
def messy():
88
return nginx.loads("""
99
# This is an example of a messy config
10+
upstream php { server unix:/tmp/php-cgi.socket; }
1011
server { server_name localhost; #this is the server server_name
1112
location /{ test_key test_value; }}
1213
""")

0 commit comments

Comments
 (0)