python.modules: vocab hierarchy for standard library modules

pre-existing bindings for various python modules can be placed here so
that they dont have to be redeclared for everyone using them
db4
Björn Lindqvist 2014-10-27 13:24:33 +01:00 committed by Doug Coleman
parent 87b0205c87
commit e819e34cec
8 changed files with 68 additions and 5 deletions

View File

@ -0,0 +1,31 @@
USING: python.syntax ;
IN: python.modules.__builtin__
PY-FROM: __builtin__ =>
callable ( obj -- ? )
dir ( obj -- seq )
int ( val -- s )
len ( seq -- n )
open ( name mode -- file )
range ( n -- seq )
repr ( obj -- str ) ;
PY-METHODS: obj =>
__name__ ( self -- n )
__str__ ( o -- str ) ;
PY-METHODS: file =>
close ( self -- )
fileno ( self -- n )
tell ( self -- n ) ;
PY-METHODS: str =>
lower ( self -- self' )
partition ( self sep -- bef sep aft )
startswith ( self str -- ? )
title ( self -- self' )
zfill ( self n -- str' ) ;
PY-METHODS: list =>
append ( list obj -- )
remove ( list obj -- ) ;

View File

@ -0,0 +1,7 @@
USING: python.syntax ;
IN: python.modules.argparse
PY-FROM: argparse => ArgumentParser ( -- self ) ;
PY-METHODS: ArgumentParser =>
add_argument ( self name ** -- )
format_help ( self -- str ) ;

View File

@ -0,0 +1,4 @@
USING: python.syntax ;
IN: python.modules.datetime
PY-FROM: datetime => timedelta ( ** -- timedelta ) ;

View File

@ -0,0 +1,6 @@
USING: python.syntax ;
IN: python.modules.os
PY-FROM: os =>
getpid ( -- y )
system ( x -- y ) ;

View File

@ -0,0 +1,6 @@
USING: python.syntax ;
IN: python.modules.os.path
PY-FROM: os.path =>
basename ( x -- x' )
splitext ( x -- base ext ) ;

View File

@ -0,0 +1,8 @@
USING: python.syntax ;
IN: python.modules.sys
PY-FROM: sys =>
path ( -- seq )
argv ( -- seq )
getrefcount ( obj -- n )
platform ( -- x ) ;

View File

@ -0,0 +1,4 @@
USING: python.syntax ;
IN: python.modules.time
PY-FROM: time => sleep ( n -- ) ;

View File

@ -1,12 +1,9 @@
USING: arrays kernel python python.ffi python.syntax sequences ; USING: arrays kernel python python.ffi python.modules.__builtin__ python.syntax
sequences ;
IN: python.throwing IN: python.throwing
PY-FROM: traceback => format_tb ( tb -- seq ) ; PY-FROM: traceback => format_tb ( tb -- seq ) ;
PY-METHODS: obj =>
__name__ ( o -- str )
__str__ ( o -- str ) ;
: throw-error ( ptype pvalue ptraceback -- ) : throw-error ( ptype pvalue ptraceback -- )
[ [
[ $__name__ py> ] [ $__name__ py> ]