Skip to content

Commit

Permalink
Merge pull request #11 from tonyseek/refactoring
Browse files Browse the repository at this point in the history
A bit improvement.
  • Loading branch information
lepture committed Jan 26, 2015
2 parents 1c299de + 9150d23 commit 12112af
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions flask_weixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def validate(self, signature, timestamp, nonce):
if self.expires_in:
try:
timestamp = int(timestamp)
except:
except (ValueError, TypeError):
# fake timestamp
return False

Expand All @@ -89,7 +89,12 @@ def parse(self, content):
:param content: A text of xml body.
"""
raw = {}
root = etree.fromstring(content)

try:
root = etree.fromstring(content)
except SyntaxError as e:
raise ValueError(*e.args)

for child in root:
raw[child.tag] = child.text

Expand Down Expand Up @@ -281,7 +286,7 @@ def view_func(self):

try:
ret = self.parse(request.data)
except:
except ValueError:
return 'invalid', 400

if 'type' not in ret:
Expand Down Expand Up @@ -350,7 +355,7 @@ def news_reply(username, sender, *items):
'<Url><![CDATA[%(url)s]]></Url>'
'</item>'
)
articles = map(lambda o: item_template % o, items)
articles = [item_template % o for o in items]

template = (
'<xml>'
Expand Down

0 comments on commit 12112af

Please sign in to comment.