本文整理汇总了Python中xmlrpc.client.Binary方法的典型用法代码示例。如果您正苦于以下问题:Python client.Binary方法的具体用法?Python client.Binary怎么用?Python client.Binary使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xmlrpc.client
的用法示例。
在下文中一共展示了client.Binary方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_dump_bytes
# 需要导入模块: from xmlrpc import client [as 别名]
# 或者: from xmlrpc.client import Binary [as 别名]
def test_dump_bytes(self):
sample = b"my dog has fleas"
self.assertEqual(sample, xmlrpclib.Binary(sample))
for type_ in bytes, bytearray, xmlrpclib.Binary:
value = type_(sample)
s = xmlrpclib.dumps((value,))
result, m = xmlrpclib.loads(s, use_builtin_types=True)
(newvalue,) = result
self.assertEqual(newvalue, sample)
self.assertIs(type(newvalue), bytes)
self.assertIsNone(m)
result, m = xmlrpclib.loads(s, use_builtin_types=False)
(newvalue,) = result
self.assertEqual(newvalue, sample)
self.assertIs(type(newvalue), xmlrpclib.Binary)
self.assertIsNone(m)
示例2: __init__
# 需要导入模块: from xmlrpc import client [as 别名]
# 或者: from xmlrpc.client import Binary [as 别名]
def __init__(self, source, instance_only=False):
self.instance_only = instance_only
with TemporaryDirectory() as tempdir:
self.source = source
self.tempdir = tempdir
if self.is_http:
self.filename = Package._download(self.source, self.tempdir)
else:
self.filename = os.path.basename(self.source)
copyfile(os.path.expanduser(self.source), os.path.join(self.tempdir, self.filename))
self.path = os.path.join(self.tempdir, self.filename)
with open(self.path, 'rb') as f:
self.body = xmlrpclib.Binary(f.read())
self._extract_files()
self._parse_metadata()
示例3: xmlrpc_run
# 需要导入模块: from xmlrpc import client [as 别名]
# 或者: from xmlrpc.client import Binary [as 别名]
def xmlrpc_run(self, port=24444, bind='127.0.0.1', logRequests=False):
'''Run xmlrpc server'''
import umsgpack
from pyspider.libs.wsgi_xmlrpc import WSGIXMLRPCApplication
try:
from xmlrpc.client import Binary
except ImportError:
from xmlrpclib import Binary
application = WSGIXMLRPCApplication()
application.register_function(self.quit, '_quit')
application.register_function(self.size)
def sync_fetch(task):
result = self.sync_fetch(task)
result = Binary(umsgpack.packb(result))
return result
application.register_function(sync_fetch, 'fetch')
def dump_counter(_time, _type):
return self._cnt[_time].to_dict(_type)
application.register_function(dump_counter, 'counter')
import tornado.wsgi
import tornado.ioloop
import tornado.httpserver
container = tornado.wsgi.WSGIContainer(application)
self.xmlrpc_ioloop = tornado.ioloop.IOLoop()
self.xmlrpc_server = tornado.httpserver.HTTPServer(container, io_loop=self.xmlrpc_ioloop)
self.xmlrpc_server.listen(port=port, address=bind)
logger.info('fetcher.xmlrpc listening on %s:%s', bind, port)
self.xmlrpc_ioloop.start()
示例4: addTorrent
# 需要导入模块: from xmlrpc import client [as 别名]
# 或者: from xmlrpc.client import Binary [as 别名]
def addTorrent(self, torrent, uris=None, options=None, position=None):
'''
This method adds BitTorrent download by uploading ".torrent" file.
torrent: string, torrent file path
uris: list, list of webseed URIs
options: dict, additional options
position: integer, position in download queue
return: This method returns GID of registered download.
'''
return self.server.aria2.addTorrent(xmlrpclib.Binary(open(torrent, 'rb').read()), uris, options, position)
示例5: addMetalink
# 需要导入模块: from xmlrpc import client [as 别名]
# 或者: from xmlrpc.client import Binary [as 别名]
def addMetalink(self, metalink, options=None, position=None):
'''
This method adds Metalink download by uploading ".metalink" file.
metalink: string, metalink file path
options: dict, additional options
position: integer, position in download queue
return: This method returns list of GID of registered download.
'''
return self.server.aria2.addMetalink(xmlrpclib.Binary(open(metalink, 'rb').read()), options, position)
示例6: add
# 需要导入模块: from xmlrpc import client [as 别名]
# 或者: from xmlrpc.client import Binary [as 别名]
def add(self, media, filepath, overwrite=True):
"""Set *media* from local file *filepath*. *overwrite* parameter specify
if the media must be overwrite if it exists remotely.
"""
with open(filepath, 'rb') as fhandler:
self._dokuwiki.send('wiki.putAttachment', media,
Binary(fhandler.read()), ow=overwrite)
示例7: set
# 需要导入模块: from xmlrpc import client [as 别名]
# 或者: from xmlrpc.client import Binary [as 别名]
def set(self, media, _bytes, overwrite=True, b64encode=False):
"""Set *media* from *_bytes*. *overwrite* parameter specify if the media
must be overwrite if it exists remotely.
"""
data = base64.b64encode(_bytes) if b64encode else Binary(_bytes)
self._dokuwiki.send('wiki.putAttachment', media, data, ow=overwrite)
示例8: test_default
# 需要导入模块: from xmlrpc import client [as 别名]
# 或者: from xmlrpc.client import Binary [as 别名]
def test_default(self):
t = xmlrpclib.Binary()
self.assertEqual(str(t), '')
示例9: test_string
# 需要导入模块: from xmlrpc import client [as 别名]
# 或者: from xmlrpc.client import Binary [as 别名]
def test_string(self):
d = b'\x01\x02\x03abc123\xff\xfe'
t = xmlrpclib.Binary(d)
self.assertEqual(str(t), str(d, "latin-1"))
示例10: test_decode
# 需要导入模块: from xmlrpc import client [as 别名]
# 或者: from xmlrpc.client import Binary [as 别名]
def test_decode(self):
d = b'\x01\x02\x03abc123\xff\xfe'
de = base64.encodebytes(d)
t1 = xmlrpclib.Binary()
t1.decode(de)
self.assertEqual(str(t1), str(d, "latin-1"))
t2 = xmlrpclib._binary(de)
self.assertEqual(str(t2), str(d, "latin-1"))
示例11: attach_file
# 需要导入模块: from xmlrpc import client [as 别名]
# 或者: from xmlrpc.client import Binary [as 别名]
def attach_file(server, token, space, title, files):
existing_page = server.confluence1.getPage(token, space, title)
for filename in files.keys():
try:
server.confluence1.removeAttachment(token, existing_page["id"], filename)
except Exception as e:
logging.exception("Skipping %s exception in removeAttachment" % e)
content_types = {
"gif": "image/gif",
"png": "image/png",
"jpg": "image/jpeg",
"jpeg": "image/jpeg",
}
extension = os.path.spl(filename)[1]
ty = content_types.get(extension, "application/binary")
attachment = {"fileName": filename, "contentType": ty, "comment": files[filename]}
f = open(filename, "rb")
try:
byts = f.read()
logging.info("calling addAttachment(%s, %s, %s, ...)", token, existing_page["id"], repr(attachment))
server.confluence1.addAttachment(token, existing_page["id"], attachment, xmlrpclib.Binary(byts))
logging.info("done")
except Exception:
logging.exception("Unable to attach %s", filename)
finally:
f.close()
示例12: send_to_ithenticate
# 需要导入模块: from xmlrpc import client [as 别名]
# 或者: from xmlrpc.client import Binary [as 别名]
def send_to_ithenticate(article, file):
# 1. Init Server
server = build_server(article.journal)
# 2. Try to get this journal's folder
folder_id = find_folder(server['server'], server['sid'], article.journal)
# 2.1 If the journal doesn't have a folder, make one
if not folder_id:
folder_id = make_folder(server['server'], server['sid'], article.journal)
# 3. Prepare the submission
first_author = article.correspondence_author
open_file = codecs.open(file.self_article_path(), 'rb')
data = xmlrpclib.Binary(bytes(open_file.read()))
article_dict = {
'title': article.title,
'author_first': first_author.first_name,
'author_last': first_author.last_name,
'filename': os.path.basename(file.original_filename),
'upload': data,
}
submission_dict = {
'sid': server['sid'],
'folder': folder_id,
'uploads': [article_dict],
'submit_to': 1,
}
submission = server['server'].document.add(
submission_dict
)
if submission['status'] == 200:
return submission['uploaded'][0].get('id')
else:
return None
示例13: attachFile
# 需要导入模块: from xmlrpc import client [as 别名]
# 或者: from xmlrpc.client import Binary [as 别名]
def attachFile(self, page, space, files):
"""
Attach (upload) a file to a page
:param page: The page name
:type page: ``str``
:param space: The space name
:type space: ``str``
:param files: The files to upload
:type files: ``dict`` where `key` is filename and `value` is the comment.
"""
if self._token2:
server = self._server.confluence2
token = self._token2
else:
server = self._server.confluence1
token = self._token1
existing_page = server.getPage(token, space, page)
for filename in files.keys():
try:
server.removeAttachment(token, existing_page["id"], filename)
except xmlrpclib.Fault:
logging.info("No existing attachment to replace")
content_types = {
"gif": "image/gif",
"png": "image/png",
"jpg": "image/jpeg",
"jpeg": "image/jpeg",
"pdf": "application/pdf",
}
extension = os.path.splitext(filename)[1:]
ty = content_types.get(extension, "application/binary")
attachment = {"fileName": filename, "contentType": ty, "comment": files[filename]}
f = open(filename, "rb")
try:
byts = f.read()
logging.info("calling addAttachment(%s, %s, %s, ...)", token, existing_page["id"], repr(attachment))
server.addAttachment(token, existing_page["id"], attachment, xmlrpclib.Binary(byts))
logging.info("done")
except xmlrpclib.Error:
logging.exception("Unable to attach %s", filename)
finally:
f.close()