This rst file is for testing the various Sphinx styles and class conversions that we’ll find in a Sphinx rst file. Ideally we want to run through everything pretty often.
Here we’re going to test some code blocks.
import os
from xml.etree import ElementTree
class AscDescBase(object): # pylint: disable=R0903
"""Base class for most Asc XML type nodes, allows for infinite desc
Description
~~~~~~~~~~~
This class is meant to be inherited by any node type that uses description
fields.
**Attributes:**
desc : [str]
Since all Asc nodes which can contain a single description, can
actually contain an infinite number of descriptions, the desc
attribute is a list, allowing us to store every single description
found during parsing.
Setting desc directly will cause the value given to append to the
end of the list, but desc can also be replaced by passing it a list
or tuple. Desc can be emptied by passing it None, [] or ().
**Public Methods:**
parse_xml_descs()
Parses an ElementTree Element for any Description tags and appends
any text they contain to the ``desc``.
"""
def __init__(self):
super(AscDescBase, self).__init__()
self._desc = []
# Properties ==============================================================
@property
def desc(self):
"""Returns the list of descriptions"""
return self._desc
@desc.setter
def desc(self, value):
"""Adds an entry to the descriptions"""
if value is None:
self._desc = []
elif type(value) in [list, tuple]:
self._desc = list(value)
else:
self._desc.append(value)
# Public Methods ==========================================================
def parse_xml_descs(self, xml_element):
"""Parses an ElementTree element to find & add any descriptions
**Args:**
xml_element : (``xml.etree.ElementTree.Element``)
The element to parse for Description elements. Any found
will be appended to the end of ``desc``
**Returns:**
None
**Raises:**
None
"""
for desc_entry in xml_element.findall('Description'):
if desc_entry.text: # Don't attend if text returns none
self.desc.append(desc_entry.text)
Wow wasn’t that a great code block! How about some console stuff now.
$ ls
art modules octopress thorium
$ cd modules/
$ ls
animatedSnap3D cardToTrack iconPanel viewerSync
$ cd animatedSnap3D/
$ tree
.
├── LICENSE
├── MANIFEST.in
├── README.rst
├── animatedSnap3D
│ ├── __init__.py
│ └── animatedSnap3D.py
└── setup.py
1 directory, 6 files
Wow that was some more great code.
Let’s try some basic line numbered code.
1 2 3 4 5 6 7 8 9 10 11 12 | if type(value) is float:
# Rather than mess about with float -> Decimal conversion,
# it suits our accuracy needs just fine to go straight to string.
value = str(value)
elif type(value) is int:
# If we're giving an int, we need to add a '.0' behind it.
value = str(value) + '.0'
elif type(value) is Decimal:
return value
elif type(value) is str:
if '.' not in value:
value += '.0'
|
Now we’re mark the code.
1 2 3 4 5 6 7 8 9 10 11 12 | if type(value) is float:
# Rather than mess about with float -> Decimal conversion,
# it suits our accuracy needs just fine to go straight to string.
value = str(value)
elif type(value) is int:
# If we're giving an int, we need to add a '.0' behind it.
value = str(value) + '.0'
elif type(value) is Decimal:
return value
elif type(value) is str:
if '.' not in value:
value += '.0'
|
cdl_convert.main()
cdl_convert.__author__
cdl_convert.__credits__
cdl_convert.base.AscDescBase.parse_xml_descs()
cdl_convert.base.AscDescBase.desc
TypeError
cdl_convert.banana
Even more tests now.
My favorite!
Note
This stuff is important.
I’m not kidding, it’s critical.
Some great warnings coming up.
Warning
Pay head to this warning, it could save your life.
Or it could kill you even.
New in version 6.7.4.3: The ability to kill people with warnings.
Holy cow! what a list.
Changed in version 1.5: Things got shifted around, and removed.
Removing things was important.
Deprecated since version 6.4: Hey don’t use this anymore
Or if you do, don’t use it a lot.
My favorite!
Note
This stuff is important.
I’m not kidding, it’s critical.
1 2 3 4 5 6 7 8 9 10 11 12 | if type(value) is float:
# Rather than mess about with float -> Decimal conversion,
# it suits our accuracy needs just fine to go straight to string.
value = str(value)
elif type(value) is int:
# If we're giving an int, we need to add a '.0' behind it.
value = str(value) + '.0'
elif type(value) is Decimal:
return value
elif type(value) is str:
if '.' not in value:
value += '.0'
|
Some great warnings coming up.
Warning
Pay head to this warning, it could save your life.
1 2 3 4 5 6 7 8 9 10 11 12 | if type(value) is float:
# Rather than mess about with float -> Decimal conversion,
# it suits our accuracy needs just fine to go straight to string.
value = str(value)
elif type(value) is int:
# If we're giving an int, we need to add a '.0' behind it.
value = str(value) + '.0'
elif type(value) is Decimal:
return value
elif type(value) is str:
if '.' not in value:
value += '.0'
|
Or it could kill you even.
New in version 6.7.4.3: The ability to kill people with warnings.
1 2 3 4 5 6 7 8 9 10 11 12 | if type(value) is float:
# Rather than mess about with float -> Decimal conversion,
# it suits our accuracy needs just fine to go straight to string.
value = str(value)
elif type(value) is int:
# If we're giving an int, we need to add a '.0' behind it.
value = str(value) + '.0'
elif type(value) is Decimal:
return value
elif type(value) is str:
if '.' not in value:
value += '.0'
|
Holy cow! what a list.
Changed in version 1.5: Things got shifted around, and removed.
Removing things was important.
1 2 3 4 5 6 7 8 9 10 11 12 | if type(value) is float:
# Rather than mess about with float -> Decimal conversion,
# it suits our accuracy needs just fine to go straight to string.
value = str(value)
elif type(value) is int:
# If we're giving an int, we need to add a '.0' behind it.
value = str(value) + '.0'
elif type(value) is Decimal:
return value
elif type(value) is str:
if '.' not in value:
value += '.0'
|
Deprecated since version 6.4: Hey don’t use this anymore
1 2 3 4 5 6 7 8 9 10 11 12 | if type(value) is float:
# Rather than mess about with float -> Decimal conversion,
# it suits our accuracy needs just fine to go straight to string.
value = str(value)
elif type(value) is int:
# If we're giving an int, we need to add a '.0' behind it.
value = str(value) + '.0'
elif type(value) is Decimal:
return value
elif type(value) is str:
if '.' not in value:
value += '.0'
|
Or if you do, don’t use it a lot.
See also
AUTODOCS, ENGAGE
Converts between common ASC CDL (http://en.wikipedia.org/wiki/ASC_CDL) formats. The American Society of Cinematographers Color Decision List (ASC CDL, or CDL for short) is a schema to simplify the process of interchanging color data between various programs and facilities.
The ASC has defined schemas for including the 10 basic numbers in 5 different formats:
Unofficial Formats:
It is the purpose of CDLConvert to convert ASC CDL information between these basic formats to further facilitate the ease of exchange of color data within the Film and TV industries.
cdl_convert supports parsing ALE, FLEx, CC, CCC, CDL and RCDL. We can write out CC, CCC, CDL and RCDL.
CDLConvert is not associated with the American Society of Cinematographers
## Public Functions
- reset_all()
- Resets all the class level memberships lists and dictionaries. This effectively resets the entire module.
## License
The MIT License (MIT)
cdl_convert Copyright (c) 2014 Sean Wallitsch http://github.com/shidarin/cdl_convert/
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Wow what a great module.
Container class for ColorDecisionLists and ColorCorrectionCollections.
Collections need to store children and have access to descriptions, input descriptions, and viewing descriptions.
Class Attributes:
- members : [ :class`ColorCollection` ]
All instanced ColorCollection are added to this member list. Unlike the ColorCorrection member’s dictionary, ColorCollection do not need any unique values to exist.
This is currently only used for determining an id value when exporting and no file_in attribute is set.
Attributes:
- all_children : (ColorCorrection, ColorDecision)
- A tuple of all the children of this collection, both Corrections and Decisions.
- color_corrections : (ColorCorrection)
- All the ColorCorrection children are listed here.
- color_decisions : (ColorDecision)
- All the ColorDecision children are listed here.
- desc : [str]
Since all Asc nodes which can contain a single description, can actually contain an infinite number of descriptions, the desc attribute is a list, allowing us to store every single description found during parsing.
Setting desc directly will cause the value given to append to the end of the list, but desc can also be replaced by passing it a list or tuple. Desc can be emptied by passing it None, [] or ().
Inherited from AscDescBase .
- element : (<xml.etree.ElementTree.Element>)
- etree style Element representing the node. Inherited from AscXMLBase .
- file_in : (str)
- Filepath used to create this ColorCollection .
- file_out : (str)
- Filepath this ColorCollection will be written to.
- input_desc : (str)
- Description of the color space, format and properties of the input images. Inherited from AscColorSpaceBase .
- is_ccc : (bool)
- True if this collection currently represents .ccc.
- is_cdl : (bool)
- True if this collection currently represents .cdl.
- type : (str)
- Either ccc or cdl, represents the type of collection this class currently will export by default.
- viewing_desc : (str)
- Viewing device, settings and environment. Inherited from AscColorSpaceBase .
- xml : (str)
- A nicely formatted XML string representing the node. Inherited from AscXMLBase.
- xml_root : (str)
- A nicely formatted XML, ready to write to file string representing the node. Formatted as an XML root, it includes the xml version and encoding tags on the first line. Inherited from AscXMLBase.
- xmlns : (str)
- Describes the version of the ASC XML Schema that cdl_convert writes out to files following the full schema (.ccc and .cdl)
Public Methods:
- append_child()
- Appends the given object, either a ColorCorrection or a ColorDecision , to the respective attribute list, either color_corrections or color_decision depending on the class of the object passed in.
- append_children()
- Given a list, will iterate through and append each element of that list to the correct child list, using the append_child() method.
- build_element()
Builds an ElementTree XML Element for this node and all nodes it contains. element, xml, and xml_root attributes use this to build the XML. This function is identical to calling the element attribute. Overrides inherited placeholder method from AscXMLBase .
Here on ColorCollection , this is a pointer to build_element_ccc() or build_element_cdl() depending on which type the ColorCollection is currently set to.
- build_element_ccc()
- Builds a CCC style XML tree representing this ColorCollection instance.
- build_element_cdl()
- Builds a CDL style XML tree representing this ColorCollection instance.
- copy_collection()
- Creates and returns an exact new instance that’s an exact copy of the current instance. Note that references to the child instances will be copied, but that the child instances themselves will not be.
- merge_collections()
- Merges all members of a list containing ColorCollection and the instance this is called on to return a new ColorCollection that is primarily a copy of this instance, but contains all children and description elements from the given collections. input_desc, viewing_desc, file_in, and type will be set to the values of the parent instance.
- parse_xml_color_corrections()
- Parses an ElementTree element to find & add all ColorCorrection.
- parse_xml_descs()
- Parses an ElementTree Element for any Description tags and appends any text they contain to the desc. Inherited from AscDescBase
- parse_xml_input_desc()
- Parses an ElementTree Element to find & add an InputDescription. If none is found, input_desc will remain set to None. Inherited from AscColorSpaceBase
- parse_xml_viewing_desc()
- Parses an ElementTree Element to find & add a ViewingDescription. If none is found, viewing_desc will remain set to None. Inherited from AscColorSpaceBase
- reset_members()
- Resets the class level members list.
- set_parentage()
- Sets all child ColorCorrection and ColorDecision parent attribute to point to this instance.
- set_to_ccc()
- Switches the type of this collection to export a ccc style xml collection by default.
- set_to_cdl()
- Switches the type of this collection to export a cdl style xml collection by default.
I’ve seen better.
Converts an incoming value to Decimal in the best way
The biggest change in 0.7 is the addition of collection format support. .ccc, Color Correction Collections, can now be parsed and written. .cdl, Color Decision Lists, can now be parsed and written. .ale and .flex files now return a collection.
Renames ColorCollectionBase to ColorCollection , since it will be used directly by both ccc and cdl.
Adds parse_ccc which returns a ColorCollection .
Adds write_ccc which writes a ColorCollection as a ccc file.
Adds parse_cdl which returns a ColorCollection .
Adds write_cdl which returns a ColorCollection as a cdl file.
ColorCollection is now a fully functional container class, with many attributes and methods.
Added ColorDecision , which stores either a ColorCorrection or ColorCorrectionRef , and an optional MediaRef
Added ColorCorrectionRef , which stores a reference to a ColorCorrection
Added parent attribute to ColorCorrection .
Calling sop_node or sat_node on a ColorCorrection before attempting to set a SOP or Sat power now works.
ColorCorrection cdl_file init argument renamed to input_file, which is now optional and able to be set after init.
parse_cc and parse_rnh_cdl now only yield a single ColorCorrection , not a single member list.
Added dev-requirements.txt (contains mock)
All determine_dest methods now take a second directory argument, which determines the output directory.
Adds sanity_check function which prints values which might be unusual to stdout.
parse_cdl and write_cdl renamed to parse_rnh_cdl and write_rnh_cdl respectively.