emat/util/xmle/xhtml.py
def load_metadata(filename):
	"""
	Extract metadata from an HTML file previously saved by `XHTML`.

	Parameters
	----------
	filename : Path-like
		The filename of the HTML file that contains the metadata.

	Returns
	-------
	object
		The unpickled meta-data saved in the file.
	"""
	import pickle, zlib, base64
	if not os.path.exists(filename):
		raise FileNotFoundError(filename)

	if (len(filename)>5 and filename[-5:]=='.html') or (len(filename)>6 and filename[-6:]=='.xhtml'):
		from html.parser import HTMLParser
		class HTMLParser_MetaDataLoader(HTMLParser):
			def handle_starttag(subself, tag, attrs):
				global self
				if tag=='meta':
					use = False
					for attrname,attrval in attrs:
						if attrname=='name' and attrval=='pythonmetadata':
							use = True
					if use:
						for attrname,attrval in attrs:
							if attrname=='content':
								attrval = base64.standard_b64decode(attrval.encode())
								attrval = zlib.decompress(attrval)
								subself.self = pickle.loads(attrval)
		parser = HTMLParser_MetaDataLoader()
		with open(filename) as f:
			parser.feed(f.read())
		try:
			if parser.self is None:
				raise ValueError('nothing loaded')
		except AttributeError:
			raise ValueError('nothing found to load')
		return parser.self
	else:
		raise ValueError('must load html')

	Extract metadata from an HTML file previously saved by `XHTML`.

	Parameters
	----------
	filename : Path-like
		The filename of the HTML file that contains the metadata.

	Returns
	-------
	object
		The unpickled meta-data saved in the file.
	
Extract metadata from an HTML file previously saved by `XHTML`.
Parameters

filename : Path-like
The filename of the HTML file that contains the metadata.

Returns

object
The unpickled meta-data saved in the file.
Extract metadata from an HTML file previously saved by ` XHTML ` . Parameters filename : Path - like The filename of the HTML file that contains the metadata . Returns object The unpickled meta - data saved in the file .
def load_metadata(filename):
	import pickle, zlib, base64
	if not os.path.exists(filename):
		raise FileNotFoundError(filename)
	if (len(filename)>5 and filename[-5:]=='.html') or (len(filename)>6 and filename[-6:]=='.xhtml'):
		from html.parser import HTMLParser
		class HTMLParser_MetaDataLoader(HTMLParser):
			def handle_starttag(subself, tag, attrs):
				global self
				if tag=='meta':
					use = False
					for attrname,attrval in attrs:
						if attrname=='name' and attrval=='pythonmetadata':
							use = True
					if use:
						for attrname,attrval in attrs:
							if attrname=='content':
								attrval = base64.standard_b64decode(attrval.encode())
								attrval = zlib.decompress(attrval)
								subself.self = pickle.loads(attrval)
		parser = HTMLParser_MetaDataLoader()
		with open(filename) as f:
			parser.feed(f.read())
		try:
			if parser.self is None:
				raise ValueError('nothing loaded')
		except AttributeError:
			raise ValueError('nothing found to load')
		return parser.self
	else:
		raise ValueError('must load html')
def load_metadata ( filename ) : import pickle , zlib , base64 if not os . path . exists ( filename ) : raise FileNotFoundError ( filename ) if ( len ( filename ) > 5 and filename [ - 5 : ] == '.html' ) or ( len ( filename ) > 6 and filename [ - 6 : ] == '.xhtml' ) : from html . parser import HTMLParser class HTMLParser_MetaDataLoader ( HTMLParser ) : def handle_starttag ( subself , tag , attrs ) : global self if tag == 'meta' : use = False for attrname , attrval in attrs : if attrname == 'name' and attrval == 'pythonmetadata' : use = True if use : for attrname , attrval in attrs : if attrname == 'content' : attrval = base64 . standard_b64decode ( attrval . encode ( ) ) attrval = zlib . decompress ( attrval ) subself . self = pickle . loads ( attrval ) parser = HTMLParser_MetaDataLoader ( ) with open ( filename ) as f : parser . feed ( f . read ( ) ) try : if parser . self is None : raise ValueError ( 'nothing loaded' ) except AttributeError : raise ValueError ( 'nothing found to load' ) return parser . self else : raise ValueError ( 'must load html' )
Extract metadata from an HTML file previously saved by `XHTML`.
Extract metadata from an HTML file previously saved by ` XHTML ` .
"""
	Extract metadata from an HTML file previously saved by `XHTML`.

	Parameters
	----------
	filename : Path-like
		The filename of the HTML file that contains the metadata.

	Returns
	-------
	object
		The unpickled meta-data saved in the file.
	"""
filename