当前位置: 首页>>代码示例>>Python>>正文


Python traceback.format_exception_only函数代码示例

本文整理汇总了Python中traceback.format_exception_only函数的典型用法代码示例。如果您正苦于以下问题:Python format_exception_only函数的具体用法?Python format_exception_only怎么用?Python format_exception_only使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了format_exception_only函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: extract_file_aod

def extract_file_aod(ts_obj, file_obj, curr_dir, pressure_file, psurf_file, label_prefix, aerosol_re, use_sub_types=None):
    press_obj = ts_obj.get_cached_file(curr_dir, pressure_file, required=True)
    psurf_obj = ts_obj.get_cached_file(curr_dir, psurf_file)

    try:
        in_press_vals  = file_obj[PRESSURE_COLUMN][:,0]
    except LookupError:
        logger.error('For file "%s" LookupError: %s' % (file_obj.filename,traceback.format_exception_only(*sys.exc_info()[0:2])))
        return None

    if press_obj != None:
        out_press_vals = press_obj[PRESSURE_COLUMN][:,0]
    else:
        out_press_vals = in_press_vals

    try:
        if psurf_obj != None:
            out_press_vals = apply_psurf_to_pressures(out_press_vals, psurf_obj[PSURF_COLUMN][0,0])
    except LookupError:
        logger.error('For file "%s" LookupError: %s' % (press_obj.filename,traceback.format_exception_only(*sys.exc_info()[0:2])))
        return None

    if not hasattr(aerosol_re, '__iter__'):
        aerosol_re = ( aerosol_re, )

    aer_columns = []
    for col_name in file_obj.labels_lower:
        for curr_re in aerosol_re:
            if re.search(curr_re.lower(), col_name) and not re.search(PRESSURE_COLUMN.lower(), col_name):
                aer_columns.append( file_obj[col_name] )

    aod_data_vals = calculate_aod_values(in_press_vals, out_press_vals, aer_columns, label_prefix, use_sub_types)

    return aod_data_vals
开发者ID:E-LLP,项目名称:RtRetrievalFramework,代码行数:34,代码来源:testset_summary.py

示例2: _cross_reference_masses

    def _cross_reference_masses(self):
        """
        Links the mass to nodes, properties (and materials depending on
        the card).
        """
        for mass in itervalues(self.masses):
            try:
                mass.cross_reference(self)
            except (SyntaxError, RuntimeError, AssertionError, KeyError, ValueError) as e:
                self._ixref_errors += 1
                var = traceback.format_exception_only(type(e), e)
                self._stored_xref_errors.append((mass, var))
                if self._ixref_errors > self._nxref_errors:
                    self.pop_xref_errors()
                    # msg = "Couldn't cross reference Mass.\n%s" % str(mass)
                    # self.log.error(msg)
                    # raise

        for prop in itervalues(self.properties_mass):
            try:
                prop.cross_reference(self)
            except (SyntaxError, RuntimeError, AssertionError, KeyError, ValueError) as e:
                self._ixref_errors += 1
                var = traceback.format_exception_only(type(e), e)
                self._stored_xref_errors.append((prop, var))
                if self._ixref_errors > self._nxref_errors:
                    self.pop_xref_errors()
开发者ID:ClaesFredo,项目名称:pyNastran,代码行数:27,代码来源:crossReference.py

示例3: google_callback

def google_callback():
    """Handle the redirect request from consumers browser containing information from identity provider"""

    # I. Get Inputs and Handle Error returned
    error_message = request.args.get('error')
    auth_code = request.args.get('code', '')
    LOGGER.debug('Google Return Error: %s, Code: %s', str(error_message), auth_code)

    # If Error, throw error message
    if error_message is not None:
        return flaskApp.custom_errors.error_formatter(code='403_opt_out', display_format='html', details=error_message)

    # II. Call Google to get credentials
    # If no success return error message
    try:
        flow = google_flow()
        credentials = flow.step2_exchange(auth_code)
        LOGGER.debug('credentials: %s', str(credentials.access_token))
    except Exception:
        LOGGER.error("Exception getting credentials: %s",
                     traceback.format_exception_only(sys.exc_info()[0], sys.exc_info()[1]))
        return flaskApp.custom_errors.error_formatter(code='500_02', display_format='html',
                                                      details=traceback.format_exception_only(sys.exc_info()[0],
                                                                                              sys.exc_info()[1]))

    # III. Use credentials to get information
    return google_fetch_user_info(str(credentials.access_token))
