~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/_rio_pyx.pyx

  • Committer: Jelmer Vernooij
  • Date: 2009-05-14 18:03:46 UTC
  • mto: (4290.1.9 rio-serializer2)
  • mto: This revision was merged to the branch mainline in revision 4368.
  • Revision ID: jelmer@samba.org-20090514180346-npwoc6ojwgj9dyzt
Use PyList_Append.

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
    void Py_INCREF(object)
37
37
    void Py_DECREF(object)
38
38
    object PyList_GetItem(object, int)
39
 
    int PyList_SetItem(object, int, object)    except -1
 
39
    int PyList_SetItem(object, int, object) except -1
40
40
    int PyList_Size(object) except -1
41
41
    object PyUnicode_Join(object, object)
42
42
    object PyUnicode_AsASCIIString(object)
43
 
 
44
 
cdef extern from "string.h":
45
 
    char *strstr(char *a, char *b)
 
43
    int PyList_Append(object, object) except -1    
46
44
 
47
45
 
48
46
from bzrlib.rio import Stanza
76
74
    entries[-1] = entries[-1][:-1]
77
75
    return PyUnicode_Join(unicode(""), entries)
78
76
 
 
77
 
79
78
cdef object _split_first_line(char *line, int len):
80
79
    cdef int i
81
80
    for i from 0 <= i < len:
114
113
            new_value = PyUnicode_DecodeUTF8(c_line+1, c_len-1, "strict")
115
114
        else: # new tag:value line
116
115
            if tag is not None:
117
 
                pairs.append((tag, _join_utf8_strip(accum_value)))
 
116
                PyList_Append(pairs, (tag, _join_utf8_strip(accum_value)))
118
117
            accum_value = []
119
118
            (tag, new_value) = _split_first_line(c_line, c_len)
120
119
            if not _valid_tag(tag):
121
120
                raise ValueError("invalid rio tag %r" % (tag,))
122
121
        accum_value.append(new_value)
123
122
    if tag is not None: # add last tag-value
124
 
        pairs.append((tag, _join_utf8_strip(accum_value)))
 
123
        PyList_Append(pairs, (tag, _join_utf8_strip(accum_value)))
125
124
        return Stanza.from_pairs(pairs)
126
125
    else:     # didn't see any content
127
126
        return None
144
143
        if line[0] == unicode('\t'): # continues previous value
145
144
            if tag is None:
146
145
                raise ValueError('invalid continuation line %r' % line)
147
 
            accum_value.append(line[1:])
 
146
            PyList_Append(accum_value, line[1:])
148
147
        else: # new tag:value line
149
148
            if tag is not None:
150
 
                pairs.append((tag, _join_utf8_strip(accum_value)))
 
149
                PyList_Append(pairs, (tag, _join_utf8_strip(accum_value)))
151
150
            try:
152
151
                colon_index = line.index(unicode(': '))
153
152
            except ValueError:
159
158
            accum_value = [line[colon_index+2:]]
160
159
 
161
160
    if tag is not None: # add last tag-value
162
 
        pairs.append((tag, _join_utf8_strip(accum_value)))
 
161
        PyList_Append(pairs, (tag, _join_utf8_strip(accum_value)))
163
162
        return Stanza.from_pairs(pairs)
164
163
    else:     # didn't see any content
165
164
        return None