Commit 0c93030d authored by Nicolas Delaby's avatar Nicolas Delaby

move Document.Url.UrlMixin to mixin.url.UrlMixin

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@40960 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent c20a0ea8
master DateTime.equalTo_fix TMP-2to3 UpdateValidationStateFromConsistency UserPropertySheet_backward_compatibility addToDate_implicit_localtime add_boolean_type allow_login_change allow_login_change_wip arnau arnau-RD-Components-CacheTool arnau-RD-Components-ERP5Form-ERP5Report arnau-RD-Components-ERP5Form-SelectionTool-MemcachedTool arnau-RD-Components-ERP5OOo arnau-RD-Components-PreferenceTool-Preference arnau-RD-Components-Products-import-compat arnau-RD-Components-astroid_cache_per_component_reset arnau-RD-Components-erp5_crm arnau-RD-Components-erp5_trade-TODO-Interactor arnau-RD-ERP5ify-portal_workflow-1-seb-merged-with-recent-master arnau-RD-ERP5ify-portal_workflow-2-do-not-rename-erp5_workflow-portal_types arnau-RD-ERP5ify-portal_workflow-BAK arnau-RD-ERP5ify-portal_workflow-WIP arnau-RD-ERP5ify-portal_workflow-WITHOUT-MIGRATION arnau-RD-ERP5ify-portal_workflow-WORKFLOWS-NOT-MIGRATED arnau-RD-py3-master-TM arnau-RD-py3-master-TM-BAK arnau-RD-py3-master-WIP arnau-RD-py3-master-WIP-BAK arnau-RD-py3-master-WIP-bt5-and-tests arnau-RD-zope4py3 arnau-TM-Components-Migrate-PortalTransforms arnau-TM-Components-ModuleSecurityInfo arnau-TM-FEC-output arnau-TM-WIP arnau-TM-isBuildable-with-multiple-BusinessLinks arnau-TM-newContent-temp_object arnau-TM-runUnitTest-clear-previous-execution-catalog arnau-TM-wkhtmltopdf arnau-WIP arnau-kns arnau-kns-without-property-mapping arnau-merge arnau-my2to3 arnau-poc arnau-real-time-inventory-accounting arnau-zope4py2 aurel-zope4py2 auto_extend_select_list autoflake backup_erp5_workflow bk_erp5ish_actions_tool bk_sqlcatalog boc-interaction-drop bt5_config cache cache-control-304-response callable-jupyter-storage catalog_filter catalog_fulltext catalog_fulltext_old cedric cedriclen cedriclen-eos certificate_authority cherry-pick-4a8e045d cleanJSByJSLint clean_up_upgrader cleanup_acquisition_base_category credential_update_action cribjs-bootloader datetimefield deferred_listbox delivery_item_barcode douglas_forum dream_distributor drop-ZServer dsn-phase3 e2e-erp5 enhance_scalability_testing eos-dev erp5-component erp5-component-bak erp5-forum erp5-imt erp5-messenger erp5-preference erp5-release erp5-slapos-upgrade erp5-util-testing erp5-vifib erp5-vifib-cleanup erp5-vifib-no-Products.DCWorkflowGraph erp5-vifib-py3 erp5_calendar erp5_catalog erp5_catalog_final erp5_corporate_identity erp5_drone_simulator erp5_free_subscription erp5_hal_json_style_fix_restricted_access_with_traverse erp5_payslip_migration erp5_workflow erp5testnode_max_timeout feat/coding_style_test feat/dedup_roles_in_pickles feat/dms_implicit_predecessor_successor_fields feat/erp5_ide feat/erp5pt feat/fsum feat/improve_rounding_tool feat/inventory_api_group_by_time_interval_list feat/lxml-html-snapshot feat/mariadb-10.11 feat/mariadb-10.11bis feat/mariadb-10.11ter feat/mariadb-10.5 feat/mariadb-10.6 feat/mariadb-11.4bis feat/mariadb-11.4bis-old feat/mariadb-11.4ter feat/notification-message-ignore-missing feat/olapy feat/python_language_support feat/reindexlastobjects_log feat/round_half_up feat/selenium-unexpected-success feat/slapos_agent_distributor feat/subject_set_query feature/renderjs-ui-no-header fix/GHSA-g5vw-3h65-2q3v fix/TALES_hide_error fix/ZMI_editor_preference fix/accounting-fec-no-line fix/advance_ecommerce_coding_crimes fix/erp5_site_global_id fix/login_validate_check_consistency fix/mariadb-1927 fix/measure-optional-variation fix/monaco-altClick fix/officejs_support_request_rss_secu fix/state_var fix/support-request-app-empty fix/testnode_proctitle fix/workflow_info fix/workflow_method_security fix_isIndexable fix_web_illustration for_testrunner_1 for_testrunner_2 for_testrunner_3 gabriel gadget-json-value graphic_gadget_js hotfix/rjs-formfields-padding improve_default_caching_policy_manager initsite interaction-drop inventory isDeletable ivan jerome-bt-reference-doc jerome_graph_editor_renderjs jerome_user_preference_time_zone jio jm/form-action-guard js-ui kns lazy_simulation_causality lignan limit_accelerated_http_cache_manager lingnan listbox_url lle-bout/metadata-modules macros_fix mame-test-stock-indexation master-erp5-test-result-scalability master-erp5-test-result-scalability-rebase master-test-fix-additionalbt5path master_w mic_wind monitoring-graph mr1362 mrp my2to3 new-render-presentation no_longer_simulated_state notebook_roque oauth-login-minor-improvement officejs override_cache_control_header_by_caching_policy_manager pere poc/json-forms-study portal_callables portal_solver_process_security_configuration presentation publish_recursiveReindexObject rebased_mrp refactor/base_edit reindex_calendar_after_change_calendar_exception restore-from-trashbin revert-192c2000 revert-38554dbe rfc/activate_default rjs_listbox_sort_icon roque_quick scalability-master scalability-master2 scalability-master2-rebase scalability-roque scalability-roque-2 scalability-run-command scalability_crash_mariadb shop-box shop-box-rebase streaming_fix streaming_fix-0 support_legacy_sftp_server support_relative_url_in_hyperlink_field support_request syncml taskdistribution-xmlrpc-binary test-renderjs-float-field-step test_cmfactivity_isolation_level test_dynamic_methods test_page testnode_software_link timezones tomo_testnode_slap_request translatable_path_master tristan tristan-merge tristan-performance trustable-x-forwarded-for ttrm unify_predicate_edit view-aggregated-amounts vivekpab_renderjs_interfaces wenjie wenjie_branch without_legacy_workflow workaround_mroonga_14 wsgi wsgi-gevent wsgi_backport_setbody_lock wsgi_medusa_stream_fix yryr yryr-components-cp yryr-inventory-cache yryr-test yryr-with-components zope2 zope2zope4py2 zope4py3 zope4py3-BEFORE-CLEANUP zope4py3-master-rebase 0.4.59.1 0.4.59 test-ui test-rjsacc test-rjs renderjs-test nexedi-erp5-vifib-20201105 erp5.util-0.4.77 erp5.util-0.4.76 erp5.util-0.4.75 erp5.util-0.4.74 erp5.util-0.4.73 erp5.util-0.4.72 erp5.util-0.4.71 erp5.util-0.4.69 erp5.util-0.4.68 erp5.util-0.4.67 erp5.util-0.4.66 erp5.util-0.4.65 erp5.util-0.4.64 erp5.util-0.4.63 erp5.util-0.4.62 erp5.util-0.4.61 erp5.util-0.4.60 erp5.util-0.4.59.1 erp5.util-0.4.59 erp5.util-0.4.58 erp5.util-0.4.57 erp5.util-0.4.56 erp5.util-0.4.55 erp5.util-0.4.54 erp5.util-0.4.53 erp5.util-0.4.52 erp5.util-0.4.49 erp5.util-0.4.46 erp5.util-0.4.44 erp5.util-0.4.43 erp5.util-0.4.41 erp5.util-0.4.40 erp5.util-0.4.37 erp5.util-0.4.1 erp5.util-0.4 erp5.util-0.3 erp5.util-0.2 erp5.util-0.1 erp5-vifib-20240326 erp5-vifib-20230331 erp5-vifib-20230201 erp5-vifib-20220526 erp5-vifib-20220302 erp5-vifib-20210707 erp5-vifib-20201229 erp5-vifib-20200129
No related merge requests found
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (c) 2002 Nexedi SARL and Contributors. All Rights Reserved.
......@@ -31,112 +32,11 @@ from Products.CMFCore.utils import getToolByName
from Products.ERP5Type import Permissions, PropertySheet
from Products.ERP5Type.Base import Base
from Products.ERP5.Document.Coordinate import Coordinate
from Products.ERP5.mixin.url import UrlMixin, no_crawl_protocol_list,\
no_host_protocol_list, default_protocol_dict
from zLOG import LOG
import urllib
no_crawl_protocol_list = ['mailto', 'javascript', ]
no_host_protocol_list = ['mailto', 'news', 'javascript',]
default_protocol_dict = { 'Email' : 'mailto',
}
class UrlMixIn:
# Declarative security
security = ClassSecurityInfo()
security.declareObjectProtected(Permissions.AccessContentsInformation)
security.declareProtected(Permissions.AccessContentsInformation,
'asURL')
def asURL(self):
"""
Returns a text representation of the Url if defined
or None else.
"""
url_string = self.getUrlString()
if not url_string:
return None
protocol = self.getUrlProtocol()
if not protocol:
# A quick fix for all objects which did not
# define protocol such as email addresses
ptype = self.getPortalType()
if default_protocol_dict.has_key(ptype):
protocol = default_protocol_dict[ptype]
else:
protocol = 'http'
if protocol in no_host_protocol_list or url_string.startswith('//'):
return '%s:%s' % (protocol, url_string)
if url_string.startswith(protocol):
return url_string
return '%s://%s' % (protocol, url_string)
security.declareProtected(Permissions.ModifyPortalContent, 'fromURL')
def fromURL(self, url):
"""
Analyses a URL and splits it into two parts. URLs
normally follow RFC 1738. However, we accept URLs
without the protocol a.k.a. scheme part (http, mailto, etc.). In this
case only the url_string a.k.a. scheme-specific-part is taken
into account. asURL will then generate the full URL.
"""
if ':' in url:
# This is the normal case (protocol specified in the URL)
protocol, url_string = url.split(':', 1)
if url_string.startswith('//'): url_string = url_string[2:]
self._setUrlProtocol(protocol)
else:
url_string = url
self.setUrlString(url_string)
security.declareProtected(Permissions.AccessContentsInformation,
'getURLServer')
def getURLServer(self):
"""
Returns the server part of a URL
XXX - we must add here more consistency checking
based on the protocol of the URL
XXX - regular expressions would be better
"""
url_string = self.getUrlString()
return url_string.split('/')[0].split(':')[0]
security.declareProtected(Permissions.AccessContentsInformation,
'getURLPort')
def getURLPort(self):
"""
Returns the port part of a URL
XXX - we must add here more consistency checking
based on the protocol of the URL
XXX - regular expressions would be better
"""
url_string = self.getUrlString()
server_part_list = url_string.split('/')[0].split(':')
if len(server_part_list) > 1:
return server_part_list[1]
return None
security.declareProtected(Permissions.AccessContentsInformation,
'getURLPath')
def getURLPath(self):
"""
Returns the path part of a URL
XXX - we must add here more consistency checking
based on the protocol of the URL
XXX - regular expressions would be better
"""
url_string = self.getUrlString()
return '/'.join(url_string.split('/')[1:])
class Url(Coordinate, Base, UrlMixIn):
class Url(Coordinate, Base, UrlMixin):
"""
A Url is allows to represent in a standard way coordinates
such as web sites, emails, ftp sites, etc.
......
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (c) 2002-2010 Nexedi SA and Contributors. All Rights Reserved.
# Jean-Paul Smets-Solanes <jp@nexedi.com>
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsibility of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# guarantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
from AccessControl import ClassSecurityInfo
from Products.ERP5Type import Permissions
from Products.ERP5Type.Utils import normaliseUrl
no_crawl_protocol_list = ['mailto', 'javascript', ]
no_host_protocol_list = ['mailto', 'news', 'javascript',]
default_protocol_dict = { 'Email' : 'mailto',
}
class UrlMixin:
# Declarative security
security = ClassSecurityInfo()
security.declareObjectProtected(Permissions.AccessContentsInformation)
security.declareProtected(Permissions.AccessContentsInformation,
'asURL')
def asURL(self):
"""
Returns a text representation of the Url if defined
or None else.
"""
url_string = self.getUrlString()
if not url_string:
return None
protocol = self.getUrlProtocol()
if not protocol:
# A quick fix for all objects which did not
# define protocol such as email addresses
ptype = self.getPortalType()
if default_protocol_dict.has_key(ptype):
protocol = default_protocol_dict[ptype]
else:
protocol = 'http'
if protocol in no_host_protocol_list or url_string.startswith('//'):
return '%s:%s' % (protocol, url_string)
if url_string.startswith(protocol):
return url_string
return '%s://%s' % (protocol, url_string)
security.declareProtected(Permissions.ModifyPortalContent, 'fromURL')
def fromURL(self, url):
"""
Analyses a URL and splits it into two parts. URLs
normally follow RFC 1738. However, we accept URLs
without the protocol a.k.a. scheme part (http, mailto, etc.). In this
case only the url_string a.k.a. scheme-specific-part is taken
into account. asURL will then generate the full URL.
"""
if ':' in url:
# This is the normal case (protocol specified in the URL)
protocol, url_string = url.split(':', 1)
if url_string.startswith('//'): url_string = url_string[2:]
self._setUrlProtocol(protocol)
else:
url_string = url
self.setUrlString(url_string)
security.declareProtected(Permissions.AccessContentsInformation,
'getURLServer')
def getURLServer(self):
"""
Returns the server part of a URL
XXX - we must add here more consistency checking
based on the protocol of the URL
XXX - regular expressions would be better
"""
url_string = self.getUrlString()
return url_string.split('/')[0].split(':')[0]
security.declareProtected(Permissions.AccessContentsInformation,
'getURLPort')
def getURLPort(self):
"""
Returns the port part of a URL
XXX - we must add here more consistency checking
based on the protocol of the URL
XXX - regular expressions would be better
"""
url_string = self.getUrlString()
server_part_list = url_string.split('/')[0].split(':')
if len(server_part_list) > 1:
return server_part_list[1]
return None
security.declareProtected(Permissions.AccessContentsInformation,
'getURLPath')
def getURLPath(self):
"""
Returns the path part of a URL
XXX - we must add here more consistency checking
based on the protocol of the URL
XXX - regular expressions would be better
"""
url_string = self.getUrlString()
return '/'.join(url_string.split('/')[1:])
def asNormalisedURL(self, base_url=None):
"""
call normaliseUrl with raw url
"""
if self.hasUrlString():
return normaliseUrl(self.asURL(), base_url=base_url)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment