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