Skip to content

Commit f67e9cb

Browse files
committed
Initial commit
0 parents  commit f67e9cb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+10068
-0
lines changed

LICENSE

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2002-2011 IronPort Systems and Cisco Systems
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in
11+
all copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19+
SOFTWARE.

README

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
This directory contains the "aplib" python package. It contains a collection
2+
of random, generic modules. The general criteria for a module being included
3+
here is that it is too small to justify tracking it as a separate component,
4+
and it is shared between different groups/products.
5+
6+
These modules were developed at IronPort Systems and have been provided by
7+
Cisco Systems under an MIT license.

aplib/__init__.py

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Copyright (c) 2002-2011 IronPort Systems and Cisco Systems
2+
#
3+
# Permission is hereby granted, free of charge, to any person obtaining a copy
4+
# of this software and associated documentation files (the "Software"), to deal
5+
# in the Software without restriction, including without limitation the rights
6+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
# copies of the Software, and to permit persons to whom the Software is
8+
# furnished to do so, subject to the following conditions:
9+
#
10+
# The above copyright notice and this permission notice shall be included in
11+
# all copies or substantial portions of the Software.
12+
#
13+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19+
# SOFTWARE.

aplib/aplib.oserrors.pyx

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Copyright (c) 2002-2011 IronPort Systems and Cisco Systems
2+
#
3+
# Permission is hereby granted, free of charge, to any person obtaining a copy
4+
# of this software and associated documentation files (the "Software"), to deal
5+
# in the Software without restriction, including without limitation the rights
6+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
# copies of the Software, and to permit persons to whom the Software is
8+
# furnished to do so, subject to the following conditions:
9+
#
10+
# The above copyright notice and this permission notice shall be included in
11+
# all copies or substantial portions of the Software.
12+
#
13+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19+
# SOFTWARE.
20+
21+
# $Header: //prod/main/ap/aplib/aplib/aplib.oserrors.pyx#2 $
22+
23+
"""OSError mapping.
24+
25+
This module maps OSErrors to specific, catchable exceptions. For example, an
26+
OSError with an errno of ENOENT will be raised as the ENOENT exception. All
27+
exceptions derive from OSError, so it is compatible with regular OSError
28+
handling.
29+
"""
30+
31+
include "python.pxi"
32+
33+
import errno
34+
import new
35+
import sys
36+
cimport libc
37+
38+
err_map = {}
39+
40+
def map_exception(e):
41+
"""Raise an errno-specific exception.
42+
43+
:Parameters:
44+
- `e`: The OSError instance.
45+
"""
46+
# Ignoring e.filename since it seems less than useful to me.
47+
try:
48+
raise err_map[e.errno](e.errno, e.strerror)
49+
except KeyError:
50+
raise e
51+
52+
def raise_oserror(int error_number):
53+
"""Raise an OSError exception by errno.
54+
55+
:Parameters:
56+
- `error_number`: The errno value to raise.
57+
"""
58+
map_exception(OSError(error_number, libc.strerror(error_number)))
59+
60+
__m = sys.modules['aplib.oserrors']
61+
__g = __m.__dict__
62+
for errcode, errname in errno.errorcode.items():
63+
# Not sure why __module__ is not getting set properly. Python looks at
64+
# globals() to fine __name__ to set the value, and it appears to be
65+
# set to __main__ for some odd reason.
66+
c = new.classobj(errname, (OSError,), {'__module__': 'aplib.oserrors'})
67+
err_map[errcode] = c
68+
__g[errname] = c

0 commit comments

Comments
 (0)