File: aval.py

package info (click to toggle)
python-librtmp 0.3.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 252 kB
  • sloc: ansic: 1,255; python: 858; makefile: 7
file content (31 lines) | stat: -rw-r--r-- 787 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from . import ffi
from .compat import bytes, integer_types, string_types


__all__ = ["AVal"]


class AVal(object):
    def __init__(self, value=None):
        self.aval = ffi.new("AVal *")

        if value is not None:
            self.value = value

    @property
    def value(self):
        buf = ffi.buffer(self.aval.av_val, self.aval.av_len)
        return buf[:]

    @value.setter
    def value(self, value):
        if isinstance(value, integer_types):
            value = str(value)
        if isinstance(value, string_types):
            value = bytes(value, "utf8")
        elif isinstance(value, bool):
            value = str(value).lower()

        self.value_str = ffi.new("char[]", value)
        self.aval.av_val = self.value_str
        self.aval.av_len = len(value)