Example #1
0
    def verify(self, xml_file_name) -> str:
        """ verify xmldsig and return signerCertificate """
        moaspss_conf = os.path.join(PROJDIR_ABS,
                                    'conf/moa-spss/MOASPSSConfiguration.xml')
        log4j_conf = os.path.join(PROJDIR_ABS, 'conf/log4j.properties')
        sig_doc = xml_file_name
        logging.debug(
            'verifying signature of %s using moa-sp, config path=%s' %
            (sig_doc, moaspss_conf))

        try:
            os.environ['PYJNIUS_ACTIVATE']
            pvzdverifysig = self.pywrapper(moaspss_conf, log4j_conf, sig_doc)
            response = pvzdverifysig.verify()
            if response.pvzdCode != 'OK':
                logging.debug("Signature verification failed, code=" +
                              response.pvzdCode + "; " + response.pvzdMessage)
                raise ValidationError("Signature verification failed, code=" +
                                      response.pvzdCode + "; " +
                                      response.pvzdMessage)
        except KeyError:
            import javabridge
            # constructor takes three string parameters
            pvzdverifysig = javabridge.make_instance(
                self.pvzd_verify_sig,
                "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V",
                moaspss_conf, log4j_conf, sig_doc)
            # method verify returns response object
            response = javabridge.call(
                pvzdverifysig, "verify", "()" + "L" +
                self.pvzd_verify_sig_pkg + "/" + "PvzdVerifySigResponse;")
            if javabridge.get_field(response, "pvzdCode",
                                    "Ljava/lang/String;") != 'OK':
                raise ValidationError(
                    "Signature verification failed, code=" +
                    javabridge.get_field(response, "pvzdCode",
                                         "Ljava/lang/String;") + "; " +
                    javabridge.get_field(response, "pvzdMessage",
                                         "Ljava/lang/String;"))

        # Following "see-what-you-signed" principle use returned data from sig library
        signed_data_str = response.referencedata
        try:
            os.environ['PYJNIUS_ACTIVATE']
            r = XmlSigVerifyerResponse(signed_data_str,
                                       response.signerCertificateEncoded)
        except KeyError:
            import javabridge
            r = XmlSigVerifyerResponse(
                signed_data_str,
                javabridge.get_field(response, "signerCertificateEncoded",
                                     "Ljava/lang/String;"))
        return r
 def missing_count(self):
     """
     The number of missing values.
     :return: The number of missing values
     :rtype: int
     """
     return javabridge.get_field(self.jobject, "missingCount", "I")
 def int_count(self):
     """
     The number of int-like values.
     :return: The number of int-like values
     :rtype: int
     """
     return javabridge.get_field(self.jobject, "intCount", "I")
 def nominal_counts(self):
     """
     Counts of each nominal value.
     :return: Counts of each nominal value
     :rtype: ndarray
     """
     return javabridge.get_env().get_int_array_elements(javabridge.get_field(self.jobject, "nominalCounts", "[I"))
 def unique_count(self):
     """
     The number of values that only appear once.
     :return: The number of values that only appear once
     :rtype: int
     """
     return javabridge.get_field(self.jobject, "uniqueCount", "I")
 def distinct_count(self):
     """
     The number of distinct values.
     :return: The number of distinct values
     :rtype: int
     """
     return javabridge.get_field(self.jobject, "distinctCount", "I")
 def int_count(self):
     """
     The number of int-like values.
     :return: The number of int-like values
     :rtype: int
     """
     return javabridge.get_field(self.jobject, "intCount", "I")
