本文整理汇总了Python中java.io.IOException方法的典型用法代码示例。如果您正苦于以下问题:Python io.IOException方法的具体用法?Python io.IOException怎么用?Python io.IOException使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.io
的用法示例。
在下文中一共展示了io.IOException方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_catch
# 需要导入模块: from java import io [as 别名]
# 或者: from java.io import IOException [as 别名]
def test_catch(self):
from java.lang import Integer
from java.lang import RuntimeException, IllegalArgumentException, NumberFormatException
with self.assertRaises(NumberFormatException): # Actual class
Integer.parseInt("hello")
with self.assertRaises(IllegalArgumentException): # Parent class
Integer.parseInt("hello")
with self.assertRaises(RuntimeException): # Grandparent class
Integer.parseInt("hello")
from java.lang import System
from java.io import IOException
try:
System.getProperty("")
except IOException: # Unrelated class
self.fail()
except NumberFormatException: # Child class
self.fail()
except IllegalArgumentException: # Actual class
pass
示例2: execute
# 需要导入模块: from java import io [as 别名]
# 或者: from java.io import IOException [as 别名]
def execute( self, cmd ):
"""Execute cmd in a shell, and return the java.lang.Process instance.
Accepts either a string command to be executed in a shell,
or a sequence of [executable, args...].
"""
shellCmd = self._formatCmd( cmd )
env = self._formatEnvironment( self.environment )
try:
p = Runtime.getRuntime().exec( shellCmd, env, File(os.getcwd()) )
return p
except IOException, ex:
raise OSError(
0,
"Failed to execute command (%s): %s" % ( shellCmd, ex )
)
########## utility methods
示例3: _extract_certs_for_paths
# 需要导入模块: from java import io [as 别名]
# 或者: from java.io import IOException [as 别名]
def _extract_certs_for_paths(paths, password=None):
# Go from Bouncy Castle API to Java's; a bit heavyweight for the Python dev ;)
key_converter = JcaPEMKeyConverter().setProvider("BC")
cert_converter = JcaX509CertificateConverter().setProvider("BC")
certs = []
private_key = None
for path in paths:
err = None
with open(path) as f:
# try to load the file as keystore file first
try:
_certs = _extract_certs_from_keystore_file(f, password)
certs.extend(_certs)
except IOException as err:
pass # reported as 'Invalid keystore format'
if err is not None: # try loading pem version instead
with open(path) as f:
_certs, _private_key = _extract_cert_from_data(f, password, key_converter, cert_converter)
private_key = _private_key if _private_key else private_key
certs.extend(_certs)
return certs, private_key
示例4: execute
# 需要导入模块: from java import io [as 别名]
# 或者: from java.io import IOException [as 别名]
def execute( self, cmd ):
"""Execute cmd in a shell, and return the java.lang.Process instance.
Accepts either a string command to be executed in a shell,
or a sequence of [executable, args...].
"""
shellCmd = self._formatCmd( cmd )
env = self._formatEnvironment( self.environment )
try:
p = Runtime.getRuntime().exec( shellCmd, env, File(os.getcwdu()) )
return p
except IOException, ex:
raise OSError(
0,
"Failed to execute command (%s): %s" % ( shellCmd, ex )
)
########## utility methods
示例5: connectToJMX
# 需要导入模块: from java import io [as 别名]
# 或者: from java.io import IOException [as 别名]
def connectToJMX(args):
# Basic JMX connection, always required
trust_managers = array([TrustAllX509TrustManager()], TrustManager)
sc = SSLContext.getInstance("SSL")
sc.init(None, trust_managers, None)
SSLContext.setDefault(sc)
jmx_url = JMXServiceURL("service:jmx:rmi:///jndi/rmi://" + args.targetHost + ":" + args.targetPort + "/jmxrmi")
print "[+] Connecting to: " + str(jmx_url)
try:
jmx_connector = JMXConnectorFactory.connect(jmx_url)
print "[+] Connected: " + str(jmx_connector.getConnectionId())
bean_server = jmx_connector.getMBeanServerConnection()
return bean_server
except IOException:
print "[-] Error: Can't connect to remote service"
sys.exit(-1)
##########
### INSTALL MODE ###
示例6: throws_java
# 需要导入模块: from java import io [as 别名]
# 或者: from java.io import IOException [as 别名]
def throws_java(msg="abc olé 中文"):
from java.io import IOException
raise IOException(msg)
示例7: _excmd
# 需要导入模块: from java import io [as 别名]
# 或者: from java.io import IOException [as 别名]
def _excmd(self, sshcmd):
'''
return (connected_ok, response_array)
'''
connected_ok=True
resp = []
try:
conn = Connection(self.hostname)
conn.connect()
self.logger.info('ssh connection created.')
isAuthenticated = conn.authenticateWithPassword(self.user, self.password)
if not isAuthenticated:
connected_ok=False
self.logger.error('ssh failed to authenticatd.')
else:
self.logger.info('ssh authenticated.')
sess = conn.openSession()
self.logger.info('ssh session created.')
sess.execCommand(sshcmd)
self.logger.info('ssh command issued. cmd is %s'%sshcmd)
stdout = StreamGobbler(sess.getStdout())
br = BufferedReader(InputStreamReader(stdout))
while True:
line = br.readLine()
if line is None:
break
else :
resp.append(line)
self.logger.warning('ssh command output: '%resp)
except IOException ,ex:
connected_ok=False
#print "oops..error,", ex
self.logger.error('ssh exception: %s'% ex)
示例8: connectToHub
# 需要导入模块: from java import io [as 别名]
# 或者: from java.io import IOException [as 别名]
def connectToHub(adr, port, pollMillis, user, password):
"""connectToHub(adr, port, pollMillis, user, password) connects to a specific non-legacy hub """
print("Connecting")
try:
iofun.connectToHub(adr, port, pollMillis, user, password)
print("Connected")
except IOException as e:
err(e.getMessage())
示例9: connectToLegacyHub
# 需要导入模块: from java import io [as 别名]
# 或者: from java.io import IOException [as 别名]
def connectToLegacyHub(adr, port):
"""connectToLegacyHub(adr, port) connects to a specific legacy hub"""
print("Connecting")
try:
iofun.connectToLegacyHub(adr, port)
print("Connected")
except IOException as e:
err(e.getMessage())
示例10: connectToSerial
# 需要导入模块: from java import io [as 别名]
# 或者: from java.io import IOException [as 别名]
def connectToSerial(dev):
"""connectToSerial("/path/to/device") connects to specific serial port """
print("Connecting")
try:
iofun.connectToSerial(dev)
print("Connected")
except IOException as e:
err(e.getMessage())