开发者ID:TradLabs,项目名称:trad_labs_api,代码行数:27,代码来源:google.py

示例4: get_target_deps

def get_target_deps(args, sha):
    try:
        cache_fn = os.path.join(CACHEDIR, 'depcache-{}'.format(sha))
        with open(cache_fn, 'rb') as f:
            deps = pickle.load(f)
    except Exception as e:
        print('Could not load dependency cache: {}'.format(
            traceback.format_exception_only(type(e), e)
        ))
        print('Introspecting dependencies...')
        deps = None

    if deps is None:
        if args.target == 'atom':
            deps = find_atom_deps(args, sha)
        elif args.target == 'vscode':
            deps = find_vscode_deps(args, sha)
        else:
            die('unsupported target: {}'.format(args.target))

    try:
        cache_fn = os.path.join(CACHEDIR, 'depcache-{}'.format(sha))
        with open(cache_fn, 'wb') as f:
            pickle.dump(deps, file=f)
    except Exception as e:
        print('Could not store dependency cache: {}'.format(
            traceback.format_exception_only(type(e), e)
        ))

    return deps
开发者ID:elprans,项目名称:atom-overlay,代码行数:30,代码来源:ebuild-gen.py

示例5: publish

    def publish(self,request,queryset):
        result = None
        failed_objects = []
        #import ipdb;ipdb.set_trace()
        try_set_push_owner("workspace_admin",enforce=True)
        warning_message = None
        try:
            for workspace in queryset:
                try:
                    workspace.publish()
                except:
                    error = sys.exc_info()
                    failed_objects.append((workspace.name,traceback.format_exception_only(error[0],error[1])))
                    #remove failed, continue to process the next publish
                    continue

            try:
                try_push_to_repository('workspace_admin',enforce=True)
            except:
                error = sys.exc_info()
                warning_message = traceback.format_exception_only(error[0],error[1])
                logger.error(traceback.format_exc())
        finally:
            try_clear_push_owner("workspace_admin",enforce=True)

        if failed_objects or warning_message:
            if failed_objects:
                if warning_message:
                    messages.warning(request, mark_safe("<ul><li>{0}</li><li>Pushing changes to repository failed:<ul>{1}</ul></li></ul>".format(warning_message,"".join(["<li>{0} : {1}</li>".format(o[0],o[1]) for o in failed_objects]))))
                else:
                    messages.warning(request, mark_safe("Publish failed for some selected workspaces:<ul>{0}</ul>".format("".join(["<li>{0} : {1}</li>".format(o[0],o[1]) for o in failed_objects]))))
            else:
                messages.warning(request, mark_safe(warning_message))
        else:
            messages.success(request, "Publish successfully for all selected workspaces")
开发者ID:parksandwildlife,项目名称:borgcollector,代码行数:35,代码来源:admin.py

