Skip to content

Commit

Permalink
Align with upstream (#6)
Browse files Browse the repository at this point in the history
* ignore pycharm files

* run tests on 3.7 to 3.10, use new circleci images

* try installing libxml deps and setting compiler flags

don't install deps already preset, bump lxml instead

downgrade lxml

* delete travis.yml

* delete tox.ini

* run tests with pytest instead

* add lintlizard step

* run lintlizard --fix (black + isort)

* remove basestring reference

* add annotation for COMPILED_PATTERNS

* ignore line length linter error

* import stuff explicilty when testing

* fix imports

* fix bad escapes for regex string

* remove (object) inheritance

* C416 swap useless list comprehensions for list

* E711 comparison to None

* SFS101 string literal formatting

* fix docstring imperative mood and spacing

* SIM102 flatten needlessly nested if statements

* remove enumerate where the index is never used

* D301 use r""" if there's any backslashes in the docstring

* replace bytestring formatting with no formatting. bytes arent strings, so they can just be dirty then

* remove unused variable

* SIM104 use yield from instead

* drop python 2 tags in setup.py

* add dependabot config

* Fix isort config

* Bump pytest from 7.1.1 to 7.1.2 (#33)

* Bump lxml from 4.6.5 to 4.9.1

Bumps [lxml](https://github.com/lxml/lxml) from 4.6.5 to 4.9.1.
- [Release notes](https://github.com/lxml/lxml/releases)
- [Changelog](https://github.com/lxml/lxml/blob/master/CHANGES.txt)
- [Commits](lxml/lxml@lxml-4.6.5...lxml-4.9.1)

---
updated-dependencies:
- dependency-name: lxml
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <[email protected]>

* Build against system libxml2

* Bump pytest from 7.1.2 to 7.1.3 (#37)

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: Alec Rosenbaum <[email protected]>
Co-authored-by: Vyacheslav Tverskoy <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Vyacheslav Tverskoy <[email protected]>
Co-authored-by: V <[email protected]>
  • Loading branch information
6 people authored Jul 4, 2023
1 parent c2d71fa commit 6044dde
Show file tree
Hide file tree
Showing 14 changed files with 1,249 additions and 810 deletions.
41 changes: 32 additions & 9 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,49 @@ workflows:
version: 2
workflow:
jobs:
- test-2.7
- test-3.5
- test-3.7
- test-3.8
- test-3.9
- test-3.10
- static-code-analysis

defaults: &defaults
working_directory: ~/code
steps:
- checkout
- run:
name: Install dependencies
command: sudo pip install -r requirements_tests.txt
name: Install Python dependencies
command: CFLAGS="-O0" pip install -r requirements_tests.txt
- run:
name: Test
command: python setup.py test
command: pytest

jobs:
test-2.7:
test-3.7:
<<: *defaults
docker:
- image: circleci/python:2.7
test-3.5:
- image: cimg/python:3.7
test-3.8:
<<: *defaults
docker:
- image: circleci/python:3.5
- image: cimg/python:3.8
test-3.9:
<<: *defaults
docker:
- image: cimg/python:3.9
test-3.10:
<<: *defaults
docker:
- image: cimg/python:3.10
static-code-analysis:
working_directory: ~/code
docker:
- image: cimg/python:3.8
steps:
- checkout
- run:
name: Install dependencies
command: pip install lintlizard==0.18.0 "click<8.1"
- run:
name: LintLizard
command: lintlizard
13 changes: 13 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Docs: https://help.github.com/en/github/administering-a-repository/configuration-options-for-dependency-updates

version: 2
updates:
# Enable version updates for python
- package-ecosystem: "pip"
schedule:
interval: "daily"
open-pull-requests-limit: 8 # note that this is _per-file_
directory: "/"
pull-request-branch-name:
# so it's compatible with docker tags
separator: "-"
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,6 @@ pip-log.txt

#Mr Developer
.mr.developer.cfg

# pycharm
.idea
7 changes: 0 additions & 7 deletions .travis.yml

This file was deleted.

10 changes: 10 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[tool.black]
target-version = ['py37']
exclude = '''
/(
\.git
| \.venv
| venv
| src
)/
'''
84 changes: 46 additions & 38 deletions quotequail/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@
# quotequail
# a library that identifies quoted text in email messages

import re
from . import _internal, _patterns

from . import _internal

__all__ = ['quote', 'quote_html', 'unwrap', 'unwrap_html']
__all__ = ["quote", "quote_html", "unwrap", "unwrap_html"]


def quote(text, limit=1000):
"""
Takes a plain text message as an argument, returns a list of tuples. The
Take a plain text message as an argument, return a list of tuples. The
first argument of the tuple denotes whether the text should be expanded by
default. The second argument is the unmodified corresponding text.
Expand All @@ -20,16 +18,19 @@ def quote(text, limit=1000):
Unless the limit param is set to None, the text will automatically be quoted
starting at the line where the limit is reached.
"""

lines = text.split('\n')
lines = text.split("\n")

found = _internal.find_quote_position(lines, _patterns.MAX_WRAP_LINES, limit)

if found != None:
return [(True, '\n'.join(lines[:found+1])), (False, '\n'.join(lines[found+1:]))]
if found is not None:
return [
(True, "\n".join(lines[: found + 1])),
(False, "\n".join(lines[found + 1 :])),
]

return [(True, text)]


def quote_html(html, limit=1000):
"""
Like quote(), but takes an HTML message as an argument. The limit param
Expand All @@ -40,24 +41,25 @@ def quote_html(html, limit=1000):

tree = _html.get_html_tree(html)

start_refs, end_refs, lines = _html.get_line_info(tree, limit+1)
start_refs, end_refs, lines = _html.get_line_info(tree, limit + 1)

found = _internal.find_quote_position(lines, 1, limit)

if found == None:
if found is None:
# No quoting found and we're below limit. We're done.
return [(True, _html.render_html_tree(tree))]
else:
start_tree = _html.slice_tree(tree, start_refs, end_refs,
(0, found+1), html_copy=html)
end_tree = _html.slice_tree(tree, start_refs, end_refs,
(found+1, None))
start_tree = _html.slice_tree(
tree, start_refs, end_refs, (0, found + 1), html_copy=html
)
end_tree = _html.slice_tree(tree, start_refs, end_refs, (found + 1, None))

return [
(True, _html.render_html_tree(start_tree)),
(False, _html.render_html_tree(end_tree)),
]


def unwrap(text):
"""
If the passed text is the text body of a forwarded message, a reply, or
Expand All @@ -72,41 +74,45 @@ def unwrap(text):
Otherwise, this function returns None.
"""

lines = text.split('\n')

result = _internal.unwrap(lines, _patterns.MAX_WRAP_LINES,
_patterns.MIN_HEADER_LINES,_patterns.MIN_QUOTED_LINES)
lines = text.split("\n")

result = _internal.unwrap(
lines,
_patterns.MAX_WRAP_LINES,
_patterns.MIN_HEADER_LINES,
_patterns.MIN_QUOTED_LINES,
)
if result:
typ, top_range, hdrs, main_range, bottom_range, needs_unindent = result

text_top = lines[slice(*top_range)] if top_range else ''
text = lines[slice(*main_range)] if main_range else ''
text_bottom = lines[slice(*bottom_range)] if bottom_range else ''
text_top = lines[slice(*top_range)] if top_range else ""
text = lines[slice(*main_range)] if main_range else ""
text_bottom = lines[slice(*bottom_range)] if bottom_range else ""

if needs_unindent:
text = _internal.unindent_lines(text)

result = {
'type': typ,
"type": typ,
}

text = '\n'.join(text).strip()
text_top = '\n'.join(text_top).strip()
text_bottom = '\n'.join(text_bottom).strip()
text = "\n".join(text).strip()
text_top = "\n".join(text_top).strip()
text_bottom = "\n".join(text_bottom).strip()

if text:
result['text'] = text
result["text"] = text
if text_top:
result['text_top'] = text_top
result["text_top"] = text_top
if text_bottom:
result['text_bottom'] = text_bottom
result["text_bottom"] = text_bottom

if hdrs:
result.update(hdrs)

return result


def unwrap_html(html):
"""
If the passed HTML is the HTML body of a forwarded message, a dictionary
Expand All @@ -133,34 +139,36 @@ def unwrap_html(html):
typ, top_range, hdrs, main_range, bottom_range, needs_unindent = result

result = {
'type': typ,
"type": typ,
}

top_range = _html.trim_slice(lines, top_range)
main_range = _html.trim_slice(lines, main_range)
bottom_range = _html.trim_slice(lines, bottom_range)

if top_range:
top_tree = _html.slice_tree(tree, start_refs, end_refs, top_range,
html_copy=html)
top_tree = _html.slice_tree(
tree, start_refs, end_refs, top_range, html_copy=html
)
html_top = _html.render_html_tree(top_tree)
if html_top:
result['html_top'] = html_top
result["html_top"] = html_top

if bottom_range:
bottom_tree = _html.slice_tree(tree, start_refs, end_refs,
bottom_range, html_copy=html)
bottom_tree = _html.slice_tree(
tree, start_refs, end_refs, bottom_range, html_copy=html
)
html_bottom = _html.render_html_tree(bottom_tree)
if html_bottom:
result['html_bottom'] = html_bottom
result["html_bottom"] = html_bottom

if main_range:
main_tree = _html.slice_tree(tree, start_refs, end_refs, main_range)
if needs_unindent:
_html.unindent_tree(main_tree)
html = _html.render_html_tree(main_tree)
if html:
result['html'] = html
result["html"] = html

if hdrs:
result.update(hdrs)
Expand Down
Loading

0 comments on commit 6044dde

Please sign in to comment.