Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
Zope
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
Zope
Commits
bc7b6a13
Commit
bc7b6a13
authored
Jul 14, 2010
by
Leonardo Rochael Almeida
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Warn on App.ImageFile.ImageFile deprecated assumption of software_home
parent
df1c8297
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
58 additions
and
2 deletions
+58
-2
src/App/ImageFile.py
src/App/ImageFile.py
+12
-1
src/App/config.py
src/App/config.py
+1
-1
src/App/tests/testImageFile.py
src/App/tests/testImageFile.py
+45
-0
No files found.
src/App/ImageFile.py
View file @
bc7b6a13
...
...
@@ -18,6 +18,7 @@ import os
import
os.path
import
stat
import
time
import
warnings
from
AccessControl.SecurityInfo
import
ClassSecurityInfo
from
Acquisition
import
Explicit
...
...
@@ -34,6 +35,13 @@ PREFIX = os.path.realpath(
os
.
path
.
join
(
os
.
path
.
dirname
(
Zope2
.
__file__
),
os
.
path
.
pardir
)
)
NON_PREFIX_WARNING
=
(
'Assuming image location to be present in the Zope2 '
'distribution. This is deprecated and might lead to '
'broken code if the directory in question is moved '
'to another distribution. Please provide either an '
'absolute file system path or a prefix. Support for '
'relative filenames without a prefix might be '
'dropped in a future Zope2 release.'
)
class
ImageFile
(
Explicit
):
"""Image objects stored in external files."""
...
...
@@ -43,9 +51,12 @@ class ImageFile(Explicit):
def
__init__
(
self
,
path
,
_prefix
=
None
):
import
Globals
# for data
if
_prefix
is
None
:
_prefix
=
getattr
(
getConfiguration
(),
'softwarehome'
,
PREFIX
)
_prefix
=
getattr
(
getConfiguration
(),
'softwarehome'
,
None
)
or
PREFIX
if
not
os
.
path
.
isabs
(
path
):
warnings
.
warn
(
NON_PREFIX_WARNING
,
UserWarning
,
2
)
elif
type
(
_prefix
)
is
not
type
(
''
):
_prefix
=
package_home
(
_prefix
)
# _prefix is ignored if path is absolute
path
=
os
.
path
.
join
(
_prefix
,
path
)
self
.
path
=
path
if
Globals
.
DevelopmentMode
:
...
...
src/App/config.py
View file @
bc7b6a13
...
...
@@ -36,7 +36,7 @@ def getConfiguration():
def
setConfiguration
(
cfg
):
"""Set the global configuration object.
Legacy sources of common configura
it
on values are updated to
Legacy sources of common configura
ti
on values are updated to
reflect the new configuration; this may be removed in some future
version.
"""
...
...
src/App/tests/testImageFile.py
0 → 100644
View file @
bc7b6a13
import
unittest
import
os.path
import
App
from
Testing.ZopeTestCase.warnhook
import
WarningsHook
class
TestImageFile
(
unittest
.
TestCase
):
def
setUp
(
self
):
# ugly: need to save the old App.config configuration value since
# ImageFile might read it and trigger setting it to the default value
self
.
oldcfg
=
App
.
config
.
_config
self
.
warningshook
=
WarningsHook
()
self
.
warningshook
.
install
()
def
tearDown
(
self
):
self
.
warningshook
.
uninstall
()
# ugly: need to restore configuration, or lack thereof
App
.
config
.
_config
=
self
.
oldcfg
def
test_warn_on_software_home_default
(
self
):
App
.
ImageFile
.
ImageFile
(
'App/www/zopelogo.jpg'
)
self
.
assertEquals
(
self
.
warningshook
.
warnings
.
pop
()[
0
],
App
.
ImageFile
.
NON_PREFIX_WARNING
)
def
test_no_warn_on_absolute_path
(
self
):
path
=
os
.
path
.
join
(
os
.
path
.
dirname
(
App
.
__file__
),
'www'
,
'zopelogo.jpg'
)
App
.
ImageFile
.
ImageFile
(
path
)
self
.
failIf
(
self
.
warningshook
.
warnings
)
def
test_no_warn_on_path_as_prefix
(
self
):
prefix
=
os
.
path
.
dirname
(
App
.
__file__
)
App
.
ImageFile
.
ImageFile
(
'www/zopelogo.jpg'
,
prefix
)
self
.
failIf
(
self
.
warningshook
.
warnings
)
def
test_no_warn_on_namespace_as_prefix
(
self
):
prefix
=
App
.
__dict__
# same as calling globals() inside the App module
App
.
ImageFile
.
ImageFile
(
'www/zopelogo.jpg'
,
prefix
)
self
.
failIf
(
self
.
warningshook
.
warnings
)
def
test_suite
():
return
unittest
.
TestSuite
((
unittest
.
makeSuite
(
TestImageFile
),
))
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment