| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
import urllib.request, urllib.parse |
| 22 |
import html |
| 23 |
import sys |
| 24 |
import traceback |
| 25 |
|
| 26 |
from .. import param |
| 27 |
from .infos import informations_configuration |
| 28 |
|
| 29 |
def rapporter(titre='', auteur='', email='', description='', historique='', |
| 30 |
log='', config='', fichier=''): |
| 31 |
parametres = param.__dict__.copy() |
| 32 |
parametres.pop("__builtins__", {}) |
| 33 |
parametres = "\n".join(str(key) + " = " + repr(val) for key, val in parametres.items()) |
| 34 |
|
| 35 |
data = { |
| 36 |
"version": param.version, |
| 37 |
"config": config or informations_configuration(), |
| 38 |
"titre": titre, |
| 39 |
"auteur": auteur, |
| 40 |
"email": email, |
| 41 |
"param": parametres, |
| 42 |
"description": description, |
| 43 |
"historique": historique, |
| 44 |
"log": log, |
| 45 |
"fichier": fichier, |
| 46 |
} |
| 47 |
for key, value in data.items(): |
| 48 |
.. |
| 49 |
data[key] = html.escape(value).replace("\n", "\n<br>\n").encode("iso-8859-1", 'xmlcharrefreplace') |
| 50 |
msg = 'Erreur.' |
| 51 |
try: |
| 52 |
filename, headers = urllib.request.urlretrieve("http://wxgeo.free.fr/wordpress/contact") |
| 53 |
with open(filename) as f: |
| 54 |
adresse = f.read(300) |
| 55 |
remote = urllib.request.urlopen(adresse, urllib.parse.urlencode(data).encode('utf8')) |
| 56 |
msg = html.unescape(remote.read().decode('utf-8')) |
| 57 |
remote.close() |
| 58 |
return True, msg |
| 59 |
except Exception as e: |
| 60 |
|
| 61 |
exc_type, exc_value, exc_traceback = sys.exc_info() |
| 62 |
msg_err = ''.join(traceback.format_exception(exc_type, exc_value, |
| 63 |
exc_traceback)) |
| 64 |
msg = f'{msg} {msg_err}' |
| 65 |
|
| 66 |
del exc_traceback |
| 67 |
return False, msg |