示例6: get_value_of_var_from_global_sheet

 def get_value_of_var_from_global_sheet(self, parameter):
     # If the parameter is a title of a sheet, we need to get the data from this sheet
     if parameter in self.workbook.keys():
         value_of_the_parameter = self.workbook['Global'].get_value_of_var_by_index_and_param(self.hostname, parameter)
         try:
             data_of_the_parameter = self.workbook[parameter].get_all_param_by_index(value_of_the_parameter)
         except KeyError as err:
             self.unresolved += 1
             self.tb += traceback.format_exception_only(KeyError, err)
             return "<unresolved>"
         template_regex = re.compile('template')
         output = ''
         for _header, _template_name in data_of_the_parameter.items():
             if template_regex.match(_header.lower()) and _template_name:
                 template_content = self.workbook[parameter].template_content_by_name(_template_name.lower())
                 output += self.fill_local_template(self, data_of_the_parameter, template_content)
         if output == '':
             self.unresolved += 1
             self.tb += traceback.format_exception_only(Warning, "No subtemplates to being picked up for the var '{}'".format(parameter))
             return "<unresolved>"
         else:
             return output
     # If the parameter/feature is only a variable (there is not a sheet for this feature)
     else:
         try:
             value = self.workbook['Global'].get_value_of_var_by_index_and_param(self.hostname, parameter)
             self.resolved += 1
             return value
         except KeyError as err:
             self.unresolved += 1
             self.tb += traceback.format_exception_only(KeyError, err)
             return "<unresolved>"
开发者ID:JoelCapitao,项目名称:NetScriptGen,代码行数:32,代码来源:Equipment.py

示例7: removePymelAll

def removePymelAll(filepath, p4merge=True, replace='ask', text=None):
    print "removePymelAll: %s" % filepath

    # if we have a directory, recurse
    if os.path.isdir(filepath):
        if text is not None:
            raise ValueError("when passing in a directory to removePymelAll, text may not be specified")
        for root, dirs, files in os.walk(filepath):
            for f in files:
                if not PYTHON_FILE_RE.match(f):
                    continue
                path = os.path.join(root, f)
                try:
                    with open(path, _READMODE) as filehandle:
                        text = filehandle.read()
                except (IOError, OSError), e:
                    print '!!!!!!!!!!!!!!!!'
                    print "Error reading %s:" % path
                    print '\n'.join(traceback.format_exception_only(type(e), e))
                if FROM_PYMEL_ALL_RE.search(text):
                    try:
                        removePymelAll(os.path.join(root, f), p4merge=p4merge, replace=replace, text=text)
                    except SyntaxError, e:
                        print '!!!!!!!!!!!!!!!!'
                        print "Error parsing %s:" % path
                        print '\n'.join(traceback.format_exception_only(type(e), e))
开发者ID:SarielD,项目名称:pymel,代码行数:26,代码来源:removePymelAll.py

示例8: _cross_reference_elements

    def _cross_reference_elements(self):
        """
        Links the elements to nodes, properties (and materials depending on
        the card).
        """
        for elem in itervalues(self.elements):
            try:
                elem.cross_reference(self)
            except (SyntaxError, RuntimeError, AssertionError, KeyError, ValueError) as e:
                self._ixref_errors += 1
                var = traceback.format_exception_only(type(e), e)
                self._stored_xref_errors.append((elem, var))
                if self._ixref_errors > self._nxref_errors:
                    self.pop_xref_errors()

        for elem in itervalues(self.rigid_elements):
            try:
                elem.cross_reference(self)
            except (SyntaxError, RuntimeError, AssertionError, KeyError, ValueError) as e:
                self._ixref_errors += 1
                var = traceback.format_exception_only(type(e), e)
                self._stored_xref_errors.append((elem, var))
                if self._ixref_errors > self._nxref_errors:
                    self.pop_xref_errors()

        for elem in itervalues(self.plotels):
            try:
                elem.cross_reference(self)
            except (SyntaxError, RuntimeError, AssertionError, KeyError, ValueError) as e:
                self._ixref_errors += 1
                var = traceback.format_exception_only(type(e), e)
                self._stored_xref_errors.append((elem, var))
                if self._ixref_errors > self._nxref_errors:
                    self.pop_xref_errors()
开发者ID:hurlei,项目名称:pyNastran,代码行数:34,代码来源:cross_reference.py

