예제 #1
0
def ilock(k=None):
    i = Closure(lambda: frames(back=4)[0].f_locals['args'][0])

    def lock(generics):
        return Lock(i, k=k)(generics)

    return lock
예제 #2
0
def mthrow(r=None):
    m = frames(back=1).module()

    def throw(generics):
        return Throw(m)(generics, r=r)

    return throw
예제 #3
0
def ithrow(r=None):
    i = Closure(lambda: frames(back=3)[0].f_locals['args'][0])

    def throw(generics):
        return Throw(i)(generics, r=r)

    return throw
예제 #4
0
def mlock(k=None):
    m = frames(back=1).module()

    def lock(generics):
        return Lock(m, k=k)(generics)

    return lock
예제 #5
0
파일: _requests.py 프로젝트: ytig/python
 def prepare_request(self, *args, **kwargs):
     ret = super().prepare_request(*args, **kwargs)
     with frames(keep=lambda f: f.f_code is Socket.request.__code__) as f:
         if f.has():
             for plug in f[0].f_locals['plugs']:
                 plug.prepare(self, ret)
     return ret
예제 #6
0
 def join(*exceptions):
     start = 'The exceptions are displayed below.\n\n'
     end = '\n\n...Display completed.'
     strings = []
     for v in exceptions:
         t = type(v)
         assert issubclass(t, BaseException)
         try:
             string = ''
             if issubclass(t, MultiException):
                 s = str(v)
                 string += s[len(start):len(s) - len(end)]
             elif issubclass(t, SyntaxError):
                 string += '  File "{}", line {}\n'.format(
                     v.filename, v.lineno)
                 string += '    {}\n'.format(v.text.strip())
                 if v.offset is not None:
                     s = v.text.rstrip('\n')
                     string += '    {}^\n'.format(''.join([
                         (c.isspace() and c or ' ')
                         for c in s[:min(len(s), v.offset) - 1].lstrip()
                     ]))
                 if t.__module__ not in (
                         '__main__',
                         'builtins',
                 ):
                     string += t.__module__ + '.'
                 string += t.__qualname__
                 string += ': ' + (v.msg or '<no detail available>')
             else:
                 with frames(make=frames.traceback(v)) as f:
                     if f.has():
                         string += '  File "{}", line {}, in {}\n'.format(
                             f[0].f_code.co_filename, f[0].f_lineno,
                             f[0].f_code.co_name)
                         string += '    {}\n'.format(
                             linecache.getline(f[0].f_code.co_filename,
                                               f[0].f_lineno).strip())
                 if t.__module__ not in (
                         '__main__',
                         'builtins',
                 ):
                     string += t.__module__ + '.'
                 string += t.__qualname__
                 try:
                     s = str(v)
                 except BaseException:
                     s = '<unprintable %s object>' % t.__name__
                 if s:
                     string += ': ' + s
             if string:
                 strings.append(string)
         except BaseException:
             pass
     return start + '\n\n'.join(strings) + end
예제 #7
0
 def __enter__(self):
     with frames(back=1) as f:
         assert f.has()
         xid = 'X:' + f[0].f_code.co_filename + '/' + str(f[0].f_lineno)
     self.stack.append(xid)
     return xid in self.__throw