line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# pyyaml/lib/yaml/reader.py |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package YAML::Perl::Reader; |
4
|
8
|
|
|
8
|
|
1509
|
use strict; |
|
8
|
|
|
|
|
19
|
|
|
8
|
|
|
|
|
389
|
|
5
|
8
|
|
|
8
|
|
52
|
use warnings; |
|
8
|
|
|
|
|
17
|
|
|
8
|
|
|
|
|
14030
|
|
6
|
|
|
|
|
|
|
|
7
|
8
|
|
|
8
|
|
62
|
use YAML::Perl::Error; |
|
8
|
|
|
|
|
17
|
|
|
8
|
|
|
|
|
90
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
package YAML::Perl::Error::Reader; |
10
|
8
|
|
|
8
|
|
49
|
use YAML::Perl::Error -base; |
|
8
|
|
|
|
|
19
|
|
|
8
|
|
|
|
|
45
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
field 'name'; |
13
|
|
|
|
|
|
|
field 'character'; |
14
|
|
|
|
|
|
|
field 'position'; |
15
|
|
|
|
|
|
|
field 'encoding'; |
16
|
|
|
|
|
|
|
field 'reason'; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# use overload '""' => sub { |
19
|
|
|
|
|
|
|
# my $self = shift; |
20
|
|
|
|
|
|
|
# "XXX"; |
21
|
|
|
|
|
|
|
# }; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
package YAML::Perl::Reader; |
24
|
8
|
|
|
8
|
|
53
|
use YAML::Perl::Processor -base; |
|
8
|
|
|
|
|
25
|
|
|
8
|
|
|
|
|
68
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
field next_layer => ''; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub open { |
29
|
30
|
|
|
30
|
0
|
60
|
my $self = shift; |
30
|
30
|
|
|
|
|
194
|
$self->SUPER::open(@_); |
31
|
30
|
|
|
|
|
52
|
my $stream = shift; |
32
|
30
|
|
|
|
|
1000
|
$self->name(''); |
33
|
30
|
|
|
|
|
756
|
$self->stream($stream); |
34
|
30
|
|
|
|
|
826
|
$self->raw_buffer($stream); |
35
|
30
|
|
|
|
|
111
|
$self->determine_encoding(); |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
field 'name'; |
39
|
|
|
|
|
|
|
field 'stream'; |
40
|
|
|
|
|
|
|
field 'stream_pointer' => 0; |
41
|
|
|
|
|
|
|
field 'eof' => True; |
42
|
|
|
|
|
|
|
field 'buffer' => ''; |
43
|
|
|
|
|
|
|
field 'pointer' => 0; |
44
|
|
|
|
|
|
|
field 'raw_buffer'; |
45
|
|
|
|
|
|
|
field 'raw_decode'; |
46
|
|
|
|
|
|
|
field 'encoding'; |
47
|
|
|
|
|
|
|
field 'index' => 0; |
48
|
|
|
|
|
|
|
field 'line' => 0; |
49
|
|
|
|
|
|
|
field 'column' => 0; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub peek { |
52
|
3198
|
|
|
3198
|
0
|
3986
|
my $self = shift; |
53
|
3198
|
|
100
|
|
|
11618
|
my $index = shift || 0; |
54
|
3198
|
50
|
|
|
|
8806
|
if ($self->{index} + $index > length( $self->{buffer} )) { |
55
|
|
|
|
|
|
|
# $self->update($index + 1); |
56
|
0
|
|
|
|
|
0
|
return "\0" |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
# print '<' . substr($self->{buffer}, $self->{index} + $index, 1) . '> '; |
59
|
3198
|
|
|
|
|
17632
|
return substr($self->{buffer}, $self->{index} + $index, 1); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub prefix { |
63
|
395
|
|
|
395
|
0
|
574
|
my $self = shift; |
64
|
395
|
50
|
|
|
|
907
|
my $length = @_ ? shift : 1; |
65
|
395
|
|
|
|
|
2490
|
return substr($self->{buffer}, $self->{index}, $length); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub forward { |
69
|
570
|
|
|
570
|
0
|
820
|
my $self = shift; |
70
|
570
|
100
|
|
|
|
1164
|
my $length = @_ ? shift : 1; |
71
|
|
|
|
|
|
|
# print '(' . $length . ') '; |
72
|
|
|
|
|
|
|
|
73
|
570
|
|
|
|
|
1485
|
while ( $length-- ) { |
74
|
809
|
|
|
|
|
1559
|
my $ch = $self->peek(); |
75
|
809
|
100
|
33
|
|
|
4543
|
if ( |
|
|
50
|
66
|
|
|
|
|
76
|
|
|
|
|
|
|
$ch =~ /[\n\x85]/ |
77
|
|
|
|
|
|
|
or ( $ch eq "\r" and $self->peek(2) != "\n" ) |
78
|
|
|
|
|
|
|
) { |
79
|
102
|
|
|
|
|
184
|
$self->{line}++; |
80
|
102
|
|
|
|
|
174
|
$self->{column} = 0; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
elsif ( $ch ne "\x{FEFF}" ) { |
83
|
707
|
|
|
|
|
1229
|
$self->{column}++ |
84
|
|
|
|
|
|
|
} |
85
|
809
|
|
|
|
|
5871
|
$self->{index}++; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub get_mark { |
90
|
543
|
|
|
543
|
0
|
774
|
my $self = shift; |
91
|
543
|
50
|
|
|
|
14417
|
if (not defined $self->stream) { |
92
|
0
|
|
|
|
|
0
|
return YAML::Perl::Mark->new( |
93
|
|
|
|
|
|
|
name => $self->name, |
94
|
|
|
|
|
|
|
index => $self->index, |
95
|
|
|
|
|
|
|
line => $self->line, |
96
|
|
|
|
|
|
|
column => $self->column, |
97
|
|
|
|
|
|
|
buffer => $self->buffer, |
98
|
|
|
|
|
|
|
pointer => $self->pointer, |
99
|
|
|
|
|
|
|
); |
100
|
|
|
|
|
|
|
} |
101
|
543
|
|
|
|
|
14011
|
return YAML::Perl::Mark->new( |
102
|
|
|
|
|
|
|
name => $self->name, |
103
|
|
|
|
|
|
|
index => $self->index, |
104
|
|
|
|
|
|
|
line => $self->line, |
105
|
|
|
|
|
|
|
column => $self->column, |
106
|
|
|
|
|
|
|
); |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
sub determine_encoding { |
110
|
30
|
|
|
30
|
0
|
54
|
my $self = shift; |
111
|
30
|
|
33
|
|
|
812
|
while (not $self->eof and length($self->raw_buffer) < 2) { |
112
|
0
|
|
|
|
|
0
|
$self->update_raw(); |
113
|
0
|
|
|
|
|
0
|
if (0 && $self->unicode_stuf_XXX()) { |
114
|
|
|
|
|
|
|
#XXX ... |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
} |
117
|
30
|
|
|
|
|
144
|
$self->update(1); |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
8
|
|
|
|
|
5912
|
use constant NON_PRINTABLE => |
121
|
8
|
|
|
8
|
|
62
|
qr/[^\x09\x0A\x0D\x20-\x7E\x85\xA0-\x{D7FF}\x{E000}-\x{FFFD}]/; |
|
8
|
|
|
|
|
16
|
|
122
|
|
|
|
|
|
|
sub check_printable { |
123
|
30
|
|
|
30
|
0
|
65
|
my $self = shift; |
124
|
30
|
|
|
|
|
50
|
my $data = shift; |
125
|
30
|
|
|
|
|
116
|
my $match = ($data =~ NON_PRINTABLE); |
126
|
30
|
50
|
|
|
|
130
|
if ($match) { |
127
|
0
|
|
|
|
|
0
|
my $character = 'x'; #XXX |
128
|
|
|
|
|
|
|
# $match->group(); |
129
|
0
|
|
|
|
|
0
|
my $position = 666; #XXX |
130
|
|
|
|
|
|
|
# $self->index + (length($self->buffer) - $self->pointer) + $match->start(); |
131
|
0
|
|
|
|
|
0
|
throw YAML::Perl::Error::Reader( |
132
|
|
|
|
|
|
|
$self->name, $position, $character, |
133
|
|
|
|
|
|
|
'unicode', "special characters are not allowed" |
134
|
|
|
|
|
|
|
); |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
sub update { |
139
|
30
|
|
|
30
|
0
|
67
|
my $self = shift; |
140
|
30
|
|
|
|
|
60
|
my $length = shift; |
141
|
|
|
|
|
|
|
|
142
|
30
|
50
|
|
|
|
863
|
if (not defined $self->raw_buffer) { |
143
|
0
|
|
|
|
|
0
|
return; |
144
|
|
|
|
|
|
|
} |
145
|
30
|
|
|
|
|
775
|
$self->buffer(substr($self->buffer, $self->pointer)); |
146
|
30
|
|
|
|
|
774
|
$self->pointer(0); |
147
|
30
|
|
|
|
|
731
|
while (length($self->buffer) < $length) { |
148
|
30
|
50
|
|
|
|
745
|
if (not $self->eof) { |
149
|
0
|
|
|
|
|
0
|
$self->update_raw(); |
150
|
|
|
|
|
|
|
} |
151
|
30
|
|
|
|
|
60
|
my ($data, $converted); |
152
|
30
|
50
|
|
|
|
729
|
if (defined $self->raw_decode) { |
153
|
|
|
|
|
|
|
try { |
154
|
0
|
|
|
0
|
|
0
|
$data, $converted = |
155
|
|
|
|
|
|
|
$self->raw_decode( |
156
|
|
|
|
|
|
|
$self->raw_buffer, |
157
|
|
|
|
|
|
|
'strict', |
158
|
|
|
|
|
|
|
$self->eof, |
159
|
|
|
|
|
|
|
); |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
# except { |
162
|
|
|
|
|
|
|
# UnicodeDecodeError, exc: |
163
|
|
|
|
|
|
|
# character = exc.object[exc.start] |
164
|
|
|
|
|
|
|
# if self.stream is not None: |
165
|
|
|
|
|
|
|
# position = self.stream_pointer-len(self.raw_buffer)+exc.start |
166
|
|
|
|
|
|
|
# else: |
167
|
|
|
|
|
|
|
# position = exc.start |
168
|
|
|
|
|
|
|
# raise ReaderError(self.name, position, character, |
169
|
|
|
|
|
|
|
# exc.encoding, exc.reason) |
170
|
|
|
|
|
|
|
# } |
171
|
0
|
|
|
|
|
0
|
} |
172
|
|
|
|
|
|
|
else { |
173
|
30
|
|
|
|
|
789
|
$data = $self->raw_buffer; |
174
|
30
|
|
|
|
|
51
|
$converted = length($data); |
175
|
|
|
|
|
|
|
} |
176
|
30
|
|
|
|
|
123
|
$self->check_printable($data); |
177
|
30
|
|
|
|
|
76
|
$self->{buffer} .= $data; |
178
|
30
|
|
|
|
|
834
|
$self->raw_buffer(substr($self->raw_buffer, $converted)); |
179
|
30
|
50
|
|
|
|
780
|
if ($self->eof) { |
180
|
30
|
|
|
|
|
71
|
$self->{buffer} .= "\0"; |
181
|
30
|
|
|
|
|
962
|
$self->raw_buffer(undef); |
182
|
30
|
|
|
|
|
121
|
last; |
183
|
|
|
|
|
|
|
} |
184
|
|
|
|
|
|
|
} |
185
|
|
|
|
|
|
|
} |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
sub update_raw { |
188
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
189
|
0
|
|
0
|
|
|
|
my $size = shift || 1024; |
190
|
0
|
|
|
|
|
|
my $data = $self->stream->read($size); |
191
|
0
|
0
|
|
|
|
|
if ($data) { |
192
|
0
|
|
|
|
|
|
$self->{raw_buffer} .= $data; |
193
|
0
|
|
|
|
|
|
$self->stream_pointer($self->stream_pointer + length($data)); |
194
|
|
|
|
|
|
|
} |
195
|
|
|
|
|
|
|
else { |
196
|
0
|
|
|
|
|
|
$self->eof(True); |
197
|
|
|
|
|
|
|
} |
198
|
|
|
|
|
|
|
} |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
1; |