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