pickle-interpreter 0.1.0 → 0.1.1
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 +8 -8
- data/README.md +54 -11
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YTRkZmQzNGYwNTFiZWMyY2IzYmE4YjYyMjk0ZjYzYWZjNWUzZDA5Ng==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NTJkMTYyMmM1ODk2ZDc5ZmYzZmZhZDQzMjAyYTcwZjg4ZjcyODNiYg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MTViNTQ0ZDZjYzk5OWViNWM3MTljZjcyYmM1OTVlMTg2ZDk3YTU1ZjlkZmYx
|
10
|
+
YTkyZGRlYmZjOTdhYTA4NWYxMDkzODI3ZGExYWIyZDllYjhiN2Q0NzYzMmE4
|
11
|
+
OWU2YWJjYWRjZDI2NjRmN2Y5NGEyMDVkY2ZjYTFkYjYxMzgxNTk=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MDY2N2VkOGE5Nzg4MTk5OThiMmY3MjYxNTc2NzE3MWYzMGMxNmFjNzI4Yjdm
|
14
|
+
YmRiZTA3YmQ3ZDZiZTM5MDZkNWM0N2MwMmNkOTNmOTZmMTcwMTYxODM3ZGEy
|
15
|
+
OTE1MzVmMWM1OTQ3MmFhYjQ2YjcyMmMyYzFjMzI4OTcwM2Y0NzE=
|
data/README.md
CHANGED
@@ -1,17 +1,60 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
1
|
+
# We can unpickle that!
|
2
|
+
|
3
|
+
This is a library for deserializing Python pickle objects (proto 2). The goal was to be able to unpickle Django session data directly from Ruby.
|
4
|
+
|
5
|
+
## Install
|
6
|
+
As a gem:
|
7
|
+
```
|
8
|
+
gem install pickle-interpreter
|
9
|
+
```
|
10
|
+
|
11
|
+
Or in your Gemfile:
|
12
|
+
```
|
13
|
+
gem 'pickle-interpreter'
|
14
|
+
```
|
15
|
+
|
16
|
+
Require:
|
17
|
+
```ruby
|
18
|
+
require 'pickle_interpreter'
|
19
|
+
```
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
For Base64-encoded strings:
|
23
|
+
```ruby
|
24
|
+
PickleInterpreter.unpickle_base64(my_string)
|
25
|
+
```
|
26
|
+
|
27
|
+
For binary strings, be sure it is using the ASCII-8bit character encoding:
|
28
|
+
```ruby
|
29
|
+
PickleInterpreter.unpickle(my_string)
|
30
|
+
```
|
31
|
+
|
32
|
+
For reading `session_data` from a `django_session` table:
|
33
|
+
```ruby
|
34
|
+
PickleInterpreter.unpickle_base64_signed(my_string).
|
35
|
+
```
|
36
|
+
*Note that this doesn't check the signature, the hash before the `:` is ignored.*
|
37
|
+
|
38
|
+
## Python Testing
|
39
|
+
```python
|
40
|
+
import base64
|
41
|
+
import pickle
|
42
|
+
|
43
|
+
session_data = <Base64 encoded string, such as django_session.session_data>
|
44
|
+
encoded_data = base64.b64decode(session_data)
|
45
|
+
hash, serialized = encoded_data.split(b':', 1)
|
46
|
+
data = pickle.loads(serialized)
|
47
|
+
|
48
|
+
# Pickle using protocol 2
|
49
|
+
serialized = pickle.dumps(data, 2)
|
50
|
+
session_data = base64.b64encode("hash" + b":" + serialized)
|
51
|
+
```
|
52
|
+
|
53
|
+
## Notes
|
9
54
|
I *think* I have at least a rudimentary implementation of all of the pickle instructions. However, I don't use a lot of Python, so I don't really have anything to test on. If you use this, and something breaks, if you send me the pickle file, and what it should decode to, I will get it fixed. jonathan@newmedio.com
|
10
55
|
|
11
56
|
For objects, however, I pretty much just create a hash with the initialization parameters baked in somewhere (i.e. with a key like "__init_args" or something appropriate to how it was called). This is certainly an area that can be improved. However, you can also just walk the tree after the fact and look for these.
|
12
57
|
|
13
58
|
Let me know how it works, and if there is anything else I need to implement. This is based on the 2014-06-10 version of this file:
|
14
59
|
|
15
|
-
http://svn.python.org/projects/python/trunk/Lib/pickletools.py
|
16
|
-
|
17
|
-
|
60
|
+
http://svn.python.org/projects/python/trunk/Lib/pickletools.py
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pickle-interpreter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jonathan Bartlett
|
@@ -10,7 +10,7 @@ bindir: bin
|
|
10
10
|
cert_chain: []
|
11
11
|
date: 2014-06-10 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description: A library to read pickled objects from
|
13
|
+
description: A library to read pickled objects (proto 2) from Python in Ruby
|
14
14
|
email: jonathan@newmedio.com
|
15
15
|
executables: []
|
16
16
|
extensions: []
|