File: sharedobject.rst

package info (click to toggle)
pyamf 0.6.1%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 7,692 kB
  • sloc: python: 17,944; xml: 455; makefile: 116; sql: 38; java: 11; sh: 7
file content (105 lines) | stat: -rw-r--r-- 2,411 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
*****************
  Shared Object 
*****************

.. topic:: Introduction

   The Adobe Flash Player has the ability to store persistent data on
   your computer, similar to a cookie, called a `Local Shared Object`_.
   PyAMF has the ability to read and write these ``.sol`` files.

.. contents::

Find the files
==============

The Local Shared Object files are not stored in the cookies folder of
your browser and the location also differs depending on the operating
system you are using.

For the Windows user::

   C:\Documents and Settings\{Your User Name}\Application Data\Macromedia\Flash Player\#SharedObjects\

On Linux::

   /home/{Your User Name}/.macromedia/Flash_Player/#SharedObjects/

On Mac OS X::

   /Users/{Your User Name}/Library/Preferences/Macromedia/Flash Player/#SharedObjects/


Manipulating the files
======================

PyAMF makes it as easy as possible to interact with these files.


Loading a Local Shared Object
-----------------------------

This file is located in the ``youtube.com`` directory, check it out on your
own system (assuming you've visited youtube.com_ at some point).

.. code-block:: python
   :linenos:

   from pyamf import sol

   file = 'timeDisplayConfig.sol'
   lso = sol.load(file)
   print lso


Which should output the following:

.. code-block:: python

   {u'modeDefaultSet': True, u'displayMode': u'played'}


Saving a Local Shared Object
----------------------------

.. code-block:: python
   :linenos:

   from pyamf import sol

   lso = sol.SOL('userData')
   lso['username'] = 'joe.bloggs'

   file = 'loginDetails.sol'
   sol.save(lso, file)


AMF0 and AMF3
=============

Since the introduction of the Adobe Flash Player 9, sol's can be read/written
using AMF0 encoding or AMF3 encoding. PyAMF also supports this. When reading
a sol file, PyAMF will automatically detect which encoding is used and act
appropriately.

When writing a sol, the default is to use AMF0. You can override this by
supplying the ``encoding`` keyword to the ``save`` function.

.. code-block:: python
    :linenos:

    from pyamf import sol, AMF3

    lso = sol.SOL('scoreData')
    lso['highScores'] = {
       'nick': 3400,
       'thijs': 3800,
       'arnar': 4500
    }

    file = 'highScores.sol'
    sol.save(lso, file, encoding=AMF3)


.. _youtube.com: http://www.youtube.com
.. _Local Shared Object: http://en.wikipedia.org/wiki/Local_Shared_Object