##// END OF EJS Templates
release: Finish preparation for 4.18.3
release: Finish preparation for 4.18.3

File last commit:

r825:dc8df3e0 stable
r828:f4cc6b3c v4.18.3 stable
Show More
utils.py
110 lines | 2.8 KiB | text/x-python | PythonLexer
initial commit
r0 # RhodeCode VCSServer provides access to different vcs backends via network.
docs: updated copyrights to 2019
r620 # Copyright (C) 2014-2019 RhodeCode GmbH
initial commit
r0 #
# 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
sync: disable prompts to not allow in any case to block processes on input.
r381 import logging
caches: replaced beaker with dogpile cache.
r483 import hashlib
sync: disable prompts to not allow in any case to block processes on input.
r381
log = logging.getLogger(__name__)
initial commit
r0
git-lfs: added vcsserver handling of git-lfs objects....
r180 def safe_int(val, default=None):
"""
Returns int() of val if val is not convertable to int use default
instead
initial commit
r0
git-lfs: added vcsserver handling of git-lfs objects....
r180 :param val:
:param default:
"""
try:
val = int(val)
except (ValueError, TypeError):
val = default
return val
git: use non-unicode author extraction as it's returned as bytes from backend, and we can...
r825 def safe_str(unicode_, to_encoding=None):
initial commit
r0 """
safe str function. Does few trick to turn unicode_ into string
:param unicode_: unicode to encode
git: use non-unicode author extraction as it's returned as bytes from backend, and we can...
r825 :param to_encoding: encode to this type UTF8 default
initial commit
r0 :rtype: str
:returns: str object
"""
git: use non-unicode author extraction as it's returned as bytes from backend, and we can...
r825 to_encoding = to_encoding or ['utf8']
initial commit
r0 # if it's not basestr cast to str
if not isinstance(unicode_, basestring):
return str(unicode_)
if isinstance(unicode_, str):
return unicode_
if not isinstance(to_encoding, (list, tuple)):
to_encoding = [to_encoding]
for enc in to_encoding:
try:
return unicode_.encode(enc)
except UnicodeEncodeError:
pass
git: use non-unicode author extraction as it's returned as bytes from backend, and we can...
r825 return unicode_.encode(to_encoding[0], 'replace')
def safe_unicode(str_, from_encoding=None):
"""
safe unicode function. Does few trick to turn str_ into unicode
:param str_: string to decode
:param from_encoding: encode from this type UTF8 default
:rtype: unicode
:returns: unicode object
"""
from_encoding = from_encoding or ['utf8']
if isinstance(str_, unicode):
return str_
if not isinstance(from_encoding, (list, tuple)):
from_encoding = [from_encoding]
initial commit
r0 try:
git: use non-unicode author extraction as it's returned as bytes from backend, and we can...
r825 return unicode(str_)
except UnicodeDecodeError:
pass
initial commit
r0
git: use non-unicode author extraction as it's returned as bytes from backend, and we can...
r825 for enc in from_encoding:
try:
return unicode(str_, enc)
except UnicodeDecodeError:
pass
return unicode(str_, from_encoding[0], 'replace')
svn: added support for hooks management of git and subversion....
r407
class AttributeDict(dict):
def __getattr__(self, attr):
return self.get(attr, None)
__setattr__ = dict.__setitem__
__delattr__ = dict.__delitem__
caches: replaced beaker with dogpile cache.
r483
def sha1(val):
return hashlib.sha1(val).hexdigest()