Example #8
0
 def test_09_03_set_field(self):
     class_name = "org/cellprofiler/javabridge/test/RealRect"
     o = javabridge.make_instance(class_name, "()V")
     test_cases = (
         ("f_boolean", "Z", True),  # <AK> added
         ("f_char", "C", "A"),
         ("f_byte", "B", 3),
         ("f_short", "S", 15),
         ("f_int", "I", 392),
         ("f_long", "J", -14),
         ("f_float", "F", 1.03),
         ("f_double", "D", -889.1),
         ("f_object", "Ljava/lang/Object;",
          javabridge.make_instance("java/lang/Integer", "(I)V", 15)),
         ("f_object", "Ljava/lang/Object;", None))
     for field_name, signature, value in test_cases:
         javabridge.set_field(o, field_name, signature, value)
         v = javabridge.get_field(o, field_name, signature)
         if isinstance(value, float):
             self.assertAlmostEqual(v, value)
         elif isinstance(value, javabridge.JB_Object):
             self.assertTrue(
                 javabridge.call(value, "equals", "(Ljava/lang/Object;)Z",
                                 v))
         else:
             self.assertEqual(v, value)
 def stddev(self):
     """
     The std deviation of values at the last calculateDerived() call
     :return: The std deviation of values at the last calculateDerived() call
     :rtype: float
     """
     return javabridge.get_field(self.jobject, "stdDev", "D")
 def stddev(self):
     """
     The std deviation of values at the last calculateDerived() call
     :return: The std deviation of values at the last calculateDerived() call
     :rtype: float
     """
     return javabridge.get_field(self.jobject, "stdDev", "D")
 def sumsq(self):
     """
     The sum of values squared seen.
     :return: The sum of values squared seen
     :rtype: float
     """
     return javabridge.get_field(self.jobject, "sumSq", "D")
 def max(self):
     """
     The maximum value seen, or Double.NaN if no values seen.
     :return: The maximum value seen, or Double.NaN if no values seen
     :rtype: float
     """
     return javabridge.get_field(self.jobject, "max", "D")
 def mean(self):
     """
     The mean of values at the last calculateDerived() call.
     :return: The mean of values at the last calculateDerived() call
     :rtype: float
     """
     return javabridge.get_field(self.jobject, "mean", "D")
 def count(self):
     """
     The number of values seen.
     :return: The number of values seen
     :rtype: float
     """
     return javabridge.get_field(self.jobject, "count", "D")
 def unique_count(self):
     """
     The number of values that only appear once.
     :return: The number of values that only appear once
     :rtype: int
     """
     return javabridge.get_field(self.jobject, "uniqueCount", "I")
 def total_count(self):
     """
     The total number of values.
     :return: The total number of values
     :rtype: int
     """
     return javabridge.get_field(self.jobject, "totalCount", "I")
 def sumsq(self):
     """
     The sum of values squared seen.
     :return: The sum of values squared seen
     :rtype: float
     """
     return javabridge.get_field(self.jobject, "sumSq", "D")
 def mean(self):
     """
     The mean of values at the last calculateDerived() call.
     :return: The mean of values at the last calculateDerived() call
     :rtype: float
     """
     return javabridge.get_field(self.jobject, "mean", "D")
 def missing_count(self):
     """
     The number of missing values.
     :return: The number of missing values
     :rtype: int
     """
     return javabridge.get_field(self.jobject, "missingCount", "I")
 def max(self):
     """
     The maximum value seen, or Double.NaN if no values seen.
     :return: The maximum value seen, or Double.NaN if no values seen
     :rtype: float
     """
     return javabridge.get_field(self.jobject, "max", "D")
 def count(self):
     """
     The number of values seen.
     :return: The number of values seen
     :rtype: float
     """
     return javabridge.get_field(self.jobject, "count", "D")
 def distinct_count(self):
     """
     The number of distinct values.
     :return: The number of distinct values
     :rtype: int
     """
     return javabridge.get_field(self.jobject, "distinctCount", "I")
 def total_count(self):
     """
     The total number of values.
     :return: The total number of values
     :rtype: int
     """
     return javabridge.get_field(self.jobject, "totalCount", "I")
 def numeric_stats(self):
     """
     Stats on numeric value distributions.
     :return: Stats on numeric value distributions
     :rtype: NumericStats
     """
     return Stats(javabridge.get_field(self.jobject, "numericStats", "Lweka/experiment/Stats;"))
 def nominal_counts(self):
     """
     Counts of each nominal value.
     :return: Counts of each nominal value
     :rtype: ndarray
     """
     return javabridge.get_env().get_int_array_elements(
         javabridge.get_field(self.jobject, "nominalCounts", "[I"))
 def nominal_weights(self):
     """
     Weight mass for each nominal value.
     :return: Weight mass for each nominal value
     :rtype: ndarray
     """
     return javabridge.get_env().get_double_array_elements(
         javabridge.get_field(self.jobject, "nominalWeights", "[D"))
 def nominal_weights(self):
     """
     Weight mass for each nominal value.
     :return: Weight mass for each nominal value
     :rtype: ndarray
     """
     return javabridge.get_env().get_double_array_elements(
         javabridge.get_field(self.jobject, "nominalWeights", "[D"))
 def numeric_stats(self):
     """
     Stats on numeric value distributions.
     :return: Stats on numeric value distributions
     :rtype: NumericStats
     """
     return Stats(
         javabridge.get_field(self.jobject, "numericStats",
                              "Lweka/experiment/Stats;"))
 def test_11_07_get_selection_bounds(self):
     display_svc = ij2.get_display_service(self.context)
     overlay_svc = ij2.get_overlay_service(self.context)
     i, j = np.mgrid[0:15, 0:1900:100]
     image = i+j
     ds = ij2.create_dataset(self.context, image, "Foo")
     display = display_svc.createDisplay("Foo", ds)
     mask = np.zeros(i.shape, bool)
     islice = slice(2,-3)
     jslice = slice(3,-4)
     mask[islice, jslice] = True
     overlay = ij2.create_overlay(self.context, mask)
     overlay_svc.addOverlays(display, J.make_list([overlay]))
     ij2.select_overlay(display.o, overlay)
     rect = overlay_svc.getSelectionBounds(display)
     self.assertEqual(J.get_field(rect, "x", "D"), 3)
     self.assertEqual(J.get_field(rect, "y", "D"), 2)
     self.assertEqual(J.get_field(rect, "width", "D"), 11)
     self.assertEqual(J.get_field(rect, "height", "D"), 9)
