text
stringlengths
0
828
params['srvname'] = service_name
if protocol is not None:
params['protocol'] = protocol
if weight is not None:
params['weight'] = weight
if port is not None:
params['port'] = port
if target is not None:
params['target'] = target
return self._request(params)"
3694,"def calc_transition_to_state(self, newstate):
""""""Given a target state, generate the sequence of transitions that would move this state machine instance to that target state.
Args:
newstate: A str state name to calculate the path to.
Returns:
A bitarray containing the bits that would transition this
state machine to the target state. The bits read from right
to left. For efficiency, this retulting bitarray is cached.
Do not edit this bitarray, or it will cause undefined
behavior.
""""""
cached_val = JTAGStateMachine._lookup_cache.\
get((self.state, newstate))
if cached_val:
return cached_val
if newstate not in self.states:
raise ValueError(""%s is not a valid state for this state ""
""machine""%newstate)
path = self._find_shortest_path(self._statestr, newstate)
if not path:
raise ValueError(""No path to the requested state."")
res = self._get_steps_from_nodes_path(path)
res.reverse()
JTAGStateMachine._lookup_cache[(self.state, newstate)] = res
return res"
3695,"def prompt(self, error=''):
""""""
Prompts the user to set the value for this item.
:return <bool> | success
""""""
if self.hidden:
return True
cmd = [self.label]
if self.default is not None:
cmd.append('(default: {0})'.format(self.default))
elif not self.required:
cmd.append('(default: )')
if self.type == 'bool':
cmd.append('(y/n)')
if self.choices:
print 'Choices:'
for choice in self.choices:
print choice
if error:
print error
value = raw_input(' '.join(cmd) + ':')
if value == '':
value = self.default
if self.type == 'bool':
if value == 'y':
value = True
elif value == 'n':
value = False
else:
value = self.default
if value is None and self.required:
return self.prompt('{0} is required.')
if self.regex and not re.match(self.regex, value):
error = '{0} must match {1}'.format(self.name, self.regex)
return self.prompt(error)
self.value = value
return True"
3696,"def build(self, outpath, structure=None):
""""""
Builds this scaffold out to the given filepath with the
chosen structure.
:param outpath | <str>
structure | <xml.etree.ElementTree.Element> || None
:return <bool> | success
""""""
if not os.path.exists(outpath):
return False
opts = {'scaffold': self}