def login():
  if request.method == 'POST':
    username = request.form['username']
    password = request.form['password']
    if validate_login(username, password): 
      session['username'] = username 
    
      ## <DEBUGGING>     
      response = fitocracy_request(username, password)
      msg = 'Sucessful login: '******'default.html', msg = msg)   
      ## </DEBUGGING>     
     
     
      return redirect(url_for('user', user_name = username))
    else: 
      msg = 'ERROR: Invalid username or password!' 
      return render_template('default.html', msg = msg)
  return render_template('default.html')
Exemple #2
0
 def __str__(self):
     return """
     Nodes: {} 
     
     Edges:
     {}
     """.format(pprint.saferepr(self.data), pprint.saferepr(self.adj))
Exemple #3
0
    def content(self):
        vars = odict()
        request = tg.request._current_obj()
        response = tg.response._current_obj()
        attr_dict = request.environ['webob.adhoc_attrs'].copy()
        attr_dict['response'] = repr(response.__dict__)

        for entry in attr_dict.keys():
            if entry.startswith('tgdb_'):
                del attr_dict[entry]

        vars['GET'] = [(k, request.GET.getall(k)) for k in request.GET]
        vars['POST'] = [(k, [saferepr(p)
            for p in request.POST.getall(k)]) for k in request.POST]
        vars['Cookies'] = [(k, request.cookies.get(k))
            for k in request.cookies]
        vars['Headers'] = [(k, saferepr(v))
            for k, v in request.environ.iteritems()
            if k.startswith('HTTP_') or k in request_header_filter]
        vars['Request Attributes'] = [(k, saferepr(v))
            for k, v in attr_dict.iteritems() if not callable(v)]
        vars['Environ'] = [(k, saferepr(v))
            for k, v in request.environ.iteritems()]

        return unicode(render(
            dict(vars=vars),
            'genshi', 'tgext.debugbar.sections.templates.request'
            ).split('\n', 1)[-1])
 def __str__(self):
     return pprint.saferepr(
         """
         Nodes: {}
         Edges: {}
         """.format(pprint.saferepr(self.data), \
                    pprint.saferepr([str(x) for x in self.adj])))
    def content(self):
        vars = odict()
        request = tg.request._current_obj()
        response = tg.response._current_obj()
        attr_dict = request.environ.get("webob.adhoc_attrs", {}).copy()
        attr_dict["response"] = repr(response.__dict__)

        for entry in list(attr_dict.keys()):
            if entry.startswith("tgdb_"):
                del attr_dict[entry]

        vars["GET"] = [(k, request.GET.getall(k)) for k in request.GET]
        vars["POST"] = [(k, [saferepr(p) for p in request.POST.getall(k)]) for k in request.POST]
        vars["Cookies"] = [(k, request.cookies.get(k)) for k in request.cookies]
        vars["Headers"] = [
            (k, saferepr(v)) for k, v in request.environ.items() if k.startswith("HTTP_") or k in request_header_filter
        ]
        vars["Request Attributes"] = [(k, saferepr(v)) for k, v in attr_dict.items() if not callable(v)]
        vars["Environ"] = [(k, saferepr(v)) for k, v in request.environ.items()]

        return unicode_text(
            render(
                dict(vars=vars), tg.config["debugbar.engine"], "tgext.debugbar.sections.templates.request!html"
            ).split("\n", 1)[-1]
        )
    def content(self):
        vars = odict()
        request = tg.request._current_obj()
        response = tg.response._current_obj()
        attr_dict = request.environ.get('webob.adhoc_attrs', {}).copy()
        attr_dict['response'] = repr(response.__dict__)

        for entry in list(attr_dict.keys()):
            if entry.startswith('tgdb_'):
                del attr_dict[entry]

        vars['GET'] = [(k, request.GET.getall(k)) for k in request.GET]
        vars['POST'] = [(k, [saferepr(p) for p in request.POST.getall(k)])
                        for k in request.POST]
        vars['Cookies'] = [(k, request.cookies.get(k))
                           for k in request.cookies]
        vars['Headers'] = [
            (k, saferepr(v)) for k, v in request.environ.items()
            if k.startswith('HTTP_') or k in request_header_filter
        ]
        vars['Request Attributes'] = [(k, saferepr(v))
                                      for k, v in attr_dict.items()
                                      if not callable(v)]
        vars['Environ'] = [(k, saferepr(v))
                           for k, v in request.environ.items()]

        return unicode_text(
            render(dict(vars=vars), tg.config['debugbar.engine'],
                   'tgext.debugbar.sections.templates.request!html').split(
                       '\n', 1)[-1])
Exemple #7
0
 def assertNotIn(self, member, container, msg=None):
     """
     Report an assertion failure if *member* IS in *container*.
     """
     if member in container:
         fmsg = "%s unexpectedly found in %s" % (pp.saferepr(member),
                                                 pp.saferepr(container))
         self.fail(msg or fmsg)
Exemple #8
0
 def assertIn(self, member, container, msg=None):
     """
     Report an assertion failure if *member* is not in *container*.
     """
     if member not in container:
         fmsg = "%s not found in %s" % (pp.saferepr(member),
                                        pp.saferepr(container))
         self.fail(msg or fmsg)
Exemple #9
0
 def __repr__(self):
     str = "client options:"
     str += pprint.saferepr(self.client_options) + '\n'
     for execution_params in self.execution_context.values():
         for command, command_options in execution_params:
             str += f"command options for {command.app.name} : "
             str += pprint.saferepr(command_options)
             str += '\n'
     return str
