From: <fwi...@us...> - 2009-01-07 18:04:28
|
Revision: 5868 http://jython.svn.sourceforge.net/jython/?rev=5868&view=rev Author: fwierzbicki Date: 2009-01-07 18:04:18 +0000 (Wed, 07 Jan 2009) Log Message: ----------- Added ARROW. Created simple (and wrong) print() builtin for sanity checks. Added support for new octal representation. passed os.py through 2to3 converter. Modified Paths: -------------- branches/jy3k/Lib/os.py branches/jy3k/grammar/Python.g branches/jy3k/src/org/python/antlr/GrammarActions.java branches/jy3k/src/org/python/core/__builtin__.java Modified: branches/jy3k/Lib/os.py =================================================================== --- branches/jy3k/Lib/os.py 2009-01-07 17:42:04 UTC (rev 5867) +++ branches/jy3k/Lib/os.py 2009-01-07 18:04:18 UTC (rev 5868) @@ -83,7 +83,7 @@ os_name = str(java.lang.System.getProperty('os.name')) os_type = None - for type, (patterns, shell_commands) in _os_map.iteritems(): + for type, (patterns, shell_commands) in _os_map.items(): for pattern in patterns: if os_name.startswith(pattern): # determine the shell_command later, when it's needed: @@ -113,7 +113,7 @@ def getCurrentWorkingDirectory(self): return File(getcwd()) def getEnv(self): - return ['%s=%s' % (key, val) for key, val in environ.iteritems()] + return ['%s=%s' % (key, val) for key, val in environ.items()] def getInputStream(self): return getattr(java.lang.System, 'in') # XXX handle resetting def getOutputStream(self): @@ -412,7 +412,7 @@ Translate an error code to a message string. """ - if not isinstance(code, (int, long)): + if not isinstance(code, int): raise TypeError('an integer is required') constant = Errno.valueOf(code) if constant is Errno.__UNKNOWN_CONSTANT__: @@ -435,7 +435,7 @@ specified access to the path. The mode argument can be F_OK to test existence, or the inclusive-OR of R_OK, W_OK, and X_OK. """ - if not isinstance(mode, (int, long)): + if not isinstance(mode, int): raise TypeError('an integer is required') f = File(sys.getPath(path)) @@ -562,14 +562,14 @@ _time_t = Integer if Platform.IS_32_BIT else Long try: - floor = long(seconds) + floor = int(seconds) except TypeError: raise TypeError('an integer is required') if not _time_t.MIN_VALUE <= floor <= _time_t.MAX_VALUE: raise OverflowError('long int too large to convert to int') # usec can't exceed 1000000 - usec = long((seconds - floor) * 1e6) + usec = int((seconds - floor) * 1e6) if usec < 0: # If rounding gave us a negative number, truncate usec = 0 @@ -608,7 +608,7 @@ rawio = FileDescriptors.get(fd) try: rawio.truncate(length) - except Exception, e: + except Exception as e: raise IOError(errno.EBADF, strerror(errno.EBADF)) def lseek(fd, pos, how): @@ -619,7 +619,8 @@ rawio = FileDescriptors.get(fd) return _handle_oserror(rawio.seek, pos, how) -def open(filename, flag, mode=0777): +#FIXME: needs to change to mode=0o777 for 3.0 +def open(filename, flag, mode=0o777): """open(filename, flag [, mode=0777]) -> fd Open a file (for low level IO). @@ -655,7 +656,7 @@ if not File(sys.getPath(filename)).createNewFile(): raise OSError(errno.EEXIST, strerror(errno.EEXIST), filename) - except java.io.IOException, ioe: + except java.io.IOException as ioe: raise OSError(ioe) mode = '%s%s%s%s' % (reading and 'r' or '', @@ -667,7 +668,7 @@ from java.io import FileNotFoundException, RandomAccessFile try: fchannel = RandomAccessFile(sys.getPath(filename), 'rws').getChannel() - except FileNotFoundException, fnfe: + except FileNotFoundException as fnfe: if path.isdir(filename): raise OSError(errno.EISDIR, strerror(errno.EISDIR)) raise OSError(errno.ENOENT, strerror(errno.ENOENT), filename) @@ -841,7 +842,7 @@ # Note that listdir and error are globals in this module due # to earlier import-*. names = listdir(top) - except error, err: + except error as err: if onerror is not None: onerror(err) return @@ -875,7 +876,7 @@ def __init__(self, environ): UserDict.UserDict.__init__(self) data = self.data - for k, v in environ.items(): + for k, v in list(environ.items()): data[k.upper()] = v def __setitem__(self, key, item): self.data[key.upper()] = item @@ -890,7 +891,7 @@ def get(self, key, failobj=None): return self.data.get(key.upper(), failobj) def update(self, dict): - for k, v in dict.items(): + for k, v in list(dict.items()): self[k] = v def copy(self): return dict(self) @@ -1063,7 +1064,7 @@ return _posix.isatty(fileno) if not isinstance(fileno, IOBase): - print fileno + print(fileno) raise TypeError('a file descriptor is required') return fileno.isatty() Modified: branches/jy3k/grammar/Python.g =================================================================== --- branches/jy3k/grammar/Python.g 2009-01-07 17:42:04 UTC (rev 5867) +++ branches/jy3k/grammar/Python.g 2009-01-07 18:04:18 UTC (rev 5868) @@ -434,7 +434,7 @@ funcdef @init { stmt stype = null; } @after { $funcdef.tree = stype; } - : decorators? DEF NAME parameters COLON suite[false] + : decorators? DEF NAME parameters (ARROW test[expr_contextType.Load])? COLON suite[false] { Token t = $DEF; if ($decorators.start != null) { @@ -754,8 +754,7 @@ } ; -//XXX: when does CPython Grammar match "dotted_name NAME NAME"? -//dotted_as_name: dotted_name [('as' | NAME) NAME] +//dotted_as_name: dotted_name ['as' NAME] dotted_as_name returns [alias atype] @after { $dotted_as_name.tree = $atype; @@ -1569,6 +1568,8 @@ -> ^(YIELD<Yield>[$YIELD, actions.castExpr($testlist.tree)]) ; +ARROW : '->' ; + AS : 'as' ; ASSERT : 'assert' ; BREAK : 'break' ; @@ -1710,8 +1711,8 @@ INT : // Hex '0' ('x' | 'X') ( '0' .. '9' | 'a' .. 'f' | 'A' .. 'F' )+ | // Octal - '0' ( '0' .. '7' )* - | '1'..'9' DIGITS* + '0' ('o' | 'O') ( '0' .. '7' )* + | '0'..'9' DIGITS* ; COMPLEX Modified: branches/jy3k/src/org/python/antlr/GrammarActions.java =================================================================== --- branches/jy3k/src/org/python/antlr/GrammarActions.java 2009-01-07 17:42:04 UTC (rev 5867) +++ branches/jy3k/src/org/python/antlr/GrammarActions.java 2009-01-07 18:04:18 UTC (rev 5868) @@ -362,8 +362,9 @@ if (s.startsWith("0x") || s.startsWith("0X")) { radix = 16; s = s.substring(2, s.length()); - } else if (s.startsWith("0")) { + } else if (s.startsWith("0o") || s.startsWith("0O")) { radix = 8; + s = s.substring(2, s.length()); } if (s.endsWith("L") || s.endsWith("l")) { s = s.substring(0, s.length()-1); Modified: branches/jy3k/src/org/python/core/__builtin__.java =================================================================== --- branches/jy3k/src/org/python/core/__builtin__.java 2009-01-07 17:42:04 UTC (rev 5867) +++ branches/jy3k/src/org/python/core/__builtin__.java 2009-01-07 18:04:18 UTC (rev 5868) @@ -370,6 +370,7 @@ dict.__setitem__("sorted", new SortedFunction()); dict.__setitem__("all", new AllFunction()); dict.__setitem__("any", new AnyFunction()); + dict.__setitem__("print", new PrintFunction()); } public static PyObject abs(PyObject o) { @@ -1591,3 +1592,22 @@ return PyFile.TYPE.__call__(args, kwds); } } + +class PrintFunction extends PyBuiltinFunctionNarrow { + PrintFunction() { + super("print", 1, 1, + "Prints the values to a stream, or to sys.stdout by default.\n" + + "Optional keyword arguments:\n" + + "file: a file-like object (stream); defaults to the current sys.stdout.\n" + + "sep: string inserted between values, default a space." + + "end: string appended after the last value, default a newline."); + } + + @Override + public PyObject __call__(PyObject arg) { + Py.println(arg); + return Py.None; + } +} + + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |