python-pickle 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/ChangeLog.md +17 -0
- data/README.md +4 -1
- data/lib/python/pickle/deserializer.rb +142 -80
- data/lib/python/pickle/instructions/bin_persid.rb +31 -0
- data/lib/python/pickle/instructions/global.rb +11 -41
- data/lib/python/pickle/instructions/has_namespace_and_name.rb +61 -0
- data/lib/python/pickle/instructions/inst.rb +34 -0
- data/lib/python/pickle/instructions/next_buffer.rb +5 -1
- data/lib/python/pickle/instructions/obj.rb +30 -0
- data/lib/python/pickle/instructions/persid.rb +31 -0
- data/lib/python/pickle/instructions/readonly_buffer.rb +4 -0
- data/lib/python/pickle/instructions.rb +64 -0
- data/lib/python/pickle/protocol0.rb +313 -68
- data/lib/python/pickle/protocol1.rb +225 -93
- data/lib/python/pickle/protocol2.rb +205 -124
- data/lib/python/pickle/protocol3.rb +92 -123
- data/lib/python/pickle/protocol4.rb +188 -165
- data/lib/python/pickle/protocol5.rb +98 -166
- data/lib/python/pickle/version.rb +1 -1
- data/lib/python/pickle.rb +71 -39
- data/spec/deserializer_spec.rb +359 -0
- data/spec/fixtures/set_v0.pkl +11 -0
- data/spec/fixtures/set_v1.pkl +0 -0
- data/spec/fixtures/set_v2.pkl +0 -0
- data/spec/fixtures/set_v3.pkl +0 -0
- data/spec/fixtures/set_v4.pkl +0 -0
- data/spec/fixtures/set_v5.pkl +0 -0
- data/spec/generate_pickles2.py +1 -0
- data/spec/generate_pickles3.py +1 -0
- data/spec/integration/load/protocol0_spec.rb +10 -0
- data/spec/integration/load/protocol1_spec.rb +10 -0
- data/spec/integration/load/protocol2_spec.rb +10 -0
- data/spec/integration/load/protocol3_spec.rb +10 -0
- data/spec/integration/load/protocol4_spec.rb +10 -0
- data/spec/integration/load/protocol5_spec.rb +10 -0
- data/spec/pickle_spec.rb +61 -0
- data/spec/protocol0_read_instruction_examples.rb +44 -0
- metadata +14 -2
@@ -93,6 +93,27 @@ shared_examples_for "Protocol0#read_instruction examples" do
|
|
93
93
|
end
|
94
94
|
end
|
95
95
|
|
96
|
+
context "when the opcode is 80" do
|
97
|
+
let(:id) { "12345" }
|
98
|
+
let(:io) { StringIO.new("#{80.chr}#{id}\n") }
|
99
|
+
|
100
|
+
it "must return a Python::Pickle::Instructions::PersID object" do
|
101
|
+
expect(subject.read_instruction).to eq(
|
102
|
+
Python::Pickle::Instructions::PersID.new(id)
|
103
|
+
)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
context "when the opcode is 81" do
|
108
|
+
let(:io) { StringIO.new(81.chr) }
|
109
|
+
|
110
|
+
it "must return Python::Pickle::Instructions::BINPERSID" do
|
111
|
+
expect(subject.read_instruction).to be(
|
112
|
+
Python::Pickle::Instructions::BINPERSID
|
113
|
+
)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
96
117
|
context "when the opcode is 82" do
|
97
118
|
let(:io) { StringIO.new(82.chr) }
|
98
119
|
|
@@ -168,6 +189,19 @@ shared_examples_for "Protocol0#read_instruction examples" do
|
|
168
189
|
end
|
169
190
|
end
|
170
191
|
|
192
|
+
context "when the opcode is 105" do
|
193
|
+
let(:namespace) { "foo" }
|
194
|
+
let(:name) { "bar" }
|
195
|
+
|
196
|
+
let(:io) { StringIO.new("#{105.chr}#{namespace}\n#{name}\n") }
|
197
|
+
|
198
|
+
it "must return Python::Pickle::Instructions::Inst" do
|
199
|
+
expect(subject.read_instruction).to eq(
|
200
|
+
Python::Pickle::Instructions::Inst.new(namespace,name)
|
201
|
+
)
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
171
205
|
context "when the opcode is 108" do
|
172
206
|
let(:io) { StringIO.new(108.chr) }
|
173
207
|
|
@@ -178,6 +212,16 @@ shared_examples_for "Protocol0#read_instruction examples" do
|
|
178
212
|
end
|
179
213
|
end
|
180
214
|
|
215
|
+
context "when the opcode is 111" do
|
216
|
+
let(:io) { StringIO.new(111.chr) }
|
217
|
+
|
218
|
+
it "must return Python::Pickle::Instructions::OBJ" do
|
219
|
+
expect(subject.read_instruction).to be(
|
220
|
+
Python::Pickle::Instructions::OBJ
|
221
|
+
)
|
222
|
+
end
|
223
|
+
end
|
224
|
+
|
181
225
|
context "when the opcode is 112" do
|
182
226
|
let(:index) { 1 }
|
183
227
|
let(:io) { StringIO.new("#{112.chr}#{index}\n") }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: python-pickle
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Postmodern
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-02-
|
11
|
+
date: 2023-02-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -53,6 +53,7 @@ files:
|
|
53
53
|
- lib/python/pickle/deserializer.rb
|
54
54
|
- lib/python/pickle/exceptions.rb
|
55
55
|
- lib/python/pickle/instruction.rb
|
56
|
+
- lib/python/pickle/instructions.rb
|
56
57
|
- lib/python/pickle/instructions/add_items.rb
|
57
58
|
- lib/python/pickle/instructions/append.rb
|
58
59
|
- lib/python/pickle/instructions/appends.rb
|
@@ -61,6 +62,7 @@ files:
|
|
61
62
|
- lib/python/pickle/instructions/bin_float.rb
|
62
63
|
- lib/python/pickle/instructions/bin_get.rb
|
63
64
|
- lib/python/pickle/instructions/bin_int1.rb
|
65
|
+
- lib/python/pickle/instructions/bin_persid.rb
|
64
66
|
- lib/python/pickle/instructions/bin_put.rb
|
65
67
|
- lib/python/pickle/instructions/bin_string.rb
|
66
68
|
- lib/python/pickle/instructions/bin_unicode.rb
|
@@ -82,7 +84,9 @@ files:
|
|
82
84
|
- lib/python/pickle/instructions/get.rb
|
83
85
|
- lib/python/pickle/instructions/global.rb
|
84
86
|
- lib/python/pickle/instructions/has_length_and_value.rb
|
87
|
+
- lib/python/pickle/instructions/has_namespace_and_name.rb
|
85
88
|
- lib/python/pickle/instructions/has_value.rb
|
89
|
+
- lib/python/pickle/instructions/inst.rb
|
86
90
|
- lib/python/pickle/instructions/int.rb
|
87
91
|
- lib/python/pickle/instructions/list.rb
|
88
92
|
- lib/python/pickle/instructions/long.rb
|
@@ -97,6 +101,8 @@ files:
|
|
97
101
|
- lib/python/pickle/instructions/new_true.rb
|
98
102
|
- lib/python/pickle/instructions/next_buffer.rb
|
99
103
|
- lib/python/pickle/instructions/none.rb
|
104
|
+
- lib/python/pickle/instructions/obj.rb
|
105
|
+
- lib/python/pickle/instructions/persid.rb
|
100
106
|
- lib/python/pickle/instructions/pop.rb
|
101
107
|
- lib/python/pickle/instructions/pop_mark.rb
|
102
108
|
- lib/python/pickle/instructions/proto.rb
|
@@ -222,6 +228,12 @@ files:
|
|
222
228
|
- spec/fixtures/object_v3.pkl
|
223
229
|
- spec/fixtures/object_v4.pkl
|
224
230
|
- spec/fixtures/object_v5.pkl
|
231
|
+
- spec/fixtures/set_v0.pkl
|
232
|
+
- spec/fixtures/set_v1.pkl
|
233
|
+
- spec/fixtures/set_v2.pkl
|
234
|
+
- spec/fixtures/set_v3.pkl
|
235
|
+
- spec/fixtures/set_v4.pkl
|
236
|
+
- spec/fixtures/set_v5.pkl
|
225
237
|
- spec/fixtures/str_v0.pkl
|
226
238
|
- spec/fixtures/str_v1.pkl
|
227
239
|
- spec/fixtures/str_v2.pkl
|