/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/_rio_pyx.pyx

  • Committer: Jelmer Vernooij
  • Date: 2017-06-10 01:43:31 UTC
  • mfrom: (6676 work)
  • mto: This revision was merged to the branch mainline in revision 6690.
  • Revision ID: jelmer@jelmer.uk-20170610014331-1xalwmij33imwidq
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""Pyrex implementation of _read_stanza_*."""
18
18
 
19
 
#python2.4 support
 
19
from __future__ import absolute_import
 
20
 
 
21
 
20
22
cdef extern from "python-compat.h":
21
23
    pass
22
24
 
39
41
    Py_UNICODE *PyUnicode_AS_UNICODE(object)
40
42
    Py_UNICODE *PyUnicode_AsUnicode(object)
41
43
    Py_ssize_t PyUnicode_GET_SIZE(object) except -1
42
 
    int PyList_Append(object, object) except -1    
 
44
    int PyList_Append(object, object) except -1
43
45
    int Py_UNICODE_ISLINEBREAK(Py_UNICODE)
44
46
    object PyUnicode_FromUnicode(Py_UNICODE *, int)
45
47
    void *Py_UNICODE_COPY(Py_UNICODE *, Py_UNICODE *, int)
47
49
cdef extern from "string.h":
48
50
    void *memcpy(void *, void *, int)
49
51
 
50
 
from breezy.rio import Stanza
 
52
from .rio import Stanza
51
53
 
52
54
cdef int _valid_tag_char(char c): # cannot_raise
53
 
    return (c == c'_' or c == c'-' or 
 
55
    return (c == c'_' or c == c'-' or
54
56
            (c >= c'a' and c <= c'z') or
55
57
            (c >= c'A' and c <= c'Z') or
56
58
            (c >= c'0' and c <= c'9'))
72
74
    return True
73
75
 
74
76
 
75
 
cdef object _split_first_line_utf8(char *line, int len, 
 
77
cdef object _split_first_line_utf8(char *line, int len,
76
78
                                   char *value, Py_ssize_t *value_len):
77
79
    cdef int i
78
80
    for i from 0 <= i < len:
85
87
    raise ValueError('tag/value separator not found in line %r' % line)
86
88
 
87
89
 
88
 
cdef object _split_first_line_unicode(Py_UNICODE *line, int len, 
 
90
cdef object _split_first_line_unicode(Py_UNICODE *line, int len,
89
91
                                      Py_UNICODE *value, Py_ssize_t *value_len):
90
92
    cdef int i
91
93
    for i from 0 <= i < len:
138
140
                accum_len = accum_len + c_len-1
139
141
            else: # new tag:value line
140
142
                if tag is not None:
141
 
                    PyList_Append(pairs, 
142
 
                        (tag, PyUnicode_DecodeUTF8(accum_value, accum_len-1, 
 
143
                    PyList_Append(pairs,
 
144
                        (tag, PyUnicode_DecodeUTF8(accum_value, accum_len-1,
143
145
                                                   "strict")))
144
 
                tag = _split_first_line_utf8(c_line, c_len, accum_value, 
 
146
                tag = _split_first_line_utf8(c_line, c_len, accum_value,
145
147
                                             &accum_len)
146
148
                if not _valid_tag(tag):
147
149
                    raise ValueError("invalid rio tag %r" % (tag,))
148
150
        if tag is not None: # add last tag-value
149
 
            PyList_Append(pairs, 
 
151
            PyList_Append(pairs,
150
152
                (tag, PyUnicode_DecodeUTF8(accum_value, accum_len-1, "strict")))
151
153
            return Stanza.from_pairs(pairs)
152
154
        else:     # didn't see any content
181
183
                break       # end of stanza
182
184
            if accum_len + c_len > accum_size:
183
185
                accum_size = accum_len + c_len
184
 
                new_accum_value = <Py_UNICODE *>realloc(accum_value, 
 
186
                new_accum_value = <Py_UNICODE *>realloc(accum_value,
185
187
                    accum_size*sizeof(Py_UNICODE))
186
188
                if new_accum_value == NULL:
187
189
                    raise MemoryError
195
197
                accum_len = accum_len + (c_len-1)
196
198
            else: # new tag:value line
197
199
                if tag is not None:
198
 
                    PyList_Append(pairs, 
 
200
                    PyList_Append(pairs,
199
201
                        (tag, PyUnicode_FromUnicode(accum_value, accum_len-1)))
200
 
                tag = _split_first_line_unicode(c_line, c_len, accum_value, 
 
202
                tag = _split_first_line_unicode(c_line, c_len, accum_value,
201
203
                                                &accum_len)
202
204
                if not _valid_tag(tag):
203
205
                    raise ValueError("invalid rio tag %r" % (tag,))