~dpm/qreator/snap

« back to all changes in this revision

Viewing changes to qreator/qrcodes/QRCodeWifiGtk.py

  • Committer: David Planella
  • Date: 2013-08-06 07:46:28 UTC
  • mfrom: (176.1.1 qreator)
  • Revision ID: david.planella@ubuntu.com-20130806074628-y6e58c6xcrxduhzv
Escape special characters in Wifi passwords

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
from gi.repository import Gtk, NetworkManager, NMClient, GLib, GdkPixbuf
21
21
 
22
22
 
 
23
def _escape(st):
 
24
        """Replace problematic characters with the escaped versions.
 
25
 
 
26
        Note that the backslash must be the first character to replace"""
 
27
        esc_string = st
 
28
        for c in ["\\", ",", ":", ";"]:
 
29
            esc_string = esc_string.replace(c, "\\" + c)
 
30
        return esc_string
 
31
    
 
32
 
23
33
class QRCodeWifiGtk(object):
24
34
    def __init__(self, qr_code_update_func):
25
35
        self.qr_code_update_func = qr_code_update_func
94
104
        if not security or ssid == '' or password == '':
95
105
            return
96
106
 
97
 
        wifi_qr_code = 'WIFI:T:{0};S:{1};P:{2};;'.format(security, ssid,
98
 
                                                         password)
 
107
        wifi_qr_code = 'WIFI:T:{0};S:{1};P:{2};;'.format(_escape(security), _escape(ssid),
 
108
                                                         _escape(password))
99
109
        self.qr_code_update_func(wifi_qr_code)
100
110
 
101
111
    def on_comboboxtextSecurity_changed(self, widget, data=None):