Ejemplo n.º 1
0
def is_equal_or_newer_release(current_version, threshold_version):
    if not current_version:
        return False

    c_match = re.match(RELEASE_VERSION_PATTERN, current_version)
    t_match = re.match(RELEASE_VERSION_PATTERN, threshold_version)

    if c_match is None:
        raise RuntimeError(
            "Invalid universe version format: {}".format(current_version))
    if t_match is None:
        raise RuntimeError(
            "Invalid threshold version format: {}".format(threshold_version))

    for i in range(1, 5):
        c = int(c_match.group(i))
        t = int(t_match.group(i))
        if c < t:
            # If any component is behind, the whole version is older.
            return False
        elif c > t:
            # If any component is ahead, the whole version is newer.
            return True
    # If all components were equal, then the versions are compatible.
    return True
Ejemplo n.º 2
0
    def initGlfw(s):

        if not init():
            raise RuntimeError("glfw didn't initialise.")

        window_hint(VISIBLE, gl.GL_TRUE)
        window_hint(CONTEXT_VERSION_MAJOR, 4)
        window_hint(CONTEXT_VERSION_MINOR, 5)
        window_hint(OPENGL_DEBUG_CONTEXT, gl.GL_TRUE)
        window_hint(OPENGL_PROFILE, OPENGL_CORE_PROFILE)
        window_hint(OPENGL_FORWARD_COMPAT, gl.GL_TRUE)
        window_hint(DOUBLEBUFFER, gl.GL_TRUE)

        window = create_window(s.width, s.height, "3d Rendering", None, None)
        set_window_pos(window, 1920 - s.width, 0)

        if not window:
            terminate()
            raise RuntimeError("glfw could not create a window")

        make_context_current(window)
        set_window_size_callback(window, s.callbackResize)
        set_mouse_button_callback(window, s.mvp.callback_mouse_button)
        set_scroll_callback(window, s.mvp.callback_scroll)

        return window
Ejemplo n.º 3
0
def getSecurityTokenManaged(username, password, endpoint):
    authReq = buildAuthXmlManaged(username, password, endpoint)
    try:
        request = urlopen("https://login.microsoftonline.com/extSTS.srf",
                          authReq.encode('utf-8'))
    except URLError:
        raise RuntimeError("Failed to send login request.")

    ns = {
        "soap":
        "http://www.w3.org/2003/05/soap-envelope",
        "wssec":
        "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
    }

    authRespTree = ET.parse(request)
    authToken = None
    fault = authRespTree.find(".//soap:Fault", ns)
    if fault is not None:
        reason = fault.find("soap:Reason/soap:Text", ns)
        if reason is not None:
            reason = reason.text
        else:
            reason = "*Unknown reason*"
        raise RuntimeError(
            "Railed to retrieve authentication token: {}".format(reason))

    tokenElm = authRespTree.find(".//wssec:BinarySecurityToken", ns)
    if tokenElm is None:
        raise RuntimeError("Failed to extract authentication token.")
    else:
        authToken = tokenElm.text
    return authToken
Ejemplo n.º 4
0
 def _block(self):
     if self._demand('BEGIN'):
         self._statement_many()
         if not self._demand('END'):
             error = 'Expected END in line {}'.format(lexer.lineno)
             raise RuntimeError(error)
     else:
         error = 'Expected a BEGIN in line {}'.format(lexer.lineno)
         raise RuntimeError(error)
Ejemplo n.º 5
0
 def _iteration(self):
     if self._demand('ITERATE'):
         if self._demand('NUMBER'):
             if self._demand('TIMES'):
                 self._statement()
             else:
                 error = 'Expected a TIMES in line {}'.format(lexer.lineno)
                 raise RuntimeError(error)
         else:
             error = 'Expected a NUMBER in line {}'.format(lexer.lineno)
             raise RuntimeError(error)
     else:
         error = 'Expected a ITERATE in line {}'.format(lexer.lineno)
         raise RuntimeError(error)
Ejemplo n.º 6
0
 def _loop(self):
     if self._demand('WHILE'):
         if self._demand('CONDITION'):
             if self._demand('DO'):
                 self._statement()
             else:
                 error = 'Expected a DO in line {}'.format(lexer.lineno)
                 raise RuntimeError(error)
         else:
             error = 'Expected a CONDITION in line {}'.format(lexer.lineno)
             raise RuntimeError(error)
     else:
         error = 'Expected a WHILE in line {}'.format(lexer.lineno)
         raise RuntimeError(error)
