Bugtracker: Work around PySimpleSOAP still lacking Base64 support.
This commit is contained in:
@ -24,7 +24,7 @@ import supybot.world as world
|
|||||||
|
|
||||||
from imp import reload
|
from imp import reload
|
||||||
|
|
||||||
__version__ = "4.6.0"
|
__version__ = "4.7.0"
|
||||||
__author__ = supybot.Author("Krytarik Raido", "krytarik", "krytarik@tuxgarage.com")
|
__author__ = supybot.Author("Krytarik Raido", "krytarik", "krytarik@tuxgarage.com")
|
||||||
__contributors__ = {
|
__contributors__ = {
|
||||||
supybot.Author("Dennis Kaarsemaker", "Seveas", "dennis@kaarsemaker.net"): ['Original Author'],
|
supybot.Author("Dennis Kaarsemaker", "Seveas", "dennis@kaarsemaker.net"): ['Original Author'],
|
||||||
|
@ -19,7 +19,7 @@ import supybot.utils as utils
|
|||||||
import supybot.conf as conf
|
import supybot.conf as conf
|
||||||
import supybot.log as supylog
|
import supybot.log as supylog
|
||||||
|
|
||||||
import re, os, json
|
import sys, os, re, json, base64
|
||||||
import xml.dom.minidom as minidom
|
import xml.dom.minidom as minidom
|
||||||
from email.parser import FeedParser
|
from email.parser import FeedParser
|
||||||
from pysimplesoap.client import SoapClient
|
from pysimplesoap.client import SoapClient
|
||||||
@ -36,7 +36,7 @@ def _getnodetxt(node):
|
|||||||
encoding = node.getAttribute('encoding')
|
encoding = node.getAttribute('encoding')
|
||||||
if encoding == 'base64':
|
if encoding == 'base64':
|
||||||
try:
|
try:
|
||||||
val = val.decode('base64')
|
val = decodeBase64(val)
|
||||||
except:
|
except:
|
||||||
val = 'Cannot convert bug data from base64.'
|
val = 'Cannot convert bug data from base64.'
|
||||||
return utils.web.htmlToText(val, tagReplace='')
|
return utils.web.htmlToText(val, tagReplace='')
|
||||||
@ -48,6 +48,18 @@ def _getnodeattr(node, attr):
|
|||||||
raise ValueError("No such attribute")
|
raise ValueError("No such attribute")
|
||||||
return utils.web.htmlToText(val, tagReplace='')
|
return utils.web.htmlToText(val, tagReplace='')
|
||||||
|
|
||||||
|
# Work around PySimpleSOAP still lacking Base64 support
|
||||||
|
def checkBase64(text):
|
||||||
|
if re.match(r'^[a-zA-Z0-9+/]+={0,2}$', text) and len(text) % 4 == 0:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
def decodeBase64(text):
|
||||||
|
if sys.version_info < (3,0):
|
||||||
|
return base64.b64decode(text)
|
||||||
|
else:
|
||||||
|
return base64.b64decode(text).decode('utf-8')
|
||||||
|
|
||||||
class BugtrackerError(Exception):
|
class BugtrackerError(Exception):
|
||||||
"""A bugtracker error"""
|
"""A bugtracker error"""
|
||||||
pass
|
pass
|
||||||
@ -363,11 +375,14 @@ class Debbugs(IBugtracker):
|
|||||||
raise BugNotFoundError
|
raise BugNotFoundError
|
||||||
try:
|
try:
|
||||||
raw = raw.item.value
|
raw = raw.item.value
|
||||||
|
title = str(raw.subject)
|
||||||
|
if checkBase64(title):
|
||||||
|
title = decodeBase64(title)
|
||||||
if str(raw.fixed_versions):
|
if str(raw.fixed_versions):
|
||||||
status = 'Fixed'
|
status = 'Fixed'
|
||||||
else:
|
else:
|
||||||
status = 'Open'
|
status = 'Open'
|
||||||
return (bugid, str(raw.package), str(raw.subject), str(raw.severity), status, '', "%s/%s" % (self.url, bugid), [], [])
|
return (bugid, str(raw.package), title, str(raw.severity), status, '', "%s/%s" % (self.url, bugid), [], [])
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise BugtrackerError(self.errparse % (self.description, e, url))
|
raise BugtrackerError(self.errparse % (self.description, e, url))
|
||||||
|
|
||||||
@ -664,7 +679,10 @@ class Mantis(IBugtracker):
|
|||||||
if not hasattr(raw, 'id'):
|
if not hasattr(raw, 'id'):
|
||||||
raise BugNotFoundError
|
raise BugNotFoundError
|
||||||
try:
|
try:
|
||||||
return (bugid, str(raw.project.name), str(raw.summary), str(raw.severity.name), str(raw.resolution.name), '', url, [], [])
|
title = str(raw.summary)
|
||||||
|
if checkBase64(title):
|
||||||
|
title = decodeBase64(title)
|
||||||
|
return (bugid, str(raw.project.name), title, str(raw.severity.name), str(raw.resolution.name), '', url, [], [])
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise BugtrackerError(self.errparse % (self.description, e, url))
|
raise BugtrackerError(self.errparse % (self.description, e, url))
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user