Exemple #10
0
 def getattr(self, path, fh=None):
     self.log("getattr " + path)
     if path != "/" and len(folder_cache) == 1:
         self.log("getattr " + path + " first read of root")
         self.populateFolderCache("/")
     if path in folder_cache:
         if 'st_size' in folder_cache[path]:
             return_val = folder_cache[path]
             self.log("getattr " + path + " " + pprint.saferepr(return_val))
             return return_val
         else:
             self.log("getattr boxid: " + str(folder_cache[path]["boxid"]))
             file_query = client.file(folder_cache[path]["boxid"]).get()
             folder_cache[path]["st_size"] = file_query["size"]
             folder_cache[path]["st_ctime"] = time.mktime(
                 time.strptime(file_query["created_at"],
                               "%Y-%m-%dT%H:%M:%S-07:00"))
             folder_cache[path]["st_mtime"] = time.mktime(
                 time.strptime(file_query["modified_at"],
                               "%Y-%m-%dT%H:%M:%S-07:00"))
             folder_cache[path]["st_atime"] = time.time()
             return_val = folder_cache[path]
             self.log("getattr " + path + " " + pprint.saferepr(return_val))
             return return_val
     else:
         # Not in cache, try populateFolderCache one direcory up
         oneback = path.split("/")
         oneback.pop()
         oneback.reverse()
         oneback.pop()
         oneback.reverse()
         self.log("getattr " + path + " oneback: " +
                  pprint.saferepr(oneback))
         if len(oneback) > 0:
             searchpath = ""
             for element in oneback:
                 searchpath += "/" + element
             self.log("getattr " + path + " searchpath: " + searchpath)
             self.populateFolderCache(searchpath)
             if path in folder_cache:
                 return_val = folder_cache[path]
                 self.log("getattr " + path + " " +
                          pprint.saferepr(return_val))
                 return return_val
             else:
                 self.log("getattr " + path +
                          " ENOENT (Not Found) - folder not found")
                 raise FuseOSError(errno.ENOENT)
                 return {}
         else:
             self.log("getattr " + path +
                      " ENOENT (Not Found) - oneback empty")
             raise FuseOSError(errno.ENOENT)
             return {}
Exemple #11
0
def request_parameters(request):
    data = {}
    yield from request.post()
    data.update({
        'url': "http://{}{}".format(request.host, request.path),
        'method': request.method,
        'get': [(k, request.GET.getall(k)) for k in request.GET],
        'post': [(k, saferepr(v)) for k, v in request.POST.items()],
        'cookies': [(k, request.cookies.get(k)) for k in request.cookies],
        'attrs': [(k, saferepr(v)) for k, v in request.items()],
        'headers': {k.title(): str(v) for k, v in request.headers.items()},
    })
    return data
 def run_zone_tests(self, tests):
     for test in tests:
         lambda_test = self.build_test( test[1] )
         setattr(self.TestBindBuilds, "test_"+str(test[0]), lambda_test )
     suite = unittest.TestLoader().loadTestsFromTestCase(self.TestBindBuilds)
     test_results = unittest.TextTestRunner(verbosity=2).run(suite)
     if test_results.errors or test_results.failures:
         # This could be more pretty
         email_to = self.testing_email
         result_email = "To: %s\n" % (email_to)
         result_email += "From: %s\n" % (self.local_email)
         result_email += "Subject: %s\n" % ("Bind build notifications")
         if test_results.errors: result_email += "Errors:\n"+pprint.saferepr(test_results.errors)
         if test_results.failures: result_email += "Failures:\n"+pprint.saferepr(test_results.failures)
         self.mail.sendmail(self.local_email, email_to, result_email)
Exemple #13
0
 def mainBody(self):
     if not self.anyReady():
         self.pause()
         return 1
     while self.dataReady("inbox"):
         self.send(saferepr(self.recv()) + "\n", "outbox")
     return 1
Exemple #14
0
def _format_assertmsg(obj):
    """Format the custom assertion message given.

    For strings this simply replaces newlines with '\n~' so that
    util.format_explanation() will preserve them instead of escaping
    newlines.  For other objects py.io.saferepr() is used first.

    """
    # reprlib appears to have a bug which means that if a string
    # contains a newline it gets escaped, however if an object has a
    # .__repr__() which contains newlines it does not get escaped.
    # However in either case we want to preserve the newline.
#     if isinstance(obj, six.text_type) or isinstance(obj, six.binary_type):
    if isinstance(obj, basestring):
        s = obj
        is_repr = False
    else:
        s = pprint.saferepr(obj)
        is_repr = True
    if isinstance(s, unicode):
        t = unicode
    else:
        t = str
    s = s.replace(t("\n"), t("\n~")).replace(t("%"), t("%%"))
    if is_repr:
        s = s.replace(t("\\n"), t("\n~"))
    return s + "\n"
Exemple #15
0
 def mainBody(self):
         if not self.anyReady():
             self.pause()
             return 1
         while self.dataReady("inbox"):
             self.send( saferepr(self.recv())+"\n", "outbox")
         return 1
