~trb143/openlp/more_media

« back to all changes in this revision

Viewing changes to openlp/plugins/presentations/lib/serializers.py

  • Committer: Tim Bentley
  • Date: 2019-06-11 18:08:21 UTC
  • mfrom: (2876.1.2 openlp)
  • Revision ID: tim.bentley@gmail.com-20190611180821-m0viu2wi93p2o97k
Head

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
 
3
 
 
4
##########################################################################
 
5
# OpenLP - Open Source Lyrics Projection                                 #
 
6
# ---------------------------------------------------------------------- #
 
7
# Copyright (c) 2008-2019 OpenLP Developers                              #
 
8
# ---------------------------------------------------------------------- #
 
9
# This program is free software: you can redistribute it and/or modify   #
 
10
# it under the terms of the GNU General Public License as published by   #
 
11
# the Free Software Foundation, either version 3 of the License, or      #
 
12
# (at your option) any later version.                                    #
 
13
#                                                                        #
 
14
# This program is distributed in the hope that it will be useful,        #
 
15
# but WITHOUT ANY WARRANTY; without even the implied warranty of         #
 
16
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          #
 
17
# GNU General Public License for more details.                           #
 
18
#                                                                        #
 
19
# You should have received a copy of the GNU General Public License      #
 
20
# along with this program.  If not, see <https://www.gnu.org/licenses/>. #
 
21
##########################################################################
 
22
"""
 
23
This module contains some helpers for serializing Path objects in Pyro4
 
24
"""
 
25
try:
 
26
    from openlp.core.common.path import Path
 
27
except ImportError:
 
28
    from pathlib import Path
 
29
 
 
30
from Pyro4.util import SerializerBase
 
31
 
 
32
 
 
33
def path_class_to_dict(obj):
 
34
    """
 
35
    Serialize a Path object for Pyro4
 
36
    """
 
37
    return {
 
38
        '__class__': 'Path',
 
39
        'parts': obj.parts
 
40
    }
 
41
 
 
42
 
 
43
def path_dict_to_class(classname, d):
 
44
    return Path(d['parts'])
 
45
 
 
46
 
 
47
def register_classes():
 
48
    """
 
49
    Register the serializers
 
50
    """
 
51
    SerializerBase.register_class_to_dict(Path, path_class_to_dict)
 
52
    SerializerBase.register_dict_to_class('Path', path_dict_to_class)