we now save and restore '\n' '\\n' differently (fix #244)
This commit is contained in:
parent
ed1b26f120
commit
0b79deddb9
|
@ -20,6 +20,7 @@
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
|
import sre
|
||||||
import common.gajim
|
import common.gajim
|
||||||
from common import i18n
|
from common import i18n
|
||||||
_ = i18n._
|
_ = i18n._
|
||||||
|
@ -52,6 +53,10 @@ class Logger:
|
||||||
if not os.path.isdir(LOGPATH):
|
if not os.path.isdir(LOGPATH):
|
||||||
print 'creating', LOGPATH, 'directory'
|
print 'creating', LOGPATH, 'directory'
|
||||||
os.mkdir(LOGPATH)
|
os.mkdir(LOGPATH)
|
||||||
|
# (?<!...) Matches if ... doesn't matche next, but doesn't consume
|
||||||
|
# the string.
|
||||||
|
# So matches on '\\n' but not if you have a '\' before that
|
||||||
|
self.re = sre.compile(r'(?<!\\)\\n')
|
||||||
|
|
||||||
def write(self, kind, msg, jid, show = None, tim = None):
|
def write(self, kind, msg, jid, show = None, tim = None):
|
||||||
if not tim:
|
if not tim:
|
||||||
|
@ -61,7 +66,18 @@ class Logger:
|
||||||
|
|
||||||
if not msg:
|
if not msg:
|
||||||
msg = ''
|
msg = ''
|
||||||
|
msg = msg.replace('\\', '\\\\')
|
||||||
msg = msg.replace('\n', '\\n')
|
msg = msg.replace('\n', '\\n')
|
||||||
|
# s1 = 'test\ntest'
|
||||||
|
# s2 = 'test\\ntest'
|
||||||
|
# s11 = s1.replace('\\', '\\\\')
|
||||||
|
# s21 = s2.replace('\\', '\\\\')
|
||||||
|
# s12 = s11.replace('\n', '\\n')
|
||||||
|
# s22 = s21.replace('\n', '\\n')
|
||||||
|
# s12
|
||||||
|
# 'test\\ntest'
|
||||||
|
# s22
|
||||||
|
# test\\\\ntest'
|
||||||
if len(jid.split('/')) > 1:
|
if len(jid.split('/')) > 1:
|
||||||
ji, nick = jid.split('/', 1)
|
ji, nick = jid.split('/', 1)
|
||||||
else:
|
else:
|
||||||
|
@ -158,7 +174,17 @@ class Logger:
|
||||||
while nb < end_line:
|
while nb < end_line:
|
||||||
line = fic.readline()
|
line = fic.readline()
|
||||||
if line:
|
if line:
|
||||||
line = line.replace('\\n', '\n')
|
line = self.re.sub('\n', line)
|
||||||
|
line = line.replace('\\\\', '\\')
|
||||||
|
# re = sre.compile(r'(?<!\\)\\n')
|
||||||
|
# s13 = re.sub('\n', s12)
|
||||||
|
# s23 = re.sub('\n', s22)
|
||||||
|
# s14 = s13.replace('\\\\', '\\')
|
||||||
|
# s24 = s23.replace('\\\\', '\\')
|
||||||
|
# s14
|
||||||
|
# 'test\ntest'
|
||||||
|
# s24
|
||||||
|
# 'test\\ntest'
|
||||||
lineSplited = line.split(':')
|
lineSplited = line.split(':')
|
||||||
if len(lineSplited) > 2:
|
if len(lineSplited) > 2:
|
||||||
lines.append(lineSplited)
|
lines.append(lineSplited)
|
||||||
|
|
Loading…
Reference in New Issue