Exemple #16
0
def load_content(loader, ctx: common.Context) -> common.Result:
    """ Load & filter content """
    start = time.time()
    # load list of parts
    result = loader.load()

    if ctx.debug:
        ctx.log_debug("loaded: %s", result)
        result.debug['loaded_duration'] = time.time() - start
        fltr_start = time.time()
        result.debug['items_loaded'] = len(result.items)
        result.debug['filters_status'] = {}

    # apply filters
    for fltcfg in ctx.input_conf.get('filters') or []:
        flt = filters.get_filter(fltcfg, ctx)
        if not flt:
            ctx.log_error("missing filter: %s", fltcfg)
            continue
        result = flt.filter(result)
        if ctx.debug:
            ctx.log_debug("filtered by %s: %s", flt, pprint.saferepr(result))
            result.debug['filters_status'][flt.name] = len(result.items)

    if ctx.args.debug:
        result.meta['filter_duration'] = time.time() - fltr_start
        result.debug['items_filterd'] = len(result.items)

    result.meta['update_duration'] = time.time() - start
    result.meta['update_date'] = time.time()
    if not result.title:
        result.title = ctx.name
    if ctx.debug:
        ctx.log_debug("result: %s", result)
    return result
Exemple #17
0
    def content(self):
        vars = {}
        request = self.request
        attr_dict = request.__dict__.copy()
        # environ is displayed separately
        del attr_dict['environ']
        if 'response' in attr_dict:
            attr_dict['response'] = repr(attr_dict['response'])
        vars.update({
            'get': [(k, request.GET.getall(k)) for k in request.GET],
            'post': [(k, [saferepr(p) for p in request.POST.getall(k)])
                     for k in request.POST],
            'cookies': [(k, request.cookies.get(k)) for k in request.cookies],
            'attrs':
            dictrepr(attr_dict),
            'environ':
            dictrepr(request.environ),
        })
        if hasattr(self.request, 'session'):
            vars.update({
                'session': dictrepr(self.request.session),
            })

        return self.render(
            'pyramid_debugtoolbar.panels:templates/request_vars.dbtmako',
            vars,
            request=self.request)
Exemple #18
0
def printReport(timecounter, text):
    text += ["LVL UP"]
    text += [pprint.saferepr(counters.echo())]
    strtime = "{:0>8}".format(
        datetime.timedelta(seconds=round(time.clock() - timecounter, 1)))
    print(strtime + " " + ", ".join(text))
    resetValues()
Exemple #19
0
 def duplicate_key(query):
     raw_params = (() if query["raw_params"] is None else tuple(
         query["raw_params"]))
     # saferepr() avoids problems because of unhashable types
     # (e.g. lists) when used as dictionary keys.
     # https://github.com/jazzband/django-debug-toolbar/issues/1091
     return (query["raw_sql"], saferepr(raw_params))
Exemple #20
0
 def destroy(self):
     if self._write_to_log_on_exit:
         logger.debug('Metrics at time of destruction:')
         for k, v in FlatMetricsNamespaceDataView(
                 self._namespace).get_data().items():
             logger.debug('{key}={value}'.format(key=k, value=saferepr(v)))
         logger.debug('Metrics Done')
Exemple #21
0
 def get_token(self, username, password, one_time_password=None):
     auth_data = {
         "scopes": ["gist"],
         "note": "Sublime GitHub",
         "note_url": "https://github.com/bgreenlee/sublime-github",
     }
     headers = {"X-GitHub-OTP": one_time_password} if one_time_password else {}
     resp = self.rsession.post(
         self.base_uri + "/authorizations",
         headers=headers,
         auth=(username, password),
         proxies=self.proxies,
         data=json.dumps(auth_data),
     )
     if resp.status_code == requests.codes.CREATED:
         logger.debug(pprint.saferepr(resp))
         data = json.loads(resp.text)
         return data["token"]
     elif resp.status_code == requests.codes.UNAUTHORIZED:
         if resp.headers["X-GitHub-OTP"].startswith("required"):
             raise self.OTPNeededException()
         else:
             raise self.UnauthorizedException()
     else:
         raise self.UnknownException("%d %s" % (resp.status_code, resp.text))
Exemple #22
0
def request_parameters(request):
    data = {}
    yield from request.post()
    data.update({
        'url':
        "http://{}{}".format(request.host, request.path),
        'method':
        request.method,
        'get': [(k, request.GET.getall(k)) for k in request.GET],
        'post': [(k, saferepr(v)) for k, v in request.POST.items()],
        'cookies': [(k, request.cookies.get(k)) for k in request.cookies],
        'attrs': [(k, saferepr(v)) for k, v in request.items()],
        'headers': {k.title(): str(v)
                    for k, v in request.headers.items()},
    })
    return data
 def get_token(self, username, password, one_time_password=None):
     auth_data = {
         "scopes": ["gist"],
         "note": "Sublime GitHub",
         "note_url": "https://github.com/bgreenlee/sublime-github"
     }
     headers = {
         'X-GitHub-OTP': one_time_password
     } if one_time_password else {}
     resp = self.rsession.post(self.base_uri + "/authorizations",
                               headers=headers,
                               auth=(username, password),
                               proxies=self.proxies,
                               data=json.dumps(auth_data))
     if resp.status_code == requests.codes.CREATED:
         logger.debug(pprint.saferepr(resp))
         data = json.loads(resp.text)
         return data["token"]
     elif resp.status_code == requests.codes.UNAUTHORIZED:
         if resp.headers['X-GitHub-OTP'].startswith('required'):
             raise self.OTPNeededException()
         else:
             raise self.UnauthorizedException()
     else:
         raise self.UnknownException("%d %s" %
                                     (resp.status_code, resp.text))
