Skip to content

Commit 4b3aaa3

Browse files
committed
Merge pull request six519#1 from achesak/master
__parseUser() now checks for if the elements are there first.
2 parents 11fb8b3 + 7d213c7 commit 4b3aaa3

File tree

1 file changed

+31
-13
lines changed

1 file changed

+31
-13
lines changed

pastebin_python/pastebin.py

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -227,20 +227,38 @@ def __parseUser(self, xmlString):
227227
228228
"""
229229
retList = []
230-
userElements = xmlString.getElementsByTagName('user')
231-
230+
userElement = xmlString.getElementsByTagName('user')[0]
231+
232232
retList.append({
233-
'user_name':userElements[0].getElementsByTagName('user_name')[0].childNodes[0].nodeValue,
234-
'user_format_short':userElements[0].getElementsByTagName('user_format_short')[0].childNodes[0].nodeValue,
235-
'user_expiration':userElements[0].getElementsByTagName('user_expiration')[0].childNodes[0].nodeValue,
236-
'user_avatar_url':userElements[0].getElementsByTagName('user_avatar_url')[0].childNodes[0].nodeValue,
237-
'user_private':userElements[0].getElementsByTagName('user_private')[0].childNodes[0].nodeValue,
238-
'user_website':userElements[0].getElementsByTagName('user_website')[0].childNodes[0].nodeValue,
239-
'user_email':userElements[0].getElementsByTagName('user_email')[0].childNodes[0].nodeValue,
240-
'user_location':userElements[0].getElementsByTagName('user_location')[0].childNodes[0].nodeValue,
241-
'user_account_type':userElements[0].getElementsByTagName('user_account_type')[0].childNodes[0].nodeValue
233+
'user_name':userElement.getElementsByTagName('user_name')[0].childNodes[0].nodeValue,
234+
'user_avatar_url':userElement.getElementsByTagName('user_avatar_url')[0].childNodes[0].nodeValue,
235+
'user_account_type':userElement.getElementsByTagName('user_account_type')[0].childNodes[0].nodeValue
242236
})
243-
237+
238+
formatElement = userElement.getElementsByTagName('user_format_short')
239+
if formatElement:
240+
retList[0]['user_format_short'] = formatElement[0].childNodes[0].nodeValue
241+
242+
expireElement = userElement.getElementsByTagName('user_expiration')
243+
if expireElement:
244+
retList[0]['user_expiration'] = expireElement[0].childNodes[0].nodeValue
245+
246+
privateElement = userElement.getElementsByTagName('user_private')
247+
if privateElement:
248+
retList[0]['user_private'] = privateElement[0].childNodes[0].nodeValue
249+
250+
websiteElement = userElement.getElementsByTagName('user_website')
251+
if websiteElement:
252+
retList[0]['user_website'] = websiteElement[0].childNodes[0].nodeValue
253+
254+
emailElement = userElement.getElementsByTagName('user_email')
255+
if emailElement:
256+
retList[0]['user_email'] = emailElement[0].childNodes[0].nodeValue
257+
258+
locationElement = userElement.getElementsByTagName('user_location')
259+
if locationElement:
260+
retList[0]['user_location'] = locationElement[0].childNodes[0].nodeValue
261+
244262
return retList
245263

246264
def __parsePaste(self, xmlString):
@@ -368,4 +386,4 @@ def getPasteRawOutput(self, api_paste_key):
368386
except urllib2.HTTPError as e:
369387
raise PastebinHTTPErrorException(str(e))
370388

371-
return response.decode('utf-8')
389+
return response.decode('utf-8')

0 commit comments

Comments
 (0)