本文整理汇总了Python中java.lang.String方法的典型用法代码示例。如果您正苦于以下问题:Python lang.String方法的具体用法?Python lang.String怎么用?Python lang.String使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.lang
的用法示例。
在下文中一共展示了lang.String方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _getaddrinfo_get_port
# 需要导入模块: from java import lang [as 别名]
# 或者: from java.lang import String [as 别名]
def _getaddrinfo_get_port(port, flags):
if isinstance(port, basestring):
try:
int_port = int(port)
except ValueError:
if flags & AI_NUMERICSERV:
raise gaierror(EAI_NONAME, "Name or service not known")
# Lookup the service by name
try:
int_port = getservbyname(port)
except error:
raise gaierror(EAI_SERVICE, "Servname not supported for ai_socktype")
elif port is None:
int_port = 0
elif not isinstance(port, (int, long)):
raise error("Int or String expected")
else:
int_port = int(port)
return int_port % 65536
示例2: test_setget_override
# 需要导入模块: from java import lang [as 别名]
# 或者: from java.lang import String [as 别名]
def test_setget_override(self):
if not test_support.is_jython:
return
# http://bugs.jython.org/issue600790
class GoofyListMapThing(ArrayList):
def __init__(self):
self.silly = "Nothing"
def __setitem__(self, key, element):
self.silly = "spam"
def __getitem__(self, key):
self.silly = "eggs"
glmt = GoofyListMapThing()
glmt['my-key'] = String('el1')
self.assertEquals(glmt.silly, "spam")
glmt['my-key']
self.assertEquals(glmt.silly, "eggs")
示例3: _get_inflate_data
# 需要导入模块: from java import lang [as 别名]
# 或者: from java.lang import String [as 别名]
def _get_inflate_data(inflater, max_length=0):
buf = jarray.zeros(1024, 'b')
s = StringIO()
total = 0
while not inflater.finished():
try:
if max_length:
l = inflater.inflate(buf, 0, min(1024, max_length - total))
else:
l = inflater.inflate(buf)
except DataFormatException, e:
raise error(str(e))
if l == 0:
break
total += l
s.write(String(buf, 0, 0, l))
if max_length and total == max_length:
break
示例4: make_property_key
# 需要导入模块: from java import lang [as 别名]
# 或者: from java.lang import String [as 别名]
def make_property_key(self, name, data_type=None, cardinality=None, auto_make=True):
pkm = self.management_system.makePropertyKey(name)
if data_type:
pkm.dataType(data_type)
else:
pkm.dataType(String)
if cardinality:
pkm.cardinality(cardinality)
elif self.default_cardinality:
pkm.cardinality(self.default_cardinality)
if auto_make:
return pkm.make()
else:
return pkm
示例5: set_relying_party_login_url
# 需要导入模块: from java import lang [as 别名]
# 或者: from java.lang import String [as 别名]
def set_relying_party_login_url(identity):
print "ThumbSignIn. Inside set_relying_party_login_url..."
session_id = identity.getSessionId()
session_attribute = session_id.getSessionAttributes()
state_jwt_token = session_attribute.get("state")
print "ThumbSignIn. Value of state_jwt_token is %s" % state_jwt_token
relying_party_login_url = ""
if (state_jwt_token is None) or ("." not in state_jwt_token):
print "ThumbSignIn. Value of state parameter is not in the format of JWT Token"
identity.setWorkingParameter(RELYING_PARTY_LOGIN_URL, relying_party_login_url)
return None
state_jwt_token_array = String(state_jwt_token).split("\\.")
state_jwt_token_payload = state_jwt_token_array[1]
state_payload_str = String(Base64Util.base64urldecode(state_jwt_token_payload), "UTF-8")
state_payload_json = JSONObject(state_payload_str)
print "ThumbSignIn. Value of state JWT token Payload is %s" % state_payload_json
if state_payload_json.has("additional_claims"):
additional_claims = state_payload_json.get("additional_claims")
relying_party_id = additional_claims.get(RELYING_PARTY_ID)
print "ThumbSignIn. Value of relying_party_id is %s" % relying_party_id
identity.setWorkingParameter(RELYING_PARTY_ID, relying_party_id)
if String(relying_party_id).startsWith("google.com"):
# google.com/a/unphishableenterprise.com
relying_party_id_array = String(relying_party_id).split("/")
google_domain = relying_party_id_array[2]
print "ThumbSignIn. Value of google_domain is %s" % google_domain
relying_party_login_url = "https://www.google.com/accounts/AccountChooser?hd="+ google_domain + "%26continue=https://apps.google.com/user/hub"
# elif (String(relying_party_id).startsWith("xyz")):
# relying_party_login_url = "xyz.com"
else:
# If relying_party_login_url is empty, Gluu's default login URL will be used
relying_party_login_url = ""
print "ThumbSignIn. Value of relying_party_login_url is %s" % relying_party_login_url
identity.setWorkingParameter(RELYING_PARTY_LOGIN_URL, relying_party_login_url)
return None
示例6: test_enable
# 需要导入模块: from java import lang [as 别名]
# 或者: from java.lang import String [as 别名]
def test_enable(self):
# Should be enabled by default
from java.lang import String # noqa: F401
set_import_enabled(False)
with self.assertRaises(ImportError):
from java.lang import String # noqa: F811
set_import_enabled(True)
from java.lang import String # noqa: F401, F811
示例7: test_single
# 需要导入模块: from java import lang [as 别名]
# 或者: from java.lang import String [as 别名]
def test_single(self):
# "java" is different because there actually is a Python module by that name.
from java.lang import String
self.assertIs(String, jclass("java.lang.String"))
self.assertNotIn("java.lang", sys.modules)
from javax.xml import XMLConstants
self.assertIs(XMLConstants, jclass("javax.xml.XMLConstants"))
self.assertNotIn("javax", sys.modules)
self.assertNotIn("javax.xml", sys.modules)
示例8: test_errors
# 需要导入模块: from java import lang [as 别名]
# 或者: from java.lang import String [as 别名]
def test_errors(self):
# "java" sub-packages give different errors on Python 2.7 because there actually is a
# Python module by that name.
with self.no_module_error(r"(java.lang|lang.String)"):
import java.lang.String # noqa: F401
with self.no_module_error(r"(java.)?lang"):
from java.lang import Nonexistent # noqa: F401
with self.no_module_error(r"(java.)?lang"):
from package1 import wildcard_java_lang # noqa: F401
with self.no_module_error(r"javax(.xml)?"):
from javax.xml import Nonexistent # noqa: F401, F811
with self.no_module_error(r"javax(.xml)?"):
from package1 import wildcard_javax_xml # noqa: F401
# A Java name and a nonexistent one.
with self.no_name_error("Nonexistent"):
from java.lang import String, Nonexistent # noqa: F401, F811
# A Python name and a nonexistent one.
with self.no_name_error("Nonexistent"):
from sys import path, Nonexistent # noqa: F401, F811
# These test files are also used in test_android.py.
with self.assertRaisesRegexp(SyntaxError, "invalid syntax"):
from package1 import syntax_error # noqa: F401
with self.no_name_error("nonexistent"):
from package1 import recursive_import_error # noqa: F401
示例9: test_output_arg
# 需要导入模块: from java import lang [as 别名]
# 或者: from java.lang import String [as 别名]
def test_output_arg(self):
string = String('\u1156\u2278\u3390\u44AB')
for btarray in ([0] * 4,
(0,) * 4,
jarray(jbyte)([0] * 4)):
# This version of getBytes returns the 8 low-order of each Unicode character.
string.getBytes(0, 4, btarray, 0)
if not isinstance(btarray, tuple):
self.assertEquals(btarray, [ctypes.c_int8(x).value
for x in [0x56, 0x78, 0x90, 0xAB]])
示例10: test_bytes
# 需要导入模块: from java import lang [as 别名]
# 或者: from java.lang import String [as 别名]
def test_bytes(self):
# Java byte arrays (signed) and Python bytes (unsigned) can be converted both ways.
self.verify_bytes([], b"")
self.verify_bytes([-128, -127, -2, -1, 0, 1, 126, 127],
b"\x80\x81\xFE\xFF\x00\x01\x7E\x7F")
# Java primitive arrays (except char[]) can be converted to their raw data bytes.
# Expected values are little-endian.
for element_type, values, expected in \
[(jboolean, [False, True], b"\x00\x01"),
(jbyte, [0, 123], bytes(1) + b"\x7b"),
(jshort, [0, 12345], bytes(2) + b"\x39\x30"),
(jint, [0, 123456789], bytes(4) + b"\x15\xcd\x5b\x07"),
(jlong, [0, 1234567890123456789], bytes(8) + b"\x15\x81\xe9\x7d\xf4\x10\x22\x11"),
(jfloat, [0, 1.99], bytes(4) + b"\x52\xb8\xfe\x3f"),
(jdouble, [0, 1.99], bytes(8) + b"\xd7\xa3\x70\x3d\x0a\xd7\xff\x3f")]:
java_type = jarray(element_type)
for python_type in [bytes, bytearray]:
with self.subTest(element_type=element_type, python_type=python_type):
self.assertEqual(b"", python_type(java_type([])))
self.assertEqual(expected, python_type(java_type(values)))
# Integer arrays containing values 0 to 255 can be converted element-wise using `list`.
for element_type in [jshort, jint, jlong]:
with self.subTest(element_type=element_type):
self.assertEqual(
b"\x00\x01\x7E\x7F\x80\x81\xFE\xFF",
bytes(list(jarray(element_type)([0, 1, 126, 127, 128, 129, 254, 255]))))
# Other array types (including multi-dimensional arrays) will be treated as an iterable
# of integers, so converting them to bytes will fail unless the array is empty.
for element_type, values in \
[(jchar, "hello"),
(jarray(jbyte), [b"hello", b"world"]),
(String, ["hello"])]:
java_type = jarray(element_type)
for python_type in [bytes, bytearray]:
with self.subTest(element_type=element_type, python_type=python_type):
self.assertEqual(b"", python_type(java_type([])))
with self.assertRaisesRegex(TypeError, "cannot be interpreted as an integer"):
python_type(java_type(values))
示例11: test_abc
# 需要导入模块: from java import lang [as 别名]
# 或者: from java.lang import String [as 别名]
def test_abc(self):
from collections import abc
for element_type_1d in [jboolean, jbyte, jshort, jint, jlong, jfloat, jdouble, jchar,
String]:
for element_type in [element_type_1d, jarray(element_type_1d)]:
with self.subTest(element_type=element_type):
cls = jarray(element_type)
self.assertTrue(issubclass(cls, abc.MutableSequence))
self.assertTrue(isinstance(cls([]), abc.MutableSequence))
示例12: test_add
# 需要导入模块: from java import lang [as 别名]
# 或者: from java.lang import String [as 别名]
def test_add(self):
tf = jarray(jboolean)([True, False])
self.assertEqual(tf, tf + [])
self.assertEqual(tf, [] + tf)
self.assertEqual(tf, tf + jarray(jboolean)([]))
self.assertEqual([True, False, True, False], tf + tf)
self.assertEqual([True, False, True], tf + [True])
self.assertEqual([True, True, False], [True] + tf)
with self.assertRaises(TypeError):
tf + True
with self.assertRaises(TypeError):
tf + None
hw = jarray(String)(["hello", "world"])
self.assertEqual([True, False, "hello", "world"], tf + hw)
示例13: test_return
# 需要导入模块: from java import lang [as 别名]
# 或者: from java.lang import String [as 别名]
def test_return(self):
from java.lang import Runnable, ClassCastException, NullPointerException
class C(dynamic_proxy(Runnable, TP.Adder, TP.GetString)):
def run(self):
return self.result # returns void
def add(self, x):
return self.result # returns int
def getString(self):
return self.result # returns String
c = C()
c_Runnable, c_Adder, c_GS = [cast(cls, c) for cls in [Runnable, TP.Adder, TP.GetString]]
c.result = None
self.assertIsNone(c_Runnable.run())
with self.assertRaises(NullPointerException):
c_Adder.add(42)
self.assertIsNone(c_GS.getString())
c.result = 42
with self.assertRaisesRegexp(ClassCastException, "Cannot convert int object to void"):
c_Runnable.run()
self.assertEqual(42, c_Adder.add(99))
with self.assertRaisesRegexp(ClassCastException, "Cannot convert int object to "
"java.lang.String"):
c_GS.getString()
c.result = "hello"
with self.assertRaisesRegexp(ClassCastException, "Cannot convert str object to void"):
c_Runnable.run()
with self.assertRaisesRegexp(ClassCastException, "Cannot convert str object to "
"java.lang.Integer"):
c_Adder.add(99)
self.assertEqual("hello", c_GS.getString())
示例14: test_args
# 需要导入模块: from java import lang [as 别名]
# 或者: from java.lang import String [as 别名]
def test_args(self):
from java.lang import String
test = self
class C(dynamic_proxy(TP.Args)):
def tooMany(self):
pass
def tooFew(self, a):
pass
def addDuck(self, a, b):
return a + b
def star(self, *args):
return ",".join(args)
def varargs(self, delim, args):
test.assertIsInstance(args, jarray(String))
return delim.join(args)
c = C()
c_Args = cast(TP.Args, c)
with self.assertRaisesRegexp(PyException, args_error(1, 2)):
c_Args.tooMany(42)
with self.assertRaisesRegexp(PyException, args_error(2, 1)):
c_Args.tooFew()
self.assertEqual(3, c_Args.addDuck(jint(1), jint(2)))
self.assertAlmostEqual(3.5, c_Args.addDuck(jfloat(1), jfloat(2.5)))
self.assertEqual("helloworld", c_Args.addDuck("hello", "world"))
self.assertEqual("", c_Args.star())
self.assertEqual("hello", c_Args.star("hello"))
self.assertEqual("hello,world", c_Args.star("hello", "world"))
with self.assertRaisesRegexp(TypeError, "cannot be applied"):
c_Args.star("hello", "world", "again")
self.assertEqual("hello,world,again", c.star("hello", "world", "again"))
with self.assertRaisesRegexp(TypeError, args_error(1, 0, varargs=True)):
c_Args.varargs()
self.assertEqual("", c_Args.varargs(":"))
self.assertEqual("hello", c_Args.varargs("|", "hello"))
self.assertEqual("hello|world", c_Args.varargs("|", "hello", "world"))
示例15: _char_slice_to_unicode
# 需要导入模块: from java import lang [as 别名]
# 或者: from java.lang import String [as 别名]
def _char_slice_to_unicode(self, characters, start, length):
"""Convert a char[] slice to a PyUnicode instance"""
text = Py.newUnicode(String(characters[start:start + length]))
return text