當前位置: 首頁>>代碼示例>>Python>>正文


Python client.Binary方法代碼示例

本文整理匯總了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) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:20,代碼來源:test_xmlrpc.py

示例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() 
開發者ID:cloudblue,項目名稱:apsconnect-cli,代碼行數:17,代碼來源:package.py

示例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() 
開發者ID:binux,項目名稱:pyspider,代碼行數:36,代碼來源:tornado_fetcher.py

示例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) 
開發者ID:abbeyokgo,項目名稱:PyOne,代碼行數:12,代碼來源:aria2.py

示例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) 
開發者ID:abbeyokgo,項目名稱:PyOne,代碼行數:11,代碼來源:aria2.py

示例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) 
開發者ID:fmenabe,項目名稱:python-dokuwiki,代碼行數:9,代碼來源:dokuwiki.py

示例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) 
開發者ID:fmenabe,項目名稱:python-dokuwiki,代碼行數:8,代碼來源:dokuwiki.py

示例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), '') 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:5,代碼來源:test_xmlrpc.py

示例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")) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:6,代碼來源:test_xmlrpc.py

示例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")) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:11,代碼來源:test_xmlrpc.py

示例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() 
開發者ID:pycontribs,項目名稱:confluence,代碼行數:29,代碼來源:confluence.py

示例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 
開發者ID:BirkbeckCTP,項目名稱:janeway,代碼行數:43,代碼來源:ithenticate.py

示例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() 
開發者ID:pycontribs,項目名稱:confluence,代碼行數:47,代碼來源:confluence.py


注:本文中的xmlrpc.client.Binary方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。