|
|
|
@ -18,9 +18,55 @@ import re
|
|
|
|
|
import types
|
|
|
|
|
import copy
|
|
|
|
|
from xml import xpath
|
|
|
|
|
from cl_template import xmlDoc
|
|
|
|
|
from cl_template import xmlDoc,blocText
|
|
|
|
|
from format.samba import samba
|
|
|
|
|
|
|
|
|
|
class plasmaBlocText(blocText):
|
|
|
|
|
def findBloc(self, text, captionTxtBloc, bodyTxtBloc):
|
|
|
|
|
""" Делит текст на блоки (с заголовками)
|
|
|
|
|
|
|
|
|
|
captionTxtBloc - регулярное выражение для заголовка блока
|
|
|
|
|
bodyTxtBloc - регулярное выражение для тела блока
|
|
|
|
|
возвращает два списка: первый - заголовки, второй - тела блоков
|
|
|
|
|
"""
|
|
|
|
|
# Заголовки блоков
|
|
|
|
|
headersTxt = []
|
|
|
|
|
# Тексты блоков
|
|
|
|
|
blocsTxt = []
|
|
|
|
|
r = captionTxtBloc.search(text)
|
|
|
|
|
if r:
|
|
|
|
|
headersTxt.append(r.group(0))
|
|
|
|
|
txtSpl = text.partition(r.group(0))
|
|
|
|
|
blocTxt = txtSpl[0]
|
|
|
|
|
txtWr = txtSpl[2]
|
|
|
|
|
rb = bodyTxtBloc.search(blocTxt)
|
|
|
|
|
if not blocTxt:
|
|
|
|
|
blocsTxt.append(blocTxt)
|
|
|
|
|
if rb:
|
|
|
|
|
blocsTxt.append(rb.group(0))
|
|
|
|
|
while (r):
|
|
|
|
|
r = captionTxtBloc.search(txtWr)
|
|
|
|
|
if r:
|
|
|
|
|
headersTxt.append(r.group(0))
|
|
|
|
|
txtSpl = txtWr.partition(r.group(0))
|
|
|
|
|
blocTxt = txtSpl[0]
|
|
|
|
|
txtWr = txtSpl[2]
|
|
|
|
|
rb = bodyTxtBloc.search(blocTxt)
|
|
|
|
|
if rb:
|
|
|
|
|
blocsTxt.append(rb.group(0))
|
|
|
|
|
else:
|
|
|
|
|
blocsTxt.append(txtWr)
|
|
|
|
|
if headersTxt and blocsTxt:
|
|
|
|
|
if len(headersTxt)>len(blocsTxt):
|
|
|
|
|
blocsTxt.insert(0,"")
|
|
|
|
|
elif len(headersTxt)<len(blocsTxt):
|
|
|
|
|
headersTxt.insert(0,"")
|
|
|
|
|
if len(headersTxt)!=len(blocsTxt):
|
|
|
|
|
return False
|
|
|
|
|
return (headersTxt, blocsTxt)
|
|
|
|
|
else:
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
class xmlDocPlasma:
|
|
|
|
|
"""Класс для замены метода joinArea в xmlDoc для plasma"""
|
|
|
|
|
# заменяемый метод для xmlDoc
|
|
|
|
@ -147,7 +193,13 @@ class plasma(samba):
|
|
|
|
|
reSepFields = re.compile(sepFields)
|
|
|
|
|
|
|
|
|
|
def __init__(self,text):
|
|
|
|
|
samba.__init__(self,text)
|
|
|
|
|
self.blocTextObj = plasmaBlocText()
|
|
|
|
|
self.text = text
|
|
|
|
|
self._splitToFields = self.splitToFields
|
|
|
|
|
# Объект документ
|
|
|
|
|
self.docObj = self._textToXML()
|
|
|
|
|
# XML документ
|
|
|
|
|
self.doc = self.docObj.doc
|
|
|
|
|
|
|
|
|
|
# Делим текст на области включая вложенные (areas массив областей)
|
|
|
|
|
def splitToAllArea(self, text, areas):
|
|
|
|
|