Debian Codegraph @

wxgeometrie/pylib/bugs_report.py

raw symbols SCIP
1 # -*- coding: utf-8 -*-
2
3 # WxGeometrie
4 # Dynamic geometry, graph plotter, and more for french mathematic teachers.
5 # Copyright (C) 2005-2013 Nicolas Pourcelot
6 #
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
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, # fichier en cours
46 }
47 for key, value in data.items():
48 # data[key] = zlib.compress(uu(value.replace("\n", "\n<br>\n")).encode("utf-8"), 9).replace("\x01", "\x01\x03").replace("\x00", "\x01\x02") # php n'aime pas les caractères nuls dans une chaîne semble-t-il...
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 # XXX: print_error() is not thread safe.
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 # Ne doit pas exister encore quand on quitte la thread semble-t-il.
66 del exc_traceback
67 return False, msg