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