Skip to content

trim old Python2 compatibility layer #556

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
# serve to show the default.

import sys, os
from webassets.six.moves import map
from webassets.six.moves import zip

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
Expand Down
5 changes: 0 additions & 5 deletions examples/appengine/helloworld.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
from __future__ import print_function
from __future__ import print_function
from __future__ import print_function
from __future__ import print_function
from __future__ import print_function
# Import assets configuration
from assets import bundle

Expand Down
11 changes: 3 additions & 8 deletions src/webassets/bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
import os
from os import path
from webassets import six
from webassets.six.moves import map
from webassets.six.moves import zip

from .filter import get_filter
from .merge import (FileHunk, UrlHunk, FilterTool, merge, merge_filters,
Expand Down Expand Up @@ -161,12 +159,9 @@ def _set_filters(self, value):
self._filters = ()
return

if isinstance(value, six.string_types):
if isinstance(value, str):
# 333: Simplify w/o condition?
if six.PY3:
filters = map(str.strip, value.split(','))
else:
filters = map(unicode.strip, unicode(value).split(','))
filters = map(str.strip, value.split(','))
elif isinstance(value, (list, tuple)):
filters = value
else:
Expand Down Expand Up @@ -276,7 +271,7 @@ def _filter_duplicates(resolved):
def _get_depends(self):
return self._depends
def _set_depends(self, value):
self._depends = [value] if isinstance(value, six.string_types) else value
self._depends = [value] if isinstance(value, str) else value
self._resolved_depends = None
depends = property(_get_depends, _set_depends, doc=
"""Allows you to define an additional set of files (glob syntax
Expand Down
6 changes: 2 additions & 4 deletions src/webassets/env.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import os
from os import path
from itertools import chain
from webassets import six
from webassets.six.moves import map
from webassets.utils import is_url

try:
Expand Down Expand Up @@ -242,7 +240,7 @@ def resolve_source(self, ctx, item):
"""

# Pass through some things unscathed
if not isinstance(item, six.string_types):
if not isinstance(item, str):
# Don't stand in the way of custom values.
return item
if is_url(item) or path.isabs(item):
Expand Down Expand Up @@ -308,7 +306,7 @@ def __init__(self):
self._anon_bundles = []

def __iter__(self):
return chain(six.itervalues(self._named_bundles), self._anon_bundles)
return chain(self._named_bundles.values(), self._anon_bundles)

def __getitem__(self, name):
return self._named_bundles[name]
Expand Down
2 changes: 0 additions & 2 deletions src/webassets/ext/jinja2.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import

import warnings
import jinja2
from jinja2.ext import Extension
Expand Down
21 changes: 3 additions & 18 deletions src/webassets/filter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,13 @@
contents (think minification, compression).
"""

from __future__ import with_statement

import os
import subprocess
import inspect
import shlex
import tempfile
import pkgutil
from webassets import six
from webassets.six.moves import map
from webassets.six.moves import zip
try:
frozenset
except NameError:
Expand All @@ -34,7 +30,7 @@ def freezedicts(obj):
if isinstance(obj, (list, tuple)):
return type(obj)([freezedicts(sub) for sub in obj])
if isinstance(obj, dict):
return frozenset(six.iteritems(obj))
return frozenset(obj.items())
return obj


Expand All @@ -50,19 +46,11 @@ def smartsplit(string, sep):
be done.
"""
assert string is not None # or shlex will read from stdin
if not six.PY3:
# On 2.6, shlex fails miserably with unicode input
is_unicode = isinstance(string, unicode)
if is_unicode:
string = string.encode('utf8')
l = shlex.shlex(string, posix=True)
l.whitespace += ','
l.whitespace_split = True
l.quotes = ''
if not six.PY3 and is_unicode:
return map(lambda s: s.decode('utf8'), list(l))
else:
return list(l)
return list(l)


class option(tuple):
Expand Down Expand Up @@ -204,9 +192,6 @@ def get_config(self, setting=False, env=None, require=True,
if value is None and not env is False:
value = os.environ.get(env)
if value is not None:
if not six.PY3:
# TODO: What charset should we use? What does Python 3 use?
value = value.decode('utf8')
if type == list:
value = smartsplit(value, ',')

Expand Down Expand Up @@ -620,7 +605,7 @@ def get_filter(f, *args, **kwargs):
# Don't need to do anything.
assert not args and not kwargs
return f
elif isinstance(f, six.string_types):
elif isinstance(f, str):
if f in _FILTERS:
klass = _FILTERS[f]
else:
Expand Down
2 changes: 0 additions & 2 deletions src/webassets/filter/autoprefixer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import with_statement

from webassets.filter import ExternalTool
from webassets.utils import working_directory

Expand Down
1 change: 0 additions & 1 deletion src/webassets/filter/clevercss.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import absolute_import
from webassets.filter import Filter


Expand Down
1 change: 0 additions & 1 deletion src/webassets/filter/closure.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
['--output_wrapper', 'foo: %output%']
"""

from __future__ import absolute_import
from webassets.filter import JavaTool


Expand Down
1 change: 0 additions & 1 deletion src/webassets/filter/coffeescript.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import print_function
import os, subprocess

from webassets.filter import Filter
Expand Down
1 change: 0 additions & 1 deletion src/webassets/filter/cssmin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import absolute_import
from webassets.filter import Filter


Expand Down
1 change: 0 additions & 1 deletion src/webassets/filter/cssprefixer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import absolute_import
from webassets.filter import Filter


Expand Down
1 change: 0 additions & 1 deletion src/webassets/filter/cssrewrite/urlpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
# Scripts maintained at http://www.voidspace.org.uk/python/index.shtml
# E-mail [email protected]

from __future__ import print_function
import posixpath
import os
try:
Expand Down
1 change: 0 additions & 1 deletion src/webassets/filter/cssutils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import absolute_import
import logging
import logging.handlers

Expand Down
1 change: 0 additions & 1 deletion src/webassets/filter/jade.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# coding=utf-8

from __future__ import print_function
import os, subprocess
from webassets.filter import Filter, register_filter
from webassets.exceptions import FilterError
Expand Down
1 change: 0 additions & 1 deletion src/webassets/filter/jinja2.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import absolute_import
from webassets.filter import Filter


Expand Down
1 change: 0 additions & 1 deletion src/webassets/filter/jsmin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import absolute_import
import warnings

from webassets.filter import Filter
Expand Down
8 changes: 1 addition & 7 deletions src/webassets/filter/jspacker/jspacker.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import print_function
## ParseMaster, version 1.0 (pre-release) (2005/05/12) x6
## Copyright 2005, Dean Edwards
## Web: http://dean.edwards.name/
Expand All @@ -9,11 +8,6 @@
## Ported to Python by Florian Schulze

import os, re
import sys
if sys.version < '3':
integer_types = (int, long,)
else:
integer_types = (int,)

# a multi-pattern parser

Expand Down Expand Up @@ -111,7 +105,7 @@ def _replacement(self, match):
replacement = pattern.replacement
if callable(replacement):
return replacement(match, i)
elif isinstance(replacement, integer_types):
elif isinstance(replacement, int):
return match.group(replacement+i)
else:
return replacement
Expand Down
2 changes: 0 additions & 2 deletions src/webassets/filter/less.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import with_statement

import os

from webassets.filter import ExternalTool
Expand Down
3 changes: 0 additions & 3 deletions src/webassets/filter/libsass.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
[1] https://bitbucket.org/jhuss/webassets-libsass
"""

from __future__ import print_function
from __future__ import absolute_import

from webassets.filter import Filter


Expand Down
2 changes: 0 additions & 2 deletions src/webassets/filter/postcss.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import with_statement

from webassets.filter import ExternalTool
from webassets.utils import working_directory

Expand Down
1 change: 0 additions & 1 deletion src/webassets/filter/rcssmin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import absolute_import
from webassets.filter import Filter


Expand Down
2 changes: 0 additions & 2 deletions src/webassets/filter/requirejs.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import with_statement

import shlex
from os import path, getcwd

Expand Down
1 change: 0 additions & 1 deletion src/webassets/filter/rjsmin/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import absolute_import
try:
import rjsmin
except ImportError:
Expand Down
2 changes: 0 additions & 2 deletions src/webassets/filter/sass.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import print_function

import os

from webassets.filter import ExternalTool
Expand Down
1 change: 0 additions & 1 deletion src/webassets/filter/sass_ruby.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import print_function
import os, subprocess

from webassets.filter import ExternalTool
Expand Down
1 change: 0 additions & 1 deletion src/webassets/filter/slimit.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import absolute_import
from webassets.filter import Filter


Expand Down
2 changes: 0 additions & 2 deletions src/webassets/filter/slimmer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import absolute_import

from webassets.filter import Filter


Expand Down
2 changes: 0 additions & 2 deletions src/webassets/filter/spritemapper.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import print_function
from __future__ import absolute_import
from webassets.six import StringIO
from contextlib import contextmanager
from webassets.filter import Filter
Expand Down
1 change: 0 additions & 1 deletion src/webassets/merge.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Contains the core functionality that manages merging of assets.
"""
from __future__ import with_statement
import contextlib

try:
Expand Down
1 change: 0 additions & 1 deletion src/webassets/script.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import print_function
import shutil
import os, sys
import time
Expand Down
3 changes: 0 additions & 3 deletions src/webassets/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
This is included in the webassets package because it is useful for testing
external libraries that use webassets (like the flask-assets wrapper).
"""
from __future__ import print_function

import tempfile
import shutil
Expand All @@ -12,8 +11,6 @@
import time

from webassets import Environment, Bundle
from webassets.six.moves import map
from webassets.six.moves import zip


__all__ = ('TempDirHelper', 'TempEnvironmentHelper',)
Expand Down
5 changes: 1 addition & 4 deletions src/webassets/updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@
increase as using the hash to reliably determine which bundles to skip.
"""

from webassets import six
from webassets.six.moves import map
from webassets.six.moves import zip
from webassets.exceptions import BundleError, BuildError
from webassets.utils import RegistryMetaclass, is_url, hash_func

Expand All @@ -48,7 +45,7 @@
"""


class BaseUpdater(six.with_metaclass(RegistryMetaclass(
class BaseUpdater(metaclass=RegistryMetaclass(
clazz=lambda: BaseUpdater, attribute='needs_rebuild',
desc='an updater implementation'))):
"""Base updater class.
Expand Down
2 changes: 0 additions & 2 deletions src/webassets/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
implementations.
"""

from __future__ import with_statement

import os
import pickle
from webassets import six
Expand Down
1 change: 0 additions & 1 deletion tests/helpers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import with_statement
import re

from webassets.test import TempDirHelper, TempEnvironmentHelper
Expand Down
2 changes: 0 additions & 2 deletions tests/test_bundle_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
more likely` found in `test_bundle_various.py``.
"""

from __future__ import with_statement

import re

import pytest
Expand Down
2 changes: 0 additions & 2 deletions tests/test_bundle_various.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
specific features/aspects, like "globbing" or "versions".
"""

from __future__ import with_statement

import copy
from os import path
import uuid
Expand Down
2 changes: 0 additions & 2 deletions tests/test_cache.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import with_statement

import random
import pytest

Expand Down
2 changes: 0 additions & 2 deletions tests/test_environment.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import with_statement

import os

import pytest
Expand Down
Loading