Ejemplo n.º 7
0
def getSecurityTokenFederated(username, password, endpoint, stsurl):
    authReq = buildAuthXmlFederated(username, password, stsurl)
    try:
        req = Request(stsurl, authReq.encode('utf-8'),
                      {"Content-Type": "application/soap+xml; charset=utf-8"})
        request = urlopen(req)
    except URLError as x:
        raise RuntimeError("Failed to send login request.")

    ns = {
        "soap": "http://www.w3.org/2003/05/soap-envelope",
        "wssec":
        "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd",
        "saml": "urn:oasis:names:tc:SAML:1.0:assertion"
    }

    # The assertion must be copied into the second request as-is without any processing as it contains a signature.
    text = request.read()
    match = re.search(r"<saml:Assertion .*</saml:Assertion>",
                      text.decode('utf-8'))

    authReq2 = buildAuthXmlFederated2(match.group(0))

    try:
        req = Request("https://login.microsoftonline.com/rst2.srf",
                      authReq2.encode('utf-8'),
                      {"Content-Type": "application/soap+xml; charset=utf-8"})
        request = urlopen(req)
    except URLError as x:
        raise RuntimeError("Failed to send login request.")

    authRespTree = ET.parse(request)
    authToken = None
    fault = authRespTree.find(".//soap:Fault", ns)
    if fault is not None:
        reason = fault.find("soap:Reason/soap:Text", ns)
        if reason is not None:
            reason = reason.text
        else:
            reason = "*Unknown reason*"
        raise RuntimeError(
            "Railed to retrieve authentication token: {}".format(reason))

    tokenElm = authRespTree.find(".//wssec:BinarySecurityToken", ns)
    if tokenElm is None:
        raise RuntimeError("Failed to extract authentication token.")
    else:
        authToken = tokenElm.text
    return authToken
Ejemplo n.º 8
0
 def _definition(self):
     if self._demand('DEFINE-NEW-INSTRUCTION'):
         if self._demand('ID'):
             if self._demand('AS'):
                 self._statement()
             else:
                 error = 'Expected AS in line {}'.format(lexer.lineno)
                 raise RuntimeError(error)
         else:
             error = 'Expected ID in line {}'.format(lexer.lineno)
             raise RuntimeError(error)
     else:
         error = 'Expected DEFINE-NEW-INSTRUCTION in line {}'.format(
             lexer.lineno)
         raise RuntimeError(error)
Ejemplo n.º 9
0
def discover_sts(username):
    request = urlopen("https://login.microsoft.com/GetUserRealm.srf",
                      "login={}&xml=1".format(username).encode('utf-8'))
    resp = ET.parse(request)
    nstype = resp.find("./NameSpaceType")
    if nstype is None:
        raise RuntimeError(
            "Invalid GetUserRealm response - missing namespace type")
    if nstype.text == "Federated":
        stsurl = resp.find("./STSAuthURL")
        if stsurl is None:
            raise RuntimeError(
                "Invalid GetUserRealm response - missing STS URL")
        return stsurl.text
    else:
        return None
Ejemplo n.º 10
0
    def __init__(self, node, node_name, master_index, tserver_index, identity_file, ssh_port,
                 start_time_ms, namespace_to_config, ysql_port, ycql_port, redis_port,
                 enable_tls_client, root_and_client_root_ca_same, ssl_protocol, enable_ysql,
                 enable_ysql_auth, master_http_port, tserver_http_port, ysql_server_http_port,
                 collect_metrics_script, universe_version):
        self.node = node
        self.node_name = node_name
        self.master_index = master_index
        self.tserver_index = tserver_index
        self.identity_file = identity_file
        self.ssh_port = ssh_port
        self.start_time_ms = start_time_ms
        self.enable_tls_client = enable_tls_client
        self.root_and_client_root_ca_same = root_and_client_root_ca_same
        self.ssl_protocol = ssl_protocol
        # TODO: best way to do mark that this is a k8s deployment?
        self.is_k8s = ssh_port == 0 and not self.identity_file
        self.k8s_details = None
        if self.is_k8s:
            self.k8s_details = KubernetesDetails(node, namespace_to_config)

        # Some validation.
        if not self.is_k8s and not os.path.isfile(self.identity_file):
            raise RuntimeError('Error: cannot find identity file {}'.format(self.identity_file))
        self.ysql_port = ysql_port
        self.ycql_port = ycql_port
        self.redis_port = redis_port
        self.enable_ysql = enable_ysql
        self.enable_ysql_auth = enable_ysql_auth
        self.master_http_port = master_http_port
        self.tserver_http_port = tserver_http_port
        self.ysql_server_http_port = ysql_server_http_port
        self.collect_metrics_script = collect_metrics_script
        self.universe_version = universe_version
        self.additional_info = {}
