Library Internals
module: .metaclasses
The .metaclasses module contains - as one might
expect - metaclasses that are used to ensure a consistent interface
throughout the Highcharts Stock for Python library.
class: HighchartsMeta
- class HighchartsMeta(**kwargs)[source]
Metaclass that is used to define the standard interface exposed for serializable objects.
Class Inheritance
digraph inheritanced2a0af0689 { bgcolor=transparent; rankdir=TB; size="8.0, 12.0"; "ABC" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="Helper class that provides a standard way to create an ABC using"]; "metaclasses.HighchartsMeta" [URL="#highcharts_stock.metaclasses.HighchartsMeta",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Metaclass that is used to define the standard interface exposed for serializable"]; "ABC" -> "metaclasses.HighchartsMeta" [arrowsize=0.5,style="setlinewidth(0.5)"]; }- classmethod _copy_dict_key(key, original, other, overwrite=True, **kwargs)[source]
Copies the value of
keyfromoriginaltoother.
- abstract classmethod _get_kwargs_from_dict(as_dict)[source]
Convenience method which returns the keyword arguments used to initialize the class from a Highcharts Javascript-compatible
dictobject.
- abstract _to_untrimmed_dict(in_cls=None) dict[source]
Generate the first-level of the
dictrepresentation of the object.Note
This method does not traverse the object structure to convert the object into a full
dictrepresentation - it merely goes “part” of the way there to replace the Highcharts for Python keys with their correpsond Highcharts JS keys.- Return type:
- _untrimmed_mro_ancestors(in_cls=None) dict[source]
Walk through the parent classes and consolidate the results of their
_to_untrimmed_dict()methods into a singledict.- Return type:
- classmethod _validate_js_literal(as_str, range=True, _break_loop_on_failure=False)[source]
Parse
as_stras a valid JavaScript literal object.- Parameters:
- Returns:
The parsed AST representation of
as_strand the updated string.- Return type:
- copy(other=None, overwrite=True, **kwargs)[source]
Copy the configuration settings from this instance to the
otherinstance.- Parameters:
other (
HighchartsMeta) – The target instance to which the properties of this instance should be copied. IfNone, will create a new instance and populate it with properties copied fromself. Defaults toNone.overwrite (
bool) – ifTrue, properties inotherthat are already set will be overwritten by their counterparts inself. Defaults toTrue.kwargs – Additional keyword arguments. Some special descendents of
HighchartsMetamay have special implementations of this method which rely on additional keyword arguments.
- Returns:
A mutated version of
otherwith new property values
- classmethod from_dict(as_dict: dict, allow_snake_case: bool = True)[source]
Construct an instance of the class from a
dictobject.- Parameters:
- Returns:
A Python object representation of
as_dict.- Return type:
- classmethod from_js_literal(as_str_or_file, allow_snake_case: bool = True, _break_loop_on_failure: bool = False)[source]
Return a Python object representation of a Highcharts JavaScript object literal.
- Parameters:
as_str_or_file (
str) – The JavaScript object literal, represented either as astror as a filename which contains the JS object literal.allow_snake_case (
bool) – IfTrue, interpretssnake_casekeys as equivalent tocamelCasekeys. Defaults toTrue._break_loop_on_failure (
bool) – IfTrue, will break any looping operations in the event of a failure. Otherwise, will attempt to repair the failure. Defaults toFalse.
- Returns:
A Python object representation of the Highcharts JavaScript object literal.
- Return type:
- classmethod from_json(as_json_or_file, allow_snake_case: bool = True)[source]
Construct an instance of the class from a JSON string.
- Parameters:
as_json_or_file – The JSON string for the object or the filename of a file that contains the JSON string.
allow_snake_case (
bool) – IfTrue, interpretssnake_casekeys as equivalent tocamelCasekeys. Defaults toTrue.
- Returns:
A Python objcet representation of
as_json.- Return type:
- to_dict() dict[source]
Generate a
dictrepresentation of the object compatible with the Highcharts JavaScript library.Note
The
dictrepresentation has a property structure and naming convention that is intentionally consistent with the Highcharts JavaScript library. This is not Pythonic, but it makes managing the interplay between the two languages much, much simpler.
- to_js_literal(filename=None, encoding='utf-8') str | None[source]
Return the object represented as a
strcontaining the JavaScript object literal.
- to_json(filename=None, encoding='utf-8')[source]
Generate a JSON string/byte string representation of the object compatible with the Highcharts JavaScript library.
Note
This method will either return a standard
stror abytesobject depending on the JSON serialization library you are using. For example, if your environment has orjson, the result will be abytesrepresentation of the string.- Parameters:
- Returns:
A JSON representation of the object compatible with the Highcharts library.
- Return type:
- static trim_dict(untrimmed: dict, to_json: bool = False) dict[source]
Remove keys from
untrimmedwhose values areNoneand convert values that have.to_dict()methods.
class: JavaScriptDict
- class JavaScriptDict(dict=None, /, **kwargs)[source]
Special
dictclass which constructs a JavaScript object that can be represented as a string.Keys are validated to be valid variable names, while values are validated to be strings.
When serialized to
str, keys are not wrapped in double quotes (as they would be in JSON) to ensure that the resulting string can be evaluated as JavaScript code.Class Inheritance
digraph inheritance8b9350330a { bgcolor=transparent; rankdir=TB; size="8.0, 12.0"; "UserDict" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled"]; "abc.MutableMapping" -> "UserDict" [arrowsize=0.5,style="setlinewidth(0.5)"]; "abc.Collection" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled"]; "abc.Sized" -> "abc.Collection" [arrowsize=0.5,style="setlinewidth(0.5)"]; "abc.Iterable" -> "abc.Collection" [arrowsize=0.5,style="setlinewidth(0.5)"]; "abc.Container" -> "abc.Collection" [arrowsize=0.5,style="setlinewidth(0.5)"]; "abc.Container" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled"]; "abc.Iterable" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled"]; "abc.Mapping" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="A Mapping is a generic container for associating key/value"]; "abc.Collection" -> "abc.Mapping" [arrowsize=0.5,style="setlinewidth(0.5)"]; "abc.MutableMapping" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="A MutableMapping is a generic container for associating"]; "abc.Mapping" -> "abc.MutableMapping" [arrowsize=0.5,style="setlinewidth(0.5)"]; "abc.Sized" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled"]; "metaclasses.JavaScriptDict" [URL="#highcharts_stock.metaclasses.JavaScriptDict",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Special :class:`dict <python:dict>` class which constructs a JavaScript"]; "UserDict" -> "metaclasses.JavaScriptDict" [arrowsize=0.5,style="setlinewidth(0.5)"]; }- classmethod _validate_js_literal(as_str, range=True, _break_loop_on_failure=False)[source]
Parse
as_stras a valid JavaScript literal object.- Parameters:
- Returns:
The parsed AST representation of
as_strand the updated string.- Return type:
- clear() None. Remove all items from D.
- classmethod from_dict(as_dict)[source]
Construct an instance of the class from a
dictobject.- Parameters:
- Returns:
A Python object representation of
as_dict.- Return type:
- classmethod from_json(as_json)[source]
Construct an instance of the class from a JSON string.
- Parameters:
- Returns:
A Python objcet representation of
as_json.- Return type:
- get(k[, d]) D[k] if k in D, else d. d defaults to None.
- items() a set-like object providing a view on D's items
- keys() a set-like object providing a view on D's keys
- pop(k[, d]) v, remove specified key and return the corresponding value.
If key is not found, d is returned if given, otherwise KeyError is raised.
- popitem() (k, v), remove and return some (key, value) pair
as a 2-tuple; but raise KeyError if D is empty.
- setdefault(k[, d]) D.get(k,d), also set D[k]=d if k not in D
- to_dict()[source]
Generate a
dictrepresentation of the object compatible with the Highcharts JavaScript library.Note
The
dictrepresentation has a property structure and naming convention that is intentionally consistent with the Highcharts JavaScript library. This is not Pythonic, but it makes managing the interplay between the two languages much, much simpler.
- to_js_literal(filename=None, encoding='utf-8') str | None[source]
Return the object represented as a
strcontaining the JavaScript object literal.
- to_json(filename=None, encoding='utf-8')[source]
Generate a JSON string/byte string representation of the object compatible with the Highcharts JavaScript library.
Note
This method will either return a standard
stror abytesobject depending on the JSON serialization library you are using. For example, if your environment has orjson, the result will be abytesrepresentation of the string.- Parameters:
- Returns:
A JSON representation of the object compatible with the Highcharts library.
- Return type:
- update([E, ]**F) None. Update D from mapping/iterable E and F.
If E present and has a .keys() method, does: for k in E: D[k] = E[k] If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v In either case, this is followed by: for k, v in F.items(): D[k] = v
- values() an object providing a view on D's values
module: .decorators
The .decorators module contains decorators and
decorator-assisting functions used throughout the Highcharts Stock for Python library.
decorator: @class_sensitive
- @class_sensitive(types=None, allow_dict=True, allow_json=True, allow_none=True, allow_js_literal=True, force_iterable=False)[source]
Validates that the values passed to a decorated function or method are de-serialized to the appropriate type.
- Parameters:
types –
typeobject or iterable oftypeobjects used to indicate which types are allowed. The first (or only) item intypeswill indicate the primary type thatvaluewill be returned as.allow_dict (
bool) – IfTrue, will accept adictobject asvalue. Defaults toTrue.allow_json (
bool) – IfTrue, will accept astrobject asvalue, under the assumption that is is deserializable as JSON. Defaults toTrue.allow_none (
bool) – IfTrue, will accept an empty orNoneobject asvalue. Defaults toTrue.allow_js_literal (
bool) – IfTrue, will accept astrobject asvalue, under the assumption that it is deserializable as a JavaScript object literal. Defaults toTrue.force_iterable (
bool) – IfTrue, will accept an iterable object asvalue. Defaults toFalse(because most attributes are just singletons).
- Types:
Note
To apply the decorator to a property setter method (the most-common use case), place it after the
@<property name>.setterdecorator and directly above the function name like so:@some_property.setter @class_sensitive(...) def some_property(self, value): ...
- Returns:
The result of the decorated function or method having validated the class typing.
- Raises:
HighchartsImplementationError – if
typesis emptyHighchartsValueError – if
typesdoes not contain atypeor iterable oftypeobjectsHighchartsValueError – if the primary type does not conform to the
HighchartsMetainterface definition
function: validate_types()
- validate_types(value, types=None, allow_dict=True, allow_json=True, allow_none=True, allow_js_literal=True, force_iterable=False, function_name=None)[source]
Validates that
valueis one or more of the allowed types, where the first type passed intypesis the primary type that it will be returned as.- Parameters:
value (Any) – The value to be validated.
types –
typeobject or iterable oftypeobjects used to indicate which types are allowed. The first (or only) item intypeswill indicate the primary type thatvaluewill be returned as.allow_dict (
bool) – IfTrue, will accept adictobject asvalue. Defaults toTrue.allow_json (
bool) – IfTrue, will accept astrobject asvalue, under the assumption that is is deserializable as JSON. Defaults toTrue.allow_none (
bool) – IfTrue, will accept an empty orNoneobject asvalue. Defaults toTrue.allow_js_literal (
bool) – IfTrue, will accept astrobject asvalue, under the assumption that it is deserializable as a JavaScript object literal. Defaults toTrue.force_iterable (
bool) – IfTrue, will accept an iterable object asvalue. Defaults toFalse(because most attributes are just singletons).function_name (
str) – The optional name of the function that was originally called.
- Types:
- Returns:
valuede-serialized to the primary type (firsttypeintypes)- Return type:
first
typeintypes- Raises:
HighchartsImplementationError – if
typesis emptyHighchartsValueError – if
typesdoes not contain atypeor iterable oftypeobjectsHighchartsValueError – if the primary type does not conform to the
HighchartsMetainterface definition
module:: .js_literal_functions
The .js_literal_functions module contains
functions that are used to parse, process, de-serialize, and serialize JavaScript literal
notation.
function: serialize_to_js_literal()
- serialize_to_js_literal(item, encoding='utf-8') str | None[source]
Convert
itemto the contents of a JavaScript object literal code snippet.- Parameters:
item – A value that is to be converted into a JS object literal notation value.
encoding (
str) – The character encoding to apply to the resulting object. Defaults to'utf-8'.
- Returns:
A JavaScript object literal code snippet, expressed as a string. Or
Noneifitemis not serializable.- Return type:
function: attempt_variable_declaration()
function: is_js_function_or_class()
function: get_js_literal()
function: assemble_js_literal()
function: convert_js_literal_to_python()
function: convert_js_property_to_python()
function: convert_js_to_python()
function: get_key_value_pairs()
- get_key_value_pairs(properties, original_str)[source]
Return the key and value pairs for properties defined in
properties.
.utility_functions
The .utility_functions module contains a
small number of functions which serve as utilities across the
Highcharts Stock for Python library. Think of it as a function “catch all” module.
function:: mro_to_dict()
function:: get_remaining_mro()
function:: mro__to_untrimmed_dict()
- mro__to_untrimmed_dict(obj, in_cls=None)[source]
Traverse the ancestor classes of
objand execute their_to_untrimmed_dict()methods.- Parameters:
obj (
HighchartsMeta) – The object to be traversed.in_cls (
typeorNone) – The class from whichmro__to_untrimmed_dict()was called.
- Returns:
Collection of untrimmed
dictrepresentations in the same order as the MRO.- Return type:
for each class in the MRO, execute _to_untrimmed_dict() do not repeat for each class
function:: validate_color()
function:: to_camelCase()
function:: parse_csv()
- parse_csv(csv_data, has_header_row=True, delimiter=',', null_text='None', wrapper_character="'", wrap_all_strings=False, double_wrapper_character_when_nested=False, escape_character='\\', line_terminator='\r\n')[source]
Parse
csv_datato return a list ofdictobjects, one for each record.- Parameters:
- Returns:
Collection of column names (or numerical keys) and CSV records as
dictvalues- Return type: