Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if field_data_list: field_data.update(zip(fields, field_data_list))
if field_data_dict: field_data.update(field_data_dict)
if struct is None: field_data, struct = dict(), field_data
assert not set(field_data.keys()).difference(fields)
if field_data: self._copy_struct_fields(field_data, fields=field_data.keys())
self._copy_struct_fields(struct, fields=set(fields).difference(field_data.keys()))
if struct:
if hasattr(struct, 'proplist'):
self.proplist, state = dict(), c.c_void_p()
while True:
k = c.pa.proplist_iterate(struct.proplist, c.byref(state))
if not k: break
self.proplist[c.force_str(k)] = c.force_str(c.pa.proplist_gets(struct.proplist, k))
if hasattr(struct, 'volume'):
self.volume = self._get_wrapper(PulseVolumeInfo)(struct.volume)
if hasattr(struct, 'n_ports'):
cls_port = self._get_wrapper(PulsePortInfo)
self.port_list = list(
cls_port(struct.ports[n].contents) for n in range(struct.n_ports) )
if hasattr(struct, 'active_port'):
cls_port = self._get_wrapper(PulsePortInfo)
self.port_active = (
None if not struct.active_port else cls_port(struct.active_port.contents) )
if hasattr(struct, 'channel_map'):
self.channel_count, self.channel_list = struct.channel_map.channels, list()
if self.channel_count > 0:
s = c.create_string_buffer(b'\0' * 512)
c.pa.channel_map_snprint(s, len(s), struct.channel_map)
self.channel_list.extend(map(c.force_str, s.value.strip().split(b',')))
if hasattr(struct, 'state'):
self.state = PulseStateEnum._c_val(
def struct_from_value( cls, name, volume,
channel_list=None, mute=False, device=None ):
'Same arguments as with class instance init.'
chan_map = c.PA_CHANNEL_MAP()
if not channel_list: c.pa.channel_map_init_mono(chan_map)
else:
if not is_str(channel_list):
channel_list = b','.join(map(c.force_bytes, channel_list))
c.pa.channel_map_parse(chan_map, channel_list)
if not isinstance(volume, PulseVolumeInfo):
volume = PulseVolumeInfo(volume, chan_map.channels)
struct = c.PA_EXT_STREAM_RESTORE_INFO(
name=c.force_bytes(name),
mute=int(bool(mute)), device=c.force_bytes(device),
channel_map=chan_map, volume=volume.to_struct() )
return struct
def struct_from_value( cls, name, volume,
channel_list=None, mute=False, device=None ):
'Same arguments as with class instance init.'
chan_map = c.PA_CHANNEL_MAP()
if not channel_list: c.pa.channel_map_init_mono(chan_map)
else:
if not is_str(channel_list):
channel_list = b','.join(map(c.force_bytes, channel_list))
c.pa.channel_map_parse(chan_map, channel_list)
if not isinstance(volume, PulseVolumeInfo):
volume = PulseVolumeInfo(volume, chan_map.channels)
struct = c.PA_EXT_STREAM_RESTORE_INFO(
name=c.force_bytes(name),
mute=int(bool(mute)), device=c.force_bytes(device),
channel_map=chan_map, volume=volume.to_struct() )
return struct