Ejemplo n.º 11
0
    def __init__(self, node, node_name, identity_file, ssh_port, start_time_ms,
                 namespace_to_config, ysql_port, ycql_port, redis_port,
                 enable_tls_client, root_and_client_root_ca_same, ssl_protocol,
                 enable_ysql_auth):
        self.node = node
        self.node_name = node_name
        self.identity_file = identity_file
        self.ssh_port = ssh_port
        self.start_time_ms = start_time_ms
        self.enable_tls_client = enable_tls_client
        self.root_and_client_root_ca_same = root_and_client_root_ca_same
        self.ssl_protocol = ssl_protocol
        # TODO: best way to do mark that this is a k8s deployment?
        self.is_k8s = ssh_port == 0 and not self.identity_file
        self.k8s_details = None
        if self.is_k8s:
            self.k8s_details = KubernetesDetails(node, namespace_to_config)

        # Some validation.
        if not self.is_k8s and not os.path.isfile(self.identity_file):
            raise RuntimeError('Error: cannot find identity file {}'.format(
                self.identity_file))
        self.ysql_port = ysql_port
        self.ycql_port = ycql_port
        self.redis_port = redis_port
        self.enable_ysql_auth = enable_ysql_auth
Ejemplo n.º 12
0
def detect(pil_image):
    cascade_file = os.path.abspath(
        "./lbpcascade_animeface/lbpcascade_animeface.xml")
    if not os.path.isfile(cascade_file):
        raise RuntimeError("%s: not found" % cascade_file)

    image = numpy.array(pil_image)
    cascade = cv2.CascadeClassifier(cascade_file)
    # image = cv2.imread(filename, cv2.IMREAD_COLOR)
    gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
    gray = cv2.equalizeHist(gray)

    faces = cascade.detectMultiScale(
        gray,
        # detector options
        scaleFactor=1.1,
        minNeighbors=5,
        minSize=(24, 24))

    regions = []
    for (x, y, w, h) in faces:
        # cv2.rectangle(image, (x, y), (x + w, y + h), (0, 0, 255), 2)
        regions.append((x, y, w, h))

    return regions
Ejemplo n.º 13
0
 def _conditional(self):
     if self._demand('IF'):
         if self._demand('CONDITION'):
             if self._demand('THEN'):
                 self._statement()
             else:
                 error = 'Expected a THEN in line {}'.format(lexer.lineno)
                 raise RuntimeError(error)
         else:
             error = 'Expected a CONDITION in line {}'.format(lexer.lineno)
             raise RuntimeError(error)
         if self._verify('ELSE'):
             self._else_conditional()
     else:
         error = 'Expected a IF line {}'.format(lexer.lineno)
         raise RuntimeError(error)
Ejemplo n.º 14
0
def parse_release_build(release_build):
    if not release_build:
        return None

    match = re.match(RELEASE_BUILD_PATTERN, release_build)
    if match is None:
        raise RuntimeError("Invalid release build format: {}".format(release_build))

    return match
Ejemplo n.º 15
0
    def loadShaderFile(s, path, shader_type):
        try:
            fh = open(path, "r")
            shader_text = str(fh.read())
            fh.close()
        except OSError as error:
            raise RuntimeError("Error loading shader: {0}".format(error))
        except:
            raise RuntimeError("Nnknow error reading shaderfile {0}".format(path))

        shader_object = gl.glCreateShader(shader_type)
        gl.glShaderSource(shader_object, shader_text)
        gl.glCompileShader(shader_object)

        if not gl.glGetShaderiv(shader_object, gl.GL_COMPILE_STATUS):
            glsl_error = gl.glGetShaderInfoLog(shader_object)
            raise RuntimeError(glsl_error.decode())

        gl.glAttachShader(s.program, shader_object)
Ejemplo n.º 16
0
    def linkProgram(s):
        program = s.program

        gl.glLinkProgram(program)

        if not gl.glGetProgramiv(program, gl.GL_LINK_STATUS):
            link_error = gl.glGetProgramInfoLog(program)
            raise RuntimeError(link_error)

        for shdr in gl.glGetAttachedShaders(program):
            gl.glDetachShader(program, shdr)
            gl.glDeleteShader(shdr)
Ejemplo n.º 17
0
 def get_person_object(self, person_id):
     person = None
     if person_id in self.people_ids_dict:
         try:
             person = self.people_ids_dict[person_id]
             return person
         except Exception:
             logger.error(self.LOG_MSG_ERR_DATABASE_GET_PERSON +
                          ' get_person_object person_id=' + str(person_id))
             import_report.error(';'.join(
                 (self.REPORT_PERSON_NOT_FOUND, str(person_id))))
     raise RuntimeError(self.REPORT_PERSON_NOT_FOUND)
