Results for python : 10

1 - locale_load + trad
def locale_load(self,lang):
		locale_file='sys/locales/'+lang+".locale"
		if not os.path.isfile(locale_file): 
			self.locale={}
			return

		locale={}
		locale_str=file_get_contents(locale_file)
		locale_str=re.findall('\"(?P<eng>.*?)\"=\"(?P<trad>.*?)\"',locale_str)
		for key,val in enumerate(locale_str):
			locale[locale_str[key][0]]=locale_str[key][1]
		self.locale=locale

# syntaxe du fichier locale
#"Title"="Titre",
#"Author"="Auteur",
#"Language"="Langue",

		
	def trad(self,term):
		if not term in self.locale: 
			return term
		return self.locale[term]
			
2 - ini_load
	def ini_load(self,ini_file):
		if not os.path.isfile(ini_file): return false
		cfg={}
		ini_str=file_get_contents(ini_file)
		ini=re.findall('(?P<var>[a-zA-Z0-9_]*?)=\"(?P<value>[^\"]*?)\"',ini_str)
		for key,val in enumerate(ini):
			cfg[ini[key][0]]=ini[key][1]
		self.cfg=cfg
		

# syntaxe des variables
# folder_path="test/"
			
3 - no_accents
def no_accents(string):
	replacements=[
		(u"é","e"),
		(u"ê","e"),
		(u"è","e"),
		(u"ë","e"),
		(u"ô","o"),
		(u"ó","o"),
		(u"ù","u"),
		(u"ú","u"),
		(u"û","u"),
		(u"ü","u"),
		(u"î","i"),
		(u"ï","i"),
		(u"í","i"),
		(u"â","a"),
		(u"à","a"),
		(u"á","a"),
		(u"ä","a"),
		(u"ñ","n")
	]
	for a, b in replacements:
		string = string.replace(a, b)
	return string
			
6 - file_get_contents & file_put_contents
# file_get_contents function
def file_get_contents(filename):
	content=""
	if not os.path.isfile(filename): return false
	f = open(filename, 'r')
	try:
		content=f.read(1000000).decode('utf8')
	finally:
		f.close()
	return content

# file_put_contents function
def file_put_contents(filename,data):
	if not os.path.isfile(filename): return false
	f = open(filename, 'w')
	f.write(data.decode('utf8'))
	f.close()
			
7 - loadJson & saveJson
# saveJson function
def saveJson(filename,data):
	f = open(filename, 'w')
	f.write(json.dumps(data))
	f.close()

# loadJson function
def loadJson(filename):
	if not os.path.isfile(filename): return false
	f = open(filename, 'r')
	content=f.read()
	if content=="":return {}
	return json.loads(content)

			
9 - file_get_contents-file_put_contents
import os
# file_get_contents function
def file_get_contents(filename):
	if not os.path.isfile(filename): return false
	f = open(filename, 'r')
	return f.read()
# file_put_contents function
def file_put_contents(filename,data):
	if not os.path.isfile(filename): return false
	f = open(filename, 'w')
	f.write(data)
	f.close()
			
10 - striptags
import re
# strip tags function
def striptags(self,string=""):
		return re.sub("<[^>]*?>|&lt;[^>]*?&gt;","",string)