Quasi 0.87 review

Download
by rbytes.net on

Quasi project is a Python shell which supports pluggable "contexts" for non-Python commands, such as OS commands, MySQLdb queries and

License: BSD License
File size: 0K
Developer: Ben
0 stars award from rbytes.net

Quasi project is a Python shell which supports pluggable "contexts" for non-Python commands, such as OS commands, MySQLdb queries and external programs.

The smart-eyed reader will have noticed the use of the built-in quoted() method in the examples above. There are a number of these that are available in the interpreter namespace (the source is, as you'd expect, in quasi.py):

* quoted() returns any string surrounded by either single or double quotes (single-quotes as default). If passed a list, it returns a list of the strings, each quoted(), joined with whitespace. Currently it uses Python's repr() as a quick-and-dirty way to do this.
* dquoted does the same, but uses double-quotes and will escape any double-quotes already in a string.
* commas() joins the elements of a list with commas; this is mostly for Windows work.
* modules() returns a list of the currently imported modules in the interpreter namespace; just to make one's working life a little easier.
* Bag() is a useful class.

Bags can behave like dicts (in that they have a keys() method, and you can access values using the x[y] syntax) or like objects (in that you can access values using the x.y syntax). You must always assign values using the former (x[y]), but after that you can reference values either way.

A Bag will also remember the order in which values were assigned; this is used in the SQL context, for example, so that a Bag's keys or values are always returned in the order that a SELECT obtained them.

There are also a number of built-in shell commands. Unlike nearly everything else that gets typed into Quasi, these execute in the namespace of the shell, not the interpreter. More on that another time, but it means that any variables your Python code may have defined are not accessible to built-in shell commands. This is why none of them need any real arguments:

* exit: exit Quasi.
* help: show lots of help on various sorts of command.
* credits: show the names of the people who have contributed to Quasi.
* license: show the Quasi (BSD-style) license.
* history: show the command history. Supports slice notation (1:20), plus history searching. For example, history sq will find all command lines that begin with "sq".
* recall: recall a previous command or set of them.

This is very useful when you've been writing indented code and want to recall a set of previous lines. Same syntax as history - specify a single line or a slice-like set of them.

Recall has a limitation; it requires a functional readline module available, to insert the recalled command into the input buffer for editing. If that can't be done, the recalled line(s) are printed to allow copying and pasting. Also, if more than one line is recalled, there's no way to edit them, so they're executed.

There are also a set of built-in commands which execute in the interpreter namespace and can, therefore, do variable-substitution trickery:

* cd: change directory. You can do cd $x to change to the directory whose path is in variable x.
* pwd: return the current working directory. You can do x=`pwd` to return the path of the current working directory into x, or just type pwd to see it.
* pushd, popd: Oh come on... they work like the bash equivalents, ok? Both return the directory where they end up, as a string, so x=`pushd subDirectory` or here=`popd` work.

Quasi 0.87 keywords