From 9d5df9e48e90fc7b46a4099a669dd3f70b7436f9 Mon Sep 17 00:00:00 2001 From: Norman Hooper Date: Fri, 5 May 2023 18:28:33 +0100 Subject: [PATCH 1/2] Resolve `SyntaxError: invalid escape sequence` --- couchdbkit/designer/fs.py | 2 +- couchdbkit/designer/macros.py | 4 ++-- couchdbkit/ext/django/schema.py | 2 +- couchdbkit/resource.py | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/couchdbkit/designer/fs.py b/couchdbkit/designer/fs.py index a6a3aab..e85e5ef 100644 --- a/couchdbkit/designer/fs.py +++ b/couchdbkit/designer/fs.py @@ -131,7 +131,7 @@ def _compare_with_current_version(self, db, doc): def attachment_stub(self, name, filepath): att = {} with open(filepath, "rb") as f: - re_sp = re.compile('\s') + re_sp = re.compile(r'\s') att = { "data": re_sp.sub('',base64.b64encode(f.read())), "content_type": ';'.join(filter(None, diff --git a/couchdbkit/designer/macros.py b/couchdbkit/designer/macros.py index d9fad95..901b771 100644 --- a/couchdbkit/designer/macros.py +++ b/couchdbkit/designer/macros.py @@ -91,7 +91,7 @@ def rreq(mo): "Processing code: No file matching '%s'" % mo.group(2)) return library - re_code = re.compile('(\/\/|#)\ ?!code (.*)') + re_code = re.compile(r'(//|#) ?!code (.*)') return re_code.sub(rreq, f_string) def run_json_macros(doc, f_string, app_dir): @@ -150,7 +150,7 @@ def rjson(mo): def rjson2(mo): return '\n'.join(varstrings) - re_json = re.compile('(\/\/|#)\ ?!json (.*)') + re_json = re.compile(r'(//|#) ?!json (.*)') re_json.sub(rjson, f_string) if not included: diff --git a/couchdbkit/ext/django/schema.py b/couchdbkit/ext/django/schema.py index 2e9529d..f9401e9 100644 --- a/couchdbkit/ext/django/schema.py +++ b/couchdbkit/ext/django/schema.py @@ -65,7 +65,7 @@ def __init__(self, meta, app_label=None): def contribute_to_class(self, cls, name): cls._meta = self - self.installed = re.sub('\.models$', '', cls.__module__) in settings.INSTALLED_APPS + self.installed = re.sub(r'\.models$', '', cls.__module__) in settings.INSTALLED_APPS # First, construct the default values for these options. self.object_name = cls.__name__ self.module_name = self.object_name.lower() diff --git a/couchdbkit/resource.py b/couchdbkit/resource.py index fcebb47..704cc3f 100644 --- a/couchdbkit/resource.py +++ b/couchdbkit/resource.py @@ -53,7 +53,7 @@ def escape_docid(docid): docid = url_quote(docid, safe='') return docid -re_sp = re.compile('\s') +re_sp = re.compile(r'\s') def encode_attachments(attachments): for k, v in six.iteritems(attachments): if v.get('stub', False): From 2672fe1c9a8866264c5e222252d49aba8d3ac441 Mon Sep 17 00:00:00 2001 From: Norman Hooper Date: Fri, 5 May 2023 19:04:14 +0100 Subject: [PATCH 2/2] Fix mutable default value --- couchdbkit/designer/fs.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/couchdbkit/designer/fs.py b/couchdbkit/designer/fs.py index e85e5ef..dd7748d 100644 --- a/couchdbkit/designer/fs.py +++ b/couchdbkit/designer/fs.py @@ -258,9 +258,10 @@ def check_ignore(self, item): return False def dir_to_fields(self, current_dir='', depth=0, - manifest=[]): + manifest=None): """ process a directory and get all members """ - + if manifest is None: + manifest = [] fields={} if not current_dir: current_dir = self.docdir