Skip to content

Commit

Permalink
Merge pull request #388 from vEpiphyte/epiphyte_syntax_080917
Browse files Browse the repository at this point in the history
Fix syntax errors
  • Loading branch information
vEpiphyte authored Aug 9, 2017
2 parents 9736d57 + 136d07d commit b7df2a7
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 53 deletions.
2 changes: 1 addition & 1 deletion synapse/axon.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ def __init__(self, axondir, **opts):

corepath = os.path.join(self.axondir, 'axon.db')
self.core = s_cortex.openurl('sqlite:///%s' % corepath)
self.core.setConfOpt('modules', (('synapse.models.axon.AxonMod', {}),) )
self.core.setConfOpt('modules', (('synapse.models.axon.AxonMod', {}),))

self._fs_mkdir_root() # create the fs root
self.flock = threading.Lock()
Expand Down
4 changes: 2 additions & 2 deletions synapse/lib/storm.py
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ def plan(self, opers):

# specify a limit backward from limit oper...
if oper[0] == 'limit' and retn:
args = oper[1].get('args',())
args = oper[1].get('args', ())
if args:
limt = s_common.intify(args[0])
if limt is not None:
Expand Down Expand Up @@ -990,7 +990,7 @@ def _stormOperLimit(self, query, oper):
raise s_common.BadSyntaxError(mesg='limit(<size>)')

if query.size() > size:
[ query.add(node) for node in query.take()[:size] ]
[query.add(node) for node in query.take()[:size]]

def _stormOperPivot(self, query, oper):
args = oper[1].get('args')
Expand Down
4 changes: 2 additions & 2 deletions synapse/lib/syntax.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,8 +478,8 @@ def parse_oper(text, off=0):

if nextchar(text, off, '='):

vval, off = parse_valu(text, off+1)
inst[1]['kwlist'].append((valu,vval))
vval, off = parse_valu(text, off + 1)
inst[1]['kwlist'].append((valu, vval))

else:

Expand Down
34 changes: 17 additions & 17 deletions synapse/lib/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
logger = logging.getLogger(__name__)

guidre = re.compile('^[0-9a-f]{32}$')

def isguid(text):
return guidre.match(text) is not None

Expand Down Expand Up @@ -188,7 +189,7 @@ def __init__(self, tlib, name, **info):
DataType.__init__(self, tlib, name, **info)

self.fmt = info.get('fmt', '%d')
#self.modval = info.get('mod',None)
# self.modval = info.get('mod',None)
self.minval = info.get('min', None)
self.maxval = info.get('max', None)

