コード例 #1
0
    def post_hassio_login(self):
        import requests

        headers = {
            'X-HASSIO-KEY': os.getenv('HASSIO_TOKEN'),
        }
        data = {
            'username': decode_text(self.get_argument('username', '')),
            'password': decode_text(self.get_argument('password', ''))
        }
        try:
            req = requests.post('http://hassio/auth',
                                headers=headers,
                                data=data)
            if req.status_code == 200:
                self.set_secure_cookie("authenticated",
                                       cookie_authenticated_yes)
                self.redirect('/')
                return
        except Exception as err:  # pylint: disable=broad-except
            _LOGGER.warning("Error during Hass.io auth request: %s", err)
            self.set_status(500)
            self.render_login_page(error="Internal server error")
            return
        self.set_status(401)
        self.render_login_page(error="Invalid username or password")
コード例 #2
0
 def post_native_login(self):
     username = decode_text(self.get_argument("username", ''))
     password = decode_text(self.get_argument("password", ''))
     if settings.check_password(username, password):
         self.set_secure_cookie("authenticated", cookie_authenticated_yes)
         self.redirect("/")
         return
     error_str = "Invalid username or password" if settings.username else "Invalid password"
     self.set_status(401)
     self.render_login_page(error=error_str)
コード例 #3
0
ファイル: util.py プロジェクト: schinckel/esphome
    def write(self, s):
        # s is usually a text_type already (self._out is of type TextIOWrapper)
        # However, s is sometimes also a bytes object in python3. Let's make sure it's a
        # text_type
        # If the conversion fails, we will create an exception, which is okay because we won't
        # be able to print it anyway.
        text = decode_text(s)
        assert isinstance(text, text_type)

        if self._filter_pattern is not None:
            self._line_buffer += text
            lines = self._line_buffer.splitlines(True)
            for line in lines:
                if '\n' not in line and '\r' not in line:
                    # Not a complete line, set line buffer
                    self._line_buffer = line
                    break
                self._line_buffer = ''

                line_without_ansi = ANSI_ESCAPE.sub('', line)
                line_without_end = line_without_ansi.rstrip()
                if self._filter_pattern.match(line_without_end) is not None:
                    # Filter pattern matched, ignore the line
                    continue

                self._write_color_replace(line)
        else:
            self._write_color_replace(text)

        # write() returns the number of characters written
        # Let's print the number of characters of the original string in order to not confuse
        # any caller.
        return len(s)
コード例 #4
0
ファイル: config_validation.py プロジェクト: zinefer/esphome
 def _vol_invalid_unicode(self):
     path = u' @ data[%s]' % u']['.join(map(repr, self.path)) \
         if self.path else u''
     # pylint: disable=no-member
     output = decode_text(self.message)
     if self.error_type:
         output += u' for ' + self.error_type
     return output + path
コード例 #5
0
 def __init__(self, base_exc):
     try:
         base = str(base_exc)
     except UnicodeDecodeError:
         base = repr(base_exc)
     base = decode_text(base)
     message = u"Invalid YAML syntax. Please see YAML syntax reference or use an " \
               u"online YAML syntax validator:\n\n{}".format(base)
     super(InvalidYAMLError, self).__init__(message)
     self.base_exc = base_exc
コード例 #6
0
ファイル: dashboard.py プロジェクト: witsoft001/esphome
    def post(self):
        from esphome import wizard

        kwargs = {
            k: u''.join(decode_text(x) for x in v)
            for k, v in self.request.arguments.items()
        }
        destination = os.path.join(CONFIG_DIR, kwargs['name'] + u'.yaml')
        wizard.wizard_write(path=destination, **kwargs)
        self.redirect('/?begin=True')
コード例 #7
0
def run_idedata(config):
    args = ['-t', 'idedata']
    stdout = run_platformio_cli_run(config, False, *args, capture_stdout=True)
    stdout = decode_text(stdout)
    match = re.search(r'{.*}', stdout)
    if match is None:
        return IDEData(None)
    try:
        return IDEData(json.loads(match.group()))
    except ValueError:
        return IDEData(None)
コード例 #8
0
def run_idedata(config):
    args = ['-t', 'idedata']
    stdout = run_platformio_cli_run(config, False, *args, capture_stdout=True)
    stdout = decode_text(stdout)
    match = re.search(r'{\s*".*}', stdout)
    if match is None:
        _LOGGER.debug("Could not match IDEData for %s", stdout)
        return IDEData(None)
    try:
        return IDEData(json.loads(match.group()))
    except ValueError:
        _LOGGER.debug("Could not load IDEData for %s", stdout, exc_info=1)
        return IDEData(None)
コード例 #9
0
def _decode_pc(config, addr):
    idedata = get_idedata(config)
    if not idedata.addr2line_path or not idedata.firmware_elf_path:
        _LOGGER.debug("decode_pc no addr2line")
        return
    command = [idedata.addr2line_path, '-pfiaC', '-e', idedata.firmware_elf_path, addr]
    try:
        translation = decode_text(subprocess.check_output(command)).strip()
    except Exception:  # pylint: disable=broad-except
        _LOGGER.debug("Caught exception for command %s", command, exc_info=1)
        return

    if "?? ??:0" in translation:
        # Nothing useful
        return
    translation = translation.replace(' at ??:?', '').replace(':?', '')
    _LOGGER.warning("Decoded %s", translation)
コード例 #10
0
 def on_message(client, userdata, msg):
     time_ = datetime.now().time().strftime(u'[%H:%M:%S]')
     payload = decode_text(msg.payload)
     message = time_ + payload
     safe_print(message)