Internally, all policy files generated by django-flashpolicies are represented by instances of flashpolicies.policies.Policy, which understands how to handle the various permitted options in policy files and can generate the correct XML. This documentation covers Policy objects and their API, but is not and should not be taken to be documentation on the format and options for cross-domain policy files; Adobe’s cross-domain policy specification is the canonical source for that information.
For most cases, simply instantiating a Policy object with one or more domains will accomplish the desired effect. The property xml_dom will yield an xml.dom.minidom.Document object representing the policy’s XML; for information on working with these objects, consult the documentation for the xml.dom.minidom module in the Python standard library. In general, however, the toprettyxml() method of the Document will be all that’s required; this serializes the Document to a string in a particular encoding, suitable for writing to a file or serving over HTTP.
For example:
>>> from flashpolicies import policies
>>> my_policy = policies.Policy('media.example.com', 'api.example.com')
>>> print my_policy.xml_dom.toprettyxml(encoding='utf-8')
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE cross-domain-policy
SYSTEM 'http://www.adobe.com/xml/dtds/cross-domain-policy.dtd'>
<cross-domain-policy>
<allow-access-from domain="media.example.com"/>
<allow-access-from domain="api.example.com"/>
</cross-domain-policy>
Wrapper object for creating and manipulating a Flash cross-domain policy.
In the simplest case – specifying one or more domains from which to allow access – simply pass the domains to the constructor. For example:
my_policy = Policy('media.example.com', 'api.example.com')
Allow access for Flash content served from a particular domain.
Parameters: |
|
---|
Allow Flash content from a particular domain to push data via HTTP headers.
Parameters: |
|
---|
Set metapolicy information (only applicable to master policy files), determining which other policy files may be used on the same domain.
Parameter: | permitted – The metapolicy to use. Acceptable values are those listed in the cross-domain policy specification, and are also available as a set of constants defined in this module. Passing an invalid value will raise TypeError. |
---|
By default, Flash assumes a default metapolicy of master-only (except for socket policies, which assume a default of all), so if this is the desired metapolicy (and, for security reasons, it often is), this method does not need to be called.
Note that a metapolicy of none forbids all access, even if one or more domains have previously been specified as allowed. As such, setting the metapolicy to none will remove all access previously granted by allow_domain() or allow_headers(). Additionally, attempting to grant access via allow_domain() or allow_headers() will, when the metapolicy is none, raise TypeError.
For ease of working with metapolicies, the following constants are defined, and correspond to the acceptable values for metapolicies as defined in the cross-domain policy specification.