OLD | NEW |
(Empty) | |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. |
| 4 |
| 5 import sys |
| 6 |
| 7 import plugin_protos |
| 8 import types |
| 9 |
| 10 |
| 11 def Debug(data): |
| 12 sys.stderr.write(str(data)) |
| 13 sys.stderr.write('\n') |
| 14 sys.stderr.flush() |
| 15 |
| 16 |
| 17 def TitleCase(s): |
| 18 return ''.join(p[0].upper() + p[1:] for p in s.split('_')) |
| 19 |
| 20 |
| 21 def Indented(s, indent=2): |
| 22 return '\n'.join((' ' * indent) + p for p in s.rstrip('\n').split('\n')) |
| 23 |
| 24 |
| 25 proto_path_to_file_map = {} |
| 26 |
| 27 |
| 28 def RegisterProtoFile(proto_file): |
| 29 proto_path_to_file_map[proto_file.Filename()] = proto_file |
| 30 types.RegisterTypesForFile(proto_file) |
| 31 |
| 32 |
| 33 def GetProtoFileForFilename(filename): |
| 34 proto_file = proto_path_to_file_map[filename] |
| 35 assert proto_file |
| 36 return proto_file |
| 37 |
| 38 |
| 39 def SetBinaryStdio(): |
| 40 import platform |
| 41 if platform.system() == 'Windows': |
| 42 import os, sys, msvcrt |
| 43 msvcrt.setmode(sys.stdin.fileno(), os.O_BINARY) |
| 44 msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY) |
| 45 |
| 46 |
| 47 def ReadRequestFromStdin(): |
| 48 SetBinaryStdio() |
| 49 data = sys.stdin.read() |
| 50 return plugin_protos.PluginRequestFromString(data) |
OLD | NEW |