Ramblings

March 17, 2008

Python stand-alone form validation

Filed under: dev, python, tool — michaelangela @ 2:47 pm

Actually, it’s not just form validation. It’s the fact that validation is independent and it just checks a Python data set against the set validators. And with this, it can be complete classes that are set up as group validators.

What that means is within the model definition, standard key validations can be assigned using ANY database backend or ORM. That can be helpful. It could also be customized depending on the need.

FormEncode

FormEncode is a validation and form generation package. The validation can be used separately from the form generation. The validation works on compound data structures, with all parts being nestable. It is separate from HTTP or any other input mechanism.

Enhanced python string interpolation

Filed under: cool, dev, python — michaelangela @ 2:39 pm

This particular module is a bit older, but it’s supposed to work with Python 2.x. There may be a newer one floating around but I’ll have to check for that. Either way, it’s pretty cool.

Python things

This module lets you quickly and conveniently interpolate
values into strings (in the flavour of Perl or Tcl, but with
less extraneous punctuation). You get a bit more power than
in other languages, because this module allows subscripting,
slicing, function calls, attribute lookup, or arbitrary expressions.
Here are the simple interpolation rules:

  1. A dollar sign and a name, possibly followed by any of:
    • an open paren, and anything up to the matching paren
    • an open bracket, and anything up to the matching bracket
    • a period and a name

    any number of times, is evaluated as a Python expression.

  2. A dollar sign immediately followed by an open curly-brace,
    and anything up to the matching curly-brace, is evaluated as
    a Python expression.
  3. Two dollar signs in a row give you one literal dollar sign.
  4. Anything else is left alone.

Expressions are evaluated in the namespace of the caller.
This lets you painlessly do:

"Here is a $string."

"Here is a $module.member."

"Here is an $object.member."

"Here is a $functioncall(with, arguments)."

"Here is an ${arbitrary + expression}."

"Here is an $array[3] member."

"Here is a $dictionary['member']."

Python getters and setters

Filed under: dev, python — michaelangela @ 7:58 am

From the python guru himself, Guido van Rossum, we have a bit on his take of python getters and setters…

[Python-Dev] Declaring setters with getters

I've come up with a relatively unobtrusive pattern for defining
setters. Given the following definition:

def propset(prop):
assert isinstance(prop, property)
def helper(func):
return property(prop.__get__, func, func, prop.__doc__)
return helper

we can declare getters and setters as follows:

class C(object):

_encoding = None

@property
def encoding(self):
return self._encoding

@propset(encoding)
def encoding(self, value=None):
if value is not None:
unicode("0", value) # Test it
self._encoding = value

c = C()
print(c.encoding)
c.encoding = "ascii"
print(c.encoding)
try:
c.encoding = "invalid" # Fails
except:
pass
print(c.encoding)

MVC moves to the web…

Filed under: dev, web20 — michaelangela @ 2:32 am

Creating and deploying mini-apps that talk with each other over well defined protocols. Interesting…

MicroApps – Microapps.org

MicroApps are small REST applications that are designed from the ground up to be integrated with other applications. Usually, they are not directly useful on their own, but must be integrated into other applications (this is what differentiates a MicroApp from a regular REST application).

How to quicikly loc your mac

Filed under: cool, mac, tool — michaelangela @ 1:44 am

I was trying to find a way to quickly loc a mac without logging out, etc. This does the trick. There is even a keyboard shortcut that can be used as well.

Macworld | Mac OS X Hints | Quickly lock your screen

But what if you don’t want to always lock your screen when the screen saver activates or your computer wakes from sleep? In other words, you don’t want to set that option in the Security pane as you must for the methods I’ve described so far. (After all, it can be a pain to have to enter your password over and over again throughout the day.) Keychain Access holds the key.

Create a free website or blog at WordPress.com.