Top Description Fields Constructors Methods
org.python.core

public Class ArgParser

extends Object
Class Inheritance
Imports
org.python.antlr.AST, java.util.HashSet, .Set

A utility class for handling mixed positional and keyword arguments. Typical usage:
  public MatchObject search(PyObject[] args, String[] kws) {
      ArgParser ap = new ArgParser("search", args, kws,
                                   "pattern", "pos", "endpos");
      String string = ap.getString(0);
      int start     = ap.getInt(1, 0);
      int end       = ap.getInt(2, string.length());
      ...

Field Summary

Modifier and TypeField and Description
private PyObject[]
private static String[]
private String
private String[]
private String[]
private static Object

Constructor Summary

AccessConstructor and Description
private
ArgParser(String funcname, PyObject[] args, String[] kws)

public
ArgParser(String
Name of the function. Used in error messages.
funcname
,
PyObject[]
The actual call arguments supplied in the call.
args
,
String[]
The actual keyword names supplied in the call.
kws
,
String
The expected argument in the function definition.
p0
)

Create an ArgParser for a one-argument function.

public
ArgParser(String
Name of the function. Used in error messages.
funcname
,
PyObject[]
The actual call arguments supplied in the call.
args
,
String[]
The actual keyword names supplied in the call.
kws
,
String
The first expected argument in the function definition.
p0
,
String
The second expected argument in the function definition.
p1
)

Create an ArgParser for a two-argument function.

public
ArgParser(String
Name of the function. Used in error messages.
funcname
,
PyObject[]
The actual call arguments supplied in the call.
args
,
String[]
The actual keyword names supplied in the call.
kws
,
String
The first expected argument in the function definition.
p0
,
String
The second expected argument in the function definition.
p1
,
String
The third expected argument in the function definition.
p2
)

Create an ArgParser for a three-argument function.

public
ArgParser(String
Name of the function. Used in error messages.
funcname
,
PyObject[]
The actual call arguments supplied in the call.
args
,
String[]
The actual keyword names supplied in the call.
kws
,
String[]
The list of expected argument in the function definition.
paramnames
)

Create an ArgParser for a multi-argument function.

public
ArgParser(String funcname, PyObject[] args, String[] kws, String[] paramnames, int minargs)

public
ArgParser(String funcname, PyObject[] args, String[] kws, String[] paramnames, int minargs, boolean takesZeroArgs)

Method Summary

Modifier and TypeMethod and Description
private int

Returns:

value as an int
asInt
(PyObject
a PyObject
value
)

Convert a PyObject to a Java integer.

private void
private static PyObject
checkedForType(PyObject arg, int pos, PyType type)

private Object
getArg(int pos, Class<T> clss, String classname)

private Object
getArg(int pos, Class<T> clss, String classname, Object def)

public int
getIndex(int
The position of the argument. First argument is numbered 0.
pos
)

Return an required argument as an index.

public int
getIndex(int
The position of the argument. First argument is numbered 0.
pos
,
int def)

Return an optional argument as an index.

public int
getInt(int
The position of the argument. First argument is numbered 0.
pos
)

Return a required argument as an int.

public int
getInt(int
The position of the argument. First argument is numbered 0.
pos
,
int def)

Return an optional argument as an int.

public PyObject
getList(int
The position of the argument. First argument is numbered 0.
pos
)

Return the remaining arguments as a tuple.

private PyObject
getOptionalArg(int pos)

public PyObject
getPyObject(int
The position of the argument. First argument is numbered 0.
pos
)

Return a required argument as a PyObject.

public PyObject
getPyObject(int
The position of the argument. First argument is numbered 0.
pos
,
PyObject def)

Return an optional argument as a PyObject.

public PyObject

Returns:

the PyObject of PyType type
getPyObjectByType
(int
the position of the argument. First argument is numbered 0
pos
,
PyType
the desired PyType of the argument
type
)

Return a required argument as a PyObject, ensuring the object is of the specified type.

public PyObject

Returns:

the PyObject of PyType type
getPyObjectByType
(int
the position of the argument. First argument is numbered 0
pos
,
PyType
the desired PyType of the argument
type
,
PyObject
to return if the argument at pos was not given (null allowed)
def
)

Return an optional argument as a PyObject, or return the default value provided, which may be null.

private PyObject
getRequiredArg(int pos)

public String
getString(int
The position of the .. First argument is numbered 0.
pos
)

Return a required argument as a String.

public String
getString(int
The position of the argument. First argument is numbered 0.
pos
,
String def)

Return an optional argument as a String.

public void
noKeywords()

Ensure no keyword arguments were passed, raising a TypeError if so.

private static String
ordinal(int n)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

argsback to summary
private PyObject[] args
emptyKwsback to summary
private static String[] emptyKws
funcnameback to summary
private String funcname
kwsback to summary
private String[] kws
paramsback to summary
private String[] params
requiredback to summary
private static Object required

Constructor Detail

ArgParserback to summary
private ArgParser(String funcname, PyObject[] args, String[] kws)
ArgParserback to summary
public ArgParser(String funcname, PyObject[] args, String[] kws, String p0)

Create an ArgParser for a one-argument function.

Parameters
funcname:String

Name of the function. Used in error messages.

args:PyObject[]

The actual call arguments supplied in the call.

kws:String[]

The actual keyword names supplied in the call.

p0:String

The expected argument in the function definition.

ArgParserback to summary
public ArgParser(String funcname, PyObject[] args, String[] kws, String p0, String p1)

Create an ArgParser for a two-argument function.

Parameters
funcname:String

Name of the function. Used in error messages.

args:PyObject[]

The actual call arguments supplied in the call.

kws:String[]

The actual keyword names supplied in the call.

p0:String

The first expected argument in the function definition.

p1:String

The second expected argument in the function definition.

ArgParserback to summary
public ArgParser(String funcname, PyObject[] args, String[] kws, String p0, String p1, String p2)

Create an ArgParser for a three-argument function.

Parameters
funcname:String

Name of the function. Used in error messages.

args:PyObject[]

The actual call arguments supplied in the call.

kws:String[]

The actual keyword names supplied in the call.

p0:String

The first expected argument in the function definition.

p1:String

The second expected argument in the function definition.

p2:String

The third expected argument in the function definition.

ArgParserback to summary
public ArgParser(String funcname, PyObject[] args, String[] kws, String[] paramnames)

Create an ArgParser for a multi-argument function.

Parameters
funcname:String

Name of the function. Used in error messages.

args:PyObject[]

The actual call arguments supplied in the call.

kws:String[]

The actual keyword names supplied in the call.

paramnames:String[]

The list of expected argument in the function definition.

ArgParserback to summary
public ArgParser(String funcname, PyObject[] args, String[] kws, String[] paramnames, int minargs)
ArgParserback to summary
public ArgParser(String funcname, PyObject[] args, String[] kws, String[] paramnames, int minargs, boolean takesZeroArgs)

Method Detail

asIntback to summary
private int asInt(PyObject value)

Convert a PyObject to a Java integer.

Parameters
value:PyObject

a PyObject

Returns:int

value as an int

checkback to summary
private void check()
checkedForTypeback to summary
private static PyObject checkedForType(PyObject arg, int pos, PyType type)
getArgback to summary
private Object getArg(int pos, Class<T> clss, String classname)
getArgback to summary
private Object getArg(int pos, Class<T> clss, String classname, Object def)
getIndexback to summary
public int getIndex(int pos)

Return an required argument as an index.

Parameters
pos:int

The position of the argument. First argument is numbered 0.

getIndexback to summary
public int getIndex(int pos, int def)

Return an optional argument as an index.

Parameters
pos:int

The position of the argument. First argument is numbered 0.

getIntback to summary
public int getInt(int pos)

Return a required argument as an int.

Parameters
pos:int

The position of the argument. First argument is numbered 0.

getIntback to summary
public int getInt(int pos, int def)

Return an optional argument as an int.

Parameters
pos:int

The position of the argument. First argument is numbered 0.

getListback to summary
public PyObject getList(int pos)

Return the remaining arguments as a tuple.

Parameters
pos:int

The position of the argument. First argument is numbered 0.

getOptionalArgback to summary
private PyObject getOptionalArg(int pos)
getPyObjectback to summary
public PyObject getPyObject(int pos)

Return a required argument as a PyObject.

Parameters
pos:int

The position of the argument. First argument is numbered 0.

getPyObjectback to summary
public PyObject getPyObject(int pos, PyObject def)

Return an optional argument as a PyObject.

Parameters
pos:int

The position of the argument. First argument is numbered 0.

getPyObjectByTypeback to summary
public PyObject getPyObjectByType(int pos, PyType type)

Return a required argument as a PyObject, ensuring the object is of the specified type.

Parameters
pos:int

the position of the argument. First argument is numbered 0

type:PyType

the desired PyType of the argument

Returns:PyObject

the PyObject of PyType type

getPyObjectByTypeback to summary
public PyObject getPyObjectByType(int pos, PyType type, PyObject def)

Return an optional argument as a PyObject, or return the default value provided, which may be null. If the returned value is not null, it must be of the specified type.

Parameters
pos:int

the position of the argument. First argument is numbered 0

type:PyType

the desired PyType of the argument

def:PyObject

to return if the argument at pos was not given (null allowed)

Returns:PyObject

the PyObject of PyType type

getRequiredArgback to summary
private PyObject getRequiredArg(int pos)
getStringback to summary
public String getString(int pos)

Return a required argument as a String.

Parameters
pos:int

The position of the .. First argument is numbered 0.

getStringback to summary
public String getString(int pos, String def)

Return an optional argument as a String.

Parameters
pos:int

The position of the argument. First argument is numbered 0.

noKeywordsback to summary
public void noKeywords()

Ensure no keyword arguments were passed, raising a TypeError if so.

ordinalback to summary
private static String ordinal(int n)