Skip to content

Commit 0ba07f4

Browse files
committed
base: Push XMLRPC Binary handling down into Backend
Signed-off-by: Cole Robinson <[email protected]>
1 parent 425378b commit 0ba07f4

3 files changed

Lines changed: 12 additions & 8 deletions

File tree

bugzilla/_backendbase.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,14 @@ def bug_attachment_get_all(self, bug_ids, paramdict):
5959
"""
6060
raise NotImplementedError()
6161

62-
def bug_attachment_create(self, paramdict):
62+
def bug_attachment_create(self, data, paramdict):
6363
"""
6464
Create a bug attachment
6565
http://bugzilla.readthedocs.io/en/latest/api/core/v1/attachment.html#create-attachment
66+
67+
:param data: raw Bytes data of the attachment to attach. API will
68+
encode this correctly if you pass it in and 'data' is not in
69+
paramdict.
6670
"""
6771
raise NotImplementedError()
6872

bugzilla/_backendxmlrpc.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66

77
# pylint: disable=import-error
88
if sys.version_info[0] >= 3:
9-
from xmlrpc.client import Fault, ProtocolError, ServerProxy, Transport
9+
from xmlrpc.client import (Binary, Fault, ProtocolError,
10+
ServerProxy, Transport)
1011
else:
11-
from xmlrpclib import Fault, ProtocolError, ServerProxy, Transport
12+
from xmlrpclib import Binary, Fault, ProtocolError, ServerProxy, Transport
1213
# pylint: enable=import-error
1314

1415
from requests import RequestException
@@ -172,7 +173,9 @@ def bug_attachment_get_all(self, bug_ids, paramdict):
172173
data = paramdict.copy()
173174
data["ids"] = listify(bug_ids)
174175
return self._xmlrpc_proxy.Bug.attachments(data)
175-
def bug_attachment_create(self, paramdict):
176+
def bug_attachment_create(self, data, paramdict):
177+
if data is not None and "data" not in paramdict:
178+
paramdict["data"] = Binary(data)
176179
return self._xmlrpc_proxy.Bug.add_attachment(paramdict)
177180
def bug_attachment_update(self, paramdict):
178181
return self._xmlrpc_proxy.Bug.update_attachment(paramdict)

bugzilla/base.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,9 @@
1919
if sys.version_info[0] >= 3:
2020
from collections.abc import Mapping
2121
from urllib.parse import urlparse, urlunparse, parse_qsl
22-
from xmlrpc.client import Binary
2322
else:
2423
from collections import Mapping
2524
from urlparse import urlparse, urlunparse, parse_qsl
26-
from xmlrpclib import Binary
2725
# pylint: enable=import-error,no-name-in-module,ungrouped-imports
2826

2927

@@ -1523,7 +1521,6 @@ def attachfile(self, idlist, attachfile, description, **kwargs):
15231521
data = f.read()
15241522
if not isinstance(data, bytes):
15251523
data = data.encode(locale.getpreferredencoding())
1526-
kwargs['data'] = Binary(data)
15271524

15281525
kwargs['ids'] = listify(idlist)
15291526

@@ -1536,7 +1533,7 @@ def attachfile(self, idlist, attachfile, description, **kwargs):
15361533
kwargs['file_name'], strict=False)[0]
15371534
kwargs['content_type'] = ctype or 'application/octet-stream'
15381535

1539-
ret = self._backend.bug_attachment_create(kwargs)
1536+
ret = self._backend.bug_attachment_create(data, kwargs)
15401537

15411538
if "attachments" in ret:
15421539
# Up to BZ 4.2

0 commit comments

Comments
 (0)