Mercurial > hg
annotate hgext/fsmonitor/pywatchman/__init__.py @ 49857:ab32fd8412a7
typing: disable a few incorrect warnings in pywatchman
The module-attr warnings are for things that only exist on Windows, and the
wrong-keyword-args warning is due to a special case for a specific constructor.
Both of these are properly conditionalized.
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Thu, 05 Jan 2023 17:31:11 -0500 |
parents | 40d3ee570d83 |
children | 493034cc3265 |
rev | line source |
---|---|
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1 # Copyright 2014-present Facebook, Inc. |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
2 # All rights reserved. |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
3 # |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
4 # Redistribution and use in source and binary forms, with or without |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
5 # modification, are permitted provided that the following conditions are met: |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
6 # |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
7 # * Redistributions of source code must retain the above copyright notice, |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
8 # this list of conditions and the following disclaimer. |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
9 # |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
10 # * Redistributions in binary form must reproduce the above copyright notice, |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
11 # this list of conditions and the following disclaimer in the documentation |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
12 # and/or other materials provided with the distribution. |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
13 # |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
14 # * Neither the name Facebook nor the names of its contributors may be used to |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
15 # endorse or promote products derived from this software without specific |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
16 # prior written permission. |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
17 # |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
19 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
20 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
21 # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
22 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
23 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
24 # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
25 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
26 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
27 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
28 |
30656
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
29 import inspect |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
30 import math |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
31 import os |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
32 import socket |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
33 import subprocess |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
34 import time |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
35 |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
36 from . import capabilities, compat, encoding, load |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
37 |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
38 |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
39 # Sometimes it's really hard to get Python extensions to compile, |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
40 # so fall back to a pure Python implementation. |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
41 try: |
30656
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
42 from . import bser |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
43 |
30656
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
44 # Demandimport causes modules to be loaded lazily. Force the load now |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
45 # so that we can fall back on pybser if bser doesn't exist |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
46 bser.pdu_info |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
47 except ImportError: |
30656
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
48 from . import pybser as bser |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
49 |
39826
c31ce080eb75
py3: convert arguments, cwd and env to native strings when spawning subprocess
Matt Harbison <matt_harbison@yahoo.com>
parents:
33769
diff
changeset
|
50 |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
51 if os.name == "nt": |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
52 import ctypes |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
53 import ctypes.wintypes |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
54 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
55 wintypes = ctypes.wintypes |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
56 GENERIC_READ = 0x80000000 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
57 GENERIC_WRITE = 0x40000000 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
58 FILE_FLAG_OVERLAPPED = 0x40000000 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
59 OPEN_EXISTING = 3 |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
60 INVALID_HANDLE_VALUE = ctypes.c_void_p(-1).value |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
61 FORMAT_MESSAGE_FROM_SYSTEM = 0x00001000 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
62 FORMAT_MESSAGE_ALLOCATE_BUFFER = 0x00000100 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
63 FORMAT_MESSAGE_IGNORE_INSERTS = 0x00000200 |
30656
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
64 WAIT_FAILED = 0xFFFFFFFF |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
65 WAIT_TIMEOUT = 0x00000102 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
66 WAIT_OBJECT_0 = 0x00000000 |
30656
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
67 WAIT_IO_COMPLETION = 0x000000C0 |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
68 INFINITE = 0xFFFFFFFF |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
69 |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
70 # Overlapped I/O operation is in progress. (997) |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
71 ERROR_IO_PENDING = 0x000003E5 |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
72 |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
73 # The pointer size follows the architecture |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
74 # We use WPARAM since this type is already conditionally defined |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
75 ULONG_PTR = ctypes.wintypes.WPARAM |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
76 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
77 class OVERLAPPED(ctypes.Structure): |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
78 _fields_ = [ |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
79 ("Internal", ULONG_PTR), |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
80 ("InternalHigh", ULONG_PTR), |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
81 ("Offset", wintypes.DWORD), |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
82 ("OffsetHigh", wintypes.DWORD), |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
83 ("hEvent", wintypes.HANDLE), |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
84 ] |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
85 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
86 def __init__(self): |
30656
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
87 self.Internal = 0 |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
88 self.InternalHigh = 0 |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
89 self.Offset = 0 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
90 self.OffsetHigh = 0 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
91 self.hEvent = 0 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
92 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
93 LPDWORD = ctypes.POINTER(wintypes.DWORD) |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
94 |
49855
36afe74e4439
watchman: refactor `ctypes.windll.kernel32` references to a local variable
Matt Harbison <matt_harbison@yahoo.com>
parents:
49537
diff
changeset
|
95 _kernel32 = ctypes.windll.kernel32 # pytype: disable=module-attr |
36afe74e4439
watchman: refactor `ctypes.windll.kernel32` references to a local variable
Matt Harbison <matt_harbison@yahoo.com>
parents:
49537
diff
changeset
|
96 |
36afe74e4439
watchman: refactor `ctypes.windll.kernel32` references to a local variable
Matt Harbison <matt_harbison@yahoo.com>
parents:
49537
diff
changeset
|
97 CreateFile = _kernel32.CreateFileA |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
98 CreateFile.argtypes = [ |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
99 wintypes.LPSTR, |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
100 wintypes.DWORD, |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
101 wintypes.DWORD, |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
102 wintypes.LPVOID, |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
103 wintypes.DWORD, |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
104 wintypes.DWORD, |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
105 wintypes.HANDLE, |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
106 ] |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
107 CreateFile.restype = wintypes.HANDLE |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
108 |
49855
36afe74e4439
watchman: refactor `ctypes.windll.kernel32` references to a local variable
Matt Harbison <matt_harbison@yahoo.com>
parents:
49537
diff
changeset
|
109 CloseHandle = _kernel32.CloseHandle |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
110 CloseHandle.argtypes = [wintypes.HANDLE] |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
111 CloseHandle.restype = wintypes.BOOL |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
112 |
49855
36afe74e4439
watchman: refactor `ctypes.windll.kernel32` references to a local variable
Matt Harbison <matt_harbison@yahoo.com>
parents:
49537
diff
changeset
|
113 ReadFile = _kernel32.ReadFile |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
114 ReadFile.argtypes = [ |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
115 wintypes.HANDLE, |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
116 wintypes.LPVOID, |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
117 wintypes.DWORD, |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
118 LPDWORD, |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
119 ctypes.POINTER(OVERLAPPED), |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
120 ] |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
121 ReadFile.restype = wintypes.BOOL |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
122 |
49855
36afe74e4439
watchman: refactor `ctypes.windll.kernel32` references to a local variable
Matt Harbison <matt_harbison@yahoo.com>
parents:
49537
diff
changeset
|
123 WriteFile = _kernel32.WriteFile |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
124 WriteFile.argtypes = [ |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
125 wintypes.HANDLE, |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
126 wintypes.LPVOID, |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
127 wintypes.DWORD, |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
128 LPDWORD, |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
129 ctypes.POINTER(OVERLAPPED), |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
130 ] |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
131 WriteFile.restype = wintypes.BOOL |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
132 |
49855
36afe74e4439
watchman: refactor `ctypes.windll.kernel32` references to a local variable
Matt Harbison <matt_harbison@yahoo.com>
parents:
49537
diff
changeset
|
133 GetLastError = _kernel32.GetLastError |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
134 GetLastError.argtypes = [] |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
135 GetLastError.restype = wintypes.DWORD |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
136 |
49855
36afe74e4439
watchman: refactor `ctypes.windll.kernel32` references to a local variable
Matt Harbison <matt_harbison@yahoo.com>
parents:
49537
diff
changeset
|
137 SetLastError = _kernel32.SetLastError |
30656
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
138 SetLastError.argtypes = [wintypes.DWORD] |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
139 SetLastError.restype = None |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
140 |
49855
36afe74e4439
watchman: refactor `ctypes.windll.kernel32` references to a local variable
Matt Harbison <matt_harbison@yahoo.com>
parents:
49537
diff
changeset
|
141 FormatMessage = _kernel32.FormatMessageA |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
142 FormatMessage.argtypes = [ |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
143 wintypes.DWORD, |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
144 wintypes.LPVOID, |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
145 wintypes.DWORD, |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
146 wintypes.DWORD, |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
147 ctypes.POINTER(wintypes.LPSTR), |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
148 wintypes.DWORD, |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
149 wintypes.LPVOID, |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
150 ] |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
151 FormatMessage.restype = wintypes.DWORD |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
152 |
49855
36afe74e4439
watchman: refactor `ctypes.windll.kernel32` references to a local variable
Matt Harbison <matt_harbison@yahoo.com>
parents:
49537
diff
changeset
|
153 LocalFree = _kernel32.LocalFree |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
154 |
49855
36afe74e4439
watchman: refactor `ctypes.windll.kernel32` references to a local variable
Matt Harbison <matt_harbison@yahoo.com>
parents:
49537
diff
changeset
|
155 GetOverlappedResult = _kernel32.GetOverlappedResult |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
156 GetOverlappedResult.argtypes = [ |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
157 wintypes.HANDLE, |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
158 ctypes.POINTER(OVERLAPPED), |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
159 LPDWORD, |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
160 wintypes.BOOL, |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
161 ] |
30656
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
162 GetOverlappedResult.restype = wintypes.BOOL |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
163 |
49855
36afe74e4439
watchman: refactor `ctypes.windll.kernel32` references to a local variable
Matt Harbison <matt_harbison@yahoo.com>
parents:
49537
diff
changeset
|
164 GetOverlappedResultEx = getattr(_kernel32, "GetOverlappedResultEx", None) |
30656
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
165 if GetOverlappedResultEx is not None: |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
166 GetOverlappedResultEx.argtypes = [ |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
167 wintypes.HANDLE, |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
168 ctypes.POINTER(OVERLAPPED), |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
169 LPDWORD, |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
170 wintypes.DWORD, |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
171 wintypes.BOOL, |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
172 ] |
30656
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
173 GetOverlappedResultEx.restype = wintypes.BOOL |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
174 |
49855
36afe74e4439
watchman: refactor `ctypes.windll.kernel32` references to a local variable
Matt Harbison <matt_harbison@yahoo.com>
parents:
49537
diff
changeset
|
175 WaitForSingleObjectEx = _kernel32.WaitForSingleObjectEx |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
176 WaitForSingleObjectEx.argtypes = [ |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
177 wintypes.HANDLE, |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
178 wintypes.DWORD, |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
179 wintypes.BOOL, |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
180 ] |
30656
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
181 WaitForSingleObjectEx.restype = wintypes.DWORD |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
182 |
49855
36afe74e4439
watchman: refactor `ctypes.windll.kernel32` references to a local variable
Matt Harbison <matt_harbison@yahoo.com>
parents:
49537
diff
changeset
|
183 CreateEvent = _kernel32.CreateEventA |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
184 CreateEvent.argtypes = [ |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
185 LPDWORD, |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
186 wintypes.BOOL, |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
187 wintypes.BOOL, |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
188 wintypes.LPSTR, |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
189 ] |
30656
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
190 CreateEvent.restype = wintypes.HANDLE |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
191 |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
192 # Windows Vista is the minimum supported client for CancelIoEx. |
49855
36afe74e4439
watchman: refactor `ctypes.windll.kernel32` references to a local variable
Matt Harbison <matt_harbison@yahoo.com>
parents:
49537
diff
changeset
|
193 CancelIoEx = _kernel32.CancelIoEx |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
194 CancelIoEx.argtypes = [wintypes.HANDLE, ctypes.POINTER(OVERLAPPED)] |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
195 CancelIoEx.restype = wintypes.BOOL |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
196 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
197 # 2 bytes marker, 1 byte int size, 8 bytes int64 value |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
198 sniff_len = 13 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
199 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
200 # This is a helper for debugging the client. |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
201 _debugging = False |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
202 if _debugging: |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
203 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
204 def log(fmt, *args): |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
205 print( |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
206 "[%s] %s" |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
207 % ( |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
208 time.strftime("%a, %d %b %Y %H:%M:%S", time.gmtime()), |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
209 fmt % args[:], |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
210 ) |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
211 ) |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
212 |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
213 |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
214 else: |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
215 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
216 def log(fmt, *args): |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
217 pass |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
218 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
219 |
30656
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
220 def _win32_strerror(err): |
47062
f38bf44e077f
black: make codebase compatible with black v21.4b2 and v20.8b1
Kyle Lippincott <spectral@google.com>
parents:
45942
diff
changeset
|
221 """expand a win32 error code into a human readable message""" |
30656
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
222 |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
223 # FormatMessage will allocate memory and assign it here |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
224 buf = ctypes.c_char_p() |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
225 FormatMessage( |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
226 FORMAT_MESSAGE_FROM_SYSTEM |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
227 | FORMAT_MESSAGE_ALLOCATE_BUFFER |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
228 | FORMAT_MESSAGE_IGNORE_INSERTS, |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
229 None, |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
230 err, |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
231 0, |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
232 buf, |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
233 0, |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
234 None, |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
235 ) |
30656
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
236 try: |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
237 return buf.value |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
238 finally: |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
239 LocalFree(buf) |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
240 |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
241 |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
242 class WatchmanError(Exception): |
30656
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
243 def __init__(self, msg=None, cmd=None): |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
244 self.msg = msg |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
245 self.cmd = cmd |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
246 |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
247 def setCommand(self, cmd): |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
248 self.cmd = cmd |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
249 |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
250 def __str__(self): |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
251 if self.cmd: |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
252 return "%s, while executing %s" % (self.msg, self.cmd) |
30656
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
253 return self.msg |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
254 |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
255 |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
256 class BSERv1Unsupported(WatchmanError): |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
257 pass |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
258 |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
259 |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
260 class UseAfterFork(WatchmanError): |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
261 pass |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
262 |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
263 |
30656
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
264 class WatchmanEnvironmentError(WatchmanError): |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
265 def __init__(self, msg, errno, errmsg, cmd=None): |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
266 super(WatchmanEnvironmentError, self).__init__( |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
267 "{0}: errno={1} errmsg={2}".format(msg, errno, errmsg), cmd |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
268 ) |
30656
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
269 |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
270 |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
271 class SocketConnectError(WatchmanError): |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
272 def __init__(self, sockpath, exc): |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
273 super(SocketConnectError, self).__init__( |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
274 "unable to connect to %s: %s" % (sockpath, exc) |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
275 ) |
30656
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
276 self.sockpath = sockpath |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
277 self.exc = exc |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
278 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
279 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
280 class SocketTimeout(WatchmanError): |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
281 """A specialized exception raised for socket timeouts during communication to/from watchman. |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
43387
diff
changeset
|
282 This makes it easier to implement non-blocking loops as callers can easily distinguish |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
43387
diff
changeset
|
283 between a routine timeout and an actual error condition. |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
284 |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
43387
diff
changeset
|
285 Note that catching WatchmanError will also catch this as it is a super-class, so backwards |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
43387
diff
changeset
|
286 compatibility in exception handling is preserved. |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
287 """ |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
288 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
289 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
290 class CommandError(WatchmanError): |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
291 """error returned by watchman |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
292 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
293 self.msg is the message returned by watchman. |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
294 """ |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
295 |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
296 def __init__(self, msg, cmd=None): |
30656
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
297 super(CommandError, self).__init__( |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
298 "watchman command error: %s" % (msg,), cmd |
30656
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
299 ) |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
300 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
301 |
48946
642e31cb55f0
py3: use class X: instead of class X(object):
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
302 class Transport: |
47062
f38bf44e077f
black: make codebase compatible with black v21.4b2 and v20.8b1
Kyle Lippincott <spectral@google.com>
parents:
45942
diff
changeset
|
303 """communication transport to the watchman server""" |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
304 |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
305 buf = None |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
306 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
307 def close(self): |
47062
f38bf44e077f
black: make codebase compatible with black v21.4b2 and v20.8b1
Kyle Lippincott <spectral@google.com>
parents:
45942
diff
changeset
|
308 """tear it down""" |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
309 raise NotImplementedError() |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
310 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
311 def readBytes(self, size): |
47062
f38bf44e077f
black: make codebase compatible with black v21.4b2 and v20.8b1
Kyle Lippincott <spectral@google.com>
parents:
45942
diff
changeset
|
312 """read size bytes""" |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
313 raise NotImplementedError() |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
314 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
315 def write(self, buf): |
47062
f38bf44e077f
black: make codebase compatible with black v21.4b2 and v20.8b1
Kyle Lippincott <spectral@google.com>
parents:
45942
diff
changeset
|
316 """write some data""" |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
317 raise NotImplementedError() |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
318 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
319 def setTimeout(self, value): |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
320 pass |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
321 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
322 def readLine(self): |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
43387
diff
changeset
|
323 """read a line |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
324 Maintains its own buffer, callers of the transport should not mix |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
325 calls to readBytes and readLine. |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
326 """ |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
327 if self.buf is None: |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
328 self.buf = [] |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
329 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
330 # Buffer may already have a line if we've received unilateral |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
331 # response(s) from the server |
30656
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
332 if len(self.buf) == 1 and b"\n" in self.buf[0]: |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
333 (line, b) = self.buf[0].split(b"\n", 1) |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
334 self.buf = [b] |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
335 return line |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
336 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
337 while True: |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
338 b = self.readBytes(4096) |
30656
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
339 if b"\n" in b: |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
340 result = b"".join(self.buf) |
30656
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
341 (line, b) = b.split(b"\n", 1) |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
342 self.buf = [b] |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
343 return result + line |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
344 self.buf.append(b) |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
345 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
346 |
48946
642e31cb55f0
py3: use class X: instead of class X(object):
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
347 class Codec: |
47062
f38bf44e077f
black: make codebase compatible with black v21.4b2 and v20.8b1
Kyle Lippincott <spectral@google.com>
parents:
45942
diff
changeset
|
348 """communication encoding for the watchman server""" |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
349 |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
350 transport = None |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
351 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
352 def __init__(self, transport): |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
353 self.transport = transport |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
354 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
355 def receive(self): |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
356 raise NotImplementedError() |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
357 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
358 def send(self, *args): |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
359 raise NotImplementedError() |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
360 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
361 def setTimeout(self, value): |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
362 self.transport.setTimeout(value) |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
363 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
364 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
365 class UnixSocketTransport(Transport): |
47062
f38bf44e077f
black: make codebase compatible with black v21.4b2 and v20.8b1
Kyle Lippincott <spectral@google.com>
parents:
45942
diff
changeset
|
366 """local unix domain socket transport""" |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
367 |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
368 sock = None |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
369 |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
370 def __init__(self, sockpath, timeout): |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
371 self.sockpath = sockpath |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
372 self.timeout = timeout |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
373 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
374 sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
375 try: |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
376 sock.settimeout(self.timeout) |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
377 sock.connect(self.sockpath) |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
378 self.sock = sock |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
379 except socket.error as e: |
30656
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
380 sock.close() |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
381 raise SocketConnectError(self.sockpath, e) |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
382 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
383 def close(self): |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
384 if self.sock: |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
385 self.sock.close() |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
386 self.sock = None |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
387 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
388 def setTimeout(self, value): |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
389 self.timeout = value |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
390 self.sock.settimeout(self.timeout) |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
391 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
392 def readBytes(self, size): |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
393 try: |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
394 buf = [self.sock.recv(size)] |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
395 if not buf[0]: |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
396 raise WatchmanError("empty watchman response") |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
397 return buf[0] |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
398 except socket.timeout: |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
399 raise SocketTimeout("timed out waiting for response") |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
400 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
401 def write(self, data): |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
402 try: |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
403 self.sock.sendall(data) |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
404 except socket.timeout: |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
405 raise SocketTimeout("timed out sending query command") |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
406 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
407 |
30656
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
408 def _get_overlapped_result_ex_impl(pipe, olap, nbytes, millis, alertable): |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
43387
diff
changeset
|
409 """Windows 7 and earlier does not support GetOverlappedResultEx. The |
30656
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
410 alternative is to use GetOverlappedResult and wait for read or write |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
411 operation to complete. This is done be using CreateEvent and |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
412 WaitForSingleObjectEx. CreateEvent, WaitForSingleObjectEx |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
413 and GetOverlappedResult are all part of Windows API since WindowsXP. |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
414 This is the exact same implementation that can be found in the watchman |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
415 source code (see get_overlapped_result_ex_impl in stream_win.c). This |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
416 way, maintenance should be simplified. |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
417 """ |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
418 log("Preparing to wait for maximum %dms", millis) |
30656
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
419 if millis != 0: |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
420 waitReturnCode = WaitForSingleObjectEx(olap.hEvent, millis, alertable) |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
421 if waitReturnCode == WAIT_OBJECT_0: |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
422 # Event is signaled, overlapped IO operation result should be available. |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
423 pass |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
424 elif waitReturnCode == WAIT_IO_COMPLETION: |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
425 # WaitForSingleObjectEx returnes because the system added an I/O completion |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
426 # routine or an asynchronous procedure call (APC) to the thread queue. |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
427 SetLastError(WAIT_IO_COMPLETION) |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
428 pass |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
429 elif waitReturnCode == WAIT_TIMEOUT: |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
430 # We reached the maximum allowed wait time, the IO operation failed |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
431 # to complete in timely fashion. |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
432 SetLastError(WAIT_TIMEOUT) |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
433 return False |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
434 elif waitReturnCode == WAIT_FAILED: |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
435 # something went wrong calling WaitForSingleObjectEx |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
436 err = GetLastError() |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
437 log("WaitForSingleObjectEx failed: %s", _win32_strerror(err)) |
30656
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
438 return False |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
439 else: |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
440 # unexpected situation deserving investigation. |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
441 err = GetLastError() |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
442 log("Unexpected error: %s", _win32_strerror(err)) |
30656
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
443 return False |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
444 |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
445 return GetOverlappedResult(pipe, olap, nbytes, False) |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
446 |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
447 |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
448 class WindowsNamedPipeTransport(Transport): |
47062
f38bf44e077f
black: make codebase compatible with black v21.4b2 and v20.8b1
Kyle Lippincott <spectral@google.com>
parents:
45942
diff
changeset
|
449 """connect to a named pipe""" |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
450 |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
451 def __init__(self, sockpath, timeout): |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
452 self.sockpath = sockpath |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
453 self.timeout = int(math.ceil(timeout * 1000)) |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
454 self._iobuf = None |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
455 |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
456 if compat.PYTHON3: |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
457 sockpath = os.fsencode(sockpath) |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
458 self.pipe = CreateFile( |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
459 sockpath, |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
460 GENERIC_READ | GENERIC_WRITE, |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
461 0, |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
462 None, |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
463 OPEN_EXISTING, |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
464 FILE_FLAG_OVERLAPPED, |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
465 None, |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
466 ) |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
467 |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
468 err = GetLastError() |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
469 if self.pipe == INVALID_HANDLE_VALUE or self.pipe == 0: |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
470 self.pipe = None |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
471 raise SocketConnectError(self.sockpath, self._make_win_err("", err)) |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
472 |
30656
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
473 # event for the overlapped I/O operations |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
474 self._waitable = CreateEvent(None, True, False, None) |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
475 err = GetLastError() |
30656
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
476 if self._waitable is None: |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
477 self._raise_win_err("CreateEvent failed", err) |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
478 |
30656
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
479 self._get_overlapped_result_ex = GetOverlappedResultEx |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
480 if ( |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
481 os.getenv("WATCHMAN_WIN7_COMPAT") == "1" |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
482 or self._get_overlapped_result_ex is None |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
483 ): |
30656
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
484 self._get_overlapped_result_ex = _get_overlapped_result_ex_impl |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
485 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
486 def _raise_win_err(self, msg, err): |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
487 raise self._make_win_err(msg, err) |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
488 |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
489 def _make_win_err(self, msg, err): |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
490 return IOError( |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
491 "%s win32 error code: %d %s" % (msg, err, _win32_strerror(err)) |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
492 ) |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
493 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
494 def close(self): |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
495 if self.pipe: |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
496 log("Closing pipe") |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
497 CloseHandle(self.pipe) |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
498 self.pipe = None |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
499 |
30656
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
500 if self._waitable is not None: |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
501 # We release the handle for the event |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
502 CloseHandle(self._waitable) |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
503 self._waitable = None |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
504 |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
505 def setTimeout(self, value): |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
506 # convert to milliseconds |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
507 self.timeout = int(value * 1000) |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
508 |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
509 def readBytes(self, size): |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
43387
diff
changeset
|
510 """A read can block for an unbounded amount of time, even if the |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
43387
diff
changeset
|
511 kernel reports that the pipe handle is signalled, so we need to |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
43387
diff
changeset
|
512 always perform our reads asynchronously |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
513 """ |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
514 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
515 # try to satisfy the read from any buffered data |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
516 if self._iobuf: |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
517 if size >= len(self._iobuf): |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
518 res = self._iobuf |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
519 self.buf = None |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
520 return res |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
521 res = self._iobuf[:size] |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
522 self._iobuf = self._iobuf[size:] |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
523 return res |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
524 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
525 # We need to initiate a read |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
526 buf = ctypes.create_string_buffer(size) |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
527 olap = OVERLAPPED() |
30656
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
528 olap.hEvent = self._waitable |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
529 |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
530 log("made read buff of size %d", size) |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
531 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
532 # ReadFile docs warn against sending in the nread parameter for async |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
533 # operations, so we always collect it via GetOverlappedResultEx |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
534 immediate = ReadFile(self.pipe, buf, size, None, olap) |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
535 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
536 if not immediate: |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
537 err = GetLastError() |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
538 if err != ERROR_IO_PENDING: |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
539 self._raise_win_err("failed to read %d bytes" % size, err) |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
540 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
541 nread = wintypes.DWORD() |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
542 if not self._get_overlapped_result_ex( |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
543 self.pipe, olap, nread, 0 if immediate else self.timeout, True |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
544 ): |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
545 err = GetLastError() |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
546 CancelIoEx(self.pipe, olap) |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
547 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
548 if err == WAIT_TIMEOUT: |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
549 log("GetOverlappedResultEx timedout") |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
550 raise SocketTimeout( |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
551 "timed out after waiting %dms for read" % self.timeout |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
552 ) |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
553 |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
554 log("GetOverlappedResultEx reports error %d", err) |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
555 self._raise_win_err("error while waiting for read", err) |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
556 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
557 nread = nread.value |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
558 if nread == 0: |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
559 # Docs say that named pipes return 0 byte when the other end did |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
560 # a zero byte write. Since we don't ever do that, the only |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
561 # other way this shows up is if the client has gotten in a weird |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
562 # state, so let's bail out |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
563 CancelIoEx(self.pipe, olap) |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
564 raise IOError("Async read yielded 0 bytes; unpossible!") |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
565 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
566 # Holds precisely the bytes that we read from the prior request |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
567 buf = buf[:nread] |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
568 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
569 returned_size = min(nread, size) |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
570 if returned_size == nread: |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
571 return buf |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
572 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
573 # keep any left-overs around for a later read to consume |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
574 self._iobuf = buf[returned_size:] |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
575 return buf[:returned_size] |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
576 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
577 def write(self, data): |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
578 olap = OVERLAPPED() |
30656
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
579 olap.hEvent = self._waitable |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
580 |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
581 immediate = WriteFile( |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
582 self.pipe, ctypes.c_char_p(data), len(data), None, olap |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
583 ) |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
584 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
585 if not immediate: |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
586 err = GetLastError() |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
587 if err != ERROR_IO_PENDING: |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
588 self._raise_win_err( |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
589 "failed to write %d bytes to handle %r" |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
590 % (len(data), self.pipe), |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
591 err, |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
592 ) |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
593 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
594 # Obtain results, waiting if needed |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
595 nwrote = wintypes.DWORD() |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
596 if self._get_overlapped_result_ex( |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
597 self.pipe, olap, nwrote, 0 if immediate else self.timeout, True |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
598 ): |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
599 log("made write of %d bytes", nwrote.value) |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
600 return nwrote.value |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
601 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
602 err = GetLastError() |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
603 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
604 # It's potentially unsafe to allow the write to continue after |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
605 # we unwind, so let's make a best effort to avoid that happening |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
606 CancelIoEx(self.pipe, olap) |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
607 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
608 if err == WAIT_TIMEOUT: |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
609 raise SocketTimeout( |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
610 "timed out after waiting %dms for write" % self.timeout |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
611 ) |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
612 self._raise_win_err( |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
613 "error while waiting for write of %d bytes" % len(data), err |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
614 ) |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
615 |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
616 |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
617 def _default_binpath(binpath=None): |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
618 if binpath: |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
619 return binpath |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
620 # The test harness sets WATCHMAN_BINARY to the binary under test, |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
621 # so we use that by default, otherwise, allow resolving watchman |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
622 # from the users PATH. |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
623 return os.environ.get("WATCHMAN_BINARY", "watchman") |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
624 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
625 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
626 class CLIProcessTransport(Transport): |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
43387
diff
changeset
|
627 """open a pipe to the cli to talk to the service |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
628 This intended to be used only in the test harness! |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
629 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
630 The CLI is an oddball because we only support JSON input |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
631 and cannot send multiple commands through the same instance, |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
632 so we spawn a new process for each command. |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
633 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
634 We disable server spawning for this implementation, again, because |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
635 it is intended to be used only in our test harness. You really |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
636 should not need to use the CLI transport for anything real. |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
637 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
638 While the CLI can output in BSER, our Transport interface doesn't |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
639 support telling this instance that it should do so. That effectively |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
640 limits this implementation to JSON input and output only at this time. |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
641 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
642 It is the responsibility of the caller to set the send and |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
643 receive codecs appropriately. |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
644 """ |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
645 |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
646 proc = None |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
647 closed = True |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
648 |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
649 def __init__(self, sockpath, timeout, binpath=None): |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
650 self.sockpath = sockpath |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
651 self.timeout = timeout |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
652 self.binpath = _default_binpath(binpath) |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
653 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
654 def close(self): |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
655 if self.proc: |
30656
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
656 if self.proc.pid is not None: |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
657 self.proc.kill() |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
658 self.proc.stdin.close() |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
659 self.proc.stdout.close() |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
660 self.proc.wait() |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
661 self.proc = None |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
662 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
663 def _connect(self): |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
664 if self.proc: |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
665 return self.proc |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
666 args = [ |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
667 self.binpath, |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
668 "--sockname={0}".format(self.sockpath), |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
669 "--logfile=/BOGUS", |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
670 "--statefile=/BOGUS", |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
671 "--no-spawn", |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
672 "--no-local", |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
673 "--no-pretty", |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
674 "-j", |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
675 ] |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
676 self.proc = subprocess.Popen( |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
677 args, stdin=subprocess.PIPE, stdout=subprocess.PIPE |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
678 ) |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
679 return self.proc |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
680 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
681 def readBytes(self, size): |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
682 self._connect() |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
683 res = self.proc.stdout.read(size) |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
684 if not res: |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
685 raise WatchmanError("EOF on CLI process transport") |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
686 return res |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
687 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
688 def write(self, data): |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
689 if self.closed: |
30656
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
690 self.close() |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
691 self.closed = False |
49856
40d3ee570d83
watchman: refactor transport connecting to unconfuse pytype
Matt Harbison <matt_harbison@yahoo.com>
parents:
49855
diff
changeset
|
692 proc = self._connect() |
40d3ee570d83
watchman: refactor transport connecting to unconfuse pytype
Matt Harbison <matt_harbison@yahoo.com>
parents:
49855
diff
changeset
|
693 res = proc.stdin.write(data) |
40d3ee570d83
watchman: refactor transport connecting to unconfuse pytype
Matt Harbison <matt_harbison@yahoo.com>
parents:
49855
diff
changeset
|
694 proc.stdin.close() |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
695 self.closed = True |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
696 return res |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
697 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
698 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
699 class BserCodec(Codec): |
47062
f38bf44e077f
black: make codebase compatible with black v21.4b2 and v20.8b1
Kyle Lippincott <spectral@google.com>
parents:
45942
diff
changeset
|
700 """use the BSER encoding. This is the default, preferred codec""" |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
701 |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
702 def __init__(self, transport, value_encoding, value_errors): |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
703 super(BserCodec, self).__init__(transport) |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
704 self._value_encoding = value_encoding |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
705 self._value_errors = value_errors |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
706 |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
707 def _loads(self, response): |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
708 return bser.loads( |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
709 response, |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
710 value_encoding=self._value_encoding, |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
711 value_errors=self._value_errors, |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
712 ) |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
713 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
714 def receive(self): |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
715 buf = [self.transport.readBytes(sniff_len)] |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
716 if not buf[0]: |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
717 raise WatchmanError("empty watchman response") |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
718 |
30656
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
719 _1, _2, elen = bser.pdu_info(buf[0]) |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
720 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
721 rlen = len(buf[0]) |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
722 while elen > rlen: |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
723 buf.append(self.transport.readBytes(elen - rlen)) |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
724 rlen += len(buf[-1]) |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
725 |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
726 response = b"".join(buf) |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
727 try: |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
728 res = self._loads(response) |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
729 return res |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
730 except ValueError as e: |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
731 raise WatchmanError("watchman response decode error: %s" % e) |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
732 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
733 def send(self, *args): |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
734 cmd = bser.dumps(*args) # Defaults to BSER v1 |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
735 self.transport.write(cmd) |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
736 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
737 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
738 class ImmutableBserCodec(BserCodec): |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
43387
diff
changeset
|
739 """use the BSER encoding, decoding values using the newer |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
43387
diff
changeset
|
740 immutable object support""" |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
741 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
742 def _loads(self, response): |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
743 return bser.loads( |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
744 response, |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
745 False, |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
746 value_encoding=self._value_encoding, |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
747 value_errors=self._value_errors, |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
748 ) |
30656
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
749 |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
750 |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
751 class Bser2WithFallbackCodec(BserCodec): |
47062
f38bf44e077f
black: make codebase compatible with black v21.4b2 and v20.8b1
Kyle Lippincott <spectral@google.com>
parents:
45942
diff
changeset
|
752 """use BSER v2 encoding""" |
30656
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
753 |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
754 def __init__(self, transport, value_encoding, value_errors): |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
755 super(Bser2WithFallbackCodec, self).__init__( |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
756 transport, value_encoding, value_errors |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
757 ) |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
758 if compat.PYTHON3: |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
759 bserv2_key = "required" |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
760 else: |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
761 bserv2_key = "optional" |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
762 |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
763 self.send(["version", {bserv2_key: ["bser-v2"]}]) |
30656
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
764 |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
765 capabilities = self.receive() |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
766 |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
767 if "error" in capabilities: |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
768 raise BSERv1Unsupported( |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
769 "The watchman server version does not support Python 3. Please " |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
770 "upgrade your watchman server." |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
771 ) |
30656
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
772 |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
773 if capabilities["capabilities"]["bser-v2"]: |
30656
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
774 self.bser_version = 2 |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
775 self.bser_capabilities = 0 |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
776 else: |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
777 self.bser_version = 1 |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
778 self.bser_capabilities = 0 |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
779 |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
780 def receive(self): |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
781 buf = [self.transport.readBytes(sniff_len)] |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
782 if not buf[0]: |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
783 raise WatchmanError("empty watchman response") |
30656
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
784 |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
785 recv_bser_version, recv_bser_capabilities, elen = bser.pdu_info(buf[0]) |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
786 |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
787 if hasattr(self, "bser_version"): |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
788 # Readjust BSER version and capabilities if necessary |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
789 self.bser_version = max(self.bser_version, recv_bser_version) |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
790 self.capabilities = self.bser_capabilities & recv_bser_capabilities |
30656
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
791 |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
792 rlen = len(buf[0]) |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
793 while elen > rlen: |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
794 buf.append(self.transport.readBytes(elen - rlen)) |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
795 rlen += len(buf[-1]) |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
796 |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
797 response = b"".join(buf) |
30656
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
798 try: |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
799 res = self._loads(response) |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
800 return res |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
801 except ValueError as e: |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
802 raise WatchmanError("watchman response decode error: %s" % e) |
30656
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
803 |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
804 def send(self, *args): |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
805 if hasattr(self, "bser_version"): |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
806 cmd = bser.dumps( |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
807 *args, |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
808 version=self.bser_version, |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
809 capabilities=self.bser_capabilities |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
810 ) |
30656
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
811 else: |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
812 cmd = bser.dumps(*args) |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
813 self.transport.write(cmd) |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
814 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
815 |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
816 class ImmutableBser2Codec(Bser2WithFallbackCodec, ImmutableBserCodec): |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
43387
diff
changeset
|
817 """use the BSER encoding, decoding values using the newer |
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
43387
diff
changeset
|
818 immutable object support""" |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
819 |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
820 pass |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
821 |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
822 |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
823 class JsonCodec(Codec): |
47062
f38bf44e077f
black: make codebase compatible with black v21.4b2 and v20.8b1
Kyle Lippincott <spectral@google.com>
parents:
45942
diff
changeset
|
824 """Use json codec. This is here primarily for testing purposes""" |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
825 |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
826 json = None |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
827 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
828 def __init__(self, transport): |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
829 super(JsonCodec, self).__init__(transport) |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
830 # optional dep on json, only if JsonCodec is used |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
831 import json |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
832 |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
833 self.json = json |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
834 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
835 def receive(self): |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
836 line = self.transport.readLine() |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
837 try: |
30656
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
838 # In Python 3, json.loads is a transformation from Unicode string to |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
839 # objects possibly containing Unicode strings. We typically expect |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
840 # the JSON blob to be ASCII-only with non-ASCII characters escaped, |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
841 # but it's possible we might get non-ASCII bytes that are valid |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
842 # UTF-8. |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
843 if compat.PYTHON3: |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
844 line = line.decode("utf-8") |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
845 return self.json.loads(line) |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
846 except Exception as e: |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
847 print(e, line) |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
848 raise |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
849 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
850 def send(self, *args): |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
851 cmd = self.json.dumps(*args) |
30656
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
852 # In Python 3, json.dumps is a transformation from objects possibly |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
853 # containing Unicode strings to Unicode string. Even with (the default) |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
854 # ensure_ascii=True, dumps returns a Unicode string. |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
855 if compat.PYTHON3: |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
856 cmd = cmd.encode("ascii") |
30656
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
857 self.transport.write(cmd + b"\n") |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
858 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
859 |
48946
642e31cb55f0
py3: use class X: instead of class X(object):
Gregory Szorc <gregory.szorc@gmail.com>
parents:
48875
diff
changeset
|
860 class client: |
47062
f38bf44e077f
black: make codebase compatible with black v21.4b2 and v20.8b1
Kyle Lippincott <spectral@google.com>
parents:
45942
diff
changeset
|
861 """Handles the communication with the watchman service""" |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
862 |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
863 sockpath = None |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
864 transport = None |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
865 sendCodec = None |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
866 recvCodec = None |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
867 sendConn = None |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
868 recvConn = None |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
869 subs = {} # Keyed by subscription name |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
870 sub_by_root = {} # Keyed by root, then by subscription name |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
871 logs = [] # When log level is raised |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
872 unilateral = ["log", "subscription"] |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
873 tport = None |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
874 useImmutableBser = None |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
875 pid = None |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
876 |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
877 def __init__( |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
878 self, |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
879 sockpath=None, |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
880 timeout=1.0, |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
881 transport=None, |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
882 sendEncoding=None, |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
883 recvEncoding=None, |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
884 useImmutableBser=False, |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
885 # use False for these two because None has a special |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
886 # meaning |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
887 valueEncoding=False, |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
888 valueErrors=False, |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
889 binpath=None, |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
890 ): |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
891 self.sockpath = sockpath |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
892 self.timeout = timeout |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
893 self.useImmutableBser = useImmutableBser |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
894 self.binpath = _default_binpath(binpath) |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
895 |
30656
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
896 if inspect.isclass(transport) and issubclass(transport, Transport): |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
897 self.transport = transport |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
898 else: |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
899 transport = transport or os.getenv("WATCHMAN_TRANSPORT") or "local" |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
900 if transport == "local" and os.name == "nt": |
30656
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
901 self.transport = WindowsNamedPipeTransport |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
902 elif transport == "local": |
30656
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
903 self.transport = UnixSocketTransport |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
904 elif transport == "cli": |
30656
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
905 self.transport = CLIProcessTransport |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
906 if sendEncoding is None: |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
907 sendEncoding = "json" |
30656
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
908 if recvEncoding is None: |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
909 recvEncoding = sendEncoding |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
910 else: |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
911 raise WatchmanError("invalid transport %s" % transport) |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
912 |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
913 sendEncoding = str( |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
914 sendEncoding or os.getenv("WATCHMAN_ENCODING") or "bser" |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
915 ) |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
916 recvEncoding = str( |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
917 recvEncoding or os.getenv("WATCHMAN_ENCODING") or "bser" |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
918 ) |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
919 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
920 self.recvCodec = self._parseEncoding(recvEncoding) |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
921 self.sendCodec = self._parseEncoding(sendEncoding) |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
922 |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
923 # We want to act like the native OS methods as much as possible. This |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
924 # means returning bytestrings on Python 2 by default and Unicode |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
925 # strings on Python 3. However we take an optional argument that lets |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
926 # users override this. |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
927 if valueEncoding is False: |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
928 if compat.PYTHON3: |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
929 self.valueEncoding = encoding.get_local_encoding() |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
930 self.valueErrors = encoding.default_local_errors |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
931 else: |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
932 self.valueEncoding = None |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
933 self.valueErrors = None |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
934 else: |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
935 self.valueEncoding = valueEncoding |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
936 if valueErrors is False: |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
937 self.valueErrors = encoding.default_local_errors |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
938 else: |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
939 self.valueErrors = valueErrors |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
940 |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
941 def _makeBSERCodec(self, codec): |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
942 def make_codec(transport): |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
943 return codec(transport, self.valueEncoding, self.valueErrors) |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
944 |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
945 return make_codec |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
946 |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
947 def _parseEncoding(self, enc): |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
948 if enc == "bser": |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
949 if self.useImmutableBser: |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
950 return self._makeBSERCodec(ImmutableBser2Codec) |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
951 return self._makeBSERCodec(Bser2WithFallbackCodec) |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
952 elif enc == "bser-v1": |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
953 if compat.PYTHON3: |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
954 raise BSERv1Unsupported( |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
955 "Python 3 does not support the BSER v1 encoding: specify " |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
956 '"bser" or omit the sendEncoding and recvEncoding ' |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
957 "arguments" |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
958 ) |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
959 if self.useImmutableBser: |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
960 return self._makeBSERCodec(ImmutableBserCodec) |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
961 return self._makeBSERCodec(BserCodec) |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
962 elif enc == "json": |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
963 return JsonCodec |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
964 else: |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
965 raise WatchmanError("invalid encoding %s" % enc) |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
966 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
967 def _hasprop(self, result, name): |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
968 if self.useImmutableBser: |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
969 return hasattr(result, name) |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
970 return name in result |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
971 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
972 def _resolvesockname(self): |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
973 # if invoked via a trigger, watchman will set this env var; we |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
974 # should use it unless explicitly set otherwise |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
975 path = os.getenv("WATCHMAN_SOCK") |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
976 if path: |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
977 return path |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
978 |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
979 cmd = [self.binpath, "--output-encoding=bser", "get-sockname"] |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
980 try: |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
981 args = dict( |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
982 stdout=subprocess.PIPE, stderr=subprocess.PIPE |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
983 ) # noqa: C408 |
30656
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
984 |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
985 if os.name == "nt": |
30656
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
986 # if invoked via an application with graphical user interface, |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
987 # this call will cause a brief command window pop-up. |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
988 # Using the flag STARTF_USESHOWWINDOW to avoid this behavior. |
49857
ab32fd8412a7
typing: disable a few incorrect warnings in pywatchman
Matt Harbison <matt_harbison@yahoo.com>
parents:
49856
diff
changeset
|
989 |
ab32fd8412a7
typing: disable a few incorrect warnings in pywatchman
Matt Harbison <matt_harbison@yahoo.com>
parents:
49856
diff
changeset
|
990 # pytype: disable=module-attr |
30656
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
991 startupinfo = subprocess.STARTUPINFO() |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
992 startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW |
49857
ab32fd8412a7
typing: disable a few incorrect warnings in pywatchman
Matt Harbison <matt_harbison@yahoo.com>
parents:
49856
diff
changeset
|
993 # pytype: enable=module-attr |
ab32fd8412a7
typing: disable a few incorrect warnings in pywatchman
Matt Harbison <matt_harbison@yahoo.com>
parents:
49856
diff
changeset
|
994 |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
995 args["startupinfo"] = startupinfo |
30656
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
996 |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
997 p = subprocess.Popen(cmd, **args) |
30656
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
998 |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
999 except OSError as e: |
43387
9eed959cd8ae
fsmonitor: reapply dd35abc409ee
Gregory Szorc <gregory.szorc@gmail.com>
parents:
43385
diff
changeset
|
1000 raise WatchmanError('"watchman" executable not in PATH (%s)' % e) |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1001 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1002 stdout, stderr = p.communicate() |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1003 exitcode = p.poll() |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1004 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1005 if exitcode: |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1006 raise WatchmanError("watchman exited with code %d" % exitcode) |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1007 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1008 result = bser.loads(stdout) |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
1009 if "error" in result: |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
1010 raise WatchmanError("get-sockname error: %s" % result["error"]) |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1011 |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
1012 return result["sockname"] |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1013 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1014 def _connect(self): |
47062
f38bf44e077f
black: make codebase compatible with black v21.4b2 and v20.8b1
Kyle Lippincott <spectral@google.com>
parents:
45942
diff
changeset
|
1015 """establish transport connection""" |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1016 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1017 if self.recvConn: |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
1018 if self.pid != os.getpid(): |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
1019 raise UseAfterFork( |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
1020 "do not re-use a connection after fork; open a new client instead" |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
1021 ) |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1022 return |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1023 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1024 if self.sockpath is None: |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1025 self.sockpath = self._resolvesockname() |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1026 |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
1027 kwargs = {} |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
1028 if self.transport == CLIProcessTransport: |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
1029 kwargs["binpath"] = self.binpath |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
1030 |
49857
ab32fd8412a7
typing: disable a few incorrect warnings in pywatchman
Matt Harbison <matt_harbison@yahoo.com>
parents:
49856
diff
changeset
|
1031 # Only CLIProcessTransport has the binpath kwarg |
ab32fd8412a7
typing: disable a few incorrect warnings in pywatchman
Matt Harbison <matt_harbison@yahoo.com>
parents:
49856
diff
changeset
|
1032 # pytype: disable=wrong-keyword-args |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
1033 self.tport = self.transport(self.sockpath, self.timeout, **kwargs) |
49857
ab32fd8412a7
typing: disable a few incorrect warnings in pywatchman
Matt Harbison <matt_harbison@yahoo.com>
parents:
49856
diff
changeset
|
1034 # pytype: enable=wrong-keyword-args |
ab32fd8412a7
typing: disable a few incorrect warnings in pywatchman
Matt Harbison <matt_harbison@yahoo.com>
parents:
49856
diff
changeset
|
1035 |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1036 self.sendConn = self.sendCodec(self.tport) |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1037 self.recvConn = self.recvCodec(self.tport) |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
1038 self.pid = os.getpid() |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1039 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1040 def __del__(self): |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1041 self.close() |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1042 |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
1043 def __enter__(self): |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
1044 self._connect() |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
1045 return self |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
1046 |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
1047 def __exit__(self, exc_type, exc_value, exc_traceback): |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
1048 self.close() |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
1049 |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1050 def close(self): |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1051 if self.tport: |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1052 self.tport.close() |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1053 self.tport = None |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1054 self.recvConn = None |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1055 self.sendConn = None |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1056 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1057 def receive(self): |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
43387
diff
changeset
|
1058 """receive the next PDU from the watchman service |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1059 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1060 If the client has activated subscriptions or logs then |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1061 this PDU may be a unilateral PDU sent by the service to |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1062 inform the client of a log event or subscription change. |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1063 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1064 It may also simply be the response portion of a request |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1065 initiated by query. |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1066 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1067 There are clients in production that subscribe and call |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1068 this in a loop to retrieve all subscription responses, |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1069 so care should be taken when making changes here. |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1070 """ |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1071 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1072 self._connect() |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1073 result = self.recvConn.receive() |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
1074 if self._hasprop(result, "error"): |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
1075 raise CommandError(result["error"]) |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1076 |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
1077 if self._hasprop(result, "log"): |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
1078 self.logs.append(result["log"]) |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1079 |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
1080 if self._hasprop(result, "subscription"): |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
1081 sub = result["subscription"] |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1082 if not (sub in self.subs): |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1083 self.subs[sub] = [] |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1084 self.subs[sub].append(result) |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1085 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1086 # also accumulate in {root,sub} keyed store |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
1087 root = os.path.normpath(os.path.normcase(result["root"])) |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1088 if not root in self.sub_by_root: |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1089 self.sub_by_root[root] = {} |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1090 if not sub in self.sub_by_root[root]: |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1091 self.sub_by_root[root][sub] = [] |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1092 self.sub_by_root[root][sub].append(result) |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1093 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1094 return result |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1095 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1096 def isUnilateralResponse(self, res): |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
1097 if "unilateral" in res and res["unilateral"]: |
30656
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
1098 return True |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
1099 # Fall back to checking for known unilateral responses |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1100 for k in self.unilateral: |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1101 if k in res: |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1102 return True |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1103 return False |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1104 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1105 def getLog(self, remove=True): |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
43387
diff
changeset
|
1106 """Retrieve buffered log data |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1107 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1108 If remove is true the data will be removed from the buffer. |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1109 Otherwise it will be left in the buffer |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1110 """ |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1111 res = self.logs |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1112 if remove: |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1113 self.logs = [] |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1114 return res |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1115 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1116 def getSubscription(self, name, remove=True, root=None): |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
43387
diff
changeset
|
1117 """Retrieve the data associated with a named subscription |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1118 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1119 If remove is True (the default), the subscription data is removed |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1120 from the buffer. Otherwise the data is returned but left in |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1121 the buffer. |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1122 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1123 Returns None if there is no data associated with `name` |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1124 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1125 If root is not None, then only return the subscription |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1126 data that matches both root and name. When used in this way, |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1127 remove processing impacts both the unscoped and scoped stores |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1128 for the subscription data. |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1129 """ |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1130 if root is not None: |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
1131 root = os.path.normpath(os.path.normcase(root)) |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
1132 if root not in self.sub_by_root: |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1133 return None |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
1134 if name not in self.sub_by_root[root]: |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1135 return None |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1136 sub = self.sub_by_root[root][name] |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1137 if remove: |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1138 del self.sub_by_root[root][name] |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1139 # don't let this grow unbounded |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1140 if name in self.subs: |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1141 del self.subs[name] |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1142 return sub |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1143 |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
1144 if name not in self.subs: |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1145 return None |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1146 sub = self.subs[name] |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1147 if remove: |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1148 del self.subs[name] |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1149 return sub |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1150 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1151 def query(self, *args): |
45942
89a2afe31e82
formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents:
43387
diff
changeset
|
1152 """Send a query to the watchman service and return the response |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1153 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1154 This call will block until the response is returned. |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1155 If any unilateral responses are sent by the service in between |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1156 the request-response they will be buffered up in the client object |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1157 and NOT returned via this method. |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1158 """ |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1159 |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
1160 log("calling client.query") |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1161 self._connect() |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1162 try: |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1163 self.sendConn.send(args) |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1164 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1165 res = self.receive() |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1166 while self.isUnilateralResponse(res): |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1167 res = self.receive() |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1168 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1169 return res |
30656
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
1170 except EnvironmentError as ee: |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
1171 # When we can depend on Python 3, we can use PEP 3134 |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
1172 # exception chaining here. |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
1173 raise WatchmanEnvironmentError( |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
1174 "I/O error communicating with watchman daemon", |
30656
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
1175 ee.errno, |
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
1176 ee.strerror, |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
1177 args, |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
1178 ) |
30656
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
1179 except WatchmanError as ex: |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1180 ex.setCommand(args) |
30656
16f4b341288d
fsmonitor: refresh pywatchman to upstream
Zack Hricz <zphricz@fb.com>
parents:
28432
diff
changeset
|
1181 raise |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1182 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1183 def capabilityCheck(self, optional=None, required=None): |
47062
f38bf44e077f
black: make codebase compatible with black v21.4b2 and v20.8b1
Kyle Lippincott <spectral@google.com>
parents:
45942
diff
changeset
|
1184 """Perform a server capability check""" |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
1185 res = self.query( |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
1186 "version", {"optional": optional or [], "required": required or []} |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
1187 ) |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1188 |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
1189 if not self._hasprop(res, "capabilities"): |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1190 # Server doesn't support capabilities, so we need to |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1191 # synthesize the results based on the version |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1192 capabilities.synthesize(res, optional) |
43385
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
1193 if "error" in res: |
6469c23a40a2
fsmonitor: refresh pywatchman with upstream
Gregory Szorc <gregory.szorc@gmail.com>
parents:
41968
diff
changeset
|
1194 raise CommandError(res["error"]) |
28432
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1195 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1196 return res |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1197 |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1198 def setTimeout(self, value): |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1199 self.recvConn.setTimeout(value) |
2377c4ac4eec
fsmonitor: dependencies for new experimental extension
Martijn Pieters <mjpieters@fb.com>
parents:
diff
changeset
|
1200 self.sendConn.setTimeout(value) |