<commit_before>
#!/usr/bin/python
from test_hdf_type import test_hdf_type
from openhdf_modes import openhdf_modes 

#########################################################################
""" This is a function to open any hdf file and return a file object"""
def openhdf(filename, verbose=None, read_mode=None, hdf4type=None):
	
	if verbose is not None:
		print filename

	""" figure out the flavor of the hdf file
	 HDF4 or 5 (supports 5-EOS as well)"""
	filetype = test_hdf_type(filename)

	# Raise an exception if not an HDF file
	if (filetype is None):
			raise Exception("File type is not HDF")
	
	if verbose is not None:
		print 'The filetype is : ', filetype

	""" open the file
	 default is read-mode"""
	
	#this returns a dictionary of functions for the file type	
	modehdf = openhdf_modes(filename,filetype, hdf4type)
	if read_mode is None:
		read_mode = 'read'
	elif read_mode.lower() not in ['read','write','append']:
		raise Exception("Read mode error.  Must be 'read','write',or 'append'")

	if verbose is not None:
		print 'Opening in ', read_mode, 'mode'

	file    = modehdf[read_mode.lower()](filename)
	file.filetype = filetype

	return file<commit_msg>openhdf_modes.py<commit_after>
#!/usr/bin/python
from test_hdf_type import test_hdf_type
from openhdf_modes import openhdf_modes 

#########################################################################
""" This is a function to open any hdf file and return a file object"""
def openhdf(filename, verbose=None, read_mode=None, hdf4type=None):
	
	if verbose is not None:
		print filename

	""" figure out the flavor of the hdf file
	 HDF4 or 5 (supports 5-EOS as well)"""
	filetype = test_hdf_type(filename)

	# Raise an exception if not an HDF file
	if (filetype is None):
			raise Exception("File type is not HDF")
	
	if verbose is not None:
		print 'The filetype is : ', filetype

	""" open the file
	 default is read-mode"""
	
	#this returns a dictionary of functions for the file type	
	modehdf = openhdf_modes(filename,filetype)
	if read_mode is None:
		read_mode = 'read'
	elif read_mode.lower() not in ['read','write','append']:
		raise Exception("Read mode error.  Must be 'read','write',or 'append'")

	if verbose is not None:
		print 'Opening in ', read_mode, 'mode'

	file    = modehdf[read_mode.lower()](filename)
	file.filetype = filetype

	return file
{'fraction_non_alphanumeric': 0.15634344297308841, 'fraction_numerical': 0.003844510892780863, 'mean_word_length': 4.643373493975903, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5749532', 'n_tokens_mistral': 799, 'n_tokens_neox': 728, 'n_words': 268}