Skip to content
This repository has been archived by the owner on Dec 10, 2018. It is now read-only.

Commit

Permalink
minor coding style tuning.
Browse files Browse the repository at this point in the history
  • Loading branch information
lxyu committed Aug 27, 2014
1 parent 9e0f178 commit dda6970
Showing 1 changed file with 12 additions and 17 deletions.
29 changes: 12 additions & 17 deletions thriftpy/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def parse(schema):
result = {
"__version__": __version__,
"__python__": __python__[:2],
"__hash__": hashlib.md5(schema.encode('utf-8')).digest(),
"__hash__": hashlib.md5(schema.encode("utf-8")).digest(),
"typedefs": {},
"consts": {},
"enums": {},
Expand Down Expand Up @@ -80,7 +80,7 @@ def parse(schema):
const = _const + ttype("ttype") + identifier("name") + EQ + value("value")

# enum parser
enum_value = pa.Group(identifier('name') + pa.Optional(EQ + integer_('value')) + pa.Optional(COMMA))
enum_value = pa.Group(identifier("name") + pa.Optional(EQ + integer_("value")) + pa.Optional(COMMA))
enum_list = pa.Group(pa.ZeroOrMore(enum_value))("members")
enum = _enum + identifier("name") + LBRACE + enum_list + RBRACE
enum.ignore(single_line_comment)
Expand Down Expand Up @@ -109,27 +109,22 @@ def parse(schema):

parser = pa.OneOrMore(
_or(
pa.Group(typedef)('typedefs*'), pa.Group(const)('consts*'),
pa.Group(enum)('enums*'), pa.Group(struct)('structs*'),
pa.Group(exception)('exceptions*'), pa.Group(service)('services')
pa.Group(typedef)("typedefs*"), pa.Group(const)("consts*"),
pa.Group(enum)("enums*"), pa.Group(struct)("structs*"),
pa.Group(exception)("exceptions*"), pa.Group(service)("services")
)
)

for parse_results, _, _ in parser.scanString(schema):
for res in parse_results:
if res.getName() == 'typedefs':
result[res.getName()][res.name] = res.ttype
elif res.getName() == 'consts':
result[res.getName()][res.name] = res.value
elif res.getName() == 'enums':
result[res.getName()][res.name] = res
elif res.getName() == 'structs':
if res.getName() == "typedefs":
result["typedefs"][res.name] = res.ttype
elif res.getName() == "consts":
result["consts"][res.name] = res.value
elif res.getName() == "enums":
result["enums"][res.name] = res
elif res.getName() in ("structs", "exceptions", "services"):
result[res.getName()].append(res)
elif res.getName() == 'exceptions':
result[res.getName()].append(res)
elif res.getName() == 'services':
result[res.getName()].append(res)

return result


Expand Down

0 comments on commit dda6970

Please sign in to comment.