def _(): for k, v in iteritems(self.environ): try: v = str(v) except Exception as e: v = str(e) yield '%s=%s' % (k, v)
def get_events(self, readable, writeable, errors): events = {} for fd in readable: events[fd] = events.get(fd, 0) | IObase.READ for fd in writeable: events[fd] = events.get(fd, 0) | IObase.WRITE for fd in errors: events[fd] = events.get(fd, 0) | IObase.ERROR return list(iteritems(events))
def get_tasks(cls, scheduler, **filters): TASKS = cls.task_container(scheduler) tasks = [] if filters: fs = [] for name, value in iteritems(filters): if not isinstance(value, (list, tuple)): value = (value,) fs.append((name, value)) for t in itervalues(TASKS): for name, values in fs: value = getattr(t, name, None) if value in values: tasks.append(t) return tasks
def match(self, path): '''Match a path and return ``None`` if no matching, otherwise a dictionary of matched variables with values. If there is more to be match in the path, the remaining string is placed in the ``__remaining__`` key of the dictionary.''' match = self._regex.search(path) if match is not None: remaining = path[match.end():] groups = match.groupdict() result = {} for name, value in iteritems(groups): try: value = self._converters[name].to_python(value) except Http404: return result[str(name)] = value if remaining: result['__remaining__'] = remaining return result
def __new__(cls, name, bases, attrs): settings = {} for base in bases: if isinstance(base, TestPluginMeta): settings.update(base.config.settings) for key, setting in list(iteritems(attrs)): if isinstance(setting, pulsar.Setting): attrs.pop(key) setting.name = setting.name or key.lower() settings[setting.name] = as_test_setting(setting) if not attrs.pop('virtual', False): setting_name = attrs.pop('name', name).lower() if setting_name: def_flag = '--%s' % setting_name.replace(' ', '-').replace( '_', '-') action = attrs.pop('action', None) type = attrs.pop('type', None) default = attrs.pop('default', None) validator = attrs.pop('validator', None) nargs = attrs.pop('nargs', None) if (validator is None and default is None and type is None and nargs is None): if action is None or action == 'store_true': action = 'store_true' default = False validator = pulsar.validate_bool elif action == 'store_false': default = True validator = pulsar.validate_bool setting = pulsar.Setting(name=setting_name, desc=attrs.pop('desc', name), type=type, flags=attrs.pop('flags', [def_flag]), action=action, default=default, validator=validator, nargs=nargs) settings[setting.name] = as_test_setting(setting) attrs['config'] = pulsar.Config(settings=settings) return super(TestPluginMeta, cls).__new__(cls, name, bases, attrs)
def __new__(cls, name, bases, attrs): settings = {} for base in bases: if isinstance(base, TestPluginMeta): settings.update(base.config.settings) for key, setting in list(iteritems(attrs)): if isinstance(setting, pulsar.Setting): attrs.pop(key) setting.name = setting.name or key.lower() settings[setting.name] = as_test_setting(setting) if not attrs.pop('virtual', False): setting_name = attrs.pop('name', name).lower() if setting_name: def_flag = '--%s' % setting_name.replace( ' ', '-').replace('_', '-') action = attrs.pop('action', None) type = attrs.pop('type', None) default = attrs.pop('default', None) validator = attrs.pop('validator', None) nargs = attrs.pop('nargs', None) if (validator is None and default is None and type is None and nargs is None): if action is None or action == 'store_true': action = 'store_true' default = False validator = pulsar.validate_bool elif action == 'store_false': default = True validator = pulsar.validate_bool setting = pulsar.Setting(name=setting_name, desc=attrs.pop('desc', name), type=type, flags=attrs.pop('flags', [def_flag]), action=action, default=default, validator=validator, nargs=nargs) settings[setting.name] = as_test_setting(setting) attrs['config'] = pulsar.Config(settings=settings) return super(TestPluginMeta, cls).__new__(cls, name, bases, attrs)
def filter_types(self, type): """Return a generator of all tasks of a specific type.""" return ((job_name, job) for job_name, job in iteritems(self) if job.type == type)
def __str__(self): env = iteritems(self.environ) return '\n%s\n' % '\n'.join(('%s = %s' % (k, v) for k, v in env))