# -*- coding: utf-8 -*-

import subprocess
import re


def parse_output(pattern, default, args):
    try:
        out_str = subprocess.check_output(args)
        if type(out_str) == bytes:
            out_str = out_str.decode()
    except:
        out_str = 'error'
    match = re.search(pattern, out_str)
    if match:
        result = match.group(1)
    else:
        result = default
    return result


def cpu_temp():
    return parse_output(r'temp=(\S*)\'C', '0', ['vcgencmd', 'measure_temp'])


def ip_address():
    return parse_output(r'(\S*)', '?', ['hostname', '-I'])


def hostname():
    return parse_output(r'(\S*)', '?', ['hostname'])


def osname():
    return parse_output(r'(.*)', '?', ['uname', '-a'])

@@ -162,11 +162,17 @@
  if 
-typ
+isinstanc
 e(ou
@@ -180,18 +180,16 @@
 _str
-) ==
+,
  bytes
+)
 :%0A  

correct pep-8 type checking