示例9: test_handle_exception

    def test_handle_exception(self, mock_sys):
        # pylint: disable=protected-access
        from letsencrypt import cli

        mock_open = mock.mock_open()
        with mock.patch('letsencrypt.cli.open', mock_open, create=True):
            exception = Exception('detail')
            cli._handle_exception(
                Exception, exc_value=exception, trace=None, args=None)
            mock_open().write.assert_called_once_with(''.join(
                traceback.format_exception_only(Exception, exception)))
            error_msg = mock_sys.exit.call_args_list[0][0][0]
            self.assertTrue('unexpected error' in error_msg)

        with mock.patch('letsencrypt.cli.open', mock_open, create=True):
            mock_open.side_effect = [KeyboardInterrupt]
            error = errors.Error('detail')
            cli._handle_exception(
                errors.Error, exc_value=error, trace=None, args=None)
            # assert_any_call used because sys.exit doesn't exit in cli.py
            mock_sys.exit.assert_any_call(''.join(
                traceback.format_exception_only(errors.Error, error)))

        args = mock.MagicMock(debug=False)
        cli._handle_exception(
            Exception, exc_value=Exception('detail'), trace=None, args=args)
        error_msg = mock_sys.exit.call_args_list[-1][0][0]
        self.assertTrue('unexpected error' in error_msg)

        interrupt = KeyboardInterrupt('detail')
        cli._handle_exception(
            KeyboardInterrupt, exc_value=interrupt, trace=None, args=None)
        mock_sys.exit.assert_called_with(''.join(
            traceback.format_exception_only(KeyboardInterrupt, interrupt)))
开发者ID:naveenholla,项目名称:letsencrypt,代码行数:34,代码来源:cli_test.py

示例10: store_error_details

def store_error_details(name, env):
    description = "Failed in method {:s}.".format(name)
    if env is not None:
        try:
            create_diagnostic_snapshot(env, "fail", name)
        except:
            logger.error("Fetching of diagnostic snapshot failed: {0}".format(
                traceback.format_exception_only(sys.exc_info()[0],
                                                sys.exc_info()[1])))
            logger.debug("Fetching of diagnostic snapshot failed: {0}".
                         format(traceback.format_exc()))
            try:
                with env.d_env.get_admin_remote()\
                        as admin_remote:
                    pull_out_logs_via_ssh(admin_remote, name)
            except:
                logger.error("Fetching of raw logs failed: {0}".format(
                    traceback.format_exception_only(sys.exc_info()[0],
                                                    sys.exc_info()[1])))
                logger.debug("Fetching of raw logs failed: {0}".
                             format(traceback.format_exc()))
        finally:
            try:
                env.make_snapshot(snapshot_name=name[-50:],
                                  description=description,
                                  is_make=True)
            except:
                logger.error(
                    "Error making the environment snapshot: {0}".format(
                        traceback.format_exception_only(sys.exc_info()[0],
                                                        sys.exc_info()[1])))
                logger.debug("Error making the environment snapshot:"
                             " {0}".format(traceback.format_exc()))
开发者ID:avgoor,项目名称:fuel-qa,代码行数:33,代码来源:decorators.py

示例11: clicks_a_link

    def clicks_a_link(self, url, verbose=True, templates_used=[]):
        """ Simulate a GET request using the test client
        """
        # request the page
        # submit the form
        import traceback, sys

        try:
            response = self.client.get(url)
        except TemplateDoesNotExist:
            exception_message = "".join(traceback.format_exception_only(sys.exc_type, sys.exc_value)).strip()

            self.fail("No url to handle (%s) or template does not exist: (%s)" % (url, exception_message))
        except ViewDoesNotExist:
            exception_message = "".join(traceback.format_exception_only(sys.exc_type, sys.exc_value)).strip()
            self.fail("No view to handle (%s): %s" % (url, exception_message))

        # check that this was a valid request
        self.failUnless(response.status_code in [200, 302])

        # if there are templates supplied for checking, make sure they are used to render the page
        for template in templates_used:
            self.assertTemplateUsed(response, template)

        # if we're not going to do anything with the response, don't bother using BeautifulSoup
        if not verbose:
            return True

        # return a BeautifulSoup document for navigating
        return BeautifulSoup(response.content)
开发者ID:carriercomm,项目名称:invoicemaster,代码行数:30,代码来源:tests.py

