Skip to content

Commit

Permalink
Removed compat module
Browse files Browse the repository at this point in the history
  • Loading branch information
nicfit committed Feb 6, 2019
1 parent db2dd3c commit ff6dc02
Show file tree
Hide file tree
Showing 31 changed files with 268 additions and 672 deletions.
4 changes: 2 additions & 2 deletions .cookiecutter.yml
Expand Up @@ -28,8 +28,8 @@ default_context:
pyapp_type: "normal"
pypi_repo_name: "eyeD3"
pypi_username: "nicfit"
pypy: "yes"
pypy3: "yes"
pypy: "no"
pypy3: "no"
release_date: "today"
requirements_yaml: "yes"
src_dir: "./src"
Expand Down
9 changes: 1 addition & 8 deletions docs/eyed3.rst
Expand Up @@ -10,18 +10,11 @@ Subpackages
eyed3.mp3
eyed3.plugins
eyed3.utils
eyed3.vorbis

Submodules
----------

eyed3.compat module
-------------------

.. automodule:: eyed3.compat
:members:
:undoc-members:
:show-inheritance:

eyed3.core module
-----------------

Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
@@ -1,6 +1,6 @@
dataclasses; python_version < "3.7"
grako==3.99.9
pillow==5.4.1
pylast
python-magic==0.4.15
requests==2.21.0
six==1.12.0
2 changes: 1 addition & 1 deletion requirements/main.txt
@@ -1,2 +1,2 @@
dataclasses; python_version < "3.7"
python-magic==0.4.15
six==1.12.0
2 changes: 1 addition & 1 deletion requirements/requirements.yml
@@ -1,6 +1,6 @@
main:
- six
- python-magic
- dataclasses; python_version < "3.7"

extra_display-plugin:
- grako
Expand Down
143 changes: 0 additions & 143 deletions src/eyed3/compat.py

This file was deleted.

4 changes: 1 addition & 3 deletions src/eyed3/core.py
Expand Up @@ -4,11 +4,9 @@
import functools
import pathlib
import dataclasses
from collections import namedtuple

from . import LOCAL_FS_ENCODING
from .utils import guessMimetype
from . import compat
from .utils.log import getLogger
log = getLogger(__name__)

Expand Down Expand Up @@ -401,7 +399,7 @@ def _validateFormat(s):
@staticmethod
def parse(s):
"""Parses date strings that conform to ISO-8601."""
if not isinstance(s, compat.UnicodeType):
if not isinstance(s, str):
s = s.decode("ascii")
s = s.strip('\x00')

Expand Down
7 changes: 2 additions & 5 deletions src/eyed3/id3/__init__.py
Expand Up @@ -19,7 +19,6 @@

from .. import core
from .. import Error
from .. import compat
from ..utils import requireUnicode
from ..utils.log import getLogger

Expand Down Expand Up @@ -121,7 +120,7 @@ class GenreException(Error):
"""Excpetion type for exceptions related to genres."""


class Genre(compat.UnicodeMixin):
class Genre:
"""A genre in terms of a ``name`` and and ``id``. Only when ``name`` is
a "standard" genre (as defined by ID3 v1) will ``id`` be a value other
than ``None``."""
Expand Down Expand Up @@ -260,9 +259,7 @@ def strip0Padding(s):
# Let everything else slide, genres suck anyway
return Genre(id=None, name=g_str)