Exemple #24
0
 def test_same_as_repr(self):
     # Simple objects, small containers and classes that overwrite __repr__
     # For those the result should be the same as repr().
     # Ahem.  The docs don't say anything about that -- this appears to
     # be testing an implementation quirk.  Starting in Python 2.5, it's
     # not true for dicts:  pprint always sorts dicts by key now; before,
     # it sorted a dict display if and only if the display required
     # multiple lines.  For that reason, dicts with more than one element
     # aren't tested here.
     for simple in (0, 0, 0+0j, 0.0, "", b"", bytearray(),
                    (), tuple2(), tuple3(),
                    [], list2(), list3(),
                    set(), set2(), set3(),
                    frozenset(), frozenset2(), frozenset3(),
                    {}, dict2(), dict3(),
                    self.assertTrue, pprint,
                    -6, -6, -6-6j, -1.5, "x", b"x", bytearray(b"x"),
                    (3,), [3], {3: 6},
                    (1,2), [3,4], {5: 6},
                    tuple2((1,2)), tuple3((1,2)), tuple3(range(100)),
                    [3,4], list2([3,4]), list3([3,4]), list3(range(100)),
                    set({7}), set2({7}), set3({7}),
                    frozenset({8}), frozenset2({8}), frozenset3({8}),
                    dict2({5: 6}), dict3({5: 6}),
                    range(10, -11, -1),
                    True, False, None, ...,
                   ):
         native = repr(simple)
         self.assertEqual(pprint.pformat(simple), native)
         self.assertEqual(pprint.pformat(simple, width=1, indent=0)
                          .replace('\n', ' '), native)
         self.assertEqual(pprint.saferepr(simple), native)
Exemple #25
0
    def __init__(self, request):
        self.request = request
        self.data = data = {}
        attrs = request.__dict__.copy()
        # environ is displayed separately
        del attrs['environ']

        if 'response' in attrs:
            attrs['response'] = repr(attrs['response'])

        if 'session' in attrs:
            self.process_session_attr(self, attrs['session'])
            del attrs['session']
        else:
            # only process the session if it's accessed
            callback_on_load(request, 'session', self.process_session_attr)

        data.update({
            'get': [(k, request.GET.getall(k)) for k in request.GET],
            'post': [(k, saferepr(v)) for k, v in request.POST.items()],
            'cookies': [(k, request.cookies.get(k)) for k in request.cookies],
            'environ': dictrepr(request.environ),
            'extracted_attributes': {},
            'attrs': dictrepr(attrs),
            'session': None,
        })
Exemple #26
0
def json_dumps_default(v):
    if isinstance(v, datetime.datetime):
        return to_iso_datetime(v)
    elif isinstance(v, float) and (math.isnan(v) or math.isinf(v)):
        return None
    else:
        return pprint.saferepr(v)
    def content(self):
        vars = {}
        request = self.request
        attr_dict = request.__dict__.copy()
        # environ is displayed separately
        del attr_dict['environ']
        if 'response' in attr_dict:
            attr_dict['response'] = repr(attr_dict['response'])
        vars.update({
            'get': [(k, request.GET.getall(k)) for k in request.GET],
            'post': [(k, [saferepr(p) for p in request.POST.getall(k)])
                    for k in request.POST],
            'cookies': [(k, request.cookies.get(k)) for k in request.cookies],
            'attrs': dictrepr(attr_dict),
            'environ': dictrepr(request.environ),
        })
        if hasattr(self.request, 'session'):
            vars.update({
                'session': dictrepr(self.request.session),
            })

        return self.render(
            'pyramid_debugtoolbar.panels:templates/request_vars.mako',
            vars,
            request=self.request)
Exemple #28
0
 def test_same_as_repr(self):
     # Simple objects, small containers and classes that overwrite __repr__
     # For those the result should be the same as repr().
     # Ahem.  The docs don't say anything about that -- this appears to
     # be testing an implementation quirk.  Starting in Python 2.5, it's
     # not true for dicts:  pprint always sorts dicts by key now; before,
     # it sorted a dict display if and only if the display required
     # multiple lines.  For that reason, dicts with more than one element
     # aren't tested here.
     for simple in (0, 0, 0 + 0j, 0.0, "", b"", (), tuple2(), tuple3(), [],
                    list2(), list3(), set(), set2(), set3(), frozenset(),
                    frozenset2(), frozenset3(), {}, dict2(), dict3(),
                    self.assertTrue, pprint, -6, -6, -6 - 6j, -1.5, "x",
                    b"x", (3, ), [3], {
                        3: 6
                    }, (1, 2), [3, 4], {
                        5: 6
                    }, tuple2((1, 2)), tuple3(
                        (1, 2)), tuple3(list(range(100))), [3, 4],
                    list2([3, 4]), list3([3, 4]), list3(list(range(100))),
                    set({7}), set2({7}), set3({7}), frozenset({8}),
                    frozenset2({8}), frozenset3({8}), dict2({5: 6}),
                    dict3({5: 6}), list(range(10, -11, -1))):
         native = repr(simple)
         self.assertEqual(pprint.pformat(simple), native)
         self.assertEqual(
             pprint.pformat(simple, width=1, indent=0).replace('\n', ' '),
             native)
         self.assertEqual(pprint.saferepr(simple), native)
