def build_artifact(self, artifact): ctx = get_ctx() feed_source = self.source page = feed_source.parent fg = FeedGenerator() fg.id(get_id(ctx.env.project.id)) fg.title(page.record_label + u" — Pallets Project") fg.link(href=url_to("/blog", external=True)) fg.link(href=url_to(feed_source, external=True), rel="self") for item in page.children.order_by('-pub_date', '-pub_order', 'title').limit(10): fe = fg.add_entry() fe.title(item["title"]) fe.content(text_type(item["body"]), type="html") fe.link(href=url_to(item, external=True)) fe.id( get_id(u"{}/{}".format(ctx.env.project.id, item["_path"].encode("utf-8")))) fe.author(name=item["author"]) updated = datetime(*item["pub_date"].timetuple()[:3]) updated = updated.isoformat() + "Z" if not updated.tzinfo else "" fe.updated(updated) with artifact.open('wb') as f: f.write(fg.atom_str(pretty=True))
def make_editor_session(pad, path, is_attachment=None, alt=PRIMARY_ALT, datamodel=None): """Creates an editor session for the given path object.""" if alt != PRIMARY_ALT and not pad.db.config.is_valid_alternative(alt): raise BadEdit('Attempted to edit an invalid alternative (%s)' % alt) raw_data = pad.db.load_raw_data(path, cls=OrderedDict, alt=alt, fallback=False) raw_data_fallback = None if alt != PRIMARY_ALT: raw_data_fallback = pad.db.load_raw_data(path, cls=OrderedDict) all_data = OrderedDict() all_data.update(raw_data_fallback or ()) all_data.update(raw_data or ()) else: all_data = raw_data id = posixpath.basename(path) if not is_valid_id(id): raise BadEdit('Invalid ID') record = None exists = all_data is not None if raw_data is None: raw_data = OrderedDict() if is_attachment is None: if not exists: is_attachment = False else: is_attachment = bool(all_data.get('_attachment_for')) elif bool(all_data.get('_attachment_for')) != is_attachment: raise BadEdit('The attachment flag passed is conflicting with the ' 'record\'s attachment flag.') if exists: # XXX: what about changing the datamodel after the fact? if datamodel is not None: raise BadEdit('When editing an existing record, a datamodel ' 'must not be provided.') datamodel = pad.db.get_datamodel_for_raw_data(all_data, pad) else: if datamodel is None: datamodel = pad.db.get_implied_datamodel(path, is_attachment, pad) elif isinstance(datamodel, string_types): datamodel = pad.db.datamodels[datamodel] if exists: record = pad.instance_from_data(dict(all_data), datamodel) for key in implied_keys: raw_data.pop(key, None) if raw_data_fallback: raw_data_fallback.pop(key, None) return EditorSession(pad, id, text_type(path), raw_data, raw_data_fallback, datamodel, record, exists, is_attachment, alt)
def default(self, o): # pylint: disable=method-hidden if is_undefined(o): return None if isinstance(o, datetime): return http_date(o) if isinstance(o, uuid.UUID): return str(o) if hasattr(o, '__html__'): return text_type(o.__html__()) return json.JSONEncoder.default(self, o)
def default(self, o): if is_undefined(o): return None if isinstance(o, datetime): return http_date(o) if isinstance(o, uuid.UUID): return str(o) if hasattr(o, '__html__'): return text_type(o.__html__()) return json.JSONEncoder.default(self, o)
def __str__(self): return text_type(self.message)
def md(s): rv = field.deserialize_value(s, pad=pad) assert isinstance(rv, MarkdownDescriptor) return text_type(rv.__get__(source)).strip()
def publish(env, target, output_path, credentials=None, **extra): url = urls.url_parse(text_type(target)) publisher = env.publishers.get(url.scheme) if publisher is None: raise PublishError('"%s" is an unknown scheme.' % url.scheme) return publisher(env, output_path).publish(url, credentials, **extra)
def sort_normalize_string(s): return unicodedata.normalize('NFD', text_type(s).lower().strip())
def append(self, item): if item is None: return item = text_type(item).strip('/') if item: self.items.append(item)
def __unicode__(self): return text_type(self.message)
def report_generic(self, message): self._write_line(style(text_type(message), fg='cyan'))
def _write_kv_info(self, key, value): self._write_line('%s: %s' % (key, style(text_type(value), fg='yellow')))
def get_id(s): s = text_type(s).encode('utf8') return uuid.UUID(bytes=hashlib.md5(s).digest(), version=3).urn
def _write_kv_info(self, key, value): self._write_line("%s: %s" % (key, style(text_type(value), fg="yellow")))