Example #30
0
 def test_11_07_get_selection_bounds(self):
     display_svc = ij2.get_display_service(self.context)
     overlay_svc = ij2.get_overlay_service(self.context)
     i, j = np.mgrid[0:15, 0:1900:100]
     image = i + j
     ds = ij2.create_dataset(self.context, image, "Foo")
     display = display_svc.createDisplay("Foo", ds)
     mask = np.zeros(i.shape, bool)
     islice = slice(2, -3)
     jslice = slice(3, -4)
     mask[islice, jslice] = True
     overlay = ij2.create_overlay(self.context, mask)
     overlay_svc.addOverlays(display, J.make_list([overlay]))
     ij2.select_overlay(display.o, overlay)
     rect = overlay_svc.getSelectionBounds(display)
     self.assertEqual(J.get_field(rect, "x", "D"), 3)
     self.assertEqual(J.get_field(rect, "y", "D"), 2)
     self.assertEqual(J.get_field(rect, "width", "D"), 11)
     self.assertEqual(J.get_field(rect, "height", "D"), 9)
Example #31
0
    def verify(self, xml_file_name) -> str:
        """ verify xmldsig and return signerCertificate """
        moaspss_conf = os.path.join(PROJDIR_ABS, 'conf/moa-spss/MOASPSSConfiguration.xml')
        log4j_conf   = os.path.join(PROJDIR_ABS, 'conf/log4j.properties')
        sig_doc      = xml_file_name
        logging.debug('verifying signature of %s using moa-sp, config path=%s' % (sig_doc, moaspss_conf))

        try:
            os.environ['PYJNIUS_ACTIVATE']
            pvzdverifysig = self.pywrapper(
                moaspss_conf,
                log4j_conf,
                sig_doc)
            response  = pvzdverifysig.verify()
            if response.pvzdCode != 'OK':
                logging.debug("Signature verification failed, code=" +
                                      response.pvzdCode + "; " + response.pvzdMessage)
                raise ValidationError("Signature verification failed, code=" +
                                      response.pvzdCode + "; " + response.pvzdMessage)
        except KeyError:
            import javabridge
            # constructor takes three string parameters
            pvzdverifysig = javabridge.make_instance(self.pvzd_verify_sig,
                "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V",
                 moaspss_conf, log4j_conf, sig_doc)
            # method verify returns response object
            response = javabridge.call(pvzdverifysig, "verify",
                "()" + "L" + self.pvzd_verify_sig_pkg + "/" + "PvzdVerifySigResponse;")
            if javabridge.get_field(response, "pvzdCode", "Ljava/lang/String;") != 'OK':
                raise ValidationError("Signature verification failed, code=" +
                    javabridge.get_field(response, "pvzdCode", "Ljava/lang/String;") + "; " +
                    javabridge.get_field(response, "pvzdMessage", "Ljava/lang/String;"))

        # Following "see-what-you-signed" principle use returned data from sig library
        signed_data_str = response.referencedata
        try:
            os.environ['PYJNIUS_ACTIVATE']
            r = XmlSigVerifyerResponse(signed_data_str, response.signerCertificateEncoded)
        except KeyError:
            import javabridge
            r = XmlSigVerifyerResponse(signed_data_str, javabridge.get_field(response, "signerCertificateEncoded", "Ljava/lang/String;"))
        return r
Example #32
0
 def __getattr__(self, name):
     try:
         jfield = self.klass.getField(name)
     except:
         raise AttributeError()
 
     STATIC = J.get_static_field("java/lang/reflect/Modifier", "STATIC", "I")
     if (J.call(jfield, "getModifiers", "()I") & STATIC) == STATIC:
         raise AttributeError()
     klass = J.call(jfield, "getType", "()Ljava/lang/Class;")
     result = J.get_field(self.o, name, sig(klass))
     if isinstance(result, J.JB_Object):
         result = JWrapper(result)
     return result
    def __getattr__(self, name):
        try:
            jfield = self.klass.getField(name)
        except:
            raise AttributeError()

        STATIC = J.get_static_field("java/lang/reflect/Modifier", "STATIC",
                                    "I")
        if (J.call(jfield, "getModifiers", "()I") & STATIC) == STATIC:
            raise AttributeError()
        klass = J.call(jfield, "getType", "()Ljava/lang/Class;")
        result = J.get_field(self.o, name, sig(klass))
        if isinstance(result, J.JB_Object):
            result = JWrapper(result)
        return result
