本文整理匯總了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())