'''
Pyjnius
=======
Accessing Java classes from Python.
All the documentation is available at: [Link]
'''
__version__ = '1.6.1'
from .env import get_java_setup
import os
import sys
if [Link] == 'win32' and sys.version_info >= (3, 8):
path = [Link](__file__)
java = get_java_setup([Link])
jdk_home = java.get_javahome()
with os.add_dll_directory(path):
for suffix in (
('bin', 'client'),
('bin', 'server'),
('bin', 'default'),
('jre', 'bin', 'client'),
('jre', 'bin', 'server'),
('jre', 'bin', 'default'),
):
path = [Link](jdk_home, *suffix)
if not [Link](path):
continue
with os.add_dll_directory(path):
try:
from .jnius import * # noqa
from .reflect import * # noqa
except Exception as e:
pass
else:
break
else:
raise Exception("Unable to create jni env, no jvm dll found.")
else:
from .jnius import * # noqa
from .reflect import * # noqa
# XXX monkey patch methods that cannot be in cython.
# Cython doesn't allow to set new attribute on methods it compiled
HASHCODE_MAX = 2 ** 31 - 1
class PythonJavaClass_(PythonJavaClass, metaclass=MetaJavaBase):
@java_method('()I', name='hashCode')
def hashCode(self):
return id(self) % HASHCODE_MAX
@java_method('()Ljava/lang/String;', name='hashCode')
def hashCode_(self):
return '{}'.format([Link]())
@java_method('()Ljava/lang/String;', name='toString')
def toString(self):
return repr(self)
@java_method('(Ljava/lang/Object;)Z', name='equals')
def equals(self, other):
return [Link]() == [Link]()
PythonJavaClass = PythonJavaClass_
# from [Link]
import os
if "ANDROID_ARGUMENT" in [Link]:
# on android, catch all exception to ensure about a [Link]
import threading
import jnius
orig_thread_run = [Link]
def jnius_thread_hook(*args, **kwargs):
try:
return orig_thread_run(*args, **kwargs)
finally:
[Link]()
[Link] = jnius_thread_hook