Example #34
0
    def p(self, *args):
        """
        Gets the p-value for r2

        Signatures:

        float p()

        Returns:

        The p value
        """
        try:
            p = self._p()
            return p
        except javabridge.JavaException:
            return javabridge.get_field(self.o, "p","F")
Example #35
0
    def dPrime(self, *args):
        """
        Gets the D' value

        Signatures:

        float dPrime()

        Returns:

        The D' value
        """
        try:
            dPrime = self._dPrime()
            return dPrime
        except javabridge.JavaException:
            return javabridge.get_field(self.o, "dprime","F")
Example #36
0
    def r2(self, *args):
        """
        Gets the r2 value

        Signatures:

        float r2()

        Returns:

        The r2 value
        """
        try:
            r2 = self._r2()
            return r2
        except javabridge.JavaException:
            return javabridge.get_field(self.o, "r2","F")
Example #37
0
    def n(self, *args):
        """
        Gets the number of individuals used to calculate LD

        Signatures:

        int n()

        Returns:

        The number of individuals used to calculate LD
        """
        try:
            n = self._n()
            return n
        except javabridge.JavaException:
            return javabridge.get_field(self.o, "n","I")
Example #38
0
 def __getattr__(self, name):
     if name in ("o", "class_wrapper", "methods"):
         raise AttributeError()
     if not hasattr(self, "methods"):
         # not initialized
         raise AttributeError()
     try:
         jfield = self.class_wrapper.getField(name)
     except:
         raise AttributeError()
 
     STATIC = J.get_static_field("java/lang/reflect/Modifier", "STATIC", "I")
     if (J.call(jfield, "getModifiers", "()I") & STATIC) == STATIC:
         raise AttributeError()
     klass = J.call(jfield, "getType", "()Ljava/lang/Class;")
     result = J.get_field(self.o, name, sig(klass))
     if isinstance(result, J.JB_Object):
         result = JWrapper(result)
     return result
Example #39
0
    def __getattr__(self, name):
        if name in ("o", "class_wrapper", "methods"):
            raise AttributeError()
        if not hasattr(self, "methods"):
            # not initialized
            raise AttributeError()
        try:
            jfield = self.class_wrapper.getField(name)
        except:
            raise AttributeError()

        STATIC = J.get_static_field("java/lang/reflect/Modifier", "STATIC",
                                    "I")
        if (J.call(jfield, "getModifiers", "()I") & STATIC) == STATIC:
            raise AttributeError()
        klass = J.call(jfield, "getType", "()Ljava/lang/Class;")
        result = J.get_field(self.o, name, sig(klass))
        if isinstance(result, J.JB_Object):
            result = JWrapper(result)
        return result
 def test_09_03_set_field(self):
     class_name = "org/cellprofiler/javabridge/test/RealRect"
     o = javabridge.make_instance(class_name, "()V")
     test_cases = (
         ("f_char", "C", "A"),
         ("f_byte", "B", 3),
         ("f_short", "S", 15),
         ("f_int", "I", 392),
         ("f_long", "J", -14),
         ("f_float", "F", 1.03),
         ("f_double", "D", -889.1),
         ("f_object", "Ljava/lang/Object;", 
          javabridge.make_instance("java/lang/Integer", "(I)V", 15)),
         ("f_object", "Ljava/lang/Object;", None))
     for field_name, signature, value in test_cases:
         javabridge.set_field(o, field_name, signature, value)
         v = javabridge.get_field(o, field_name, signature)
         if isinstance(value, float):
             self.assertAlmostEqual(v, value)
         elif isinstance(value, javabridge.JB_Object):
             self.assertTrue(javabridge.call(
                 value, "equals", "(Ljava/lang/Object;)Z", v))
         else:
             self.assertEqual(v, value)
Example #41
0
 def fn():
     o = javabridge.make_instance("java/lang/Object", "()V")
     javabridge.get_field(o, "NoSuchField", "I")
Example #42
0
 def test_09_01_00_get_field(self):
     o = javabridge.make_instance(
         "org/cellprofiler/javabridge/test/RealRect", "(DDDD)V", 1, 2, 3, 4)
     self.assertEqual(javabridge.get_field(o, "x", "D"), 1)
 def fn():
     o = javabridge.make_instance("java/lang/Object", "()V")
     javabridge.get_field(o, "NoSuchField", "I")
 def test_09_01_00_get_field(self):
     o = javabridge.make_instance("org/cellprofiler/javabridge/test/RealRect", "(DDDD)V", 1, 2, 3, 4)
     self.assertEqual(javabridge.get_field(o, "x", "D"), 1)