def write(self, abs_path: Text, data) -> None: Json.write( abs_path, Json.load(Json.dump(data)), ident=self._indent, sort_keys=self._sort_keys )
def json(self): """ Deserialize response text containing JSON """ if not self.text: return None return Json.load(self.text)
def to_json(self): """ Returns JSON representation of the error This was customized as the Falcon Base errors return JSON pretty printed """ return Json.dump(self.to_dict())
def render(self, embryo: 'Embryo', style_config: Dict = None) -> None: """ # Args - embryo: the Embryo object - context: a context dict for use by jinja2 templates. - style_config: yapf style options for code formating. 1. Create the directories and files in the file system. 2. Render templates into said files. """ self.embryo = embryo self.root = embryo.destination.rstrip('/') self._buildjinja2_templates() self._analyze_embryo() # prepare a copy of the context for logging purposes only ctx = self.embryo.dumped_context.copy() del ctx['embryo'] ctx_json = Json.dump(ctx, indent=2, sort_keys=True) say(f'context:\n\n{ctx_json}\n') say( 'tree:\n\n{tree}'.format( tree='\n'.join( ' ' * 4 + line for line in Yaml.dump(self.embryo.tree).split('\n') ) ) ) self.embryo.fs._touch_filesystem(self.root, self.directory_paths, self.fpaths) self._render_files(style_config) self.embryo.persist()
def build_base_filters(cls): from appyratus.files import Json return { 'snake': StringUtils.snake, 'dash': StringUtils.dash, 'title': StringUtils.title, 'camel': StringUtils.camel, 'camel_lower': lambda x: StringUtils.camel(x, lower=True), 'plural': StringUtils.plural, 'singular': StringUtils.singular, 'alphanumeric': StringUtils.alphanumeric, 'contiguous': StringUtils.contiguous, 'constant': StringUtils.constant, 'format_python': FormatPythonFilter(), 'python2html': Python2HtmlFilter(), 'markdown2html': Markdown2HtmlFilter(), 'keyword': KeywordFilter(), 'dot': StringUtils.dot, 'wrap': StringUtils.wrap, 'json': lambda obj: (Json.dump(obj, indent=2, sort_keys=True)), 'jinja': lambda tpl, ctx: self.env.from_string(tpl).render(ctx), 'jinja_exp': lambda x: "{{ " + x + " }}", 'jinja_stmt': lambda x: "{% " + x + " %}", 'datetime': DateTimeFilter(), }
def _read_file(cls, path: Text) -> Dict: ext = os.path.splitext(path)[-1].lower().lstrip('.') if ext in ('yaml', 'yml'): return cls._expand_vars(Yaml.read(path) or {}) elif ext == 'json': return cls._expand_vars(Json.read(path) or {}) else: raise UnrecognizedManifestFileFormat( f'only json and yaml manifest files are ' f'supported: {path}')
def load_static_context(self) -> Dict: path = os.path.join(self.path, 'context.yml') if os.path.exists(path): return Yaml.read(path) or {} path = os.path.join(self.path, 'context.json') if os.path.exists(path): return Json.read(path) or {} raise ValueError(f'cannot find context file')
def read(self, abs_path: Text) -> dict: return Json.read(abs_path)
def extensions(self) -> set: return Json.extensions()