Fixes and Enhancements since Version 0.5 alpha 3 |
Fixes and Enhancements since Version 0.5 alpha 3 |
|
|
|
- Added 'peak.running.options', a new option-parsing framework that extends |
|
'optparse' to support the PEAK 'commands' framework. Command instances |
|
can now refer to 'self.parsed_args' to find their non-option arguments, |
|
and to trigger setting of their attributes (or calling of methods) based on |
|
their raw arguments from 'self.argv'. See 'options.txt' in the |
|
'peak.running' package directory for a complete tutorial. |
|
|
|
- There is now a 'binding.initAttrs()' function that can be used to initialize |
|
an object's attributes from e.g. constructor keyword arguments, similar to |
|
how 'binding.Component' and 'binding.Attribute' constructors work. |
|
|
|
- Security permissions can now be declared as attribute metadata. |
|
|
|
That is, instead of doing declarations like this:: |
|
|
|
class Foo: |
|
bar = binding.Require("Something", permissionNeeded=SomePerm) |
|
|
|
class AnElement(model.Element): |
|
class someFeature(model.Attribute): |
|
permissionNeeded = SomePerm |
|
|
|
you can (and should) now do them like this:: |
|
|
|
class Foo: |
|
bar = binding.Require("Something", [SomePerm]) |
|
|
|
class AnElement(model.Element): |
|
class someFeature(model.Attribute): |
|
metadata = [SomePerm] |
|
|
|
or this:: |
|
|
|
class Foo: |
|
binding.metadata(bar = [SomePerm]) |
|
|
|
class AnElement(model.Element): |
|
|
|
binding.metadata(someFeature = [SomePerm]) |
|
|
|
class someFeature(model.Attribute): |
|
# ... |
|
|
|
It isn't necessary to enclose metadata in brackets, but it helps to |
|
emphasize its annotational nature. Also note that e.g. 'web.bindResource()' |
|
needs 'metadata' to be a keyword argument. |
|
|
|
- The 'permissionNeeded' attribute of 'model.Feature' and 'binding.Attribute' |
|
objects is now DEPRECATED. See examples above for how to upgrade, and please |
|
switch to using metadata as soon as practical. In addition the |
|
'security.IGuardedDescriptor' interface has been removed, because it was |
|
only used in connection with the 'permissionNeeded' attribute mechanism. |
|
|
|
- Added a new "attribute metadata" mini-framework to 'peak.binding'. This |
|
framework makes it possible to declare arbitrary metadata about attributes, |
|
using either a class advisor ('binding.metadata()', similar in form and |
|
function to the existing 'security.allow()') or using a 'metadata' attribute |
|
of attribute bindings (which is the second positional parameter in all |
|
the standard bindings like 'Make', 'Obtain', etc.). Over time, existing |
|
metadata mechanisms will be refactored to use this new mini-framework, |
|
instead of the various integrated ad-hoc mechanisms that exist now (like |
|
the 'permissionNeeded' attribute). For more information on how the new |
|
metadata hooks work, including doctest examples, see the 'attributes.txt' |
|
file in the 'peak.binding' package, under the heading "Attribute Metadata". |
|
|
|
- Added a new function, 'binding.activateClass()', that can be used to |
|
activate any bindings in the class. This can now be used in place of |
|
subclassing a PEAK base class or using a PEAK metaclass. In future, this |
|
will be integrated into PEAK attribute descriptors such that defining a |
|
descriptor within a class' body is sufficient to cause this function to be |
|
invoked. |
|
|
|
- 'binding.IBindingNode' was REMOVED, consolidated into 'binding.IComponent', |
|
as its various individual methods have been replaced with generic functions |
|
in the existing 'binding' API. For example, 'binding.getParentComponent(x)' |
|
should be used in preference to 'x.getParentComponent()' unless it is |
|
a requirement that 'x' implement the full 'binding.IComponent' interface. |
|
This makes it easier to define what 'binding.getParentComponent()' and |
|
'binding.getComponentName()' will mean for non-component types, as you do |
|
not have to define an adapter class with all of the 'IBindingNode' methods. |
|
Also, this makes PEAK itself cleaner, as we often weren't bothering to |
|
properly implement the full 'IBindingNode' interface anyway. |
|
|
|
In addition, 'binding.suggestParentComponent()' is now also a generic |
|
function, dispatching on the target (i.e. child) object. |
|
|
|
- 'naming.IReferenceable' was REMOVED, as it is not in use anywhere in PEAK. |
|
This will be replaced with a generic function when we do actually need this |
|
functionality. |
|
|
|
- There is a new 'config.getStreamFactory' generic function, to make it easy |
|
to accept URLs, filenames, or 'naming.IStreamFactory' objects as the source |
|
of a "file". |
|
|
|
Its typical usage is just:: |
|
|
|
factory = config.getStreamFactory(self,source) |
|
stream = factory.open('t') # open for reading in text mode |
|
|
|
where 'source' is a string or a 'naming.IStreamFactory', and 'self' is a |
|
component to be used as lookup context. The returned 'factory' is a |
|
'naming.IStreamFactory' that can then be '.open()'-ed for reading, or used |
|
in other ways as needed. |
|
|
|
If you have special objects that you'd like to be able to treat as stream |
|
sources, you can register them by defining an extension, e.g.:: |
|
|
|
[config.getStreamFactory.when(MyType)] |
|
def getStreamFactory(context,source): |
|
"""Return a naming.IStreamFactory for 'source' (a 'MyType' instance)""" |
|
|
|
Wherever practical, as we encounter them, we'll be changing PEAK API's that |
|
take filenames to also accept stream sources. |
|
|
|
- Added an optional 'base' argument to 'naming.parseURL()', to allow parsing |
|
URLs relative to a base URL. For a URL scheme to support this, it must |
|
implement the new 'naming.IBaseURL' interface. See the |
|
'peak.naming.factories.openable' module for example implementations. |
|
|
|
- Added a 'data:' URL scheme, implementing RFC 2397 (although it's not as |
|
strict in its parsing of the content type and parameters as the RFC calls |
|
for). This is a semi-convenient way to provide configuration data in-line, |
|
since a 'data:' URL can be a 'config.getStreamFactory()' source. |
|
|
- Added 'config.processXML()', a function that provides a high-level, |
- Added 'config.processXML()', a function that provides a high-level, |
configuration-driven interface to 'peak.util.SOX.NegotiatingParser'. This |
configuration-driven interface to 'peak.util.SOX.NegotiatingParser'. This |
simple front-end lets you supply as little as a configuration context and |
simple front-end lets you supply as little as a configuration context and |
you will need to rewrite appropriately. |
you will need to rewrite appropriately. |
|
|
- 'config.loadConfigFile()' and 'config.loadConfigFiles()' now accept URLs, |
- 'config.loadConfigFile()' and 'config.loadConfigFiles()' now accept URLs, |
'naming.IStreamFactory' objects, and 'config.IStreamSource' objects as well |
'naming.IStreamFactory' objects, and other 'config.getStreamFactory()' |
as filenames. This was primarily added to support use of |
targets as well as filenames. This was primarily added to support use of |
'config.packageFile()' or 'pkgfile:' URLs, in place of using |
'config.packageFile()' or 'pkgfile:' URLs, in place of using |
'config.fileNearModule()'. |
'config.fileNearModule()'. |
|
|
- There is a new 'config.IStreamSource' protocol, to make it easy to accept |
|
URLs, filenames, or 'naming.IStreamFactory' objects as the source of a |
|
"file". |
|
|
|
Its typical usage is just:: |
|
|
|
factory = config.IStreamSource(data).getFactory(self) |
|
stream = factory.open('t') # open for reading in text mode |
|
|
|
where 'data' is a string or a 'naming.IStreamFactory', and 'self' is a |
|
component to be used as lookup context. The returned 'factory' is a |
|
'naming.IStreamFactory' that can then be '.open()'-ed for reading, or used |
|
in other ways as needed. |
|
|
|
Wherever practical, as we encounter them, we'll be changing PEAK API's that |
|
take filenames to also accept stream sources. |
|
|
|
- The 'naming.IStreamFactory' interface now has an 'address' attribute, which |
- The 'naming.IStreamFactory' interface now has an 'address' attribute, which |
is the string form of the canonical URL of the target stream. This was |
is the string form of the canonical URL of the target stream. This was |
added to make it easier to e.g. report errors in a stream that's being |
added to make it easier to e.g. report errors in a stream that's being |