def user_process_info(pid): if pid not in user_processes_by_pid: return None user_process = user_processes_by_pid[pid] return select_attrs( user_process, "user_id time_since_last_used awaiting_input fresh_process history", )
def basic_dict(call): return dict( arguments=call.arguments_list, **select_attrs( call, "id function_id return_value traceback " "exception start_time", ), )
def current_state(self): return dict( **select_attrs(self, "hints step_index"), page_index=self.page.index, showEditor=self.page.index >= WritingPrograms.index, showSnoop=(self.page.index, self.step_index) >= (UnderstandingProgramsWithSnoop.index, 1), showPythonTutor=self.page.index >= UnderstandingProgramsWithPythonTutor.index, showBirdseye=True, )
def get_pages(): return dict( pages={ slug: dict( **select_attrs(page, "slug title index step_names"), steps=page.step_dicts, ) for slug, page in pages.items() }, pageSlugsList=page_slugs_list, )
def load_data(self): user = self.user if user.is_anonymous: return {} return dict( pages=[ select_attrs(page, "title step_texts") for page in pages.values() ], state=self.current_state(), user=dict( email=user.email, developerMode=user.developer_mode, ), )
def load_chapters(): chapters_dir = Path(__file__).parent / "chapters" path: Path for path in sorted(chapters_dir.glob("c*.py")): module_name = path.stem full_module_name = "core.chapters." + module_name import_module(full_module_name) slug = module_name[4:] title = slug.replace("_", " ").title() title = t.get(t.chapter_title(slug), title) chapter_pages = [ select_attrs(page, "title slug") for page in pages.values() if page.__module__ == full_module_name ] yield dict(slug=slug, title=title, pages=chapter_pages)
def load_data(self): user = self.user if user.is_anonymous: return {} return dict( pages=[ dict(**select_attrs(page, "slug title index"), steps=page.step_dicts) for page in pages.values() ], state=self.current_state(), user=dict( email=user.email, developerMode=user.developer_mode, ), page_index=pages[self.user.page_slug].index, )
def basic_dict(func): return select_attrs(func, 'file name lineno hash body_hash type')