1 - Serveur de fichiers rapide en Python
Terminal depuis le dossier à partager puis:
(en Python 2) : python -m SimpleHTTPServer 5555
(en Python 3) : python -m http.server 5555
et accédez avec un simple navigateur (http://adresseip:5555)
Terminal depuis le dossier à partager puis:
(en Python 2) : python -m SimpleHTTPServer 5555
(en Python 3) : python -m http.server 5555
et accédez avec un simple navigateur (http://adresseip:5555)
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]
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/"
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
import urllib
# get_distant_file function
def get_distant_file(string):
try:
data=urllib.urlopen(string).read()
except:
data=""
finally:
return data.encode('utf8')
# strip tags function
def striptags(string):
return re.sub(u"<head>[^^]*?</head>|<[^>]*?>|<[^>]*?>| ",u" ",string)
# 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()
# 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)
# aff(var)
def aff(var):
import pprint
pprint.pprint(var)
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()
import re
# strip tags function
def striptags(self,string=""):
return re.sub("<[^>]*?>|<[^>]*?>","",string)