Beispiel #1
0
 def __getattr__(self, name):
     value = super(API, self).__getattr__(name)
     if (value is None) or (value == []):
         l = ListWrapper(self.keys())
         x = l.findFirstContaining(
             API.make_key(
                 name.split(API.make_key('', ''))[-1], APIVersion1001.
                 __version__) if (
                     name.startswith('/') and name.endswith('/')) else name)
         if (x > -1):
             return super(API, self).__getattr__(l[x])
         else:
             return super(APIVersion1001, self).__getattr__(name)
     return value
Beispiel #2
0
    def process(self, html=None):
        l = lists.HashedLists()
        n = 1

        def recurse_into(aTag, _list=lists.HashedLists(), n=1):
            is_tag = lambda t: (misc.ObjectTypeName.typeClassName(t) ==
                                'BeautifulSoup.Tag')
            is_valid_tag = lambda t: (t.name in ['table', 'tr', 'th', 'td'])
            if (is_tag(aTag)) and (is_valid_tag(aTag)):
                for aKid in aTag.childGenerator() if (
                        is_valid_tag(aTag)) else []:
                    if (is_tag(aKid)):
                        print misc.ObjectTypeName.typeClassName(
                            aKid), aKid.name,
                        if (aKid.name == 'table'):
                            recurse_into(aKid, _list=_list, n=n)
                        elif (aKid.name == 'tr'):
                            n += 1
                            print
                            recurse_into(aKid, _list=_list, n=n)
                        elif (aKid.name in ['th', 'td']):
                            data = aKid.contents if (misc.isList(
                                aKid.contents)) and (len(
                                    aKid.contents) == 1) else [
                                        misc.unpack([
                                            t for t in aKid.contents
                                            if (not is_tag(t))
                                        ])
                                    ]
                            print data
                            _list['%s' % (n)] = data
            return

        if (html is not None):
            self.html = _utils.ascii_only(html)
        soup = BeautifulSoup.BeautifulSoup(self.html)
        tables = soup.findAll('table')
        for aTable in tables:
            recurse_into(aTable, _list=l, n=n)
        print '=' * 40
        keys = misc.sortCopy([int(k) for k in l.keys()])
        items = ListWrapper()
        for k in keys:
            _items = l['%s' % (k)]
            items.append([_items])
        return items
Beispiel #3
0
    def parseMessage(self, data):
        from vyperlogix.lists.ListWrapper import ListWrapper

        def fuzzyCompare(_item, s_search):
            f = lambda _item, s_search: _item.lower().find(s_search.lower()
                                                           ) > -1
            does_match = f(_item, s_search)
            return does_match

        def emptyCompare(_item, s_search):
            f = lambda _item, s_search: str(_item).strip() == s_search
            does_match = f(_item, s_search)
            return does_match

        def parse_for_target(_toks, _target, callback=None):
            _val = ''
            i = _toks.findFirstContaining(_target, callback=callback)
            if (i > -1):
                _val = [_toks[i].split(_target)[-1]]
            return _val

        toks = ListWrapper(data.split('\n'))

        d = lists.HashedLists2()

        _f = toks.findFirstContaining('', callback=emptyCompare)
        if (_f > -1):
            _f -= 1

        d[const_headers_symbol] = tuple([t.strip() for t in toks[0:_f]])
        d[const_body_symbol] = tuple([t.strip() for t in toks[_f + 1:]])

        d[const_from_symbol] = parse_for_target(toks,
                                                const_from_symbol,
                                                callback=fuzzyCompare)

        d[const_to_symbol] = parse_for_target(toks,
                                              const_to_symbol,
                                              callback=fuzzyCompare)

        d[const_subject_symbol] = parse_for_target(toks,
                                                   const_subject_symbol,
                                                   callback=fuzzyCompare)

        return d
