-
Notifications
You must be signed in to change notification settings - Fork 230
/
Copy pathos_patches.py
128 lines (95 loc) · 2.29 KB
/
os_patches.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# -*- coding: utf-8 -*-
"""this module contains the patches for the os module."""
from mlpatches.base import FunctionPatch, PatchGroup
from mlpatches.os_popen import popen, popen2, popen3, popen4, system
from mlpatches.os_process import getpid, getppid, kill
# define patches
class PopenPatch(FunctionPatch):
PY2 = True
PY3 = False
module = "os"
function = "popen"
replacement = popen
class Popen2Patch(FunctionPatch):
PY2 = True
PY3 = False
module = "os"
function = "popen2"
replacement = popen2
class Popen3Patch(FunctionPatch):
PY2 = True
PY3 = False
module = "os"
function = "popen3"
replacement = popen3
class Popen4Patch(FunctionPatch):
PY2 = True
PY3 = False
module = "os"
function = "popen4"
replacement = popen4
class SystemPatch(FunctionPatch):
PY2 = True
PY3 = False
module = "os"
function = "system"
replacement = system
class GetpidPatch(FunctionPatch):
PY2 = True
PY3 = True
module = "os"
function = "getpid"
replacement = getpid
class GetppidPatch(FunctionPatch):
PY2 = True
PY3 = True
module = "os"
function = "getppid"
replacement = getppid
class KillPatch(FunctionPatch):
PY2 = True
PY3 = True
module = "os"
function = "kill"
replacement = kill
# create patch instances
POPEN_PATCH = PopenPatch()
POPEN2_PATCH = Popen2Patch()
POPEN3_PATCH = Popen3Patch()
POPEN4_PATCH = Popen4Patch()
SYSTEM_PATCH = SystemPatch()
GETPID_PATCH = GetpidPatch()
GETPPID_PATCH = GetppidPatch()
KILL_PATCH = KillPatch()
# define groups
class PopenPatches(PatchGroup):
"""all popen patches."""
patches = [
POPEN_PATCH,
POPEN2_PATCH,
POPEN3_PATCH,
POPEN4_PATCH,
]
class ProcessingPatches(PatchGroup):
"""all patches to emulate prcessing behavior"""
patches = [
GETPID_PATCH,
GETPPID_PATCH,
KILL_PATCH,
]
class OsPatches(PatchGroup):
"""all os patches."""
patches = [
POPEN_PATCH,
POPEN2_PATCH,
POPEN3_PATCH,
POPEN4_PATCH,
SYSTEM_PATCH,
GETPID_PATCH,
GETPPID_PATCH,
KILL_PATCH,
]
# create group instances
POPEN_PATCHES = PopenPatches()
OS_PATCHES = OsPatches()
PROCESSING_PATCHES = ProcessingPatches()