本文整理汇总了Python中java.lang.Exception方法的典型用法代码示例。如果您正苦于以下问题:Python lang.Exception方法的具体用法?Python lang.Exception怎么用?Python lang.Exception使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.lang
的用法示例。
在下文中一共展示了lang.Exception方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: deserial
# 需要导入模块: from java import lang [as 别名]
# 或者: from java.lang import Exception [as 别名]
def deserial(self, data):
if not self.is_jython:
print ('[!] This module can only be used in jython!')
return data
try:
# turn data into a Java object
bis = io.ByteArrayInputStream(data)
ois = io.ObjectInputStream(bis)
obj = ois.readObject()
# converting Java object to XML structure
xs = XStream()
xml = xs.toXML(obj)
return xml
except Exception as e:
print ('[!] Caught Exception. Could not convert.\n')
return data
示例2: serial
# 需要导入模块: from java import lang [as 别名]
# 或者: from java.lang import Exception [as 别名]
def serial(self, data):
if not self.is_jython:
print ('[!] This module can only be used in jython!')
return data
try:
# Creating XStream object and creating Java object from XML structure
xs = XStream()
serial = xs.fromXML(data)
# writing created Java object to and serializing it with ObjectOutputStream
bos = io.ByteArrayOutputStream()
oos = io.ObjectOutputStream(bos)
oos.writeObject(serial)
# I had a problem with signed vs. unsigned bytes, hence the & 0xff
return "".join([chr(x & 0xff) for x in bos.toByteArray().tolist()])
except Exception as e:
print ('[!] Caught Exception. Could not convert.\n')
return data
示例3: inet_pton
# 需要导入模块: from java import lang [as 别名]
# 或者: from java.lang import Exception [as 别名]
def inet_pton(family, ip_string):
try:
if family == AF_INET:
if not is_ipv4_address(ip_string):
raise error("illegal IP address string passed to inet_pton")
elif family == AF_INET6:
if not is_ipv6_address(ip_string):
raise error("illegal IP address string passed to inet_pton")
else:
raise error(errno.EAFNOSUPPORT, "Address family not supported by protocol")
ia = java.net.InetAddress.getByName(ip_string)
bytes = []
for byte in ia.getAddress():
if byte < 0:
bytes.append(byte+256)
else:
bytes.append(byte)
return "".join([chr(byte) for byte in bytes])
except java.lang.Exception, jlx:
raise _map_exception(jlx)
示例4: accept
# 需要导入模块: from java import lang [as 别名]
# 或者: from java.lang import Exception [as 别名]
def accept(self):
"This signifies a server socket"
try:
if not self.sock_impl:
self.listen()
assert self.server
new_sock = self.sock_impl.accept()
if not new_sock:
raise would_block_error()
cliconn = _tcpsocket()
cliconn.pending_options[ (SOL_SOCKET, SO_REUSEADDR) ] = new_sock.jsocket.getReuseAddress()
cliconn.sock_impl = new_sock
cliconn._setup()
return cliconn, new_sock.getpeername()
except java.lang.Exception, jlx:
raise _map_exception(jlx)
示例5: recv
# 需要导入模块: from java import lang [as 别名]
# 或者: from java.lang import Exception [as 别名]
def recv(self, n):
try:
if not self.sock_impl: raise error(errno.ENOTCONN, 'Socket is not connected')
if self.sock_impl.jchannel.isConnectionPending():
self.sock_impl.jchannel.finishConnect()
data = jarray.zeros(n, 'b')
m = self.sock_impl.read(data)
if m == -1:#indicates EOF has been reached, so we just return the empty string
return ""
elif m <= 0:
if self.mode == MODE_NONBLOCKING:
raise would_block_error()
return ""
if m < n:
data = data[:m]
return data.tostring()
except java.lang.Exception, jlx:
raise _map_exception(jlx)
示例6: recvfrom
# 需要导入模块: from java import lang [as 别名]
# 或者: from java.lang import Exception [as 别名]
def recvfrom(self, num_bytes, flags=None):
"""
There is some disagreement as to what the behaviour should be if
a recvfrom operation is requested on an unbound socket.
See the following links for more information
http://bugs.jython.org/issue1005
http://bugs.sun.com/view_bug.do?bug_id=6621689
"""
try:
# This is the old 2.1 behaviour
#assert self.sock_impl
# This is amak's preferred interpretation
#raise error(errno.ENOTCONN, "Recvfrom on unbound udp socket meaningless operation")
# And this is the option for cpython compatibility
if not self.sock_impl:
self.sock_impl = _datagram_socket_impl()
self._config()
return self.sock_impl.recvfrom(num_bytes, flags)
except java.lang.Exception, jlx:
raise _map_exception(jlx)
示例7: gethostname
# 需要导入模块: from java import lang [as 别名]
# 或者: from java.lang import Exception [as 别名]
def gethostname():
try:
return asPyString(java.net.InetAddress.getLocalHost().getHostName())
except java.lang.Exception, jlx:
raise _map_exception(jlx)
示例8: gethostbyname
# 需要导入模块: from java import lang [as 别名]
# 或者: from java.lang import Exception [as 别名]
def gethostbyname(name):
try:
return asPyString(java.net.InetAddress.getByName(name).getHostAddress())
except java.lang.Exception, jlx:
raise _map_exception(jlx)
示例9: _decode_idna
# 需要导入模块: from java import lang [as 别名]
# 或者: from java.lang import Exception [as 别名]
def _decode_idna(name, flags=0):
try:
jflags = 0
if flags & NI_IDN_ALLOW_UNASSIGNED:
jflags |= au
if flags & NI_IDN_USE_STD3_ASCII_RULES:
jflags |= usar
return decode_fn(name, jflags)
except Exception, x:
raise UnicodeDecodeError(name)
示例10: getaddrinfo
# 需要导入模块: from java import lang [as 别名]
# 或者: from java.lang import Exception [as 别名]
def getaddrinfo(host, port, family=AF_INET, socktype=None, proto=0, flags=0):
try:
if _ipv4_addresses_only:
family = AF_INET
if not family in [AF_INET, AF_INET6, AF_UNSPEC]:
raise gaierror(errno.EIO, 'ai_family not supported')
host = _getaddrinfo_get_host(host, family, flags)
port = _getaddrinfo_get_port(port, flags)
filter_fns = []
filter_fns.append({
AF_INET: lambda x: isinstance(x, java.net.Inet4Address),
AF_INET6: lambda x: isinstance(x, java.net.Inet6Address),
AF_UNSPEC: lambda x: isinstance(x, java.net.InetAddress),
}[family])
passive_mode = flags is not None and flags & AI_PASSIVE
canonname_mode = flags is not None and flags & AI_CANONNAME
results = []
for a in java.net.InetAddress.getAllByName(host):
if len([f for f in filter_fns if f(a)]):
family = {java.net.Inet4Address: AF_INET, java.net.Inet6Address: AF_INET6}[a.getClass()]
if passive_mode and not canonname_mode:
canonname = ""
else:
canonname = asPyString(a.getCanonicalHostName())
if host is None and passive_mode and not canonname_mode:
sockaddr = INADDR_ANY
else:
sockaddr = asPyString(a.getHostAddress())
# TODO: Include flowinfo and scopeid in a 4-tuple for IPv6 addresses
sock_tuple = {AF_INET : _ipv4_address_t, AF_INET6 : _ipv6_address_t}[family](sockaddr, port, a)
results.append((family, socktype, proto, canonname, sock_tuple))
return results
except java.lang.Exception, jlx:
raise _map_exception(jlx)
示例11: setsockopt
# 需要导入模块: from java import lang [as 别名]
# 或者: from java.lang import Exception [as 别名]
def setsockopt(self, level, optname, value):
try:
if self.sock_impl:
self.sock_impl.setsockopt(level, optname, value)
else:
self.pending_options[ (level, optname) ] = value
except java.lang.Exception, jlx:
raise _map_exception(jlx)
示例12: getsockopt
# 需要导入模块: from java import lang [as 别名]
# 或者: from java.lang import Exception [as 别名]
def getsockopt(self, level, optname):
try:
if self.sock_impl:
return self.sock_impl.getsockopt(level, optname)
else:
return self.pending_options.get( (level, optname), None)
except java.lang.Exception, jlx:
raise _map_exception(jlx)
示例13: shutdown
# 需要导入模块: from java import lang [as 别名]
# 或者: from java.lang import Exception [as 别名]
def shutdown(self, how):
assert how in (SHUT_RD, SHUT_WR, SHUT_RDWR)
if not self.sock_impl:
raise error(errno.ENOTCONN, "Transport endpoint is not connected")
try:
self.sock_impl.shutdown(how)
except java.lang.Exception, jlx:
raise _map_exception(jlx)
示例14: close
# 需要导入模块: from java import lang [as 别名]
# 或者: from java.lang import Exception [as 别名]
def close(self):
try:
if self.sock_impl:
self.sock_impl.close()
except java.lang.Exception, jlx:
raise _map_exception(jlx)
示例15: getsockname
# 需要导入模块: from java import lang [as 别名]
# 或者: from java.lang import Exception [as 别名]
def getsockname(self):
try:
if self.sock_impl is None:
# If the user has already bound an address, return that
if self.local_addr:
return self.local_addr
# The user has not bound, connected or listened
# This is what cpython raises in this scenario
raise error(errno.EINVAL, "Invalid argument")
return self.sock_impl.getsockname()
except java.lang.Exception, jlx:
raise _map_exception(jlx)