Exemple #29
0
    def test_container_repr_override_called(self):
        N = 1000
        # Ensure that __repr__ override is called for subclasses of containers

        for cont in (
                list_custom_repr(),
                list_custom_repr([1, 2, 3]),
                list_custom_repr(range(N)),
                tuple_custom_repr(),
                tuple_custom_repr([1, 2, 3]),
                tuple_custom_repr(range(N)),
                set_custom_repr(),
                set_custom_repr([1, 2, 3]),
                set_custom_repr(range(N)),
                frozenset_custom_repr(),
                frozenset_custom_repr([1, 2, 3]),
                frozenset_custom_repr(range(N)),
                dict_custom_repr(),
                dict_custom_repr({5: 6}),
                dict_custom_repr(zip(range(N), range(N))),
        ):
            native = repr(cont)
            expected = '*' * len(native)
            self.assertEqual(pprint.pformat(cont), expected)
            self.assertEqual(pprint.pformat(cont, width=1, indent=0), expected)
            self.assertEqual(pprint.saferepr(cont), expected)
def wakeup_asg(asg):
    log.debug('Initializing ASG: %s', pprint.saferepr(asg))
    tags = {i['Key']: i['Value'] for i in asg['Tags']}
    if not valid(tags, desired_wakeup_tags_schema):
        error = "Autoscaling group doesn't contain correct wakeup tags %s ".format(
            c.jsonify(tags))
        log.error(error)
        raise ValueError(error)

    initial_capacity = int(tags['InitialCapacity'])
    desired_capacity = int(tags['DesiredCapacity'])
    min_size = int(tags['MinSize'])
    max_size = int(tags['MaxSize'])

    if (int(asg['MinSize'])         != min_size or \
        int(asg['MaxSize'])         != max_size or \
        int(asg['DesiredCapacity']) != desired_capacity) and \
        int(asg['MaxSize'])         == initial_capacity:
        log.info(
            'Resizing autoscaling group from initial %i to desired %i capacity',
            initial_capacity, desired_capacity)
        asg_client.update_auto_scaling_group(
            AutoScalingGroupName=asg['AutoScalingGroupName'],
            MinSize=min_size,
            MaxSize=max_size,
            DesiredCapacity=desired_capacity)
 def duplicate_key(query):
     raw_params = (
         () if query["raw_params"] is None else tuple(query["raw_params"])
     )
     # saferepr() avoids problems because of unhashable types
     # (e.g. lists) when used as dictionary keys.
     # https://github.com/jazzband/django-debug-toolbar/issues/1091
     return (query["raw_sql"], saferepr(raw_params))
Exemple #32
0
def _json_serializer(obj):
    """JSON serializer for objects not serializable by default json code"""
    if isinstance(obj, (datetime, date)):
        return obj.isoformat(sep=" ")

    if isinstance(obj, (types.TracebackType, TracebackFrameProxy)):
        return "<Traceback object>"

    return saferepr(obj)
Exemple #33
0
 def _err_msg(self, sql, args=None):
     msg = "Exception for table %s.%s\n" % (self.db, self.name)
     msg += 'SQL request %s\n' % sql
     if args:
         import pprint
         msg += 'Arguments : %s\n' % pprint.saferepr(args)
     out = io.StringIO()
     traceback.print_exc(file=out)
     msg += out.getvalue()
     return msg
Exemple #34
0
	def save_error(self):
		ctx = self.ctx
		exc = self.exc

		timestamp = str(datetime.utcnow()).split('.')[0].replace(' ', '_').replace(':', '')
		filename = str(ctx.message.id) + '_' + timestamp + '.error'

		try:
			raise exc
		except:
			tb = traceback.format_exc()

		content = (
			'{0.stamp}\n\nMESSAGE CONTENT:\n{0.message.content}\n\n'
			'COMMAND: {0.command.qualified_name}\nARGS: {1}\nKWARGS: {2}\n\n{3}'
		).format(ctx, saferepr(ctx.args[2:]), saferepr(ctx.kwargs), tb)

		with open('error/{0}'.format(filename), 'w', encoding='utf-8-sig') as f:
			f.write(content)
Exemple #35
0
def _base__repr__(self):
    import pprint
    obj = vars(self)
    output = {}
    for i in self.__mapper__.columns.keys():
        try:
            output[i] = obj[i]
        except KeyError:
            pass
    return pprint.saferepr((output, self.__mapper__.relationships.keys()))
Exemple #36
0
 def _err_msg(self, sql, args=None):
     msg = "Exception for table %s.%s\n" % (self.db, self.name)
     msg += 'SQL request %s\n' % sql
     if args:
         import pprint
         msg += 'Arguments : %s\n' % pprint.saferepr(args)
     out = io.StringIO()
     traceback.print_exc(file=out)
     msg += out.getvalue()
     return msg
Exemple #37
0
 def process_response(self, response):
     self.data = data = {}
     request = self.request
     yield from request.post()
     data.update({
         'get': [(k, request.GET.getall(k)) for k in request.GET],
         'post': [(k, saferepr(v)) for k, v in request.POST.items()],
         'cookies': [(k, request.cookies.get(k)) for k in request.cookies],
         'attrs': [(k, v) for k, v in request.items()],
     })
Exemple #38
0
def main():
    try:
        return wifimitmcli()
    except KeyboardInterrupt:
        print('Stopping.')
        return ExitCode.KEYBOARD_INTERRUPT.value
    except subprocess.CalledProcessError as e:
        logger.error(str(e) + ' ' + saferepr(e))
        print(str(e), file=sys.stderr)
        return ExitCode.SUBPROCESS_ERROR.value
