common/utilities.py
def as_encoded_str(s, encoding='utf8', errors='strict'):
    """Ensures passed argument is always an encoded string if it's Unicode.

    However, if it's not string-like then it is returned as is.
    """
    if isinstance(s, unicode):
        s = s.encode(encoding, errors)
    return s
Ensures passed argument is always an encoded string if it's Unicode.

    However, if it's not string-like then it is returned as is.
    
Ensures passed argument is always an encoded string if it's Unicode.
However, if it's not string-like then it is returned as is.
Ensures passed argument is always an encoded string if it ' s Unicode . However if it ' s not string - like then it is returned as is .
def as_encoded_str(s, encoding='utf8', errors='strict'):
    if isinstance(s, unicode):
        s = s.encode(encoding, errors)
    return s
def as_encoded_str ( s , encoding = 'utf8' , errors = 'strict' ) : if isinstance ( s , unicode ) : s = s . encode ( encoding , errors ) return s
Ensures passed argument is always an encoded string if it's Unicode.
Ensures passed argument is always an encoded string if it ' s Unicode .
"""Ensures passed argument is always an encoded string if it's Unicode.

    However, if it's not string-like then it is returned as is.
    """
s
encoding
errors