From patchwork Thu Jan 5 16:30:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 39662 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp384943wrt; Thu, 5 Jan 2023 08:31:08 -0800 (PST) X-Google-Smtp-Source: AMrXdXtY2x3XlsCEEIsS3d5+KOnTpR4ZMze5/ZOvd8a6RF/svbKTq7h1DvDlDd3KDEwBpa0TGERu X-Received: by 2002:a05:6402:3998:b0:46b:203:f388 with SMTP id fk24-20020a056402399800b0046b0203f388mr55768334edb.39.1672936268777; Thu, 05 Jan 2023 08:31:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672936268; cv=none; d=google.com; s=arc-20160816; b=tM5Y51kA+HqfnZIZstiLbaLUnUJlEyOyUuOSu8QD/pke1uThQvq2ucyptN3K6lCHW5 yWhkwSVaEQJcn5orGlOHp7UsVrdr8EtDFHkKmjCmpa4CqBQ0Xc0qP0SAfD9tUD9vrFop OmJ96gclnRMj4RLAEsPcfQQrOgDncXJBhKQbgBcvXhUPF+hvc8AzbeBPVe90Daqw1XME 1+S3XoAqpZW4ONqbXO15uBLIk8S4kckO1XfjNDyxGIod//4FQam8tnc4Q/p7k/I5mAIn eOIdED2FtrmfN/3fB3DTausYB9zRk2cl0rNc5aggRClz7iRA8vxRAv3Mu6pEtFFvZOXm wM2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:to :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=KO9YyopE73FEuf0zmBe/UOkfRYmqatKj3QZj1zJNn4I=; b=U3OfIifBEIlM67AvmAfFymxz2zPWJqzBJRQ1+FuiHDsXKIvx3RNoIUDatpHIM6aiaY fIrXNE8D22RSc4zbZLmv2YAFjP/H5yR3pN+SN1zzFPXHs9pDH129EGGh6lguzBPC0RN8 ajVY5xdmhdbyzCWWHmH5q935rglEmJKgX13dmQqK7FYrlgwnMhZlQ817FgBr60QEF8kd b3hxrDnTXDoiY0Dtg60BZ2+/UhHy6wcNo3v6NBV/x3cci/GjkfXvgzP69F52JyL1HZu+ afB0TdgxRcl6SryaYV6/Exw9bKxRZK2q4p+iU4FjUVyu7/wLw+ZHx0MfT6H7UXb4xFYI tacQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=FTEBdwyl; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id gb25-20020a170907961900b007c195fb9e24si37191883ejc.42.2023.01.05.08.31.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Jan 2023 08:31:08 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=FTEBdwyl; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 93C4F3858C39 for ; Thu, 5 Jan 2023 16:31:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 93C4F3858C39 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1672936267; bh=KO9YyopE73FEuf0zmBe/UOkfRYmqatKj3QZj1zJNn4I=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=FTEBdwylilF+ijUSBsBMRl3FMva8aZtbxEgpMCNTwyVmDwoXEmk5bBThrtF/ICt+k IMrsyjVO024dDXJjQ3pA3lIRBpZ2h1uehqWuXITi6a0q0NPVTPSRe12bcZHmtUZ3NF PfwAhE36QkeCg96bRrCPbtLSvAH3DaiEIJfOLO1g= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id F1CC13858280 for ; Thu, 5 Jan 2023 16:30:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org F1CC13858280 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-661-laIXYxIgPzO2Uu7KMtmupA-1; Thu, 05 Jan 2023 11:30:11 -0500 X-MC-Unique: laIXYxIgPzO2Uu7KMtmupA-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id EEF4229324B0; Thu, 5 Jan 2023 16:30:07 +0000 (UTC) Received: from localhost (unknown [10.33.36.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id B6F3C492B06; Thu, 5 Jan 2023 16:30:07 +0000 (UTC) To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Fix printers for Python 2 [PR108212] Date: Thu, 5 Jan 2023 16:30:07 +0000 Message-Id: <20230105163007.82096-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jonathan Wakely via Gcc-patches From: Jonathan Wakely Reply-To: Jonathan Wakely Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754200820854425991?= X-GMAIL-MSGID: =?utf-8?q?1754200820854425991?= Tested powerpc64le-linux (python 2.7) and x86_64-linux (Python 3.10). Pushed to trunk. -- >8 -- The datetime.timezone.utc singleton doesn't exist in Python 2, but we can create it ourselves by deriving from datetime.tzinfo. libstdc++-v3/ChangeLog: PR libstdc++/108212 * python/libstdcxx/v6/printers.py (_utc_timezone): New global variable. (StdChronoTimePointPrinter::to_string): Use it. --- libstdc++-v3/python/libstdcxx/v6/printers.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/libstdc++-v3/python/libstdcxx/v6/printers.py b/libstdc++-v3/python/libstdcxx/v6/printers.py index 7e694f48f28..8cfb4f26b0e 100644 --- a/libstdc++-v3/python/libstdcxx/v6/printers.py +++ b/libstdc++-v3/python/libstdcxx/v6/printers.py @@ -19,7 +19,7 @@ import gdb import itertools import re import sys, os, errno -from datetime import datetime, timezone +import datetime ### Python 2 + Python 3 compatibility code @@ -45,6 +45,7 @@ if sys.version_info[0] > 2: izip = zip # Also, int subsumes long long = int + _utc_timezone = datetime.timezone.utc else: ### Python 2 stuff class Iterator: @@ -64,6 +65,20 @@ else: # In Python 2, we still need these from itertools from itertools import imap, izip + # Python 2 does not provide the datetime.UTC singleton. + class UTC(datetime.tzinfo): + """Concrete tzinfo class representing the UTC time zone""" + + def utcoffset(self, dt): + return datetime.timedelta(0) + + def tzname(self, dt): + return "UTC" + + def dst(self, dt): + return datetime.timedelta(0) + _utc_timezone = UTC() + # Try to use the new-style pretty-printing if available. _use_gdb_pp = True try: @@ -1955,7 +1970,7 @@ class StdChronoTimePointPrinter: num, den = printer._ratio() secs = (r * num / den) + offset try: - dt = datetime.fromtimestamp(secs, timezone.utc) + dt = datetime.fromtimestamp(secs, _utc_timezone) time = ' [{:%Y-%m-%d %H:%M:%S}]'.format(dt) except: pass