Exemple #39
0
    async def handle_DATA(self, server, session, envelope):
        post = {}
        msg = email.message_from_bytes(envelope.content)
        print(saferepr(msg))
        if 'message-id' in msg:
            print('Message-ID:', msg['message-id'])
        post['headers'] = dict(msg.items())
        for part in msg.walk():
            if part.get_content_type() == 'text/plain' and not bool(
                    post.get('plain')):
                post['plain'] = part.get_payload()
            if part.get_content_type() == 'text/html' and not bool(
                    post.get('html')):
                post['html'] = part.get_payload()
            if not part.get_content_disposition() is None:
                with open('/tmp/file.jpg', 'wb') as f:
                    f.write(part.get_payload(i=None, decode=True))

        print(saferepr(post))
        return '250 Message accepted for delivery'
def send_task(self, task_id):
    """The task of sending a task to Asana."""
    task = Task.objects.get(id=task_id)
    try:
        if not settings.TESTING:
            AsanaApi().send_task(task)
    except Exception as e:
        error_message = ('Can`t send the task to Asana: %s',
                         pprint.saferepr(e))
        logger.exception(error_message)
        raise self.retry(exc=e, countdown=2**(self.request.retries + 5))
Exemple #41
0
 def run_zone_tests(self, tests):
     for test in tests:
         lambda_test = self.build_test(test[1])
         setattr(self.TestBindBuilds, "test_" + str(test[0]), lambda_test)
     suite = unittest.TestLoader().loadTestsFromTestCase(
         self.TestBindBuilds)
     test_results = unittest.TextTestRunner(verbosity=2).run(suite)
     if test_results.errors or test_results.failures:
         # This could be more pretty
         email_to = self.testing_email
         result_email = "To: %s\n" % (email_to)
         result_email += "From: %s\n" % (self.local_email)
         result_email += "Subject: %s\n" % ("Bind build notifications")
         if test_results.errors:
             result_email += "Errors:\n" + pprint.saferepr(
                 test_results.errors)
         if test_results.failures:
             result_email += "Failures:\n" + pprint.saferepr(
                 test_results.failures)
         self.mail.sendmail(self.local_email, email_to, result_email)
Exemple #42
0
def def2model(de):
    sections = {
        section: parse_section(de[section])
        for section in ['log', 'event']
    }
    processors = {
        name: parse_section(processor)
        for name, processor in de['job'].items()
    }

    mode = FileMode(
        target_versions={TargetVersion.PY36},
        string_normalization=False,
    )

    sections_f = black.format_str(saferepr(sections), mode=mode)
    processors_f = black.format_str(saferepr(processors), mode=mode)

    print(
        def2model_template.format(sections=sections_f,
                                  processors=processors_f))
Exemple #43
0
    def _repr_(self):
        """
        EXAMPLES::

            sage: from sage.sets.family import FiniteFamily
            sage: FiniteFamily({3: 'a'}) # indirect doctest
            Finite family {3: 'a'}

            sage: FiniteFamily({3: 'a', 4: 'b'}) # indirect doctest
            Finite family {3: 'a', 4: 'b'}

            sage: FiniteFamily({3: 'a', 4: 'b'}, keys=[4,3]) # indirect doctest
            Finite family {4: 'b', 3: 'a'}
        """
        if self._keys is None:
            d = ' '.join(pformat(self._dictionary)[1:-1].splitlines())
        else:
            d = ', '.join(
                '{}: {}'.format(saferepr(key), saferepr(self._dictionary[key]))
                for key in self._keys)
        return 'Finite family {{{}}}'.format(d)
Exemple #44
0
    def endFile(self):
        # Print out all the dictionaries as Python strings.
        # Could just print(dict) but that's not human-readable
        dicts = ([self.basetypes,
                  'basetypes'], [self.consts, 'consts'], [self.enums, 'enums'],
                 [self.flags, 'flags'], [self.funcpointers, 'funcpointers'],
                 [self.protos,
                  'protos'], [self.structs,
                              'structs'], [self.handles, 'handles'],
                 [self.defines,
                  'defines'], [self.typeCategory,
                               'typeCategory'], [self.alias, 'alias'])
        for (entry_dict, name) in dicts:
            write(name + ' = {}', file=self.outFile)
            for key in sorted(entry_dict.keys()):
                write(name + '[' + enquote(key) + '] = ',
                      entry_dict[key],
                      file=self.outFile)

        # Dictionary containing the relationships of a type
        # (e.g. a dictionary with each related type as keys).
        write('mapDict = {}', file=self.outFile)

        # Could just print(self.mapDict), but prefer something
        # human-readable and stable-ordered
        for baseType in sorted(self.mapDict.keys()):
            write('mapDict[' + enquote(baseType) + '] = ',
                  file=self.outFile,
                  end='')
            pprint.pprint(self.mapDict[baseType], self.outFile)

        # Generate feature <-> interface mappings
        for feature in self.features:
            self.mapInterfaces(feature)

        # Write out the reverse map from APIs to requiring features
        write('requiredBy = {}', file=self.outFile)

        for api in sorted(self.apimap):
            # Construct list of requirements as Python list arguments
            ##reqs = ', '.join('({}, {})'.format(enquote(dep[0]), enquote(dep[1])) for dep in self.apimap[api])
            ##write('requiredBy[{}] = ( {} )'.format(enquote(api), reqs), file=self.outFile)

            # Ideally these would be sorted by dep[0] as well
            reqs = ', '.join(
                '({}, {})'.format(enquote(dep[0]), enquote(dep[1]))
                for dep in self.apimap[api])
            write('requiredBy[{}] = {}'.format(
                enquote(api), pprint.saferepr(self.apimap[api])),
                  file=self.outFile)

        OutputGenerator.endFile(self)
