##// END OF EJS Templates
release: updated pip2nix output for 4.12.1
release: updated pip2nix output for 4.12.1

File last commit:

r407:34976bc5 default
r438:45eade2e stable
Show More
utils.py
82 lines | 2.3 KiB | text/x-python | PythonLexer
initial commit
r0 # RhodeCode VCSServer provides access to different vcs backends via network.
core: udpate copyright string to 2018
r352 # Copyright (C) 2014-2018 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
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
initial commit
r0 def safe_str(unicode_, to_encoding=['utf8']):
"""
safe str function. Does few trick to turn unicode_ into string
In case of UnicodeEncodeError, we try to return it with encoding detected
by chardet library if it fails fallback to string with errors replaced
:param unicode_: unicode to encode
:rtype: str
:returns: str object
"""
# 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
try:
import chardet
encoding = chardet.detect(unicode_)['encoding']
if encoding is None:
raise UnicodeEncodeError()
return unicode_.encode(encoding)
except (ImportError, UnicodeEncodeError):
return unicode_.encode(to_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__