# Path: version_metadata/utils.py
# def sanity_check_fail(msg):
# 	def __init__(self, message, iterable):
# 	def __init__(self):
# 	def __call__(self, m):
# 	def entry(self, m): 
# 	def warn(self, m):
# 	def debugonly(self, *args):
# 	def trystr(self, x):
# 	def __init__(self):
# 	def fread(self, f, encoding=''):
# 	def fentries(self, f):
# 	def writel(self, f, entries, sep=b'\n', encoding=None):
# 	def dumpf(self, f, data):
# 	def fexists(self, filename):
# 	def demanduniq(self, iterable):
# 	def tryuniq(self, iterable):
# 	def safedict(self, tuples):
# 	def now(self):
# 	def basename(self, f):
# 	def getpath(data, ifmissing, *args):
# 	def __init__(self):
# 	def loadf(self, f):
# 	def dumpf(self, f, data):
# 	def multidictLoadf(self, f):
# 	def loads(self, data):
# 	def multidictLoadStr(self, data):
# 		def multidictParser(pairs):
# 	def pretty(self, arg):
# 	def pp(self, arg):
# 	def copyobj(self, x):
# class NonUniqException(Exception):
# class Logger:
# class Utils:
# class Json:


from lxml import etree
from collections import defaultdict
from .utils import cmn, json2, logger, NonUniqException
			found = self.extract_optional(obj,k)
			key = k.lower().split('/')[-1]
			hashed[key] = cmn.tryuniq(list(map(lambda x: x.text, found))) if found else  "__missing__:{0}/{1}".format(k, found)
		hashed['@idblock'] = {k: obj.attrib[k] for k in obj.attrib}
		if object_type in ['EXPERIMENT']:
			hashed = self.extract_additional_experiment_attributes(obj, hashed)
		return hashed
	def from_sra_main_to_attributes(self, hashed):
		if 'library_strategy' in hashed:
			if 'LIBRARY_STRATEGY' in hashed['attributes'] or 'library_strategy' in hashed['attributes']:
				lib_strat_attr = 'LIBRARY_STRATEGY' if 'LIBRARY_STRATEGY' in hashed['attributes'] else 'library_strategy'
				hashed['attributes']['LIBRARY_STRATEGY_IHEC'] = hashed['attributes'][lib_strat_attr]
				old_lib_start = hashed['attributes'].pop(lib_strat_attr)
				logger("#warn:__library_strategy__ defined in both SRA block and as IHEC attribute:{0}, value pushed into 'LIBRARY_STRATEGY_IHEC'\n".format(old_lib_start))
			hashed['attributes']['LIBRARY_STRATEGY'] = [hashed['library_strategy']]
		#hashed['attributes']['@idblock'] = hashed['@idblock']	
		return hashed
	def parse_attributes_block(self, obj, objtype):
		if not objtype in self.expected_obj_tags: # [objtype, self.expected_obj_tags]
			utils.sanity_check_fail('__unexpected_object_type__:' + objtype)
		attrtag = '{0}_ATTRIBUTES'.format(objtype)
		attributes_found = list(obj.findall(attrtag))
		if len(attributes_found) == 0:
			logger.warn("#__warn__... no attributes block found...\n")
			return dict()
		attrs = cmn.demanduniq(attributes_found)
		attrhash = defaultdict(list)
		for e in attrs.getchildren():
			try:
				tag = cmn.demanduniq(e.findall('TAG')).text

# Path: version_metadata/utils.py
# def sanity_check_fail(msg):
# 	def __init__(self, message, iterable):
# 	def __init__(self):
# 	def __call__(self, m):
# 	def entry(self, m): 
# 	def warn(self, m):
# 	def debugonly(self, *args):
# 	def trystr(self, x):
# 	def __init__(self):
# 	def fread(self, f, encoding=''):
# 	def fentries(self, f):
# 	def writel(self, f, entries, sep=b'\n', encoding=None):
# 	def dumpf(self, f, data):
# 	def fexists(self, filename):
# 	def demanduniq(self, iterable):
# 	def tryuniq(self, iterable):
# 	def safedict(self, tuples):
# 	def now(self):
# 	def basename(self, f):
# 	def getpath(data, ifmissing, *args):
# 	def __init__(self):
# 	def loadf(self, f):
# 	def dumpf(self, f, data):
# 	def multidictLoadf(self, f):
# 	def loads(self, data):
# 	def multidictLoadStr(self, data):
# 		def multidictParser(pairs):
# 	def pretty(self, arg):
# 	def pp(self, arg):
# 	def copyobj(self, x):
# class NonUniqException(Exception):
# class Logger:
# class Utils:
# class Json:


# Path: version_metadata/sraparse.py
from lxml import etree
from collections import defaultdict
from .utils import cmn, json2, logger, NonUniqException

			found = self.extract_optional(obj,k)
			key = k.lower().split('/')[-1]
			hashed[key] = cmn.tryuniq(list(map(lambda x: x.text, found))) if found else  "__missing__:{0}/{1}".format(k, found)
		hashed['@idblock'] = {k: obj.attrib[k] for k in obj.attrib}
		if object_type in ['EXPERIMENT']:
			hashed = self.extract_additional_experiment_attributes(obj, hashed)
		return hashed
	def from_sra_main_to_attributes(self, hashed):
		if 'library_strategy' in hashed:
			if 'LIBRARY_STRATEGY' in hashed['attributes'] or 'library_strategy' in hashed['attributes']:
				lib_strat_attr = 'LIBRARY_STRATEGY' if 'LIBRARY_STRATEGY' in hashed['attributes'] else 'library_strategy'
				hashed['attributes']['LIBRARY_STRATEGY_IHEC'] = hashed['attributes'][lib_strat_attr]
				old_lib_start = hashed['attributes'].pop(lib_strat_attr)
				logger("#warn:__library_strategy__ defined in both SRA block and as IHEC attribute:{0}, value pushed into 'LIBRARY_STRATEGY_IHEC'\n".format(old_lib_start))
			hashed['attributes']['LIBRARY_STRATEGY'] = [hashed['library_strategy']]
		#hashed['attributes']['@idblock'] = hashed['@idblock']	
		return hashed
	def parse_attributes_block(self, obj, objtype):
		if not objtype in self.expected_obj_tags: # [objtype, self.expected_obj_tags]
			utils.sanity_check_fail('__unexpected_object_type__:' + objtype)
		attrtag = '{0}_ATTRIBUTES'.format(objtype)
		attributes_found = list(obj.findall(attrtag))
		if len(attributes_found) == 0:
			logger.warn("#__warn__... no attributes block found...\n")
			return dict()
		attrs = cmn.demanduniq(attributes_found)
		attrhash = defaultdict(list)
		for e in attrs.getchildren():
			try:
				tag = cmn.demanduniq(e.findall('TAG')).text

				value = cmn.demanduniq(e.findall('VALUE')).text