How to use the buildbot.util.unicode2bytes function in buildbot

To help you get started, we’ve selected a few buildbot examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github buildbot / buildbot / master / buildbot / clients / tryclient.py View on Github external
if tryport:
                argv += ["-p", tryport]

            argv += [tryhost, buildbotbin, "tryserver", "--jobdir", trydir]
            pp = RemoteTryPP(self.jobfile)
            reactor.spawnProcess(pp, argv[0], argv, os.environ)
            d = pp.d
            return d
        if self.connect == "pb":
            user = self.getopt("username")
            passwd = self.getopt("passwd")
            master = self.getopt("master")
            tryhost, tryport = master.split(":")
            tryport = int(tryport)
            f = pb.PBClientFactory()
            d = f.login(credentials.UsernamePassword(unicode2bytes(user), unicode2bytes(passwd)))
            reactor.connectTCP(tryhost, tryport, f)
            d.addCallback(self._deliverJob_pb)
            return d
        raise RuntimeError("unknown connecttype '{}', "
                           "should be 'ssh' or 'pb'".format(self.connect))
github buildbot / buildbot / master / buildbot / clients / sendchange.py View on Github external
def __init__(self, master, auth=('change', 'changepw'), encoding='utf8'):
        self.username = unicode2bytes(auth[0])
        self.password = unicode2bytes(auth[1])
        self.host, self.port = master.split(":")
        self.port = int(self.port)
        self.encoding = encoding
github buildbot / buildbot / master / buildbot / www / rest.py View on Github external
def handleErrors(self, writeError):
        try:
            yield
        except exceptions.InvalidPathError as e:
            msg = unicode2bytes(e.args[0])
            writeError(msg or b"invalid path", errcode=404,
                       jsonrpccode=JSONRPC_CODES['invalid_request'])
            return
        except exceptions.InvalidControlException as e:
            msg = unicode2bytes(str(e))
            writeError(msg or b"invalid control action", errcode=501,
                       jsonrpccode=JSONRPC_CODES["method_not_found"])
            return
        except BadRequest as e:
            msg = unicode2bytes(e.args[0])
            writeError(msg or b"invalid request", errcode=400,
                       jsonrpccode=JSONRPC_CODES["method_not_found"])
            return
        except BadJsonRpc2 as e:
            msg = unicode2bytes(e.message)
            writeError(msg, errcode=400, jsonrpccode=e.jsonrpccode)
github buildbot / buildbot / master / buildbot / reporters / words.py View on Github external
def startService(self):
        self._root.putChild(unicode2bytes(self.path), self)
        try:
            super().startService()
        except AttributeError:
            pass
github buildbot / buildbot / master / buildbot / www / rest.py View on Github external
jsonrpccode=JSONRPC_CODES["method_not_found"])
            return
        except BadJsonRpc2 as e:
            msg = unicode2bytes(e.message)
            writeError(msg, errcode=400, jsonrpccode=e.jsonrpccode)
            return
        except Forbidden as e:
            # There is nothing in jsonrc spec about forbidden error, so pick
            # invalid request
            msg = unicode2bytes(e.message)
            writeError(
                msg, errcode=403, jsonrpccode=JSONRPC_CODES["invalid_request"])
            return
        except Exception as e:
            log.err(_why='while handling API request')
            msg = unicode2bytes(repr(e))
            writeError(repr(e), errcode=500,
                       jsonrpccode=JSONRPC_CODES["internal_error"])
            return
github buildbot / buildbot / master / buildbot / util / httpclientservice.py View on Github external
def _prepareRequest(self, ep, kwargs):
        assert ep == "" or ep.startswith("/"), "ep should start with /: " + ep
        url = self._base_url + ep
        if self._auth is not None and 'auth' not in kwargs:
            kwargs['auth'] = self._auth
        headers = kwargs.get('headers', {})
        if self._headers is not None:
            headers.update(self._headers)
        kwargs['headers'] = headers

        # we manually do the json encoding in order to automatically convert timestamps
        # for txrequests and treq
        json = kwargs.pop('json', None)
        if isinstance(json, dict):
            jsonStr = jsonmodule.dumps(json, default=toJson)
            jsonBytes = unicode2bytes(jsonStr)
            kwargs['headers']['Content-Type'] = 'application/json'
            kwargs['data'] = jsonBytes
        return url, kwargs
github buildbot / buildbot / master / buildbot / www / rest.py View on Github external
def handleErrors(self, writeError):
        try:
            yield
        except exceptions.InvalidPathError as e:
            msg = unicode2bytes(e.args[0])
            writeError(msg or b"invalid path", errcode=404,
                       jsonrpccode=JSONRPC_CODES['invalid_request'])
            return
        except exceptions.InvalidControlException as e:
            msg = unicode2bytes(str(e))
            writeError(msg or b"invalid control action", errcode=501,
                       jsonrpccode=JSONRPC_CODES["method_not_found"])
            return
        except BadRequest as e:
            msg = unicode2bytes(e.args[0])
            writeError(msg or b"invalid request", errcode=400,
                       jsonrpccode=JSONRPC_CODES["method_not_found"])
            return
        except BadJsonRpc2 as e:
            msg = unicode2bytes(e.message)
            writeError(msg, errcode=400, jsonrpccode=e.jsonrpccode)
            return
        except Forbidden as e:
            # There is nothing in jsonrc spec about forbidden error, so pick
            # invalid request
            msg = unicode2bytes(e.message)
github buildbot / buildbot / master / buildbot / scripts / tryserver.py View on Github external
def tryserver(config):
    jobdir = os.path.expanduser(config["jobdir"])
    job = sys.stdin.read()
    # now do a 'safecat'-style write to jobdir/tmp, then move atomically to
    # jobdir/new . Rather than come up with a unique name randomly, I'm just
    # going to MD5 the contents and prepend a timestamp.
    timestring = "%d" % time.time()
    m = md5()
    job = unicode2bytes(job)
    m.update(job)
    jobhash = m.hexdigest()
    fn = "%s-%s" % (timestring, jobhash)
    tmpfile = os.path.join(jobdir, "tmp", fn)
    newfile = os.path.join(jobdir, "new", fn)
    with open(tmpfile, "wb") as f:
        f.write(job)
    os.rename(tmpfile, newfile)

    return 0