Skip to content

Simple

sangfroid.value.Simple(*args) #

Bases: sangfroid.value.value.Value

Abstract superclass of Values which are based directly on Python builtin types.

Issue

Subclasses of Simple should coerce freely to and from their builtin types, but they don't. See issue #14.

Properties

our_type (type): the Python type we're based on.

Source code in sangfroid/value/value.py
16
17
18
19
20
21
22
23
24
25
26
27
def __init__(self, *args):

    if len(args)==1 and isinstance(args[0], bs4.element.Tag):
        self._tag = args[0]
    else:
        self._tag = self._get_empty_tag()
        if len(args)==1:
            self.value = args[0]
        else:
            self.value = args

    assert self._tag is not None

is_animated property writable #

Whether the value is animated.

timeline property writable #

Our timeline, showing how our value changes over time.

If we're not animated, the timeline will be empty.

Timeline objects hold no state of their own except a reference back to their parent Value. So this call constructs a new Timeline instance every time.

as_python_expression() #

A Python expression which could be passed to the constructor of this class in order to recreate this value.

Used by etc/pick-and-mix-to-layers.py.

Source code in sangfroid/value/value.py
285
286
287
288
289
290
291
292
def as_python_expression(self) -> str:
    """
    A Python expression which could be passed to the constructor
    of this class in order to recreate this value.

    Used by `etc/pick-and-mix-to-layers.py`.
    """
    return str(self)

from_tag(tag) classmethod #

Given a Beautiful Soup tag, returns an instance of an appropriate subclass of Value, representing it.

Parameters:

Name Type Description Default
tag bs4.Tag

the Beautiful Soup tag.

required

Raises:

Type Description
KeyError

if there's no known subclass of Value to represent that tag.

ValueError

if the tag is animated, but not marked with a type.

Source code in sangfroid/value/value.py
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
@classmethod
def from_tag(cls,
             tag: bs4.Tag,
             ) -> Self:
    """
    Given a Beautiful Soup tag, returns an instance of an appropriate
    subclass of `Value`, representing it.

    Args:
        tag: the Beautiful Soup tag.

    Raises:
        KeyError: if there's no known subclass of `Value` to represent
            that tag.
        ValueError: if the tag is animated, but not marked with a type.
    """

    if tag.name==cls.ANIMATED:

        type_name = tag['type']
        if type_name is None:
            raise ValueError(f"Animated values need a type: {tag}")

    else:
        type_name = tag.name

    result_type = cls.handles_type.from_name(name=type_name)
    result = result_type._construct_from(tag)

    return result