mirror of
https://github.com/home-assistant/core.git
synced 2025-04-24 01:08:12 +00:00
More unicode support added to the core
This commit is contained in:
parent
8d23976763
commit
28389f6c39
@ -171,7 +171,7 @@ def create_bus_job_handler(logger):
|
||||
except Exception: # pylint: disable=broad-except
|
||||
# Catch any exception our service/event_listener might throw
|
||||
# We do not want to crash our ThreadPool
|
||||
logger.exception("BusHandler:Exception doing job")
|
||||
logger.exception(u"BusHandler:Exception doing job")
|
||||
|
||||
return job_handler
|
||||
|
||||
@ -189,10 +189,10 @@ class ServiceCall(object):
|
||||
|
||||
def __repr__(self):
|
||||
if self.data:
|
||||
return "<ServiceCall {}.{}: {}>".format(
|
||||
return u"<ServiceCall {}.{}: {}>".format(
|
||||
self.domain, self.service, util.repr_helper(self.data))
|
||||
else:
|
||||
return "<ServiceCall {}.{}>".format(self.domain, self.service)
|
||||
return u"<ServiceCall {}.{}>".format(self.domain, self.service)
|
||||
|
||||
|
||||
# pylint: disable=too-few-public-methods
|
||||
@ -207,10 +207,10 @@ class Event(object):
|
||||
|
||||
def __repr__(self):
|
||||
if self.data:
|
||||
return "<Event {}: {}>".format(
|
||||
return u"<Event {}: {}>".format(
|
||||
self.event_type, util.repr_helper(self.data))
|
||||
else:
|
||||
return "<Event {}>".format(self.event_type)
|
||||
return u"<Event {}>".format(self.event_type)
|
||||
|
||||
|
||||
class Bus(object):
|
||||
@ -268,7 +268,7 @@ class Bus(object):
|
||||
|
||||
except KeyError: # if key domain or service does not exist
|
||||
raise ServiceDoesNotExistError(
|
||||
"Service does not exist: {}/{}".format(domain, service))
|
||||
u"Service does not exist: {}/{}".format(domain, service))
|
||||
|
||||
def register_service(self, domain, service, service_func):
|
||||
""" Register a service. """
|
||||
@ -290,7 +290,7 @@ class Bus(object):
|
||||
|
||||
event = Event(event_type, event_data)
|
||||
|
||||
self.logger.info("Bus:Handling {}".format(event))
|
||||
self.logger.info(u"Bus:Handling {}".format(event))
|
||||
|
||||
if not listeners:
|
||||
return
|
||||
@ -371,13 +371,13 @@ class Bus(object):
|
||||
log_error = self.logger.error
|
||||
|
||||
log_error(
|
||||
"Bus:All {} threads are busy and {} jobs pending".format(
|
||||
u"Bus:All {} threads are busy and {} jobs pending".format(
|
||||
self.thread_count, self.pool.queue.qsize()))
|
||||
|
||||
jobs = self.pool.current_jobs
|
||||
|
||||
for start, job in jobs:
|
||||
log_error("Bus:Current job from {}: {}".format(
|
||||
log_error(u"Bus:Current job from {}: {}".format(
|
||||
util.datetime_to_str(start), job))
|
||||
|
||||
|
||||
@ -436,11 +436,11 @@ class State(object):
|
||||
|
||||
def __repr__(self):
|
||||
if self.attributes:
|
||||
return "<state {}:{} @ {}>".format(
|
||||
return u"<state {}:{} @ {}>".format(
|
||||
self.state, util.repr_helper(self.attributes),
|
||||
util.datetime_to_str(self.last_changed))
|
||||
else:
|
||||
return "<state {} @ {}>".format(
|
||||
return u"<state {} @ {}>".format(
|
||||
self.state, util.datetime_to_str(self.last_changed))
|
||||
|
||||
|
||||
|
@ -209,10 +209,10 @@ class RequestHandler(BaseHTTPRequestHandler):
|
||||
for t_method, t_path, t_handler in RequestHandler.PATHS:
|
||||
|
||||
# we either do string-comparison or regular expression matching
|
||||
# pylint: disable=maybe-no-member
|
||||
if isinstance(t_path, str):
|
||||
path_match = url.path == t_path
|
||||
else:
|
||||
# pylint: disable=maybe-no-member
|
||||
path_match = t_path.match(url.path)
|
||||
|
||||
if path_match and method == t_method:
|
||||
@ -335,13 +335,13 @@ class RequestHandler(BaseHTTPRequestHandler):
|
||||
|
||||
state = self.server.statemachine.get_state(entity_id)
|
||||
|
||||
attributes = "<br>".join(
|
||||
["{}: {}".format(attr, state.attributes[attr])
|
||||
attributes = u"<br>".join(
|
||||
[u"{}: {}".format(attr, state.attributes[attr])
|
||||
for attr in state.attributes])
|
||||
|
||||
write(("<tr>"
|
||||
"<td>{}</td><td>{}</td><td>{}</td><td>{}</td>"
|
||||
"</tr>").format(
|
||||
write((u"<tr>"
|
||||
u"<td>{}</td><td>{}</td><td>{}</td><td>{}</td>"
|
||||
u"</tr>").format(
|
||||
entity_id,
|
||||
state.state,
|
||||
attributes,
|
||||
|
@ -7,7 +7,7 @@ import re
|
||||
RE_SANITIZE_FILENAME = re.compile(r"(~|(\.\.)|/|\+)")
|
||||
RE_SLUGIFY = re.compile(r'[^A-Za-z0-9_]+')
|
||||
|
||||
DATE_STR_FORMAT = "%H:%M:%S %d-%m-%Y"
|
||||
DATE_STR_FORMAT = u"%H:%M:%S %d-%m-%Y"
|
||||
|
||||
|
||||
def sanitize_filename(filename):
|
||||
@ -59,15 +59,15 @@ def filter_entity_ids(entity_ids, domain_filter=None, strip_domain=False):
|
||||
def repr_helper(inp):
|
||||
""" Helps creating a more readable string representation of objects. """
|
||||
if isinstance(inp, dict):
|
||||
return ", ".join(
|
||||
repr_helper(key)+"="+repr_helper(item) for key, item in inp.items()
|
||||
return u", ".join(
|
||||
repr_helper(key)+u"="+repr_helper(item) for key, item in inp.items()
|
||||
)
|
||||
elif isinstance(inp, list):
|
||||
return '[' + ', '.join(inp) + ']'
|
||||
return u'[' + u', '.join(inp) + u']'
|
||||
elif isinstance(inp, datetime.datetime):
|
||||
return datetime_to_str(inp)
|
||||
else:
|
||||
return str(inp)
|
||||
return unicode(inp)
|
||||
|
||||
|
||||
# Reason why I decided to roll my own ThreadPool instead of using
|
||||
|
Loading…
x
Reference in New Issue
Block a user