Re: Python and Cyrillic characters in regular expression

2008-09-05 Thread phasma
string = uПривет
(u'\u041f\u0440\u0438\u0432\u0435\u0442',)

string = uHi.Привет
(u'Hi',)

On Sep 4, 9:53 pm, Fredrik Lundh [EMAIL PROTECTED] wrote:
 phasma wrote:
  Hi, I'm trying extract all alphabetic characters from string.

  reg = re.compile('(?u)([\w\s]+)', re.UNICODE)
  buf = re.match(string)

  But it's doesn't work. If string starts from Cyrillic character, all
  works fine. But if string starts from Latin character, match returns
  only Latin characters.

 can you provide a few sample strings that show this behaviour?

 /F

--
http://mail.python.org/mailman/listinfo/python-list

BZip2 decompression and parsing XML

2008-06-06 Thread phasma
Hi.

I'm trying to disassemble bzipped file. If I use minidom.parseString,
I'm getting this error:

Traceback (most recent call last):
  File ./replications.py, line 342, in ?

  File /usr/lib64/python2.4/xml/dom/minidom.py, line 1925, in
parseString
return expatbuilder.parseString(string)
  File /usr/lib64/python2.4/xml/dom/expatbuilder.py, line 940, in
parseString
return builder.parseString(string)
  File /usr/lib64/python2.4/xml/dom/expatbuilder.py, line 223, in
parseString
parser.Parse(string, True)
xml.parsers.expat.ExpatError: not well-formed (invalid token): line
538676, column 17

If I use minidom.parse, I'm getting this error:

Traceback (most recent call last):
  File ./replications.py, line 341, in ?
files.xml = minidom.parse(bz2.decompress(dump))
  File /usr/lib64/python2.4/xml/dom/minidom.py, line 1915, in parse
return expatbuilder.parse(file)
  File /usr/lib64/python2.4/xml/dom/expatbuilder.py, line 922, in
parse
fp = open(file, 'rb')
IOError

But XML parsed normally.

Code:

try:
handler = open(args[0], r)
dump = handler.read()
handler.close()
except IOError, error:
print(Can't open dump: %s % error)
sys.exit(1)

files.xml = minidom.parse(bz2.decompress(dump))

--
http://mail.python.org/mailman/listinfo/python-list


Export data to OpenDocument Text

2008-03-30 Thread phasma
Hi!

I'm trying to save data from sqlite to OpenDocument Text.

Code:

localtime = time.localtime(time.time())

try:
odt_file = zipfile.ZipFile(file_name, w)
except:
print(Невозможно открыть файл для записи)
return False


buff_file = zipfile.ZipInfo(mimetype, localtime)

odt_file.writestr(buff_file, application/
vnd.oasis.opendocument.text)

buff_file = zipfile.ZipInfo(content.xml, localtime)
buff_file.external_attr = 2179792896
buff_file.flag_bits = 8
buff_file.compress_type = zipfile.ZIP_DEFLATED

odt_file.writestr(buff_file, \n.join(content_xml))

buff_file = zipfile.ZipInfo(styles.xml, localtime)
buff_file.external_attr = 2179792896
buff_file.flag_bits = 8
buff_file.compress_type = zipfile.ZIP_DEFLATED

odt_file.writestr(buff_file, \n.join(style_xml))

buff_file = zipfile.ZipInfo(meta.xml, localtime)
buff_file.external_attr = 2179792896
buff_file.flag_bits = 8
buff_file.compress_type = zipfile.ZIP_DEFLATED

odt_file.writestr(buff_file, \n.join(meta_xml))

buff_file = zipfile.ZipInfo(META-INF/manifest.xml, localtime)
buff_file.external_attr = 2179792896
buff_file.flag_bits = 8
buff_file.compress_type = zipfile.ZIP_DEFLATED

odt_file.writestr(buff_file, \n.join(manifest_xml))

odt_file.close()

OpenOffice can't open this file, in what a problem ?

sample file: http://omploader.org/vZjlo/test.odt
-- 
http://mail.python.org/mailman/listinfo/python-list