Skip to content

Commit ea23c04

Browse files
committed
base: Reimplement openattachment to use get_attachments
This impl predates any attachment APIs, so it grabs attachment from a URL. This is broken with current bugzilla.redhat.com though, and since it requires silly tricks anyways, just convert to using standard APIs
1 parent 45e1458 commit ea23c04

1 file changed

Lines changed: 5 additions & 26 deletions

File tree

bugzilla/base.py

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1531,34 +1531,13 @@ def attachfile(self, idlist, attachfile, description, **kwargs):
15311531
def openattachment(self, attachid):
15321532
'''Get the contents of the attachment with the given attachment ID.
15331533
Returns a file-like object.'''
1534-
1535-
def get_filename(headers):
1536-
import re
1537-
1538-
match = re.search(
1539-
r'^.*filename="?(.*)"$',
1540-
headers.get('content-disposition', '')
1541-
)
1542-
1543-
# default to attchid if no match was found
1544-
return match.group(1) if match else attachid
1545-
1546-
att_uri = self._attachment_uri(attachid)
1547-
1548-
defaults = self._transport.request_defaults.copy()
1549-
defaults["headers"] = defaults["headers"].copy()
1550-
del(defaults["headers"]["Content-Type"])
1551-
1552-
response = self._transport.session.get(
1553-
att_uri, stream=True, **defaults)
1534+
attachments = self.get_attachments(None, attachid)
1535+
data = attachments["attachments"][str(attachid)]
1536+
xmlrpcbinary = data["data"]
15541537

15551538
ret = BytesIO()
1556-
for chunk in response.iter_content(chunk_size=1024):
1557-
if chunk:
1558-
ret.write(chunk)
1559-
ret.name = get_filename(response.headers)
1560-
1561-
# Hooray, now we have a file-like object with .read() and .name
1539+
ret.write(xmlrpcbinary.data)
1540+
ret.name = data["file_name"]
15621541
ret.seek(0)
15631542
return ret
15641543

0 commit comments

Comments
 (0)