Beispiel #4
0
 def __getattr__(self, name):
     value = super(API, self).__getattr__(name)
     if (value is None) or (len(value) == 0):  # and (name != '/'):
         _d_ = HashedFuzzySmartLists({})
         _values_ = []
         for k in self.keys():
             if (misc.isDict(super(API, self).__getattr__(k))) and (super(
                     API, self).__getattr__(k).has_key('url')):
                 _k_ = super(API, self).__getattr__(k)['url'].replace(
                     '/' + k.split('@')[0], '')
                 _d_[_k_] = SmartFuzzyObject(
                     super(API, self).__getattr__(k))
         l = ListWrapper(_d_.keys())
         _name_ = name.split(API.make_key('', ''))[-1]
         if (not self.__specific__):
             while (len(_name_) > 0):
                 _list_ = l.findAllContaining(_name_) if (
                     _name_ != '/') else l.findAllMatching(_name_)
                 _items_ = [
                     item for item in _list_ if (item.endswith(_name_))
                 ]
                 x = l.findFirstMatching(_items_[0] if (
                     len(_items_) > 0) else _name_) if (
                         (len(_list_) > 0) or
                         (_name_ == '/')) else l.findFirstContaining(
                             _items_[0] if (len(_items_) > 0) else _name_)
                 if (x > -1):
                     for v in _d_[l[x]]:
                         _values_.append(v)
                     break
                 else:
                     x = l.findFirstContaining(_name_)
                     if (x > -1):
                         for v in _d_[l[x]]:
                             _values_.append(v)
                         break
                     else:
                         _l_ = _name_.split('/')
                         del _l_[-2 if (len(_l_[-1]) == 0) else -1]
                         _name_ = '/'.join(_l_)
     return value if (len(_values_) == 0) else _values_
