Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Static Public Attributes
test.test_optparse.TestExtendAddTypes.MyOption Class Reference
Inheritance diagram for test.test_optparse.TestExtendAddTypes.MyOption:
Inheritance graph
[legend]
Collaboration diagram for test.test_optparse.TestExtendAddTypes.MyOption:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def check_file
def __str__
def takes_value
def get_opt_string
def check_value
def convert_value
def process
def take_action

Public Attributes

 action
 type
 dest
 nargs

Static Public Attributes

tuple TYPES = Option.TYPES+("file",)
tuple TYPE_CHECKER = copy.copy(Option.TYPE_CHECKER)
list ATTRS
tuple ACTIONS
tuple STORE_ACTIONS
tuple TYPED_ACTIONS
tuple ALWAYS_TYPED_ACTIONS
tuple CONST_ACTIONS
 CHECK_METHODS = None
list CHECK_METHODS

Detailed Description

Definition at line 1013 of file test_optparse.py.


Member Function Documentation

def optparse.Option.__str__ (   self) [inherited]

Definition at line 745 of file optparse.py.

00745 
00746     def __str__(self):
00747         return "/".join(self._short_opts + self._long_opts)

def test.test_optparse.TestExtendAddTypes.MyOption.check_file (   option,
  opt,
  value 
)

Definition at line 1014 of file test_optparse.py.

01014 
01015         def check_file(option, opt, value):
01016             if not os.path.exists(value):
01017                 raise OptionValueError("%s: file does not exist" % value)
01018             elif not os.path.isfile(value):
01019                 raise OptionValueError("%s: not a regular file" % value)
01020             return value

def optparse.Option.check_value (   self,
  opt,
  value 
) [inherited]

Definition at line 762 of file optparse.py.

00762 
00763     def check_value(self, opt, value):
00764         checker = self.TYPE_CHECKER.get(self.type)
00765         if checker is None:
00766             return value
00767         else:
00768             return checker(self, opt, value)

Here is the call graph for this function:

Here is the caller graph for this function:

def optparse.Option.convert_value (   self,
  opt,
  value 
) [inherited]

Definition at line 769 of file optparse.py.

00769 
00770     def convert_value(self, opt, value):
00771         if value is not None:
00772             if self.nargs == 1:
00773                 return self.check_value(opt, value)
00774             else:
00775                 return tuple([self.check_value(opt, v) for v in value])

Here is the call graph for this function:

Here is the caller graph for this function:

def optparse.Option.get_opt_string (   self) [inherited]

Definition at line 753 of file optparse.py.

00753 
00754     def get_opt_string(self):
00755         if self._long_opts:
00756             return self._long_opts[0]
00757         else:
00758             return self._short_opts[0]
00759 

def optparse.Option.process (   self,
  opt,
  value,
  values,
  parser 
) [inherited]

Definition at line 776 of file optparse.py.

00776 
00777     def process(self, opt, value, values, parser):
00778 
00779         # First, convert the value(s) to the right type.  Howl if any
00780         # value(s) are bogus.
00781         value = self.convert_value(opt, value)
00782 
00783         # And then take whatever action is expected of us.
00784         # This is a separate method to make life easier for
00785         # subclasses to add new actions.
00786         return self.take_action(
00787             self.action, self.dest, opt, value, values, parser)

Here is the call graph for this function:

def optparse.Option.take_action (   self,
  action,
  dest,
  opt,
  value,
  values,
  parser 
) [inherited]

Reimplemented in test.test_optparse.TestExtendAddActions.MyOption.

Definition at line 788 of file optparse.py.

00788 
00789     def take_action(self, action, dest, opt, value, values, parser):
00790         if action == "store":
00791             setattr(values, dest, value)
00792         elif action == "store_const":
00793             setattr(values, dest, self.const)
00794         elif action == "store_true":
00795             setattr(values, dest, True)
00796         elif action == "store_false":
00797             setattr(values, dest, False)
00798         elif action == "append":
00799             values.ensure_value(dest, []).append(value)
00800         elif action == "append_const":
00801             values.ensure_value(dest, []).append(self.const)
00802         elif action == "count":
00803             setattr(values, dest, values.ensure_value(dest, 0) + 1)
00804         elif action == "callback":
00805             args = self.callback_args or ()
00806             kwargs = self.callback_kwargs or {}
00807             self.callback(self, opt, value, parser, *args, **kwargs)
00808         elif action == "help":
00809             parser.print_help()
00810             parser.exit()
00811         elif action == "version":
00812             parser.print_version()
00813             parser.exit()
00814         else:
00815             raise ValueError("unknown action %r" % self.action)
00816 
00817         return 1
00818 
00819 # class Option
00820 

Here is the call graph for this function:

Here is the caller graph for this function:

def optparse.Option.takes_value (   self) [inherited]

Definition at line 750 of file optparse.py.

00750 
00751     def takes_value(self):
00752         return self.type is not None


Member Data Documentation

Definition at line 629 of file optparse.py.

tuple optparse.Option.ACTIONS [static, inherited]
Initial value:
("store",
               "store_const",
               "store_true",
               "store_false",
               "append",
               "append_const",
               "count",
               "callback",
               "help",
               "version")

Reimplemented in test.test_optparse.TestExtendAddActions.MyOption.

Definition at line 481 of file optparse.py.

tuple optparse.Option.ALWAYS_TYPED_ACTIONS [static, inherited]
Initial value:
("store",
                            "append")

Definition at line 511 of file optparse.py.

list optparse.Option.ATTRS [static, inherited]
Initial value:
['action',
             'type',
             'dest',
             'default',
             'nargs',
             'const',
             'choices',
             'callback',
             'callback_args',
             'callback_kwargs',
             'help',
             'metavar']

Definition at line 466 of file optparse.py.

optparse.Option.CHECK_METHODS = None [static, inherited]

Definition at line 554 of file optparse.py.

list optparse.Option.CHECK_METHODS [static, inherited]
Initial value:
[_check_action,
                     _check_type,
                     _check_choice,
                     _check_dest,
                     _check_const,
                     _check_nargs,
                     _check_callback]

Definition at line 734 of file optparse.py.

tuple optparse.Option.CONST_ACTIONS [static, inherited]
Initial value:
("store_const",
                     "append_const")

Definition at line 515 of file optparse.py.

optparse.Option.dest [inherited]

Definition at line 687 of file optparse.py.

optparse.Option.nargs [inherited]

Definition at line 700 of file optparse.py.

tuple optparse.Option.STORE_ACTIONS [static, inherited]
Initial value:
("store",
                     "store_const",
                     "store_true",
                     "store_false",
                     "append",
                     "append_const",
                     "count")

Reimplemented in test.test_optparse.TestExtendAddActions.MyOption.

Definition at line 495 of file optparse.py.

optparse.Option.type [inherited]

Definition at line 638 of file optparse.py.

Reimplemented from optparse.Option.

Definition at line 1022 of file test_optparse.py.

tuple optparse.Option.TYPED_ACTIONS [static, inherited]
Initial value:
("store",
                     "append",
                     "callback")

Reimplemented in test.test_optparse.TestExtendAddActions.MyOption.

Definition at line 505 of file optparse.py.

Reimplemented from optparse.Option.

Definition at line 1021 of file test_optparse.py.


The documentation for this class was generated from the following file: