Python xmlrpc.client.Binary() Examples

The following are 21 code examples of xmlrpc.client.Binary(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module xmlrpc.client , or try the search function .
Example #1
Source File: test_xmlrpc.py    From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 6 votes vote down vote up
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) 
Example #2
Source File: test_xmlrpc.py    From Fluid-Designer with GNU General Public License v3.0 6 votes vote down vote up
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) 
Example #3
Source File: test_xmlrpc.py    From ironpython3 with Apache License 2.0 6 votes vote down vote up
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) 
Example #4
Source File: confluence.py    From confluence with MIT License 5 votes vote down vote up
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() 
Example #5
Source File: test_xmlrpc.py    From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 5 votes vote down vote up
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")) 
Example #6
Source File: test_xmlrpc.py    From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 5 votes vote down vote up
def test_string(self):
        d = b'\x01\x02\x03abc123\xff\xfe'
        t = xmlrpclib.Binary(d)
        self.assertEqual(str(t), str(d, "latin-1")) 
Example #7
Source File: test_xmlrpc.py    From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 5 votes vote down vote up
def test_default(self):
        t = xmlrpclib.Binary()
        self.assertEqual(str(t), '') 
Example #8
Source File: test_xmlrpc.py    From ironpython3 with Apache License 2.0 5 votes vote down vote up
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")) 
Example #9
Source File: test_xmlrpc.py    From ironpython3 with Apache License 2.0 5 votes vote down vote up
def test_string(self):
        d = b'\x01\x02\x03abc123\xff\xfe'
        t = xmlrpclib.Binary(d)
        self.assertEqual(str(t), str(d, "latin-1")) 
Example #10
Source File: test_xmlrpc.py    From ironpython3 with Apache License 2.0 5 votes vote down vote up
def test_default(self):
        t = xmlrpclib.Binary()
        self.assertEqual(str(t), '') 
Example #11
Source File: ithenticate.py    From janeway with GNU Affero General Public License v3.0 5 votes vote down vote up
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 
Example #12
Source File: package.py    From apsconnect-cli with Apache License 2.0 5 votes vote down vote up
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() 
Example #13
Source File: test_xmlrpc.py    From Fluid-Designer with GNU General Public License v3.0 5 votes vote down vote up
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")) 
Example #14
Source File: test_xmlrpc.py    From Fluid-Designer with GNU General Public License v3.0 5 votes vote down vote up
def test_string(self):
        d = b'\x01\x02\x03abc123\xff\xfe'
        t = xmlrpclib.Binary(d)
        self.assertEqual(str(t), str(d, "latin-1")) 
Example #15
Source File: test_xmlrpc.py    From Fluid-Designer with GNU General Public License v3.0 5 votes vote down vote up
def test_default(self):
        t = xmlrpclib.Binary()
        self.assertEqual(str(t), '') 
Example #16
Source File: dokuwiki.py    From python-dokuwiki with MIT License 5 votes vote down vote up
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) 
Example #17
Source File: dokuwiki.py    From python-dokuwiki with MIT License 5 votes vote down vote up
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) 
Example #18
Source File: aria2.py    From PyOne with Mozilla Public License 2.0 5 votes vote down vote up
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) 
Example #19
Source File: aria2.py    From PyOne with Mozilla Public License 2.0 5 votes vote down vote up
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) 
Example #20
Source File: tornado_fetcher.py    From pyspider with Apache License 2.0 5 votes vote down vote up
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() 
Example #21
Source File: confluence.py    From confluence with MIT License 4 votes vote down vote up
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()