Skip to content

Commit 09d286e

Browse files
committed
Add hash method to all formula, use unicode more through the system, add framework for adding more parsers
1 parent c554763 commit 09d286e

23 files changed

+368
-352
lines changed

Diff for: .coveragerc

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ omit =
77
*/site-packages/nose/*
88
*/unittest2/*
99

10-
#exclude_lines =
11-
# Have to re-enable the standard pragma
12-
# pragma: no cover
10+
[report]
11+
exclude_lines =
12+
if __name__ == .__main__.:

Diff for: .gitignore

+1-157
Original file line numberDiff line numberDiff line change
@@ -1,161 +1,5 @@
1-
# Created by .ignore support plugin (hsz.mobi)
2-
### github template
3-
#==================
4-
# OS X #
5-
#==================
61
.DS_Store
7-
.AppleDouble
8-
.LSOverride
9-
10-
# Icon must end with two \r
11-
Icon
12-
13-
# Thumbnails
14-
._*
15-
16-
# Files that might appear on external disk
17-
.Spotlight-V100
18-
.Trashes
19-
20-
# Directories potentially created on remote AFP share
21-
.AppleDB
22-
.AppleDesktop
23-
Network Trash Folder
24-
Temporary Items
25-
.apdisk
26-
27-
#==================
28-
# WINDOWS #
29-
#==================
30-
31-
# Windows image file caches
32-
Thumbs.db
33-
ehthumbs.db
34-
35-
# Folder config file
36-
Desktop.ini
37-
38-
# Recycle Bin used on file shares
39-
$RECYCLE.BIN/
40-
41-
# Windows Installer files
42-
*.cab
43-
*.msi
44-
*.msm
45-
*.msp
46-
47-
# Windows shortcuts
48-
*.lnk
49-
50-
#==================
51-
# JETBRAINS #
52-
#==================
53-
54-
# Directory-based project format:
552
.idea/
56-
57-
# File-based project format:
58-
*.ipr
59-
*.iws
60-
61-
# Plugin-specific files:
62-
# IntelliJ
63-
out/
64-
65-
# mpeltonen/sbt-idea plugin
66-
.idea_modules/
67-
68-
# JIRA plugin
69-
atlassian-ide-plugin.xml
70-
71-
# Crashlytics plugin (for Android Studio and IntelliJ)
72-
com_crashlytics_export_strings.xml
73-
crashlytics.properties
74-
crashlytics-build.properties
75-
76-
#==================
77-
# SUBLIME TEXT #
78-
#==================
79-
80-
# cache files for sublime text
81-
*.tmlanguage.cache
82-
*.tmPreferences.cache
83-
*.stTheme.cache
84-
85-
# workspace files are user-specific
86-
*.sublime-workspace
87-
88-
# project files should be checked into the repository, unless a significant
89-
# proportion of contributors will probably not be using SublimeText
90-
*.sublime-project
91-
92-
# sftp configuration file
93-
sftp-config.json
94-
95-
#==================
96-
# Miscellaneous #
97-
#==================
98-
99-
*.zip
100-
*.swp
101-
102-
#==================
103-
# Python #
104-
#==================
105-
# Byte-compiled / optimized / DLL files
1063
__pycache__/
1074
*.py[cod]
108-
109-
# C extensions
110-
*.so
111-
112-
# Distribution / packaging
113-
.Python
114-
env/
115-
build/
116-
develop-eggs/
117-
dist/
118-
downloads/
119-
eggs/
120-
.eggs/
121-
lib/
122-
lib64/
123-
parts/
124-
sdist/
125-
var/
126-
*.egg-info/
127-
.installed.cfg
128-
*.egg
129-
130-
# PyInstaller
131-
# Usually these files are written by a python script from a template
132-
# before PyInstaller builds the exe, so as to inject date/other infos into it.
133-
*.manifest
134-
*.spec
135-
136-
# Installer logs
137-
pip-log.txt
138-
pip-delete-this-directory.txt
139-
140-
# Unit test / coverage reports
141-
htmlcov/
142-
.tox/
143-
.coverage
144-
.coverage.*
145-
.cache
146-
nosetests.xml
147-
coverage.xml
148-
*,cover
149-
150-
# Translations
151-
*.mo
152-
*.pot
153-
154-
# Django stuff:
155-
*.log
156-
157-
# Sphinx documentation
158-
docs/_build/
159-
160-
# PyBuilder
161-
target/
5+
.coverage

Diff for: forseti/formula.py

+35-15
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
Predicate for use within Forseti
44
"""
55
# pylint: disable=too-few-public-methods,missing-docstring
6+
from __future__ import unicode_literals
7+
from six import string_types
68

79

810
class Formula(object):
@@ -12,28 +14,31 @@ def __init__(self):
1214
pass
1315

1416
def __repr__(self):
15-
raise NotImplementedError("Not implemented yet")
17+
raise NotImplementedError("Not implemented")
1618

1719
def __str__(self):
18-
raise NotImplementedError("Not implemented yet")
20+
raise NotImplementedError("Not implemented")
1921

2022
def __eq__(self, other):
21-
raise NotImplementedError("Not implemented yet")
23+
raise NotImplementedError("Not implemented")
2224

2325
def __ne__(self, other):
24-
raise NotImplementedError("Not implemented yet")
26+
raise NotImplementedError("Not implemented")
2527

2628
def __lt__(self, other):
27-
raise NotImplementedError("Not implemented yet")
29+
raise NotImplementedError("Not implemented")
2830

2931
def __le__(self, other):
30-
raise NotImplementedError("Not implemented yet")
32+
raise NotImplementedError("Not implemented")
3133

3234
def __gt__(self, other):
33-
raise NotImplementedError("Not implemented yet")
35+
raise NotImplementedError("Not implemented")
3436

3537
def __ge__(self, other):
36-
raise NotImplementedError("Not implemented yet")
38+
raise NotImplementedError("Not implemented")
39+
40+
def __hash__(self):
41+
raise NotImplementedError("Not implemented")
3742

3843

3944
class Symbol(Formula):
@@ -44,8 +49,8 @@ class Symbol(Formula):
4449
arity = 0
4550

4651
def __init__(self, arg):
47-
if not isinstance(arg, str):
48-
raise TypeError(str(arg) + " is not a string")
52+
if not isinstance(arg, string_types):
53+
raise TypeError(str(arg) + " is not a string type")
4954
super(Symbol, self).__init__()
5055
self.arg = arg
5156
self. args = [arg]
@@ -89,6 +94,9 @@ def __gt__(self, other):
8994
def __ge__(self, other):
9095
return other < self or other == self
9196

97+
def __hash__(self):
98+
return hash(repr(self))
99+
92100

93101
class LogicalOperator(Formula):
94102
"""
@@ -119,10 +127,10 @@ def __repr__(self):
119127
120128
:return: __repr__()
121129
"""
122-
raise NotImplementedError("Not implemented yet")
130+
raise NotImplementedError("Not implemented")
123131

124132
def __str__(self):
125-
raise NotImplementedError("Not implemented yet")
133+
raise NotImplementedError("Not implemented")
126134

127135
def __eq__(self, other):
128136
if isinstance(self, type(other)):
@@ -156,6 +164,9 @@ def __gt__(self, other):
156164
def __ge__(self, other):
157165
return other < self or other == self
158166

167+
def __hash__(self):
168+
return hash(repr(self))
169+
159170

160171
class Not(LogicalOperator):
161172
"""
@@ -319,18 +330,18 @@ def __init__(self, arg1, arg2):
319330
super(Quantifier, self).__init__()
320331
if isinstance(arg1, Symbol):
321332
self.symbol = arg1.arg
322-
elif isinstance(arg1, str):
333+
elif isinstance(arg1, string_types):
323334
self.symbol = arg1
324335
else:
325336
raise Exception
326337

327338
self.args = [arg2]
328339

329340
def __repr__(self):
330-
raise NotImplementedError("Not implemented yet")
341+
raise NotImplementedError("Not implemented")
331342

332343
def __str__(self):
333-
raise NotImplementedError("Not implemented yet")
344+
raise NotImplementedError("Not implemented")
334345

335346
def __eq__(self, other):
336347
if isinstance(self, type(other)):
@@ -345,6 +356,9 @@ def __lt__(self, other):
345356
if not isinstance(other, Quantifier):
346357
return False
347358

359+
def __hash__(self):
360+
return hash(repr(self))
361+
348362

349363
class Universal(Quantifier):
350364
"""
@@ -401,6 +415,9 @@ def __eq__(self, other):
401415
def __ne__(self, other):
402416
return not self == other
403417

418+
def __hash__(self):
419+
return hash(repr(self))
420+
404421
@staticmethod
405422
def reset():
406423
Skolem.count = 1
@@ -430,6 +447,9 @@ def __eq__(self, other):
430447
def __ne__(self, other):
431448
return not self == other
432449

450+
def __hash__(self):
451+
return hash(repr(self))
452+
433453
@staticmethod
434454
def reset():
435455
Herbrand.count = 1

0 commit comments

Comments
 (0)