def getFragmentSchemata(name): """Get matching XML schema for theme fragment""" request = getRequest() filename = (u'{0:s}.xml'.format(name)).encode('utf-8', 'ignore') if not isThemeEnabled(request): return SimpleVocabulary([]) currentTheme = getCurrentTheme() if currentTheme is None: return SimpleVocabulary([]) themeDirectory = queryResourceDirectory(THEME_RESOURCE_NAME, currentTheme) if themeDirectory is None: return SimpleVocabulary([]) if not themeDirectory.isDirectory(FRAGMENTS_DIRECTORY): return SimpleVocabulary([]) if not themeDirectory[FRAGMENTS_DIRECTORY].isFile(filename): return () handle = themeDirectory[FRAGMENTS_DIRECTORY].openFile(filename) schemata = parse(handle, 'collective.themefragments').schemata.values() for schema_ in schemata: schema_.__name__ = schema_.__name__.encode('utf-8', 'ignore') return schemata
def getFragmentSchemata(name): """Get matching XML schema for theme fragment""" request = getRequest() filename = '{0}.xml'.format(name) if not isThemeEnabled(request): return SimpleVocabulary([]) currentTheme = getCurrentTheme() if currentTheme is None: return SimpleVocabulary([]) themeDirectory = queryResourceDirectory(THEME_RESOURCE_NAME, currentTheme) if themeDirectory is None: return SimpleVocabulary([]) if not themeDirectory.isDirectory(FRAGMENTS_DIRECTORY): return SimpleVocabulary([]) if not themeDirectory[FRAGMENTS_DIRECTORY].isFile(filename): return () with themeDirectory[FRAGMENTS_DIRECTORY].openFile(filename) as handle: schemata = parse(handle, 'collective.themefragments').schemata.values() return schemata
def loadFile(filename, reload=False, policy=u"", _frame=2): global _model_cache path = utils.relativeToCallingPackage(filename, _frame) if reload or path not in _model_cache: parsed_model = parser.parse(path, policy=policy) for schema in parsed_model.schemata.values(): schema.setTaggedValue(FILENAME_KEY, path) _model_cache[path] = parsed_model return _model_cache[path]
def loadString(model, policy=u""): return parser.parse(StringIO(model), policy=policy)
def loadString(model, policy=u""): if isinstance(model, str) and not isinstance(model, bytes): model = model.encode('utf-8') return parser.parse(BytesIO(model), policy=policy)
def loadString(model, policy=u""): if not isinstance(model, six.binary_type): model = model.encode() return parser.parse(BytesIO(model), policy=policy)