本文整理汇总了Python中xmlrpclib.Binary方法的典型用法代码示例。如果您正苦于以下问题:Python xmlrpclib.Binary方法的具体用法?Python xmlrpclib.Binary怎么用?Python xmlrpclib.Binary使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xmlrpclib
的用法示例。
在下文中一共展示了xmlrpclib.Binary方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: terminate_proc
# 需要导入模块: import xmlrpclib [as 别名]
# 或者: from xmlrpclib import Binary [as 别名]
def terminate_proc(self, argv):
try:
(ptype, val) = argv.split(' ')
# ptype = '/PID' if ptype == 'pid' else '/IM'
# cmd = 'cmd.exe /c taskkill %s %s' % (ptype, val)
# log = 'cmd.log'
# p = subprocess.Popen(cmd, stdout=file(log, 'w'), stderr=subprocess.STDOUT)
# p.wait()
# data = self.__read_file(log)
# https://www.cnblogs.com/xjh713/p/6306587.html?utm_source=itdadao&utm_medium=referral
if sys.platform == 'win32':
ptype = '/PID' if ptype == 'pid' else '/IM'
data = os.popen('taskkill %s %s' % (ptype, val)).read()
else:
os.kill(val, signal.SIGKILL)
return (True, xmlrpclib.Binary(data))
except Exception as e:
return (False, str(e))
示例2: main
# 需要导入模块: import xmlrpclib [as 别名]
# 或者: from xmlrpclib import Binary [as 别名]
def main(options, args):
address = "%s://%s:%s@%s:%s%s" % (PROTOCOL, options.username, options.password,
options.server, options.port, ENDPOINT)
print "Connecting to: %s" % hidepassword(address)
server = xmlrpclib.ServerProxy(address, verbose=VERBOSE)
try:
plugin_id, version_id = server.plugin.upload(xmlrpclib.Binary(open(args[0]).read()))
print "Plugin ID: %s" % plugin_id
print "Version ID: %s" % version_id
except xmlrpclib.ProtocolError, err:
print "A protocol error occurred"
print "URL: %s" % hidepassword(err.url, 0)
print "HTTP/HTTPS headers: %s" % err.headers
print "Error code: %d" % err.errcode
print "Error message: %s" % err.errmsg
示例3: __init__
# 需要导入模块: import xmlrpclib [as 别名]
# 或者: from xmlrpclib 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()
示例4: xmlrpc_run
# 需要导入模块: import xmlrpclib [as 别名]
# 或者: from xmlrpclib 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()
示例5: main
# 需要导入模块: import xmlrpclib [as 别名]
# 或者: from xmlrpclib import Binary [as 别名]
def main(parameters, arguments):
"""Main entry point.
:param parameters: Command line parameters.
:param arguments: Command line arguments.
"""
address = "%s://%s:%s@%s:%s%s" % (
PROTOCOL,
parameters.username,
parameters.password,
parameters.server,
parameters.port,
ENDPOINT)
print "Connecting to: %s" % hide_password(address)
server = xmlrpclib.ServerProxy(address, verbose=VERBOSE)
try:
plugin_id, version_id = server.plugin.upload(
xmlrpclib.Binary(open(arguments[0]).read()))
print "Plugin ID: %s" % plugin_id
print "Version ID: %s" % version_id
except xmlrpclib.ProtocolError, err:
print "A protocol error occurred"
print "URL: %s" % hide_password(err.url, 0)
print "HTTP/HTTPS headers: %s" % err.headers
print "Error code: %d" % err.errcode
print "Error message: %s" % err.errmsg
示例6: addTorrent
# 需要导入模块: import xmlrpclib [as 别名]
# 或者: from xmlrpclib 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)
示例7: addMetalink
# 需要导入模块: import xmlrpclib [as 别名]
# 或者: from xmlrpclib 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)
示例8: add
# 需要导入模块: import xmlrpclib [as 别名]
# 或者: from xmlrpclib 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)
示例9: set
# 需要导入模块: import xmlrpclib [as 别名]
# 或者: from xmlrpclib 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)
示例10: test_default
# 需要导入模块: import xmlrpclib [as 别名]
# 或者: from xmlrpclib import Binary [as 别名]
def test_default(self):
t = xmlrpclib.Binary()
self.assertEqual(str(t), '')
示例11: test_string
# 需要导入模块: import xmlrpclib [as 别名]
# 或者: from xmlrpclib import Binary [as 别名]
def test_string(self):
d = '\x01\x02\x03abc123\xff\xfe'
t = xmlrpclib.Binary(d)
self.assertEqual(str(t), d)
示例12: test_decode
# 需要导入模块: import xmlrpclib [as 别名]
# 或者: from xmlrpclib import Binary [as 别名]
def test_decode(self):
d = '\x01\x02\x03abc123\xff\xfe'
de = base64.encodestring(d)
t1 = xmlrpclib.Binary()
t1.decode(de)
self.assertEqual(str(t1), d)
t2 = xmlrpclib._binary(de)
self.assertEqual(str(t2), d)
示例13: upload_file
# 需要导入模块: import xmlrpclib [as 别名]
# 或者: from xmlrpclib import Binary [as 别名]
def upload_file():
with open(filepath, "rb") as handle:
binary_data = xmlrpclib.Binary(handle.read())
proxy.server_receive_file(filename,binary_data)
示例14: attach_file
# 需要导入模块: import xmlrpclib [as 别名]
# 或者: from xmlrpclib 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()
示例15: getPdf
# 需要导入模块: import xmlrpclib [as 别名]
# 或者: from xmlrpclib import Binary [as 别名]
def getPdf(self,aMsg):
c = canvas.Canvas(None)
c.drawString(100,100,aMsg)
c.showPage()
c.save()
return xmlrpclib.Binary(c.getpdfdata())