Exemple #45
0
    def _pprint_numdict(
        self, object, stream, indent, allowance, context, level
    ):

        write = stream.write
        name = type(object).__name__
        indent += len(name) + 1
        end = [" " * indent, 'default=', _pprint.saferepr(object.default),')']
        
        stream.write(name + '(')
        self._pprint_dict(object, stream, indent, allowance, context, level)
        stream.write(',\n')
        stream.write("".join(end))
Exemple #46
0
    def __str__(self):
        string = BaseTestCase.__str__(self);

        data = self.__data;
        if data:
            # cuts long data representation
            dataRepr = pprint.saferepr(data);
            if 80 < len(dataRepr) :
                dataRepr = '{0}...{1}'.format(dataRepr[:70], dataRepr[-7:]);

            string += ' with data set #{0:d} {1}'.format(
                self.__dataId,
                dataRepr,
            );

        return string;
 def __init__(self, request):
     self.data = data = {}
     attr_dict = request.__dict__.copy()
     # environ is displayed separately
     del attr_dict['environ']
     if 'response' in attr_dict:
         attr_dict['response'] = repr(attr_dict['response'])
     data.update({
         'get': [(k, request.GET.getall(k)) for k in request.GET],
         'post': [(k, saferepr(v)) for k, v in request.POST.items()],
         'cookies': [(k, request.cookies.get(k)) for k in request.cookies],
         'attrs': dictrepr(attr_dict),
         'environ': dictrepr(request.environ),
     })
     if hasattr(request, 'session'):
         data.update({
             'session': dictrepr(request.session),
         })
Exemple #48
0
 def __init__(self, request):
     self.data = data = {}
     attr_dict = request.__dict__.copy()
     # environ is displayed separately
     del attr_dict["environ"]
     if "response" in attr_dict:
         attr_dict["response"] = repr(attr_dict["response"])
     data.update(
         {
             "get": [(k, request.GET.getall(k)) for k in request.GET],
             "post": [(k, saferepr(v)) for k, v in request.POST.items()],
             "cookies": [(k, request.cookies.get(k)) for k in request.cookies],
             "attrs": dictrepr(attr_dict),
             "environ": dictrepr(request.environ),
         }
     )
     if hasattr(request, "session"):
         data.update({"session": dictrepr(request.session)})
Exemple #49
0
 def get_token(self, username, password):
     auth_data = {
         "scopes": ["gist"],
         "note": "Sublime GitHub",
         "note_url": "https://github.com/bgreenlee/sublime-github"
     }
     resp = self.rsession.post(self.base_uri + "/authorizations",
                               auth=(username, password),
                               proxies=self.proxies,
                               data=json.dumps(auth_data))
     if resp.status_code == requests.codes.CREATED:
         logger.debug(pprint.saferepr(resp))
         data = json.loads(resp.text)
         return data["token"]
     elif resp.status_code == requests.codes.UNAUTHORIZED:
         raise self.UnauthorizedException()
     else:
         raise self.UnknownException("%d %s" % (resp.status_code, resp.text))
Exemple #50
0
 def amon_tween(request, amonpy=amonpy):
     try:
         return handler(request)
     except Exception as exc:
         url = request.url
         env_excludes = ("HTTP_COOKIE", "webob._parsed_cookies")
         env = [(k, request.get(k)) for k in request.environ if k not in env_excludes]
         info = exc_info(exc, sys.exc_info()[2])
         extras = {}
         if request.GET:
             extras.update({"get": saferepr([(k, request.GET.getall(k)) for k in request.GET])})
         if request.POST:
             extras.update(
                 {"post": saferepr([(k, [saferepr(p) for p in request.POST.getall(k)]) for k in request.POST])}
             )
         if request.cookies:
             extras.update({"cookies": saferepr(request.cookies.items())})
         if hasattr(request, "session"):
             if request.session:
                 extras.update({"session": saferepr(request.session.items())})
         if request.matchdict:
             extras.update({"matchdict": saferepr(request.matchdict.items())})
         if request.matched_route:
             extras.update(
                 {
                     "matched_route": saferepr(
                         [("name", request.matched_route.name), ("path", request.matched_route.path)]
                     )
                 }
             )
         data = {
             "exception_class": info["exception_class"],
             "url": url,
             "backtrace": info["backtrace"],
             "message": info["message"],
             "enviroment": saferepr(env),
             "data": extras,
         }
         amonpy.exception(data)
         raise
    def process_response(self, response):
        self.data = data = {}
        request = self.request
        post_data = yield from request.post()
        data.update({
            'get': [(k, request.query.getall(k))
                    for k in sorted(request.query)],
            'post': [(k, saferepr(post_data.getall(k)))
                     for k in sorted(post_data)],
            'cookies': [(k, v) for k, v in sorted(request.cookies.items())],
            'attrs': [(k, v) for k, v in sorted(request.items())],
        })

        # TODO: think about aiohttp_security

        # session to separate table
        session = request.get('aiohttp_session')
        if session and not session.empty:
            data.update({
                'session': [(k, v) for k, v in sorted(session.items())],
            })