示例12: _cross_reference_materials

    def _cross_reference_materials(self):
        """
        Links the materials to materials (e.g. MAT1, CREEP)
        often this is a pass statement
        """
        for mat in itervalues(self.materials):  # MAT1
            try:
                mat.cross_reference(self)
            except (SyntaxError, RuntimeError, AssertionError, KeyError, ValueError) as e:
                self._ixref_errors += 1
                var = traceback.format_exception_only(type(e), e)
                self._stored_xref_errors.append((mat, var))
                if self._ixref_errors > self._nxref_errors:
                    self.pop_xref_errors()

        # CREEP - depends on MAT1
        data = [self.MATS1, self.MATS3, self.MATS8,
                self.MATT1, self.MATT2, self.MATT3, self.MATT4, self.MATT5,
                self.MATT8, self.MATT9]
        for material_deps in data:
            for mat in itervalues(material_deps):
                try:
                    mat.cross_reference(self)
                except (SyntaxError, RuntimeError, AssertionError, KeyError, ValueError) as e:
                    self._ixref_errors += 1
                    var = traceback.format_exception_only(type(e), e)
                    self._stored_xref_errors.append((mat, var))
                    if self._ixref_errors > self._nxref_errors:
                        self.pop_xref_errors()
开发者ID:hurlei,项目名称:pyNastran,代码行数:29,代码来源:cross_reference.py

示例13: handle_errors

 def handle_errors(row, exc):
     self.num_request_done += 1
     try:
         name = type(exc).__name__
         self.exception_type[name] += 1
     except Exception as e:
         print traceback.format_exception_only(type(e), e)
开发者ID:emolsson,项目名称:cassandra-dtest,代码行数:7,代码来源:materialized_views_test.py

示例14: add

def add(request):
    if request.POST:
        errors = {}

        paused = request.POST.has_key('paused')
        url = request.POST['url']
        if url:
            try:
                f = urllib.urlopen(url)
                content = f.read()
                f.close()

                metainfo = ConvertedMetainfo(bdecode(content))
                name = metainfo.name_fs[:50]
    
            except Exception, e:
                err = traceback.format_exception_only(e.__class__, e)
                errors.setdefault('url', []).append(''.join(err))
                
        else:
            try:
                torrent = request.FILES['torrent']
                content = torrent['content']
                metainfo = ConvertedMetainfo(bdecode(content))
                name = metainfo.name_fs[:50]

            except Exception, e:
                err = traceback.format_exception_only(e.__class__, e)
                errors.setdefault('torrent', []).append(''.join(err))
开发者ID:kirkeby,项目名称:django-stuff,代码行数:29,代码来源:__init__.py

示例15: test_get_tag_objects_blank

def test_get_tag_objects_blank(stc):
    fail_msg = ''
    try:
        tag_utils.get_tag_object('')
    except:
        exc_info = sys.exc_info()
        fail_list = traceback.format_exception_only(exc_info[0],
                                                    exc_info[1])
        fail_msg = fail_list[0] if len(fail_list) == 1 else '\n'.join(fail_list)
    if fail_msg == '':
        raise AssertionError('function did not fail as expected')
    if 'must not be blank' not in fail_msg:
        raise AssertionError('function failed with unexpected exception: "' +
                             fail_msg + '"')
    try:
        tag_utils.get_tag_object_list(['non-blank', ''])
    except:
        exc_info = sys.exc_info()
        fail_list = traceback.format_exception_only(exc_info[0],
                                                    exc_info[1])
        fail_msg = fail_list[0] if len(fail_list) == 1 else '\n'.join(fail_list)
    if fail_msg == '':
        raise AssertionError('function did not fail as expected')
    if 'must not be blank' not in fail_msg:
        raise AssertionError('function failed with unexpected exception: "' +
                             fail_msg + '"')
开发者ID:CmWork,项目名称:STAKCommands,代码行数:26,代码来源:test_tag_utils.py


注:本文中的traceback.format_exception_only函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。