Expand Down Expand Up @@ -317,8 +318,8 @@ def _splitpairs(text, sep0, sep1):
Split parts via sep0 and then pairs by sep2
'''
for part in text.split(sep0):
k,v = part.split(sep1)
yield k.strip(),v.strip()
k, v = part.split(sep1)
yield k.strip(), v.strip()

class CompType(DataType):

Expand All @@ -332,16 +333,16 @@ def __init__(self, tlib, name, **info):
if fstr:

if fstr.find('=') != -1:
self.fields.extend( _splitpairs(fstr, ',', '='))
self.fields.extend(_splitpairs(fstr, ',', '='))

else:
self.fields.extend( _splitpairs(fstr, '|', ','))
self.fields.extend(_splitpairs(fstr, '|', ','))

self.fsize = len(self.fields)

ostr = self.info.get('optfields')
if ostr:
self.optfields.extend( _splitpairs(ostr, ',', '='))
self.optfields.extend(_splitpairs(ostr, ',', '='))
# stabilize order to alphabetical since it effects
# the eventual guid generation
self.optfields.sort()
Expand Down Expand Up @@ -371,34 +372,34 @@ def _norm_list(self, valu, oldval=None):
vlen = len(valu)

if vlen < self.fsize:
self._raiseBadValu(valu, mesg='Expected %d fields and got %d' % (self.fsize,len(valu)))
self._raiseBadValu(valu, mesg='Expected %d fields and got %d' % (self.fsize, len(valu)))

for k,v in valu[self.fsize:]:
for k, v in valu[self.fsize:]:
opts[k] = v

vals = valu[:self.fsize]
for v,(name,tname) in s_compat.iterzip(vals,self.fields):
for v, (name, tname) in s_compat.iterzip(vals, self.fields):

norm,ssubs = self.tlib.getTypeNorm(tname,v)
norm, ssubs = self.tlib.getTypeNorm(tname, v)

subs[name] = norm
for subkey,subval in ssubs.items():
for subkey, subval in ssubs.items():
subs[name + ':' + subkey] = subval
retn.append(norm)

for name,tname in self.optfields:
for name, tname in self.optfields:

v = opts.get(name)
if v is None:
continue

norm,ssubs = self.tlib.getTypeNorm(tname,v)
norm, ssubs = self.tlib.getTypeNorm(tname, v)

subs[name] = norm
for subkey,subval in ssubs.items():
for subkey, subval in ssubs.items():
subs[name + ':' + subkey] = subval

retn.append( (name,norm) )
retn.append((name, norm))

return s_common.guid(retn), subs

Expand Down Expand Up @@ -562,7 +563,6 @@ def _zipvals(self, vals):
return s_compat.iterzip(vals, self._get_fields())

class BoolType(DataType):

def norm(self, valu, oldval=None):
if s_compat.isstr(valu):
valu = valu.lower()
Expand All @@ -580,6 +580,7 @@ def repr(self, valu):
return repr(bool(valu))

tagre = re.compile(r'^([\w]+\.)*[\w]+$')

class TagType(DataType):

def norm(self, valu, oldval=None):
Expand All @@ -589,7 +590,6 @@ def norm(self, valu, oldval=None):
subs = {}

if len(parts) == 2:

strs = parts[1].split('-')
tims = [self.tlib.getTypeNorm('time', s)[0] for s in strs]

Expand Down
6 changes: 3 additions & 3 deletions synapse/tests/test_lib_storm.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,13 @@ def test_storm_limit(self):
# test that the limit operator correctly handles being first (no opers[-1])
# and will subsequently filter down to the correct number of nodes
nodes = core.eval('[ inet:ipv4=1.2.3.4 inet:ipv4=3.4.5.6 ]')
self.eq(len(core.eval(' limit(1) ', data=nodes)), 1 )
self.eq(len(core.eval(' limit(1) ', data=nodes)), 1)

# test that the limit() operator reaches backward to limit a previous oper
# during the planning pass...
oper = core.plan( core.parse(' inet:ipv4 limit(1) ') )[0]
oper = core.plan(core.parse(' inet:ipv4 limit(1) '))[0]
opts = dict(oper[1].get('kwlist'))
self.eq(opts.get('limit'), 1 )
self.eq(opts.get('limit'), 1)

self.raises(BadSyntaxError, core.eval, 'inet:ipv4 limit()')
self.raises(BadSyntaxError, core.eval, 'inet:ipv4 limit(nodes=10)')
Expand Down
5 changes: 2 additions & 3 deletions synapse/tests/test_syntax.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,10 @@ def test_storm_syntax_oper_args(self):
args = oper[1].get('args')
opts = dict(oper[1].get('kwlist'))

self.eq(args[0], [1,2])
self.eq(args[0], [1, 2])
self.eq(args[1], 'lol')
self.eq(args[2], 'hehe haha')

self.eq(opts.get('one'), [3,4])
self.eq(opts.get('one'), [3, 4])
self.eq(opts.get('two'), 5)
self.eq(opts.get('three'), 'whee')

49 changes: 24 additions & 25 deletions synapse/tests/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,33 +507,32 @@ def test_types_comp_optfields(self):

tlib.addType('foo:bar', subof='comp', fields='foo=str,bar=int', optfields='baz=str,faz=int')

subs = (('bar',20),('baz','asdf'),('faz',30),('foo','qwer'))
subs = (('bar', 20), ('baz', 'asdf'), ('faz', 30), ('foo', 'qwer'))

v0,s0 = tlib.getTypeNorm('foo:bar', ('qwer',20,('baz','asdf'),('faz',30)))
v1,s1 = tlib.getTypeNorm('foo:bar', ('qwer',20,('faz',30),('baz','asdf')))
v2,s2 = tlib.getTypeNorm('foo:bar', '(qwer,20,baz=asdf,faz=30)')
v3,s3 = tlib.getTypeNorm('foo:bar', '(qwer,20,faz=30,baz=asdf)')
v0, s0 = tlib.getTypeNorm('foo:bar', ('qwer', 20, ('baz', 'asdf'), ('faz', 30)))
v1, s1 = tlib.getTypeNorm('foo:bar', ('qwer', 20, ('faz', 30), ('baz', 'asdf')))
v2, s2 = tlib.getTypeNorm('foo:bar', '(qwer,20,baz=asdf,faz=30)')
v3, s3 = tlib.getTypeNorm('foo:bar', '(qwer,20,faz=30,baz=asdf)')

self.eq(v0,v1)
self.eq(v1,v2)
self.eq(v2,v3)
self.eq(v0, v1)
self.eq(v1, v2)
self.eq(v2, v3)

self.eq(subs, tuple(sorted(s0.items())))
self.eq(subs, tuple(sorted(s1.items())))
self.eq(subs, tuple(sorted(s2.items())))
self.eq(subs, tuple(sorted(s3.items())))

subs = (('bar', 20), ('baz', 'asdf'), ('foo', 'qwer'))

subs = (('bar',20),('baz','asdf'),('foo','qwer'))
v0, s0 = tlib.getTypeNorm('foo:bar', ('qwer', 20, ('baz', 'asdf')))
v1, s1 = tlib.getTypeNorm('foo:bar', ('qwer', 20, ('baz', 'asdf')))
v2, s2 = tlib.getTypeNorm('foo:bar', '(qwer,20,baz=asdf)')
v3, s3 = tlib.getTypeNorm('foo:bar', '(qwer,20,baz=asdf)')

v0,s0 = tlib.getTypeNorm('foo:bar', ('qwer',20,('baz','asdf')))
v1,s1 = tlib.getTypeNorm('foo:bar', ('qwer',20,('baz','asdf')))
v2,s2 = tlib.getTypeNorm('foo:bar', '(qwer,20,baz=asdf)')
v3,s3 = tlib.getTypeNorm('foo:bar', '(qwer,20,baz=asdf)')

self.eq(v0,v1)
self.eq(v1,v2)
self.eq(v2,v3)
self.eq(v0, v1)
self.eq(v1, v2)
self.eq(v2, v3)

self.eq(subs, tuple(sorted(s0.items())))
self.eq(subs, tuple(sorted(s1.items())))
Expand All @@ -546,16 +545,16 @@ def test_types_comp_opt_only(self):

tlib.addType('foo:bar', subof='comp', optfields='baz=str,faz=int')

subs = (('baz','asdf'),('faz',30))
subs = (('baz', 'asdf'), ('faz', 30))

v0,s0 = tlib.getTypeNorm('foo:bar', (('baz','asdf'),('faz',30)))
v1,s1 = tlib.getTypeNorm('foo:bar', (('faz',30),('baz','asdf')))
v2,s2 = tlib.getTypeNorm('foo:bar', '(baz=asdf,faz=30)')
v3,s3 = tlib.getTypeNorm('foo:bar', '(faz=30,baz=asdf)')
v0, s0 = tlib.getTypeNorm('foo:bar', (('baz', 'asdf'), ('faz', 30)))
v1, s1 = tlib.getTypeNorm('foo:bar', (('faz', 30), ('baz', 'asdf')))
v2, s2 = tlib.getTypeNorm('foo:bar', '(baz=asdf,faz=30)')
v3, s3 = tlib.getTypeNorm('foo:bar', '(faz=30,baz=asdf)')

self.eq(v0,v1)
self.eq(v1,v2)
self.eq(v2,v3)
self.eq(v0, v1)
self.eq(v1, v2)
self.eq(v2, v3)

self.eq(subs, tuple(sorted(s0.items())))
self.eq(subs, tuple(sorted(s1.items())))
Expand Down

0 comments on commit b7df2a7

Please sign in to comment.