Skip to content
Merged
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
1 change: 0 additions & 1 deletion src/webassets/bundle.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from contextlib import contextmanager
import os
from os import path
from webassets import six

from .filter import get_filter
from .merge import (FileHunk, UrlHunk, FilterTool, merge, merge_filters,
Expand Down
5 changes: 2 additions & 3 deletions src/webassets/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import errno
import tempfile
import warnings
from webassets import six
from webassets.merge import BaseHunk
from webassets.filter import Filter, freezedicts
from webassets.utils import md5_constructor, pickle
Expand Down Expand Up @@ -67,9 +66,9 @@ def walk(obj):
yield obj.data().encode('utf-8')
elif isinstance(obj, int):
yield str(obj).encode('utf-8')
elif isinstance(obj, six.text_type):
elif isinstance(obj, str):
yield obj.encode('utf-8')
elif isinstance(obj, six.binary_type):
elif isinstance(obj, bytes):
yield obj
elif hasattr(obj, "id"):
for i in walk(obj.id()):
Expand Down
9 changes: 4 additions & 5 deletions src/webassets/filter/compass.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import shutil
import subprocess
from io import open
from webassets import six

from webassets.exceptions import FilterError
from webassets.filter import Filter, option
Expand All @@ -49,13 +48,13 @@ def string_rep(val):
""" Determine the correct string rep for the config file """
if isinstance(val, bool):
# True -> true and False -> false
return six.text_type(val).lower()
elif isinstance(val, six.string_types) and val.startswith(':'):
return str(val).lower()
elif isinstance(val, str) and val.startswith(':'):
# ruby symbols, like :nested, used for "output_style"
return six.text_type(val)
return str(val)
elif isinstance(val, dict):
# ruby hashes, for "sass_options" for example
return u'{%s}' % ', '.join("'%s' => '%s'" % i for i in val.items())
return '{%s}' % ', '.join("'%s' => '%s'" % i for i in val.items())
elif isinstance(val, tuple):
val = list(val)
# works fine with strings and lists
Expand Down
2 changes: 1 addition & 1 deletion src/webassets/filter/spritemapper.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from webassets.six import StringIO
from contextlib import contextmanager
from io import StringIO
from webassets.filter import Filter

try:
Expand Down
10 changes: 4 additions & 6 deletions src/webassets/loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@
import glob, fnmatch
import inspect
import types
from webassets import six
try:
import yaml
except ImportError:
pass

from webassets import six
from webassets import Environment
from webassets.bundle import Bundle
from webassets.exceptions import EnvironmentError
Expand Down Expand Up @@ -53,7 +51,7 @@ def _yield_bundle_contents(self, data):
Each item yielded will be either a string representing a file path
or a bundle."""
contents = data.get('contents', [])
if isinstance(contents, six.string_types):
if isinstance(contents, str):
contents = contents,
for content in contents:
if isinstance(content, dict):
Expand All @@ -74,7 +72,7 @@ def _get_bundle(self, data):
def _get_bundles(self, obj, known_bundles=None):
"""Return a dict that keys bundle names to bundles."""
bundles = {}
for key, data in six.iteritems(obj):
for key, data in obj.items():
if data is None:
data = {}
bundles[key] = self._get_bundle(data)
Expand All @@ -100,7 +98,7 @@ def _open(self):

The filename can be False if it is unknown.
"""
if isinstance(self.file_or_filename, six.string_types):
if isinstance(self.file_or_filename, str):
return open(self.file_or_filename), self.file_or_filename

file = self.file_or_filename
Expand Down Expand Up @@ -244,7 +242,7 @@ def load_environment(self):

# Load bundles
bundles = self._get_bundles(obj.get('bundles', {}))
for name, bundle in six.iteritems(bundles):
for name, bundle in bundles.items():
env.register(name, bundle)

return env
Expand Down
12 changes: 3 additions & 9 deletions src/webassets/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,10 @@
"""
import contextlib

try:
from urllib.request import Request as URLRequest, urlopen
from urllib.error import HTTPError
except ImportError:
from urllib2 import Request as URLRequest, urlopen
from urllib2 import HTTPError
import logging
from io import open
from webassets import six
from webassets.six.moves import filter
from urllib.request import Request as URLRequest, urlopen
from urllib.error import HTTPError

from .utils import cmp_debug_levels, StringIO, hash_func

Expand Down Expand Up @@ -120,7 +114,7 @@ def data(self):
else:
with contextlib.closing(response):
data = response.read()
if isinstance(data, six.binary_type):
if isinstance(data, bytes):
data = data.decode('utf-8')
self._data = data

Expand Down
2 changes: 1 addition & 1 deletion src/webassets/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os, sys
import time
import logging
from io import StringIO

from webassets.loaders import PythonLoader, YAMLLoader
from webassets.bundle import get_all_bundle_files
Expand All @@ -10,7 +11,6 @@
from webassets.merge import MemoryHunk
from webassets.version import get_manifest
from webassets.cache import FilesystemCache
from webassets.utils import set, StringIO


__all__ = ('CommandError', 'CommandLineEnvironment', 'main')
Expand Down
51 changes: 8 additions & 43 deletions src/webassets/utils.py
Original file line number Diff line number Diff line change
@@ -1,57 +1,22 @@
from webassets import six
import base64
import contextlib
import hashlib
import os
import pickle
import sys
import re
from io import StringIO
from itertools import takewhile
from urllib import parse as urlparse

from .exceptions import BundleError


__all__ = ('md5_constructor', 'pickle', 'set', 'StringIO',
'common_path_prefix', 'working_directory', 'is_url')


import base64

if sys.version_info >= (2, 5):
import hashlib
md5_constructor = hashlib.md5
else:
import md5
md5_constructor = md5.new


try:
import cPickle as pickle
except ImportError:
import pickle


try:
set
except NameError:
from sets import Set as set
else:
set = set


try:
FileNotFoundError
except NameError:
FileNotFoundError = IOError
else:
FileNotFoundError = FileNotFoundError


from webassets.six import StringIO


try:
from urllib import parse as urlparse
except ImportError: # Python 2
import urlparse
import urllib
md5_constructor = hashlib.md5
set = set

def hash_func(data):
from .cache import make_md5
Expand Down Expand Up @@ -149,7 +114,7 @@ def resolve_option(option, env=None):
return instantiate(option, env)

# If it is a string
elif isinstance(option, six.string_types):
elif isinstance(option, str):
parts = option.split(':', 1)
key = parts[0]
arg = parts[1] if len(parts) > 1 else None
Expand Down
9 changes: 4 additions & 5 deletions src/webassets/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import os
import pickle
from webassets import six

from webassets.merge import FileHunk
from webassets.utils import md5_constructor, RegistryMetaclass, is_url
Expand All @@ -19,9 +18,9 @@ class VersionIndeterminableError(Exception):
pass


class Version(six.with_metaclass(RegistryMetaclass(
class Version(metaclass=RegistryMetaclass(
clazz=lambda: Version, attribute='determine_version',
desc='a version implementation'))):
desc='a version implementation')):
"""A Version class that can be assigned to the ``Environment.versioner``
attribute.

Expand Down Expand Up @@ -165,8 +164,8 @@ def determine_version(self, bundle, ctx, hunk=None):
return hasher.hexdigest()[:self.length]


class Manifest(six.with_metaclass(RegistryMetaclass(
clazz=lambda: Manifest, desc='a manifest implementation'))):
class Manifest(metaclass=RegistryMetaclass(
clazz=lambda: Manifest, desc='a manifest implementation')):
"""Persists information about the versions bundles are at.

The Manifest plays a role only if you insert the bundle version in your
Expand Down
2 changes: 1 addition & 1 deletion tests/test_bundle_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def test_auto_create_target_directory(self):

def test_with_custom_output(self):
"""build() method can write to a custom file object."""
from webassets.six import StringIO
from io import StringIO
buffer = StringIO()
self.mkbundle('in1', 'in2', output='out').build(output=buffer)
assert buffer.getvalue() == 'A\nB'
Expand Down
12 changes: 3 additions & 9 deletions tests/test_bundle_various.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,15 @@
"""

import copy
from io import StringIO
from os import path
import uuid
try:
from urllib.request import \
HTTPHandler, build_opener, install_opener, addinfourl
except ImportError: # Py2
from urllib2 import HTTPHandler, build_opener, install_opener, addinfourl
from urllib.request import \
HTTPHandler, build_opener, install_opener, addinfourl

import pytest

from webassets.six import StringIO
from webassets.six.moves import filter

from webassets import Bundle
from webassets.utils import set
from webassets.bundle import get_all_bundle_files
from webassets.env import Environment
from webassets.exceptions import BundleError, BuildError
Expand Down
3 changes: 1 addition & 2 deletions tests/test_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import pytest

from webassets import six
from webassets import Environment
from webassets.env import RegisterError
from webassets import Bundle
Expand Down Expand Up @@ -222,7 +221,7 @@ def test_versioner(self):

# Standard string values
self.m.versions = 'timestamp'
assert isinstance(self.m.config['versions'], six.string_types)
assert isinstance(self.m.config['versions'], str)
assert isinstance(self.m.versions, Version)
assert self.m.versions == 'timestamp' # __eq__
assert self.m.versions != 'hash'
Expand Down
9 changes: 2 additions & 7 deletions tests/test_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -1185,11 +1185,7 @@ def test_compass_with_unicode(self):

# It's very hard to test this with doctest_match
# And by asserting that it's in the content this test is proven
from webassets.six import PY3
if PY3:
assert """content: "áé";""" in self.get('out.css')
else:
assert """content: "\xc3\xa1\xc3\xa9";""" in self.get('out.css')
assert """content: "áé";""" in self.get('out.css')

def test_images_dir(self):
# [bug] Make sure the compass plugin can reference images. It expects
Expand Down Expand Up @@ -1229,8 +1225,7 @@ def setup_method(self):
self.compass_config = CompassConfig(self.config).to_string()

def test_compass_config_is_unicode(self):
from webassets.six import text_type
assert isinstance(self.compass_config, text_type)
assert isinstance(self.compass_config, str)

def test_string_value(self):
assert "http_path = '/'" in self.compass_config
Expand Down