|
|
# RhodeCode VCSServer provides access to different vcs backends via network.
|
|
|
# Copyright (C) 2014-2023 RhodeCode GmbH
|
|
|
#
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
# the Free Software Foundation; either version 3 of the License, or
|
|
|
# (at your option) any later version.
|
|
|
#
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
# GNU General Public License for more details.
|
|
|
#
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
# along with this program; if not, write to the Free Software Foundation,
|
|
|
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
import logging
|
|
|
import hashlib
|
|
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
class AttributeDictBase(dict):
|
|
|
def __getstate__(self):
|
|
|
odict = self.__dict__ # get attribute dictionary
|
|
|
return odict
|
|
|
|
|
|
def __setstate__(self, dict):
|
|
|
self.__dict__ = dict
|
|
|
|
|
|
__setattr__ = dict.__setitem__
|
|
|
__delattr__ = dict.__delitem__
|
|
|
|
|
|
|
|
|
class StrictAttributeDict(AttributeDictBase):
|
|
|
"""
|
|
|
Strict Version of Attribute dict which raises an Attribute error when
|
|
|
requested attribute is not set
|
|
|
"""
|
|
|
def __getattr__(self, attr):
|
|
|
try:
|
|
|
return self[attr]
|
|
|
except KeyError:
|
|
|
raise AttributeError('{} object has no attribute {}'.format(
|
|
|
self.__class__, attr))
|
|
|
|
|
|
|
|
|
class AttributeDict(AttributeDictBase):
|
|
|
def __getattr__(self, attr):
|
|
|
return self.get(attr, None)
|
|
|
|
|
|
|
|
|
def sha1(val):
|
|
|
return hashlib.sha1(val).hexdigest()
|
|
|
|