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