Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def main():
"""The main entry point for igraph when invoked from the command
line shell"""
config = Configuration.instance()
if config.filename:
print >> sys.stderr, "Using configuration from %s" % config.filename
else:
print >> sys.stderr, "No configuration file, using defaults"
if config.has_key("shells"):
parts = [part.strip() for part in config["shells"].split(",")]
shell_classes = []
available_classes = dict([(k, v) for k, v in globals().iteritems() \
if isinstance(v, type) and issubclass(v, Shell)])
for part in parts:
klass = available_classes.get(part, None)
if klass is None:
print >> sys.stderr, "Warning: unknown shell class `%s'" % part
continue
def main():
"""The main entry point for igraph when invoked from the command
line shell"""
config = Configuration.instance()
if config.filename:
print("Using configuration from %s" % config.filename, file=sys.stderr)
else:
print("No configuration file, using defaults", file=sys.stderr)
if config.has_key("shells"):
parts = [part.strip() for part in config["shells"].split(",")]
shell_classes = []
available_classes = dict([(k, v) for k, v in globals().iteritems()
if isinstance(v, type) and issubclass(v, Shell)])
for part in parts:
klass = available_classes.get(part, None)
if klass is None:
print("Warning: unknown shell class `%s'" % part, file=sys.stderr)
continue
# Special case if the attribute name is "label"
if attr_spec.name == "label":
if attr_spec.alt_name in kwds and kwds[attr_spec.alt_name] is None:
return [None] * n
# If the attribute uses an external callable to derive the attribute
# values, call it and store the results
if attr_spec.func is not None:
func = attr_spec.func
result = [func(i) for i in xrange(n)]
return result
# Get the configuration object
if config is None:
config = Configuration.instance()
# Fetch the defaults from the vertex/edge sequence
try:
attrs = seq[attr_spec.name]
except KeyError:
attrs = None
# Override them from the keyword arguments (if any)
result = kwds.get(attr_spec.alt_name, None)
if attrs:
if not result:
result = attrs
else:
if isinstance(result, str):
result = [result] * n
try:
for i in vertex_order)
# Draw the vertices
drawer_method = vertex_drawer.draw
context.set_line_width(1)
for vertex, visual_vertex, coords in vertex_coord_iter:
drawer_method(visual_vertex, vertex, coords)
# Set the font we will use to draw the labels
vertex_label_family = 'sans-serif' if not hasattr(graph, "vertex_label_family") \
else graph.vertex_label_family
# Decide whether the labels have to be wrapped
wrap = kwds.get("wrap_labels")
if wrap is None:
wrap = Configuration.instance()["plotting.wrap_labels"]
wrap = bool(wrap)
# Construct the iterator that we will use to draw the vertex labels
if vertex_order is None:
# Default vertex order
vertex_coord_iter = izip(vertex_builder, layout)
else:
# Specified vertex order
vertex_coord_iter = ((vertex_builder[i], layout[i])
for i in vertex_order)
# Draw the vertex labels
for vertex, coords in vertex_coord_iter:
if vertex.label is None:
continue
def show(self):
"""Saves the plot to a temporary file and shows it."""
if not isinstance(self._surface, cairo.ImageSurface):
sur = cairo.ImageSurface(cairo.FORMAT_ARGB32,
int(self.bbox.width), int(self.bbox.height))
ctx = cairo.Context(sur)
self.redraw(ctx)
else:
sur = self._surface
ctx = self._ctx
if self._is_dirty:
self.redraw(ctx)
with named_temporary_file(prefix="igraph", suffix=".png") as tmpfile:
sur.write_to_png(tmpfile)
config = Configuration.instance()
imgviewer = config["apps.image_viewer"]
if not imgviewer:
# No image viewer was given and none was detected. This
# should only happen on unknown platforms.
plat = platform.system()
raise NotImplementedError("showing plots is not implemented " + \
"on this platform: %s" % plat)
else:
os.system("%s %s" % (imgviewer, tmpfile))
if platform.system() == "Darwin" or self._windows_hacks:
# On Mac OS X and Windows, launched applications are likely to
# fork and give control back to Python immediately.
# Chances are that the temporary image file gets removed
# before the image viewer has a chance to open it, so
# we wait here a little bit. Yes, this is quite hackish :(
time.sleep(5)
def _get_response(self, path, params={}, compressed=False):
"""Sends a request to Nexus at the given path with the given parameters
and returns a file-like object for the response. `compressed` denotes
whether we accept compressed responses."""
if self.url is None:
url = Configuration.instance()["remote.nexus.url"]
else:
url = self.url
url = "%s%s?%s" % (url, path, urlencode(params))
request = urllib2.Request(url)
if compressed:
request.add_header("Accept-Encoding", "gzip")
if self.debug:
print "[debug] Sending request: %s" % url
return self._opener.open(request)
def _get_response(self, path, params={}, compressed=False):
"""Sends a request to Nexus at the given path with the given parameters
and returns a file-like object for the response. `compressed` denotes
whether we accept compressed responses."""
if self.url is None:
url = Configuration.instance()["remote.nexus.url"]
else:
url = self.url
url = "%s%s?%s" % (url, path, urlencode(params))
request = urllib2.Request(url)
if compressed:
request.add_header("Accept-Encoding", "gzip")
if self.debug:
print "[debug] Sending request: %s" % url
return self._opener.open(request)
result = Plot(target, bbox, background=kwds.get("background", "white"))
if "margin" in kwds:
bbox = bbox.contract(kwds["margin"])
del kwds["margin"]
else:
bbox = bbox.contract(20)
result.add(obj, bbox, *args, **kwds)
if target is None and _is_running_in_ipython():
# Get the default value of the `inline` argument from the configuration if
# needed
inline = kwds.get("inline")
if inline is None:
config = Configuration.instance()
inline = config["shell.ipython.inlining.Plot"]
# If we requested an inline plot, just return the result and IPython will
# call its _repr_svg_ method. If we requested a non-inline plot, show the
# plot in a separate window and return nothing
if inline:
return result
else:
result.show()
return
# We are either not in IPython or the user specified an explicit plot target,
# so just show or save the result
if target is None:
result.show()
elif isinstance(target, basestring):