1 #!/usr/bin/env python 2 3 import java.io 4 import os 5 import sys 6 7 class Character(object): 8 def __init__(self, value): 9 raise NotImplementedError, "__init__" 10 11 def charValue(self): 12 raise NotImplementedError, "charValue" 13 charValue___ = charValue 14 15 def hashCode(self): 16 raise NotImplementedError, "hashCode" 17 hashCode___ = hashCode 18 19 def equals(self, anObject): 20 raise NotImplementedError, "equals" 21 equals___java__lang__Object = equals 22 23 def toString(self): 24 raise NotImplementedError, "toString" 25 toString___ = toString 26 27 def isLowerCase(self, ch): 28 raise NotImplementedError, "isLowerCase" 29 isLowerCase____C_ = staticmethod(isLowerCase) 30 31 def isUpperCase(self, ch): 32 raise NotImplementedError, "isUpperCase" 33 isUpperCase____C_ = staticmethod(isUpperCase) 34 35 def isTitleCase(self, ch): 36 raise NotImplementedError, "isTitleCase" 37 isTitleCase____C_ = staticmethod(isTitleCase) 38 39 def isDigit(self, ch): 40 raise NotImplementedError, "isDigit" 41 isDigit____C_ = staticmethod(isDigit) 42 43 def isDefined(self, ch): 44 raise NotImplementedError, "isDefined" 45 isDefined____C_ = staticmethod(isDefined) 46 47 def isLetter(self, ch): 48 raise NotImplementedError, "isLetter" 49 isLetter____C_ = staticmethod(isLetter) 50 51 def isLetterOrDigit(self, ch): 52 raise NotImplementedError, "isLetterOrDigit" 53 isLetterOrDigit____C_ = staticmethod(isLetterOrDigit) 54 55 def isJavaLetter(self, ch): 56 raise NotImplementedError, "isJavaLetter" 57 isJavaLetter____C_ = staticmethod(isJavaLetter) 58 59 def isJavaLetterOrDigit(self, ch): 60 raise NotImplementedError, "isJavaLetterOrDigit" 61 isJavaLetterOrDigit____C_ = staticmethod(isJavaLetterOrDigit) 62 63 def isJavaIdentifierStart(self, ch): 64 raise NotImplementedError, "isJavaIdentifierStart" 65 isJavaIdentifierStart____C_ = staticmethod(isJavaIdentifierStart) 66 67 def isJavaIdentifierPart(self, ch): 68 raise NotImplementedError, "isJavaIdentifierPart" 69 isJavaIdentifierPart____C_ = staticmethod(isJavaIdentifierPart) 70 71 def isUnicodeIdentifierStart(self, ch): 72 raise NotImplementedError, "isUnicodeIdentifierStart" 73 isUnicodeIdentifierStart____C_ = staticmethod(isUnicodeIdentifierStart) 74 75 def isUnicodeIdentifierPart(self, ch): 76 raise NotImplementedError, "isUnicodeIdentifierPart" 77 isUnicodeIdentifierPart____C_ = staticmethod(isUnicodeIdentifierPart) 78 79 def isIdentifierIgnorable(self, ch): 80 raise NotImplementedError, "isIdentifierIgnorable" 81 isIdentifierIgnorable____C_ = staticmethod(isIdentifierIgnorable) 82 83 def toLowerCase(self, ch): 84 raise NotImplementedError, "toLowerCase" 85 toLowerCase____C_ = staticmethod(toLowerCase) 86 87 def toUpperCase(self, ch): 88 raise NotImplementedError, "toUpperCase" 89 toUpperCase____C_ = staticmethod(toUpperCase) 90 91 def toTitleCase(self, ch): 92 raise NotImplementedError, "toTitleCase" 93 toTitleCase____C_ = staticmethod(toTitleCase) 94 95 def digit(self, ch, radix): 96 raise NotImplementedError, "digit" 97 digit____C_____I_ = staticmethod(digit) 98 99 def getNumericValue(self, ch): 100 raise NotImplementedError, "getNumericValue" 101 getNumericValue____C_ = staticmethod(getNumericValue) 102 103 def isSpace(self, ch): 104 raise NotImplementedError, "isSpace" 105 isSpace____C_ = staticmethod(isSpace) 106 107 def isSpaceChar(self, ch): 108 raise NotImplementedError, "isSpaceChar" 109 isSpaceChar____C_ = staticmethod(isSpaceChar) 110 111 def isWhitespace(self, ch): 112 raise NotImplementedError, "isWhitespace" 113 isWhitespace____C_ = staticmethod(isWhitespace) 114 115 def isISOControl(self, ch): 116 raise NotImplementedError, "isISOControl" 117 isISOControl____C_ = staticmethod(isISOControl) 118 119 def getType(self, ch): 120 raise NotImplementedError, "getType" 121 getType____C_ = staticmethod(getType) 122 123 def forDigit(self, ch, radix): 124 raise NotImplementedError, "forDigit" 125 forDigit____C_____I_ = staticmethod(forDigit) 126 127 def compareTo(self, *args): 128 # compareTo(self, anotherCharacter) 129 # compareTo(self, o) 130 raise NotImplementedError, "compareTo" 131 compareTo____C_ = compareTo 132 compareTo___java__lang__Object = compareTo 133 134 setattr(Character, "__init____C_", Character.__init__) 135 136 class Class(object): 137 def forName(className): 138 parts = unicode(className).split(".") 139 obj = __import__(".".join(parts[:-1]), globals(), {}, []) 140 for part in parts[1:]: 141 obj = getattr(obj, part) 142 return obj 143 144 forName___java__lang__String = staticmethod(forName) 145 # NOTE: To be enhanced. 146 forName___java__lang__String____Z____java__lang__ClassLoader = staticmethod(forName) 147 148 # NOTE: Establish a better exception hierarchy. 149 150 class Error(object): 151 def __init__(self, *args): 152 self.args = args 153 154 setattr(Error, "__init_____", Error.__init__) 155 setattr(Error, "__init_____java__lang__String", Error.__init__) 156 157 class Exception(object): 158 def __init__(self, *args): 159 self.args = args 160 161 setattr(Exception, "__init_____", Exception.__init__) 162 setattr(Exception, "__init_____java__lang__String", Exception.__init__) 163 164 class IndexOutOfBoundsException(object): 165 def __init__(self, *args): 166 self.args = args 167 168 setattr(IndexOutOfBoundsException, "__init_____", IndexOutOfBoundsException.__init__) 169 setattr(IndexOutOfBoundsException, "__init_____java__lang__String", IndexOutOfBoundsException.__init__) 170 171 class IllegalArgumentException(Exception): 172 def __init__(self, *args): 173 self.args = args 174 175 setattr(IllegalArgumentException, "__init_____", IllegalArgumentException.__init__) 176 setattr(IllegalArgumentException, "__init_____java__lang__String", IllegalArgumentException.__init__) 177 178 class NullPointerException(object): 179 def __init__(self, *args): 180 self.args = args 181 182 setattr(NullPointerException, "__init_____", NullPointerException.__init__) 183 setattr(NullPointerException, "__init_____java__lang__String", NullPointerException.__init__) 184 185 class SecurityException(Exception): 186 def __init__(self, *args): 187 self.args = args 188 189 setattr(SecurityException, "__init_____", SecurityException.__init__) 190 setattr(SecurityException, "__init_____java__lang__String", SecurityException.__init__) 191 192 class String(object): 193 194 # NOTE: This method should not be needed, really. 195 def __str__(self): 196 return self.value.encode("utf-8") 197 198 def __unicode__(self): 199 return self.value 200 201 def init__empty(self): 202 self.value = u"" 203 204 def init__String(self, obj): 205 self.value = obj.value 206 207 def __init__(self, *args): 208 209 "Python string initialisation only." 210 211 if len(args) == 1 and isinstance(args[0], str): 212 self.value = unicode(args[0]) 213 return 214 elif len(args) == 1 and isinstance(args[0], unicode): 215 self.value = args[0] 216 return 217 # __init__(self) 218 elif len(args) == 0: 219 self.__init__empty() 220 return 221 # __init__(self, original) 222 elif len(args) == 1 and isinstance(args[0], String): 223 self.init__String(args[0]) 224 return 225 # __init__(self, value) 226 # __init__(self, value, offset, count) 227 # __init__(self, ascii, hibyte, offset, count) 228 # __init__(self, ascii, hibyte) 229 # __init__(self, bytes, offset, length, enc) 230 # __init__(self, bytes, enc) 231 # __init__(self, bytes, offset, length) 232 # __init__(self, bytes) 233 elif len(args) >= 1 and isinstance(args[0], list): 234 raise NotImplementedError, "__init__" 235 # __init__(self, buffer) 236 raise NotImplementedError, "__init__" 237 238 def length(self): 239 return len(self.value) 240 length___ = length 241 242 def charAt(self, index): 243 return ord(self.value[index]) 244 charAt____I_ = charAt 245 246 def getChars(self, srcBegin, srcEnd, dst, dstBegin): 247 raise NotImplementedError, "getChars" 248 getChars____I_____I_____C__array_____I_ = getChars 249 250 def getBytes(self, *args): 251 # void getBytes(self, srcBegin, srcEnd, dst, dstBegin) 252 # byte[] getBytes(self, enc) 253 # byte[] getBytes(self) 254 raise NotImplementedError, "getBytes" 255 getBytes___ = getBytes 256 getBytes____I_____I_____B__array_____I_ = getBytes 257 258 def equals(self, anObject): 259 return isinstance(anObject, self.__class__) and self.value == anObject.value 260 equals___java__lang__Object = equals 261 262 def compareTo(self, obj): 263 if self.value < obj.value: 264 return -1 265 elif self.value == obj.value: 266 return 0 267 else: 268 return 1 269 compareTo___java__lang__String = compareTo 270 271 # NOTE: Comparator defined using private classes. This implementation just 272 # NOTE: uses Python's lower method. 273 def compareToIgnoreCase(self, str): 274 value = self.value.lower() 275 value2 = str.value.lower() 276 if value < value2: 277 return -1 278 elif value == value2: 279 return 0 280 else: 281 return 1 282 compareToIgnoreCase___java__lang__String = compareToIgnoreCase 283 284 # NOTE: Comparator defined using private classes. This implementation just 285 # NOTE: uses Python's lower method. 286 def equalsIgnoreCase(self, anotherString): 287 value = self.value.lower() 288 value2 = anotherString.value.lower() 289 return value == value2 290 equalsIgnoreCase___java__lang__String = equalsIgnoreCase 291 292 def regionMatches(self, *args): 293 # regionMatches(self, toffset, other, ooffset, len) 294 # regionMatches(self, ignoreCase, toffset, other, ooffset, len) 295 raise NotImplementedError, "regionMatches" 296 297 def startsWith(self, *args): 298 # startsWith(self, prefix, toffset) 299 # startsWith(self, prefix) 300 raise NotImplementedError, "startsWith" 301 302 def endsWith(self, suffix): 303 raise NotImplementedError, "endsWith" 304 305 def hashCode(self): 306 raise NotImplementedError, "hashCode" 307 308 def indexOf____I_(self, ch): 309 return self.value.find(chr(ch)) 310 311 def indexOf____I_____I_(self, ch, fromIndex): 312 return self.value.find(chr(ch), fromIndex) 313 314 def indexOf___java__lang__String___(self, str): 315 return self.value.find(str.value) 316 317 def indexOf___java__lang__String____I_(self, str, fromIndex): 318 return self.value.find(str.value, fromIndex) 319 320 def lastIndexOf(self, *args): 321 # lastIndexOf(self, ch) 322 # lastIndexOf(self, ch, fromIndex) 323 # lastIndexOf(self, str) 324 # lastIndexOf(self, str, fromIndex) 325 raise NotImplementedError, "lastIndexOf" 326 327 def substring(self, *args): 328 # substring(self, beginIndex) 329 # substring(self, beginIndex, endIndex) 330 raise NotImplementedError, "substring" 331 332 def concat(self, str): 333 raise NotImplementedError, "concat" 334 335 def replace(self, oldChar, newChar): 336 raise NotImplementedError, "replace" 337 338 def toLowerCase(self, *args): 339 # toLowerCase(self, locale) 340 # toLowerCase(self) 341 raise NotImplementedError, "toLowerCase" 342 343 def toUpperCase(self, *args): 344 # toUpperCase(self, locale) 345 # toUpperCase(self) 346 raise NotImplementedError, "toUpperCase" 347 348 def trim(self): 349 raise NotImplementedError, "trim" 350 351 def toString(self): 352 return self 353 354 def toCharArray(self): 355 raise NotImplementedError, "toCharArray" 356 357 def valueOf(self, *args): 358 # valueOf(self, obj) 359 # valueOf(self, data) 360 # valueOf(self, data, offset, count) 361 # valueOf(self, b) 362 # valueOf(self, c) 363 # valueOf(self, l) 364 # valueOf(self, f) 365 # valueOf(self, d) 366 raise NotImplementedError, "valueOf" 367 valueOf = staticmethod(valueOf) 368 369 def copyValueOf(self, *args): 370 # copyValueOf(self, data, offset, count) 371 # copyValueOf(self, data) 372 raise NotImplementedError, "copyValueOf" 373 copyValueOf = staticmethod(copyValueOf) 374 375 def intern(self): 376 raise NotImplementedError, "intern" 377 378 setattr(String, "__init_____", String.init__empty) 379 setattr(String, "__init_____java__lang__String", String.init__String) 380 381 class System(object): 382 in_ = java.io.InputStream(sys.stdin) 383 out = java.io.PrintStream(sys.stdout) 384 err = java.io.PrintStream(sys.stderr) 385 386 def getProperty___java__lang__String(key): 387 try: 388 return os.environ[key] 389 except KeyError: 390 return None 391 392 getProperty___java__lang__String = staticmethod(getProperty___java__lang__String) 393 394 setattr(System, "in", System.in_) 395 396 # vim: tabstop=4 expandtab shiftwidth=4