import socket

black = '30m'
red = '31m'
green = '32m'
yellow = '33m'
blue = '34m'
magenta = '35m'
cyan = '36m'
gray = '37m'

bg_black = '40m'
bg_red = '41m'
bg_green = '42m'
bg_yellow = '43m'
bg_blue = '44m'
bg_magenta = '45m'
bg_cyan = '46m'
bg_gray = '47m'

hosts = {'LM0276MEB':('m', bg_gray),
	 'grond': (gray, bg_red),
	 'milou': (yellow, bg_blue),
	 'anchorage': (black, bg_green),
	 'fairbanks': (black, bg_yellow),
         'ribes': (black, bg_cyan),
         'other': (red, bg_gray)
}

hostname = socket.gethostname()

def get_colors():
    fg = hosts['other'][0]
    bg = hosts['other'][1]
    for hname in hosts:
	if hostname in hname or hname in hostname:
	    fg = hosts[hname][0]
	    bg = hosts[hname][1]
    return "\033[{fg}\033[{bg} \u@\h \033[0m".format(fg=fg, bg=bg)

print get_colors()

@@ -618,17 +618,24 @@
  hosts:%0A
-%09
+        
 if hostn
@@ -669,17 +669,24 @@
 stname:%0A
-%09
+        
     fg =
@@ -702,17 +702,24 @@
 ame%5D%5B0%5D%0A
-%09
+        
     bg =
@@ -746,16 +746,17 @@
  return 
+r
 %22%5C033%5B%7Bf
@@ -809,17 +809,17 @@
 )%0A%0Aprint
- 
+(
 get_colo
@@ -822,9 +822,10 @@
 colors()
+)
 %0A

update to py3.5 syntax