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