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