text
stringlengths
0
828
allIn = True
# check if all symbols on the right part of rule are in generates set
for symbol in rightPart:
if symbol not in generates:
allIn = False
break
# Symbol is missing so rule is not process
if not allIn:
continue
# Rule is process - remove it from processing rules and make symbol as generating
additional.add(rule.fromSymbol)
rules.remove(rule)
# end of rules iterations
# ff current and previous iterations are same, than end iterations
if additional == generates:
break
# swap sets from previous and current iterations
generates = additional
# remove nonterms that are not generating
nongenerating = grammar.nonterminals.difference(generates)
grammar.nonterminals.remove(*nongenerating)
# return the grammar
return grammar"
4182,"def skip_first(pipe, items=1):
''' this is an alias for skip to parallel the dedicated skip_last function
to provide a little more readability to the code. the action of actually
skipping does not occur until the first iteration is done
'''
pipe = iter(pipe)
for i in skip(pipe, items):
yield i"
4183,"def find(self, query=None, **kwargs):
""""""
You can pass in the appropriate model object from the queries module,
or a dictionary with the keys and values for the query,
or a set of key=value parameters.
""""""
url = self.getUrl()
if query is not None:
if isinstance(query, queries.SlickQuery):
url = url + ""?"" + urlencode(query.to_dict())
elif isinstance(query, dict):
url = url + ""?"" + urlencode(query)
elif len(kwargs) > 0:
url = url + ""?"" + urlencode(kwargs)
# hopefully when we discover what problems exist in slick to require this, we can take the loop out
for retry in range(3):
try:
self.logger.debug(""Making request to slick at url %s"", url)
r = requests.get(url)
self.logger.debug(""Request returned status code %d"", r.status_code)
if r.status_code is 200:
retval = []
objects = r.json()
for dct in objects:
retval.append(self.model.from_dict(dct))
return retval
else:
self.logger.error(""Slick returned an error when trying to access %s: status code %s"" % (url, str(r.status_code)))
self.logger.error(""Slick response: "", pprint.pformat(r))
except BaseException as error:
self.logger.warn(""Received exception while connecting to slick at %s"", url, exc_info=sys.exc_info())
raise SlickCommunicationError(
""Tried 3 times to request data from slick at url %s without a successful status code."", url)"
4184,"def findOne(self, query=None, mode=FindOneMode.FIRST, **kwargs):
""""""
Perform a find, with the same options present, but only return a maximum of one result. If find returns
an empty array, then None is returned.
If there are multiple results from find, the one returned depends on the mode parameter. If mode is
FindOneMode.FIRST, then the first result is returned. If the mode is FindOneMode.LAST, then the last is
returned. If the mode is FindOneMode.ERROR, then a SlickCommunicationError is raised.
""""""
results = self.find(query, **kwargs)
if len(results) is 0:
return None
elif len(results) is 1 or mode == FindOneMode.FIRST:
return results[0]
elif mode == FindOneMode.LAST:
return results[-1]"
4185,"def get(self):
""""""Get the specified object from slick. You specify which one you want by providing the id as a parameter to
the parent object. Example:
slick.projects(""4fd8cd95e4b0ee7ba54b9885"").get()
""""""
url = self.getUrl()
# hopefully when we discover what problems exist in slick to require this, we can take the loop out
for retry in range(3):
try:
self.logger.debug(""Making request to slick at url %s"", url)
r = requests.get(url)
self.logger.debug(""Request returned status code %d"", r.status_code)
if r.status_code is 200:
return self.model.from_dict(r.json())
else:
self.logger.debug(""Body of what slick returned: %s"", r.text)
except BaseException as error: