rem
stringlengths
0
322k
add
stringlengths
0
2.05M
context
stringlengths
8
228k
def _send_packet(self, packet_type, data, seq = 0, timeout = 2.0):
def _send_packet(self, packet_type, data, seq = 0, timeout = None):
def _send_packet(self, packet_type, data, seq = 0, timeout = 2.0): if not self.socket: raise IPCDisconnectedError("Remote end no longer connected") if seq == 0: seq = self.last_seq = self.last_seq + 1
self.write(struct.pack("l", len(pdata)) + pdata)
self.write(struct.pack("I", len(pdata)) + pdata)
def _send_packet(self, packet_type, data, seq = 0, timeout = 2.0): if not self.socket: raise IPCDisconnectedError("Remote end no longer connected") if seq == 0: seq = self.last_seq = self.last_seq + 1
raise IPCTimeoutError
raise IPCTimeoutError, (type,)
def request(self, type, data, timeout = None): if timeout == None: timeout = self._default_timeout
for pos, cb_all in zip(range(len(self._callbacks)), self._callbacks[:]): cb_callback, cb_args, cb_kwargs, cb_once, cb_weak = cb_all if cb_weak and args != None:
for cb in self._callbacks[:]: cb_callback, cb_args, cb_kwargs, cb_once, cb_weak = cb if cb_weak:
def _disconnect(self, callback, args, kwargs): new_callbacks = [] for pos, cb_all in zip(range(len(self._callbacks)), self._callbacks[:]): cb_callback, cb_args, cb_kwargs, cb_once, cb_weak = cb_all if cb_weak and args != None: cb_callback = cb_callback._get_callback() cb_args, cb_kwargs = unweakref_data((cb_args, cb_kw...
if (cb_callback == callback and args == None) or \
if (cb_callback == callback and len(args) == 0) or \
def _disconnect(self, callback, args, kwargs): new_callbacks = [] for pos, cb_all in zip(range(len(self._callbacks)), self._callbacks[:]): cb_callback, cb_args, cb_kwargs, cb_once, cb_weak = cb_all if cb_weak and args != None: cb_callback = cb_callback._get_callback() cb_args, cb_kwargs = unweakref_data((cb_args, cb_kw...
new_callbacks.append(cb_all) if len(new_callbacks) != self._callbacks:
new_callbacks.append(cb) if len(new_callbacks) != len(self._callbacks):
def _disconnect(self, callback, args, kwargs): new_callbacks = [] for pos, cb_all in zip(range(len(self._callbacks)), self._callbacks[:]): cb_callback, cb_args, cb_kwargs, cb_once, cb_weak = cb_all if cb_weak and args != None: cb_callback = cb_callback._get_callback() cb_args, cb_kwargs = unweakref_data((cb_args, cb_kw...
if self._ref and self._ref():
if self._ref and self._ref() is not None:
def __nonzero__(self): if self._ref and self._ref(): return 1 else: return 0
return MainThreadCallback(self,stop, cmd)()
return MainThreadCallback(self.stop, cmd)()
def stop( self, cmd = '' ): """ Stop the child. If 'cmd' is given, this stop command will send to the app to stop itself. If this is not working, kill -15 and kill -9 will be used to kill the app. """ if self.stopping: return
def build(self): """ """ _modules.append(self)
def build(self): """ """ _modules.append(self)
if not kwargs.has_key('ext_modules'): kwargs['ext_modules'] = _modules
def _find_packages(kwargs, dirname, files): """ Helper function to create 'packages' and 'package_dir'. """ if not '__init__.py' in files: return python_dirname = 'kaa.' + kwargs['module'] + \ dirname[3:].replace('/', '.') kwargs['package_dir'][python_dirname] = dirname kwargs['packages'].append(python_dirname)
if type(value._operand) in (int, long, float) and attr_type in (int, long, float):
if attr_type in (int, long, float) and (type(value._operand) in (int, long, float) or \ isinstance(value._operand, basestring) and value._operand.isdigit()):
def query_raw(self, **attrs): """ Query the database for objects matching all of the given attributes (specified in kwargs). There are a few special kwarg attributes:
generally, given N rows, each term matches (1/N)*100 percent rows with
generally, given N terms, each term matches (1/N)*100 percent rows with
def _query_keywords(self, words, limit = 100, object_type = None): """ Queries the database for the keywords supplied in the words strings. (Search terms are delimited by spaces.)
if kwargs.has_key('ext_modules'):
if kwargs.get('ext_modules'):
def _find_packages(kwargs, dirname, files): """ Helper function to create 'packages' and 'package_dir'. """ if not '__init__.py' in files: return python_dirname = 'kaa.' + kwargs['module'] + \ dirname[3:].replace('/', '.') kwargs['package_dir'][python_dirname] = dirname kwargs['packages'].append(python_dirname)
notifier.dispatcher_add(signal.emit)
notifier.dispatcher_add(_idle_signal_emit)
def _idle_signal_changed(signal, flag): if flag == Signal.SIGNAL_CONNECTED and signal.count() == 1: notifier.dispatcher_add(signal.emit) elif flag == Signal.SIGNAL_DISCONNECTED and signal.count() == 0: notifier.dispatcher_remove(signal.emit)
notifier.dispatcher_remove(signal.emit)
notifier.dispatcher_remove(idle_signal_emit)
def _idle_signal_changed(signal, flag): if flag == Signal.SIGNAL_CONNECTED and signal.count() == 1: notifier.dispatcher_add(signal.emit) elif flag == Signal.SIGNAL_DISCONNECTED and signal.count() == 0: notifier.dispatcher_remove(signal.emit)
kwarg in setup() in extensions with no ext_modules.
kwarg in setup() for modules with no ext_modules.
def __del__(self): """ Delete the config file. """ if self.configfile: self.configfile.unlink()
namespace (kaa/) that have several independent extensions: that is, each extension in Kaa can be installed separately, but they coexist under the
namespace (kaa/) that have several independent modules: that is, each module in Kaa can be installed separately, but they coexist under the
def __del__(self): """ Delete the config file. """ if self.configfile: self.configfile.unlink()
kaa.notifier.SocketDispatcher(_handle_lirc_input).register(fd) kaa.signals["shutdown"].connect(pylirc.exit)
_dispatcher = kaa.notifier.SocketDispatcher(_handle_lirc_input) _dispatcher.register(fd) kaa.signals["shutdown"].connect(_handle_lirc_shutdown, pylirc)
def init(appname = None, cfg = None): if cfg == None: cfgfile = os.path.expanduser("~/.lircrc") if appname == None: appname = "kaa" has_lirc = False try: import pylirc except ImportError: return False try: fd = pylirc.init(appname, cfgfile) except IOError: return False if fd: pylirc.blocking(0) kaa.notifier.SocketDi...
e = None
def loop(): """ Notifier main loop function. It will loop until an exception is raised or sys.exit is called. """ global running running = True set_current_as_mainthread() e = None try: notifier.loop() except (KeyboardInterrupt, SystemExit): try: # This looks stupid, I know that. The problem is that if we have # a Key...
pass
log.exception('loop')
def loop(): """ Notifier main loop function. It will loop until an exception is raised or sys.exit is called. """ global running running = True set_current_as_mainthread() e = None try: notifier.loop() except (KeyboardInterrupt, SystemExit): try: # This looks stupid, I know that. The problem is that if we have # a Key...
if e: traceback.print_exc()
def loop(): """ Notifier main loop function. It will loop until an exception is raised or sys.exit is called. """ global running running = True set_current_as_mainthread() e = None try: notifier.loop() except (KeyboardInterrupt, SystemExit): try: # This looks stupid, I know that. The problem is that if we have # a Key...
def __init__(self, name, type='', descr=u'', default=None):
def __init__(self, name, type='', desc=u'', default=None):
def __init__(self, name, type='', descr=u'', default=None): self.name = name self.type = type self.descr = descr self.default = default self.value = default if type == '': if default == None: raise AttributeError('define type or default') self.type = default.__class__ if not descr and hasattr(default, '_descr'): self.d...
self.descr = descr
self.desc = desc
def __init__(self, name, type='', descr=u'', default=None): self.name = name self.type = type self.descr = descr self.default = default self.value = default if type == '': if default == None: raise AttributeError('define type or default') self.type = default.__class__ if not descr and hasattr(default, '_descr'): self.d...
if not descr and hasattr(default, '_descr'): self.descr = default._descr if isinstance(self.descr, str): self.descr = unicode(self.descr, ENCODING, 'replace')
if not desc and hasattr(default, '_desc'): self.desc = default._desc if isinstance(self.desc, str): self.desc = unicode(self.desc, ENCODING, 'replace')
def __init__(self, name, type='', descr=u'', default=None): self.name = name self.type = type self.descr = descr self.default = default self.value = default if type == '': if default == None: raise AttributeError('define type or default') self.type = default.__class__ if not descr and hasattr(default, '_descr'): self.d...
def _cfg_string(self, prefix, print_descr=True):
def _cfg_string(self, prefix, print_desc=True):
def _cfg_string(self, prefix, print_descr=True): if not prefix.endswith(']'): prefix = prefix + self.name if hasattr(self.value, '_cfg_string'): return self.value._cfg_string(prefix, print_descr) descr = newline = '' if print_descr: descr = '# %s\n' % self.descr.encode(ENCODING, 'replace').\ replace('\n', '\n# ') newli...
return self.value._cfg_string(prefix, print_descr) descr = newline = '' if print_descr: descr = '
return self.value._cfg_string(prefix, print_desc) desc = newline = '' if print_desc: desc = '
def _cfg_string(self, prefix, print_descr=True): if not prefix.endswith(']'): prefix = prefix + self.name if hasattr(self.value, '_cfg_string'): return self.value._cfg_string(prefix, print_descr) descr = newline = '' if print_descr: descr = '# %s\n' % self.descr.encode(ENCODING, 'replace').\ replace('\n', '\n# ') newli...
return '%s return '%s%s = %s%s' % (descr, prefix, value, newline)
return '%s return '%s%s = %s%s' % (desc, prefix, value, newline)
def _cfg_string(self, prefix, print_descr=True): if not prefix.endswith(']'): prefix = prefix + self.name if hasattr(self.value, '_cfg_string'): return self.value._cfg_string(prefix, print_descr) descr = newline = '' if print_descr: descr = '# %s\n' % self.descr.encode(ENCODING, 'replace').\ replace('\n', '\n# ') newli...
value = self.type(value)
if isinstance(value, str) and self.type == unicode: value = unicode(value, ENCODING, 'replace') elif isinstance(value, unicode) and self.type == str: value = value.encode(ENCODING, 'replace') else: value = self.type(value)
def _cfg_set(self, value): if isinstance(self.type, (list, tuple)): if not value in self.type: # This could crash, but that is ok value = self.type[0].__class__(value) if value in self.type: self.value = value return value raise AttributeError('Variable must be one of %s' % str(self.type)) if not isinstance(value, self...
def __init__(self, schema, descr=u'', name=''):
def __init__(self, schema, desc=u'', name=''):
def __init__(self, schema, descr=u'', name=''): self._dict = {} self._vars = [] self._descr = descr self._name = name for data in copy.deepcopy(schema): if not isinstance(data, Var): if not data._name: raise AttributeError('Inline Group needs name') data = Var(name=data._name, default=data) self._dict[data.name] = d...
self._descr = descr
self._desc = desc
def __init__(self, schema, descr=u'', name=''): self._dict = {} self._vars = [] self._descr = descr self._name = name for data in copy.deepcopy(schema): if not isinstance(data, Var): if not data._name: raise AttributeError('Inline Group needs name') data = Var(name=data._name, default=data) self._dict[data.name] = d...
if isinstance(self._descr, str): self._descr = unicode(self._descr, ENCODING, 'replace')
if isinstance(self._desc, str): self._desc = unicode(self._desc, ENCODING, 'replace')
def __init__(self, schema, descr=u'', name=''): self._dict = {} self._vars = [] self._descr = descr self._name = name for data in copy.deepcopy(schema): if not isinstance(data, Var): if not data._name: raise AttributeError('Inline Group needs name') data = Var(name=data._name, default=data) self._dict[data.name] = d...
def _cfg_string(self, prefix, print_descr=True):
def _cfg_string(self, prefix, print_desc=True):
def _cfg_string(self, prefix, print_descr=True): ret = [] desc = self._descr.encode(ENCODING, 'replace').replace('\n', '\n# ') if prefix: if print_descr: ret.append('#\n# %s\n# %s\n#\n' % (prefix, desc)) prefix += '.' for name in self._vars: var = self._dict[name] ret.append(var._cfg_string(prefix, print_descr)) retur...
desc = self._descr.encode(ENCODING, 'replace').replace('\n', '\n
desc = self._desc.encode(ENCODING, 'replace').replace('\n', '\n
def _cfg_string(self, prefix, print_descr=True): ret = [] desc = self._descr.encode(ENCODING, 'replace').replace('\n', '\n# ') if prefix: if print_descr: ret.append('#\n# %s\n# %s\n#\n' % (prefix, desc)) prefix += '.' for name in self._vars: var = self._dict[name] ret.append(var._cfg_string(prefix, print_descr)) retur...
if print_descr:
if print_desc:
def _cfg_string(self, prefix, print_descr=True): ret = [] desc = self._descr.encode(ENCODING, 'replace').replace('\n', '\n# ') if prefix: if print_descr: ret.append('#\n# %s\n# %s\n#\n' % (prefix, desc)) prefix += '.' for name in self._vars: var = self._dict[name] ret.append(var._cfg_string(prefix, print_descr)) retur...
ret.append(var._cfg_string(prefix, print_descr))
ret.append(var._cfg_string(prefix, print_desc))
def _cfg_string(self, prefix, print_descr=True): ret = [] desc = self._descr.encode(ENCODING, 'replace').replace('\n', '\n# ') if prefix: if print_descr: ret.append('#\n# %s\n# %s\n#\n' % (prefix, desc)) prefix += '.' for name in self._vars: var = self._dict[name] ret.append(var._cfg_string(prefix, print_descr)) retur...
def __init__(self, schema, descr=u'', name='', type=unicode):
def __init__(self, schema, desc=u'', name='', type=unicode):
def __init__(self, schema, descr=u'', name='', type=unicode): if not isinstance(schema, Var): schema = Var(name=name, default=schema) self._schema = copy.deepcopy(schema) self._dict = {} self._type = type self._descr = descr self._name = name if isinstance(self._descr, str): self._descr = unicode(self._descr, ENCOD...
self._descr = descr
self._desc = desc
def __init__(self, schema, descr=u'', name='', type=unicode): if not isinstance(schema, Var): schema = Var(name=name, default=schema) self._schema = copy.deepcopy(schema) self._dict = {} self._type = type self._descr = descr self._name = name if isinstance(self._descr, str): self._descr = unicode(self._descr, ENCOD...
if isinstance(self._descr, str): self._descr = unicode(self._descr, ENCODING, 'replace')
if isinstance(self._desc, str): self._desc = unicode(self._desc, ENCODING, 'replace')
def __init__(self, schema, descr=u'', name='', type=unicode): if not isinstance(schema, Var): schema = Var(name=name, default=schema) self._schema = copy.deepcopy(schema) self._dict = {} self._type = type self._descr = descr self._name = name if isinstance(self._descr, str): self._descr = unicode(self._descr, ENCOD...
def _cfg_string(self, prefix, print_descr=True):
def _cfg_string(self, prefix, print_desc=True):
def _cfg_string(self, prefix, print_descr=True): ret = [] if type(self._schema) == Var and print_descr: ret.append('#\n# %s\n# %s\n#\n' % \ (prefix, self._descr.encode(ENCODING, 'replace'))) print_descr = False
if type(self._schema) == Var and print_descr:
if type(self._schema) == Var and print_desc:
def _cfg_string(self, prefix, print_descr=True): ret = [] if type(self._schema) == Var and print_descr: ret.append('#\n# %s\n# %s\n#\n' % \ (prefix, self._descr.encode(ENCODING, 'replace'))) print_descr = False
(prefix, self._descr.encode(ENCODING, 'replace'))) print_descr = False
(prefix, self._desc.encode(ENCODING, 'replace'))) print_desc = False
def _cfg_string(self, prefix, print_descr=True): ret = [] if type(self._schema) == Var and print_descr: ret.append('#\n# %s\n# %s\n#\n' % \ (prefix, self._descr.encode(ENCODING, 'replace'))) print_descr = False
ret.append(var._cfg_string('%s[%s]' % (prefix, key), print_descr)) if not print_descr:
ret.append(var._cfg_string('%s[%s]' % (prefix, key), print_desc)) if not print_desc:
def _cfg_string(self, prefix, print_descr=True): ret = [] if type(self._schema) == Var and print_descr: ret.append('#\n# %s\n# %s\n#\n' % \ (prefix, self._descr.encode(ENCODING, 'replace'))) print_descr = False
def __init__(self, schema, descr=u'', name=''): Dict.__init__(self, schema, descr, name, int)
def __init__(self, schema, desc=u'', name=''): Dict.__init__(self, schema, desc, name, int)
def __init__(self, schema, descr=u'', name=''): Dict.__init__(self, schema, descr, name, int)
def __init__(self, schema, descr=u'', name=''): Group.__init__(self, schema, descr, name)
def __init__(self, schema, desc=u'', name=''): Group.__init__(self, schema, desc, name)
def __init__(self, schema, descr=u'', name=''): Group.__init__(self, schema, descr, name) self._filename = '' self._bad_lines = []
error = ('Unable to parse the line', line)
error = ('Unable to parse the line', line.encode(local_encoding))
def load(self, filename): self._filename = filename regexp = re.compile('(([a-zA-Z0-9_]+)|(\[.*?\]))') f = open(filename) for line in f.readlines(): if line.find('#') >= 0: line = line[:line.find('#')] line = line.strip() if not line: continue if line.count('=') != 1: error = ('Unable to parse the line', line) if not e...
error = (str(e), line)
error = (str(e), line.encode(local_encoding))
def load(self, filename): self._filename = filename regexp = re.compile('(([a-zA-Z0-9_]+)|(\[.*?\]))') f = open(filename) for line in f.readlines(): if line.find('#') >= 0: line = line[:line.find('#')] line = line.strip() if not line: continue if line.count('=') != 1: error = ('Unable to parse the line', line) if not e...
config = Config(descr='basic config group', schema=[ Var(name='foo', descr='some text', default=5),
config = Config(desc='basic config group', schema=[ Var(name='foo', desc='some text', default=5),
def load(self, filename): self._filename = filename regexp = re.compile('(([a-zA-Z0-9_]+)|(\[.*?\]))') f = open(filename) for line in f.readlines(): if line.find('#') >= 0: line = line[:line.find('#')] line = line.strip() if not line: continue if line.count('=') != 1: error = ('Unable to parse the line', line) if not e...
descr='more text\ndescription has two lines'),
desc='more text\ndescription has two lines'),
def load(self, filename): self._filename = filename regexp = re.compile('(([a-zA-Z0-9_]+)|(\[.*?\]))') f = open(filename) for line in f.readlines(): if line.find('#') >= 0: line = line[:line.find('#')] line = line.strip() if not line: continue if line.count('=') != 1: error = ('Unable to parse the line', line) if not e...
Group(name='inline', descr='this is a subgroup', schema=[ Var(name='x', descr='descr_x', default=7 ), Var(name='y', type=range(0,5), descr='descr_y', default=3 ) ])
Group(name='inline', desc='this is a subgroup', schema=[ Var(name='x', desc='desc_x', default=7 ), Var(name='y', type=range(0,5), desc='desc_y', default=3 ) ])
def load(self, filename): self._filename = filename regexp = re.compile('(([a-zA-Z0-9_]+)|(\[.*?\]))') f = open(filename) for line in f.readlines(): if line.find('#') >= 0: line = line[:line.find('#')] line = line.strip() if not line: continue if line.count('=') != 1: error = ('Unable to parse the line', line) if not e...
subgroup = Group(descr='this is a subgroup', schema=[ Var(name='x', descr='descr_x with non ascii ', default=7 ),
subgroup = Group(desc='this is a subgroup', schema=[ Var(name='x', desc=u'desc_x with non ascii ', default=7 ),
def load(self, filename): self._filename = filename regexp = re.compile('(([a-zA-Z0-9_]+)|(\[.*?\]))') f = open(filename) for line in f.readlines(): if line.find('#') >= 0: line = line[:line.find('#')] line = line.strip() if not line: continue if line.count('=') != 1: error = ('Unable to parse the line', line) if not e...
Var(name='y', type=range(0,5), descr='descr_y', default=3 ) ])
Var(name='y', type=range(0,5), desc='desc_y', default=3 ) ])
def load(self, filename): self._filename = filename regexp = re.compile('(([a-zA-Z0-9_]+)|(\[.*?\]))') f = open(filename) for line in f.readlines(): if line.find('#') >= 0: line = line[:line.find('#')] line = line.strip() if not line: continue if line.count('=') != 1: error = ('Unable to parse the line', line) if not e...
subsubgroup = Group(descr='desrc of subsubgroup', schema=[ Var(name='a', descr='descr a', default=3 ) ])
subsubgroup = Group(desc='desrc of subsubgroup', schema=[ Var(name='a', desc='desc a', default=3 ) ])
def load(self, filename): self._filename = filename regexp = re.compile('(([a-zA-Z0-9_]+)|(\[.*?\]))') f = open(filename) for line in f.readlines(): if line.find('#') >= 0: line = line[:line.find('#')] line = line.strip() if not line: continue if line.count('=') != 1: error = ('Unable to parse the line', line) if not e...
l = List(descr='desrc of list subsubgroup', schema=Group([ Var(name='a', type=int, descr='descr a', default=3 ),
l = List(desc='desrc of list subsubgroup', schema=Group([ Var(name='a', type=int, desc='desc a', default=3 ),
def load(self, filename): self._filename = filename regexp = re.compile('(([a-zA-Z0-9_]+)|(\[.*?\]))') f = open(filename) for line in f.readlines(): if line.find('#') >= 0: line = line[:line.find('#')] line = line.strip() if not line: continue if line.count('=') != 1: error = ('Unable to parse the line', line) if not e...
Group(name='z', descr='this is a subgroup', schema=[ Var(name='x', descr='descr_x', default=7 ), Var(name='y', type=range(0,5), descr='descr_y', default=3 ) ]) ]))
Group(name='z', desc='this is a subgroup', schema=[ Var(name='x', desc='desc_x', default=7 ), Var(name='y', type=range(0,5), desc='desc_y', default=3 ) ]) ]))
def load(self, filename): self._filename = filename regexp = re.compile('(([a-zA-Z0-9_]+)|(\[.*?\]))') f = open(filename) for line in f.readlines(): if line.find('#') >= 0: line = line[:line.find('#')] line = line.strip() if not line: continue if line.count('=') != 1: error = ('Unable to parse the line', line) if not e...
epg = Dict(descr='desrc of dict epg', schema=Var(name='a', descr='descr a', default='' ))
epg = Dict(desc='desrc of dict epg', schema=Var(name='a', desc='desc a', default='' ))
def load(self, filename): self._filename = filename regexp = re.compile('(([a-zA-Z0-9_]+)|(\[.*?\]))') f = open(filename) for line in f.readlines(): if line.find('#') >= 0: line = line[:line.find('#')] line = line.strip() if not line: continue if line.count('=') != 1: error = ('Unable to parse the line', line) if not e...
subgroup = Group(descr='this is a subgroup', schema=[ Var(name='x', descr='descr_x', default=7 ) ])
subgroup = Group(desc='this is a subgroup', schema=[ Var(name='x', desc='desc_x', default=7 ) ])
def load(self, filename): self._filename = filename regexp = re.compile('(([a-zA-Z0-9_]+)|(\[.*?\]))') f = open(filename) for line in f.readlines(): if line.find('#') >= 0: line = line[:line.find('#')] line = line.strip() if not line: continue if line.count('=') != 1: error = ('Unable to parse the line', line) if not e...
epg['x'] = 'non-ascii: ' epg['also-non-ascii '] = 'non-ascii: '
epg['x'] = u'non-ascii: ' epg[u'also-non-ascii '] = u'non-ascii: '
def load(self, filename): self._filename = filename regexp = re.compile('(([a-zA-Z0-9_]+)|(\[.*?\]))') f = open(filename) for line in f.readlines(): if line.find('#') >= 0: line = line[:line.find('#')] line = line.strip() if not line: continue if line.count('=') != 1: error = ('Unable to parse the line', line) if not e...
print 'step'
def _send_packet(self, packet_type, data, seq = 0, timeout = None, reply_cb = None): if not self.socket: return
os.write(_thread_notifier_pipe[1], "1")
if len(_thread_notifier_queue) == 0: os.write(_thread_notifier_pipe[1], "1")
def wakeup(): """ Wake up main thread. """ os.write(_thread_notifier_pipe[1], "1")
if cb_callback(*args, **kwargs):
if cb_callback(*(args + cb_args), **cb_kwargs):
def emit(self, *args, **kwargs): retval = False for cb_callback, cb_args, cb_kwargs, cb_once, cb_weak in self._callbacks[:]: if cb_weak: cb_callback = cb_callback._get_callback() cb_args, cb_kwargs = unweakref_data((cb_args, cb_kwargs)) else: cb_kwargs = cb_kwargs.copy()
self.unregister()
if id == self._id: self.unregister()
def __call__(self, *args, **kwargs): if not self._get_callback(): if self.active(): self.unregister() return False
DEBUG=1 DEBUG=0 def _debug(level, text, *args): if DEBUG >= level: for arg in args: text += " " + str(arg) log.error(text)
# def bar(self):
_debug(1, "New connection", client_sock)
log.debug("New connection", client_sock)
def handle_connection(self): client_sock = self.socket.accept()[0] client_sock.setblocking(False) _debug(1, "New connection", client_sock) client = IPCChannel(self, auth_secret = self._auth_secret, sock = client_sock) self.clients[client_sock] = client self.signals["client_connected"].emit(client)
if not _debug or not hasattr(self, 'address'):
if not hasattr(self, 'address'):
def close(self): if not _debug or not hasattr(self, 'address'): # Python is shutting down _globals have gone away. return
_debug(1, "Closing IPCServer, clients:", self.clients)
log.debug("Closing IPCServer, clients:", self.clients)
def close(self): if not _debug or not hasattr(self, 'address'): # Python is shutting down _globals have gone away. return
_debug(1, "Client closed", self.socket) _debug(1, "Current proxied objects", self._proxied_objects)
log.debug("Client closed", self.socket) log.debug("Current proxied objects", self._proxied_objects)
def handle_close(self): _debug(1, "Client closed", self.socket) _debug(1, "Current proxied objects", self._proxied_objects) self._rmon.unregister() self._wmon.unregister() if self.socket: self.socket.close() self.socket = None if self.server: self.server.client_closed(self)
return
return False
def handle_read(self): try: data = self.socket.recv(1024*1024) except socket.error, (err, msg): if err == errno.EAGAIN: # Resource temporarily unavailable -- we are trying to read # data on a socket when none is available. return # If we're here, then the socket is likely disconnected. data = None except: data = None
_debug(1, "Short packet, need %d, have %d" % (payload_len, len(self.read_buffer)))
log.debug("Short packet, need %d, have %d" % (payload_len, len(self.read_buffer)))
def handle_read(self): try: data = self.socket.recv(1024*1024) except socket.error, (err, msg): if err == errno.EAGAIN: # Resource temporarily unavailable -- we are trying to read # data on a socket when none is available. return # If we're here, then the socket is likely disconnected. data = None except: data = None
_debug(2, "Registered write monitor, write buffer length=%d" % len(self.write_buffer))
log.debug("Registered write monitor, write buffer length=%d" % len(self.write_buffer))
def write(self, data): self.write_buffer += data if not self._wmon.active(): _debug(2, "Registered write monitor, write buffer length=%d" % len(self.write_buffer)) self._wmon.register(self.socket.fileno(), kaa.notifier.IO_WRITE)
_debug(2, "Handle write, write buffer length=%d" % len(self.write_buffer))
log.debug("Handle write, write buffer length=%d" % len(self.write_buffer))
def handle_write(self): if not self.writable(): return
_debug(1, "-> REPLY: seq=%d, command=%s, data=%d" % (seq, command, len(payload)))
log.debug("-> REPLY: seq=%d, command=%s, data=%d" % (seq, command, len(payload)))
def handle_packet(self, seq, packet_type, payload): # Untaint packet_type. if len(packet_type) <= 4 or packet_type[:3] not in ("REP", "REQ") or \ not packet_type[4:].isalpha(): log.warning("Bad request from remote; disconnecting.") return self.handle_close()
_debug(1, "-> REQUEST: seq=%d, command=%s, data=%d" % (seq, command, len(payload)))
log.debug("-> REQUEST: seq=%d, command=%s, data=%d" % (seq, command, len(payload)))
def handle_packet(self, seq, packet_type, payload): # Untaint packet_type. if len(packet_type) <= 4 or packet_type[:3] not in ("REP", "REQ") or \ not packet_type[4:].isalpha(): log.warning("Bad request from remote; disconnecting.") return self.handle_close()
_debug(1, "<- REQUEST: seq=%d, type=%s, data=%d, timeout=%d" % (seq, packet_type, len(pdata), timeout))
log.debug("<- REQUEST: seq=%d, type=%s, data=%d, timeout=%d" % (seq, packet_type, len(pdata), timeout))
def _send_packet(self, packet_type, data, seq = 0, timeout = None, reply_cb = None): if not self.socket: return
_debug(1, "<- REPLY: seq=%d, type=%s, data=%d" % (seq, packet_type, len(pdata)))
log.debug("<- REPLY: seq=%d, type=%s, data=%d" % (seq, packet_type, len(pdata)))
def _send_packet(self, packet_type, data, seq = 0, timeout = None, reply_cb = None): if not self.socket: return
_debug(1, "<- REQUEST COMPLETE: seq=%d, type=%s" % (seq, packet_type))
log.debug("<- REQUEST COMPLETE: seq=%d, type=%s" % (seq, packet_type))
def _send_packet(self, packet_type, data, seq = 0, timeout = None, reply_cb = None): if not self.socket: return
_debug(1, "-> getattr", type(obj), objid, attr)
log.debug("-> getattr", type(obj), objid, attr)
def handle_request_getattr(self, (objid, attr)): obj = self._get_proxied_object(objid) _debug(1, "-> getattr", type(obj), objid, attr) if attr == "__ipcstr__": return str(obj)
_debug(1, "-> setattr", type(obj), objid, attr, value)
log.debug("-> setattr", type(obj), objid, attr, value)
def handle_request_setattr(self, (objid, attr, value)): obj = self._get_proxied_object(objid) value = self._unproxy_data(value) _debug(1, "-> setattr", type(obj), objid, attr, value) # It'd be nice to raise NOREPLY here and make setattr oneway, but # we need to be able to send exceptions to the remote side. setattr(obj...
_debug(1, "-> () CALL %s" % obj.__name__)
log.debug("-> () CALL %s" % obj.__name__)
def handle_request_call(self, (objid, args, kwargs)): _ipc_args = {} for arg in ("copy_result", "noproxy_result", "oneway", "noproxy_args"): if "__ipc_" + arg in kwargs: _ipc_args[arg] = kwargs["__ipc_" + arg] del kwargs["__ipc_" + arg]
_debug(1, "-> () CALL METH: ", objid, meth)
log.debug("-> () CALL METH: ", objid, meth)
def handle_request_callmeth(self, (objid, meth, args, kwargs)): args = self._unproxy_data(args) obj = self._get_proxied_object(objid) _debug(1, "-> () CALL METH: ", objid, meth) result = getattr(obj, meth)(*args, **kwargs) return self._proxy_data(result)
_debug(1, "-> Refcount-- on local object", objid)
log.debug("-> Refcount-- on local object", objid)
def handle_request_decref(self, objid): if objid not in self._proxied_objects: return _debug(1, "-> Refcount-- on local object", objid) self._decref_proxied_object(objid) raise "NOREPLY"
_debug(1, "-> Refcount++ on local object", objid)
log.debug("-> Refcount++ on local object", objid)
def handle_request_incref(self, objid): if objid not in self._proxied_objects: return _debug(1, "-> Refcount++ on local object", objid) self._incref_proxied_object(objid) raise "NOREPLY"
_debug(1, "-> Refcount=0; EXPIRING local proxied object", objid, type(self._proxied_objects[objid][0]))
log.debug("-> Refcount=0; EXPIRING local proxied object", objid, type(self._proxied_objects[objid][0]))
def _decref_proxied_object(self, objid): if objid in self._proxied_objects: self._proxied_objects[objid][1] -= 1 if self._proxied_objects[objid][1] == 0: _debug(1, "-> Refcount=0; EXPIRING local proxied object", objid, type(self._proxied_objects[objid][0])) del self._proxied_objects[objid] else: _debug(1, "<- Refcount-...
_debug(1, "<- Refcount-- on remote object", objid)
log.debug("<- Refcount-- on remote object", objid)
def _decref_proxied_object(self, objid): if objid in self._proxied_objects: self._proxied_objects[objid][1] -= 1 if self._proxied_objects[objid][1] == 0: _debug(1, "-> Refcount=0; EXPIRING local proxied object", objid, type(self._proxied_objects[objid][0])) del self._proxied_objects[objid] else: _debug(1, "<- Refcount-...
_debug(1, "<- Refcount++ on object", objid)
log.debug("<- Refcount++ on object", objid)
def _incref_proxied_object(self, objid): if objid in self._proxied_objects: self._proxied_objects[objid][1] += 1 else: _debug(1, "<- Refcount++ on object", objid) self.request("INCREF", objid, timeout = 0)
_debug(1, "PROXY: (EXISTING) IPCProxy object created from", type(obj), objid)
log.debug("PROXY: (EXISTING) IPCProxy object created from", type(obj), objid)
def _proxy_object(self, obj): objid = self._make_objid(obj) if objid in self._proxied_objects: # Increase refcount self._proxied_objects[objid][1] += 1 _debug(1, "PROXY: (EXISTING) IPCProxy object created from", type(obj), objid) else: self._proxied_objects[objid] = [obj, 1] _debug(1, "PROXY: (NEW) IPCProxy object crea...
_debug(1, "PROXY: (NEW) IPCProxy object created from", type(obj), objid)
log.debug("PROXY: (NEW) IPCProxy object created from", type(obj), objid)
def _proxy_object(self, obj): objid = self._make_objid(obj) if objid in self._proxied_objects: # Increase refcount self._proxied_objects[objid][1] += 1 _debug(1, "PROXY: (EXISTING) IPCProxy object created from", type(obj), objid) else: self._proxied_objects[objid] = [obj, 1] _debug(1, "PROXY: (NEW) IPCProxy object crea...
if not _debug or not self._ipc_client:
if not self._ipc_client:
def __del__(self): # Test _debug function too. If it's None it means we're on shutdown. # This is just a hack to silence "ignored exception" messages. if not _debug or not self._ipc_client: return
_debug(2, "IPCProxy.__getattribute__: %s" % attr)
log.debug("IPCProxy.__getattribute__: %s" % attr)
def __getattribute__(self, attr): _debug(2, "IPCProxy.__getattribute__: %s" % attr) if attr == "__class__" and not self._ipc_local() and self._ipc_class: #print "Spoofing type", self, self._ipc_class return self._ipc_class if attr.startswith("_ipc_") or self._ipc_local(): return object.__getattribute__(self, attr) elif...
_debug(1, "TIME: invocation took %.04f" % (time.time()-t0))
log.debug("TIME: invocation took %.04f" % (time.time()-t0))
def __call__(self, *args, **kwargs): t0=time.time() if self._ipc_callable == False: raise TypeError, "Object not callable" elif self._ipc_callable == None: try: getattr(self, "__call__") self._ipc_callable = True except AttributeError: self._ipc_callable = False if "__ipc_copy_result" in kwargs: log.warning("DEPRECATI...
while async == None and len(result_holder) == 0:
if async != None: return while len(result_holder) == 0:
def connect(self, addr, async = None): """ Connects to the host specified in addr. If addr is a string in the form host:port, or a tuple the form (host, port), a TCP socket is established. Otherwise a Unix socket is established and addr is treated as a filename.
print 'already there'
def create_logger(level = logging.WARNING): """ Create a simple logging object for applicatins that don't want to create a logging handler on their own. You should always have a logging object. """ log = logging.getLogger() # delete current handler for l in log.handlers: log.removeHandler(l) # Create a simple logger o...
qmname = '.'.join(SplitAll(path))
qmname = '.'.join(map(lambda p: QMSanitize(p), SplitAll(path)))
def DoQMTestDir(path, control): """Create a QMTest directory for a given path. The provided directory must have a 'benchmark.xml' file. This creates the corresponding QMTest directories, and copies files from the original directory to the test directories. 'path' -- Path to the benchmark in the source tree. 'control...
self.run_and_log('make -C %s/regtest/tools/texec' % \ self.streamit_home, 'texeclog', 'Building texec')
def prep(self): # Perl regtest would mail the results of 'cvs checkout' and # compilation to the admins list. Consciously avoid doing # that, since we never read it. Do log these to files, though. os.makedirs(self.working_dir) os.chdir(self.working_dir)
os.path.join(regtest_root,
os.path.join(self.streamit_home,
def rt_report(self): os.mkdir(rt_root) # Ignore errors (but hope it works). os.spawnl(os.P_WAIT, os.path.join(regtest_root, 'regtest/qmtest/rt-results.py'), 'rt-results.py', os.path.join(self.streamit_home, 'results.qmr'), rt_root)
e.Run(['make', '-f', 'Makefile.cluster', 'run_cluster'], dir=test_home_dir)
e.Run(['make', 'CCFLAGS=-O0', '-f', 'Makefile.cluster'], dir=test_home_dir)
def Run(self, context, result): """Actually run the StreamIt compiler."""
if os.access(os.path.join(test_home_dir,'run_cluster'), os.F_OK): makestatus=0
if os.access(os.path.join(test_home_dir,'run_cluster'), os.F_OK) \ or os.access(os.path.join(test_home_dir,'fusion'), os.F_OK): makestatus=0
def Run(self, context, result): """Actually run the StreamIt compiler."""
meaningful for the uniprocessor and RAW backends, since 'strc'
meaningful for the uniprocessor, cluster and RAW backends, since 'strc'
def Run(self, context, result): """Actually run the StreamIt compiler."""
self._RunNamedFile(context, result, 'run_cluster')
test_home_dir = context_to_dir(context) if os.access(os.path.join(test_home_dir,'fusion'), os.F_OK): self._RunNamedFile(context, result, 'fusion') else: self._RunNamedFile(context, result, 'run_cluster')
def _RunClu(self, context, result): self._RunNamedFile(context, result, 'run_cluster')
cvs_date = ''
def report(self): header = """StreamIt Regression Test Summary
last_dirname = os.path.basename(os.path.realpath(regtest_root + '/latest')) re_pattern=re.compile('^(\d\d\d\d)(\d\d)(\d\d)\.(\d\d)(\d\d)') m = re_pattern.match(last_dirname) cvs_date = m.group(1)+'-'+m.group(2)+'-'+m.group(3)+' '+m.group(4)+':'+m.group(5) except: pass if cvs_date:
except: pass if self.cvs_date:
def report(self): header = """StreamIt Regression Test Summary