Exemple #52
0
def parseArguments():
    """Parse the command-line arguments."""
    parser = argparse.ArgumentParser(description=__doc__.split("\n")[0])

    input = parser.add_argument_group("input",
        description="Supported URL list formats.")
    input.add_argument("-g", "--gcsv", nargs="?",
        help="path to Google crawl error csv file(s)")
    input.add_argument("-p", "--plain", nargs="?",
        help="path to newline separated file(s)")

    output = parser.add_argument_group("output",
        description="Supported output formats.")
    formats = {"rack": "rack-rewrite 301 static redirect",
               "csv":  "comma separated"}
    output.add_argument("-o", "--output", choices=formats.keys(),
        help="an output format; one of: " + pprint.saferepr(formats) +
             " else, a machine-readable format")
    output.add_argument("-e", "--ext", action="store_true",
        help="remove file extension in redirects")
    output.add_argument("-s", "--subdomain", action="store_true",
        help="remove subdomains in redirects")

    files = parser.add_argument_group("files",
        description="Heuristics regarding filename format.")
    files.add_argument("-u", "--utc", action="store_true",
        help="filenames start with a date in UTC format")

    search = parser.add_argument_group("search",
        description="Fuzzy search parameters.")
    search.add_argument("-c", "--cutoff", default=0.32, type=float,
        help="fuzzy search threshold (float, defaults to: 0.32)")
    search.add_argument("-m", "--matches", default=1, type=int,
        help="number of fuzzy search matches (int, defaults to: 1)")

    parser.add_argument("-d", "--dirs", nargs="?", default=".",
        help="path to directory(s) of files")

    return parser.parse_args()
Exemple #53
0
def around(func, args, kwargs, func_name, compact):
  if conf['active']:
    if(not state['started']):
      raise RuntimeError('Not started.')

    state['tracing'] = func_name
    sys.settrace(trace_snapshot_at_return)
    try:
      ret_vals = func(*args, **kwargs)
    finally:
      sys.settrace(None)
    state['tracing'] = None

    if not compact and (state['last_was'] == 'post'):
      if conf['timestamps']:
        state['log'].write(" " * state['timestamp_size'])
      state['log'].write(conf['col_background'] + ("|" + " " * conf['indent_inc']) * state['indent'] + "|\n")
    if conf['timestamps']:
      state['log'].write(conf['col_background'] + timestamp())
    state['log'].write(
      conf['col_background'] + ("|" + " " * conf['indent_inc']) * state['indent'] +
      "|-->{}{}{}(".format(conf['col_pre_func'], func_name, conf['col_background'])
    )
    if state['traced_locals']:
      state['log'].write(
        "{}, ".format(conf['col_background']).join(
          "{}{} {}= {}{}".format(conf['col_argname'], key, conf['col_background'], conf['col_value'],
            pprint.saferepr(state['traced_locals'][key])
          ) for key in state['traced_locals']
        )
      )
      state['traced_locals'] = None
    state['log'].write("{})\n".format(conf['col_background']))

    state['log'].write(conf['col_reset'])
    state['last_was'] = 'around'
    return(ret_vals)
 def __repr__(self):
     return "%s(%s)" % (self.__class__, pprint.saferepr(self.__dict__))
Exemple #55
0
 def value_repr(self, instance):
     return '<pre style="display:inline-block;white-space:pre-wrap;">{}</pre>'.format(
         escape(saferepr(instance.value))
     )
Exemple #56
0
    def log(self, fault, runtime, *args):
        """
        Log the transaction
        """

        # Do not log system or Get calls
        #if self.name.startswith('system') or self.name.startswith('Get'):
        #    return False
        # Do not log ReportRunlevel
        if self.name.startswith('system'):
            return False
        if self.name.startswith('ReportRunlevel'):
            return False

        # Create a new event
        event = Event(self.api)
        event['fault_code'] = 0
        if fault:
            event['fault_code'] = fault.faultCode
        event['runtime'] = runtime

        # Redact passwords and sessions
        newargs = args
        if args:
            newargs = []
            for arg in args:
                if not isinstance(arg, dict):
                    newargs.append(arg)
                    continue
                # what type of auth this is
                if arg.has_key('AuthMethod'):
                    auth_methods = ['session', 'password', 'capability', 'gpg', 'hmac','anonymous']
                    auth_method = arg['AuthMethod']
                    if auth_method in auth_methods:
                        event['auth_type'] = auth_method
                for password in 'AuthString', 'session', 'password':
                    if arg.has_key(password):
                        arg = arg.copy()
                        arg[password] = "Removed by API"
                newargs.append(arg)

        # Log call representation
        # XXX Truncate to avoid DoS
        event['call'] = self.name + pprint.saferepr(newargs)
        event['call_name'] = self.name

        # Both users and nodes can call some methods
        if isinstance(self.caller, Person):
            event['person_id'] = self.caller['person_id']
        elif isinstance(self.caller, Node):
            event['node_id'] = self.caller['node_id']

        event.sync(commit = False)

        if hasattr(self, 'event_objects') and isinstance(self.event_objects, dict):
            for key in self.event_objects.keys():
                for object_id in self.event_objects[key]:
                    event.add_object(key, object_id, commit = False)


        # Set the message for this event
        if fault:
            event['message'] = fault.faultString
        elif hasattr(self, 'message'):
            event['message'] = self.message

        # Commit
        event.sync()
 def __str__(self):
     import pprint
     return pprint.saferepr(self)
Exemple #58
0
def save_repr(d, filename, env_string=''):
    with open(filename, 'wb') as save_file:
        save_file.write(env_string)
        save_file.write('e=' + pprint.saferepr(d))
 def __str__(self):
     return 'PageResult (%s): %s' % (self._status,  pprint.saferepr(self.__dict__))