Source Code Cross Referenced for PyString.java in  » Scripting » jython » org » python » core » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Scripting » jython » org.python.core 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /// Copyright (c) Corporation for National Research Initiatives
0002:        package org.python.core;
0003:
0004:        /**
0005:         * A builtin python string.
0006:         */
0007:        public class PyString extends PyBaseString implements  ClassDictInit {
0008:            //~ BEGIN GENERATED REGION -- DO NOT EDIT SEE gexpose.py
0009:            /* type info */
0010:
0011:            public static final String exposed_name = "str";
0012:
0013:            public static void typeSetup(PyObject dict, PyType.Newstyle marker) {
0014:                class exposed___ne__ extends PyBuiltinMethodNarrow {
0015:
0016:                    exposed___ne__(PyObject self, PyBuiltinFunction.Info info) {
0017:                        super (self, info);
0018:                    }
0019:
0020:                    public PyBuiltinFunction bind(PyObject self) {
0021:                        return new exposed___ne__(self, info);
0022:                    }
0023:
0024:                    public PyObject __call__(PyObject arg0) {
0025:                        PyObject ret = ((PyString) self).str___ne__(arg0);
0026:                        if (ret == null)
0027:                            return Py.NotImplemented;
0028:                        return ret;
0029:                    }
0030:
0031:                }
0032:                dict.__setitem__("__ne__", new PyMethodDescr("__ne__",
0033:                        PyString.class, 1, 1, new exposed___ne__(null, null)));
0034:                class exposed___eq__ extends PyBuiltinMethodNarrow {
0035:
0036:                    exposed___eq__(PyObject self, PyBuiltinFunction.Info info) {
0037:                        super (self, info);
0038:                    }
0039:
0040:                    public PyBuiltinFunction bind(PyObject self) {
0041:                        return new exposed___eq__(self, info);
0042:                    }
0043:
0044:                    public PyObject __call__(PyObject arg0) {
0045:                        PyObject ret = ((PyString) self).str___eq__(arg0);
0046:                        if (ret == null)
0047:                            return Py.NotImplemented;
0048:                        return ret;
0049:                    }
0050:
0051:                }
0052:                dict.__setitem__("__eq__", new PyMethodDescr("__eq__",
0053:                        PyString.class, 1, 1, new exposed___eq__(null, null)));
0054:                class exposed___lt__ extends PyBuiltinMethodNarrow {
0055:
0056:                    exposed___lt__(PyObject self, PyBuiltinFunction.Info info) {
0057:                        super (self, info);
0058:                    }
0059:
0060:                    public PyBuiltinFunction bind(PyObject self) {
0061:                        return new exposed___lt__(self, info);
0062:                    }
0063:
0064:                    public PyObject __call__(PyObject arg0) {
0065:                        PyObject ret = ((PyString) self).str___lt__(arg0);
0066:                        if (ret == null)
0067:                            return Py.NotImplemented;
0068:                        return ret;
0069:                    }
0070:
0071:                }
0072:                dict.__setitem__("__lt__", new PyMethodDescr("__lt__",
0073:                        PyString.class, 1, 1, new exposed___lt__(null, null)));
0074:                class exposed___le__ extends PyBuiltinMethodNarrow {
0075:
0076:                    exposed___le__(PyObject self, PyBuiltinFunction.Info info) {
0077:                        super (self, info);
0078:                    }
0079:
0080:                    public PyBuiltinFunction bind(PyObject self) {
0081:                        return new exposed___le__(self, info);
0082:                    }
0083:
0084:                    public PyObject __call__(PyObject arg0) {
0085:                        PyObject ret = ((PyString) self).str___le__(arg0);
0086:                        if (ret == null)
0087:                            return Py.NotImplemented;
0088:                        return ret;
0089:                    }
0090:
0091:                }
0092:                dict.__setitem__("__le__", new PyMethodDescr("__le__",
0093:                        PyString.class, 1, 1, new exposed___le__(null, null)));
0094:                class exposed___gt__ extends PyBuiltinMethodNarrow {
0095:
0096:                    exposed___gt__(PyObject self, PyBuiltinFunction.Info info) {
0097:                        super (self, info);
0098:                    }
0099:
0100:                    public PyBuiltinFunction bind(PyObject self) {
0101:                        return new exposed___gt__(self, info);
0102:                    }
0103:
0104:                    public PyObject __call__(PyObject arg0) {
0105:                        PyObject ret = ((PyString) self).str___gt__(arg0);
0106:                        if (ret == null)
0107:                            return Py.NotImplemented;
0108:                        return ret;
0109:                    }
0110:
0111:                }
0112:                dict.__setitem__("__gt__", new PyMethodDescr("__gt__",
0113:                        PyString.class, 1, 1, new exposed___gt__(null, null)));
0114:                class exposed___ge__ extends PyBuiltinMethodNarrow {
0115:
0116:                    exposed___ge__(PyObject self, PyBuiltinFunction.Info info) {
0117:                        super (self, info);
0118:                    }
0119:
0120:                    public PyBuiltinFunction bind(PyObject self) {
0121:                        return new exposed___ge__(self, info);
0122:                    }
0123:
0124:                    public PyObject __call__(PyObject arg0) {
0125:                        PyObject ret = ((PyString) self).str___ge__(arg0);
0126:                        if (ret == null)
0127:                            return Py.NotImplemented;
0128:                        return ret;
0129:                    }
0130:
0131:                }
0132:                dict.__setitem__("__ge__", new PyMethodDescr("__ge__",
0133:                        PyString.class, 1, 1, new exposed___ge__(null, null)));
0134:                class exposed___getitem__ extends PyBuiltinMethodNarrow {
0135:
0136:                    exposed___getitem__(PyObject self,
0137:                            PyBuiltinFunction.Info info) {
0138:                        super (self, info);
0139:                    }
0140:
0141:                    public PyBuiltinFunction bind(PyObject self) {
0142:                        return new exposed___getitem__(self, info);
0143:                    }
0144:
0145:                    public PyObject __call__(PyObject arg0) {
0146:                        PyObject ret = ((PyString) self).seq___finditem__(arg0);
0147:                        if (ret == null) {
0148:                            throw Py.IndexError("index out of range: " + arg0);
0149:                        }
0150:                        return ret;
0151:                    }
0152:
0153:                }
0154:                dict.__setitem__("__getitem__", new PyMethodDescr(
0155:                        "__getitem__", PyString.class, 1, 1,
0156:                        new exposed___getitem__(null, null)));
0157:                class exposed___getslice__ extends PyBuiltinMethodNarrow {
0158:
0159:                    exposed___getslice__(PyObject self,
0160:                            PyBuiltinFunction.Info info) {
0161:                        super (self, info);
0162:                    }
0163:
0164:                    public PyBuiltinFunction bind(PyObject self) {
0165:                        return new exposed___getslice__(self, info);
0166:                    }
0167:
0168:                    public PyObject __call__(PyObject arg0, PyObject arg1,
0169:                            PyObject arg2) {
0170:                        return ((PyString) self).seq___getslice__(arg0, arg1,
0171:                                arg2);
0172:                    }
0173:
0174:                    public PyObject __call__(PyObject arg0, PyObject arg1) {
0175:                        return ((PyString) self).seq___getslice__(arg0, arg1);
0176:                    }
0177:
0178:                }
0179:                dict.__setitem__("__getslice__", new PyMethodDescr(
0180:                        "__getslice__", PyString.class, 2, 3,
0181:                        new exposed___getslice__(null, null)));
0182:                class exposed___contains__ extends PyBuiltinMethodNarrow {
0183:
0184:                    exposed___contains__(PyObject self,
0185:                            PyBuiltinFunction.Info info) {
0186:                        super (self, info);
0187:                    }
0188:
0189:                    public PyBuiltinFunction bind(PyObject self) {
0190:                        return new exposed___contains__(self, info);
0191:                    }
0192:
0193:                    public PyObject __call__(PyObject arg0) {
0194:                        return Py.newBoolean(((PyString) self)
0195:                                .str___contains__(arg0));
0196:                    }
0197:
0198:                }
0199:                dict.__setitem__("__contains__", new PyMethodDescr(
0200:                        "__contains__", PyString.class, 1, 1,
0201:                        new exposed___contains__(null, null)));
0202:                class exposed___len__ extends PyBuiltinMethodNarrow {
0203:
0204:                    exposed___len__(PyObject self, PyBuiltinFunction.Info info) {
0205:                        super (self, info);
0206:                    }
0207:
0208:                    public PyBuiltinFunction bind(PyObject self) {
0209:                        return new exposed___len__(self, info);
0210:                    }
0211:
0212:                    public PyObject __call__() {
0213:                        return Py.newInteger(((PyString) self).str___len__());
0214:                    }
0215:
0216:                }
0217:                dict.__setitem__("__len__", new PyMethodDescr("__len__",
0218:                        PyString.class, 0, 0, new exposed___len__(null, null)));
0219:                class exposed___add__ extends PyBuiltinMethodNarrow {
0220:
0221:                    exposed___add__(PyObject self, PyBuiltinFunction.Info info) {
0222:                        super (self, info);
0223:                    }
0224:
0225:                    public PyBuiltinFunction bind(PyObject self) {
0226:                        return new exposed___add__(self, info);
0227:                    }
0228:
0229:                    public PyObject __call__(PyObject arg0) {
0230:                        return ((PyString) self).str___add__(arg0);
0231:                    }
0232:
0233:                }
0234:                dict.__setitem__("__add__", new PyMethodDescr("__add__",
0235:                        PyString.class, 1, 1, new exposed___add__(null, null)));
0236:                class exposed___mod__ extends PyBuiltinMethodNarrow {
0237:
0238:                    exposed___mod__(PyObject self, PyBuiltinFunction.Info info) {
0239:                        super (self, info);
0240:                    }
0241:
0242:                    public PyBuiltinFunction bind(PyObject self) {
0243:                        return new exposed___mod__(self, info);
0244:                    }
0245:
0246:                    public PyObject __call__(PyObject arg0) {
0247:                        return ((PyString) self).str___mod__(arg0);
0248:                    }
0249:
0250:                }
0251:                dict.__setitem__("__mod__", new PyMethodDescr("__mod__",
0252:                        PyString.class, 1, 1, new exposed___mod__(null, null)));
0253:                class exposed___mul__ extends PyBuiltinMethodNarrow {
0254:
0255:                    exposed___mul__(PyObject self, PyBuiltinFunction.Info info) {
0256:                        super (self, info);
0257:                    }
0258:
0259:                    public PyBuiltinFunction bind(PyObject self) {
0260:                        return new exposed___mul__(self, info);
0261:                    }
0262:
0263:                    public PyObject __call__(PyObject arg0) {
0264:                        return ((PyString) self).str___mul__(arg0);
0265:                    }
0266:
0267:                }
0268:                dict.__setitem__("__mul__", new PyMethodDescr("__mul__",
0269:                        PyString.class, 1, 1, new exposed___mul__(null, null)));
0270:                class exposed___reduce__ extends PyBuiltinMethodNarrow {
0271:
0272:                    exposed___reduce__(PyObject self,
0273:                            PyBuiltinFunction.Info info) {
0274:                        super (self, info);
0275:                    }
0276:
0277:                    public PyBuiltinFunction bind(PyObject self) {
0278:                        return new exposed___reduce__(self, info);
0279:                    }
0280:
0281:                    public PyObject __call__() {
0282:                        return ((PyString) self).str___reduce__();
0283:                    }
0284:
0285:                }
0286:                dict.__setitem__("__reduce__", new PyMethodDescr("__reduce__",
0287:                        PyString.class, 0, 0,
0288:                        new exposed___reduce__(null, null)));
0289:                class exposed___rmul__ extends PyBuiltinMethodNarrow {
0290:
0291:                    exposed___rmul__(PyObject self, PyBuiltinFunction.Info info) {
0292:                        super (self, info);
0293:                    }
0294:
0295:                    public PyBuiltinFunction bind(PyObject self) {
0296:                        return new exposed___rmul__(self, info);
0297:                    }
0298:
0299:                    public PyObject __call__(PyObject arg0) {
0300:                        return ((PyString) self).str___rmul__(arg0);
0301:                    }
0302:
0303:                }
0304:                dict
0305:                        .__setitem__("__rmul__", new PyMethodDescr("__rmul__",
0306:                                PyString.class, 1, 1, new exposed___rmul__(
0307:                                        null, null)));
0308:                class exposed___str__ extends PyBuiltinMethodNarrow {
0309:
0310:                    exposed___str__(PyObject self, PyBuiltinFunction.Info info) {
0311:                        super (self, info);
0312:                    }
0313:
0314:                    public PyBuiltinFunction bind(PyObject self) {
0315:                        return new exposed___str__(self, info);
0316:                    }
0317:
0318:                    public PyObject __call__() {
0319:                        return ((PyString) self).str___str__();
0320:                    }
0321:
0322:                }
0323:                dict.__setitem__("__str__", new PyMethodDescr("__str__",
0324:                        PyString.class, 0, 0, new exposed___str__(null, null)));
0325:                class exposed___unicode__ extends PyBuiltinMethodNarrow {
0326:
0327:                    exposed___unicode__(PyObject self,
0328:                            PyBuiltinFunction.Info info) {
0329:                        super (self, info);
0330:                    }
0331:
0332:                    public PyBuiltinFunction bind(PyObject self) {
0333:                        return new exposed___unicode__(self, info);
0334:                    }
0335:
0336:                    public PyObject __call__() {
0337:                        return ((PyString) self).str___unicode__();
0338:                    }
0339:
0340:                }
0341:                dict.__setitem__("__unicode__", new PyMethodDescr(
0342:                        "__unicode__", PyString.class, 0, 0,
0343:                        new exposed___unicode__(null, null)));
0344:                class exposed___hash__ extends PyBuiltinMethodNarrow {
0345:
0346:                    exposed___hash__(PyObject self, PyBuiltinFunction.Info info) {
0347:                        super (self, info);
0348:                    }
0349:
0350:                    public PyBuiltinFunction bind(PyObject self) {
0351:                        return new exposed___hash__(self, info);
0352:                    }
0353:
0354:                    public PyObject __call__() {
0355:                        return Py.newInteger(((PyString) self).str_hashCode());
0356:                    }
0357:
0358:                }
0359:                dict
0360:                        .__setitem__("__hash__", new PyMethodDescr("__hash__",
0361:                                PyString.class, 0, 0, new exposed___hash__(
0362:                                        null, null)));
0363:                class exposed___repr__ extends PyBuiltinMethodNarrow {
0364:
0365:                    exposed___repr__(PyObject self, PyBuiltinFunction.Info info) {
0366:                        super (self, info);
0367:                    }
0368:
0369:                    public PyBuiltinFunction bind(PyObject self) {
0370:                        return new exposed___repr__(self, info);
0371:                    }
0372:
0373:                    public PyObject __call__() {
0374:                        return new PyString(((PyString) self).str_toString());
0375:                    }
0376:
0377:                }
0378:                dict
0379:                        .__setitem__("__repr__", new PyMethodDescr("__repr__",
0380:                                PyString.class, 0, 0, new exposed___repr__(
0381:                                        null, null)));
0382:                class exposed_capitalize extends PyBuiltinMethodNarrow {
0383:
0384:                    exposed_capitalize(PyObject self,
0385:                            PyBuiltinFunction.Info info) {
0386:                        super (self, info);
0387:                    }
0388:
0389:                    public PyBuiltinFunction bind(PyObject self) {
0390:                        return new exposed_capitalize(self, info);
0391:                    }
0392:
0393:                    public PyObject __call__() {
0394:                        return new PyString(((PyString) self).str_capitalize());
0395:                    }
0396:
0397:                }
0398:                dict.__setitem__("capitalize", new PyMethodDescr("capitalize",
0399:                        PyString.class, 0, 0,
0400:                        new exposed_capitalize(null, null)));
0401:                class exposed_center extends PyBuiltinMethodNarrow {
0402:
0403:                    exposed_center(PyObject self, PyBuiltinFunction.Info info) {
0404:                        super (self, info);
0405:                    }
0406:
0407:                    public PyBuiltinFunction bind(PyObject self) {
0408:                        return new exposed_center(self, info);
0409:                    }
0410:
0411:                    public PyObject __call__(PyObject arg0) {
0412:                        try {
0413:                            return new PyString(((PyString) self)
0414:                                    .str_center(arg0.asInt(0)));
0415:                        } catch (PyObject.ConversionException e) {
0416:                            String msg;
0417:                            switch (e.index) {
0418:                            case 0:
0419:                                msg = "expected an integer";
0420:                                break;
0421:                            default:
0422:                                msg = "xxx";
0423:                            }
0424:                            throw Py.TypeError(msg);
0425:                        }
0426:                    }
0427:
0428:                }
0429:                dict.__setitem__("center", new PyMethodDescr("center",
0430:                        PyString.class, 1, 1, new exposed_center(null, null)));
0431:                class exposed_count extends PyBuiltinMethodNarrow {
0432:
0433:                    exposed_count(PyObject self, PyBuiltinFunction.Info info) {
0434:                        super (self, info);
0435:                    }
0436:
0437:                    public PyBuiltinFunction bind(PyObject self) {
0438:                        return new exposed_count(self, info);
0439:                    }
0440:
0441:                    public PyObject __call__(PyObject arg0, PyObject arg1,
0442:                            PyObject arg2) {
0443:                        try {
0444:                            return Py.newInteger(((PyString) self).str_count(
0445:                                    arg0.asString(0), arg1.asInt(1), arg2
0446:                                            .asInt(2)));
0447:                        } catch (PyObject.ConversionException e) {
0448:                            String msg;
0449:                            switch (e.index) {
0450:                            case 1:
0451:                            case 2:
0452:                                msg = "expected an integer";
0453:                                break;
0454:                            case 0:
0455:                                msg = "expected a string";
0456:                                break;
0457:                            default:
0458:                                msg = "xxx";
0459:                            }
0460:                            throw Py.TypeError(msg);
0461:                        }
0462:                    }
0463:
0464:                    public PyObject __call__(PyObject arg0, PyObject arg1) {
0465:                        try {
0466:                            return Py.newInteger(((PyString) self).str_count(
0467:                                    arg0.asString(0), arg1.asInt(1)));
0468:                        } catch (PyObject.ConversionException e) {
0469:                            String msg;
0470:                            switch (e.index) {
0471:                            case 1:
0472:                                msg = "expected an integer";
0473:                                break;
0474:                            case 0:
0475:                                msg = "expected a string";
0476:                                break;
0477:                            default:
0478:                                msg = "xxx";
0479:                            }
0480:                            throw Py.TypeError(msg);
0481:                        }
0482:                    }
0483:
0484:                    public PyObject __call__(PyObject arg0) {
0485:                        try {
0486:                            return Py.newInteger(((PyString) self)
0487:                                    .str_count(arg0.asString(0)));
0488:                        } catch (PyObject.ConversionException e) {
0489:                            String msg;
0490:                            switch (e.index) {
0491:                            case 0:
0492:                                msg = "expected a string";
0493:                                break;
0494:                            default:
0495:                                msg = "xxx";
0496:                            }
0497:                            throw Py.TypeError(msg);
0498:                        }
0499:                    }
0500:
0501:                }
0502:                dict.__setitem__("count", new PyMethodDescr("count",
0503:                        PyString.class, 1, 3, new exposed_count(null, null)));
0504:                class exposed_decode extends PyBuiltinMethodNarrow {
0505:
0506:                    exposed_decode(PyObject self, PyBuiltinFunction.Info info) {
0507:                        super (self, info);
0508:                    }
0509:
0510:                    public PyBuiltinFunction bind(PyObject self) {
0511:                        return new exposed_decode(self, info);
0512:                    }
0513:
0514:                    public PyObject __call__(PyObject arg0, PyObject arg1) {
0515:                        try {
0516:                            return new PyUnicode(((PyString) self).str_decode(
0517:                                    arg0.asString(0), arg1.asString(1)));
0518:                        } catch (PyObject.ConversionException e) {
0519:                            String msg;
0520:                            switch (e.index) {
0521:                            case 0:
0522:                            case 1:
0523:                                msg = "expected a string";
0524:                                break;
0525:                            default:
0526:                                msg = "xxx";
0527:                            }
0528:                            throw Py.TypeError(msg);
0529:                        }
0530:                    }
0531:
0532:                    public PyObject __call__(PyObject arg0) {
0533:                        try {
0534:                            return new PyUnicode(((PyString) self)
0535:                                    .str_decode(arg0.asString(0)));
0536:                        } catch (PyObject.ConversionException e) {
0537:                            String msg;
0538:                            switch (e.index) {
0539:                            case 0:
0540:                                msg = "expected a string";
0541:                                break;
0542:                            default:
0543:                                msg = "xxx";
0544:                            }
0545:                            throw Py.TypeError(msg);
0546:                        }
0547:                    }
0548:
0549:                    public PyObject __call__() {
0550:                        return new PyUnicode(((PyString) self).str_decode());
0551:                    }
0552:
0553:                }
0554:                dict.__setitem__("decode", new PyMethodDescr("decode",
0555:                        PyString.class, 0, 2, new exposed_decode(null, null)));
0556:                class exposed_encode extends PyBuiltinMethodNarrow {
0557:
0558:                    exposed_encode(PyObject self, PyBuiltinFunction.Info info) {
0559:                        super (self, info);
0560:                    }
0561:
0562:                    public PyBuiltinFunction bind(PyObject self) {
0563:                        return new exposed_encode(self, info);
0564:                    }
0565:
0566:                    public PyObject __call__(PyObject arg0, PyObject arg1) {
0567:                        try {
0568:                            return new PyString(((PyString) self).str_encode(
0569:                                    arg0.asString(0), arg1.asString(1)));
0570:                        } catch (PyObject.ConversionException e) {
0571:                            String msg;
0572:                            switch (e.index) {
0573:                            case 0:
0574:                            case 1:
0575:                                msg = "expected a string";
0576:                                break;
0577:                            default:
0578:                                msg = "xxx";
0579:                            }
0580:                            throw Py.TypeError(msg);
0581:                        }
0582:                    }
0583:
0584:                    public PyObject __call__(PyObject arg0) {
0585:                        try {
0586:                            return new PyString(((PyString) self)
0587:                                    .str_encode(arg0.asString(0)));
0588:                        } catch (PyObject.ConversionException e) {
0589:                            String msg;
0590:                            switch (e.index) {
0591:                            case 0:
0592:                                msg = "expected a string";
0593:                                break;
0594:                            default:
0595:                                msg = "xxx";
0596:                            }
0597:                            throw Py.TypeError(msg);
0598:                        }
0599:                    }
0600:
0601:                    public PyObject __call__() {
0602:                        return new PyString(((PyString) self).str_encode());
0603:                    }
0604:
0605:                }
0606:                dict.__setitem__("encode", new PyMethodDescr("encode",
0607:                        PyString.class, 0, 2, new exposed_encode(null, null)));
0608:                class exposed_endswith extends PyBuiltinMethodNarrow {
0609:
0610:                    exposed_endswith(PyObject self, PyBuiltinFunction.Info info) {
0611:                        super (self, info);
0612:                    }
0613:
0614:                    public PyBuiltinFunction bind(PyObject self) {
0615:                        return new exposed_endswith(self, info);
0616:                    }
0617:
0618:                    public PyObject __call__(PyObject arg0, PyObject arg1,
0619:                            PyObject arg2) {
0620:                        try {
0621:                            return Py.newBoolean(((PyString) self)
0622:                                    .str_endswith(arg0.asString(0), arg1
0623:                                            .asInt(1), arg2.asInt(2)));
0624:                        } catch (PyObject.ConversionException e) {
0625:                            String msg;
0626:                            switch (e.index) {
0627:                            case 1:
0628:                            case 2:
0629:                                msg = "expected an integer";
0630:                                break;
0631:                            case 0:
0632:                                msg = "expected a string";
0633:                                break;
0634:                            default:
0635:                                msg = "xxx";
0636:                            }
0637:                            throw Py.TypeError(msg);
0638:                        }
0639:                    }
0640:
0641:                    public PyObject __call__(PyObject arg0, PyObject arg1) {
0642:                        try {
0643:                            return Py.newBoolean(((PyString) self)
0644:                                    .str_endswith(arg0.asString(0), arg1
0645:                                            .asInt(1)));
0646:                        } catch (PyObject.ConversionException e) {
0647:                            String msg;
0648:                            switch (e.index) {
0649:                            case 1:
0650:                                msg = "expected an integer";
0651:                                break;
0652:                            case 0:
0653:                                msg = "expected a string";
0654:                                break;
0655:                            default:
0656:                                msg = "xxx";
0657:                            }
0658:                            throw Py.TypeError(msg);
0659:                        }
0660:                    }
0661:
0662:                    public PyObject __call__(PyObject arg0) {
0663:                        try {
0664:                            return Py.newBoolean(((PyString) self)
0665:                                    .str_endswith(arg0.asString(0)));
0666:                        } catch (PyObject.ConversionException e) {
0667:                            String msg;
0668:                            switch (e.index) {
0669:                            case 0:
0670:                                msg = "expected a string";
0671:                                break;
0672:                            default:
0673:                                msg = "xxx";
0674:                            }
0675:                            throw Py.TypeError(msg);
0676:                        }
0677:                    }
0678:
0679:                }
0680:                dict
0681:                        .__setitem__("endswith", new PyMethodDescr("endswith",
0682:                                PyString.class, 1, 3, new exposed_endswith(
0683:                                        null, null)));
0684:                class exposed_expandtabs extends PyBuiltinMethodNarrow {
0685:
0686:                    exposed_expandtabs(PyObject self,
0687:                            PyBuiltinFunction.Info info) {
0688:                        super (self, info);
0689:                    }
0690:
0691:                    public PyBuiltinFunction bind(PyObject self) {
0692:                        return new exposed_expandtabs(self, info);
0693:                    }
0694:
0695:                    public PyObject __call__(PyObject arg0) {
0696:                        try {
0697:                            return new PyString(((PyString) self)
0698:                                    .str_expandtabs(arg0.asInt(0)));
0699:                        } catch (PyObject.ConversionException e) {
0700:                            String msg;
0701:                            switch (e.index) {
0702:                            case 0:
0703:                                msg = "expected an integer";
0704:                                break;
0705:                            default:
0706:                                msg = "xxx";
0707:                            }
0708:                            throw Py.TypeError(msg);
0709:                        }
0710:                    }
0711:
0712:                    public PyObject __call__() {
0713:                        return new PyString(((PyString) self).str_expandtabs());
0714:                    }
0715:
0716:                }
0717:                dict.__setitem__("expandtabs", new PyMethodDescr("expandtabs",
0718:                        PyString.class, 0, 1,
0719:                        new exposed_expandtabs(null, null)));
0720:                class exposed_find extends PyBuiltinMethodNarrow {
0721:
0722:                    exposed_find(PyObject self, PyBuiltinFunction.Info info) {
0723:                        super (self, info);
0724:                    }
0725:
0726:                    public PyBuiltinFunction bind(PyObject self) {
0727:                        return new exposed_find(self, info);
0728:                    }
0729:
0730:                    public PyObject __call__(PyObject arg0, PyObject arg1,
0731:                            PyObject arg2) {
0732:                        try {
0733:                            return Py.newInteger(((PyString) self).str_find(
0734:                                    arg0.asString(0), arg1.asInt(1), arg2
0735:                                            .asInt(2)));
0736:                        } catch (PyObject.ConversionException e) {
0737:                            String msg;
0738:                            switch (e.index) {
0739:                            case 1:
0740:                            case 2:
0741:                                msg = "expected an integer";
0742:                                break;
0743:                            case 0:
0744:                                msg = "expected a string";
0745:                                break;
0746:                            default:
0747:                                msg = "xxx";
0748:                            }
0749:                            throw Py.TypeError(msg);
0750:                        }
0751:                    }
0752:
0753:                    public PyObject __call__(PyObject arg0, PyObject arg1) {
0754:                        try {
0755:                            return Py.newInteger(((PyString) self).str_find(
0756:                                    arg0.asString(0), arg1.asInt(1)));
0757:                        } catch (PyObject.ConversionException e) {
0758:                            String msg;
0759:                            switch (e.index) {
0760:                            case 1:
0761:                                msg = "expected an integer";
0762:                                break;
0763:                            case 0:
0764:                                msg = "expected a string";
0765:                                break;
0766:                            default:
0767:                                msg = "xxx";
0768:                            }
0769:                            throw Py.TypeError(msg);
0770:                        }
0771:                    }
0772:
0773:                    public PyObject __call__(PyObject arg0) {
0774:                        try {
0775:                            return Py.newInteger(((PyString) self)
0776:                                    .str_find(arg0.asString(0)));
0777:                        } catch (PyObject.ConversionException e) {
0778:                            String msg;
0779:                            switch (e.index) {
0780:                            case 0:
0781:                                msg = "expected a string";
0782:                                break;
0783:                            default:
0784:                                msg = "xxx";
0785:                            }
0786:                            throw Py.TypeError(msg);
0787:                        }
0788:                    }
0789:
0790:                }
0791:                dict.__setitem__("find", new PyMethodDescr("find",
0792:                        PyString.class, 1, 3, new exposed_find(null, null)));
0793:                class exposed_index extends PyBuiltinMethodNarrow {
0794:
0795:                    exposed_index(PyObject self, PyBuiltinFunction.Info info) {
0796:                        super (self, info);
0797:                    }
0798:
0799:                    public PyBuiltinFunction bind(PyObject self) {
0800:                        return new exposed_index(self, info);
0801:                    }
0802:
0803:                    public PyObject __call__(PyObject arg0, PyObject arg1,
0804:                            PyObject arg2) {
0805:                        try {
0806:                            return Py.newInteger(((PyString) self).str_index(
0807:                                    arg0.asString(0), arg1.asInt(1), arg2
0808:                                            .asInt(2)));
0809:                        } catch (PyObject.ConversionException e) {
0810:                            String msg;
0811:                            switch (e.index) {
0812:                            case 1:
0813:                            case 2:
0814:                                msg = "expected an integer";
0815:                                break;
0816:                            case 0:
0817:                                msg = "expected a string";
0818:                                break;
0819:                            default:
0820:                                msg = "xxx";
0821:                            }
0822:                            throw Py.TypeError(msg);
0823:                        }
0824:                    }
0825:
0826:                    public PyObject __call__(PyObject arg0, PyObject arg1) {
0827:                        try {
0828:                            return Py.newInteger(((PyString) self).str_index(
0829:                                    arg0.asString(0), arg1.asInt(1)));
0830:                        } catch (PyObject.ConversionException e) {
0831:                            String msg;
0832:                            switch (e.index) {
0833:                            case 1:
0834:                                msg = "expected an integer";
0835:                                break;
0836:                            case 0:
0837:                                msg = "expected a string";
0838:                                break;
0839:                            default:
0840:                                msg = "xxx";
0841:                            }
0842:                            throw Py.TypeError(msg);
0843:                        }
0844:                    }
0845:
0846:                    public PyObject __call__(PyObject arg0) {
0847:                        try {
0848:                            return Py.newInteger(((PyString) self)
0849:                                    .str_index(arg0.asString(0)));
0850:                        } catch (PyObject.ConversionException e) {
0851:                            String msg;
0852:                            switch (e.index) {
0853:                            case 0:
0854:                                msg = "expected a string";
0855:                                break;
0856:                            default:
0857:                                msg = "xxx";
0858:                            }
0859:                            throw Py.TypeError(msg);
0860:                        }
0861:                    }
0862:
0863:                }
0864:                dict.__setitem__("index", new PyMethodDescr("index",
0865:                        PyString.class, 1, 3, new exposed_index(null, null)));
0866:                class exposed_isalnum extends PyBuiltinMethodNarrow {
0867:
0868:                    exposed_isalnum(PyObject self, PyBuiltinFunction.Info info) {
0869:                        super (self, info);
0870:                    }
0871:
0872:                    public PyBuiltinFunction bind(PyObject self) {
0873:                        return new exposed_isalnum(self, info);
0874:                    }
0875:
0876:                    public PyObject __call__() {
0877:                        return Py.newBoolean(((PyString) self).str_isalnum());
0878:                    }
0879:
0880:                }
0881:                dict.__setitem__("isalnum", new PyMethodDescr("isalnum",
0882:                        PyString.class, 0, 0, new exposed_isalnum(null, null)));
0883:                class exposed_isalpha extends PyBuiltinMethodNarrow {
0884:
0885:                    exposed_isalpha(PyObject self, PyBuiltinFunction.Info info) {
0886:                        super (self, info);
0887:                    }
0888:
0889:                    public PyBuiltinFunction bind(PyObject self) {
0890:                        return new exposed_isalpha(self, info);
0891:                    }
0892:
0893:                    public PyObject __call__() {
0894:                        return Py.newBoolean(((PyString) self).str_isalpha());
0895:                    }
0896:
0897:                }
0898:                dict.__setitem__("isalpha", new PyMethodDescr("isalpha",
0899:                        PyString.class, 0, 0, new exposed_isalpha(null, null)));
0900:                class exposed_isdecimal extends PyBuiltinMethodNarrow {
0901:
0902:                    exposed_isdecimal(PyObject self, PyBuiltinFunction.Info info) {
0903:                        super (self, info);
0904:                    }
0905:
0906:                    public PyBuiltinFunction bind(PyObject self) {
0907:                        return new exposed_isdecimal(self, info);
0908:                    }
0909:
0910:                    public PyObject __call__() {
0911:                        return Py.newBoolean(((PyString) self).str_isdecimal());
0912:                    }
0913:
0914:                }
0915:                dict.__setitem__("isdecimal",
0916:                        new PyMethodDescr("isdecimal", PyString.class, 0, 0,
0917:                                new exposed_isdecimal(null, null)));
0918:                class exposed_isdigit extends PyBuiltinMethodNarrow {
0919:
0920:                    exposed_isdigit(PyObject self, PyBuiltinFunction.Info info) {
0921:                        super (self, info);
0922:                    }
0923:
0924:                    public PyBuiltinFunction bind(PyObject self) {
0925:                        return new exposed_isdigit(self, info);
0926:                    }
0927:
0928:                    public PyObject __call__() {
0929:                        return Py.newBoolean(((PyString) self).str_isdigit());
0930:                    }
0931:
0932:                }
0933:                dict.__setitem__("isdigit", new PyMethodDescr("isdigit",
0934:                        PyString.class, 0, 0, new exposed_isdigit(null, null)));
0935:                class exposed_islower extends PyBuiltinMethodNarrow {
0936:
0937:                    exposed_islower(PyObject self, PyBuiltinFunction.Info info) {
0938:                        super (self, info);
0939:                    }
0940:
0941:                    public PyBuiltinFunction bind(PyObject self) {
0942:                        return new exposed_islower(self, info);
0943:                    }
0944:
0945:                    public PyObject __call__() {
0946:                        return Py.newBoolean(((PyString) self).str_islower());
0947:                    }
0948:
0949:                }
0950:                dict.__setitem__("islower", new PyMethodDescr("islower",
0951:                        PyString.class, 0, 0, new exposed_islower(null, null)));
0952:                class exposed_isnumeric extends PyBuiltinMethodNarrow {
0953:
0954:                    exposed_isnumeric(PyObject self, PyBuiltinFunction.Info info) {
0955:                        super (self, info);
0956:                    }
0957:
0958:                    public PyBuiltinFunction bind(PyObject self) {
0959:                        return new exposed_isnumeric(self, info);
0960:                    }
0961:
0962:                    public PyObject __call__() {
0963:                        return Py.newBoolean(((PyString) self).str_isnumeric());
0964:                    }
0965:
0966:                }
0967:                dict.__setitem__("isnumeric",
0968:                        new PyMethodDescr("isnumeric", PyString.class, 0, 0,
0969:                                new exposed_isnumeric(null, null)));
0970:                class exposed_isspace extends PyBuiltinMethodNarrow {
0971:
0972:                    exposed_isspace(PyObject self, PyBuiltinFunction.Info info) {
0973:                        super (self, info);
0974:                    }
0975:
0976:                    public PyBuiltinFunction bind(PyObject self) {
0977:                        return new exposed_isspace(self, info);
0978:                    }
0979:
0980:                    public PyObject __call__() {
0981:                        return Py.newBoolean(((PyString) self).str_isspace());
0982:                    }
0983:
0984:                }
0985:                dict.__setitem__("isspace", new PyMethodDescr("isspace",
0986:                        PyString.class, 0, 0, new exposed_isspace(null, null)));
0987:                class exposed_istitle extends PyBuiltinMethodNarrow {
0988:
0989:                    exposed_istitle(PyObject self, PyBuiltinFunction.Info info) {
0990:                        super (self, info);
0991:                    }
0992:
0993:                    public PyBuiltinFunction bind(PyObject self) {
0994:                        return new exposed_istitle(self, info);
0995:                    }
0996:
0997:                    public PyObject __call__() {
0998:                        return Py.newBoolean(((PyString) self).str_istitle());
0999:                    }
1000:
1001:                }
1002:                dict.__setitem__("istitle", new PyMethodDescr("istitle",
1003:                        PyString.class, 0, 0, new exposed_istitle(null, null)));
1004:                class exposed_isunicode extends PyBuiltinMethodNarrow {
1005:
1006:                    exposed_isunicode(PyObject self, PyBuiltinFunction.Info info) {
1007:                        super (self, info);
1008:                    }
1009:
1010:                    public PyBuiltinFunction bind(PyObject self) {
1011:                        return new exposed_isunicode(self, info);
1012:                    }
1013:
1014:                    public PyObject __call__() {
1015:                        return Py.newBoolean(((PyString) self).str_isunicode());
1016:                    }
1017:
1018:                }
1019:                dict.__setitem__("isunicode",
1020:                        new PyMethodDescr("isunicode", PyString.class, 0, 0,
1021:                                new exposed_isunicode(null, null)));
1022:                class exposed_isupper extends PyBuiltinMethodNarrow {
1023:
1024:                    exposed_isupper(PyObject self, PyBuiltinFunction.Info info) {
1025:                        super (self, info);
1026:                    }
1027:
1028:                    public PyBuiltinFunction bind(PyObject self) {
1029:                        return new exposed_isupper(self, info);
1030:                    }
1031:
1032:                    public PyObject __call__() {
1033:                        return Py.newBoolean(((PyString) self).str_isupper());
1034:                    }
1035:
1036:                }
1037:                dict.__setitem__("isupper", new PyMethodDescr("isupper",
1038:                        PyString.class, 0, 0, new exposed_isupper(null, null)));
1039:                class exposed_join extends PyBuiltinMethodNarrow {
1040:
1041:                    exposed_join(PyObject self, PyBuiltinFunction.Info info) {
1042:                        super (self, info);
1043:                    }
1044:
1045:                    public PyBuiltinFunction bind(PyObject self) {
1046:                        return new exposed_join(self, info);
1047:                    }
1048:
1049:                    public PyObject __call__(PyObject arg0) {
1050:                        return ((PyString) self).str_join(arg0);
1051:                    }
1052:
1053:                }
1054:                dict.__setitem__("join", new PyMethodDescr("join",
1055:                        PyString.class, 1, 1, new exposed_join(null, null)));
1056:                class exposed_ljust extends PyBuiltinMethodNarrow {
1057:
1058:                    exposed_ljust(PyObject self, PyBuiltinFunction.Info info) {
1059:                        super (self, info);
1060:                    }
1061:
1062:                    public PyBuiltinFunction bind(PyObject self) {
1063:                        return new exposed_ljust(self, info);
1064:                    }
1065:
1066:                    public PyObject __call__(PyObject arg0) {
1067:                        try {
1068:                            return new PyString(((PyString) self)
1069:                                    .str_ljust(arg0.asInt(0)));
1070:                        } catch (PyObject.ConversionException e) {
1071:                            String msg;
1072:                            switch (e.index) {
1073:                            case 0:
1074:                                msg = "expected an integer";
1075:                                break;
1076:                            default:
1077:                                msg = "xxx";
1078:                            }
1079:                            throw Py.TypeError(msg);
1080:                        }
1081:                    }
1082:
1083:                }
1084:                dict.__setitem__("ljust", new PyMethodDescr("ljust",
1085:                        PyString.class, 1, 1, new exposed_ljust(null, null)));
1086:                class exposed_lower extends PyBuiltinMethodNarrow {
1087:
1088:                    exposed_lower(PyObject self, PyBuiltinFunction.Info info) {
1089:                        super (self, info);
1090:                    }
1091:
1092:                    public PyBuiltinFunction bind(PyObject self) {
1093:                        return new exposed_lower(self, info);
1094:                    }
1095:
1096:                    public PyObject __call__() {
1097:                        return new PyString(((PyString) self).str_lower());
1098:                    }
1099:
1100:                }
1101:                dict.__setitem__("lower", new PyMethodDescr("lower",
1102:                        PyString.class, 0, 0, new exposed_lower(null, null)));
1103:                class exposed_lstrip extends PyBuiltinMethodNarrow {
1104:
1105:                    exposed_lstrip(PyObject self, PyBuiltinFunction.Info info) {
1106:                        super (self, info);
1107:                    }
1108:
1109:                    public PyBuiltinFunction bind(PyObject self) {
1110:                        return new exposed_lstrip(self, info);
1111:                    }
1112:
1113:                    public PyObject __call__(PyObject arg0) {
1114:                        try {
1115:                            return new PyString(((PyString) self)
1116:                                    .str_lstrip(arg0.asStringOrNull(0)));
1117:                        } catch (PyObject.ConversionException e) {
1118:                            String msg;
1119:                            switch (e.index) {
1120:                            case 0:
1121:                                msg = "expected a string or None";
1122:                                break;
1123:                            default:
1124:                                msg = "xxx";
1125:                            }
1126:                            throw Py.TypeError(msg);
1127:                        }
1128:                    }
1129:
1130:                    public PyObject __call__() {
1131:                        return new PyString(((PyString) self).str_lstrip());
1132:                    }
1133:
1134:                }
1135:                dict.__setitem__("lstrip", new PyMethodDescr("lstrip",
1136:                        PyString.class, 0, 1, new exposed_lstrip(null, null)));
1137:                class exposed_replace extends PyBuiltinMethodNarrow {
1138:
1139:                    exposed_replace(PyObject self, PyBuiltinFunction.Info info) {
1140:                        super (self, info);
1141:                    }
1142:
1143:                    public PyBuiltinFunction bind(PyObject self) {
1144:                        return new exposed_replace(self, info);
1145:                    }
1146:
1147:                    public PyObject __call__(PyObject arg0, PyObject arg1,
1148:                            PyObject arg2) {
1149:                        try {
1150:                            return ((PyString) self).str_replace(arg0, arg1,
1151:                                    arg2.asInt(2));
1152:                        } catch (PyObject.ConversionException e) {
1153:                            String msg;
1154:                            switch (e.index) {
1155:                            case 2:
1156:                                msg = "expected an integer";
1157:                                break;
1158:                            default:
1159:                                msg = "xxx";
1160:                            }
1161:                            throw Py.TypeError(msg);
1162:                        }
1163:                    }
1164:
1165:                    public PyObject __call__(PyObject arg0, PyObject arg1) {
1166:                        return ((PyString) self).str_replace(arg0, arg1);
1167:                    }
1168:
1169:                }
1170:                dict.__setitem__("replace", new PyMethodDescr("replace",
1171:                        PyString.class, 2, 3, new exposed_replace(null, null)));
1172:                class exposed_rfind extends PyBuiltinMethodNarrow {
1173:
1174:                    exposed_rfind(PyObject self, PyBuiltinFunction.Info info) {
1175:                        super (self, info);
1176:                    }
1177:
1178:                    public PyBuiltinFunction bind(PyObject self) {
1179:                        return new exposed_rfind(self, info);
1180:                    }
1181:
1182:                    public PyObject __call__(PyObject arg0, PyObject arg1,
1183:                            PyObject arg2) {
1184:                        try {
1185:                            return Py.newInteger(((PyString) self).str_rfind(
1186:                                    arg0.asString(0), arg1.asInt(1), arg2
1187:                                            .asInt(2)));
1188:                        } catch (PyObject.ConversionException e) {
1189:                            String msg;
1190:                            switch (e.index) {
1191:                            case 1:
1192:                            case 2:
1193:                                msg = "expected an integer";
1194:                                break;
1195:                            case 0:
1196:                                msg = "expected a string";
1197:                                break;
1198:                            default:
1199:                                msg = "xxx";
1200:                            }
1201:                            throw Py.TypeError(msg);
1202:                        }
1203:                    }
1204:
1205:                    public PyObject __call__(PyObject arg0, PyObject arg1) {
1206:                        try {
1207:                            return Py.newInteger(((PyString) self).str_rfind(
1208:                                    arg0.asString(0), arg1.asInt(1)));
1209:                        } catch (PyObject.ConversionException e) {
1210:                            String msg;
1211:                            switch (e.index) {
1212:                            case 1:
1213:                                msg = "expected an integer";
1214:                                break;
1215:                            case 0:
1216:                                msg = "expected a string";
1217:                                break;
1218:                            default:
1219:                                msg = "xxx";
1220:                            }
1221:                            throw Py.TypeError(msg);
1222:                        }
1223:                    }
1224:
1225:                    public PyObject __call__(PyObject arg0) {
1226:                        try {
1227:                            return Py.newInteger(((PyString) self)
1228:                                    .str_rfind(arg0.asString(0)));
1229:                        } catch (PyObject.ConversionException e) {
1230:                            String msg;
1231:                            switch (e.index) {
1232:                            case 0:
1233:                                msg = "expected a string";
1234:                                break;
1235:                            default:
1236:                                msg = "xxx";
1237:                            }
1238:                            throw Py.TypeError(msg);
1239:                        }
1240:                    }
1241:
1242:                }
1243:                dict.__setitem__("rfind", new PyMethodDescr("rfind",
1244:                        PyString.class, 1, 3, new exposed_rfind(null, null)));
1245:                class exposed_rindex extends PyBuiltinMethodNarrow {
1246:
1247:                    exposed_rindex(PyObject self, PyBuiltinFunction.Info info) {
1248:                        super (self, info);
1249:                    }
1250:
1251:                    public PyBuiltinFunction bind(PyObject self) {
1252:                        return new exposed_rindex(self, info);
1253:                    }
1254:
1255:                    public PyObject __call__(PyObject arg0, PyObject arg1,
1256:                            PyObject arg2) {
1257:                        try {
1258:                            return Py.newInteger(((PyString) self).str_rindex(
1259:                                    arg0.asString(0), arg1.asInt(1), arg2
1260:                                            .asInt(2)));
1261:                        } catch (PyObject.ConversionException e) {
1262:                            String msg;
1263:                            switch (e.index) {
1264:                            case 1:
1265:                            case 2:
1266:                                msg = "expected an integer";
1267:                                break;
1268:                            case 0:
1269:                                msg = "expected a string";
1270:                                break;
1271:                            default:
1272:                                msg = "xxx";
1273:                            }
1274:                            throw Py.TypeError(msg);
1275:                        }
1276:                    }
1277:
1278:                    public PyObject __call__(PyObject arg0, PyObject arg1) {
1279:                        try {
1280:                            return Py.newInteger(((PyString) self).str_rindex(
1281:                                    arg0.asString(0), arg1.asInt(1)));
1282:                        } catch (PyObject.ConversionException e) {
1283:                            String msg;
1284:                            switch (e.index) {
1285:                            case 1:
1286:                                msg = "expected an integer";
1287:                                break;
1288:                            case 0:
1289:                                msg = "expected a string";
1290:                                break;
1291:                            default:
1292:                                msg = "xxx";
1293:                            }
1294:                            throw Py.TypeError(msg);
1295:                        }
1296:                    }
1297:
1298:                    public PyObject __call__(PyObject arg0) {
1299:                        try {
1300:                            return Py.newInteger(((PyString) self)
1301:                                    .str_rindex(arg0.asString(0)));
1302:                        } catch (PyObject.ConversionException e) {
1303:                            String msg;
1304:                            switch (e.index) {
1305:                            case 0:
1306:                                msg = "expected a string";
1307:                                break;
1308:                            default:
1309:                                msg = "xxx";
1310:                            }
1311:                            throw Py.TypeError(msg);
1312:                        }
1313:                    }
1314:
1315:                }
1316:                dict.__setitem__("rindex", new PyMethodDescr("rindex",
1317:                        PyString.class, 1, 3, new exposed_rindex(null, null)));
1318:                class exposed_rjust extends PyBuiltinMethodNarrow {
1319:
1320:                    exposed_rjust(PyObject self, PyBuiltinFunction.Info info) {
1321:                        super (self, info);
1322:                    }
1323:
1324:                    public PyBuiltinFunction bind(PyObject self) {
1325:                        return new exposed_rjust(self, info);
1326:                    }
1327:
1328:                    public PyObject __call__(PyObject arg0) {
1329:                        try {
1330:                            return new PyString(((PyString) self)
1331:                                    .str_rjust(arg0.asInt(0)));
1332:                        } catch (PyObject.ConversionException e) {
1333:                            String msg;
1334:                            switch (e.index) {
1335:                            case 0:
1336:                                msg = "expected an integer";
1337:                                break;
1338:                            default:
1339:                                msg = "xxx";
1340:                            }
1341:                            throw Py.TypeError(msg);
1342:                        }
1343:                    }
1344:
1345:                }
1346:                dict.__setitem__("rjust", new PyMethodDescr("rjust",
1347:                        PyString.class, 1, 1, new exposed_rjust(null, null)));
1348:                class exposed_rstrip extends PyBuiltinMethodNarrow {
1349:
1350:                    exposed_rstrip(PyObject self, PyBuiltinFunction.Info info) {
1351:                        super (self, info);
1352:                    }
1353:
1354:                    public PyBuiltinFunction bind(PyObject self) {
1355:                        return new exposed_rstrip(self, info);
1356:                    }
1357:
1358:                    public PyObject __call__(PyObject arg0) {
1359:                        try {
1360:                            return new PyString(((PyString) self)
1361:                                    .str_rstrip(arg0.asStringOrNull(0)));
1362:                        } catch (PyObject.ConversionException e) {
1363:                            String msg;
1364:                            switch (e.index) {
1365:                            case 0:
1366:                                msg = "expected a string or None";
1367:                                break;
1368:                            default:
1369:                                msg = "xxx";
1370:                            }
1371:                            throw Py.TypeError(msg);
1372:                        }
1373:                    }
1374:
1375:                    public PyObject __call__() {
1376:                        return new PyString(((PyString) self).str_rstrip());
1377:                    }
1378:
1379:                }
1380:                dict.__setitem__("rstrip", new PyMethodDescr("rstrip",
1381:                        PyString.class, 0, 1, new exposed_rstrip(null, null)));
1382:                class exposed_split extends PyBuiltinMethodNarrow {
1383:
1384:                    exposed_split(PyObject self, PyBuiltinFunction.Info info) {
1385:                        super (self, info);
1386:                    }
1387:
1388:                    public PyBuiltinFunction bind(PyObject self) {
1389:                        return new exposed_split(self, info);
1390:                    }
1391:
1392:                    public PyObject __call__(PyObject arg0, PyObject arg1) {
1393:                        try {
1394:                            return ((PyString) self).str_split(arg0
1395:                                    .asStringOrNull(0), arg1.asInt(1));
1396:                        } catch (PyObject.ConversionException e) {
1397:                            String msg;
1398:                            switch (e.index) {
1399:                            case 1:
1400:                                msg = "expected an integer";
1401:                                break;
1402:                            case 0:
1403:                                msg = "expected a string or None";
1404:                                break;
1405:                            default:
1406:                                msg = "xxx";
1407:                            }
1408:                            throw Py.TypeError(msg);
1409:                        }
1410:                    }
1411:
1412:                    public PyObject __call__(PyObject arg0) {
1413:                        try {
1414:                            return ((PyString) self).str_split(arg0
1415:                                    .asStringOrNull(0));
1416:                        } catch (PyObject.ConversionException e) {
1417:                            String msg;
1418:                            switch (e.index) {
1419:                            case 0:
1420:                                msg = "expected a string or None";
1421:                                break;
1422:                            default:
1423:                                msg = "xxx";
1424:                            }
1425:                            throw Py.TypeError(msg);
1426:                        }
1427:                    }
1428:
1429:                    public PyObject __call__() {
1430:                        return ((PyString) self).str_split();
1431:                    }
1432:
1433:                }
1434:                dict.__setitem__("split", new PyMethodDescr("split",
1435:                        PyString.class, 0, 2, new exposed_split(null, null)));
1436:                class exposed_splitlines extends PyBuiltinMethodNarrow {
1437:
1438:                    exposed_splitlines(PyObject self,
1439:                            PyBuiltinFunction.Info info) {
1440:                        super (self, info);
1441:                    }
1442:
1443:                    public PyBuiltinFunction bind(PyObject self) {
1444:                        return new exposed_splitlines(self, info);
1445:                    }
1446:
1447:                    public PyObject __call__(PyObject arg0) {
1448:                        return ((PyString) self).str_splitlines(arg0
1449:                                .__nonzero__());
1450:                    }
1451:
1452:                    public PyObject __call__() {
1453:                        return ((PyString) self).str_splitlines();
1454:                    }
1455:
1456:                }
1457:                dict.__setitem__("splitlines", new PyMethodDescr("splitlines",
1458:                        PyString.class, 0, 1,
1459:                        new exposed_splitlines(null, null)));
1460:                class exposed_startswith extends PyBuiltinMethodNarrow {
1461:
1462:                    exposed_startswith(PyObject self,
1463:                            PyBuiltinFunction.Info info) {
1464:                        super (self, info);
1465:                    }
1466:
1467:                    public PyBuiltinFunction bind(PyObject self) {
1468:                        return new exposed_startswith(self, info);
1469:                    }
1470:
1471:                    public PyObject __call__(PyObject arg0, PyObject arg1,
1472:                            PyObject arg2) {
1473:                        try {
1474:                            return Py.newBoolean(((PyString) self)
1475:                                    .str_startswith(arg0.asString(0), arg1
1476:                                            .asInt(1), arg2.asInt(2)));
1477:                        } catch (PyObject.ConversionException e) {
1478:                            String msg;
1479:                            switch (e.index) {
1480:                            case 1:
1481:                            case 2:
1482:                                msg = "expected an integer";
1483:                                break;
1484:                            case 0:
1485:                                msg = "expected a string";
1486:                                break;
1487:                            default:
1488:                                msg = "xxx";
1489:                            }
1490:                            throw Py.TypeError(msg);
1491:                        }
1492:                    }
1493:
1494:                    public PyObject __call__(PyObject arg0, PyObject arg1) {
1495:                        try {
1496:                            return Py.newBoolean(((PyString) self)
1497:                                    .str_startswith(arg0.asString(0), arg1
1498:                                            .asInt(1)));
1499:                        } catch (PyObject.ConversionException e) {
1500:                            String msg;
1501:                            switch (e.index) {
1502:                            case 1:
1503:                                msg = "expected an integer";
1504:                                break;
1505:                            case 0:
1506:                                msg = "expected a string";
1507:                                break;
1508:                            default:
1509:                                msg = "xxx";
1510:                            }
1511:                            throw Py.TypeError(msg);
1512:                        }
1513:                    }
1514:
1515:                    public PyObject __call__(PyObject arg0) {
1516:                        try {
1517:                            return Py.newBoolean(((PyString) self)
1518:                                    .str_startswith(arg0.asString(0)));
1519:                        } catch (PyObject.ConversionException e) {
1520:                            String msg;
1521:                            switch (e.index) {
1522:                            case 0:
1523:                                msg = "expected a string";
1524:                                break;
1525:                            default:
1526:                                msg = "xxx";
1527:                            }
1528:                            throw Py.TypeError(msg);
1529:                        }
1530:                    }
1531:
1532:                }
1533:                dict.__setitem__("startswith", new PyMethodDescr("startswith",
1534:                        PyString.class, 1, 3,
1535:                        new exposed_startswith(null, null)));
1536:                class exposed_strip extends PyBuiltinMethodNarrow {
1537:
1538:                    exposed_strip(PyObject self, PyBuiltinFunction.Info info) {
1539:                        super (self, info);
1540:                    }
1541:
1542:                    public PyBuiltinFunction bind(PyObject self) {
1543:                        return new exposed_strip(self, info);
1544:                    }
1545:
1546:                    public PyObject __call__(PyObject arg0) {
1547:                        try {
1548:                            return new PyString(((PyString) self)
1549:                                    .str_strip(arg0.asStringOrNull(0)));
1550:                        } catch (PyObject.ConversionException e) {
1551:                            String msg;
1552:                            switch (e.index) {
1553:                            case 0:
1554:                                msg = "expected a string or None";
1555:                                break;
1556:                            default:
1557:                                msg = "xxx";
1558:                            }
1559:                            throw Py.TypeError(msg);
1560:                        }
1561:                    }
1562:
1563:                    public PyObject __call__() {
1564:                        return new PyString(((PyString) self).str_strip());
1565:                    }
1566:
1567:                }
1568:                dict.__setitem__("strip", new PyMethodDescr("strip",
1569:                        PyString.class, 0, 1, new exposed_strip(null, null)));
1570:                class exposed_swapcase extends PyBuiltinMethodNarrow {
1571:
1572:                    exposed_swapcase(PyObject self, PyBuiltinFunction.Info info) {
1573:                        super (self, info);
1574:                    }
1575:
1576:                    public PyBuiltinFunction bind(PyObject self) {
1577:                        return new exposed_swapcase(self, info);
1578:                    }
1579:
1580:                    public PyObject __call__() {
1581:                        return new PyString(((PyString) self).str_swapcase());
1582:                    }
1583:
1584:                }
1585:                dict
1586:                        .__setitem__("swapcase", new PyMethodDescr("swapcase",
1587:                                PyString.class, 0, 0, new exposed_swapcase(
1588:                                        null, null)));
1589:                class exposed_title extends PyBuiltinMethodNarrow {
1590:
1591:                    exposed_title(PyObject self, PyBuiltinFunction.Info info) {
1592:                        super (self, info);
1593:                    }
1594:
1595:                    public PyBuiltinFunction bind(PyObject self) {
1596:                        return new exposed_title(self, info);
1597:                    }
1598:
1599:                    public PyObject __call__() {
1600:                        return new PyString(((PyString) self).str_title());
1601:                    }
1602:
1603:                }
1604:                dict.__setitem__("title", new PyMethodDescr("title",
1605:                        PyString.class, 0, 0, new exposed_title(null, null)));
1606:                class exposed_translate extends PyBuiltinMethodNarrow {
1607:
1608:                    exposed_translate(PyObject self, PyBuiltinFunction.Info info) {
1609:                        super (self, info);
1610:                    }
1611:
1612:                    public PyBuiltinFunction bind(PyObject self) {
1613:                        return new exposed_translate(self, info);
1614:                    }
1615:
1616:                    public PyObject __call__(PyObject arg0, PyObject arg1) {
1617:                        try {
1618:                            return new PyString(((PyString) self)
1619:                                    .str_translate(arg0.asString(0), arg1
1620:                                            .asString(1)));
1621:                        } catch (PyObject.ConversionException e) {
1622:                            String msg;
1623:                            switch (e.index) {
1624:                            case 0:
1625:                            case 1:
1626:                                msg = "expected a string";
1627:                                break;
1628:                            default:
1629:                                msg = "xxx";
1630:                            }
1631:                            throw Py.TypeError(msg);
1632:                        }
1633:                    }
1634:
1635:                    public PyObject __call__(PyObject arg0) {
1636:                        try {
1637:                            return new PyString(((PyString) self)
1638:                                    .str_translate(arg0.asString(0)));
1639:                        } catch (PyObject.ConversionException e) {
1640:                            String msg;
1641:                            switch (e.index) {
1642:                            case 0:
1643:                                msg = "expected a string";
1644:                                break;
1645:                            default:
1646:                                msg = "xxx";
1647:                            }
1648:                            throw Py.TypeError(msg);
1649:                        }
1650:                    }
1651:
1652:                }
1653:                dict.__setitem__("translate",
1654:                        new PyMethodDescr("translate", PyString.class, 1, 2,
1655:                                new exposed_translate(null, null)));
1656:                class exposed_upper extends PyBuiltinMethodNarrow {
1657:
1658:                    exposed_upper(PyObject self, PyBuiltinFunction.Info info) {
1659:                        super (self, info);
1660:                    }
1661:
1662:                    public PyBuiltinFunction bind(PyObject self) {
1663:                        return new exposed_upper(self, info);
1664:                    }
1665:
1666:                    public PyObject __call__() {
1667:                        return new PyString(((PyString) self).str_upper());
1668:                    }
1669:
1670:                }
1671:                dict.__setitem__("upper", new PyMethodDescr("upper",
1672:                        PyString.class, 0, 0, new exposed_upper(null, null)));
1673:                class exposed_zfill extends PyBuiltinMethodNarrow {
1674:
1675:                    exposed_zfill(PyObject self, PyBuiltinFunction.Info info) {
1676:                        super (self, info);
1677:                    }
1678:
1679:                    public PyBuiltinFunction bind(PyObject self) {
1680:                        return new exposed_zfill(self, info);
1681:                    }
1682:
1683:                    public PyObject __call__(PyObject arg0) {
1684:                        try {
1685:                            return new PyString(((PyString) self)
1686:                                    .str_zfill(arg0.asInt(0)));
1687:                        } catch (PyObject.ConversionException e) {
1688:                            String msg;
1689:                            switch (e.index) {
1690:                            case 0:
1691:                                msg = "expected an integer";
1692:                                break;
1693:                            default:
1694:                                msg = "xxx";
1695:                            }
1696:                            throw Py.TypeError(msg);
1697:                        }
1698:                    }
1699:
1700:                }
1701:                dict.__setitem__("zfill", new PyMethodDescr("zfill",
1702:                        PyString.class, 1, 1, new exposed_zfill(null, null)));
1703:                dict.__setitem__("__new__", new PyNewWrapper(PyString.class,
1704:                        "__new__", -1, -1) {
1705:
1706:                    public PyObject new_impl(boolean init, PyType subtype,
1707:                            PyObject[] args, String[] keywords) {
1708:                        return str_new(this , init, subtype, args, keywords);
1709:                    }
1710:
1711:                });
1712:            }
1713:
1714:            //~ END GENERATED REGION -- DO NOT EDIT SEE gexpose.py
1715:
1716:            private static final PyType STRTYPE = PyType
1717:                    .fromClass(PyString.class);
1718:
1719:            protected String string;
1720:            private transient int cached_hashcode = 0;
1721:            private transient boolean interned = false;
1722:
1723:            // for PyJavaClass.init()
1724:            public PyString() {
1725:                this (STRTYPE, "");
1726:            }
1727:
1728:            public PyString(PyType subType, String string) {
1729:                super (subType);
1730:                if (string == null) {
1731:                    throw new IllegalArgumentException(
1732:                            "Cannot create PyString from null!");
1733:                }
1734:                this .string = string;
1735:            }
1736:
1737:            public PyString(String string) {
1738:                this (STRTYPE, string);
1739:            }
1740:
1741:            public PyString(char c) {
1742:                this (STRTYPE, String.valueOf(c));
1743:            }
1744:
1745:            final static PyObject str_new(PyNewWrapper new_, boolean init,
1746:                    PyType subtype, PyObject[] args, String[] keywords) {
1747:                ArgParser ap = new ArgParser("str", args, keywords,
1748:                        new String[] { "object" }, 0);
1749:                PyObject S = ap.getPyObject(0, null);
1750:                if (new_.for_type == subtype) {
1751:                    if (S == null) {
1752:                        return new PyString("");
1753:                    }
1754:                    return S.__str__();
1755:                } else {
1756:                    if (S == null) {
1757:                        return new PyStringDerived(subtype, "");
1758:                    }
1759:                    return new PyStringDerived(subtype, S.__str__().toString());
1760:                }
1761:            }
1762:
1763:            /** <i>Internal use only. Do not call this method explicit.</i> */
1764:            public static void classDictInit(PyObject dict)
1765:                    throws PyIgnoreMethodTag {
1766:            }
1767:
1768:            public String safeRepr() throws PyIgnoreMethodTag {
1769:                return "'string' object";
1770:            }
1771:
1772:            public PyString __str__() {
1773:                return str___str__();
1774:            }
1775:
1776:            final PyString str___str__() {
1777:                return this ;
1778:            }
1779:
1780:            public PyUnicode __unicode__() {
1781:                return str___unicode__();
1782:            }
1783:
1784:            final PyUnicode str___unicode__() {
1785:                return new PyUnicode(this .toString());
1786:            }
1787:
1788:            public int __len__() {
1789:                return str___len__();
1790:            }
1791:
1792:            final int str___len__() {
1793:                return string.length();
1794:            }
1795:
1796:            public String toString() {
1797:                return str_toString();
1798:            }
1799:
1800:            final String str_toString() {
1801:                return string;
1802:            }
1803:
1804:            public String internedString() {
1805:                if (interned)
1806:                    return string;
1807:                else {
1808:                    string = string.intern();
1809:                    interned = true;
1810:                    return string;
1811:                }
1812:            }
1813:
1814:            public PyString __repr__() {
1815:                return new PyString(encode_UnicodeEscape(string, true));
1816:            }
1817:
1818:            private static char[] hexdigit = "0123456789ABCDEF".toCharArray();
1819:
1820:            public static String encode_UnicodeEscape(String str,
1821:                    boolean use_quotes) {
1822:                return encode_UnicodeEscape(str, use_quotes, false);
1823:            }
1824:
1825:            public static String encode_UnicodeEscape(String str,
1826:                    boolean use_quotes, boolean unicodeDesignatorPresent) {
1827:                int size = str.length();
1828:                StringBuffer v = new StringBuffer(str.length());
1829:
1830:                char quote = 0;
1831:
1832:                if (use_quotes) {
1833:                    quote = str.indexOf('\'') >= 0 && str.indexOf('"') == -1 ? '"'
1834:                            : '\'';
1835:                    v.append(quote);
1836:                }
1837:
1838:                for (int i = 0; size-- > 0;) {
1839:                    int ch = str.charAt(i++);
1840:                    /* Escape quotes */
1841:                    if (use_quotes && (ch == quote || ch == '\\')) {
1842:                        v.append('\\');
1843:                        v.append((char) ch);
1844:                    }
1845:                    /* Map 16-bit characters to '\\uxxxx' */
1846:                    else if (ch >= 256) {
1847:                        if (use_quotes && !unicodeDesignatorPresent) {
1848:                            v.insert(0, 'u');
1849:                            unicodeDesignatorPresent = true;
1850:                        }
1851:                        v.append('\\');
1852:                        v.append('u');
1853:                        v.append(hexdigit[(ch >> 12) & 0xf]);
1854:                        v.append(hexdigit[(ch >> 8) & 0xf]);
1855:                        v.append(hexdigit[(ch >> 4) & 0xf]);
1856:                        v.append(hexdigit[ch & 15]);
1857:                    }
1858:                    /* Map non-printable US ASCII to '\ooo' */
1859:                    else if (use_quotes && ch == '\n')
1860:                        v.append("\\n");
1861:                    else if (use_quotes && ch == '\t')
1862:                        v.append("\\t");
1863:                    else if (use_quotes && ch == '\b')
1864:                        v.append("\\b");
1865:                    else if (use_quotes && ch == '\f')
1866:                        v.append("\\f");
1867:                    else if (use_quotes && ch == '\r')
1868:                        v.append("\\r");
1869:                    else if (ch < ' ' || ch >= 127) {
1870:                        v.append("\\x");
1871:                        v.append(hexdigit[(ch >> 4) & 0xF]);
1872:                        v.append(hexdigit[ch & 0xF]);
1873:                    }
1874:                    /* Copy everything else as-is */
1875:                    else
1876:                        v.append((char) ch);
1877:                }
1878:                if (use_quotes)
1879:                    v.append(quote);
1880:                return v.toString();
1881:            }
1882:
1883:            private static ucnhashAPI pucnHash = null;
1884:
1885:            public static String decode_UnicodeEscape(String str, int start,
1886:                    int end, String errors, boolean unicode) {
1887:                StringBuffer v = new StringBuffer(end - start);
1888:                for (int s = start; s < end;) {
1889:                    char ch = str.charAt(s);
1890:
1891:                    /* Non-escape characters are interpreted as Unicode ordinals */
1892:                    if (ch != '\\') {
1893:                        v.append(ch);
1894:                        s++;
1895:                        continue;
1896:                    }
1897:
1898:                    /* \ - Escapes */
1899:                    s++;
1900:                    if (s == end) {
1901:                        codecs.decoding_error("unicode escape", v, errors,
1902:                                "\\ at end of string");
1903:                        break;
1904:                    }
1905:                    ch = str.charAt(s++);
1906:                    switch (ch) {
1907:
1908:                    /* \x escapes */
1909:                    case '\n':
1910:                        break;
1911:                    case '\\':
1912:                        v.append('\\');
1913:                        break;
1914:                    case '\'':
1915:                        v.append('\'');
1916:                        break;
1917:                    case '\"':
1918:                        v.append('\"');
1919:                        break;
1920:                    case 'b':
1921:                        v.append('\b');
1922:                        break;
1923:                    case 'f':
1924:                        v.append('\014');
1925:                        break; /* FF */
1926:                    case 't':
1927:                        v.append('\t');
1928:                        break;
1929:                    case 'n':
1930:                        v.append('\n');
1931:                        break;
1932:                    case 'r':
1933:                        v.append('\r');
1934:                        break;
1935:                    case 'v':
1936:                        v.append('\013');
1937:                        break; /* VT */
1938:                    case 'a':
1939:                        v.append('\007');
1940:                        break; /* BEL, not classic C */
1941:
1942:                    /* \OOO (octal) escapes */
1943:                    case '0':
1944:                    case '1':
1945:                    case '2':
1946:                    case '3':
1947:                    case '4':
1948:                    case '5':
1949:                    case '6':
1950:                    case '7':
1951:
1952:                        int x = Character.digit(ch, 8);
1953:                        for (int j = 0; j < 2 && s < end; j++, s++) {
1954:                            ch = str.charAt(s);
1955:                            if (ch < '0' || ch > '7')
1956:                                break;
1957:                            x = (x << 3) + Character.digit(ch, 8);
1958:                        }
1959:                        v.append((char) x);
1960:                        break;
1961:
1962:                    case 'x':
1963:                        int i;
1964:                        for (x = 0, i = 0; i < 2 && s < end; i++) {
1965:                            ch = str.charAt(s + i);
1966:                            int d = Character.digit(ch, 16);
1967:                            if (d == -1) {
1968:                                codecs.decoding_error("unicode escape", v,
1969:                                        errors, "truncated \\xXX");
1970:                                i++;
1971:                                break;
1972:                            }
1973:
1974:                            x = ((x << 4) & ~0xF) + d;
1975:                        }
1976:                        s += i;
1977:                        v.append((char) x);
1978:                        break;
1979:
1980:                    /* \ uXXXX with 4 hex digits */
1981:                    case 'u':
1982:                        if (!unicode) {
1983:                            v.append('\\');
1984:                            v.append('u');
1985:                            break;
1986:                        }
1987:                        if (s + 4 > end) {
1988:                            codecs.decoding_error("unicode escape", v, errors,
1989:                                    "truncated \\uXXXX");
1990:                            break;
1991:                        }
1992:                        for (x = 0, i = 0; i < 4; i++) {
1993:                            ch = str.charAt(s + i);
1994:                            int d = Character.digit(ch, 16);
1995:                            if (d == -1) {
1996:                                codecs.decoding_error("unicode escape", v,
1997:                                        errors, "truncated \\uXXXX");
1998:                                break;
1999:                            }
2000:                            x = ((x << 4) & ~0xF) + d;
2001:                        }
2002:                        s += i;
2003:                        v.append((char) x);
2004:                        break;
2005:
2006:                    case 'N':
2007:                        if (!unicode) {
2008:                            v.append('\\');
2009:                            v.append('N');
2010:                            break;
2011:                        }
2012:                        /* Ok, we need to deal with Unicode Character Names now,
2013:                         * make sure we've imported the hash table data...
2014:                         */
2015:                        if (pucnHash == null) {
2016:                            PyObject mod = imp.importName("ucnhash", true);
2017:                            mod = mod.__call__();
2018:                            pucnHash = (ucnhashAPI) mod
2019:                                    .__tojava__(Object.class);
2020:                            if (pucnHash.getCchMax() < 0)
2021:                                codecs.decoding_error("unicode escape", v,
2022:                                        errors, "Unicode names not loaded");
2023:                        }
2024:
2025:                        if (str.charAt(s) == '{') {
2026:                            int startName = s + 1;
2027:                            int endBrace = startName;
2028:
2029:                            /* look for either the closing brace, or we
2030:                             * exceed the maximum length of the unicode
2031:                             * character names
2032:                             */
2033:                            int maxLen = pucnHash.getCchMax();
2034:                            while (endBrace < end
2035:                                    && str.charAt(endBrace) != '}'
2036:                                    && (endBrace - startName) <= maxLen) {
2037:                                endBrace++;
2038:                            }
2039:                            if (endBrace != end && str.charAt(endBrace) == '}') {
2040:                                int value = pucnHash.getValue(str, startName,
2041:                                        endBrace);
2042:                                if (value < 0) {
2043:                                    codecs.decoding_error("unicode escape", v,
2044:                                            errors,
2045:                                            "Invalid Unicode Character Name");
2046:                                } else {
2047:
2048:                                    if (value < 1 << 16) {
2049:                                        /* In UCS-2 range, easy solution.. */
2050:                                        v.append((char) value);
2051:                                    } else {
2052:                                        /* Oops, its in UCS-4 space, */
2053:                                        /* compute and append the two surrogates: */
2054:                                        /* translate from 10000..10FFFF to 0..FFFFF */
2055:                                        value -= 0x10000;
2056:
2057:                                        /* high surrogate = top 10 bits added to D800 */
2058:                                        v
2059:                                                .append((char) (0xD800 + (value >> 10)));
2060:
2061:                                        /* low surrogate = bottom 10 bits added to DC00 */
2062:                                        v
2063:                                                .append((char) (0xDC00 + (value & ~0xFC00)));
2064:                                    }
2065:                                }
2066:                                s = endBrace + 1;
2067:                                break;
2068:                            } else {
2069:                                codecs.decoding_error("unicode escape", v,
2070:                                        errors,
2071:                                        "Unicode name missing closing brace");
2072:                            }
2073:                        } else {
2074:                            codecs.decoding_error("unicode escape", v, errors,
2075:                                    "Missing opening brace for Unicode "
2076:                                            + "Character Name escape");
2077:                        }
2078:                        break;
2079:
2080:                    default:
2081:                        v.append('\\');
2082:                        v.append(str.charAt(s - 1));
2083:                        break;
2084:                    }
2085:                }
2086:                return v.toString();
2087:            }
2088:
2089:            public boolean equals(Object other) {
2090:                if (!(other instanceof  PyString))
2091:                    return false;
2092:
2093:                PyString o = (PyString) other;
2094:                if (interned && o.interned)
2095:                    return string == o.string;
2096:
2097:                return string.equals(o.string);
2098:            }
2099:
2100:            public int __cmp__(PyObject other) {
2101:                return str___cmp__(other);
2102:            }
2103:
2104:            final int str___cmp__(PyObject other) {
2105:                if (!(other instanceof  PyString))
2106:                    return -2;
2107:
2108:                int c = string.compareTo(((PyString) other).string);
2109:                return c < 0 ? -1 : c > 0 ? 1 : 0;
2110:            }
2111:
2112:            public PyObject __eq__(PyObject other) {
2113:                return str___eq__(other);
2114:            }
2115:
2116:            final PyObject str___eq__(PyObject other) {
2117:                String s = coerce(other);
2118:                if (s == null)
2119:                    return null;
2120:                return string.equals(s) ? Py.One : Py.Zero;
2121:            }
2122:
2123:            public PyObject __ne__(PyObject other) {
2124:                return str___ne__(other);
2125:            }
2126:
2127:            final PyObject str___ne__(PyObject other) {
2128:                String s = coerce(other);
2129:                if (s == null)
2130:                    return null;
2131:                return string.equals(s) ? Py.Zero : Py.One;
2132:            }
2133:
2134:            public PyObject __lt__(PyObject other) {
2135:                String s = coerce(other);
2136:                if (s == null)
2137:                    return null;
2138:                return string.compareTo(s) < 0 ? Py.One : Py.Zero;
2139:            }
2140:
2141:            final PyObject str___lt__(PyObject other) {
2142:                return __lt__(other);
2143:            }
2144:
2145:            public PyObject __le__(PyObject other) {
2146:                String s = coerce(other);
2147:                if (s == null)
2148:                    return null;
2149:                return string.compareTo(s) <= 0 ? Py.One : Py.Zero;
2150:            }
2151:
2152:            final PyObject str___le__(PyObject other) {
2153:                return __le__(other);
2154:            }
2155:
2156:            public PyObject __gt__(PyObject other) {
2157:                String s = coerce(other);
2158:                if (s == null)
2159:                    return null;
2160:                return string.compareTo(s) > 0 ? Py.One : Py.Zero;
2161:            }
2162:
2163:            final PyObject str___gt__(PyObject other) {
2164:                return __gt__(other);
2165:            }
2166:
2167:            public PyObject __ge__(PyObject other) {
2168:                String s = coerce(other);
2169:                if (s == null)
2170:                    return null;
2171:                return string.compareTo(s) >= 0 ? Py.One : Py.Zero;
2172:            }
2173:
2174:            final PyObject str___ge__(PyObject other) {
2175:                return __ge__(other);
2176:            }
2177:
2178:            private static String coerce(PyObject o) {
2179:                if (o instanceof  PyString)
2180:                    return o.toString();
2181:                return null;
2182:            }
2183:
2184:            public int hashCode() {
2185:                return str_hashCode();
2186:            }
2187:
2188:            final int str_hashCode() {
2189:                if (cached_hashcode == 0)
2190:                    cached_hashcode = string.hashCode();
2191:                return cached_hashcode;
2192:            }
2193:
2194:            private byte[] getBytes() {
2195:                return to_bytes(string);
2196:            }
2197:
2198:            public static byte[] to_bytes(String s) {
2199:                byte[] bytes = new byte[s.length()];
2200:                for (int i = 0; i < bytes.length; i++) {
2201:                    char c = s.charAt(i);
2202:                    if (c < 256) {
2203:                        bytes[i] = (byte) c;
2204:                    } else {
2205:                        throw Py
2206:                                .ValueError("Strings added to sha hashes must not contain characters with value > 255");
2207:                    }
2208:                }
2209:                return bytes;
2210:            }
2211:
2212:            public Object __tojava__(Class c) {
2213:                if (c.isAssignableFrom(String.class)) {
2214:                    return string;
2215:                }
2216:
2217:                if (c == Character.TYPE || c == Character.class)
2218:                    if (string.length() == 1)
2219:                        return new Character(string.charAt(0));
2220:
2221:                if (c.isArray()) {
2222:                    if (c.getComponentType() == Byte.TYPE)
2223:                        return getBytes();
2224:                    if (c.getComponentType() == Character.TYPE)
2225:                        return string.toCharArray();
2226:                }
2227:
2228:                if (c.isInstance(this ))
2229:                    return this ;
2230:
2231:                return Py.NoConversion;
2232:            }
2233:
2234:            protected PyObject pyget(int i) {
2235:                return Py.newString(string.charAt(i));
2236:            }
2237:
2238:            protected PyObject getslice(int start, int stop, int step) {
2239:                if (step > 0 && stop < start)
2240:                    stop = start;
2241:                if (step == 1)
2242:                    return fromSubstring(start, stop);
2243:                else {
2244:                    int n = sliceLength(start, stop, step);
2245:                    char new_chars[] = new char[n];
2246:                    int j = 0;
2247:                    for (int i = start; j < n; i += step)
2248:                        new_chars[j++] = string.charAt(i);
2249:
2250:                    return createInstance(new String(new_chars));
2251:                }
2252:            }
2253:
2254:            public PyString createInstance(String str) {
2255:                return new PyString(str);
2256:            }
2257:
2258:            public boolean __contains__(PyObject o) {
2259:                return str___contains__(o);
2260:            }
2261:
2262:            final boolean str___contains__(PyObject o) {
2263:                if (!(o instanceof  PyString))
2264:                    throw Py
2265:                            .TypeError("'in <string>' requires string as left operand");
2266:                PyString other = (PyString) o;
2267:                return string.indexOf(other.string) >= 0;
2268:            }
2269:
2270:            protected PyObject repeat(int count) {
2271:                if (count < 0)
2272:                    count = 0;
2273:                int s = string.length();
2274:                char new_chars[] = new char[s * count];
2275:                for (int i = 0; i < count; i++) {
2276:                    string.getChars(0, s, new_chars, i * s);
2277:                }
2278:                return createInstance(new String(new_chars));
2279:            }
2280:
2281:            final PyObject str___mul__(PyObject o) {
2282:                if (!(o instanceof  PyInteger || o instanceof  PyLong))
2283:                    throw Py.TypeError("can't multiply sequence to non-int");
2284:                int count = ((PyInteger) o.__int__()).getValue();
2285:                return repeat(count);
2286:            }
2287:
2288:            final PyObject str___rmul__(PyObject o) {
2289:                if (!(o instanceof  PyInteger || o instanceof  PyLong))
2290:                    throw Py.TypeError("can't multiply sequence to non-int");
2291:                int count = ((PyInteger) o.__int__()).getValue();
2292:                return repeat(count);
2293:            }
2294:
2295:            public PyObject __add__(PyObject generic_other) {
2296:                return str___add__(generic_other);
2297:            }
2298:
2299:            final PyObject str___add__(PyObject generic_other) {
2300:                if (generic_other instanceof  PyString) {
2301:                    PyString other = (PyString) generic_other;
2302:                    String result = string.concat(other.string);
2303:                    if (generic_other instanceof  PyUnicode) {
2304:                        return new PyUnicode(result);
2305:                    }
2306:                    return createInstance(result);
2307:                } else
2308:                    return null;
2309:            }
2310:
2311:            /**
2312:             * Used for pickling.
2313:             *
2314:             * @return a tuple of (class, tuple)
2315:             */
2316:            public PyObject __reduce__() {
2317:                return str___reduce__();
2318:            }
2319:
2320:            final PyObject str___reduce__() {
2321:                return object___reduce__();
2322:            }
2323:
2324:            public PyTuple __getnewargs__() {
2325:                return new PyTuple(
2326:                        new PyObject[] { new PyString(str_toString()) });
2327:            }
2328:
2329:            public PyObject __mod__(PyObject other) {
2330:                return str___mod__(other);
2331:            }
2332:
2333:            public PyObject str___mod__(PyObject other) {
2334:                StringFormatter fmt = new StringFormatter(string);
2335:                return fmt.format(other);
2336:            }
2337:
2338:            public PyObject __int__() {
2339:                return Py.newInteger(atoi(10));
2340:            }
2341:
2342:            public PyLong __long__() {
2343:                return atol(10);
2344:            }
2345:
2346:            public PyFloat __float__() {
2347:                return new PyFloat(atof());
2348:            }
2349:
2350:            public PyObject __pos__() {
2351:                throw Py.TypeError("bad operand type for unary +");
2352:            }
2353:
2354:            public PyObject __neg__() {
2355:                throw Py.TypeError("bad operand type for unary -");
2356:            }
2357:
2358:            public PyObject __invert__() {
2359:                throw Py.TypeError("bad operand type for unary ~");
2360:            }
2361:
2362:            public PyComplex __complex__() {
2363:                boolean got_re = false;
2364:                boolean got_im = false;
2365:                boolean done = false;
2366:                boolean sw_error = false;
2367:
2368:                int s = 0;
2369:                int n = string.length();
2370:                while (s < n && Character.isSpaceChar(string.charAt(s)))
2371:                    s++;
2372:
2373:                if (s == n) {
2374:                    throw Py.ValueError("empty string for complex()");
2375:                }
2376:
2377:                double z = -1.0;
2378:                double x = 0.0;
2379:                double y = 0.0;
2380:
2381:                int sign = 1;
2382:                do {
2383:                    char c = string.charAt(s);
2384:                    switch (c) {
2385:                    case '-':
2386:                        sign = -1;
2387:                        /* Fallthrough */
2388:                    case '+':
2389:                        if (done || s + 1 == n) {
2390:                            sw_error = true;
2391:                            break;
2392:                        }
2393:                        //  a character is guaranteed, but it better be a digit
2394:                        //  or J or j
2395:                        c = string.charAt(++s); //  eat the sign character
2396:                        //  and check the next
2397:                        if (!Character.isDigit(c) && c != 'J' && c != 'j')
2398:                            sw_error = true;
2399:                        break;
2400:
2401:                    case 'J':
2402:                    case 'j':
2403:                        if (got_im || done) {
2404:                            sw_error = true;
2405:                            break;
2406:                        }
2407:                        if (z < 0.0) {
2408:                            y = sign;
2409:                        } else {
2410:                            y = sign * z;
2411:                        }
2412:                        got_im = true;
2413:                        done = got_re;
2414:                        sign = 1;
2415:                        s++; // eat the J or j
2416:                        break;
2417:
2418:                    case ' ':
2419:                        while (s < n && Character.isSpaceChar(string.charAt(s)))
2420:                            s++;
2421:                        if (s != n)
2422:                            sw_error = true;
2423:                        break;
2424:
2425:                    default:
2426:                        boolean digit_or_dot = (c == '.' || Character
2427:                                .isDigit(c));
2428:                        if (!digit_or_dot) {
2429:                            sw_error = true;
2430:                            break;
2431:                        }
2432:                        int end = endDouble(string, s);
2433:                        z = Double.valueOf(string.substring(s, end))
2434:                                .doubleValue();
2435:                        s = end;
2436:                        if (s < n) {
2437:                            c = string.charAt(s);
2438:                            if (c == 'J' || c == 'j') {
2439:                                break;
2440:                            }
2441:                        }
2442:                        if (got_re) {
2443:                            sw_error = true;
2444:                            break;
2445:                        }
2446:
2447:                        /* accept a real part */
2448:                        x = sign * z;
2449:                        got_re = true;
2450:                        done = got_im;
2451:                        z = -1.0;
2452:                        sign = 1;
2453:                        break;
2454:
2455:                    } /* end of switch  */
2456:
2457:                } while (s < n && !sw_error);
2458:
2459:                if (sw_error) {
2460:                    throw Py.ValueError("malformed string for complex() "
2461:                            + string.substring(s));
2462:                }
2463:
2464:                return new PyComplex(x, y);
2465:            }
2466:
2467:            private int endDouble(String string, int s) {
2468:                int n = string.length();
2469:                while (s < n) {
2470:                    char c = string.charAt(s++);
2471:                    if (Character.isDigit(c))
2472:                        continue;
2473:                    if (c == '.')
2474:                        continue;
2475:                    if (c == 'e' || c == 'E') {
2476:                        if (s < n) {
2477:                            c = string.charAt(s);
2478:                            if (c == '+' || c == '-')
2479:                                s++;
2480:                            continue;
2481:                        }
2482:                    }
2483:                    return s - 1;
2484:                }
2485:                return s;
2486:            }
2487:
2488:            // Add in methods from string module
2489:            public String lower() {
2490:                return str_lower();
2491:            }
2492:
2493:            final String str_lower() {
2494:                return string.toLowerCase();
2495:            }
2496:
2497:            public String upper() {
2498:                return str_upper();
2499:            }
2500:
2501:            final String str_upper() {
2502:                return string.toUpperCase();
2503:            }
2504:
2505:            public String title() {
2506:                return str_title();
2507:            }
2508:
2509:            final String str_title() {
2510:                char[] chars = string.toCharArray();
2511:                int n = chars.length;
2512:
2513:                boolean previous_is_cased = false;
2514:                for (int i = 0; i < n; i++) {
2515:                    char ch = chars[i];
2516:                    if (previous_is_cased)
2517:                        chars[i] = Character.toLowerCase(ch);
2518:                    else
2519:                        chars[i] = Character.toTitleCase(ch);
2520:
2521:                    if (Character.isLowerCase(ch) || Character.isUpperCase(ch)
2522:                            || Character.isTitleCase(ch))
2523:                        previous_is_cased = true;
2524:                    else
2525:                        previous_is_cased = false;
2526:                }
2527:                return new String(chars);
2528:            }
2529:
2530:            public String swapcase() {
2531:                return str_swapcase();
2532:            }
2533:
2534:            final String str_swapcase() {
2535:                char[] chars = string.toCharArray();
2536:                int n = chars.length;
2537:                for (int i = 0; i < n; i++) {
2538:                    char c = chars[i];
2539:                    if (Character.isUpperCase(c)) {
2540:                        chars[i] = Character.toLowerCase(c);
2541:                    } else if (Character.isLowerCase(c)) {
2542:                        chars[i] = Character.toUpperCase(c);
2543:                    }
2544:                }
2545:                return new String(chars);
2546:            }
2547:
2548:            public String strip() {
2549:                return str_strip();
2550:            }
2551:
2552:            final String str_strip() {
2553:                return str_strip(null);
2554:            }
2555:
2556:            public String strip(String sep) {
2557:                return str_strip(sep);
2558:            }
2559:
2560:            final String str_strip(String sep) {
2561:                char[] chars = string.toCharArray();
2562:                int n = chars.length;
2563:                int start = 0;
2564:                if (sep == null)
2565:                    while (start < n && Character.isWhitespace(chars[start]))
2566:                        start++;
2567:                else
2568:                    while (start < n && sep.indexOf(chars[start]) >= 0)
2569:                        start++;
2570:
2571:                int end = n - 1;
2572:                if (sep == null)
2573:                    while (end >= 0 && Character.isWhitespace(chars[end]))
2574:                        end--;
2575:                else
2576:                    while (end >= 0 && sep.indexOf(chars[end]) >= 0)
2577:                        end--;
2578:
2579:                if (end >= start) {
2580:                    return (end < n - 1 || start > 0) ? string.substring(start,
2581:                            end + 1) : string;
2582:                } else {
2583:                    return "";
2584:                }
2585:            }
2586:
2587:            public String lstrip() {
2588:                return str_lstrip();
2589:            }
2590:
2591:            final String str_lstrip() {
2592:                return str_lstrip(null);
2593:            }
2594:
2595:            public String lstrip(String sep) {
2596:                return str_lstrip(sep);
2597:            }
2598:
2599:            final String str_lstrip(String sep) {
2600:                char[] chars = string.toCharArray();
2601:                int n = chars.length;
2602:                int start = 0;
2603:                if (sep == null)
2604:                    while (start < n && Character.isWhitespace(chars[start]))
2605:                        start++;
2606:                else
2607:                    while (start < n && sep.indexOf(chars[start]) >= 0)
2608:                        start++;
2609:
2610:                return (start > 0) ? string.substring(start, n) : string;
2611:            }
2612:
2613:            public String rstrip() {
2614:                return str_rstrip();
2615:            }
2616:
2617:            final String str_rstrip() {
2618:                return str_rstrip(null);
2619:            }
2620:
2621:            public String rstrip(String sep) {
2622:                return str_rstrip(sep);
2623:            }
2624:
2625:            final String str_rstrip(String sep) {
2626:                char[] chars = string.toCharArray();
2627:                int n = chars.length;
2628:                int end = n - 1;
2629:                if (sep == null)
2630:                    while (end >= 0 && Character.isWhitespace(chars[end]))
2631:                        end--;
2632:                else
2633:                    while (end >= 0 && sep.indexOf(chars[end]) >= 0)
2634:                        end--;
2635:
2636:                return (end < n - 1) ? string.substring(0, end + 1) : string;
2637:            }
2638:
2639:            public PyList split() {
2640:                return str_split();
2641:            }
2642:
2643:            final PyList str_split() {
2644:                return str_split(null, -1);
2645:            }
2646:
2647:            public PyList split(String sep) {
2648:                return str_split(sep);
2649:            }
2650:
2651:            final PyList str_split(String sep) {
2652:                return str_split(sep, -1);
2653:            }
2654:
2655:            public PyList split(String sep, int maxsplit) {
2656:                return str_split(sep, maxsplit);
2657:            }
2658:
2659:            final PyList str_split(String sep, int maxsplit) {
2660:                if (sep != null)
2661:                    return splitfields(sep, maxsplit);
2662:
2663:                PyList list = new PyList();
2664:
2665:                char[] chars = string.toCharArray();
2666:                int n = chars.length;
2667:
2668:                if (maxsplit < 0)
2669:                    maxsplit = n;
2670:
2671:                int splits = 0;
2672:                int index = 0;
2673:                while (index < n && splits < maxsplit) {
2674:                    while (index < n && Character.isWhitespace(chars[index]))
2675:                        index++;
2676:                    if (index == n)
2677:                        break;
2678:                    int start = index;
2679:
2680:                    while (index < n && !Character.isWhitespace(chars[index]))
2681:                        index++;
2682:                    list.append(fromSubstring(start, index));
2683:                    splits++;
2684:                }
2685:                while (index < n && Character.isWhitespace(chars[index]))
2686:                    index++;
2687:                if (index < n) {
2688:                    list.append(fromSubstring(index, n));
2689:                }
2690:                return list;
2691:            }
2692:
2693:            private PyList splitfields(String sep, int maxsplit) {
2694:                if (sep.length() == 0) {
2695:                    throw Py.ValueError("empty separator");
2696:                }
2697:
2698:                PyList list = new PyList();
2699:
2700:                int length = string.length();
2701:                if (maxsplit < 0)
2702:                    maxsplit = length;
2703:
2704:                int lastbreak = 0;
2705:                int splits = 0;
2706:                int sepLength = sep.length();
2707:                while (splits < maxsplit) {
2708:                    int index = string.indexOf(sep, lastbreak);
2709:                    if (index == -1)
2710:                        break;
2711:                    splits += 1;
2712:                    list.append(fromSubstring(lastbreak, index));
2713:                    lastbreak = index + sepLength;
2714:                }
2715:                if (lastbreak <= length) {
2716:                    list.append(fromSubstring(lastbreak, length));
2717:                }
2718:                return list;
2719:            }
2720:
2721:            public PyList splitlines() {
2722:                return str_splitlines();
2723:            }
2724:
2725:            final PyList str_splitlines() {
2726:                return str_splitlines(false);
2727:            }
2728:
2729:            public PyList splitlines(boolean keepends) {
2730:                return str_splitlines(keepends);
2731:            }
2732:
2733:            final PyList str_splitlines(boolean keepends) {
2734:                PyList list = new PyList();
2735:
2736:                char[] chars = string.toCharArray();
2737:                int n = chars.length;
2738:
2739:                int j = 0;
2740:                for (int i = 0; i < n;) {
2741:                    /* Find a line and append it */
2742:                    while (i < n
2743:                            && chars[i] != '\n'
2744:                            && chars[i] != '\r'
2745:                            && Character.getType(chars[i]) != Character.LINE_SEPARATOR)
2746:                        i++;
2747:
2748:                    /* Skip the line break reading CRLF as one line break */
2749:                    int eol = i;
2750:                    if (i < n) {
2751:                        if (chars[i] == '\r' && i + 1 < n
2752:                                && chars[i + 1] == '\n')
2753:                            i += 2;
2754:                        else
2755:                            i++;
2756:                        if (keepends)
2757:                            eol = i;
2758:                    }
2759:                    list.append(fromSubstring(j, eol));
2760:                    j = i;
2761:                }
2762:                if (j < n) {
2763:                    list.append(fromSubstring(j, n));
2764:                }
2765:                return list;
2766:            }
2767:
2768:            protected PyString fromSubstring(int begin, int end) {
2769:                return createInstance(string.substring(begin, end));
2770:            }
2771:
2772:            public int index(String sub) {
2773:                return str_index(sub);
2774:            }
2775:
2776:            final int str_index(String sub) {
2777:                return str_index(sub, 0, string.length());
2778:            }
2779:
2780:            public int index(String sub, int start) {
2781:                return str_index(sub, start);
2782:            }
2783:
2784:            final int str_index(String sub, int start) {
2785:                return str_index(sub, start, string.length());
2786:            }
2787:
2788:            public int index(String sub, int start, int end) {
2789:                return str_index(sub, start, end);
2790:            }
2791:
2792:            final int str_index(String sub, int start, int end) {
2793:                int n = string.length();
2794:
2795:                if (start < 0)
2796:                    start = n + start;
2797:                if (end < 0)
2798:                    end = n + end;
2799:
2800:                int index;
2801:                if (end < n) {
2802:                    index = string.substring(start, end).indexOf(sub);
2803:                } else {
2804:                    index = string.indexOf(sub, start);
2805:                }
2806:                if (index == -1)
2807:                    throw Py.ValueError("substring not found in string.index");
2808:                return index;
2809:            }
2810:
2811:            public int rindex(String sub) {
2812:                return str_rindex(sub);
2813:            }
2814:
2815:            final int str_rindex(String sub) {
2816:                return str_rindex(sub, 0, string.length());
2817:            }
2818:
2819:            public int rindex(String sub, int start) {
2820:                return str_rindex(sub, start);
2821:            }
2822:
2823:            final int str_rindex(String sub, int start) {
2824:                return str_rindex(sub, start, string.length());
2825:            }
2826:
2827:            public int rindex(String sub, int start, int end) {
2828:                return str_rindex(sub, start, end);
2829:            }
2830:
2831:            final int str_rindex(String sub, int start, int end) {
2832:                int n = string.length();
2833:
2834:                if (start < 0)
2835:                    start = n + start;
2836:                if (end < 0)
2837:                    end = n + end;
2838:
2839:                int index;
2840:                if (start > 0) {
2841:                    index = string.substring(start, end).lastIndexOf(sub);
2842:                } else {
2843:                    index = string.lastIndexOf(sub, end);
2844:                }
2845:                if (index == -1)
2846:                    throw Py.ValueError("substring not found in string.rindex");
2847:                return index;
2848:            }
2849:
2850:            public int count(String sub) {
2851:                return str_count(sub);
2852:            }
2853:
2854:            final int str_count(String sub) {
2855:                return count(sub, 0, string.length());
2856:            }
2857:
2858:            public int count(String sub, int start) {
2859:                return str_count(sub, start);
2860:            }
2861:
2862:            final int str_count(String sub, int start) {
2863:                return count(sub, start, string.length());
2864:            }
2865:
2866:            public int count(String sub, int start, int end) {
2867:                return str_count(sub, start, end);
2868:            }
2869:
2870:            final int str_count(String sub, int start, int end) {
2871:                int len = string.length();
2872:                if (end > len)
2873:                    end = len;
2874:                if (end < 0)
2875:                    end += len;
2876:                if (end < 0)
2877:                    end = 0;
2878:                if (start < 0)
2879:                    start += len;
2880:                if (start < 0)
2881:                    start = 0;
2882:
2883:                int n = sub.length();
2884:                end = end + 1 - n;
2885:                if (n == 0)
2886:                    return end - start;
2887:
2888:                int count = 0;
2889:                while (start < end) {
2890:                    int index = string.indexOf(sub, start);
2891:                    if (index >= end || index == -1)
2892:                        break;
2893:                    count++;
2894:                    start = index + n;
2895:                }
2896:                return count;
2897:            }
2898:
2899:            public int find(String sub) {
2900:                return str_find(sub);
2901:            }
2902:
2903:            final int str_find(String sub) {
2904:                return str_find(sub, 0, string.length());
2905:            }
2906:
2907:            public int find(String sub, int start) {
2908:                return str_find(sub, start);
2909:            }
2910:
2911:            final int str_find(String sub, int start) {
2912:                return str_find(sub, start, string.length());
2913:            }
2914:
2915:            public int find(String sub, int start, int end) {
2916:                return str_find(sub, start, end);
2917:            }
2918:
2919:            final int str_find(String sub, int start, int end) {
2920:                int n = string.length();
2921:                if (start < 0)
2922:                    start = n + start;
2923:                if (end < 0)
2924:                    end = n + end;
2925:                if (end > n)
2926:                    end = n;
2927:                if (start > end)
2928:                    start = end;
2929:                int slen = sub.length();
2930:                end = end - slen;
2931:
2932:                int index = string.indexOf(sub, start);
2933:                if (index > end)
2934:                    return -1;
2935:                return index;
2936:            }
2937:
2938:            public int rfind(String sub) {
2939:                return str_rfind(sub);
2940:            }
2941:
2942:            final int str_rfind(String sub) {
2943:                return str_rfind(sub, 0, string.length());
2944:            }
2945:
2946:            public int rfind(String sub, int start) {
2947:                return str_rfind(sub, start);
2948:            }
2949:
2950:            final int str_rfind(String sub, int start) {
2951:                return str_rfind(sub, start, string.length());
2952:            }
2953:
2954:            public int rfind(String sub, int start, int end) {
2955:                return str_rfind(sub, start, end);
2956:            }
2957:
2958:            final int str_rfind(String sub, int start, int end) {
2959:                int n = string.length();
2960:                if (start < 0)
2961:                    start = n + start;
2962:                if (end < 0)
2963:                    end = n + end;
2964:                if (end > n)
2965:                    end = n;
2966:                if (start > end)
2967:                    start = end;
2968:                int slen = sub.length();
2969:                end = end - slen;
2970:
2971:                int index = string.lastIndexOf(sub, end);
2972:                if (index < start)
2973:                    return -1;
2974:                return index;
2975:            }
2976:
2977:            public double atof() {
2978:                StringBuffer s = null;
2979:                int n = string.length();
2980:                for (int i = 0; i < n; i++) {
2981:                    char ch = string.charAt(i);
2982:                    if (ch == '\u0000') {
2983:                        throw Py
2984:                                .ValueError("null byte in argument for float()");
2985:                    }
2986:                    if (Character.isDigit(ch)) {
2987:                        if (s == null)
2988:                            s = new StringBuffer(string);
2989:                        int val = Character.digit(ch, 10);
2990:                        s.setCharAt(i, Character.forDigit(val, 10));
2991:                    }
2992:                }
2993:                String sval = string;
2994:                if (s != null)
2995:                    sval = s.toString();
2996:                try {
2997:                    // Double.valueOf allows format specifier ("d" or "f") at the end
2998:                    String lowSval = sval.toLowerCase();
2999:                    if (lowSval.endsWith("d") || lowSval.endsWith("f")) {
3000:                        throw new NumberFormatException(
3001:                                "format specifiers not allowed");
3002:                    }
3003:                    return Double.valueOf(sval).doubleValue();
3004:                } catch (NumberFormatException exc) {
3005:                    throw Py.ValueError("invalid literal for __float__: "
3006:                            + string);
3007:                }
3008:            }
3009:
3010:            public int atoi() {
3011:                return atoi(10);
3012:            }
3013:
3014:            public int atoi(int base) {
3015:                if ((base != 0 && base < 2) || (base > 36)) {
3016:                    throw Py.ValueError("invalid base for atoi()");
3017:                }
3018:
3019:                int b = 0;
3020:                int e = string.length();
3021:
3022:                while (b < e && Character.isWhitespace(string.charAt(b)))
3023:                    b++;
3024:
3025:                while (e > b && Character.isWhitespace(string.charAt(e - 1)))
3026:                    e--;
3027:
3028:                char sign = 0;
3029:                if (b < e) {
3030:                    sign = string.charAt(b);
3031:                    if (sign == '-' || sign == '+') {
3032:                        b++;
3033:                        while (b < e
3034:                                && Character.isWhitespace(string.charAt(b)))
3035:                            b++;
3036:                    }
3037:
3038:                    if (base == 0 || base == 16) {
3039:                        if (string.charAt(b) == '0') {
3040:                            if (b < e - 1
3041:                                    && Character.toUpperCase(string
3042:                                            .charAt(b + 1)) == 'X') {
3043:                                base = 16;
3044:                                b += 2;
3045:                            } else {
3046:                                if (base == 0)
3047:                                    base = 8;
3048:                            }
3049:                        }
3050:                    }
3051:                }
3052:
3053:                if (base == 0)
3054:                    base = 10;
3055:
3056:                String s = string;
3057:                if (b > 0 || e < string.length())
3058:                    s = string.substring(b, e);
3059:
3060:                try {
3061:                    long result = Long.parseLong(s, base);
3062:                    if (result < 0 && !(sign == '-' && result == -result))
3063:                        throw Py.ValueError("invalid literal for __int__: "
3064:                                + string);
3065:                    if (sign == '-')
3066:                        result = -result;
3067:                    if (result < Integer.MIN_VALUE
3068:                            || result > Integer.MAX_VALUE)
3069:                        throw Py.ValueError("invalid literal for __int__: "
3070:                                + string);
3071:                    return (int) result;
3072:                } catch (NumberFormatException exc) {
3073:                    throw Py.ValueError("invalid literal for __int__: "
3074:                            + string);
3075:                } catch (StringIndexOutOfBoundsException exc) {
3076:                    throw Py.ValueError("invalid literal for __int__: "
3077:                            + string);
3078:                }
3079:            }
3080:
3081:            public PyLong atol() {
3082:                return atol(10);
3083:            }
3084:
3085:            public PyLong atol(int base) {
3086:                String str = string;
3087:                int b = 0;
3088:                int e = str.length();
3089:
3090:                while (b < e && Character.isWhitespace(str.charAt(b)))
3091:                    b++;
3092:
3093:                while (e > b && Character.isWhitespace(str.charAt(e - 1)))
3094:                    e--;
3095:                if (e > b
3096:                        && (str.charAt(e - 1) == 'L' || str.charAt(e - 1) == 'l'))
3097:                    e--;
3098:
3099:                char sign = 0;
3100:                if (b < e) {
3101:                    sign = string.charAt(b);
3102:                    if (sign == '-' || sign == '+') {
3103:                        b++;
3104:                        while (b < e && Character.isWhitespace(str.charAt(b)))
3105:                            b++;
3106:                    }
3107:
3108:                    if (base == 0 || base == 16) {
3109:                        if (string.charAt(b) == '0') {
3110:                            if (b < e - 1
3111:                                    && Character.toUpperCase(string
3112:                                            .charAt(b + 1)) == 'X') {
3113:                                base = 16;
3114:                                b += 2;
3115:                            } else {
3116:                                if (base == 0)
3117:                                    base = 8;
3118:                            }
3119:                        }
3120:                    }
3121:                }
3122:                if (base == 0)
3123:                    base = 10;
3124:
3125:                if (base < 2 || base > 36)
3126:                    throw Py
3127:                            .ValueError("invalid base for long literal:" + base);
3128:
3129:                if (b > 0 || e < str.length())
3130:                    str = str.substring(b, e);
3131:
3132:                try {
3133:                    java.math.BigInteger bi = null;
3134:                    if (sign == '-')
3135:                        bi = new java.math.BigInteger("-" + str, base);
3136:                    else
3137:                        bi = new java.math.BigInteger(str, base);
3138:                    return new PyLong(bi);
3139:                } catch (NumberFormatException exc) {
3140:                    throw Py.ValueError("invalid literal for __long__: " + str);
3141:                } catch (StringIndexOutOfBoundsException exc) {
3142:                    throw Py.ValueError("invalid literal for __long__: " + str);
3143:                }
3144:            }
3145:
3146:            private static String spaces(int n) {
3147:                char[] chars = new char[n];
3148:                for (int i = 0; i < n; i++)
3149:                    chars[i] = ' ';
3150:                return new String(chars);
3151:            }
3152:
3153:            public String ljust(int width) {
3154:                return str_ljust(width);
3155:            }
3156:
3157:            final String str_ljust(int width) {
3158:                int n = width - string.length();
3159:                if (n <= 0)
3160:                    return string;
3161:                return string + spaces(n);
3162:            }
3163:
3164:            public String rjust(int width) {
3165:                return str_rjust(width);
3166:            }
3167:
3168:            final String str_rjust(int width) {
3169:                int n = width - string.length();
3170:                if (n <= 0)
3171:                    return string;
3172:                return spaces(n) + string;
3173:            }
3174:
3175:            public String center(int width) {
3176:                return str_center(width);
3177:            }
3178:
3179:            final String str_center(int width) {
3180:                int n = width - string.length();
3181:                if (n <= 0)
3182:                    return string;
3183:                int half = n / 2;
3184:                if (n % 2 > 0 && width % 2 > 0)
3185:                    half += 1;
3186:                return spaces(half) + string + spaces(n - half);
3187:            }
3188:
3189:            public String zfill(int width) {
3190:                return str_zfill(width);
3191:            }
3192:
3193:            final String str_zfill(int width) {
3194:                String s = string;
3195:                int n = s.length();
3196:                if (n >= width)
3197:                    return s;
3198:                char[] chars = new char[width];
3199:                int nzeros = width - n;
3200:                int i = 0;
3201:                int sStart = 0;
3202:                if (n > 0) {
3203:                    char start = s.charAt(0);
3204:                    if (start == '+' || start == '-') {
3205:                        chars[0] = start;
3206:                        i += 1;
3207:                        nzeros++;
3208:                        sStart = 1;
3209:                    }
3210:                }
3211:                for (; i < nzeros; i++) {
3212:                    chars[i] = '0';
3213:                }
3214:                s.getChars(sStart, s.length(), chars, i);
3215:                return new String(chars);
3216:            }
3217:
3218:            public String expandtabs() {
3219:                return str_expandtabs();
3220:            }
3221:
3222:            final String str_expandtabs() {
3223:                return str_expandtabs(8);
3224:            }
3225:
3226:            public String expandtabs(int tabsize) {
3227:                return str_expandtabs(tabsize);
3228:            }
3229:
3230:            final String str_expandtabs(int tabsize) {
3231:                String s = string;
3232:                StringBuffer buf = new StringBuffer((int) (s.length() * 1.5));
3233:                char[] chars = s.toCharArray();
3234:                int n = chars.length;
3235:                int position = 0;
3236:
3237:                for (int i = 0; i < n; i++) {
3238:                    char c = chars[i];
3239:                    if (c == '\t') {
3240:                        int spaces = tabsize - position % tabsize;
3241:                        position += spaces;
3242:                        while (spaces-- > 0) {
3243:                            buf.append(' ');
3244:                        }
3245:                        continue;
3246:                    }
3247:                    if (c == '\n' || c == '\r') {
3248:                        position = -1;
3249:                    }
3250:                    buf.append(c);
3251:                    position++;
3252:                }
3253:                return buf.toString();
3254:            }
3255:
3256:            public String capitalize() {
3257:                return str_capitalize();
3258:            }
3259:
3260:            final String str_capitalize() {
3261:                if (string.length() == 0)
3262:                    return string;
3263:                String first = string.substring(0, 1).toUpperCase();
3264:                return first.concat(string.substring(1).toLowerCase());
3265:            }
3266:
3267:            final PyString str_replace(PyObject oldPiece, PyObject newPiece) {
3268:                return str_replace(oldPiece, newPiece, string.length());
3269:            }
3270:
3271:            final PyString str_replace(PyObject oldPiece, PyObject newPiece,
3272:                    int maxsplit) {
3273:                if (!(oldPiece instanceof  PyString)
3274:                        || !(newPiece instanceof  PyString)) {
3275:                    throw Py.TypeError("str or unicode required for replace");
3276:                }
3277:                return ((PyString) newPiece).str_join(str_split(
3278:                        ((PyString) oldPiece).string, maxsplit));
3279:            }
3280:
3281:            public String join(PyObject seq) {
3282:                return str_join(seq).string;
3283:            }
3284:
3285:            final PyString str_join(PyObject seq) {
3286:                StringBuffer buf = new StringBuffer();
3287:
3288:                PyObject iter = seq.__iter__();
3289:                PyObject obj = null;
3290:                boolean needsUnicode = false;
3291:                for (int i = 0; (obj = iter.__iternext__()) != null; i++) {
3292:                    if (!(obj instanceof  PyString)) {
3293:                        throw Py.TypeError("sequence item " + i
3294:                                + ": expected string, " + obj.safeRepr()
3295:                                + " found");
3296:                    }
3297:                    if (obj instanceof  PyUnicode) {
3298:                        needsUnicode = true;
3299:                    }
3300:                    if (i > 0) {
3301:                        buf.append(string);
3302:                    }
3303:                    buf.append(obj.__str__());
3304:                }
3305:                if (needsUnicode || this  instanceof  PyUnicode) {
3306:                    return new PyUnicode(buf.toString());
3307:                }
3308:                return new PyString(buf.toString());
3309:            }
3310:
3311:            public boolean startswith(String prefix) {
3312:                return str_startswith(prefix);
3313:            }
3314:
3315:            final boolean str_startswith(String prefix) {
3316:                return string.startsWith(prefix);
3317:            }
3318:
3319:            public boolean startswith(String prefix, int offset) {
3320:                return str_startswith(prefix, offset);
3321:            }
3322:
3323:            final boolean str_startswith(String prefix, int offset) {
3324:                return string.startsWith(prefix, offset);
3325:            }
3326:
3327:            public boolean startswith(String prefix, int start, int end) {
3328:                return str_startswith(prefix, start, end);
3329:            }
3330:
3331:            final boolean str_startswith(String prefix, int start, int end) {
3332:                if (start < 0 || start + prefix.length() > string.length())
3333:                    return false;
3334:                if (end > string.length())
3335:                    end = string.length();
3336:                String substr = string.substring(start, end);
3337:                return substr.startsWith(prefix);
3338:            }
3339:
3340:            public boolean endswith(String suffix) {
3341:                return str_endswith(suffix);
3342:            }
3343:
3344:            final boolean str_endswith(String suffix) {
3345:                return string.endsWith(suffix);
3346:            }
3347:
3348:            public boolean endswith(String suffix, int start) {
3349:                return str_endswith(suffix, start);
3350:            }
3351:
3352:            final boolean str_endswith(String suffix, int start) {
3353:                return str_endswith(suffix, start, string.length());
3354:            }
3355:
3356:            public boolean endswith(String suffix, int start, int end) {
3357:                return str_endswith(suffix, start, end);
3358:            }
3359:
3360:            final boolean str_endswith(String suffix, int start, int end) {
3361:                int len = string.length();
3362:
3363:                if (start < 0 || start > len || suffix.length() > len)
3364:                    return false;
3365:
3366:                end = (end <= len ? end : len);
3367:                if (end < start)
3368:                    return false;
3369:
3370:                String substr = string.substring(start, end);
3371:                return substr.endsWith(suffix);
3372:            }
3373:
3374:            public String translate(String table) {
3375:                return str_translate(table);
3376:            }
3377:
3378:            final String str_translate(String table) {
3379:                return str_translate(table, null);
3380:            }
3381:
3382:            public String translate(String table, String deletechars) {
3383:                return str_translate(table, deletechars);
3384:            }
3385:
3386:            final String str_translate(String table, String deletechars) {
3387:                if (table.length() != 256)
3388:                    throw Py
3389:                            .ValueError("translation table must be 256 characters long");
3390:
3391:                StringBuffer buf = new StringBuffer(string.length());
3392:                for (int i = 0; i < string.length(); i++) {
3393:                    char c = string.charAt(i);
3394:                    if (deletechars != null && deletechars.indexOf(c) >= 0)
3395:                        continue;
3396:                    try {
3397:                        buf.append(table.charAt(c));
3398:                    } catch (IndexOutOfBoundsException e) {
3399:                        throw Py
3400:                                .TypeError("translate() only works for 8-bit character strings");
3401:                    }
3402:                }
3403:                return buf.toString();
3404:            }
3405:
3406:            //XXX: is this needed?
3407:            public String translate(PyObject table) {
3408:                StringBuffer v = new StringBuffer(string.length());
3409:                for (int i = 0; i < string.length(); i++) {
3410:                    char ch = string.charAt(i);
3411:
3412:                    PyObject w = Py.newInteger(ch);
3413:                    PyObject x = table.__finditem__(w);
3414:                    if (x == null) {
3415:                        /* No mapping found: default to 1-1 mapping */
3416:                        v.append(ch);
3417:                        continue;
3418:                    }
3419:
3420:                    /* Apply mapping */
3421:                    if (x instanceof  PyInteger) {
3422:                        int value = ((PyInteger) x).getValue();
3423:                        v.append((char) value);
3424:                    } else if (x == Py.None) {
3425:                        ;
3426:                    } else if (x instanceof  PyString) {
3427:                        if (x.__len__() != 1) {
3428:                            /* 1-n mapping */
3429:                            throw new PyException(Py.NotImplementedError,
3430:                                    "1-n mappings are currently not implemented");
3431:                        }
3432:                        v.append(x.toString());
3433:                    } else {
3434:                        /* wrong return value */
3435:                        throw Py
3436:                                .TypeError("character mapping must return integer, "
3437:                                        + "None or unicode");
3438:                    }
3439:                }
3440:                return v.toString();
3441:            }
3442:
3443:            public boolean islower() {
3444:                return str_islower();
3445:            }
3446:
3447:            final boolean str_islower() {
3448:                int n = string.length();
3449:
3450:                /* Shortcut for single character strings */
3451:                if (n == 1)
3452:                    return Character.isLowerCase(string.charAt(0));
3453:
3454:                boolean cased = false;
3455:                for (int i = 0; i < n; i++) {
3456:                    char ch = string.charAt(i);
3457:
3458:                    if (Character.isUpperCase(ch) || Character.isTitleCase(ch))
3459:                        return false;
3460:                    else if (!cased && Character.isLowerCase(ch))
3461:                        cased = true;
3462:                }
3463:                return cased;
3464:            }
3465:
3466:            public boolean isupper() {
3467:                return str_isupper();
3468:            }
3469:
3470:            final boolean str_isupper() {
3471:                int n = string.length();
3472:
3473:                /* Shortcut for single character strings */
3474:                if (n == 1)
3475:                    return Character.isUpperCase(string.charAt(0));
3476:
3477:                boolean cased = false;
3478:                for (int i = 0; i < n; i++) {
3479:                    char ch = string.charAt(i);
3480:
3481:                    if (Character.isLowerCase(ch) || Character.isTitleCase(ch))
3482:                        return false;
3483:                    else if (!cased && Character.isUpperCase(ch))
3484:                        cased = true;
3485:                }
3486:                return cased;
3487:            }
3488:
3489:            public boolean isalpha() {
3490:                return str_isalpha();
3491:            }
3492:
3493:            final boolean str_isalpha() {
3494:                int n = string.length();
3495:
3496:                /* Shortcut for single character strings */
3497:                if (n == 1)
3498:                    return Character.isLetter(string.charAt(0));
3499:
3500:                if (n == 0)
3501:                    return false;
3502:
3503:                for (int i = 0; i < n; i++) {
3504:                    char ch = string.charAt(i);
3505:
3506:                    if (!Character.isLetter(ch))
3507:                        return false;
3508:                }
3509:                return true;
3510:            }
3511:
3512:            public boolean isalnum() {
3513:                return str_isalnum();
3514:            }
3515:
3516:            final boolean str_isalnum() {
3517:                int n = string.length();
3518:
3519:                /* Shortcut for single character strings */
3520:                if (n == 1)
3521:                    return _isalnum(string.charAt(0));
3522:
3523:                if (n == 0)
3524:                    return false;
3525:
3526:                for (int i = 0; i < n; i++) {
3527:                    char ch = string.charAt(i);
3528:
3529:                    if (!_isalnum(ch))
3530:                        return false;
3531:                }
3532:                return true;
3533:            }
3534:
3535:            private boolean _isalnum(char ch) {
3536:                // This can ever be entirely compatible with CPython. In CPython
3537:                // The type is not used, the numeric property is determined from
3538:                // the presense of digit, decimal or numeric fields. These fields
3539:                // are not available in exactly the same way in java.
3540:                return Character.isLetterOrDigit(ch)
3541:                        || Character.getType(ch) == Character.LETTER_NUMBER;
3542:            }
3543:
3544:            public boolean isdecimal() {
3545:                return str_isdecimal();
3546:            }
3547:
3548:            final boolean str_isdecimal() {
3549:                int n = string.length();
3550:
3551:                /* Shortcut for single character strings */
3552:                if (n == 1) {
3553:                    char ch = string.charAt(0);
3554:                    return _isdecimal(ch);
3555:                }
3556:
3557:                if (n == 0)
3558:                    return false;
3559:
3560:                for (int i = 0; i < n; i++) {
3561:                    char ch = string.charAt(i);
3562:
3563:                    if (!_isdecimal(ch))
3564:                        return false;
3565:                }
3566:                return true;
3567:            }
3568:
3569:            private boolean _isdecimal(char ch) {
3570:                // See the comment in _isalnum. Here it is even worse.
3571:                return Character.getType(ch) == Character.DECIMAL_DIGIT_NUMBER;
3572:            }
3573:
3574:            public boolean isdigit() {
3575:                return str_isdigit();
3576:            }
3577:
3578:            final boolean str_isdigit() {
3579:                int n = string.length();
3580:
3581:                /* Shortcut for single character strings */
3582:                if (n == 1)
3583:                    return Character.isDigit(string.charAt(0));
3584:
3585:                if (n == 0)
3586:                    return false;
3587:
3588:                for (int i = 0; i < n; i++) {
3589:                    char ch = string.charAt(i);
3590:
3591:                    if (!Character.isDigit(ch))
3592:                        return false;
3593:                }
3594:                return true;
3595:            }
3596:
3597:            public boolean isnumeric() {
3598:                return str_isnumeric();
3599:            }
3600:
3601:            final boolean str_isnumeric() {
3602:                int n = string.length();
3603:
3604:                /* Shortcut for single character strings */
3605:                if (n == 1)
3606:                    return _isnumeric(string.charAt(0));
3607:
3608:                if (n == 0)
3609:                    return false;
3610:
3611:                for (int i = 0; i < n; i++) {
3612:                    char ch = string.charAt(i);
3613:                    if (!_isnumeric(ch))
3614:                        return false;
3615:                }
3616:                return true;
3617:            }
3618:
3619:            private boolean _isnumeric(char ch) {
3620:                int type = Character.getType(ch);
3621:                return type == Character.DECIMAL_DIGIT_NUMBER
3622:                        || type == Character.LETTER_NUMBER
3623:                        || type == Character.OTHER_NUMBER;
3624:            }
3625:
3626:            public boolean istitle() {
3627:                return str_istitle();
3628:            }
3629:
3630:            final boolean str_istitle() {
3631:                int n = string.length();
3632:
3633:                /* Shortcut for single character strings */
3634:                if (n == 1)
3635:                    return Character.isTitleCase(string.charAt(0))
3636:                            || Character.isUpperCase(string.charAt(0));
3637:
3638:                boolean cased = false;
3639:                boolean previous_is_cased = false;
3640:                for (int i = 0; i < n; i++) {
3641:                    char ch = string.charAt(i);
3642:
3643:                    if (Character.isUpperCase(ch) || Character.isTitleCase(ch)) {
3644:                        if (previous_is_cased)
3645:                            return false;
3646:                        previous_is_cased = true;
3647:                        cased = true;
3648:                    } else if (Character.isLowerCase(ch)) {
3649:                        if (!previous_is_cased)
3650:                            return false;
3651:                        previous_is_cased = true;
3652:                        cased = true;
3653:                    } else
3654:                        previous_is_cased = false;
3655:                }
3656:                return cased;
3657:            }
3658:
3659:            public boolean isspace() {
3660:                return str_isspace();
3661:            }
3662:
3663:            final boolean str_isspace() {
3664:                int n = string.length();
3665:
3666:                /* Shortcut for single character strings */
3667:                if (n == 1)
3668:                    return Character.isWhitespace(string.charAt(0));
3669:
3670:                if (n == 0)
3671:                    return false;
3672:
3673:                for (int i = 0; i < n; i++) {
3674:                    char ch = string.charAt(i);
3675:
3676:                    if (!Character.isWhitespace(ch))
3677:                        return false;
3678:                }
3679:                return true;
3680:            }
3681:
3682:            public boolean isunicode() {
3683:                return str_isunicode();
3684:            }
3685:
3686:            final boolean str_isunicode() {
3687:                int n = string.length();
3688:                for (int i = 0; i < n; i++) {
3689:                    char ch = string.charAt(i);
3690:                    if (ch > 255)
3691:                        return true;
3692:                }
3693:                return false;
3694:            }
3695:
3696:            public String encode() {
3697:                return str_encode();
3698:            }
3699:
3700:            final String str_encode() {
3701:                return str_encode(null, null);
3702:            }
3703:
3704:            public String encode(String encoding) {
3705:                return str_encode(encoding);
3706:            }
3707:
3708:            final String str_encode(String encoding) {
3709:                return str_encode(encoding, null);
3710:            }
3711:
3712:            public String encode(String encoding, String errors) {
3713:                return str_encode(encoding, errors);
3714:            }
3715:
3716:            final String str_encode(String encoding, String errors) {
3717:                return codecs.encode(this , encoding, errors);
3718:            }
3719:
3720:            public String decode() {
3721:                return str_decode();
3722:            }
3723:
3724:            final String str_decode() {
3725:                return str_decode(null, null); // xxx
3726:            }
3727:
3728:            public String decode(String encoding) {
3729:                return str_decode(encoding);
3730:            }
3731:
3732:            final String str_decode(String encoding) {
3733:                return str_decode(encoding, null);
3734:            }
3735:
3736:            public String decode(String encoding, String errors) {
3737:                return str_decode(encoding, errors);
3738:            }
3739:
3740:            final String str_decode(String encoding, String errors) {
3741:                return codecs.decode(this , encoding, errors);
3742:            }
3743:
3744:            /* arguments' conversion helper */
3745:
3746:            public String asString(int index)
3747:                    throws PyObject.ConversionException {
3748:                return string;
3749:            }
3750:
3751:            public String asName(int index) throws PyObject.ConversionException {
3752:                return internedString();
3753:            }
3754:
3755:        }
3756:
3757:        final class StringFormatter {
3758:            int index;
3759:            String format;
3760:            StringBuffer buffer;
3761:            boolean negative;
3762:            int precision;
3763:            int argIndex;
3764:            PyObject args;
3765:
3766:            final char pop() {
3767:                try {
3768:                    return format.charAt(index++);
3769:                } catch (StringIndexOutOfBoundsException e) {
3770:                    throw Py.ValueError("incomplete format");
3771:                }
3772:            }
3773:
3774:            final char peek() {
3775:                return format.charAt(index);
3776:            }
3777:
3778:            final void push() {
3779:                index--;
3780:            }
3781:
3782:            public StringFormatter(String format) {
3783:                index = 0;
3784:                this .format = format;
3785:                buffer = new StringBuffer(format.length() + 100);
3786:            }
3787:
3788:            PyObject getarg() {
3789:                PyObject ret = null;
3790:                switch (argIndex) {
3791:                // special index indicating a mapping
3792:                case -3:
3793:                    return args;
3794:                    // special index indicating a single item that has already been
3795:                    // used
3796:                case -2:
3797:                    break;
3798:                // special index indicating a single item that has not yet been
3799:                // used
3800:                case -1:
3801:                    argIndex = -2;
3802:                    return args;
3803:                default:
3804:                    ret = args.__finditem__(argIndex++);
3805:                    break;
3806:                }
3807:                if (ret == null)
3808:                    throw Py
3809:                            .TypeError("not enough arguments for format string");
3810:                return ret;
3811:            }
3812:
3813:            int getNumber() {
3814:                char c = pop();
3815:                if (c == '*') {
3816:                    PyObject o = getarg();
3817:                    if (o instanceof  PyInteger)
3818:                        return ((PyInteger) o).getValue();
3819:                    throw Py.TypeError("* wants int");
3820:                } else {
3821:                    if (Character.isDigit(c)) {
3822:                        int numStart = index - 1;
3823:                        while (Character.isDigit(c = pop()))
3824:                            ;
3825:                        index -= 1;
3826:                        Integer i = Integer.valueOf(format.substring(numStart,
3827:                                index));
3828:                        return i.intValue();
3829:                    }
3830:                    index -= 1;
3831:                    return 0;
3832:                }
3833:            }
3834:
3835:            private void checkPrecision(String type) {
3836:                if (precision > 250) {
3837:                    // A magic number. Larger than in CPython.
3838:                    throw Py.OverflowError("formatted " + type
3839:                            + " is too long (precision too long?)");
3840:                }
3841:
3842:            }
3843:
3844:            private String formatLong(PyString arg, char type, boolean altFlag) {
3845:                checkPrecision("long");
3846:                String s = arg.toString();
3847:                int end = s.length();
3848:                int ptr = 0;
3849:
3850:                int numnondigits = 0;
3851:                if (type == 'x' || type == 'X')
3852:                    numnondigits = 2;
3853:
3854:                if (s.endsWith("L"))
3855:                    end--;
3856:
3857:                negative = s.charAt(0) == '-';
3858:                if (negative) {
3859:                    ptr++;
3860:                }
3861:
3862:                int numdigits = end - numnondigits - ptr;
3863:                if (!altFlag) {
3864:                    switch (type) {
3865:                    case 'o':
3866:                        if (numdigits > 1) {
3867:                            ++ptr;
3868:                            --numdigits;
3869:                        }
3870:                        break;
3871:                    case 'x':
3872:                    case 'X':
3873:                        ptr += 2;
3874:                        numnondigits -= 2;
3875:                        break;
3876:                    }
3877:                }
3878:                if (precision > numdigits) {
3879:                    StringBuffer buf = new StringBuffer();
3880:                    for (int i = 0; i < numnondigits; ++i)
3881:                        buf.append(s.charAt(ptr++));
3882:                    for (int i = 0; i < precision - numdigits; i++)
3883:                        buf.append('0');
3884:                    for (int i = 0; i < numdigits; i++)
3885:                        buf.append(s.charAt(ptr++));
3886:                    s = buf.toString();
3887:                } else if (end < s.length() || ptr > 0)
3888:                    s = s.substring(ptr, end);
3889:
3890:                switch (type) {
3891:                case 'x':
3892:                    s = s.toLowerCase();
3893:                    break;
3894:                }
3895:                return s;
3896:            }
3897:
3898:            private String formatInteger(PyObject arg, int radix,
3899:                    boolean unsigned) {
3900:                return formatInteger(((PyInteger) arg.__int__()).getValue(),
3901:                        radix, unsigned);
3902:            }
3903:
3904:            private String formatInteger(long v, int radix, boolean unsigned) {
3905:                checkPrecision("integer");
3906:                if (unsigned) {
3907:                    if (v < 0)
3908:                        v = 0x100000000l + v;
3909:                } else {
3910:                    if (v < 0) {
3911:                        negative = true;
3912:                        v = -v;
3913:                    }
3914:                }
3915:                String s = Long.toString(v, radix);
3916:                while (s.length() < precision) {
3917:                    s = "0" + s;
3918:                }
3919:                return s;
3920:            }
3921:
3922:            private String formatFloatDecimal(PyObject arg, boolean truncate) {
3923:                return formatFloatDecimal(arg.__float__().getValue(), truncate);
3924:            }
3925:
3926:            private String formatFloatDecimal(double v, boolean truncate) {
3927:                checkPrecision("decimal");
3928:                java.text.NumberFormat format = java.text.NumberFormat
3929:                        .getInstance(java.util.Locale.US);
3930:                int prec = precision;
3931:                if (prec == -1)
3932:                    prec = 6;
3933:                if (v < 0) {
3934:                    v = -v;
3935:                    negative = true;
3936:                }
3937:                format.setMaximumFractionDigits(prec);
3938:                format.setMinimumFractionDigits(truncate ? 0 : prec);
3939:                format.setGroupingUsed(false);
3940:
3941:                String ret = format.format(v);
3942:                //         System.err.println("formatFloat: "+v+", prec="+prec+", ret="+ret);
3943:                //         if (ret.indexOf('.') == -1) {
3944:                //             return ret+'.';
3945:                //         }
3946:                return ret;
3947:            }
3948:
3949:            private String formatFloatExponential(PyObject arg, char e,
3950:                    boolean truncate) {
3951:                StringBuffer buf = new StringBuffer();
3952:                double v = arg.__float__().getValue();
3953:                boolean isNegative = false;
3954:                if (v < 0) {
3955:                    v = -v;
3956:                    isNegative = true;
3957:                }
3958:                double power = 0.0;
3959:                if (v > 0)
3960:                    power = ExtraMath.closeFloor(ExtraMath.log10(v));
3961:                //System.err.println("formatExp: "+v+", "+power);
3962:                int savePrecision = precision;
3963:
3964:                if (truncate)
3965:                    precision = -1;
3966:                else
3967:                    precision = 3;
3968:
3969:                String exp = formatInteger((long) power, 10, false);
3970:                if (negative) {
3971:                    negative = false;
3972:                    exp = '-' + exp;
3973:                } else {
3974:                    if (!truncate)
3975:                        exp = '+' + exp;
3976:                }
3977:
3978:                precision = savePrecision;
3979:
3980:                double base = v / Math.pow(10, power);
3981:                buf.append(formatFloatDecimal(base, truncate));
3982:                buf.append(e);
3983:
3984:                buf.append(exp);
3985:                negative = isNegative;
3986:
3987:                return buf.toString();
3988:            }
3989:
3990:            public PyString format(PyObject args) {
3991:                PyObject dict = null;
3992:                this .args = args;
3993:                boolean needUnicode = false;
3994:                if (args instanceof  PyTuple) {
3995:                    argIndex = 0;
3996:                } else {
3997:                    // special index indicating a single item rather than a tuple
3998:                    argIndex = -1;
3999:                    if (args instanceof  PyDictionary
4000:                            || args instanceof  PyStringMap
4001:                            || (!(args instanceof  PySequence) && args
4002:                                    .__findattr__("__getitem__") != null)) {
4003:                        dict = args;
4004:                        argIndex = -3;
4005:                    }
4006:                }
4007:
4008:                while (index < format.length()) {
4009:                    boolean ljustFlag = false;
4010:                    boolean signFlag = false;
4011:                    boolean blankFlag = false;
4012:                    boolean altFlag = false;
4013:                    boolean zeroFlag = false;
4014:
4015:                    int width = -1;
4016:                    precision = -1;
4017:
4018:                    char c = pop();
4019:                    if (c != '%') {
4020:                        buffer.append(c);
4021:                        continue;
4022:                    }
4023:                    c = pop();
4024:                    if (c == '(') {
4025:                        //System.out.println("( found");
4026:                        if (dict == null)
4027:                            throw Py.TypeError("format requires a mapping");
4028:                        int parens = 1;
4029:                        int keyStart = index;
4030:                        while (parens > 0) {
4031:                            c = pop();
4032:                            if (c == ')')
4033:                                parens--;
4034:                            else if (c == '(')
4035:                                parens++;
4036:                        }
4037:                        String tmp = format.substring(keyStart, index - 1);
4038:                        this .args = dict.__getitem__(new PyString(tmp));
4039:                        //System.out.println("args: "+args+", "+argIndex);
4040:                    } else {
4041:                        push();
4042:                    }
4043:                    while (true) {
4044:                        switch (c = pop()) {
4045:                        case '-':
4046:                            ljustFlag = true;
4047:                            continue;
4048:                        case '+':
4049:                            signFlag = true;
4050:                            continue;
4051:                        case ' ':
4052:                            blankFlag = true;
4053:                            continue;
4054:                        case '#':
4055:                            altFlag = true;
4056:                            continue;
4057:                        case '0':
4058:                            zeroFlag = true;
4059:                            continue;
4060:                        }
4061:                        break;
4062:                    }
4063:                    push();
4064:                    width = getNumber();
4065:                    if (width < 0) {
4066:                        width = -width;
4067:                        ljustFlag = true;
4068:                    }
4069:                    c = pop();
4070:                    if (c == '.') {
4071:                        precision = getNumber();
4072:                        if (precision < -1)
4073:                            precision = 0;
4074:
4075:                        c = pop();
4076:                    }
4077:                    if (c == 'h' || c == 'l' || c == 'L') {
4078:                        c = pop();
4079:                    }
4080:                    if (c == '%') {
4081:                        buffer.append(c);
4082:                        continue;
4083:                    }
4084:                    PyObject arg = getarg();
4085:                    //System.out.println("args: "+args+", "+argIndex+", "+arg);
4086:                    char fill = ' ';
4087:                    String string = null;
4088:                    negative = false;
4089:                    if (zeroFlag)
4090:                        fill = '0';
4091:                    else
4092:                        fill = ' ';
4093:
4094:                    switch (c) {
4095:                    case 's':
4096:                    case 'r':
4097:                        fill = ' ';
4098:                        if (c == 's')
4099:                            string = arg.__str__().toString();
4100:                        else
4101:                            string = arg.__repr__().toString();
4102:                        if (precision >= 0 && string.length() > precision) {
4103:                            string = string.substring(0, precision);
4104:                        }
4105:                        if (arg instanceof  PyUnicode) {
4106:                            needUnicode = true;
4107:                        }
4108:                        break;
4109:                    case 'i':
4110:                    case 'd':
4111:                        if (arg instanceof  PyLong)
4112:                            string = formatLong(arg.__str__(), c, altFlag);
4113:                        else
4114:                            string = formatInteger(arg, 10, false);
4115:                        break;
4116:                    case 'u':
4117:                        if (arg instanceof  PyLong)
4118:                            string = formatLong(arg.__str__(), c, altFlag);
4119:                        else
4120:                            string = formatInteger(arg, 10, true);
4121:                        break;
4122:                    case 'o':
4123:                        if (arg instanceof  PyLong)
4124:                            string = formatLong(arg.__oct__(), c, altFlag);
4125:                        else {
4126:                            string = formatInteger(arg, 8, true);
4127:                            if (altFlag && string.charAt(0) != '0') {
4128:                                string = "0" + string;
4129:                            }
4130:                        }
4131:                        break;
4132:                    case 'x':
4133:                        if (arg instanceof  PyLong)
4134:                            string = formatLong(arg.__hex__(), c, altFlag);
4135:                        else {
4136:                            string = formatInteger(arg, 16, true);
4137:                            string = string.toLowerCase();
4138:                            if (altFlag) {
4139:                                string = "0x" + string;
4140:                            }
4141:                        }
4142:                        break;
4143:                    case 'X':
4144:                        if (arg instanceof  PyLong)
4145:                            string = formatLong(arg.__hex__(), c, altFlag);
4146:                        else {
4147:                            string = formatInteger(arg, 16, true);
4148:                            string = string.toUpperCase();
4149:                            if (altFlag) {
4150:                                string = "0X" + string;
4151:                            }
4152:                        }
4153:
4154:                        break;
4155:                    case 'e':
4156:                    case 'E':
4157:                        string = formatFloatExponential(arg, c, false);
4158:                        break;
4159:                    case 'f':
4160:                        string = formatFloatDecimal(arg, false);
4161:                        //                 if (altFlag && string.indexOf('.') == -1)
4162:                        //                     string += '.';
4163:                        break;
4164:                    case 'g':
4165:                    case 'G':
4166:                        int prec = precision;
4167:                        if (prec == -1)
4168:                            prec = 6;
4169:                        double v = arg.__float__().getValue();
4170:                        int digits = (int) Math.ceil(ExtraMath.log10(v));
4171:                        if (digits > 0) {
4172:                            if (digits <= prec) {
4173:                                precision = prec - digits;
4174:                                string = formatFloatDecimal(arg, true);
4175:                            } else {
4176:                                string = formatFloatExponential(arg,
4177:                                        (char) (c - 2), true);
4178:                            }
4179:                        } else {
4180:                            string = formatFloatDecimal(arg, true);
4181:                        }
4182:                        if (altFlag && string.indexOf('.') == -1) {
4183:                            int zpad = prec - string.length();
4184:                            string += '.';
4185:                            if (zpad > 0) {
4186:                                char zeros[] = new char[zpad];
4187:                                for (int ci = 0; ci < zpad; zeros[ci++] = '0')
4188:                                    ;
4189:                                string += new String(zeros);
4190:                            }
4191:                        }
4192:                        break;
4193:                    case 'c':
4194:                        fill = ' ';
4195:                        if (arg instanceof  PyString) {
4196:                            string = ((PyString) arg).toString();
4197:                            if (string.length() != 1)
4198:                                throw Py.TypeError("%c requires int or char");
4199:                            if (arg instanceof  PyUnicode) {
4200:                                needUnicode = true;
4201:                            }
4202:                            break;
4203:                        }
4204:                        char tmp = (char) ((PyInteger) arg.__int__())
4205:                                .getValue();
4206:                        string = new Character(tmp).toString();
4207:                        break;
4208:
4209:                    default:
4210:                        throw Py.ValueError("unsupported format character '"
4211:                                + codecs.encode(Py.newString(c), null,
4212:                                        "replace") + "' (0x"
4213:                                + Integer.toHexString(c) + ") at index "
4214:                                + (index - 1));
4215:                    }
4216:                    int length = string.length();
4217:                    int skip = 0;
4218:                    String signString = null;
4219:                    if (negative) {
4220:                        signString = "-";
4221:                    } else {
4222:                        if (signFlag) {
4223:                            signString = "+";
4224:                        } else if (blankFlag) {
4225:                            signString = " ";
4226:                        }
4227:                    }
4228:
4229:                    if (width < length)
4230:                        width = length;
4231:                    if (signString != null) {
4232:                        if (fill != ' ')
4233:                            buffer.append(signString);
4234:                        if (width > length)
4235:                            width--;
4236:                    }
4237:                    if (altFlag && (c == 'x' || c == 'X')) {
4238:                        if (fill != ' ') {
4239:                            buffer.append('0');
4240:                            buffer.append(c);
4241:                            skip += 2;
4242:                        }
4243:                        width -= 2;
4244:                        if (width < 0)
4245:                            width = 0;
4246:                        length -= 2;
4247:                    }
4248:                    if (width > length && !ljustFlag) {
4249:                        do {
4250:                            buffer.append(fill);
4251:                        } while (--width > length);
4252:                    }
4253:                    if (fill == ' ') {
4254:                        if (signString != null)
4255:                            buffer.append(signString);
4256:                        if (altFlag && (c == 'x' || c == 'X')) {
4257:                            buffer.append('0');
4258:                            buffer.append(c);
4259:                            skip += 2;
4260:                        }
4261:                    }
4262:                    if (skip > 0)
4263:                        buffer.append(string.substring(skip));
4264:                    else
4265:                        buffer.append(string);
4266:
4267:                    while (--width >= length) {
4268:                        buffer.append(' ');
4269:                    }
4270:                }
4271:                if (argIndex == -1
4272:                        || (argIndex >= 0 && args.__finditem__(argIndex) != null)) {
4273:                    throw Py.TypeError("not all arguments converted");
4274:                }
4275:                if (needUnicode) {
4276:                    return new PyUnicode(buffer.toString());
4277:                }
4278:                return new PyString(buffer.toString());
4279:            }
4280:
4281:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.