johnbachman / py-fcm

Automatically exported from code.google.com/p/py-fcm
0 stars 1 forks source link

Incorrect userwarning about start/end delimiter of fcs file #20

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. open an fcs file with ReadFCS

What is the expected output? What do you see instead?

I get a warning that is not correct. (stats and ends with the '\' delimiter)

 UserWarning: text in segment does not start and end with delimiter
  warn("text in segment does not start and end with delimiter")

What version of the product are you using? On what operating system?

fcm 0.9.1
ubuntu 12.04 (not relevant)

Please provide any additional information below.

-------------------------------------------------------
Bug location:

readfcs.py (lines 304)

def parse_pairs(text):
    """return key/value pairs from a delimited string"""
    delim = text[0]
    if delim == r'|':
        delim = '\|'
    if delim == r'\a'[0]: # test for delimiter being \
        delim = '\\\\' # regex will require it to be \\
    if delim != text[-1]:
        warn("text in segment does not start and end with delimiter")
    tmp = text[1:-1].replace('$', '')
    # match the delimited character unless it's doubled
    regex = re.compile('(?<=[^%s])%s(?!%s)' % (delim, delim, delim))
    tmp = regex.split(tmp)
    return dict(zip([ x.lower() for x in tmp[::2]], tmp[1::2]))

------------------------------------------------

Likely Solution: 

def parse_pairs(text):
    """return key/value pairs from a delimited string"""
    delim = text[0]

    if delim != text[-1]:
        warn("text in segment does not start and end with delimiter")

    if delim == r'|':
        delim = '\|'
    elif delim == r'\a'[0]: # test for delimiter being \
        delim = '\\\\' # regex will require it to be \\

    tmp = text[1:-1].replace('$', '')
    # match the delimited character unless it's doubled
    regex = re.compile('(?<=[^%s])%s(?!%s)' % (delim, delim, delim))
    tmp = regex.split(tmp)
    return dict(zip([ x.lower() for x in tmp[::2]], tmp[1::2]))

(Changed order of if statements and added an elif for the second if cascade)

Original issue reported on code.google.com by eyurt...@gmail.com on 4 Apr 2013 at 8:52

GoogleCodeExporter commented 9 years ago
good catch.  I'll get this fixed and committed.

Original comment by Jacob.Frelinger@gmail.com on 4 Apr 2013 at 10:27

GoogleCodeExporter commented 9 years ago
Fixed in rev: be51ad4743e2
Thanks!

Original comment by Jacob.Frelinger@gmail.com on 5 Apr 2013 at 12:01