def __unicode__(self):
"""When Python2 support is dropped this method must be renamed __str__
and the UnicodeMixin base class is dropped."""
def __str__(self):
s = ""
if self.id is not None:
s += "(%d)" % self.id
Expand Down
30 changes: 14 additions & 16 deletions src/eyed3/id3/frames.py
Expand Up @@ -6,7 +6,6 @@
from ..utils import requireUnicode, requireBytes
from ..utils.binfuncs import (bin2bytes, bin2dec, bytes2bin, dec2bin,
bytes2dec, dec2bytes)
from ..compat import unicode, UnicodeType, BytesType, byteiter
from .. import Error
from . import ID3_V2, ID3_V2_3, ID3_V2_4
from . import (LATIN1_ENCODING, UTF_8_ENCODING, UTF_16BE_ENCODING,
Expand Down Expand Up @@ -295,7 +294,7 @@ def render(self):
self._initEncoding()
self.data = (self.encoding +
self.text.encode(id3EncodingToString(self.encoding)))
assert(type(self.data) == BytesType)
assert(type(self.data) is bytes)
return super(TextFrame, self).render()


Expand Down Expand Up @@ -349,7 +348,7 @@ def render(self):
class DateFrame(TextFrame):
def __init__(self, id, date=""):
assert(id in DATE_FIDS or id in DEPRECATED_DATE_FIDS)
super(DateFrame, self).__init__(id, text=unicode(date))
super(DateFrame, self).__init__(id, text=str(date))
self.date = self.text
self.encoding = LATIN1_ENCODING

Expand Down Expand Up @@ -378,17 +377,16 @@ def date(self, date):
try:
if type(date) is str:
date = core.Date.parse(date)
elif type(date) is unicode:
elif type(date) is str:
date = core.Date.parse(date.encode("latin1"))
elif not isinstance(date, core.Date):
raise TypeError("str, unicode, and eyed3.core.Date type "
"expected")
raise TypeError("str or eyed3.core.Date type expected")
except ValueError:
log.warning("Invalid date text: %s" % date)
self.text = ""
return

self.text = unicode(str(date))
self.text = str(date)

def _initEncoding(self):
# Dates are always latin1 since they are always represented in ISO 8601
Expand Down Expand Up @@ -463,7 +461,7 @@ def parse(self, data, frame_header):
log.debug("UserUrlFrame description: %s" % self.description)
# The URL is ascii, ensure
try:
self.url = unicode(u, "ascii").encode("ascii")
self.url = str(u, "ascii").encode("ascii")
except UnicodeDecodeError:
log.warning("Non ascii url, clearing.")
self.url = ""
Expand Down Expand Up @@ -540,12 +538,12 @@ def description(self, d):

@property
def mime_type(self):
return unicode(self._mime_type, "ascii")
return str(self._mime_type, "ascii")

@mime_type.setter
def mime_type(self, m):
m = m or b''
self._mime_type = m if isinstance(m, BytesType) else m.encode('ascii')
self._mime_type = m if isinstance(m, bytes) else m.encode('ascii')

@property
def picture_type(self):
Expand Down Expand Up @@ -767,12 +765,12 @@ def description(self, txt):

@property
def mime_type(self):
return unicode(self._mime_type, "ascii")
return str(self._mime_type, "ascii")

@mime_type.setter
def mime_type(self, m):
m = m or b''
self._mime_type = m if isinstance(m, BytesType) else m.encode('ascii')
self._mime_type = m if isinstance(m, bytes) else m.encode('ascii')

@property
def filename(self):
Expand Down Expand Up @@ -952,9 +950,9 @@ def email(self):
@email.setter
def email(self, email):
# XXX: becoming a pattern?
if isinstance(email, UnicodeType):
if isinstance(email, str):
self._email = email.encode(ascii_encode)
elif isinstance(email, BytesType):
elif isinstance(email, bytes):
_ = email.decode("ascii") # noqa
self._email = email
else:
Expand Down Expand Up @@ -1506,7 +1504,7 @@ def __contains__(self, fid):
def deunsyncData(data):
output = []
safe = True
for val in byteiter(data):
for val in [bytes([b]) for b in data]:
if safe:
output.append(val)
safe = (val != b'\xff')
Expand Down Expand Up @@ -1560,7 +1558,7 @@ def decodeUnicode(bites, encoding):
# Catch and fix bad utf16 data, it is everywhere.
log.warning("Fixing utf16 data with extra zero bytes")
bites = bites[:-1]
return unicode(bites, codec).rstrip("\x00")
return str(bites, codec).rstrip("\x00")


def splitUnicode(data, encoding):
Expand Down

0 comments on commit ff6dc02

Please sign in to comment.