Ejemplo n.º 18
0
def split_tsv_file(tsv_file):
    ROW_DELIM = '\n'
    FIELD_DELIM = '\t'

    try:
        with open(tsv_file) as input_data:
            return [
                row.replace(ROW_DELIM, '').split(FIELD_DELIM)
                for row in input_data
            ]
    except OSError:
        raise RuntimeError('Test data file not found')
Ejemplo n.º 19
0
def get_default_test_data_dir_path():
    MAX_SEARCH_DEPTH = 4

    path = r'C:\Users\chengj\PycharmProjects\Py_Element_view\epi_judge_python_solutions\test_data'
    #path = 'test_data'
    for _ in range(MAX_SEARCH_DEPTH):
        if os.path.isdir(path):
            return path
        path = os.path.join(os.path.pardir, path)

    raise RuntimeError(
        'Can\'t find test data directory. Please start the program with "--test_data_dir <path>" command-line option'
    )
Ejemplo n.º 20
0
 def _program(self):
     if self._demand('BEGINNING-OF-PROGRAM'):
         self._definition_many()
         if self._demand('BEGINNING-OF-EXECUTION'):
             self._statement_many()
             if self._demand('END-OF-EXECUTION'):
                 if not self._demand('END-OF-PROGRAM'):
                     error = 'Expected END-OF-PROGRAM in line {}'.format(
                         lexer.lineno)
                     raise RuntimeError(error)
             else:
                 error = 'Expected END-OF-EXECUTION in line {}'.format(
                     lexer.lineno)
                 raise RuntimeError(error)
         else:
             error = 'Expected BEGINNING-OF-EXECUTION in line {}'.format(
                 lexer.lineno)
             raise RuntimeError(error)
     else:
         error = 'Expected BEGINNING-OF-PROGRAM in line {}'.format(
             lexer.lineno)
         raise RuntimeError(error)
Ejemplo n.º 21
0
 def _statement_prima(self):
     if self._verify('BEGIN'):
         self._statement()
     elif self._verify('ITERATE'):
         self._statement()
     elif self._verify('WHILE'):
         self._statement()
     elif self._verify('IF'):
         self._statement()
     elif self._verify('INSTRUCTION'):
         self._statement()
     elif self._verify('ID'):
         error = 'Expected a STATEMENT in line {}'.format(lexer.lineno)
         raise RuntimeError(error)
Ejemplo n.º 22
0
 def setUpClass(cls):
     """
     Connect to the database and create our table
     """
     if config.TEST_DATABASE is not config.DATABASE:
         raise RuntimeError(
             "Datatbase names do not match, fix your configuration")
     database.connect()
     database.execute_sql(
         'PRAGMA foreign_keys = ON;')  # needed for sqlite only
     create_cust_table()
     # add a bunch of customers to make sure works with non-empty database
     # maybe change this so it isn't quite so many, tests take too long now
     bs.add_from_csv('customer.csv')
     cls.active_cust_csv = get_count('customer.csv')
Ejemplo n.º 23
0
 def _statement(self):
     if self._verify('BEGIN'):
         self._block()
     elif self._verify('ITERATE'):
         self._iteration()
     elif self._verify('WHILE'):
         self._loop()
     elif self._verify('IF'):
         self._conditional()
     elif self._verify('INSTRUCTION'):
         self._instruction()
     else:
         error = 'Expected a STATEMENT in line {}'.format(lexer.lineno)
         raise RuntimeError(error)
     self._statement_prima()
Ejemplo n.º 24
0
 def append(self, value):
     if self._iter_count > 0:
         raise RuntimeError('ListSI is immutable during iterations')
     self._real_list.append(value)
Ejemplo n.º 25
0
 def __delitem__(self, index):
     if self._iter_count > 0:
         raise RuntimeError('ListSI is immutable during iterations')
     del self._real_list[index]
Ejemplo n.º 26
0
 def __check_glfw(self):
     # Initiallize gflw
     if not glfw.init():
         raise RuntimeError("GLFW initialization error")
Ejemplo n.º 27
0
 def _else_conditional(self):
     if self._demand('ELSE'):
         self._statement()
     else:
         error = 'Expected ELSE in line {}'.format(lexer.lineno)
         raise RuntimeError(error)
Ejemplo n.º 28
0
 def _instruction(self):
     if not self._demand('INSTRUCTION'):
         error = 'Expected a INSTRUCTION in line {}'.format(lexer.lineno)
         raise RuntimeError(error)