def requestHighlights(repository, sha1s): requests = [{ "repository_path": repository.path, "sha1": sha1, "path": path, "language": language } for sha1, (path, language) in sha1s.items() if not syntaxhighlight.isHighlighted(sha1, language)] if not requests: return try: connection = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) connection.connect(configuration.services.HIGHLIGHT["address"]) connection.send(json_encode(requests)) connection.shutdown(socket.SHUT_WR) data = "" while True: received = connection.recv(4096) if not received: break data += received connection.close() except socket.error, error: raise Exception, "Syntax highlighting background service failed: %s" % error[ 1]
def requestHighlights(repository, sha1s): requests = [{ "repository_path": repository.path, "sha1": sha1, "path": path, "language": language } for sha1, (path, language) in sha1s.items() if not syntaxhighlight.isHighlighted(sha1, language)] if not requests: return try: connection = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) connection.connect(configuration.services.HIGHLIGHT["address"]) connection.send(json_encode(requests)) connection.shutdown(socket.SHUT_WR) data = "" while True: received = connection.recv(4096) if not received: break data += received connection.close() except socket.error, error: raise Exception, "Syntax highlighting background service failed: %s" % error[1]
def requestHighlights(repository, sha1s): requests = [{ "repository_path": repository.path, "sha1": sha1, "path": path, "language": language } for sha1, (path, language) in sha1s.items() if not syntaxhighlight.isHighlighted(sha1, language)] if not requests: return try: connection = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) connection.connect(configuration.services.HIGHLIGHT["address"]) connection.send(json_encode(requests)) connection.shutdown(socket.SHUT_WR) data = "" while True: received = connection.recv(4096) if not received: break data += received connection.close() except socket.error as error: raise HighlightBackgroundServiceError(error[1]) try: results = json_decode(data) except ValueError: raise HighlightBackgroundServiceError( "returned an invalid response (%r)" % data) if type(results) != list: # If not a list, the result is probably an error message. raise HighlightBackgroundServiceError(str(results)) if len(results) != len(requests): raise HighlightBackgroundServiceError("didn't process all requests")
def request_result(self, request): if isHighlighted(request["sha1"], request["language"], request["mode"]): result = request.copy() result["highlighted"] = True return result
def request_result(self, request): if isHighlighted(request["sha1"], request["language"]): result = request.copy() result["highlighted"] = True return result
class HighlightBackgroundServiceError(base.ImplementationError): def __init__(self, message): super(HighlightBackgroundServiceError, self).__init__( "Highlight background service failed: %s" % message) def requestHighlights(repository, sha1s, mode, async=False): requests = [ { "repository_path": repository.path, "sha1": sha1, "path": path, "language": language, "mode": mode } for sha1, (path, language) in sha1s.items() if not syntaxhighlight.isHighlighted(sha1, language, mode) ] if not requests: return False try: connection = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) connection.connect(configuration.services.HIGHLIGHT["address"]) connection.send(json_encode({ "requests": requests, "async": async })) connection.shutdown(socket.SHUT_WR) data = ""
class HighlightBackgroundServiceError(base.ImplementationError): def __init__(self, message): super(HighlightBackgroundServiceError, self).__init__( "Highlight background service failed: %s" % message) def requestHighlights(repository, sha1s, mode, async=False): requests = [{ "repository_path": repository.path, "sha1": sha1, "path": path, "language": language, "mode": mode } for sha1, (path, language) in sha1s.items() if not syntaxhighlight.isHighlighted(sha1, language, mode)] if not requests: return False try: connection = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) connection.connect(configuration.services.HIGHLIGHT["address"]) connection.send(json_encode({"requests": requests, "async": async})) connection.shutdown(socket.SHUT_WR) data = "" while True: received = connection.recv(4096) if not received: break