Beispiel #5
0
def crontab(config,
            jsonHandler=None,
            callback=None,
            logging_callback=None,
            default=None,
            threaded=False):
    import os, sys, time, signal
    from vyperlogix.misc import _utils
    from vyperlogix.process.shell import SmartShell
    from vyperlogix.lists.ListWrapper import ListWrapper

    normalize = lambda items: [
        s for s in [
            ''.join(ll[0:ll.findFirstMatching('#') if
                       (ll.findFirstMatching('#') > -1) else len(ll)]).strip()
            for ll in [ListWrapper(l) for l in items if (len(l) > 0)]
        ] if (len(s) > 0)
    ]

    def __logger__(msg):
        if (callable(logging_callback)):
            try:
                logging_callback(msg)
            except:
                pass

    def __crontab__(config,
                    jsonHandler=jsonHandler,
                    callback=callback,
                    logging_callback=logging_callback,
                    default=default):
        __lines__ = ''

        __logger__(
            'INFO.1.1: verbose="%s" (%s).' %
            (config.verbose, ObjectTypeName.typeClassName(config.verbose)))
        try:
            __logger__('INFO.1.2: config="%s".' % (config))
            if (config.verbose):
                __logger__('INFO.1.3: JSON FPath ?: "%s".' %
                           (config.jsonFpath))
            if (callable(jsonHandler)):
                try:
                    __config__ = jsonHandler(config.jsonFpath)
                except Exception as ex:
                    __config__ = SmartObject()
            __file__ = config.schedulefpath if (misc.isStringValid(
                config.schedulefpath)) else None
            if (config.verbose):
                __logger__('INFO.1.4: Crontab ?: "%s".' % (__file__))
            if (os.path.exists(__file__)):
                if (config.verbose):
                    __logger__('INFO.1.5: Crontab Exists: "%s".' % (__file__))
                __lines__ = _utils._readFileFrom(__file__)
                if (config.verbose):
                    __logger__('INFO.1.6: Crontab Content: "%s".' %
                               (__lines__))
        except Exception as ex:
            __logger__('EXCEPTION.1: "%s".' %
                       (_utils.formattedException(details=ex)))

        __logger__('INFO.1.6.1: config.isRunning="%s".' % (config.isRunning))
        while (config.isRunning and threaded):
            jobs = [
                CronExpression(__line__) for __line__ in normalize(__lines__)
                if (misc.isStringValid(__line__))
            ]
            config.isRunning = callback(jobs) if (callable(callback)) else True
            if (config.isRunning):
                for job in jobs:
                    if (config.verbose):
                        __logger__('INFO.1.7: Job: "%s".' % (job))
                    if job.check_trigger(time.gmtime(time.time())[:5]):
                        if (config.dryrun):
                            __logger__('INFO.1.8: Execute: %s' % (job.comment))
                        else:
                            import tempfile
                            __cmd__ = tempfile.NamedTemporaryFile().name
                            __sysout__ = _utils.stringIO()

                            def __callback__(ss, data=None):
                                global __begin__
                                if (data) and (misc.isString(data)) and (
                                        len(data) > 0):
                                    __logger__('INFO.1.9: %s' % (data))
                                return

                            def __onExit__(ss):
                                __logger__('INFO.1.10: __onExit__')
                                __logger__('INFO.1.11: %s' %
                                           (__sysout__.getvalue()))
                                if (os.path.exists(__cmd__)):
                                    os.remove(__cmd__)

                            wfHandle = open(__cmd__, 'w')
                            print >> wfHandle, '@echo on\n'
                            print >> wfHandle, '%s\n' % (job.comment)
                            wfHandle.flush()
                            wfHandle.close()
                            ss = SmartShell(__cmd__,
                                            callback=__callback__,
                                            isDebugging=True,
                                            onExit=__onExit__,
                                            sysout=__sysout__)
                            ss.execute()

                if (threaded):
                    if (config.verbose):
                        __logger__('INFO.1.12: Sleeping for %s secs...' %
                                   (config.resolution))
                    time.sleep(config.resolution if (
                        isinstance(config.resolution, float)
                        or isinstance(config.resolution, int)) else 60)

                    if (callable(jsonHandler)):
                        try:
                            __config__ = jsonHandler(config.jsonFpath)
                        except Exception as ex:
                            __config__ = SmartObject()
                    __file__ = config.schedulefpath if (misc.isStringValid(
                        config.schedulefpath)) else None
                    if (os.path.exists(__file__)):
                        if (config.verbose):
                            __logger__('INFO.1.13: Crontab Exists: "%s".' %
                                       (__file__))
                        __lines__ = _utils._readFileFrom(__file__)
                        if (config.verbose):
                            __logger__('INFO.1.14: Crontab Content: "%s".' %
                                       (__lines__))
        else:
            __logger__(
                'WARNING.1.15: Cannot execute crontab unless threaded is %s (true).'
                % (threaded))
        return config.isRunning

    __logger__('INFO.1: threaded="%s".' % (threaded))
    if (threaded):

        @threadpool.threadify(__Q__)
        def threaded_crontab(config,
                             jsonHandler=jsonHandler,
                             callback=callback,
                             logging_callback=logging_callback,
                             default=default):
            return __crontab__(config,
                               jsonHandler=jsonHandler,
                               callback=callback,
                               logging_callback=logging_callback,
                               default=default)

        threaded_crontab(config,
                         jsonHandler=jsonHandler,
                         callback=callback,
                         logging_callback=logging_callback,
                         default=default)
        __logger__('INFO.2: isRunning="%s".' % (config.isRunning))
        if (not config.isRunning):
            if (config.verbose):
                if (callable(logging_callback)):
                    try:
                        logging_callback(
                            'INFO: Cannot run due to application defined criteria expressed via the callback.'
                        )
                    except:
                        pass
            __logger__('INFO.3: TERMINATING !!!')
            pid = os.getpid()
            os.kill(pid, signal.SIGTERM)
    else:
        __logger__('INFO.3: threaded="%s".' % (threaded))
        __crontab__(config,
                    jsonHandler=jsonHandler,
                    callback=callback,
                    logging_callback=logging_callback,
                    default=default)
