File: bugs_report.py

package info (click to toggle)
geophar 18.08.7%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 10,960 kB
  • sloc: python: 41,141; javascript: 1,529; makefile: 101; xml: 97; sh: 45
file content (59 lines) | stat: -rw-r--r-- 2,440 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# -*- coding: utf-8 -*-

#    WxGeometrie
#    Dynamic geometry, graph plotter, and more for french mathematic teachers.
#    Copyright (C) 2005-2013  Nicolas Pourcelot
#
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

import urllib.request, urllib.parse
import cgi

from .. import param
from .infos import informations_configuration

def rapporter(titre='', auteur='', email='', description='', historique='',
              log='', config='', fichier=''):
    parametres = param.__dict__.copy()
    parametres.pop("__builtins__", {})
    parametres = "\n".join(str(key) + " = " + repr(val) for key, val in parametres.items())

    data = {
    "version": param.version,
    "config": config or informations_configuration(),
    "titre": titre,
    "auteur": auteur,
    "email": email,
    "param": parametres,
    "description": description,
    "historique": historique,
    "log": log,
    "fichier": fichier, # fichier en cours
    }
    for key, value in data.items():
#        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...
        data[key] = cgi.escape(value).replace("\n", "\n<br>\n").encode("iso-8859-1", 'xmlcharrefreplace')
    msg = 'Erreur inconnue.'
    try:
        filename, headers = urllib.request.urlretrieve("http://wxgeo.free.fr/wordpress/contact")
        with open(filename) as f:
            adresse = f.read(300)
        remote = urllib.request.urlopen(adresse, urllib.parse.urlencode(data))
        msg = remote.read()
        remote.close()
        return True, msg
    except Exception:
        # XXX: print_error() is not thread safe.
        return False, msg