Skip to content

PYTHONSTARTUP file with non-ascii codes generates error #888

Closed
@niloct

Description

@niloct

I have this code set up on .pythonrc:

try:
    import django
    from django.conf import settings
    if not settings.configured:
        django.setup()
        print('Imported django settings.')
        try:
            exec_strs = [
                (app, 'from {}.models import *'.format(app))
                for app in settings.INSTALLED_APPS
            ]
            for app, x in exec_strs:
                try:
                    exec(x)
                except:
                    pass
                else:
                    print('Imported models for app {}'.format(app))
        except:
            pass
except django.core.exceptions.ImproperlyConfigured as msg:
    print('Erro na configuração do django ao importar módulo: {}'.format(msg))

On latest bpython, it prints an ascii decode error whenever I start bpython (I'm running Python 3.9.2).

The issue is this code:

def get_encoding_file(fname):

It assumes old style comment block coding: utf-8, and if it fails, then assumes ascii encoding.

You could assume utf-8 encoding if there is no block, or try to decode the string and catch a UnicodeDecodeError.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy