Skip to content

Commit dca3922

Browse files
Merge pull request #1 from thperret/python3
add python3 support
2 parents cb2656a + 3b78c39 commit dca3922

15 files changed

Lines changed: 65 additions & 23 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
parser.out
66
parsetab.py
77
*.pyc
8+
*.egg-info/

setup.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,13 @@
1414
license = "BSD",
1515
description = "Parser/evaluator for the Sieve filtering language (RFC 5228)",
1616
long_description = long_description,
17+
install_requires=[
18+
"ply",
19+
],
1720
classifiers = [
1821
"Programming Language :: Python",
1922
"Programming Language :: Python :: 2",
23+
"Programming Language :: Python :: 3",
2024
"License :: OSI Approved :: BSD License",
2125
"Development Status :: 4 - Beta",
2226
"Intended Audience :: Developers",

sifter/comparators/ascii_casemap.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
import string
2+
try:
3+
# Python 3
4+
maketrans = str.maketrans
5+
except AttributeError:
6+
# Python 2
7+
maketrans = string.maketrans
28

39
from sifter.comparators.octet import ComparatorOctet
410

@@ -10,7 +16,6 @@ class ComparatorASCIICasemap(ComparatorOctet):
1016

1117
@classmethod
1218
def sort_key(cls, s):
13-
return s.translate(string.maketrans(string.ascii_lowercase,
14-
string.ascii_uppercase))
19+
return s.upper()
1520

1621
ComparatorASCIICasemap.register()

sifter/extensions/builtin.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
import sifter.comparators.octet
2121

2222
import sifter.extension
23-
map(sifter.extension.register,
23+
list(map(sifter.extension.register,
2424
('fileinto',
2525
'comparator-i;ascii-casemap',
2626
'comparator-i;octet',
27-
))
27+
)))

sifter/grammar/command.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import sifter.grammar
2-
import rule
2+
from . import rule
33
import sifter.utils
44

55
__all__ = ('Command',)

sifter/grammar/command_list.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,7 @@ def evaluate(self, message, state=None):
2222
# isn't required by the standard, but we might as well.
2323
if len(state.actions) > 0 and state.actions[-1][0] == 'stop':
2424
break
25+
if state.actions.implicit_keep:
26+
state.actions.append('keep')
2527
return state.actions
2628

sifter/grammar/lexer.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ def t_newline(t):
9393
r'(\r\n)+'
9494
t.lexer.lineno += t.value.count('\n')
9595

96+
def t_error(t):
97+
t.lexer.skip(1)
98+
9699

97100
if __name__ == '__main__':
98101
# PLY has a simple debugging mode that'll print out tokens for input coming

sifter/grammar/rule.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ def validate_arguments(self, tagged_args=None, positional_args=None):
5151
if not isinstance(self.arguments[i], sifter.grammar.Tag):
5252
break
5353
num_valid_args = 0
54-
for arg_name, arg_validator in tagged_args.iteritems():
54+
for arg_name, arg_validator in tagged_args.items():
5555
num_valid_args = arg_validator.validate(self.arguments, i)
56-
if num_valid_args > 0:
56+
if num_valid_args is not None and num_valid_args > 0:
5757
if arg_name in seen_args:
5858
raise RuleSyntaxError(
5959
"%s argument to %s was already seen earlier: %s"

sifter/grammar/test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import rule
1+
from . import rule
22

33
__all__ = ('Test',)
44

sifter/t/evaluation_3.msg

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Date: Tue, 1 Apr 1997 09:06:31 -0800 (PST)
2+
From: user1@example.org
3+
To: roadrunner@acme.example.com
4+
Subject: I have a present for you
5+
6+
Look, I'm sorry about the whole anvil thing, and I really
7+
didn't mean to try and drop it on you from the top of the
8+
cliff. I want to try to make it up to you. I've got some
9+
great birdseed over here at my place--top of the line
10+
stuff--and if you come by, I'll have it all wrapped up
11+
for you. I'm really sorry for all the problems I've caused
12+
for you over the years, but I know we can work this out.
13+
--
14+
Wile E. Coyote "Super Genius" coyote@desert.example.org

0 commit comments

Comments
 (0)