Package org.python.core
Class ArgParser
java.lang.Object
org.python.core.ArgParser
A utility class for handling mixed positional and keyword arguments.
A 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());
...
-
Constructor Summary
ConstructorsConstructorDescriptionCreate an ArgParser with one method argumentCreate an ArgParser with three method argumentCreate an ArgParser with two method argumentCreate an ArgParser with three method argument -
Method Summary
Modifier and TypeMethodDescriptionintgetInt(int pos) Return a required argument as an int.intgetInt(int pos, int def) Return an optional argument as an int.getList(int pos) Return the remaining arguments as a tuple.getPyObject(int pos) Return a required argument as a PyObject.getPyObject(int pos, PyObject def) Return an optional argument as a PyObject.getString(int pos) Return a required argument as a String.Return an optional argument as a String.
-
Constructor Details
-
ArgParser
Create an ArgParser with one method argument- Parameters:
funcname- Name of the method. Used in error messages.args- The actual call arguments supplied in the call.kws- The actual keyword names supplied in the call.p0- The expected argument in the method definition.
-
ArgParser
Create an ArgParser with two method argument- Parameters:
funcname- Name of the method. Used in error messages.args- The actual call arguments supplied in the call.kws- The actual keyword names supplied in the call.p0- The first expected argument in the method definition.p1- The second expected argument in the method definition.
-
ArgParser
Create an ArgParser with three method argument- Parameters:
funcname- Name of the method. Used in error messages.args- The actual call arguments supplied in the call.kws- The actual keyword names supplied in the call.p0- The first expected argument in the method definition.p1- The second expected argument in the method definition.p2- The third expected argument in the method definition.
-
ArgParser
Create an ArgParser with three method argument- Parameters:
funcname- Name of the method. Used in error messages.args- The actual call arguments supplied in the call.kws- The actual keyword names supplied in the call.paramnames- The list of expected argument in the method definition.
-
ArgParser
-
-
Method Details
-
getString
Return a required argument as a String.- Parameters:
pos- The position of the .. First argument is numbered 0.
-
getString
Return an optional argument as a String.- Parameters:
pos- The position of the argument. First argument is numbered 0.
-
getInt
public int getInt(int pos) Return a required argument as an int.- Parameters:
pos- The position of the argument. First argument is numbered 0.
-
getInt
public int getInt(int pos, int def) Return an optional argument as an int.- Parameters:
pos- The position of the argument. First argument is numbered 0.
-
getPyObject
Return a required argument as a PyObject.- Parameters:
pos- The position of the argument. First argument is numbered 0.
-
getPyObject
Return an optional argument as a PyObject.- Parameters:
pos- The position of the argument. First argument is numbered 0.
-
getList
Return the remaining arguments as a tuple.- Parameters:
pos- The position of the argument. First argument is numbered 0.
-