def email_url_config(cls, url, backend=None):
        """Parses an email URL."""

        config = {}

        url = urlparse(url) if not isinstance(url, cls.URL_CLASS) else url

        # Remove query strings
        path = url.path[1:]
        path = unquote_plus(path.split('?', 2)[0])

        # Update with environment configuration
        config.update({
            'EMAIL_FILE_PATH': path,
            'EMAIL_HOST_USER': _cast_urlstr(url.username),
            'EMAIL_HOST_PASSWORD': _cast_urlstr(url.password),
            'EMAIL_HOST': url.hostname,
            'EMAIL_PORT': _cast_int(url.port),
        })

        if backend:
            config['EMAIL_BACKEND'] = backend
        elif url.scheme not in cls.EMAIL_SCHEMES:
            raise ImproperlyConfigured('Invalid email schema %s' % url.scheme)
        elif url.scheme in cls.EMAIL_SCHEMES:
            config['EMAIL_BACKEND'] = cls.EMAIL_SCHEMES[url.scheme]

        if url.scheme in ('smtps', 'smtp+tls'):
            config['EMAIL_USE_TLS'] = True
        elif url.scheme == 'smtp+ssl':
            config['EMAIL_USE_SSL'] = True

        if url.query:
            config_options = {}
            for k, v in parse_qs(url.query).items():
                opt = {k.upper(): _cast_int(v[0])}
                if k.upper() in cls._EMAIL_BASE_OPTIONS:
                    config.update(opt)
                else:
                    config_options.update(opt)
            config['OPTIONS'] = config_options

        return config
def email_url_config ( cls , url , backend = None ) : config = { } url = urlparse ( url ) if not isinstance ( url , cls . URL_CLASS ) else url path = url . path [ 1 : ] path = unquote_plus ( path . split ( '?' , 2 ) [ 0 ] ) config . update ( { 'EMAIL_FILE_PATH' : path , 'EMAIL_HOST_USER' : _cast_urlstr ( url . username ) , 'EMAIL_HOST_PASSWORD' : _cast_urlstr ( url . password ) , 'EMAIL_HOST' : url . hostname , 'EMAIL_PORT' : _cast_int ( url . port ) , } ) if backend : config [ 'EMAIL_BACKEND' ] = backend elif url . scheme not in cls . EMAIL_SCHEMES : raise ImproperlyConfigured ( 'Invalid email schema %s' % url . scheme ) elif url . scheme in cls . EMAIL_SCHEMES : config [ 'EMAIL_BACKEND' ] = cls . EMAIL_SCHEMES [ url . scheme ] if url . scheme in ( 'smtps' , 'smtp+tls' ) : config [ 'EMAIL_USE_TLS' ] = True elif url . scheme == 'smtp+ssl' : config [ 'EMAIL_USE_SSL' ] = True if url . query : config_options = { } for k , v in parse_qs ( url . query ) . items ( ) : opt = { k . upper ( ) : _cast_int ( v [ 0 ] ) } if k . upper ( ) in cls . _EMAIL_BASE_OPTIONS : config . update ( opt ) else : config_options . update ( opt ) config [ 'OPTIONS' ] = config_options return config
Parses an email URL.