Beispiel #6
0
def default(request,
            _get_user=None,
            domain='localhost',
            secure_endpoint='http://localhost',
            insecure_endpoint='http://localhost',
            air_id=None,
            air_version={},
            apiMap=None,
            logging=None,
            callback=None):
    try:
        __apiMap__ = apiMap if (apiMap.isAPI) else API({}, secure_endpoint,
                                                       insecure_endpoint)
    except:
        __apiMap__ = API({}, secure_endpoint, insecure_endpoint)
    qryObj = django_utils.queryObject(request)
    parms = django_utils.parse_url_parms(request)
    context = RequestContext(request)

    __domainName = domain

    try:
        _user = __get_user__(request) if (
            _get_user is None) else _get_user(request)
    except:
        user = __default_superuser__()
    u = request.session.get('user')
    if (u):
        _user = u
    if (misc.isDict(_user)):
        _user = SmartFuzzyObject(_user)
    _is_method_post_ = django_utils.is_method_post(request)

    is_logging_info = (logging is not None)
    if (logging is not None):
        logging.info('(+++) is_logging_info=%s' % (is_logging_info))

    is_html = lambda url: (url.endswith('.html')) or (url.endswith('.htm'))

    try:
        s_response = ''
        __error__ = ''

        url = '/%s%s' % (str('/'.join(parms)), '/' if
                         ((len(parms) > 0) and
                          (not is_html(parms[-1]))) else '')

        if (is_logging_info):
            logging.info('(1) url=%s' % (url))
        elif (settings.IS_PRODUCTION_SERVER):
            print '(1) url=%s' % (url)

        if (url.find('/activate/') > -1):
            toks = ListWrapper(url.split('/'))
            i = toks.findFirstMatching('activate')
            if (i > -1):
                del toks[i + 1]
            url = '/'.join(toks)

        browserAnalysis = django_utils.get_browser_analysis(
            request, parms, any([]))

        _current_site = __domainName
        _current_site = _current_site.replace('.appspot',
                                              '').replace('.com', '').lower()

        aid = parms[-1] if (len(parms) > 0) else ''

        get_value_from = lambda value, key, default: value[key] if (v.has_key(
            key)) else default

        __isUsingChrome__ = (str(
            browserAnalysis.browserName).lower() == 'Chrome'.lower())
        __isUsingOpera__ = (str(
            browserAnalysis.browserName).lower() == 'Opera'.lower())
        __isUsingFireFox__ = (str(
            browserAnalysis.browserName).lower() == 'FireFox'.lower())
        _data = {
            'HTTP_USER_AGENT':
            django_utils.get_from_META(request, 'HTTP_USER_AGENT', ''),
            'browserName':
            browserAnalysis.browserName,
            'browserVersion':
            browserAnalysis.browserVersion,
            'isRunningLocal':
            browserAnalysis.isRunningLocal(request),
            'isJavaScriptOptimized':
            browserAnalysis.isJavaScriptOptimized,
            'isUsingUnsupportedBrowser':
            browserAnalysis.isUsingUnsupportedBrowser,
            'isUsingMSIE':
            browserAnalysis.isUsingMSIE,
            'isBrowserWebKit':
            browserAnalysis.isBrowserWebKit,
            'isUsingAndroid':
            browserAnalysis.isUsingAndroid,
            'isUsingChrome':
            __isUsingChrome__,
            'isUsingOpera':
            __isUsingOpera__,
            'isUsingFireFox':
            __isUsingFireFox__,
            'isUsingChromeOrWebKit': (__isUsingChrome__)
            or (browserAnalysis.isBrowserWebKit),
            'qryObj':
            qryObj,
            'serial':
            str(uuid.uuid4()),
            'isShowingFlash':
            True,
            'isShowingTitleBar':
            True,
            'is_superuser':
            _user.is_superuser,
            'secure_endpoint':
            secure_endpoint,
            'insecure_endpoint':
            insecure_endpoint,
            'request_endpoint':
            secure_endpoint if
            (django_utils.is_request_HTTPS(request)) else insecure_endpoint,
            'version':
            air_version[air_id] if (air_version[air_id]) else settings.VERSION,
            'air_id':
            air_id,
            'apiMap':
            dict([(' '.join(
                [str(s).capitalize() for s in k.split('@')[-1].split('_')]), [
                    get_value_from(v, 'url',
                                   '').replace('/' + k.split('@')[0], ''),
                    get_value_from(v, 'isPostRequired', False),
                    get_value_from(v, 'fields', [])
                ]) for k, v in __apiMap__.asPythonDict().iteritems()
                  if (len(k.split('@')) == 2)])
        }
        try:
            _data['IS_NOT_LOGGED_IN'] = settings.IS_NOT_LOGGED_IN if (
                not _user) else (len(_user.is_authenticated) == 0) if (
                    misc.isList(_user.is_authenticated)
                ) else not _user.is_authenticated
        except:
            _data['IS_NOT_LOGGED_IN'] = False
        try:
            _data['IS_LOGGED_IN'] = not _data['IS_NOT_LOGGED_IN']
        except:
            _data['IS_LOGGED_IN'] = False
        try:
            _data['USER_NAME'] = _user.name if (
                _user and _data['IS_LOGGED_IN']) else 'Anonymous'
        except:
            _data['IS_NOT_LOGGED_IN'] = False
        try:
            _data[
                'IS_PRODUCTION_WEB_SERVER'] = settings.IS_PRODUCTION_WEB_SERVER
        except:
            _data['IS_PRODUCTION_WEB_SERVER'] = False
        try:
            _data[
                'IS_NOT_PRODUCTION_WEB_SERVER'] = settings.IS_NOT_PRODUCTION_WEB_SERVER
        except:
            _data['IS_NOT_PRODUCTION_WEB_SERVER'] = False
        _data['AVAILABLE_AUTH_METHODS'] = []
        try:
            from users.g import AuthMethods
            for n, v in AuthMethods:
                e = AuthMethods(n)
                if (e.value > 0):
                    if (e.value == 1):
                        _data[
                            'IS_DJANGO_AUTH_METHOD'] = AuthMethods.django.value > 0
                        _data['AVAILABLE_AUTH_METHODS'].append(
                            'IS_DJANGO_AUTH_METHOD')
                    else:
                        k = 'IS_%s_AUTH_METHOD' % (n.upper())
                        _data[k] = e.value > 0
                        _data['AVAILABLE_AUTH_METHODS'].append(k)
        except:
            _data['IS_DJANGO_AUTH_METHOD'] = True
            _data['AVAILABLE_AUTH_METHODS'].append('IS_DJANGO_AUTH_METHOD')
        if (is_logging_info):
            logging.info('(1.1) _data=%s' % (str(_data)))
        for k, v in request.session.iteritems():
            _data[k] = v
        if (is_logging_info):
            logging.info('(1.2) _data=%s' % (str(_data)))

        air_id = parms[-1].split('.')[0] if (
            len(parms) > 0
        ) else ''  # avoid the key error that would be caused without this line of code...

        if (is_logging_info):
            logging.info('(5) air_id=%s' % (air_id))
            logging.info('(5.1) _data=%s' % (str(_data)))

        _is_callable_ = lambda v: any([callable(x.func) for x in v]) if (
            misc.isList(v)) else callable(v.func)

        __apiMap__.__specific__ = is_html(url)
        m = __apiMap__[url]
        isUrlMapped = (m != None) and (m != []) and (_is_callable_(m))
        if (not isUrlMapped):
            if (not is_html(url)):
                url = '/%s%s' % (str('/'.join(parms[0:-1])), '/' if
                                 (len(parms[0:-1]) > 0) else '')
            m = __apiMap__[url]
            isUrlMapped = (m != None) and (m != []) and (_is_callable_(m))
            if (isUrlMapped):
                air_id = aid

                if (is_logging_info):
                    logging.info('(6) air_id=%s' % (air_id))

                if (settings.IS_PRODUCTION_SERVER):
                    settings.DOMAIN_NAME = settings.APPSPOT_NAME = air_domain[
                        air_id]
            else:
                _m_ = [
                    k for k in air_version.keys() if ((len(aid) > 0) and (
                        (aid.lower().find(k.lower()) > -1) or
                        (k.lower().find(aid.lower()) > -1))) or (
                            k.lower().find(_current_site) > -1) or (
                                _current_site.lower().find(k.lower()) > -1)
                ]
                air_id = _m_[0] if (len(_m_) > 0) else air_id

                if (is_logging_info):
                    logging.info('(7) air_id=%s, _m_=%s, aid=%s' %
                                 (air_id, _m_, aid))

        http_host = django_utils.get_from_META(request,
                                               'HTTP_HOST',
                                               default='')
        if (__apiMap__.__secure_endpoint__.find('127.0.0.1') >
                -1) and (http_host.find('localhost') > -1):
            http_host = http_host.replace('localhost', '127.0.0.1')
        http_host = http_host.split(':')[0]
        _is_http_host_correct_ = True if (
            not settings.IS_HTTPS_REQUIRED) else (
                __apiMap__.__secure_endpoint__.find(http_host) > -1)
        _is_request_correct_ = ((not settings.IS_PRODUCTION_SERVER)
                                or (not settings.IS_HTTPS_REQUIRED)
                                or ((settings.IS_PRODUCTION_SERVER) and
                                    (django_utils.is_request_HTTPS(request))))

        def __resolve_mapping_from_rules__(m, qryObj):
            for mm in m:
                _rules_ = [
                    r for r in [(str(k).split('_'), k) for k in mm.keys()]
                    if (str(r[0][0]).lower() == 'rules') and (len(r[0]) == 2)
                ]
                _has_rules_ = any([len(r[0]) == 2 for r in _rules_])
                _is_rules_ = False
                if (_has_rules_):
                    rCnt = 0
                    for r in _rules_:
                        try:
                            obj = eval(r[0][-1])
                            if (obj):
                                val = mm[r[-1]]
                                if (val):
                                    for k, v in val.iteritems():
                                        if (obj[k] == v):
                                            rCnt += 1
                                            m = mm
                                            _is_rules_ = True
                                            isUrlMapped = True
                                            return isUrlMapped, m, _has_rules_
                                        else:
                                            _re_ = re.compile(v)
                                            if (_re_.match(obj[k])):
                                                rCnt += 1
                                                m = mm
                                                _is_rules_ = True
                                                isUrlMapped = True
                                                return isUrlMapped, m, _has_rules_
                        except:
                            pass
                    if (rCnt < 1):
                        isUrlMapped = False
                else:
                    m = m[0]
                    isUrlMapped = True
                    return isUrlMapped, m, _has_rules_
            return False, m, False

        isUrlMapped, m, _has_rules_ = __resolve_mapping_from_rules__(m, qryObj)
        _is_method_correct_ = ((isUrlMapped)) and (
            ((m.isPostRequired) and _is_method_post_) or
            ((not m.isPostRequired) and not _is_method_post_))
        if (is_logging_info):
            logging.info('(7.0) http_host=%s' % (http_host))
            logging.info('(7.1) isUrlMapped=%s' % (isUrlMapped))
            try:
                logging.info('(7.2) m.isPostRequired=%s' % (m.isPostRequired))
            except:
                pass
            logging.info('(7.3) _is_method_post_=%s' % (_is_method_post_))
            logging.info('(7.3.1) _is_method_correct_=%s' %
                         (_is_method_correct_))
            logging.info('(7.3.2) _is_http_host_correct_=%s, http_host=%s' %
                         (_is_http_host_correct_, http_host))
            logging.info('(7.3.3) _is_request_correct_=%s' %
                         (_is_request_correct_))
            logging.info('(7.3.4) _has_rules_=%s' % (_has_rules_))

            logging.info('(7.4) __apiMap__.__secure_endpoint__=%s' %
                         (__apiMap__.__secure_endpoint__))
            logging.info('(7.5) settings.IS_PRODUCTION_SERVER=%s' %
                         (settings.IS_PRODUCTION_SERVER))
            logging.info('(7.5.1) settings.IS_HTTPS_REQUIRED=%s' %
                         (settings.IS_HTTPS_REQUIRED))
            logging.info('(7.6) django_utils.is_request_HTTPS(request)=%s' %
                         (django_utils.is_request_HTTPS(request)))
            logging.info(
                '(7.7) django_utils.get_from_environ(request,\'SERVER_PORT\',80)=%s'
                % (django_utils.get_from_environ(request, 'SERVER_PORT', 80)))
            logging.info(
                '(7.8) django_utils.is_Production()=%s, django_utils.is_Staging()=%s'
                % (django_utils.is_Production(request),
                   django_utils.is_Staging(request)))
        if (isUrlMapped) and (_is_method_correct_) and (
                _is_http_host_correct_
        ) and (
                _is_request_correct_
        ):  # (must be mapped), (must use POST), (must use secure endpoint) and (if production must use SSL).
            if (is_logging_info):
                logging.info('(8.0) !!!')
            try:
                response = m.func(request,
                                  parms,
                                  browserAnalysis,
                                  air_id,
                                  __apiMap__,
                                  data=_data)
                if (is_logging_info):
                    logging.info('(8) response=%s' % (response))
                    logging.info('(9) settings.APP_SESSION_KEY=%s' %
                                 (settings.APP_SESSION_KEY))
                django_utils.give_response_session_id_using(
                    request, response, settings.APP_SESSION_KEY)
                return response
            except Exception as e:
                info_string = _utils.formattedException(details=e)
                logging.info('%s' % (info_string))
            return django_utils.render_main_html(
                request,
                browserAnalysis,
                qryObj,
                data=_data,
                is_logging_info=is_logging_info,
                current_site=_current_site,
                aid=aid,
                air_id=air_id,
                logging=logging,
                context=context)
        if (air_version[air_id] is None):
            try:
                _message = django_utils.get_from_post_or_get(
                    request, 'message', '')
                if (len(_message) > 0):
                    _data['message'] = _message
                _url_ = os.sep + os.sep.join(
                    [c for c in url.split('/') if (len(c) > 0)])
                _s_ = os.sep.join([settings.MEDIA_ROOT, _url_])
                if (os.path.isfile(_s_)) and (os.path.exists(_s_)):
                    _url_ = '/static/' + '/'.join(
                        [c for c in url.split('/') if (len(c) > 0)])
                    try:
                        return HttpResponseRedirect(
                            _url_
                        )  # allow the web server to handle this rather than the application server...
                    except:
                        pass
                    return django_static.serve(
                        _s_
                    )  # if all else fails the application server should handle the request...
                _url_ = '/'.join(
                    url.split('/')[1 if (url.startswith('/')) else 0:])
                if (callable(callback)):
                    try:
                        response = callback(request, _url_, _data)
                        if (isinstance(response, HttpResponseRedirect)):
                            return response
                    except:
                        logging.exception('%s' % (_url_))
                return render_to_response(_url_,
                                          _data,
                                          context_instance=context)
            except TemplateDoesNotExist, e:
                try:
                    _url_ += 'index.htm'
                    if (callable(callback)):
                        try:
                            callback(request,
                                     _url_,
                                     _data,
                                     context_instance=context)
                        except:
                            pass
                    return render_to_response(_url_,
                                              _data,
                                              context_instance=context)
                except TemplateDoesNotExist, e:
                    try:
                        _url_ += 'l'
                        if (callable(callback)):
                            try:
                                callback(request,
                                         _url_,
                                         _data,
                                         context_instance=context)
                            except:
                                pass
                        return render_to_response(_url_,
                                                  _data,
                                                  context_instance=context)
                    except TemplateDoesNotExist, e:
                        info_string = _utils.formattedException(details=e)
                        logging.info('%s' % (info_string))
Beispiel #7
0
__imports__ = [
    f for f in sys.path
    if (f.replace(os.sep, '/').split('/')[-1].lower().find('django') > -1)
]

from vyperlogix.webpy.session import Session
from vyperlogix.misc._utils import timeStampForFileName
from vyperlogix.misc._utils import formattedException

from vyperlogix.misc import _utils

from vyperlogix.lists.ListWrapper import ListWrapper

from vyperlogix.django import django_utils

paths = ListWrapper(sys.path)

for m in __imports__:
    i = paths.findFirstMatching(m)
    if (i > -1):
        del sys.path[i]

django_utils.assert_version(1.4)

urls = (
    '/',
    'Index',
    '/watcher/(.+)',
    'Watcher',
    '/watcher',
    'Watcher',