Skip to content
Snippets Groups Projects
Commit daefea01 authored by Yann Leboulanger's avatar Yann Leboulanger
Browse files

function moved to helpers.py

parent 210d9895
No related branches found
No related tags found
No related merge requests found
......@@ -19,6 +19,7 @@
from common import i18n
_ = i18n._
import sre
def get_uf_show(show):
'''returns a userfriendly string for dnd/xa/chat
......@@ -49,4 +50,28 @@ def get_sorted_keys(adict):
keys = adict.keys()
keys.sort()
return keys
\ No newline at end of file
def to_one_line(msg):
msg = msg.replace('\\', '\\\\')
msg = msg.replace('\n', '\\n')
# s1 = 'test\ntest\\ntest'
# s11 = s1.replace('\\', '\\\\')
# s12 = s11.replace('\n', '\\n')
# s12
# 'test\\ntest\\\\ntest'
return msg
def from_one_line(msg):
# (?<!\\) is a lookbehind assertion which asks anything but '\'
# to match the regexp that follows it
# So here match '\\n' but not if you have a '\' before that
re = sre.compile(r'(?<!\\)\\n')
msg = re.sub('\n', msg)
msg = msg.replace('\\\\', '\\')
# s12 = 'test\\ntest\\\\ntest'
# s13 = re.sub('\n', s12)
# s14 s13.replace('\\\\', '\\')
# s14
# 'test\ntest\\ntest'
return msg
......@@ -20,10 +20,10 @@
import os
import sys
import time
import sre
import common.gajim
from common import i18n
_ = i18n._
from common import helpers
LOGPATH = os.path.expanduser('~/.gajim/logs')
if os.name == 'nt':
......@@ -54,12 +54,6 @@ class Logger:
print 'creating', LOGPATH, 'directory'
os.mkdir(LOGPATH)
# (?<!\\) is a lookbehind assertion which asks anything but '\'
# to match the regexp that follows it
# So here match '\\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):
if not tim:
tim = time.time()
......@@ -68,18 +62,7 @@ class Logger:
if not msg:
msg = ''
msg = msg.replace('\\', '\\\\')
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'
msg = helpers.to_one_line(msg)
if len(jid.split('/')) > 1:
ji, nick = jid.split('/', 1)
else:
......@@ -176,17 +159,7 @@ class Logger:
while nb < end_line:
line = fic.readline()
if line:
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'
line = helpers.from_one_line(line)
lineSplited = line.split(':')
if len(lineSplited) > 2:
lines.append(lineSplited)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment