Python: module booman.token

booman.token | index booman/token.py

`# Boodler: a programmable soundscape tool
# Copyright 2007-9 by Andrew Plotkin <erkyrath@eblong.com>
# <http://boodler.org/>
# This program is distributed under the LGPL.
# See the LGPL document, or the above URL, for details.`

Modules
`` |  |
boopak.collect os | boopak.pinfo readline | boopak.version |

Classes
`` |  | InputSource Token PackageFileURLToken PackageOptVersionToken PackageToken PathToken DirToken FileToken ResourceToken YesNoToken
class DirToken(PathToken)
`` | `DirToken: Grab the name of a file. DirToken(mustexist=True) -- constructor If mustexist is True, this only accepts the name of a directory which exists.`
| Method resolution order: DirToken PathToken Token Methods defined here: accept(self, source) Data and other attributes defined here: prompt = 'dir' Methods inherited from PathToken: __init__(self, mustexist=True)
class FileToken(PathToken)
`` | `FileToken: Grab the name of a file. FileToken(mustexist=True) -- constructor If mustexist is True, this only accepts the name of a file which exists.`
| Method resolution order: FileToken PathToken Token Methods defined here: accept(self, source) Data and other attributes defined here: prompt = 'file' Methods inherited from PathToken: __init__(self, mustexist=True)
class InputSource
`` | `InputSource: represents the user's input (which may include command- line arguments and pieces of previously-typed commands). Various Tokens pull information out of the InputSource; when it is empty, it asks for more from the user. A Token can also push information back into the InputSource, which means that lookahead is possible. InputSource(args=None) -- constructor The args, if supplied, should be a list of shell-style arguments. (That is, entries may contain whitespace; and the whitespace should be considered to be a part of the entries, as opposed to separating entries.) Methods: is_empty() -- check whether any input is currently stored up pop_word() -- grab one word of input push_word() -- push back one word of input drain() -- grab all remaining words of input`
| Methods defined here: __init__(self, args=None) drain(self) `drain() -> list of str Grab all the remaining words of input, and return them as a list. If the InputSource is empty, this returns an empty list.` is_empty(self) `is_empty() -> bool Check whether any input is currently stored up.` pop_word(self, tok) `pop_word(tok) -> str Grab one word of input. This typically means one whitespace- delimited word (although arguments from the command line are treated a bit differently). If no input is available, the user is prompted for some, using the token argument's prompt.` push_word(self, val) `push_word(val) -> None Push back one word of input. This will become the next word popped.` Data and other attributes defined here: EMPTY = 0 LINE = 2 SHELL = 1
class PackageFileURLToken(Token)
`` | `PackageFileURLToken: Grab the name of a package (including version number if available), or a filename, or a URL. Returns one of the tuples (collect.Source_PACKAGE, (pkgname, vers)) (collect.Source_FILE, filename) (collect.Source_URL, url) This uses some slightly rough heuristics to decide what's a package name and what's a filename.`
| Methods defined here: accept(self, source) Data and other attributes defined here: greedy = True prompt = 'package/file/url'
class PackageOptVersionToken(Token)
`` | `PackageOptVersionToken: Grab the name of a package, and also a version number (if one is provided). Returns (pkgname, vers) where vers may be a VersionNumber, VersionSpec, or None.`
| Methods defined here: accept(self, source) Data and other attributes defined here: greedy = True prompt = 'package'
class PackageToken(Token)
`` | `PackageToken: Grab the name of a package.`
| Methods defined here: accept(self, source) Data and other attributes defined here: prompt = 'package'
class PathToken(Token)
`` | `PathToken: Grab the name of a file or directory. PathToken(mustexist=True) -- constructor If mustexist is True, this only accepts the name of a file or directory which exists.`
| Methods defined here: __init__(self, mustexist=True) accept(self, source) Data and other attributes defined here: prompt = 'path'
class ResourceToken(Token)
`` | `ResourceToken: Grab the name of a resource. This must be pkgname/resource, pkgname:spec/resource, or pkgname::vers/resource. Returns ((pkgname, vers), resource), where vers will be None, a VersionSpec, or a VersionNumber.`
| Methods defined here: accept(self, source) Data and other attributes defined here: prompt = 'resource'
class Token
`` | `Token: represents a command element to be parsed. Or you can think of it this way: a Token is an object which can grab an element from the user's input (whether from a prompt or from a command-line argument). Each subclass of Token grabs a particular kind of element. For example, CommandToken (in command.py) grabs a word that matches one of the commands (help, quit, etc). Publicly readable fields: prompt -- the string to use when prompting for this element (by itself) Methods: accept() -- grab the desired command element and return it.`
| Methods defined here: accept(self, source) `accept(source) -> value Grab the desired command element from the given InputSource, and return it. The type of value returned depends on the Token subclass. (Raising KeyboardInterrupt is always a possibility.)` Data and other attributes defined here: prompt = ''
class YesNoToken(Token)
`` | `YesNoToken: Grab a "yes" or "no" element from the user. This token is always interactive; ignores command-line arguments and dangling parts of the InputSource, and goes straight for input_line(). Returns True or False. (But not CommandCancelled.)`
| Methods defined here: accept(self, source) Data and other attributes defined here: prompt = 'yes/no'

Functions
`` |  | input_line(prompt='') `input_line(prompt='') -> str Read a line of text, using readline (if available). The prompt will be ">" following the optional prompt argument. The line returned will be whitespace-stripped. If the user enters an empty line, this raises CommandCancelled. If the user interrupts the program, this raises KeyboardInterrupt. (EOF on stdin also appears as a KeyboardInterrupt.)`