Skip to content

Commit

Permalink
Merge branch 'release/3.3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
cdown committed May 22, 2020
2 parents 14981bf + 9e8482c commit 11f06e6
Show file tree
Hide file tree
Showing 15 changed files with 73 additions and 19 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@ jobs:
## Linux

# CPython (in official virtualenv)
- python: '2.7'
- python: '3.5'
- python: '3.6'
# 3.7 is below
- python: '3.8'
env: TOXENV=doctest

# PyPy (in official virtualenv)
- python: pypy
env: TOXENV=pypy
- python: pypy3
env: TOXENV=pypy3

Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
source_suffix = ".rst"
templates_path = ["_templates"]

version = "3.2.1"
version = "3.3.0"
release = version

html_static_path = ["_static"]
Expand Down
13 changes: 10 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
#!/usr/bin/env python

import codecs
from distutils.core import setup

try:
from setuptools import setup
except ImportError:
from distutils.core import setup


with codecs.open("README.rst", encoding="utf8") as readme_f:
README = readme_f.read()

setup(
name="srt",
version="3.2.1",
python_requires=">=3.5",
version="3.3.0",
python_requires=">=2.7",
description="A tiny library for parsing, modifying, and composing SRT files.",
long_description=README,
author="Chris Down",
Expand All @@ -33,6 +38,8 @@
"Intended Audience :: Developers",
"License :: Public Domain",
"Operating System :: OS Independent",
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
Expand Down
17 changes: 13 additions & 4 deletions srt.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#!/usr/bin/env python
# coding=utf8

"""A tiny library for parsing, modifying, and composing SRT files."""

from __future__ import unicode_literals
import functools
import re
from datetime import timedelta
Expand Down Expand Up @@ -68,11 +70,15 @@
SECONDS_IN_MINUTE = 60
HOURS_IN_DAY = 24
MICROSECONDS_IN_MILLISECOND = 1000
FILE_TYPES = (io.IOBase,)

try:
FILE_TYPES = (file, io.IOBase) # pytype: disable=name-error
except NameError: # `file` doesn't exist in Python 3
FILE_TYPES = (io.IOBase,)


@functools.total_ordering
class Subtitle:
class Subtitle(object):
r"""
The metadata relating to a single subtitle. Subtitles are sorted by start
time by default.
Expand Down Expand Up @@ -109,7 +115,9 @@ def __lt__(self, other):
)

def __repr__(self):
item_list = ", ".join("%s=%r" % (k, v) for k, v in vars(self).items())
# Python 2/3 cross compatibility
var_items = getattr(vars(self), "iteritems", getattr(vars(self), "items"))
item_list = ", ".join("%s=%r" % (k, v) for k, v in var_items())
return "%s(%s)" % (type(self).__name__, item_list)

def to_srt(self, strict=True, eol="\n"):
Expand Down Expand Up @@ -294,7 +302,8 @@ def _should_skip_sub(subtitle):

def parse(srt):
r'''
Convert an SRT formatted string to a :term:`generator` of Subtitle objects.
Convert an SRT formatted string (in Python 2, a :class:`unicode` object) to
a :term:`generator` of Subtitle objects.
This function works around bugs present in many SRT files, most notably
that it is designed to not bork when presented with a blank line as part of
Expand Down
6 changes: 5 additions & 1 deletion srt_tools/srt-fixed-timeshift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ def main():
srt_tools.utils.set_basic_args(args)
corrected_subs = scalar_correct_subs(args.input, args.seconds)
output = srt_tools.utils.compose_suggest_on_fail(corrected_subs, strict=args.strict)
args.output.write(output)

try:
args.output.write(output)
except (UnicodeEncodeError, TypeError): # Python 2 fallback
args.output.write(output.encode(args.encoding))


if __name__ == "__main__": # pragma: no cover
Expand Down
6 changes: 5 additions & 1 deletion srt_tools/srt-linear-timeshift
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,11 @@ def main():
srt_tools.utils.set_basic_args(args)
corrected_subs = linear_correct_subs(args.input, angular, linear)
output = srt_tools.utils.compose_suggest_on_fail(corrected_subs, strict=args.strict)
args.output.write(output)

try:
args.output.write(output)
except (UnicodeEncodeError, TypeError): # Python 2 fallback
args.output.write(output.encode(args.encoding))


if __name__ == "__main__": # pragma: no cover
Expand Down
6 changes: 5 additions & 1 deletion srt_tools/srt-lines-matching
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,11 @@ def main():
output = srt_tools.utils.compose_suggest_on_fail(
matching_subtitles_only, strict=args.strict
)
args.output.write(output)

try:
args.output.write(output)
except (UnicodeEncodeError, TypeError): # Python 2 fallback
args.output.write(output.encode(args.encoding))


if __name__ == "__main__": # pragma: no cover
Expand Down
6 changes: 5 additions & 1 deletion srt_tools/srt-mux
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,11 @@ def main():
merge_subs(muxed_subs, args.ms, "end", args.width)

output = srt_tools.utils.compose_suggest_on_fail(muxed_subs, strict=args.strict)
args.output.write(output)

try:
args.output.write(output)
except (UnicodeEncodeError, TypeError): # Python 2 fallback
args.output.write(output.encode(args.encoding))


if __name__ == "__main__": # pragma: no cover
Expand Down
6 changes: 5 additions & 1 deletion srt_tools/srt-normalise
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ def main():
logging.basicConfig(level=args.log_level)
srt_tools.utils.set_basic_args(args)
output = srt_tools.utils.compose_suggest_on_fail(args.input, strict=args.strict)
args.output.write(output)

try:
args.output.write(output)
except (UnicodeEncodeError, TypeError): # Python 2 fallback
args.output.write(output.encode(args.encoding))


if __name__ == "__main__": # pragma: no cover
Expand Down
5 changes: 4 additions & 1 deletion srt_tools/srt-play
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ def print_sub(sub, encoding):
log.debug("Timer woke up to print %s", sub.content)

with output_lock:
sys.stdout.write(sub.content + "\n\n")
try:
sys.stdout.write(sub.content + "\n\n")
except UnicodeEncodeError: # Python 2 fallback
sys.stdout.write(sub.content.encode(encoding) + "\n\n")
sys.stdout.flush()


Expand Down
6 changes: 5 additions & 1 deletion srt_tools/srt-process
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ def main():
srt_tools.utils.set_basic_args(args)
processed_subs = strip_to_matching_lines_only(args.input, args.module, args.func)
output = srt_tools.utils.compose_suggest_on_fail(processed_subs, strict=args.strict)
args.output.write(output)

try:
args.output.write(output)
except (UnicodeEncodeError, TypeError): # Python 2 fallback
args.output.write(output.encode(args.encoding))


if __name__ == "__main__": # pragma: no cover
Expand Down
6 changes: 5 additions & 1 deletion srt_tools/tests/test_srt_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
import subprocess
import sys
import tempfile
from shlex import quote

try:
from shlex import quote
except ImportError: # <3.3 fallback
from pipes import quote


sample_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), "files")
Expand Down
6 changes: 4 additions & 2 deletions tests/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
pytest==5.*
pytest==4.*; python_version < '3.0'
pytest==5.*; python_version >= '3.0'
pytest-cov==2.*
hypothesis==5.*
hypothesis==4.*; python_version < '3.0'
hypothesis==5.*; python_version >= '3.0'
1 change: 1 addition & 0 deletions tests/test_srt.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env python
# coding=utf8

from __future__ import unicode_literals
from datetime import timedelta
Expand Down
3 changes: 2 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ deps =
commands =
# C0330: https://github.com/psf/black/issues/1178
# R0913: These are intentional design decisions, so leave them.
pylint --disable=C0330,R0913 srt.py
# R0205: We still support py2.
pylint --disable=C0330,R0913,R0205 srt.py

[testenv:black]
skipsdist = True
Expand Down

0 comments on commit 11f06e6

Please sign in to comment.