1 # GNU MediaGoblin -- federated, autonomous media hosting
2 # Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS.
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU Affero General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU Affero General Public License for more details.
14 # You should have received a copy of the GNU Affero General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 from sqlalchemy
.types
import TypeDecorator
, Unicode
, VARCHAR
22 class PathTupleWithSlashes(TypeDecorator
):
23 "Represents a Tuple of strings as a slash separated string."
27 def process_bind_param(self
, value
, dialect
):
32 value
= '/'.join(value
)
35 def process_result_value(self
, value
, dialect
):
37 value
= tuple(value
.split('/'))
41 # The following class and only this one class is in very
42 # large parts based on example code from sqlalchemy.
44 # The original copyright notice and license follows:
45 # Copyright (C) 2005-2011 the SQLAlchemy authors and contributors <see AUTHORS file>
47 # This module is part of SQLAlchemy and is released under
48 # the MIT License: http://www.opensource.org/licenses/mit-license.php
50 class JSONEncoded(TypeDecorator
):
51 "Represents an immutable structure as a json-encoded string."
55 def process_bind_param(self
, value
, dialect
):
57 value
= json
.dumps(value
)
60 def process_result_value(self
, value
, dialect
):
62 value
= json
.loads(value
)